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