second stage boot loader now loads the main program
[bootcensus] / Makefile
1 csrc = $(wildcard src/*.c) $(wildcard src/libc/*.c)
2 ssrc = $(wildcard src/*.s) $(wildcard src/libc/*.s) $(wildcard src/boot/*.s)
3 obj = $(csrc:.c=.o) $(ssrc:.s=.o)
4 dep = $(obj:.o=.d)
5 elf = test
6 bin = test.bin
7
8 warn = -pedantic -Wall
9 dbg = -g
10 inc = -Isrc -Isrc/libc
11
12 CFLAGS = $(ccarch) -march=i386 $(warn) $(dbg) -nostdinc -fno-builtin $(inc) $(def)
13 ASFLAGS = $(asarch) -march=i386 $(dbg) -nostdinc -fno-builtin $(inc)
14 LDFLAGS = $(ldarch) -T pcboot.ld -print-gc-sections
15
16
17 ifneq ($(shell uname -m), i386)
18         ccarch = -m32
19         asarch = --32
20         ldarch = -m elf_i386
21 endif
22
23 floppy.img: boot.img
24         dd if=/dev/zero of=$@ bs=512 count=2880
25         dd if=$< of=$@ conv=notrunc
26
27 boot.img: bootldr.bin $(bin)
28         cat bootldr.bin $(bin) >$@
29
30 # bootldr.bin will contain only .boot and .boot2
31 bootldr.bin: $(elf)
32         objcopy -O binary -j '.boot*' $< $@
33
34 # the main binary will contain every section *except* .boot and .boot2
35 $(bin): $(elf)
36         objcopy -O binary -R '.boot*' $< $@
37
38 $(elf): $(obj)
39         $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS)
40
41 -include $(dep)
42
43 %.d: %.c
44         @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
45
46 .PHONY: clean
47 clean:
48         rm -f $(obj) $(bin) boot.img floppy.img link.map
49
50 .PHONY: cleandep
51 cleandep:
52         rm -f $(dep)
53
54 .PHONY: disasm
55 disasm: bootldr.disasm $(elf).disasm
56
57 bootldr.disasm: $(elf)
58         objdump -d $< -j .boot -j .boot2 -m i8086 >$@
59
60 $(elf).disasm: $(elf)
61         objdump -d $< -j .startup -j .text -m i386 >$@
62
63 .PHONY: run
64 run: $(bin)
65         qemu-system-i386 -fda floppy.img -serial file:serial.log