From e9b6397d2f902eb4f5bf0fd513013d92af074cfc Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 25 Nov 2013 09:17:02 +0000 Subject: [PATCH] Add a rule for creating directories The tricky thing here is that if you have a directory as a prerequisite, you need to declare it as a "order-only prerequisite" ("dir/prog: stuff | dir"), otherwise the target will be rebuilt every time because the timestamp on the directory keeps changing. --- Makefile.lib | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile.lib b/Makefile.lib index cacf921052..be2b19591e 100644 --- a/Makefile.lib +++ b/Makefile.lib @@ -9,12 +9,21 @@ include Makefile.config # Installing stuff. +define create-dir = + ifndef $(1)_SEEN + $(1)_SEEN = 1 + $(1): + install -d $(1) + endif +endef + define install-file-in = install:: $(1)/$(notdir $(2)) - $(1)/$(notdir $(2)): $(2) - install -d $(1) + $$(eval $$(call create-dir,$(1))) + + $(1)/$(notdir $(2)): $(2) | $(1) install -t $(1) $(2) endef @@ -139,7 +148,10 @@ define PROGRAMS_template = $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) $(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) - $(1)_INSTALL_PATH := $$(bindir)/$(1) + $(1)_INSTALL_DIR := $$(bindir) + $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1) + + $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) install:: $$($(1)_INSTALL_PATH) @@ -147,15 +159,13 @@ define PROGRAMS_template = _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) - $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) - install -d $$(dir $$($(1)_INSTALL_PATH)) - $(QUIET) $(CXX) -o $$($(1)_INSTALL_PATH) $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) + $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR) + $(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) else - $$($(1)_INSTALL_PATH): $$($(1)_PATH) - install -d $$(dir $$($(1)_INSTALL_PATH)) - cp $$< $$@ + $$($(1)_INSTALL_PATH): $$($(1)_PATH) | $$($(1)_INSTALL_DIR) + install -t $$($(1)_INSTALL_DIR) $$< endif