Makefile 1.23 KB
Newer Older
Shiz's avatar
epoch  
Shiz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
LDRDIR = ldr
OBJDIR = obj
BINDIR = bin
SRCDIR = src
DATADIR = data

COPTFLAGS=-Os -fvisibility=hidden -mpreferred-stack-boundary=2 -fwhole-program \
  -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

ASFLAGS=-f elf -I $(LDRDIR)/
CFLAGS=-Wall -Wextra -Wpedantic -std=c99 $(COPTFLAGS) -nostartfiles -fno-PIC
CXXFLAGS=-Wall -Wextra -Wpedantic -std=c++11 $(CXXOPTFLAGS) -nostartfiles -fno-PIC
LIBS=-lGL -ldl -lc
LDFLAGS=--oformat=binary -T ldr/link.ld


.PHONY: all
all: $(BINDIR)/test

.PHONY: clean
clean:
	rm -rf $(OBJDIR)/* $(BINDIR)/*


.SECONDARY:

$(OBJDIR)/%.o: $(SRCDIR)/%.c
	$(CC) $(CFLAGS) -c $^ -o $@

$(OBJDIR)/%.o.syms: $(OBJDIR)/%.o
	readelf -s $^ | grep UND | sed 1d | awk '{ print $$8 }' > $@

$(OBJDIR)/symbols.%.s: $(OBJDIR)/%.o.syms
	$(LDRDIR)/mksyms $(LIBS) $$(cat $^) > $@

$(OBJDIR)/header.%.o: $(OBJDIR)/symbols.%.s $(LDRDIR)/header.s $(LDRDIR)/loader.s
	nasm $(ASFLAGS) $< -o $@

$(BINDIR)/%: $(OBJDIR)/%.o $(OBJDIR)/header.%.o
	$(LD) $(LDFLAGS) $^ -o $@