blob: c8e68bda182eb2b74952b89863df3c35edf3f54c [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'Connore6eb3f52008-04-13 17:37:41 -040011SRCBOTH=output.c util.c floppy.c ata.c kbd.c pci.c boot.c serial.c clock.c
12SRC16=$(SRCBOTH) disk.c system.c mouse.c cdrom.c apm.c pcibios.c
Kevin O'Connorba2d0df2008-04-13 16:59:03 -040013SRC32=$(SRCBOTH) post.c rombios32.c post_menu.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'Connorba2d0df2008-04-13 16:59:03 -040020COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=3 \
21 -mpreferred-stack-boundary=2 -mrtd \
Kevin O'Connorbc28a2b2008-03-11 19:32:38 -040022 -ffreestanding -fwhole-program -fomit-frame-pointer \
23 -fno-delete-null-pointer-checks
Kevin O'Connor786502d2008-02-27 10:41:41 -050024COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
25COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
26COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
27
28CFLAGS = $(COMMONCFLAGS) -g
Kevin O'Connor410680b2008-03-02 20:48:35 -050029CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables
30CFLAGS16 = $(CFLAGS16INC) -g
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050031
Kevin O'Connor44c631d2008-03-02 11:24:36 -050032TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC)))
Kevin O'Connor59fead62008-05-10 15:49:20 -040033all: $(OUT) $(OUT)bios.bin $(TABLETMP)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050034
35# Run with "make V=1" to see the actual compile commands
36ifdef V
37Q=
38else
39Q=@
40endif
41
42.PHONY : all FORCE
43
44vpath %.c src
45vpath %.S src
46
47################ Build rules
Kevin O'Connor410680b2008-03-02 20:48:35 -050048
49# Do a whole file compile - two methods are supported. The first
50# involves including all the content textually via #include
51# directives. The second method uses gcc's "-combine" option.
52ifdef AVOIDCOMBINE
53DEPHACK=
54define whole-compile
55@echo " Compiling whole program $3"
56$(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c
57$(Q)$(CC) $1 -c $3.tmp.c -o $3
58endef
59else
60# Ugly way to get gcc to generate .d files correctly.
61DEPHACK=-combine src/null.c
62define whole-compile
63@echo " Compiling whole program $3"
64$(Q)$(CC) $1 -combine -c $2 -o $3
65endef
66endif
67
68
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050069$(OUT)%.proc.16.s: $(OUT)%.16.s
70 @echo " Moving data sections to text in $<"
Kevin O'Connord5f1e842008-02-28 20:01:11 -050071 $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050072
73$(OUT)%.16.s: %.c
74 @echo " Generating assembler for $<"
Kevin O'Connor410680b2008-03-02 20:48:35 -050075 $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050076
77$(OUT)%.lds: %.lds.S
78 @echo " Precompiling $<"
79 $(Q)$(CPP) -P $< -o $@
80
81$(OUT)%.bin: $(OUT)%.o
82 @echo " Extracting binary $@"
83 $(Q)objcopy -O binary $< $@
84
85$(OUT)%.offset.auto.h: $(OUT)%.o
86 @echo " Generating symbol offset header $@"
Kevin O'Connor596cf602008-03-01 10:11:55 -050087 $(Q)nm $< | ./tools/defsyms.py $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050088
Kevin O'Connor410680b2008-03-02 20:48:35 -050089$(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050090
Kevin O'Connor44c631d2008-03-02 11:24:36 -050091TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC)))
92$(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050093 @echo " Generating 16bit layout of $@"
94 $(Q)$(CC) $(CFLAGS16) -c $< -o $@
95
96$(OUT)rom16.o: $(OUT)romlayout16.o
97 @echo " Linking $@"
Kevin O'Connorbdce35f2008-02-26 21:33:14 -050098 $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050099
Kevin O'Connor47baa3c2008-03-08 13:17:16 -0500100$(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500101
102$(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds
103 @echo " Linking $@"
104 $(Q)ld -T $(OUT)rombios32.lds $< -o $@
105
Kevin O'Connor59fead62008-05-10 15:49:20 -0400106$(OUT)bios.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500107 @echo " Building $@"
108 $(Q)./tools/buildrom.py
109
110####### Generic rules
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500111clean:
112 rm -rf $(OUT)
113
114$(OUT):
115 mkdir $@
116
117-include $(OUT)*.d