forked from haileys/rustboot
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMakefile
67 lines (46 loc) · 1.47 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
CC=gcc -m32
LD=ld
RUSTC := rustc --cfg libc -Z no-landing-pads -O --target i386-intel-linux
NASM=nasm
QEMU=qemu-system-i386
BUILDDIR=./build
PROGDIR=./src/programs
OBJDIR=$(BUILDDIR)/obj
OBJS := $(OBJDIR)/runtime.asm.o $(OBJDIR)/main.o $(OBJDIR)/isr_wrapper.asm.o
PROGRAMS = $(BUILDDIR)/programs/do-nothing.o
all: $(BUILDDIR)/floppy.img
.SUFFIXES:
.SUFFIXES: .o .rs .asm
.PHONY: clean run
$(OBJDIR)/%.asm.o: src/%.asm
mkdir -p $(OBJDIR)
$(NASM) -f elf32 -o $@ $<
$(OBJDIR)/main.bc: src/main.rs
mkdir -p $(OBJDIR)
$(RUSTC) src/rust-core/core/lib.rs --out-dir $(BUILDDIR)
$(RUSTC) --lib --emit-llvm -L $(BUILDDIR) -o $@ $<
$(OBJDIR)/main.o: $(OBJDIR)/main.bc
clang -c -O2 -o $@ $<
$(BUILDDIR)/loader.bin: src/loader.asm
mkdir -p $(BUILDDIR)
$(NASM) -o $@ -f bin $<
$(BUILDDIR)/main.elf: src/linker.ld $(OBJS) $(PROGRAMS)
mkdir -p $(BUILDDIR)
$(LD) -Map=$(BUILDDIR)/linker.map -o $@ -T $^ "-(" build/libcore-2e829c2f-0.0.rlib "-)"
$(BUILDDIR)/main.bin: $(BUILDDIR)/main.elf
mkdir -p $(BUILDDIR)
objcopy -O binary $< $@
$(BUILDDIR)/floppy.img: $(BUILDDIR)/loader.bin $(BUILDDIR)/main.bin
cat $^ > $@
run: $(BUILDDIR)/floppy.img
$(QEMU) -serial stdio -fda $<
debug: $(BUILDDIR)/floppy.img
$(QEMU) -monitor stdio -fda $<
clean:
-rm -rf $(BUILDDIR)
$(BUILDDIR)/programs/%: $(PROGDIR)/%.c
mkdir -p $(BUILDDIR)/programs
$(CC) -static -nostdlib -o $@ $<
$(BUILDDIR)/programs/%.o: $(BUILDDIR)/programs/%
objcopy -B i386 -I binary -O elf32-i386 $< $@
test: $(PROGDIR)/do-nothing.o