From 0da82efa5d67ab1eb8b8cc066704d7f863451d5b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 Feb 2014 11:02:49 +0100 Subject: [PATCH 1/4] GNU Make 3.81 compatibility MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3.81 doesn't understand the ‘define foo =’ syntax, which was added in 3.82. So use ‘define foo’ instead. --- install.mk | 12 ++++++------ jars.mk | 2 +- lib.mk | 2 +- libraries.mk | 2 +- programs.mk | 2 +- templates.mk | 2 +- tests.mk | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/install.mk b/install.mk index 093f30b8..e8543f6b 100644 --- a/install.mk +++ b/install.mk @@ -1,6 +1,6 @@ # Add a rule for creating $(1) as a directory. This template may be # called multiple times for the same directory. -define create-dir = +define create-dir ifndef $(1)_SEEN $(1)_SEEN = 1 $(1): @@ -11,7 +11,7 @@ endef # Add a rule for installing file $(1) as file $(2) with mode $(3). # The directory containing $(2) will be created automatically. -define install-file-as = +define install-file-as install: $(2) @@ -25,23 +25,23 @@ endef # Add a rule for installing file $(1) in directory $(2) with mode # $(3). The directory will be created automatically. -define install-file-in = +define install-file-in $$(eval $$(call install-file-as,$(1),$(2)/$$(notdir $(1)),$(3))) endef -define install-program-in = +define install-program-in $$(eval $$(call install-file-in,$(1),$(2),0755)) endef -define install-data-in = +define install-data-in $$(eval $$(call install-file-in,$(1),$(2),0644)) endef # Install a symlink from $(2) to $(1). Note that $(1) need not exist. -define install-symlink = +define install-symlink install: $(2) diff --git a/jars.mk b/jars.mk index 9595c1c4..99470f37 100644 --- a/jars.mk +++ b/jars.mk @@ -1,4 +1,4 @@ -define build-jar = +define build-jar $(1)_NAME ?= $(1) _d := $$(strip $$($(1)_DIR)) diff --git a/lib.mk b/lib.mk index 6e02bc91..6bcd83a0 100644 --- a/lib.mk +++ b/lib.mk @@ -60,7 +60,7 @@ include mk/tests.mk # Include all sub-Makefiles. -define include-sub-makefile = +define include-sub-makefile d := $$(patsubst %/,%,$$(dir $(1))) include $(1) endef diff --git a/libraries.mk b/libraries.mk index a6965325..69dede9a 100644 --- a/libraries.mk +++ b/libraries.mk @@ -38,7 +38,7 @@ endif # # - BUILD_SHARED_LIBS: if equal to ‘1’, a dynamic library will be # built, otherwise a static library. -define build-library = +define build-library $(1)_NAME ?= $(1) _d := $$(strip $$($(1)_DIR)) _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) diff --git a/programs.mk b/programs.mk index 30539d12..74f2982a 100644 --- a/programs.mk +++ b/programs.mk @@ -15,7 +15,7 @@ programs-list := # # - $(1)_INSTALL_DIR: the directory where the program will be # installed; defaults to $(bindir). -define build-program = +define build-program _d := $$($(1)_DIR) _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) diff --git a/templates.mk b/templates.mk index 6d7b1034..8e8b2864 100644 --- a/templates.mk +++ b/templates.mk @@ -2,7 +2,7 @@ template-files := # Create the file $(1) from $(1).in by running config.status (which # substitutes all ‘@var@’ variables set by the configure script). -define instantiate-template = +define instantiate-template clean-files += $(1) diff --git a/tests.mk b/tests.mk index bb94a83a..6bdb4e57 100644 --- a/tests.mk +++ b/tests.mk @@ -1,5 +1,5 @@ # Run program $1 as part of ‘make installcheck’. -define run-install-test = +define run-install-test installcheck: $1 From 4161fce472a8875427e73776d0e8665ca49c1835 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 6 Feb 2014 10:59:58 +0100 Subject: [PATCH 2/4] Create the target directory of libraries and programs --- install.mk | 2 +- libraries.mk | 6 ++++-- programs.mk | 4 +++- tracing.mk | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/install.mk b/install.mk index e8543f6b..8211e43e 100644 --- a/install.mk +++ b/install.mk @@ -4,7 +4,7 @@ define create-dir ifndef $(1)_SEEN $(1)_SEEN = 1 $(1): - $$(trace-install) install -d $(1) + $$(trace-mkdir) install -d $(1) endif endef diff --git a/libraries.mk b/libraries.mk index 69dede9a..e1c694cb 100644 --- a/libraries.mk +++ b/libraries.mk @@ -50,6 +50,8 @@ define build-library $(1)_LDFLAGS_USE := $(1)_LDFLAGS_USE_INSTALLED := + $$(eval $$(call create-dir,$$(_d))) + ifeq ($(BUILD_SHARED_LIBS), 1) ifdef $(1)_ALLOW_UNDEFINED @@ -64,7 +66,7 @@ define build-library $(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT) - $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) + $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d) $$(trace-ld) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) @@ -88,7 +90,7 @@ define build-library $(1)_PATH := $$(_d)/$$($(1)_NAME).a - $$($(1)_PATH): $$($(1)_OBJS) + $$($(1)_PATH): $$($(1)_OBJS) | $$(_d) $(trace-ar) ar crs $$@ $$? $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) diff --git a/programs.mk b/programs.mk index 74f2982a..218fd37a 100644 --- a/programs.mk +++ b/programs.mk @@ -22,7 +22,9 @@ define build-program _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_PATH := $$(_d)/$(1) - $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) + $$(eval $$(call create-dir,$$(_d))) + + $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d) $$(trace-ld) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $(1)_INSTALL_DIR ?= $$(bindir) diff --git a/tracing.mk b/tracing.mk index 08c4ec10..13912d3c 100644 --- a/tracing.mk +++ b/tracing.mk @@ -10,6 +10,7 @@ ifeq ($(V), 0) trace-install = @echo " INST " $@; trace-javac = @echo " JAVAC " $@; trace-jar = @echo " JAR " $@; + trace-mkdir = @echo " MKDIR " $@; suppress = @ From 97f8e9bc76b08ac6d63c6419490f8fcc9670a58b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 6 Feb 2014 19:06:08 +0100 Subject: [PATCH 3/4] Remove dead code --- tests.mk | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests.mk b/tests.mk index 6bdb4e57..004a4802 100644 --- a/tests.mk +++ b/tests.mk @@ -3,9 +3,6 @@ define run-install-test installcheck: $1 - # Run the test in its own directory to mimick Automake behaviour. - $1.run: $1 $(_PREV_TEST) - _installcheck-list += $1 endef From a210c995cdd9279ed4137ec5d2e4cc928cb36097 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 7 Feb 2014 15:06:21 +0100 Subject: [PATCH 4/4] Support DESTDIR --- install.mk | 29 +++++++++++++++++------------ libraries.mk | 10 +++++----- programs.mk | 10 +++++----- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/install.mk b/install.mk index 8211e43e..e4bc734e 100644 --- a/install.mk +++ b/install.mk @@ -1,10 +1,11 @@ # Add a rule for creating $(1) as a directory. This template may be # called multiple times for the same directory. define create-dir - ifndef $(1)_SEEN - $(1)_SEEN = 1 - $(1): - $$(trace-mkdir) install -d $(1) + _i := $(DESTDIR)$$(strip $(1)) + ifndef $$(_i)_SEEN + $$(_i)_SEEN = 1 + $$(_i): + $$(trace-mkdir) install -d "$$@" endif endef @@ -13,12 +14,14 @@ endef # The directory containing $(2) will be created automatically. define install-file-as - install: $(2) + _i := $(DESTDIR)$$(strip $(2)) - $$(eval $$(call create-dir,$$(dir $(2)))) + install: $$(_i) - $(2): $(1) | $$(dir $(2)) - $$(trace-install) install -m $(3) $(1) $(2) + $$(_i): $(1) | $$(dir $$(_i)) + $$(trace-install) install -m $(3) $(1) "$$@" + + $$(eval $$(call create-dir, $$(dir $(2)))) endef @@ -43,12 +46,14 @@ endef # Install a symlink from $(2) to $(1). Note that $(1) need not exist. define install-symlink - install: $(2) + _i := $(DESTDIR)$$(strip $(2)) - $$(eval $$(call create-dir,$$(dir $(2)))) + install: $$(_i) - $(2): | $$(dir $(2)) - $$(trace-install) ln -sfn $(1) $(2) + $$(_i): | $$(dir $$(_i)) + $$(trace-install) ln -sfn $(1) "$$@" + + $$(eval $$(call create-dir, $$(dir $(2)))) endef diff --git a/libraries.mk b/libraries.mk index e1c694cb..c4169479 100644 --- a/libraries.mk +++ b/libraries.mk @@ -50,7 +50,7 @@ define build-library $(1)_LDFLAGS_USE := $(1)_LDFLAGS_USE_INSTALLED := - $$(eval $$(call create-dir,$$(_d))) + $$(eval $$(call create-dir, $$(_d))) ifeq ($(BUILD_SHARED_LIBS), 1) @@ -71,16 +71,16 @@ define build-library $(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) - $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT) + $(1)_INSTALL_PATH := $(DESTDIR)$$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT) _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) - $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) + $$(eval $$(call create-dir, $$($(1)_INSTALL_DIR))) - $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR) + $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR) $$(trace-ld) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) - $(1)_LDFLAGS_USE_INSTALLED += -L$$($(1)_INSTALL_DIR) -Wl,-rpath,$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) + $(1)_LDFLAGS_USE_INSTALLED += -L$$(DESTDIR)$$($(1)_INSTALL_DIR) -Wl,-rpath,$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) ifdef $(1)_FORCE_INSTALL install: $$($(1)_INSTALL_PATH) diff --git a/programs.mk b/programs.mk index 218fd37a..ab04ff93 100644 --- a/programs.mk +++ b/programs.mk @@ -22,7 +22,7 @@ define build-program _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_PATH := $$(_d)/$(1) - $$(eval $$(call create-dir,$$(_d))) + $$(eval $$(call create-dir, $$(_d))) $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d) $$(trace-ld) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) @@ -30,20 +30,20 @@ define build-program $(1)_INSTALL_DIR ?= $$(bindir) $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1) - $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) + $$(eval $$(call create-dir, $$($(1)_INSTALL_DIR))) - install: $$($(1)_INSTALL_PATH) + install: $(DESTDIR)$$($(1)_INSTALL_PATH) ifeq ($(BUILD_SHARED_LIBS), 1) _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) - $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR) + $(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR) $$(trace-ld) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) else - $$($(1)_INSTALL_PATH): $$($(1)_PATH) | $$($(1)_INSTALL_DIR) + $(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR) install -t $$($(1)_INSTALL_DIR) $$< endif