From 31f4b63dffb49e65d3de4ecbef573e15b0f44e36 Mon Sep 17 00:00:00 2001 From: Michael Sullivan Date: Wed, 13 Jun 2012 15:27:07 -0700 Subject: [PATCH] Update the build system to handle dependency on header files. Closes #2547. --- mk/platform.mk | 14 +++++++++----- mk/rt.mk | 19 +++++-------------- mk/rustllvm.mk | 2 ++ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/mk/platform.mk b/mk/platform.mk index 61526f1f559..1a487ca80d8 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -214,14 +214,16 @@ ifeq ($(CFG_C_COMPILER),clang) endif CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g CFG_GCCISH_LINK_FLAGS += -g - CFG_DEPEND_C = $(CFG_GCCISH_CROSS)$(CXX) $(CFG_GCCISH_CFLAGS) -MT "$(1)" \ - -MM $(2) + # These flags will cause the compiler to produce a .d file + # next to the .o file that lists header deps. + CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d) define CFG_MAKE_CC CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ $$(CFG_GCCISH_CFLAGS) $$(CFG_CLANG_CFLAGS) \ $$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \ $$(CFG_CLANG_CFLAGS_$$(HOST_$(1))) \ + $$(CFG_DEPEND_FLAGS) \ -c -o $$(1) $$(2) CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ @@ -245,8 +247,9 @@ ifeq ($(CFG_C_COMPILER),gcc) endif CFG_GCCISH_CFLAGS += -Wall -Werror -fno-rtti -g CFG_GCCISH_LINK_FLAGS += -g - CFG_DEPEND_C = $(CFG_GCCISH_CROSS)$(CXX) $(CFG_GCCISH_CFLAGS) -MT "$(1)" \ - -MM $(2) + # These flags will cause the compiler to produce a .d file + # next to the .o file that lists header deps. + CFG_DEPEND_FLAGS = -MMD -MP -MT $(1) -MF $(1:%.o=%.d) define CFG_MAKE_CC CFG_COMPILE_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ @@ -254,6 +257,7 @@ ifeq ($(CFG_C_COMPILER),gcc) $$(CFG_GCCISH_CFLAGS_$$(HOST_$(1))) \ $$(CFG_GCC_CFLAGS) \ $$(CFG_GCC_CFLAGS_$$(HOST_$(1))) \ + $$(CFG_DEPEND_FLAGS) \ -c -o $$(1) $$(2) CFG_LINK_C_$(1) = $$(CFG_GCCISH_CROSS)$$(CXX) \ $$(CFG_GCCISH_LINK_FLAGS) -o $$(1) \ @@ -272,7 +276,7 @@ endif # We're using llvm-mc as our assembler because it supports # .cfi pseudo-ops on mac define CFG_MAKE_ASSEMBLER - CFG_ASSEMBLE_$(1)=$$(CPP) $$(2) | \ + CFG_ASSEMBLE_$(1)=$$(CPP) $$(CFG_DEPEND_FLAGS) $$(2) | \ $$(LLVM_MC_$$(CFG_HOST_TRIPLE)) \ -assemble \ -filetype=obj \ diff --git a/mk/rt.mk b/mk/rt.mk index cd382267301..7f5d024079e 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -79,17 +79,6 @@ RUNTIME_S_$(1) := rt/arch/$$(HOST_$(1))/_context.S \ rt/arch/$$(HOST_$(1))/ccall.S \ rt/arch/$$(HOST_$(1))/record_sp.S -RUNTIME_HDR_$(1) := $$(wildcard \ - rt/*.h \ - rt/bigint/*.h \ - rt/isaac/*.h \ - rt/msvc/*.h \ - rt/sync/*.h \ - rt/uthash/*.h \ - rt/util/*.h \ - rt/vg/*.h \ - rt/arch/$$(HOST_$(1))/*.h) - ifeq ($$(HOST_$(1)), i386) LIBUV_ARCH_$(1) := ia32 else @@ -116,14 +105,17 @@ RUNTIME_INCS_$(1) := -I $$(S)src/rt -I $$(S)src/rt/isaac -I $$(S)src/rt/uthash \ -I $$(S)src/libuv/include RUNTIME_OBJS_$(1) := $$(RUNTIME_CS_$(1):rt/%.cpp=rt/$(1)/%.o) \ $$(RUNTIME_S_$(1):rt/%.S=rt/$(1)/%.o) +RUNTIME_DEP_FILES_$(1) := $$(RUNTIME_OBJS_$(1):%.o=%.d) +-include $$(RUNTIME_DEP_FILES_$(1)) + RUNTIME_LIBS_$(1) := $$(LIBUV_LIB_$(1)) -rt/$(1)/%.o: rt/%.cpp $$(RUNTIME_HDR_$(1)) $$(MKFILE_DEPS) +rt/$(1)/%.o: rt/%.cpp $$(MKFILE_DEPS) @$$(call E, compile: $$@) $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, $$(RUNTIME_INCS_$(1)) \ $$(SNAP_DEFINES)) $$< -rt/$(1)/%.o: rt/%.S $$(RUNTIME_HDR_$(1)) $$(MKFILE_DEPS) \ +rt/$(1)/%.o: rt/%.S $$(MKFILE_DEPS) \ $$(LLVM_CONFIG_$$(CFG_HOST_TRIPLE)) @$$(call E, compile: $$@) $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<) @@ -134,7 +126,6 @@ rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a: \ $$(Q)ar rcs $$@ $$< rt/$(1)/$(CFG_RUNTIME): $$(RUNTIME_OBJS_$(1)) $$(MKFILE_DEPS) \ - $$(RUNTIME_HDR_$(1)) \ $$(RUNTIME_DEF_$(1)) \ $$(RUNTIME_LIBS_$(1)) @$$(call E, link: $$@) diff --git a/mk/rustllvm.mk b/mk/rustllvm.mk index fea09dae5af..63b71eb3850 100644 --- a/mk/rustllvm.mk +++ b/mk/rustllvm.mk @@ -20,6 +20,8 @@ RUSTLLVM_INCS_$(1) = $$(LLVM_EXTRA_INCDIRS_$(1)) \ -iquote $$(LLVM_INCDIR_$(1)) \ -iquote $$(S)src/rustllvm/include RUSTLLVM_OBJS_OBJS_$(1) := $$(RUSTLLVM_OBJS_CS_$(1):rustllvm/%.cpp=rustllvm/$(1)/%.o) +RUSTLLVM_DEP_FILES_$(1) := $$(RUSTLLVM_OBJS_OBJS_$(1):%.o=%.d) +-include $$(RUSTLLVM_DEP_FILES_$(1)) rustllvm/$(1)/$(CFG_RUSTLLVM): $$(RUSTLLVM_OBJS_OBJS_$(1)) \ $$(MKFILE_DEPS) $$(RUSTLLVM_DEF_$(1))