Rewrite ps2 port (keyboard/mouse) handling.
[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 system.c mouse.c kbd.c pci.c \
12         serial.c clock.c pic.c cdrom.c ps2port.c
13 SRC16=$(SRCBOTH) disk.c apm.c pcibios.c vgahooks.c
14 SRC32=$(SRCBOTH) post.c shadow.c post_menu.c memmap.c coreboot.c boot.c \
15       acpi.c pirtable.c smm.c smpdetect.c mptable.c smbios.c pciinit.c
16 TABLESRC=font.c cbt.c floppy_dbt.c
17
18 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
19               /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
20
21 # Default compiler flags
22 COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
23                -mpreferred-stack-boundary=2 -mrtd \
24                -ffreestanding -fwhole-program -fomit-frame-pointer \
25                -fno-delete-null-pointer-checks
26 COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
27 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
28 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
29
30 CFLAGS = $(COMMONCFLAGS) -g -DMODE16=0
31 CFLAGS16INC = $(COMMONCFLAGS) -DMODE16=1 -fno-jump-tables -fno-defer-pop \
32               $(call cc-option,$(CC),--param large-stack-frame=8,)
33 CFLAGS16 = $(CFLAGS16INC) -g
34
35 TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
36 all: $(OUT) $(OUT)bios.bin $(TABLETMP)
37
38 # Run with "make V=1" to see the actual compile commands
39 ifdef V
40 Q=
41 else
42 Q=@
43 endif
44
45 .PHONY : all FORCE
46
47 vpath %.c src
48 vpath %.S src
49
50 ################ Build rules
51
52 # Do a whole file compile - two methods are supported.  The first
53 # involves including all the content textually via #include
54 # directives.  The second method uses gcc's "-combine" option.
55 ifdef AVOIDCOMBINE
56 DEPHACK=
57 define whole-compile
58 @echo "  Compiling whole program $3"
59 $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
60 $(Q)$(CC) $1 -c $3.tmp.c -o $3
61 endef
62 else
63 # Ugly way to get gcc to generate .d files correctly.
64 DEPHACK=-combine src/null.c
65 define whole-compile
66 @echo "  Compiling whole program $3"
67 $(Q)$(CC) $1 -combine -c $2 -o $3
68 endef
69 endif
70
71
72 $(OUT)%.proc.16.s: $(OUT)%.16.s
73         @echo "  Moving data sections to text in $<"
74         $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
75
76 $(OUT)%.16.s: %.c
77         @echo "  Generating assembler for $<"
78         $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
79
80 $(OUT)%.lds: %.lds.S
81         @echo "  Precompiling $<"
82         $(Q)$(CPP) -P $< -o $@
83
84
85 $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
86
87 TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
88 $(OUT)romlayout16.o: romlayout.S $(OUT)blob.16.s $(TABLEASM)
89         @echo "  Generating 16bit layout of $@"
90         $(Q)$(CC) $(CFLAGS16) -c $< -o $@
91
92 $(OUT)romlayout32.o: ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
93
94 $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
95         @echo "  Linking (no relocs) $@"
96         $(Q)ld -r -T $(OUT)rombios32.lds $< -o $@
97
98 $(OUT)rom16.o: $(OUT)romlayout16.o $(OUT)rom32.o $(OUT)rombios16.lds
99         @echo "  Linking $@"
100         $(Q)objcopy --prefix-symbols=_code32_ $(OUT)rom32.o $(OUT)rom32.rename.o
101         $(Q)ld -T $(OUT)rombios16.lds -R $(OUT)rom32.rename.o $< -o $@
102
103 $(OUT)rom.o: $(OUT)rom16.o $(OUT)rom32.o $(OUT)rombios.lds
104         @echo "  Linking $@"
105         $(Q)ld -T $(OUT)rombios.lds $(OUT)rom16.o $(OUT)rom32.o -o $@
106
107 $(OUT)bios.bin.elf: $(OUT)rom.o
108         @echo "  Prepping $@"
109         $(Q)nm $< | ./tools/checkrom.py
110         $(Q)strip $< -o $@
111
112 $(OUT)bios.bin: $(OUT)bios.bin.elf
113         @echo "  Extracting binary $@"
114         $(Q)objcopy -O binary $< $@
115
116
117 ####### Generic rules
118 clean:
119         rm -rf $(OUT)
120
121 $(OUT):
122         mkdir $@
123
124 -include $(OUT)*.d