Basic support for PCI BIOS.
[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 cdrom.c apm.c util.c pcibios.c pci.c
13 SRC32=post.c output.c rombios32.c util.c ata.c kbd.c pci.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 \
21                -ffreestanding -fwhole-program -fomit-frame-pointer \
22                -fno-delete-null-pointer-checks
23 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
24 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
25 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
26
27 CFLAGS = $(COMMONCFLAGS) -g
28 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
29 CFLAGS16 = $(CFLAGS16INC) -g
30
31 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
32 all: $(OUT) $(OUT)rom.bin $(TABLETMP)
33
34 # Run with "make V=1" to see the actual compile commands
35 ifdef V
36 Q=
37 else
38 Q=@
39 endif
40
41 .PHONY : all FORCE
42
43 vpath %.c src
44 vpath %.S src
45
46 ################ Build rules
47
48 # Do a whole file compile - two methods are supported.  The first
49 # involves including all the content textually via #include
50 # directives.  The second method uses gcc's "-combine" option.
51 ifdef AVOIDCOMBINE
52 DEPHACK=
53 define whole-compile
54 @echo "  Compiling whole program $3"
55 $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
56 $(Q)$(CC) $1 -c $3.tmp.c -o $3
57 endef
58 else
59 # Ugly way to get gcc to generate .d files correctly.
60 DEPHACK=-combine src/null.c
61 define whole-compile
62 @echo "  Compiling whole program $3"
63 $(Q)$(CC) $1 -combine -c $2 -o $3
64 endef
65 endif
66
67
68 $(OUT)%.proc.16.s: $(OUT)%.16.s
69         @echo "  Moving data sections to text in $<"
70         $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
71
72 $(OUT)%.16.s: %.c
73         @echo "  Generating assembler for $<"
74         $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
75
76 $(OUT)%.lds: %.lds.S
77         @echo "  Precompiling $<"
78         $(Q)$(CPP) -P $< -o $@
79
80 $(OUT)%.bin: $(OUT)%.o
81         @echo "  Extracting binary $@"
82         $(Q)objcopy -O binary $< $@
83
84 $(OUT)%.offset.auto.h: $(OUT)%.o
85         @echo "  Generating symbol offset header $@"
86         $(Q)nm $< | ./tools/defsyms.py $@
87
88 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
89
90 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
91 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
92         @echo "  Generating 16bit layout of $@"
93         $(Q)$(CC) $(CFLAGS16) -c $< -o $@
94
95 $(OUT)rom16.o: $(OUT)romlayout16.o
96         @echo "  Linking $@"
97         $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
98
99 $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
100
101 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
102         @echo "  Linking $@"
103         $(Q)ld -T $(OUT)rombios32.lds $< -o $@
104
105 $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
106         @echo "  Building $@"
107         $(Q)./tools/buildrom.py
108
109 ####### Generic rules
110 clean:
111         rm -rf $(OUT)
112
113 $(OUT):
114         mkdir $@
115
116 -include $(OUT)*.d