diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-25T09·17+0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-11-25T09·17+0000 |
commit | e9b6397d2f902eb4f5bf0fd513013d92af074cfc (patch) | |
tree | a8885e6bb9cc641550e6b4a7774a3dc93c1e77fb | |
parent | 4315acb8c0a40703b17f837ab82e9a691b5c14ab (diff) |
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.
-rw-r--r-- | Makefile.lib | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Makefile.lib b/Makefile.lib index cacf921052e8..be2b19591ee5 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 |