blob: 7415f6afc64988220393b49b843ca250c5c8daf8 [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 \
Kevin O'Connora4d35762008-03-08 15:43:03 -050012 boot.c ata.c cdrom.c apm.c util.c
13SRC32=post.c output.c rombios32.c util.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'Connor410680b2008-03-02 20:48:35 -050020COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 \
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040021 -ffreestanding -fwhole-program -fomit-frame-pointer \
22 -fno-delete-null-pointer-checks
Kevin O'Connor786502d2008-02-27 10:41:41 -050023COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
24COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
25COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
26
27CFLAGS = $(COMMONCFLAGS) -g
Kevin O'Connor410680b2008-03-02 20:48:35 -050028CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
29CFLAGS16 = $(CFLAGS16INC) -g
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050030
Kevin O'Connor44c631d2008-03-02 11:24:36 -050031TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
32all: $(OUT) $(OUT)rom.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050033
34# Run with "make V=1" to see the actual compile commands
35ifdef V
36Q=
37else
38Q=@
39endif
40
41.PHONY : all FORCE
42
43vpath %.c src
44vpath %.S src
45
46################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050047
48# Do a whole file compile - two methods are supported. The first
49# involves including all the content textually via #include
50# directives. The second method uses gcc's "-combine" option.
51ifdef AVOIDCOMBINE
52DEPHACK=
53define whole-compile
54@echo " Compiling whole program $3"
55$(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
56$(Q)$(CC) $1 -c $3.tmp.c -o $3
57endef
58else
59# Ugly way to get gcc to generate .d files correctly.
60DEPHACK=-combine src/null.c
61define whole-compile
62@echo " Compiling whole program $3"
63$(Q)$(CC) $1 -combine -c $2 -o $3
64endef
65endif
66
67
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050068$(OUT)%.proc.16.s: $(OUT)%.16.s
69 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050070 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050071
72$(OUT)%.16.s: %.c
73 @echo " Generating assembler for $<"
Kevin O'Connor410680b2008-03-02 20:48:35 -050074 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050075
76$(OUT)%.lds: %.lds.S
77 @echo " Precompiling $<"
78 $(Q)$(CPP) -P $< -o $@
79
80$(OUT)%.bin: $(OUT)%.o
81 @echo " Extracting binary $@"
82 $(Q)objcopy -O binary $< $@
83
84$(OUT)%.offset.auto.h: $(OUT)%.o
85 @echo " Generating symbol offset header $@"
Kevin O'Connor596cf602008-03-01 10:11:55 -050086 $(Q)nm $< | ./tools/defsyms.py $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050087
Kevin O'Connor410680b2008-03-02 20:48:35 -050088$(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050089
Kevin O'Connor44c631d2008-03-02 11:24:36 -050090TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
91$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050092 @echo " Generating 16bit layout of $@"
93 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
94
95$(OUT)rom16.o: $(OUT)romlayout16.o
96 @echo " Linking $@"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050097 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050098
99$(OUT)rom16.bin: $(OUT)rom16.o
100 @echo " Extracting binary $@"
101 $(Q)objcopy -O binary $< $@
102
Kevin O'Connor47baa3c2008-03-08 13:17:16 -0500103$(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500104
105$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
106 @echo " Linking $@"
107 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
108
109$(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
110 @echo " Building $@"
111 $(Q)./tools/buildrom.py
112
113####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500114clean:
115 rm -rf $(OUT)
116
117$(OUT):
118 mkdir $@
119
120-include $(OUT)*.d