blob: ba2a80ee872c8519fc0eed5abf07ac319bbf2dc1 [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'Connord5f1e842008-02-28 20:01:11 -050025CFLAGS16WHOLE = $(CFLAGS16) -g -fwhole-program
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050026
27all: $(OUT) $(OUT)rom.bin
28
29# Run with "make V=1" to see the actual compile commands
30ifdef V
31Q=
32else
33Q=@
34endif
35
36.PHONY : all FORCE
37
38vpath %.c src
39vpath %.S src
40
41################ Build rules
42$(OUT)%.proc.16.s: $(OUT)%.16.s
43 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050044 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050045
46$(OUT)%.16.s: %.c
47 @echo " Generating assembler for $<"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050048 $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050049
50$(OUT)%.lds: %.lds.S
51 @echo " Precompiling $<"
52 $(Q)$(CPP) -P $< -o $@
53
54$(OUT)%.bin: $(OUT)%.o
55 @echo " Extracting binary $@"
56 $(Q)objcopy -O binary $< $@
57
58$(OUT)%.offset.auto.h: $(OUT)%.o
59 @echo " Generating symbol offset header $@"
60 $(Q)nm $< | ./tools/defsyms.py > $@
61
62$(OUT)blob.16.s:
63 @echo " Generating whole program assembler $@"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050064 $(Q)$(CC) $(CFLAGS16WHOLE) -S -combine -c $(addprefix src/, $(SRC16)) -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050065
66$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(OUT)font.proc.16.s $(OUT)cbt.proc.16.s
67 @echo " Generating 16bit layout of $@"
68 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
69
70$(OUT)rom16.o: $(OUT)romlayout16.o
71 @echo " Linking $@"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050072 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050073
74$(OUT)rom16.bin: $(OUT)rom16.o
75 @echo " Extracting binary $@"
76 $(Q)objcopy -O binary $< $@
77
78$(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h
79 @echo " Compiling whole program $@"
80 $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@
81
82$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
83 @echo " Linking $@"
84 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
85
86$(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
87 @echo " Building $@"
88 $(Q)./tools/buildrom.py
89
90####### Generic rules
91clean:
92 rm -rf $(OUT)
93
94$(OUT):
95 mkdir $@
96
97-include $(OUT)*.d