Makefile 1.25 KB
Newer Older
Shiz's avatar
epoch  
Shiz committed
1
2
3
4
5
6
LDRDIR = ldr
OBJDIR = obj
BINDIR = bin
SRCDIR = src
DATADIR = data

7
COPTFLAGS=-Os -fvisibility=hidden -mpreferred-stack-boundary=3 -fwhole-program \
Shiz's avatar
epoch  
Shiz committed
8
9
10
11
12
13
14
15
16
  -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
17
LIBS=-lc
Shiz's avatar
epoch  
Shiz committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
LDFLAGS=--oformat=binary -T ldr/link.ld


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

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


.SECONDARY:

$(OBJDIR)/%.o: $(SRCDIR)/%.c
32
	$(CC) -m32 $(CFLAGS) -c $^ -o $@
Shiz's avatar
epoch  
Shiz committed
33
34
35
36
37
38
39
40

$(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
PoroCYon's avatar
PoroCYon committed
41
	nasm -DUSE_INTERP $(ASFLAGS) $< -o $@
Shiz's avatar
epoch  
Shiz committed
42
43

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