From 103d8572d64db2eda2f4d4e6d28630a5f6bebe52 Mon Sep 17 00:00:00 2001 From: Piotr Czarnecki Date: Sun, 16 Mar 2014 18:26:38 +0100 Subject: [PATCH] Improve build system 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 https://github.com/mozilla/rust/issues/5870. Specified that makefiles should use bash. --- .gitignore | 11 ----------- arch/arm/Makefile | 30 ++++++++++++++++++------------ arch/arm/boot/.gitignore | 11 ++++++++++- 3 files changed, 28 insertions(+), 24 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 2e196fef8d..0000000000 --- a/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -**/boot/*.o -**/boot/*.bc -**/boot/lib*.rlib -**/boot/*.ll - -**/boot/*.elf -**/boot/*.bin -**/boot/*.img -**/boot/*.embed - -**/boot/*.d diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 39ab8f9ec5..017aa4393c 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -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 @@ -20,14 +20,18 @@ 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 @@ -35,18 +39,20 @@ 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) @@ -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)),) @@ -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 diff --git a/arch/arm/boot/.gitignore b/arch/arm/boot/.gitignore index 35c7641984..bb362e4856 100644 --- a/arch/arm/boot/.gitignore +++ b/arch/arm/boot/.gitignore @@ -1,2 +1,11 @@ -core.s +*.d + main.s + +lib*.rlib +*.bc + +*.elf +*.o +*.embed +*.bin