Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 1 | # 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 |
| 8 | OUT=out/ |
| 9 | |
| 10 | # Source files |
Kevin O'Connor | 3491e8b | 2008-02-29 00:22:27 -0500 | [diff] [blame] | 11 | SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c \ |
| 12 | boot.c ata.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 13 | SRC32=post.c output.c |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 14 | TABLESRC=font.c cbt.c floppy_dbt.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 15 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 16 | cc-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'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 19 | # Default compiler flags |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 20 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 \ |
| 21 | -ffreestanding -fwhole-program |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame] | 22 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 23 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 24 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 25 | |
| 26 | CFLAGS = $(COMMONCFLAGS) -g |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 27 | CFLAGS16INC = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables |
| 28 | CFLAGS16 = $(CFLAGS16INC) -g |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 29 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 30 | TABLETMP=$(addprefix $(OUT), $(patsubst %.c,%.16.s,$(TABLESRC))) |
| 31 | all: $(OUT) $(OUT)rom.bin $(TABLETMP) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 32 | |
| 33 | # Run with "make V=1" to see the actual compile commands |
| 34 | ifdef V |
| 35 | Q= |
| 36 | else |
| 37 | Q=@ |
| 38 | endif |
| 39 | |
| 40 | .PHONY : all FORCE |
| 41 | |
| 42 | vpath %.c src |
| 43 | vpath %.S src |
| 44 | |
| 45 | ################ Build rules |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 46 | |
| 47 | # Do a whole file compile - two methods are supported. The first |
| 48 | # involves including all the content textually via #include |
| 49 | # directives. The second method uses gcc's "-combine" option. |
| 50 | ifdef AVOIDCOMBINE |
| 51 | DEPHACK= |
| 52 | define whole-compile |
| 53 | @echo " Compiling whole program $3" |
| 54 | $(Q)/bin/echo -e '$(foreach i,$2,#include "../$i"\n)' > $3.tmp.c |
| 55 | $(Q)$(CC) $1 -c $3.tmp.c -o $3 |
| 56 | endef |
| 57 | else |
| 58 | # Ugly way to get gcc to generate .d files correctly. |
| 59 | DEPHACK=-combine src/null.c |
| 60 | define whole-compile |
| 61 | @echo " Compiling whole program $3" |
| 62 | $(Q)$(CC) $1 -combine -c $2 -o $3 |
| 63 | endef |
| 64 | endif |
| 65 | |
| 66 | |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 67 | $(OUT)%.proc.16.s: $(OUT)%.16.s |
| 68 | @echo " Moving data sections to text in $<" |
Kevin O'Connor | d5f1e84 | 2008-02-28 20:01:11 -0500 | [diff] [blame] | 69 | $(Q)sed 's/\t\.section\t\.rodata.*// ; s/\t\.data//' < $< > $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 70 | |
| 71 | $(OUT)%.16.s: %.c |
| 72 | @echo " Generating assembler for $<" |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 73 | $(Q)$(CC) $(CFLAGS16INC) $(DEPHACK) -S -c $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 74 | |
| 75 | $(OUT)%.lds: %.lds.S |
| 76 | @echo " Precompiling $<" |
| 77 | $(Q)$(CPP) -P $< -o $@ |
| 78 | |
| 79 | $(OUT)%.bin: $(OUT)%.o |
| 80 | @echo " Extracting binary $@" |
| 81 | $(Q)objcopy -O binary $< $@ |
| 82 | |
| 83 | $(OUT)%.offset.auto.h: $(OUT)%.o |
| 84 | @echo " Generating symbol offset header $@" |
Kevin O'Connor | 596cf60 | 2008-03-01 10:11:55 -0500 | [diff] [blame] | 85 | $(Q)nm $< | ./tools/defsyms.py $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 86 | |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 87 | $(OUT)blob.16.s: ; $(call whole-compile, $(CFLAGS16) -S, $(addprefix src/, $(SRC16)),$@) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 88 | |
Kevin O'Connor | 44c631d | 2008-03-02 11:24:36 -0500 | [diff] [blame] | 89 | TABLEASM=$(addprefix $(OUT), $(patsubst %.c,%.proc.16.s,$(TABLESRC))) |
| 90 | $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(TABLEASM) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 91 | @echo " Generating 16bit layout of $@" |
| 92 | $(Q)$(CC) $(CFLAGS16) -c $< -o $@ |
| 93 | |
| 94 | $(OUT)rom16.o: $(OUT)romlayout16.o |
| 95 | @echo " Linking $@" |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 96 | $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 97 | |
| 98 | $(OUT)rom16.bin: $(OUT)rom16.o |
| 99 | @echo " Extracting binary $@" |
| 100 | $(Q)objcopy -O binary $< $@ |
| 101 | |
Kevin O'Connor | 410680b | 2008-03-02 20:48:35 -0500 | [diff] [blame^] | 102 | $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h ; $(call whole-compile, $(CFLAGS), $(addprefix src/, $(SRC32)),$@) |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 103 | |
| 104 | $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds |
| 105 | @echo " Linking $@" |
| 106 | $(Q)ld -T $(OUT)rombios32.lds $< -o $@ |
| 107 | |
| 108 | $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h |
| 109 | @echo " Building $@" |
| 110 | $(Q)./tools/buildrom.py |
| 111 | |
| 112 | ####### Generic rules |
| 113 | clean: |
| 114 | rm -rf $(OUT) |
| 115 | |
| 116 | $(OUT): |
| 117 | mkdir $@ |
| 118 | |
| 119 | -include $(OUT)*.d |