Skip to content

Commit

Permalink
Improve build system
Browse files Browse the repository at this point in the history
ARM target works except dependency info.

Moved .gitignore from project root to build directories.
Makefile reads patterns specified in gitignore to find
all output files and remove them with the help of `find` and
`xargs`.
Do not overwrite dep info. Using `sed` to remove some dependency info.
See http://stackoverflow.com/a/9054420
and rust-lang/rust#5870.
Specified that makefiles should use bash.
  • Loading branch information
pczarn committed Mar 25, 2014
1 parent 7ab5c87 commit 103d857
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
11 changes: 0 additions & 11 deletions .gitignore

This file was deleted.

30 changes: 18 additions & 12 deletions arch/arm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AS := $(GCC_PREFIX)as
LD := $(GCC_PREFIX)ld

LLC := $(LLVM_ROOT)/bin/llc
LLCFLAGS := -march=arm -mcpu=arm926ej-s --float-abi=hard -asm-verbose
LLCFLAGS := -mtriple=$(TARGET) -march=arm -mcpu=arm926ej-s --float-abi=hard -asm-verbose

GDB := $(GCC_PREFIX)gdb
OBJCOPY := $(GCC_PREFIX)objcopy
Expand All @@ -20,33 +20,39 @@ QEMUFLAGS := -M versatilepb -m 32M -serial stdio
BDIR := ./boot
CORE_LIB := ../../rust-core/core/lib.rs
LCORE := $(BDIR)/$(shell $(RUSTC) --crate-file-name $(CORE_LIB))

OBJS := $(BDIR)/loader.o $(BDIR)/aeabi_runtime.o $(BDIR)/main.o $(BDIR)/core.o
LINK := $(BDIR)/linker.ld $(OBJS)

MODS := $(wildcard */*.rs) $(wildcard ../../kernel/*.rs) $(wildcard ../../kernel/*/*.rs) $(wildcard ../../kernel/*/*/*.rs)
# Remove dependencies of other targets. Currently not useful for one target.
DEP_RM := arch\/
DEP_KEEP := arch\/arm
DEP_SCRIPT := 's/\($(DEP_KEEP)\)/\n\1/g;s/ \S*$(DEP_RM)\S*//g;s/\n\($(DEP_KEEP)\)/\1/g'

-include ./config.mk
-include $(BDIR)/core.d
-include $(BDIR)/loader.d
-include $(BDIR)/main.d

.PHONY: all run debug clean

all: $(BDIR)/kernel.bin
@wc -c $^

# Library rust-core
$(LCORE):
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/core.d $(CORE_LIB) --emit=bc,link --out-dir $(BDIR)
$(LCORE) $(BDIR)/core.bc:
$(RUSTC) $(RUSTCFLAGS) $(CORE_LIB) --dep-info --emit=bc,link --out-dir $(BDIR)

# Compile rustboot
$(BDIR)/main.bc: ../../lib.rs $(MODS) $(LCORE)
$(RUSTC) $(RUSTCFLAGS) --dep-info $(@D)/main.d -L $(BDIR) --emit=bc ../../lib.rs --out-dir $(BDIR)
# Compile rustboot. Produce dependency info
$(BDIR)/main.bc: $(LCORE)
$(RUSTC) $(RUSTCFLAGS) -L $(BDIR) --dep-info --emit=bc ../../lib.rs --out-dir $(BDIR)
@sed -i $(DEP_SCRIPT) $(BDIR)/main.d

%.s: %.bc
$(LLC) $(LLCFLAGS) $^ -o $@

# Assemble object files. note: do not overwrite deps with -MD $*.d
%.o: %.s
$(AS) -MD $*.d -g $< -o $@
$(AS) -g $< -o $@

# kernel (object)
$(BDIR)/kernel.elf: $(LINK)
Expand All @@ -57,8 +63,8 @@ $(BDIR)/kernel.bin: $(BDIR)/kernel.elf
$(OBJCOPY) -O binary $^ $@

# running
run: $(BDIR)/kernel.bin
$(QEMU) $(QEMUFLAGS) -kernel $^
run: all
$(QEMU) $(QEMUFLAGS) -kernel $(BDIR)/kernel.bin

debug: $(BDIR)/kernel.elf
ifeq ($(strip $(TMUX)),)
Expand All @@ -74,4 +80,4 @@ else
endif

clean:
rm -f $(BDIR)/*.{d,o,bc,rlib,so,ll,embed,elf,bin}
@cat $(BDIR)/.gitignore | xargs -I{} find $(BDIR) -name {} | xargs rm -f
11 changes: 10 additions & 1 deletion arch/arm/boot/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
core.s
*.d

main.s

lib*.rlib
*.bc

*.elf
*.o
*.embed
*.bin

0 comments on commit 103d857

Please sign in to comment.