moving some standard library functions to assembly
[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 Ssrc = $(wildcard src/*.S)
4 obj = $(csrc:.c=.o) $(ssrc:.s=.o) $(Ssrc:.S=.o)
5 dep = $(obj:.o=.d)
6 elf = test
7 bin = test.bin
8
9 warn = -pedantic -Wall
10 #opt = -O2
11 dbg = -g
12 inc = -Isrc -Isrc/libc
13 gccopt = -fno-pic -ffreestanding -nostdinc -fno-builtin
14
15 CFLAGS = $(ccarch) -march=i386 $(warn) $(opt) $(dbg) $(gccopt) $(inc) $(def)
16 ASFLAGS = $(asarch) -march=i386 $(dbg) -nostdinc -fno-builtin $(inc)
17 LDFLAGS = $(ldarch) -nostdlib -T pcboot.ld -print-gc-sections
18
19
20 ifneq ($(shell uname -m), i386)
21         ccarch = -m32
22         asarch = --32
23         ldarch = -m elf_i386
24 endif
25
26 floppy.img: boot.img
27         dd if=/dev/zero of=$@ bs=512 count=2880
28         dd if=$< of=$@ conv=notrunc
29
30 boot.img: bootldr.bin $(bin)
31         cat bootldr.bin $(bin) >$@
32
33 # bootldr.bin will contain only .boot and .boot2
34 bootldr.bin: $(elf)
35         objcopy -O binary -j '.boot*' $< $@
36
37 # the main binary will contain every section *except* .boot and .boot2
38 $(bin): $(elf)
39         objcopy -O binary -R '.boot*' $< $@
40
41 $(elf): $(obj)
42         $(LD) -o $@ $(obj) -Map link.map $(LDFLAGS)
43
44 %.o: %.S
45         $(CC) -o $@ $(CFLAGS) -c $<
46
47 -include $(dep)
48
49 %.d: %.c
50         @$(CPP) $(CFLAGS) $< -MM -MT $(@:.d=.o) >$@
51
52 .PHONY: clean
53 clean:
54         rm -f $(obj) $(bin) boot.img floppy.img link.map
55
56 .PHONY: cleandep
57 cleandep:
58         rm -f $(dep)
59
60 .PHONY: disasm
61 disasm: bootldr.disasm $(elf).disasm
62
63 bootldr.disasm: $(elf)
64         objdump -d $< -j .boot -j .boot2 -m i8086 >$@
65
66 $(elf).disasm: $(elf)
67         objdump -d $< -j .startup -j .text -m i386 >$@
68
69 $(elf).sym: $(elf)
70         objcopy --only-keep-debug $< $@
71
72 .PHONY: run
73 run: $(bin)
74         qemu-system-i386 -fda floppy.img -serial file:serial.log
75
76 .PHONY: debug
77 debug: $(bin) $(elf).sym
78         qemu-system-i386 -fda floppy.img -serial file:serial.log -s -S
79
80 .PHONY: sym
81 sym: $(elf).sym