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