Update TODO notes.
[seabios.git] / Makefile
1 # Legacy Bios build system
2 #
3 # Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 #
5 # This file may be distributed under the terms of the GNU GPLv3 license.
6
7 # Output directory
8 OUT=out/
9
10 # Source files
11 SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \
12       boot.c ata.c
13 SRC32=post.c output.c
14
15 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
16               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
17
18 # Default compiler flags
19 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
20 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
21 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
22 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
23
24 CFLAGS = $(COMMONCFLAGS) -g
25 CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
26 CFLAGS16WHOLE = $(CFLAGS16) -g -fwhole-program
27
28 all: $(OUT) $(OUT)rom.bin
29
30 # Run with "make V=1" to see the actual compile commands
31 ifdef V
32 Q=
33 else
34 Q=@
35 endif
36
37 .PHONY : all FORCE
38
39 vpath %.c src
40 vpath %.S src
41
42 ################ Build rules
43 $(OUT)%.proc.16.s: $(OUT)%.16.s
44         @echo "  Moving data sections to text in $<"
45         $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
46
47 $(OUT)%.16.s: %.c
48         @echo "  Generating assembler for $<"
49         $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@
50
51 $(OUT)%.lds: %.lds.S
52         @echo "  Precompiling $<"
53         $(Q)$(CPP) -P $< -o $@
54
55 $(OUT)%.bin: $(OUT)%.o
56         @echo "  Extracting binary $@"
57         $(Q)objcopy -O binary $< $@
58
59 $(OUT)%.offset.auto.h: $(OUT)%.o
60         @echo "  Generating symbol offset header $@"
61         $(Q)nm $< | ./tools/defsyms.py $@
62
63 $(OUT)blob.16.s:
64         @echo "  Generating whole program assembler $@"
65         $(Q)$(CC) $(CFLAGS16WHOLE) -S -combine -c $(addprefix src/, $(SRC16)) -o $@
66
67 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(OUT)font.proc.16.s $(OUT)cbt.proc.16.s
68         @echo "  Generating 16bit layout of $@"
69         $(Q)$(CC) $(CFLAGS16) -c $< -o $@
70
71 $(OUT)rom16.o: $(OUT)romlayout16.o
72         @echo "  Linking $@"
73         $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
74
75 $(OUT)rom16.bin: $(OUT)rom16.o
76         @echo "  Extracting binary $@"
77         $(Q)objcopy -O binary $< $@
78
79 $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h
80         @echo "  Compiling whole program $@"
81         $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@
82
83 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
84         @echo "  Linking $@"
85         $(Q)ld -T $(OUT)rombios32.lds $< -o $@
86
87 $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
88         @echo "  Building $@"
89         $(Q)./tools/buildrom.py
90
91 ####### Generic rules
92 clean:
93         rm -rf $(OUT)
94
95 $(OUT):
96         mkdir $@
97
98 -include $(OUT)*.d