Makefile 1.68 KB
Newer Older
PoroCYon's avatar
PoroCYon committed
1
2
3
4
5
OBJDIR := obj
BINDIR := bin
SRCDIR := src
LDDIR  := ld
TESTDIR:= test
Shiz's avatar
epoch  
Shiz committed
6

PoroCYon's avatar
PoroCYon committed
7
8
# -mpreferred-stack-boundary=3 messes up the stack and kills SSE!
COPTFLAGS=-Os -fvisibility=hidden -fwhole-program \
Shiz's avatar
epoch  
Shiz committed
9
10
11
12
13
14
  -ffast-math -funsafe-math-optimizations -fno-stack-protector -fomit-frame-pointer \
  -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables
CXXOPTFLAGS=$(COPTFLAGS) \
  -fno-rtti -fno-enforce-eh-specs -fnothrow-opt -fno-use-cxa-get-exception-ptr \
  -fno-implicit-templates -fno-threadsafe-statics -fno-use-cxa-atexit

PoroCYon's avatar
PoroCYon committed
15
CFLAGS=-Wall -Wextra -Wpedantic -std=gnu11 -nostartfiles -fno-PIC $(COPTFLAGS)
Shiz's avatar
epoch  
Shiz committed
16
CXXFLAGS=-Wall -Wextra -Wpedantic -std=c++11 $(CXXOPTFLAGS) -nostartfiles -fno-PIC
PoroCYon's avatar
PoroCYon committed
17
18
19
20
21
22
23
24

ASFLAGS=-f elf -I $(SRCDIR)/
LDFLAGS=-m elf_i386
LDFLAGS_=$(LDFLAGS) -T $(LDDIR)/link.ld --oformat=binary

CFLAGS   += -m32
CXXFLAGS += -m32

25
LIBS=-lc
Shiz's avatar
epoch  
Shiz committed
26

PoroCYon's avatar
PoroCYon committed
27
28
29
30
ASFLAGS += -DUSE_INTERP

NASM    ?= nasm
PYTHON3 ?= python3
Shiz's avatar
epoch  
Shiz committed
31

PoroCYon's avatar
PoroCYon committed
32
33
34
all: $(BINDIR)/sdl $(BINDIR)/hello

LIBS += -lSDL2 -lGL
Shiz's avatar
epoch  
Shiz committed
35
36

clean:
PoroCYon's avatar
PoroCYon committed
37
	@$(RM) -vrf $(OBJDIR) $(BINDIR)
Shiz's avatar
epoch  
Shiz committed
38

PoroCYon's avatar
PoroCYon committed
39
40
%/:
	@mkdir -vp "$@"
Shiz's avatar
epoch  
Shiz committed
41
42
43

.SECONDARY:

PoroCYon's avatar
PoroCYon committed
44
45
46
47
48
49
50
51
52
53
54
55
56
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(OBJDIR)/
	$(CC) -m32 $(CFLAGS) -c "$<" -o "$@"
$(OBJDIR)/%.o: $(TESTDIR)/%.c $(OBJDIR)/
	$(CC) -m32 $(CFLAGS) -c "$<" -o "$@"

$(OBJDIR)/%.start.o: $(OBJDIR)/%.o $(OBJDIR)/crt1.o
	$(LD) $(LDFLAGS) -r -o "$@" $^

$(OBJDIR)/crt1.o: $(SRCDIR)/crt1.c $(OBJDIR)/
	$(CC) $(CFLAGS) -c "$<" -o "$@"

$(OBJDIR)/symbols.%.asm: $(OBJDIR)/%.start.o
	$(PYTHON3) ./smol.py $(LIBS) "$<" "$@"
Shiz's avatar
epoch  
Shiz committed
57

PoroCYon's avatar
PoroCYon committed
58
59
60
$(OBJDIR)/stub.%.o: $(OBJDIR)/symbols.%.asm $(SRCDIR)/header.asm \
        $(SRCDIR)/loader.asm
	$(NASM) $(ASFLAGS) $< -o $@
Shiz's avatar
epoch  
Shiz committed
61

PoroCYon's avatar
PoroCYon committed
62
63
$(BINDIR)/%: $(OBJDIR)/%.start.o $(OBJDIR)/stub.%.o $(BINDIR)/
	$(LD) $(LDFLAGS_) $(OBJDIR)/$*.start.o $(OBJDIR)/stub.$*.o -o "$@"
Shiz's avatar
epoch  
Shiz committed
64

PoroCYon's avatar
PoroCYon committed
65
.PHONY: all clean
Shiz's avatar
epoch  
Shiz committed
66