Browse Source

Use an intermediate timestamp file to know when to touch source files

The previous approach spawned a shell for every single source files. As
we disable parallel make jobs, this is very time consuming.

The new approach uses an intermediate timestamp file in $(ERLANG_MK_TMP)
to record the last modification of any of $(MAKEFILE_LIST) and touch
all source files in one command. Then, the .app file depends on this
timestamp file.

We test the existence of this timestamp file: if if doesn't exist, don't
touch source files, they will be built anyway.

$(PROJECT).d now depends directly on $(MAKEFILE_LIST); before, this
dependency was indirect through $(ERL_FILES). Also, once $(ERL_FILES)
were touched, we do the same with $(PROJECT).d because there is no need
to regen it because of this.
Jean-Sébastien Pédron 9 years ago
parent
commit
4717afcc48
3 changed files with 23 additions and 5 deletions
  1. 13 3
      core/erlc.mk
  2. 9 1
      plugins/erlydtl.mk
  3. 1 1
      test/core_app.mk

+ 13 - 3
core/erlc.mk

@@ -216,13 +216,23 @@ define makedep.erl
 endef
 
 ifeq ($(if $(NO_MAKEDEP),$(wildcard $(PROJECT).d),),)
-$(PROJECT).d:: $(ERL_FILES) $(call core_find,include/,*.hrl)
+$(PROJECT).d:: $(ERL_FILES) $(call core_find,include/,*.hrl) $(MAKEFILE_LIST)
 	$(makedep_verbose) $(call erlang,$(call makedep.erl,$@))
 endif
 
+ifneq ($(words $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES)),0)
 # Rebuild everything when the Makefile changes.
-$(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):: $(MAKEFILE_LIST)
-	@touch $@
+$(ERLANG_MK_TMP)/last-makefile-change: $(MAKEFILE_LIST)
+	$(verbose) mkdir -p $(ERLANG_MK_TMP)
+	$(verbose) if test -f $@; then \
+		touch $(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES); \
+		touch -c $(PROJECT).d; \
+	fi
+	$(verbose) touch $@
+
+$(ERL_FILES) $(CORE_FILES) $(ASN1_FILES) $(MIB_FILES) $(XRL_FILES) $(YRL_FILES):: $(ERLANG_MK_TMP)/last-makefile-change
+ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change
+endif
 
 -include $(PROJECT).d
 

+ 9 - 1
plugins/erlydtl.mk

@@ -24,10 +24,18 @@ DTL_NAMES   = $(addsuffix $(DTL_SUFFIX),$(DTL_FILES:$(DTL_PATH)/%.dtl=%))
 DTL_MODULES = $(if $(DTL_FULL_PATH),$(subst /,_,$(DTL_NAMES)),$(notdir $(DTL_NAMES)))
 BEAM_FILES += $(addsuffix .beam,$(addprefix ebin/,$(DTL_MODULES)))
 
+ifneq ($(words $(DTL_FILES)),0)
 # Rebuild templates when the Makefile changes.
-$(DTL_FILES): $(MAKEFILE_LIST)
+$(ERLANG_MK_TMP)/last-makefile-change-erlydtl: $(MAKEFILE_LIST)
+	@mkdir -p $(ERLANG_MK_TMP)
+	@if test -f $@; then \
+		touch $(DTL_FILES); \
+	fi
 	@touch $@
 
+ebin/$(PROJECT).app:: $(ERLANG_MK_TMP)/last-makefile-change-erlydtl
+endif
+
 define erlydtl_compile.erl
 	[begin
 		Module0 = case "$(strip $(DTL_FULL_PATH))" of

+ 1 - 1
test/core_app.mk

@@ -850,7 +850,7 @@ core-app-makefile-change: build clean
 	$t touch $(APP)/Makefile
 	$t $(SLEEP)
 	$t $(MAKE) -C $(APP) $v
-	$t find $(APP) -type f -newer $(APP)/Makefile | sort | diff $(APP)/EXPECT -
+	$t find $(APP) -type f -newer $(APP)/Makefile -not -path "$(APP)/.erlang.mk/*" | sort | diff $(APP)/EXPECT -
 	$t rm $(APP)/EXPECT
 
 core-app-mib: build clean