blob: ad99d817a244bc08c92fd95dfe2a2825398cfd82 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001# 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
8OUT=out/
9
10# Source files
Kevin O'Connor4b60c002008-02-25 22:29:55 -050011SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c boot.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050012SRC32=post.c output.c
13
Kevin O'Connor786502d2008-02-27 10:41:41 -050014cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
15 /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;)
16
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050017# Default compiler flags
Kevin O'Connor786502d2008-02-27 10:41:41 -050018COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
19COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
20COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
21COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
22
23CFLAGS = $(COMMONCFLAGS) -g
24CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050025
26all: $(OUT) $(OUT)rom.bin
27
28# Run with "make V=1" to see the actual compile commands
29ifdef V
30Q=
31else
32Q=@
33endif
34
35.PHONY : all FORCE
36
37vpath %.c src
38vpath %.S src
39
40################ Build rules
41$(OUT)%.proc.16.s: $(OUT)%.16.s
42 @echo " Moving data sections to text in $<"
43 $(Q)sed 's/\t.section\t.rodata.*// ; s/\t.data//' < $< > $@
44
45$(OUT)%.16.s: %.c
46 @echo " Generating assembler for $<"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050047 $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050048
49$(OUT)%.lds: %.lds.S
50 @echo " Precompiling $<"
51 $(Q)$(CPP) -P $< -o $@
52
53$(OUT)%.bin: $(OUT)%.o
54 @echo " Extracting binary $@"
55 $(Q)objcopy -O binary $< $@
56
57$(OUT)%.offset.auto.h: $(OUT)%.o
58 @echo " Generating symbol offset header $@"
59 $(Q)nm $< | ./tools/defsyms.py > $@
60
61$(OUT)blob.16.s:
62 @echo " Generating whole program assembler $@"
63 $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $(addprefix src/, $(SRC16)) -o $@
64
65$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(OUT)font.proc.16.s $(OUT)cbt.proc.16.s
66 @echo " Generating 16bit layout of $@"
67 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
68
69$(OUT)rom16.o: $(OUT)romlayout16.o
70 @echo " Linking $@"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050071 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050072
73$(OUT)rom16.bin: $(OUT)rom16.o
74 @echo " Extracting binary $@"
75 $(Q)objcopy -O binary $< $@
76
77$(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h
78 @echo " Compiling whole program $@"
79 $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@
80
81$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
82 @echo " Linking $@"
83 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
84
85$(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
86 @echo " Building $@"
87 $(Q)./tools/buildrom.py
88
89####### Generic rules
90clean:
91 rm -rf $(OUT)
92
93$(OUT):
94 mkdir $@
95
96-include $(OUT)*.d