From fafb42e6b1f0dd3022d33e235a4229060d2b2d1d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 15 Jul 2011 16:12:41 -0700 Subject: [PATCH] Merge the stage1,2,3.mk files into a common definition in stageN.mk, more rearrangement of host/target libs. --- Makefile.in | 92 ++++++++++++------------------------- mk/stage0.mk | 28 +++++++++--- mk/stage1.mk | 51 --------------------- mk/stage2.mk | 46 ------------------- mk/stage3.mk | 45 ------------------- mk/stageN.mk | 97 ++++++++++++++++++++++++++++++++++++++++ src/comp/back/link.rs | 2 +- src/comp/driver/rustc.rs | 2 +- 8 files changed, 149 insertions(+), 214 deletions(-) delete mode 100644 mk/stage1.mk delete mode 100644 mk/stage2.mk delete mode 100644 mk/stage3.mk create mode 100644 mk/stageN.mk diff --git a/Makefile.in b/Makefile.in index bf2a8e0b4184..54a86f4c4426 100644 --- a/Makefile.in +++ b/Makefile.in @@ -108,19 +108,6 @@ X := $(CFG_EXE_SUFFIX) # Look in doc and src dirs. VPATH := $(S)doc $(S)src -# Compilers we build, we now know how to run. -STAGE0 := $(Q)$(call CFG_RUN_TARG,stage0,stage0,\ - stage0/rustc$(X) $(CFG_RUSTC_FLAGS)) -STAGE1 := $(Q)$(call CFG_RUN_TARG,stage1,stage0, \ - $(CFG_VALGRIND_COMPILE) stage1/rustc$(X) \ - $(CFG_RUSTC_FLAGS)) -STAGE2 := $(Q)$(call CFG_RUN_TARG,stage2,stage1, \ - $(CFG_VALGRIND_COMPILE) stage2/rustc$(X) \ - $(CFG_RUSTC_FLAGS)) -STAGE3 := $(Q)$(call CFG_RUN_TARG,stage3,stage2, \ - $(CFG_VALGRIND_COMPILE) stage3/rustc$(X) \ - $(CFG_RUSTC_FLAGS)) - # "Source" files we generate in builddir along the way. GENERATED := @@ -147,19 +134,6 @@ COMPILER_CRATE := $(S)src/comp/rustc.rc COMPILER_INPUTS := $(wildcard $(addprefix $(S)src/comp/, \ rustc.rc *.rs */*.rs */*/*.rs)) -###################################################################### -# Main target dependency variables -###################################################################### - -LREQ := rt/$(CFG_RUNTIME) rustllvm/$(CFG_RUSTLLVM) -SREQ0 := stage0/rustc$(X) $(LREQ) rt/main.o stage0/lib/glue.o \ - stage0/lib/$(CFG_STDLIB) -SREQ1 := stage1/rustc$(X) $(LREQ) rt/main.o stage1/lib/glue.o \ - stage1/lib/$(CFG_STDLIB) -SREQ2 := stage2/rustc$(X) $(LREQ) rt/main.o stage2/lib/glue.o \ - stage2/lib/$(CFG_STDLIB) - - ###################################################################### # Exports for sub-utilities ###################################################################### @@ -178,7 +152,32 @@ LLVM_AS := $(CFG_LLVM_BINDIR)/llvm-as$(X) LLC := $(CFG_LLVM_BINDIR)/llc$(X) ###################################################################### -# Single-target rules +# Per-stage targets and runner +###################################################################### + +define SREQ +SREQ$(1) = stage$(1)/rustc$(X) \ + stage$(1)/$$(CFG_RUNTIME) \ + stage$(1)/$$(CFG_STDLIB) \ + stage$(1)/$$(CFG_RUSTLLVM) \ + stage$(1)/lib/glue.o \ + stage$(1)/lib/main.o \ + stage$(1)/lib/$$(CFG_RUNTIME) \ + stage$(1)/lib/$$(CFG_STDLIB) \ + $$(MKFILES) + +STAGE$(1) := $$(Q)$$(call CFG_RUN_TARG,stage$(1),stage$(1), \ + $$(CFG_VALGRIND_COMPILE) stage$(1)/rustc$$(X) \ + $$(CFG_RUSTC_FLAGS)) +endef + +$(eval $(call SREQ,0)) +$(eval $(call SREQ,1)) +$(eval $(call SREQ,2)) +$(eval $(call SREQ,3)) + +###################################################################### +# Entrypoint rule ###################################################################### ifneq ($(CFG_IN_TRANSITION),) @@ -188,40 +187,9 @@ CFG_INFO := $(info cfg: *** compiler is in snapshot transition ***) CFG_INFO := $(info cfg: *** stage2 and later will not be built ***) CFG_INFO := $(info cfg:) -all: rt/$(CFG_RUNTIME) \ - rustllvm/$(CFG_RUSTLLVM) \ - stage0/lib/$(CFG_STDLIB) \ - stage0/intrinsics.bc \ - stage0/rustc$(X) \ - $(GENERATED) \ - $(DOCS) \ - stage1/lib/$(CFG_STDLIB) \ - stage1/intrinsics.bc \ - stage1/lib/glue.o \ - stage1/rustc$(X) \ - +all: $(SREQ0) $(SREQ1) $(GENERATED) $(DOCS) else - -all: rt/$(CFG_RUNTIME) \ - rustllvm/$(CFG_RUSTLLVM) \ - stage0/lib/$(CFG_STDLIB) \ - stage0/intrinsics.bc \ - stage0/rustc$(X) \ - $(GENERATED) \ - $(DOCS) \ - stage1/lib/$(CFG_STDLIB) \ - stage1/intrinsics.bc \ - stage1/lib/glue.o \ - stage1/rustc$(X) \ - stage2/lib/$(CFG_STDLIB) \ - stage2/intrinsics.bc \ - stage2/lib/glue.o \ - stage2/rustc$(X) \ - stage3/lib/$(CFG_STDLIB) \ - stage3/lib/glue.o \ - stage3/intrinsics.bc \ - stage3/rustc$(X) - +all: $(SREQ0) $(SREQ1) $(SREQ2) $(SREQ3) $(GENERATED) $(DOCS) endif @@ -240,9 +208,7 @@ config.mk: $(S)configure $(S)Makefile.in $(S)src/snapshots.txt include $(CFG_SRC_DIR)/mk/intrinsics.mk include $(CFG_SRC_DIR)/mk/stage0.mk -include $(CFG_SRC_DIR)/mk/stage1.mk -include $(CFG_SRC_DIR)/mk/stage2.mk -include $(CFG_SRC_DIR)/mk/stage3.mk +include $(CFG_SRC_DIR)/mk/stageN.mk include $(CFG_SRC_DIR)/mk/rt.mk include $(CFG_SRC_DIR)/mk/rustllvm.mk include $(CFG_SRC_DIR)/mk/autodep.mk diff --git a/mk/stage0.mk b/mk/stage0.mk index 658ae63f4f59..c01b8045e132 100644 --- a/mk/stage0.mk +++ b/mk/stage0.mk @@ -3,19 +3,33 @@ stage0/rustc$(X): $(S)src/snapshots.txt $(S)src/etc/get-snapshot.py $(MKFILES) $(Q)$(S)src/etc/get-snapshot.py $(Q)touch $@ -# These two will be made in the process of making rustc above. +# Host libs will be made in the process of making rustc above. -stage0/lib/glue.o: stage0/rustc$(X) - $(Q)touch $@ +# FIXME: temporary hack: the first two are currently carried in +# lib/ directory only, so we copy them out. -stage0/lib/$(CFG_STDLIB): stage0/rustc$(X) - $(Q)touch $@ +stage0/$(CFG_RUNTIME): stage0/lib/$(CFG_RUNTIME) + $(Q)cp $< $@ -stage0/intrinsics.bc: stage0/rustc$(X) - $(Q)touch $@ +stage0/$(CFG_STDLIB): stage0/lib/$(CFG_STDLIB) + $(Q)cp $< $@ stage0/$(CFG_RUSTLLVM): stage0/rustc$(X) $(Q)touch $@ +# Target libs will be made in the process of making rustc above. + +stage0/lib/glue.o: stage0/rustc$(X) + $(Q)touch $@ + +# FIXME: temporary hack: currently not distributing main.o like we should; +# copying from rt + +stage0/lib/main.o: rt/main.o + $(Q)cp $< $@ + stage0/lib/$(CFG_RUNTIME): stage0/rustc$(X) $(Q)touch $@ + +stage0/lib/$(CFG_STDLIB): stage0/rustc$(X) + $(Q)touch $@ diff --git a/mk/stage1.mk b/mk/stage1.mk deleted file mode 100644 index fb6bbf80c46c..000000000000 --- a/mk/stage1.mk +++ /dev/null @@ -1,51 +0,0 @@ -stage1/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage1/rustc$(X) stage0/lib/$(CFG_STDLIB) stage1/intrinsics.bc \ - stage1/lib/$(CFG_RUNTIME) stage1/$(CFG_RUSTLLVM) \ - stage1/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE1) --lib -o $@ $< - -stage1/lib/libstd.rlib: $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage1/rustc$(X) stage0/lib/$(CFG_STDLIB) stage1/intrinsics.bc \ - stage1/lib/$(CFG_RUNTIME) stage1/$(CFG_RUSTLLVM) \ - stage1/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE1) --lib --static -o $@ $< - -stage1/lib/glue.o: stage1/rustc$(X) stage0/lib/$(CFG_STDLIB) \ - stage1/intrinsics.bc stage1/$(CFG_RUSTLLVM) \ - stage0/lib/$(CFG_RUNTIME) - @$(call E, generate: $@) - $(STAGE1) -c -o $@ --glue - -stage1/intrinsics.bc: $(INTRINSICS_BC) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage1/lib/$(CFG_RUNTIME): rt/$(CFG_RUNTIME) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage1/$(CFG_RUSTLLVM): rustllvm/$(CFG_RUSTLLVM) - @$(call E, cp: $@) - $(Q)cp $< $@ - -# Due to make not wanting to run the same implicit rules twice on the same -# rule tree (implicit-rule recursion prevention, see "Chains of Implicit -# Rules" in GNU Make manual) we have to re-state the %.o and %.s patterns here -# for different directories, to handle cases where (say) a test relies on a -# compiler that relies on a .o file. - -stage1/%.o: stage1/%.s - @$(call E, assemble [gcc]: $@) - $(Q)gcc $(CFG_GCCISH_CFLAGS) -o $@ -c $< - -stage1/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ0) \ - stage0/intrinsics.bc - @$(call E, compile_and_link: $@) - $(STAGE0) -o $@ $< - -stage1/lib/$(CFG_LIBRUSTC): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ1) \ - stage1/intrinsics.bc - @$(call E, compile_and_link: $@) - $(STAGE1) --lib -o $@ $< diff --git a/mk/stage2.mk b/mk/stage2.mk deleted file mode 100644 index c259f334f522..000000000000 --- a/mk/stage2.mk +++ /dev/null @@ -1,46 +0,0 @@ -stage2/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage2/rustc$(X) stage1/lib/$(CFG_STDLIB) stage2/intrinsics.bc \ - stage2/lib/$(CFG_RUNTIME) stage2/$(CFG_RUSTLLVM) \ - stage2/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE2) --lib -o $@ $< - -stage2/lib/libstd.rlib: $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage2/rustc$(X) stage1/lib/$(CFG_STDLIB) stage2/intrinsics.bc \ - stage2/lib/$(CFG_RUNTIME) stage2/$(CFG_RUSTLLVM) \ - stage2/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE2) --lib --static -o $@ $< - -stage2/lib/glue.o: stage2/rustc$(X) stage1/lib/$(CFG_STDLIB) \ - stage2/intrinsics.bc stage2/$(CFG_RUSTLLVM) \ - stage1/lib/$(CFG_RUNTIME) - @$(call E, generate: $@) - $(STAGE2) -c -o $@ --glue - -stage2/intrinsics.bc: $(INTRINSICS_BC) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage2/lib/$(CFG_RUNTIME): rt/$(CFG_RUNTIME) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage2/$(CFG_RUSTLLVM): rustllvm/$(CFG_RUSTLLVM) - @$(call E, cp: $@) - $(Q)cp $< $@ - -# Due to make not wanting to run the same implicit rules twice on the same -# rule tree (implicit-rule recursion prevention, see "Chains of Implicit -# Rules" in GNU Make manual) we have to re-state the %.o and %.s patterns here -# for different directories, to handle cases where (say) a test relies on a -# compiler that relies on a .o file. - -stage2/%.o: stage2/%.s - @$(call E, assemble [gcc]: $@) - $(Q)gcc $(CFG_GCCISH_CFLAGS) -o $@ -c $< - -stage2/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ1) \ - stage1/intrinsics.bc - @$(call E, compile_and_link: $@) - $(STAGE1) -o $@ $< diff --git a/mk/stage3.mk b/mk/stage3.mk deleted file mode 100644 index dc3102712838..000000000000 --- a/mk/stage3.mk +++ /dev/null @@ -1,45 +0,0 @@ -stage3/lib/$(CFG_STDLIB): $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage3/rustc$(X) stage2/lib/$(CFG_STDLIB) stage3/intrinsics.bc \ - stage3/lib/$(CFG_RUNTIME) stage3/$(CFG_RUSTLLVM) \ - stage3/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE3) --lib -o $@ $< - -stage3/lib/libstd.rlib: $(STDLIB_CRATE) $(STDLIB_INPUTS) \ - stage3/rustc$(X) stage2/lib/$(CFG_STDLIB) stage3/intrinsics.bc \ - stage3/lib/$(CFG_RUNTIME) stage3/$(CFG_RUSTLLVM) \ - stage3/lib/glue.o $(LREQ) $(MKFILES) - @$(call E, compile_and_link: $@) - $(STAGE3) --lib --static -o $@ $< - -stage3/lib/glue.o: stage3/rustc$(X) stage2/lib/$(CFG_STDLIB) \ - stage3/intrinsics.bc stage3/$(CFG_RUSTLLVM) \ - stage2/lib/$(CFG_RUNTIME) - @$(call E, generate: $@) - $(STAGE3) -c -o $@ --glue - -stage3/intrinsics.bc: $(INTRINSICS_BC) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage3/lib/$(CFG_RUNTIME): rt/$(CFG_RUNTIME) - @$(call E, cp: $@) - $(Q)cp $< $@ - -stage3/$(CFG_RUSTLLVM): rustllvm/$(CFG_RUSTLLVM) - @$(call E, cp: $@) - $(Q)cp $< $@ - -# Due to make not wanting to run the same implicit rules twice on the same -# rule tree (implicit-rule recursion prevention, see "Chains of Implicit -# Rules" in GNU Make manual) we have to re-state the %.o and %.s patterns here -# for different directories, to handle cases where (say) a test relies on a -# compiler that relies on a .o file. - -stage3/%.o: stage3/%.s - @$(call E, assemble [gcc]: $@) - $(Q)gcc $(CFG_GCCISH_CFLAGS) -o $@ -c $< - -stage3/rustc$(X): $(COMPILER_CRATE) $(COMPILER_INPUTS) $(SREQ2) stage2/intrinsics.bc - @$(call E, compile_and_link: $@) - $(STAGE2) -o $@ $< diff --git a/mk/stageN.mk b/mk/stageN.mk new file mode 100644 index 000000000000..48aee68b45e8 --- /dev/null +++ b/mk/stageN.mk @@ -0,0 +1,97 @@ +# StageN template: arg 1 is the N we're building *from*, arg 2 is N+1. +# +# The easiest way to read this template is to assume we're building stage2 +# using stage1, and mentally gloss $(1) as 1, $(2) as 2. + +define STAGEN + +# Host libraries and executables (stage$(2)/rustc and its runtime needs) +# +# NB: Due to make not wanting to run the same implicit rules twice on the same +# rule tree (implicit-rule recursion prevention, see "Chains of Implicit +# Rules" in GNU Make manual) we have to re-state the %.o and %.s patterns here +# for different directories, to handle cases where (say) a test relies on a +# compiler that relies on a .o file. + +STAGE$(2) := $$(Q)$$(call CFG_RUN_TARG,stage$(2),stage$(1), \ + $$(CFG_VALGRIND_COMPILE) stage$(2)/rustc$$(X) \ + $$(CFG_RUSTC_FLAGS)) + +stage$(2)/%.o: stage$(2)/%.s + @$$(call E, assemble [gcc]: $$@) + $$(Q)gcc $$(CFG_GCCISH_CFLAGS) -o $$@ -c $$< + +stage$(2)/rustc$$(X): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \ + stage$(2)/$$(CFG_RUNTIME) \ + stage$(2)/$$(CFG_STDLIB) \ + stage$(2)/$$(CFG_RUSTLLVM) \ + $$(SREQ$(1)) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(1)) -L stage$(2) -o $$@ $$< + +stage$(2)/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +stage$(2)/$$(CFG_STDLIB): stage$(1)/lib/$$(CFG_STDLIB) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +stage$(2)/$$(CFG_RUSTLLVM): rustllvm/$$(CFG_RUSTLLVM) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + + +# Target libraries (for binaries generated by stage$(2)/rustc) + +stage$(2)/lib/intrinsics.bc: $$(INTRINSICS_BC) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +stage$(2)/lib/glue.o: stage$(2)/rustc$$(X) \ + stage$(2)/$$(CFG_RUNTIME) \ + stage$(2)/$$(CFG_RUSTLLVM) \ + stage$(2)/lib/intrinsics.bc \ + $$(SREQ$(1)) + @$$(call E, generate: $$@) + $$(STAGE$(2)) -c -o $$@ --glue + +stage$(2)/lib/$$(CFG_STDLIB): $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \ + stage$(2)/rustc$$(X) \ + stage$(2)/$$(CFG_RUNTIME) \ + stage$(2)/$$(CFG_RUSTLLVM) \ + stage$(2)/lib/glue.o \ + $$(SREQ$(1)) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(2)) --lib -o $$@ $$< + +stage$(2)/lib/libstd.rlib: $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \ + stage$(2)/rustc$$(X) \ + stage$(2)/$$(CFG_RUNTIME) \ + stage$(2)/$$(CFG_RUSTLLVM) \ + stage$(2)/lib/glue.o \ + $$(SREQ$(1)) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(2)) --lib --static -o $$@ $$< + + +stage$(2)/lib/main.o: rt/main.o + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +stage$(2)/lib/$$(CFG_RUNTIME): rt/$$(CFG_RUNTIME) + @$$(call E, cp: $$@) + $$(Q)cp $$< $$@ + +stage$(2)/lib/$$(CFG_LIBRUSTC): $$(COMPILER_CRATE) $$(COMPILER_INPUTS) \ + $$(SREQ$(2)) + @$$(call E, compile_and_link: $$@) + $$(STAGE$(2)) --lib -o $$@ $$< + +endef + +# Instantiate template for 0->1, 1->2, 2->3 build dirs + +$(eval $(call STAGEN,0,1)) +$(eval $(call STAGEN,1,2)) +$(eval $(call STAGEN,2,3)) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index aa0f71ff8e29..ab9f47e3cc02 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -41,7 +41,7 @@ fn llvm_err(session::session sess, str msg) { } fn link_intrinsics(session::session sess, ModuleRef llmod) { - auto path = fs::connect(sess.get_opts().sysroot, "intrinsics.bc"); + auto path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc"); auto membuf = llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(str::buf(path)); if (membuf as uint == 0u) { diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 9d195c44ada6..b810fbecc729 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -508,7 +508,7 @@ fn main(vec[str] args) { } let str glu = binary_dir + "/lib/glue.o"; - let str main = "rt/main.o"; + let str main = binary_dir + "/lib/main.o"; let str stage = "-L" + binary_dir + "/lib"; let str prog = "gcc"; // The invocations of gcc share some flags across platforms