blob: f198767a33d970c720916c751d8c9bfa0dbb64ed [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'Connor3491e8b2008-02-29 00:22:27 -050011SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \
12 boot.c ata.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050013SRC32=post.c output.c
Kevin O'Connor44c631d2008-03-02 11:24:36 -050014TABLESRC=font.c cbt.c floppy_dbt.c
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050015
Kevin O'Connor786502d2008-02-27 10:41:41 -050016cc-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
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050019# Default compiler flags
Kevin O'Connor786502d2008-02-27 10:41:41 -050020COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding
21COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
22COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
23COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
24
25CFLAGS = $(COMMONCFLAGS) -g
26CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
Kevin O'Connord5f1e842008-02-28 20:01:11 -050027CFLAGS16WHOLE = $(CFLAGS16) -g -fwhole-program
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050028
Kevin O'Connor44c631d2008-03-02 11:24:36 -050029TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
30all: $(OUT) $(OUT)rom.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050031
32# Run with "make V=1" to see the actual compile commands
33ifdef V
34Q=
35else
36Q=@
37endif
38
39.PHONY : all FORCE
40
41vpath %.c src
42vpath %.S src
43
44################ Build rules
45$(OUT)%.proc.16.s: $(OUT)%.16.s
46 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050047 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050048
49$(OUT)%.16.s: %.c
50 @echo " Generating assembler for $<"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050051 $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050052
53$(OUT)%.lds: %.lds.S
54 @echo " Precompiling $<"
55 $(Q)$(CPP) -P $< -o $@
56
57$(OUT)%.bin: $(OUT)%.o
58 @echo " Extracting binary $@"
59 $(Q)objcopy -O binary $< $@
60
61$(OUT)%.offset.auto.h: $(OUT)%.o
62 @echo " Generating symbol offset header $@"
Kevin O'Connor596cf602008-03-01 10:11:55 -050063 $(Q)nm $< | ./tools/defsyms.py $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050064
65$(OUT)blob.16.s:
66 @echo " Generating whole program assembler $@"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050067 $(Q)$(CC) $(CFLAGS16WHOLE) -S -combine -c $(addprefix src/, $(SRC16)) -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050068
Kevin O'Connor44c631d2008-03-02 11:24:36 -050069TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
70$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050071 @echo " Generating 16bit layout of $@"
72 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
73
74$(OUT)rom16.o: $(OUT)romlayout16.o
75 @echo " Linking $@"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050076 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050077
78$(OUT)rom16.bin: $(OUT)rom16.o
79 @echo " Extracting binary $@"
80 $(Q)objcopy -O binary $< $@
81
82$(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h
83 @echo " Compiling whole program $@"
84 $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@
85
86$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
87 @echo " Linking $@"
88 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
89
90$(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
91 @echo " Building $@"
92 $(Q)./tools/buildrom.py
93
94####### Generic rules
95clean:
96 rm -rf $(OUT)
97
98$(OUT):
99 mkdir $@
100
101-include $(OUT)*.d