From 22c900da082aea1d6615cfa36cb1d0591ffff139 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 4 Sep 2014 19:35:24 +0200 Subject: [PATCH 1/9] Hack for supporting Boost on Homebrew --- lib.mk | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib.mk b/lib.mk index 56e162d50..8b109e2ce 100644 --- a/lib.mk +++ b/lib.mk @@ -40,6 +40,14 @@ ifeq ($(BUILD_SHARED_LIBS), 1) endif +# On MacOS X, some boost libraries have an -mt suffix +ifeq ($(OS), Darwin) + ifndef NIX_STORE + BOOST_SUFFIX = -mt + endif +endif + + # Pass -g if we want debug info. BUILD_DEBUG ?= 1 From afbdd5533448724aaf32b434fda8478ad5d80a0f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 5 Sep 2014 12:08:06 +0200 Subject: [PATCH 2/9] Hack to prevent Makefile.config from being regenerated by "make clean" --- templates.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/templates.mk b/templates.mk index ab99168bb..c7ac7afbf 100644 --- a/templates.mk +++ b/templates.mk @@ -8,8 +8,12 @@ define instantiate-template endef +ifneq ($(MAKECMDGOALS), clean) + %.h: %.h.in $(trace-gen) rm -f $@ && ./config.status --quiet --header=$@ %: %.in $(trace-gen) rm -f $@ && ./config.status --quiet --file=$@ + +endif From 075cfe3b97bf0e90577bb7e842ba467524fad0ef Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 5 Sep 2014 14:17:05 +0200 Subject: [PATCH 3/9] Add support for using a build directory --- functions.mk | 2 +- lib.mk | 10 ++++++++++ libraries.mk | 4 ++-- patterns.mk | 9 ++++++--- programs.mk | 4 ++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/functions.mk b/functions.mk index 45d917399..c48775db8 100644 --- a/functions.mk +++ b/functions.mk @@ -10,5 +10,5 @@ filename-to-dep = $(dir $1).$(notdir $1).dep # empty string if not found. find-program = $(shell for i in $$(IFS=: ; echo $$PATH); do p=$$i/$(strip $1); if [ -e $$p ]; then echo $$p; break; fi; done) -# Remove trailing slash. +# Ensure that the given string ends in a single slash. add-trailing-slash = $(patsubst %/,%,$(1))/ diff --git a/lib.mk b/lib.mk index 8b109e2ce..aa92d8d94 100644 --- a/lib.mk +++ b/lib.mk @@ -25,6 +25,16 @@ sysconfdir ?= $(prefix)/etc mandir ?= $(prefix)/share/man +# Initialise support for build directories. +builddir ?= + +ifdef builddir + buildprefix = $(builddir)/ +else + buildprefix = +endif + + # Pass -fPIC if we're building dynamic libraries. BUILD_SHARED_LIBS ?= 1 diff --git a/libraries.mk b/libraries.mk index 3b91c699e..206481979 100644 --- a/libraries.mk +++ b/libraries.mk @@ -45,9 +45,9 @@ endif # built, otherwise a static library. define build-library $(1)_NAME ?= $(1) - _d := $$(strip $$($(1)_DIR)) + _d := $(buildprefix)$$(strip $$($(1)_DIR)) _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) - $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) + $(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs)))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_INSTALL_DIR ?= $$(libdir) diff --git a/patterns.mk b/patterns.mk index 6b2cfd017..3219d9629 100644 --- a/patterns.mk +++ b/patterns.mk @@ -1,8 +1,11 @@ -%.o: %.cc +$(buildprefix)%.o: %.cc + @mkdir -p "$(dir $@)" $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP -%.o: %.cpp +$(buildprefix)%.o: %.cpp + @mkdir -p "$(dir $@)" $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP -%.o: %.c +$(buildprefix)%.o: %.c + @mkdir -p "$(dir $@)" $(trace-cc) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP diff --git a/programs.mk b/programs.mk index 72afdf952..3ac64494e 100644 --- a/programs.mk +++ b/programs.mk @@ -23,9 +23,9 @@ programs-list := # - $(1)_INSTALL_DIR: the directory where the program will be # installed; defaults to $(bindir). define build-program - _d := $$($(1)_DIR) + _d := $(buildprefix)$$($(1)_DIR) _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) - $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) + $(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs)))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_PATH := $$(_d)/$(1) From 44e7e3bb9b36bca7023d207c51b7380b78ccfc4c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Sep 2014 15:28:30 +0200 Subject: [PATCH 4/9] Improved support for building JARs --- jars.mk | 9 +++++++-- lib.mk | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/jars.mk b/jars.mk index 99470f374..186a81df1 100644 --- a/jars.mk +++ b/jars.mk @@ -1,4 +1,5 @@ define build-jar + $(1)_NAME ?= $(1) _d := $$(strip $$($(1)_DIR)) @@ -7,10 +8,14 @@ define build-jar $(1)_TMPDIR := $$(_d)/.$$($(1)_NAME).jar.tmp - $$($(1)_PATH): $$($(1)_SOURCES) + _jars := $$(foreach jar, $$($(1)_JARS), $$($$(jar)_PATH)) + + $$($(1)_PATH): $$($(1)_SOURCES) $$(_jars) @rm -rf $$($(1)_TMPDIR) @mkdir -p $$($(1)_TMPDIR) - $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) $$($(1)_SOURCES) + $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) \ + $$(foreach fn, $$($(1)_SOURCES), '$$(fn)') \ + -cp "$$(subst $$(space),,$$(foreach jar,$$($(1)_JARS),$$($$(jar)_PATH):))$$$$CLASSPATH" $$(trace-jar) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) . @rm -rf $$($(1)_TMPDIR) diff --git a/lib.mk b/lib.mk index aa92d8d94..16a43f45e 100644 --- a/lib.mk +++ b/lib.mk @@ -14,6 +14,11 @@ dist-files := OS = $(shell uname -s) +# Hack to define a literal space. +space := +space += + + # Default installation paths. prefix ?= /usr/local libdir ?= $(prefix)/lib From 9648222ef0ad7cd4478d61c3ffd6fe9926a859df Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Sep 2014 15:47:31 +0200 Subject: [PATCH 5/9] Support specifying a JAR manifest --- jars.mk | 2 +- lib.mk | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jars.mk b/jars.mk index 186a81df1..abe3f9fe5 100644 --- a/jars.mk +++ b/jars.mk @@ -16,7 +16,7 @@ define build-jar $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) \ $$(foreach fn, $$($(1)_SOURCES), '$$(fn)') \ -cp "$$(subst $$(space),,$$(foreach jar,$$($(1)_JARS),$$($$(jar)_PATH):))$$$$CLASSPATH" - $$(trace-jar) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) . + $$(trace-jar) jar cfm $$($(1)_PATH) <(echo -e '$$(subst $$(newline),\n,$$($(1)_MANIFEST))') -C $$($(1)_TMPDIR) . @rm -rf $$($(1)_TMPDIR) $(1)_INSTALL_DIR ?= $$(libdir)/java diff --git a/lib.mk b/lib.mk index 16a43f45e..31308deaa 100644 --- a/lib.mk +++ b/lib.mk @@ -14,11 +14,22 @@ dist-files := OS = $(shell uname -s) +# Use bash (required for process substitution in the JAR function). +SHELL = bash + + # Hack to define a literal space. space := space += +# Hack to define a literal newline. +define newline + + +endef + + # Default installation paths. prefix ?= /usr/local libdir ?= $(prefix)/lib From 5c4d2dab99d9a8c18055fda25678e055ef6ef168 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Sep 2014 16:24:26 +0200 Subject: [PATCH 6/9] Fix JAR installation --- jars.mk | 4 ++-- lib.mk | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jars.mk b/jars.mk index abe3f9fe5..a11178342 100644 --- a/jars.mk +++ b/jars.mk @@ -10,7 +10,7 @@ define build-jar _jars := $$(foreach jar, $$($(1)_JARS), $$($$(jar)_PATH)) - $$($(1)_PATH): $$($(1)_SOURCES) $$(_jars) + $$($(1)_PATH): $$($(1)_SOURCES) $$(_jars) $$($(1)_EXTRA_DEPS)| $$($(1)_ORDER_AFTER) @rm -rf $$($(1)_TMPDIR) @mkdir -p $$($(1)_TMPDIR) $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) \ @@ -19,7 +19,7 @@ define build-jar $$(trace-jar) jar cfm $$($(1)_PATH) <(echo -e '$$(subst $$(newline),\n,$$($(1)_MANIFEST))') -C $$($(1)_TMPDIR) . @rm -rf $$($(1)_TMPDIR) - $(1)_INSTALL_DIR ?= $$(libdir)/java + $(1)_INSTALL_DIR ?= $$(jardir) $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).jar diff --git a/lib.mk b/lib.mk index 31308deaa..fd39d35bb 100644 --- a/lib.mk +++ b/lib.mk @@ -36,6 +36,7 @@ libdir ?= $(prefix)/lib bindir ?= $(prefix)/bin libexecdir ?= $(prefix)/libexec datadir ?= $(prefix)/share +jardir ?= $(datadir)/java localstatedir ?= $(prefix)/var sysconfdir ?= $(prefix)/etc mandir ?= $(prefix)/share/man From 72d684d592233829b785d5fbec10da6e9ce580df Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 12 Sep 2014 12:50:03 +0200 Subject: [PATCH 7/9] Don't rely on process substitution --- jars.mk | 4 +++- lib.mk | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/jars.mk b/jars.mk index a11178342..c8513e664 100644 --- a/jars.mk +++ b/jars.mk @@ -16,7 +16,9 @@ define build-jar $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) \ $$(foreach fn, $$($(1)_SOURCES), '$$(fn)') \ -cp "$$(subst $$(space),,$$(foreach jar,$$($(1)_JARS),$$($$(jar)_PATH):))$$$$CLASSPATH" - $$(trace-jar) jar cfm $$($(1)_PATH) <(echo -e '$$(subst $$(newline),\n,$$($(1)_MANIFEST))') -C $$($(1)_TMPDIR) . + @echo -e '$$(subst $$(newline),\n,$$($(1)_MANIFEST))' > $$($(1)_PATH).manifest + $$(trace-jar) jar cfm $$($(1)_PATH) $$($(1)_PATH).manifest -C $$($(1)_TMPDIR) . + @rm $$($(1)_PATH).manifest @rm -rf $$($(1)_TMPDIR) $(1)_INSTALL_DIR ?= $$(jardir) diff --git a/lib.mk b/lib.mk index fd39d35bb..f390a7e8a 100644 --- a/lib.mk +++ b/lib.mk @@ -14,10 +14,6 @@ dist-files := OS = $(shell uname -s) -# Use bash (required for process substitution in the JAR function). -SHELL = bash - - # Hack to define a literal space. space := space += From 938454d8f37dac17f042691ecc58f605fbe1635e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 10 Dec 2014 13:01:10 +0100 Subject: [PATCH 8/9] Don't use RPATH on Darwin --- libraries.mk | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries.mk b/libraries.mk index 206481979..766f7ccf7 100644 --- a/libraries.mk +++ b/libraries.mk @@ -76,9 +76,12 @@ define build-library $(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT) $$($(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)) + $$(trace-ld) $(CXX) -o $$(abspath $$@) -shared $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $$($(1)_LDFLAGS_UNINSTALLED) - $(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) + ifneq ($(OS), Darwin) + $(1)_LDFLAGS_USE += -Wl,-rpath,$$(abspath $$(_d)) + endif + $(1)_LDFLAGS_USE += -L$$(_d) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) $(1)_INSTALL_PATH := $(DESTDIR)$$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT) @@ -90,10 +93,12 @@ define build-library $$(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$$(DESTDIR)$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) - ifeq ($(SET_RPATH_TO_LIBS), 1) - $(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath,$$($(1)_INSTALL_DIR) - else - $(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath-link,$$($(1)_INSTALL_DIR) + ifneq ($(OS), Darwin) + ifeq ($(SET_RPATH_TO_LIBS), 1) + $(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath,$$($(1)_INSTALL_DIR) + else + $(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath-link,$$($(1)_INSTALL_DIR) + endif endif ifdef $(1)_FORCE_INSTALL From 36c67860363c93eb00cf5b8e2ad34f6f775e6901 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 10 Dec 2014 13:01:28 +0100 Subject: [PATCH 9/9] Cruft --- lib.mk | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib.mk b/lib.mk index f390a7e8a..ba1fb3a2a 100644 --- a/lib.mk +++ b/lib.mk @@ -62,15 +62,6 @@ ifeq ($(BUILD_SHARED_LIBS), 1) SET_RPATH_TO_LIBS ?= 1 endif - -# On MacOS X, some boost libraries have an -mt suffix -ifeq ($(OS), Darwin) - ifndef NIX_STORE - BOOST_SUFFIX = -mt - endif -endif - - # Pass -g if we want debug info. BUILD_DEBUG ?= 1