Enhance included bios tables.
[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 TABLESRC=font.c cbt.c floppy_dbt.c
15
16 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
17               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
18
19 # Default compiler flags
20 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
21 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
22 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
23 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
24
25 CFLAGS = $(COMMONCFLAGS) -g
26 CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
27 CFLAGS16WHOLE = $(CFLAGS16) -g -fwhole-program
28
29 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
30 all: $(OUT) $(OUT)rom.bin $(TABLETMP)
31
32 # Run with "make V=1" to see the actual compile commands
33 ifdef V
34 Q=
35 else
36 Q=@
37 endif
38
39 .PHONY : all FORCE
40
41 vpath %.c src
42 vpath %.S src
43
44 ################ Build rules
45 $(OUT)%.proc.16.s: $(OUT)%.16.s
46         @echo "  Moving data sections to text in $<"
47         $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
48
49 $(OUT)%.16.s: %.c
50         @echo "  Generating assembler for $<"
51         $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@
52
53 $(OUT)%.lds: %.lds.S
54         @echo "  Precompiling $<"
55         $(Q)$(CPP) -P $< -o $@
56
57 $(OUT)%.bin: $(OUT)%.o
58         @echo "  Extracting binary $@"
59         $(Q)objcopy -O binary $< $@
60
61 $(OUT)%.offset.auto.h: $(OUT)%.o
62         @echo "  Generating symbol offset header $@"
63         $(Q)nm $< | ./tools/defsyms.py $@
64
65 $(OUT)blob.16.s:
66         @echo "  Generating whole program assembler $@"
67         $(Q)$(CC) $(CFLAGS16WHOLE) -S -combine -c $(addprefix src/, $(SRC16)) -o $@
68
69 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
70 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
71         @echo "  Generating 16bit layout of $@"
72         $(Q)$(CC) $(CFLAGS16) -c $< -o $@
73
74 $(OUT)rom16.o: $(OUT)romlayout16.o
75         @echo "  Linking $@"
76         $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
77
78 $(OUT)rom16.bin: $(OUT)rom16.o
79         @echo "  Extracting binary $@"
80         $(Q)objcopy -O binary $< $@
81
82 $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h
83         @echo "  Compiling whole program $@"
84         $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@
85
86 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
87         @echo "  Linking $@"
88         $(Q)ld -T $(OUT)rombios32.lds $< -o $@
89
90 $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
91         @echo "  Building $@"
92         $(Q)./tools/buildrom.py
93
94 ####### Generic rules
95 clean:
96         rm -rf $(OUT)
97
98 $(OUT):
99         mkdir $@
100
101 -include $(OUT)*.d