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