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.
This commit is contained in:
parent
4315acb8c0
commit
e9b6397d2f
1 changed files with 19 additions and 9 deletions
28
Makefile.lib
28
Makefile.lib
|
@ -9,12 +9,21 @@ include Makefile.config
|
||||||
|
|
||||||
|
|
||||||
# Installing stuff.
|
# Installing stuff.
|
||||||
|
define create-dir =
|
||||||
|
ifndef $(1)_SEEN
|
||||||
|
$(1)_SEEN = 1
|
||||||
|
$(1):
|
||||||
|
install -d $(1)
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
define install-file-in =
|
define install-file-in =
|
||||||
|
|
||||||
install:: $(1)/$(notdir $(2))
|
install:: $(1)/$(notdir $(2))
|
||||||
|
|
||||||
$(1)/$(notdir $(2)): $(2)
|
$$(eval $$(call create-dir,$(1)))
|
||||||
install -d $(1)
|
|
||||||
|
$(1)/$(notdir $(2)): $(2) | $(1)
|
||||||
install -t $(1) $(2)
|
install -t $(1) $(2)
|
||||||
|
|
||||||
endef
|
endef
|
||||||
|
@ -139,7 +148,10 @@ define PROGRAMS_template =
|
||||||
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs)
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs)
|
||||||
$(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
$(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)
|
install:: $$($(1)_INSTALL_PATH)
|
||||||
|
|
||||||
|
@ -147,15 +159,13 @@ define PROGRAMS_template =
|
||||||
|
|
||||||
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
||||||
|
|
||||||
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final)
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR)
|
||||||
install -d $$(dir $$($(1)_INSTALL_PATH))
|
$(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
||||||
$(QUIET) $(CXX) -o $$($(1)_INSTALL_PATH) $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
$$($(1)_INSTALL_PATH): $$($(1)_PATH)
|
$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $$($(1)_INSTALL_DIR)
|
||||||
install -d $$(dir $$($(1)_INSTALL_PATH))
|
install -t $$($(1)_INSTALL_DIR) $$<
|
||||||
cp $$< $$@
|
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue