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 | 4b60c00 | 2008-02-25 22:29:55 -0500 | [diff] [blame] | 11 | SRC16=floppy.c disk.c system.c clock.c serial.c kbd.c mouse.c output.c boot.c |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 12 | SRC32=post.c output.c |
| 13 | |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame^] | 14 | cc-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'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 17 | # Default compiler flags |
Kevin O'Connor | 786502d | 2008-02-27 10:41:41 -0500 | [diff] [blame^] | 18 | COMMONCFLAGS = -Wall -Os -MD -m32 -march=i386 -mregparm=2 -ffreestanding |
| 19 | COMMONCFLAGS += $(call cc-option,$(CC),-nopie,) |
| 20 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,) |
| 21 | COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,) |
| 22 | |
| 23 | CFLAGS = $(COMMONCFLAGS) -g |
| 24 | CFLAGS16 = $(COMMONCFLAGS) -DMODE16 -fno-jump-tables |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 25 | |
| 26 | all: $(OUT) $(OUT)rom.bin |
| 27 | |
| 28 | # Run with "make V=1" to see the actual compile commands |
| 29 | ifdef V |
| 30 | Q= |
| 31 | else |
| 32 | Q=@ |
| 33 | endif |
| 34 | |
| 35 | .PHONY : all FORCE |
| 36 | |
| 37 | vpath %.c src |
| 38 | vpath %.S src |
| 39 | |
| 40 | ################ Build rules |
| 41 | $(OUT)%.proc.16.s: $(OUT)%.16.s |
| 42 | @echo " Moving data sections to text in $<" |
| 43 | $(Q)sed 's/\t.section\t.rodata.*// ; s/\t.data//' < $< > $@ |
| 44 | |
| 45 | $(OUT)%.16.s: %.c |
| 46 | @echo " Generating assembler for $<" |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 47 | $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $< src/null.c -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 48 | |
| 49 | $(OUT)%.lds: %.lds.S |
| 50 | @echo " Precompiling $<" |
| 51 | $(Q)$(CPP) -P $< -o $@ |
| 52 | |
| 53 | $(OUT)%.bin: $(OUT)%.o |
| 54 | @echo " Extracting binary $@" |
| 55 | $(Q)objcopy -O binary $< $@ |
| 56 | |
| 57 | $(OUT)%.offset.auto.h: $(OUT)%.o |
| 58 | @echo " Generating symbol offset header $@" |
| 59 | $(Q)nm $< | ./tools/defsyms.py > $@ |
| 60 | |
| 61 | $(OUT)blob.16.s: |
| 62 | @echo " Generating whole program assembler $@" |
| 63 | $(Q)$(CC) $(CFLAGS16) -fwhole-program -S -combine -c $(addprefix src/, $(SRC16)) -o $@ |
| 64 | |
| 65 | $(OUT)romlayout16.o: romlayout.S $(OUT)blob.proc.16.s $(OUT)font.proc.16.s $(OUT)cbt.proc.16.s |
| 66 | @echo " Generating 16bit layout of $@" |
| 67 | $(Q)$(CC) $(CFLAGS16) -c $< -o $@ |
| 68 | |
| 69 | $(OUT)rom16.o: $(OUT)romlayout16.o |
| 70 | @echo " Linking $@" |
Kevin O'Connor | bdce35f | 2008-02-26 21:33:14 -0500 | [diff] [blame] | 71 | $(Q)ld -melf_i386 -e post16 -Ttext 0 $< -o $@ |
Kevin O'Connor | f076a3e | 2008-02-25 22:25:15 -0500 | [diff] [blame] | 72 | |
| 73 | $(OUT)rom16.bin: $(OUT)rom16.o |
| 74 | @echo " Extracting binary $@" |
| 75 | $(Q)objcopy -O binary $< $@ |
| 76 | |
| 77 | $(OUT)romlayout32.o: $(OUT)rom16.offset.auto.h |
| 78 | @echo " Compiling whole program $@" |
| 79 | $(Q)$(CC) $(CFLAGS) -fwhole-program -combine -c $(addprefix src/, $(SRC32)) -o $@ |
| 80 | |
| 81 | $(OUT)rom32.o: $(OUT)romlayout32.o $(OUT)rombios32.lds |
| 82 | @echo " Linking $@" |
| 83 | $(Q)ld -T $(OUT)rombios32.lds $< -o $@ |
| 84 | |
| 85 | $(OUT)rom.bin: $(OUT)rom16.bin $(OUT)rom32.bin $(OUT)rom16.offset.auto.h $(OUT)rom32.offset.auto.h |
| 86 | @echo " Building $@" |
| 87 | $(Q)./tools/buildrom.py |
| 88 | |
| 89 | ####### Generic rules |
| 90 | clean: |
| 91 | rm -rf $(OUT) |
| 92 | |
| 93 | $(OUT): |
| 94 | mkdir $@ |
| 95 | |
| 96 | -include $(OUT)*.d |