From 49a385096e08b42277b7105d5d8d1e0e62b6b7a4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 10 Dec 2013 15:54:34 +0100 Subject: [PATCH 01/24] Initial commit (imported from the Nix repo) --- mk/clean.mk | 7 ++++ mk/dist.mk | 10 +++++ mk/install.mk | 53 +++++++++++++++++++++++++++ mk/lib.mk | 67 ++++++++++++++++++++++++++++++++++ mk/libraries.mk | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ mk/patterns.mk | 5 +++ mk/programs.mk | 57 +++++++++++++++++++++++++++++ mk/templates.mk | 10 +++++ mk/tests.mk | 29 +++++++++++++++ 9 files changed, 335 insertions(+) create mode 100644 mk/clean.mk create mode 100644 mk/dist.mk create mode 100644 mk/install.mk create mode 100644 mk/lib.mk create mode 100644 mk/libraries.mk create mode 100644 mk/patterns.mk create mode 100644 mk/programs.mk create mode 100644 mk/templates.mk create mode 100644 mk/tests.mk diff --git a/mk/clean.mk b/mk/clean.mk new file mode 100644 index 00000000..3287ac87 --- /dev/null +++ b/mk/clean.mk @@ -0,0 +1,7 @@ +clean_files := + +clean: + rm -fv $(clean_files) + +dryclean: + @echo $(clean_files) diff --git a/mk/dist.mk b/mk/dist.mk new file mode 100644 index 00000000..3e89aec8 --- /dev/null +++ b/mk/dist.mk @@ -0,0 +1,10 @@ +dist_name = $(PACKAGE_NAME)-$(PACKAGE_VERSION) + +dist_files := + +dist: $(dist_name).tar.bz2 + +$(dist_name).tar.bz2: $(dist_files) + $(QUIET) tar cvfj $@ $(dist_files) --transform 's,^,$(dist_name)/,' + +clean_files += $(dist_name).tar.bz2 diff --git a/mk/install.mk b/mk/install.mk new file mode 100644 index 00000000..c5eb8eb3 --- /dev/null +++ b/mk/install.mk @@ -0,0 +1,53 @@ +# 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): + $(QUIET) install -d $(1) + endif +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 = + + install: $(2) + + $$(eval $$(call create-dir,$$(dir $(2)))) + + $(2): $(1) | $$(dir $(2)) + $(QUIET) install -m $(3) $(1) $(2) + +endef + + +# Add a rule for installing file $(1) in directory $(2) with mode +# $(3). The directory will be created automatically. +define install-file-in = + $$(eval $$(call install-file-as,$(1),$(2)/$$(notdir $(1)),$(3))) +endef + + +define install-program-in = + $$(eval $$(call install-file-in,$(1),$(2),0755)) +endef + + +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 = + + install: $(2) + + $$(eval $$(call create-dir,$$(dir $(2)))) + + $(2): | $$(dir $(2)) + $(QUIET) ln -sfn $(1) $(2) + +endef diff --git a/mk/lib.mk b/mk/lib.mk new file mode 100644 index 00000000..60b6815e --- /dev/null +++ b/mk/lib.mk @@ -0,0 +1,67 @@ +default: all + + +# Include Autoconf variables. +template_files += Makefile.config +include Makefile.config + + +# Get rid of default suffixes. FIXME: is this a good idea? +.SUFFIXES: + + +# Initialise some variables. +QUIET = @ +bin_SCRIPTS := +noinst_SCRIPTS := + + +# Pass -fPIC if we're building dynamic libraries. +BUILD_SHARED_LIBS = 1 + +ifeq ($(BUILD_SHARED_LIBS), 1) + GLOBAL_CFLAGS += -fPIC + GLOBAL_CXXFLAGS += -fPIC + GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries +endif + + +# Pass -g if we want debug info. +BUILD_DEBUG = 1 + +ifeq ($(BUILD_DEBUG), 1) + GLOBAL_CFLAGS += -g + GLOBAL_CXXFLAGS += -g +endif + + +include mk/clean.mk +include mk/dist.mk +include mk/install.mk +include mk/libraries.mk +include mk/programs.mk +include mk/patterns.mk +include mk/templates.mk +include mk/tests.mk + + +# Include all sub-Makefiles. +define include-sub-makefile = + d := $$(patsubst %/, %, $$(dir $(1))) + include $(1) +endef + +$(foreach mf, $(SUBS), $(eval $(call include-sub-makefile, $(mf)))) + + +# Instantiate stuff. +$(foreach lib, $(LIBS), $(eval $(call build-library,$(lib)))) +$(foreach prog, $(PROGRAMS), $(eval $(call build-program,$(prog)))) +$(foreach script, $(bin_SCRIPTS), $(eval $(call install-program-in,$(script),$(bindir)))) +$(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script))) +$(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script))) +$(foreach template, $(template_files), $(eval $(call instantiate-template,$(template)))) +$(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) + + +all: $(programs_list) $(libs_list) diff --git a/mk/libraries.mk b/mk/libraries.mk new file mode 100644 index 00000000..58c67063 --- /dev/null +++ b/mk/libraries.mk @@ -0,0 +1,97 @@ +libs_list := + +# Build a library with symbolic name $(1). The library is defined by +# various variables prefixed by ‘$(1)_’: +# +# - $(1)_NAME: the name of the library (e.g. ‘libfoo’); defaults to +# $(1). +# +# - $(1)_DIR: the directory containing the sources of the library, and +# where the (non-installed) library will be placed. +# +# - $(1)_SOURCES: the source files of the library. +# +# - $(1)_LIBS: the symbolic names of other libraries on which this +# library depends. +# +# - $(1)_ALLOW_UNDEFINED: if set, the library is allowed to have +# undefined symbols. Has no effect for static libraries. +# +# - $(1)_LDFLAGS: additional linker flags. +# +# - $(1)_LDFLAGS_PROPAGATED: additional linker flags, also propagated +# to the linking of programs/libraries that use this library. +# +# - $(1)_FORCE_INSTALL: if defined, the library will be installed even +# if it's not needed (i.e. dynamically linked) by a program. +# +# - $(1)_INSTALL_DIR: the directory where the library will be +# installed. Defaults to $(libdir). +# +# - BUILD_SHARED_LIBS: if equal to ‘1’, a dynamic library will be +# built, otherwise a static library. +define build-library = + $(1)_NAME ?= $(1) + _d := $$(strip $$($(1)_DIR)) + _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) + $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) + _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) + + $(1)_INSTALL_DIR ?= $$(libdir) + + $(1)_LDFLAGS_USE := + $(1)_LDFLAGS_USE_INSTALLED := + + ifeq ($(BUILD_SHARED_LIBS), 1) + + ifndef $(1)_ALLOW_UNDEFINED + $(1)_LDFLAGS += -z defs + endif + + $(1)_PATH := $$(_d)/$$($(1)_NAME).so + + $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) + $(QUIET) $(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))) + + $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).so + + _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) + + $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) + + $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR) + $(QUIET) $(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))) + + ifdef $(1)_FORCE_INSTALL + install: $$($(1)_INSTALL_PATH) + endif + + else + + $(1)_PATH := $$(_d)/$$($(1)_NAME).a + + $$($(1)_PATH): $$($(1)_OBJS) + $(QUIET) ar crs $$@ $$? + + $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) + + $(1)_INSTALL_PATH := $$(libdir)/$$($(1)_NAME).a + + endif + + $(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED) + $(1)_LDFLAGS_USE_INSTALLED += $$($(1)_LDFLAGS_PROPAGATED) + + # Propagate CXXFLAGS to the individual object files. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) + + include $$(wildcard $$(_d)/*.dep) + + libs_list += $$($(1)_PATH) + clean_files += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep + dist_files += $$(_srcs) +endef diff --git a/mk/patterns.mk b/mk/patterns.mk new file mode 100644 index 00000000..87d90955 --- /dev/null +++ b/mk/patterns.mk @@ -0,0 +1,5 @@ +%.o: %.cc + $(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + +%.o: %.c + $(QUIET) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP diff --git a/mk/programs.mk b/mk/programs.mk new file mode 100644 index 00000000..648a6053 --- /dev/null +++ b/mk/programs.mk @@ -0,0 +1,57 @@ +programs_list := + +# Build a program with symbolic name $(1). The program is defined by +# various variables prefixed by ‘$(1)_’: +# +# - $(1)_DIR: the directory containing the sources of the program, and +# where the (non-installed) program will be placed. +# +# - $(1)_SOURCES: the source files of the program. +# +# - $(1)_LIBS: the symbolic names of libraries on which this program +# depends. +# +# - $(1)_LDFLAGS: additional linker flags. +# +# - $(1)_INSTALL_DIR: the directory where the program will be +# installed; defaults to $(bindir). +define build-program = + _d := $$($(1)_DIR) + _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) + $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) + _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) + $(1)_PATH := $$(_d)/$(1) + + $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) + $(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) + + $(1)_INSTALL_DIR ?= $$(bindir) + $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1) + + $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) + + install: $$($(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) + $(QUIET) $(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) + install -t $$($(1)_INSTALL_DIR) $$< + + endif + + # Propagate CXXFLAGS to the individual object files. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) + + include $$(wildcard $$(_d)/*.dep) + + programs_list += $$($(1)_PATH) + clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/*.dep + dist_files += $$(_srcs) +endef diff --git a/mk/templates.mk b/mk/templates.mk new file mode 100644 index 00000000..fa91e250 --- /dev/null +++ b/mk/templates.mk @@ -0,0 +1,10 @@ +# Create the file $(1) from $(1).in by running config.status (which +# substitutes all ‘@var@’ variables set by the configure script). +define instantiate-template = + + clean_files += $(1) + +endef + +%: %.in + $(QUIET) ./config.status --quiet --file $@ diff --git a/mk/tests.mk b/mk/tests.mk new file mode 100644 index 00000000..8a3bff66 --- /dev/null +++ b/mk/tests.mk @@ -0,0 +1,29 @@ +# Run program $1 as part of ‘make installcheck’. +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 + +installcheck: install + @total=0; failed=0; for i in $(_installcheck_list); do \ + total=$$((total + 1)); \ + echo "running test $$i"; \ + if (cd $$(dirname $$i) && $(TESTS_ENVIRONMENT) $$(basename $$i)); then \ + echo "PASS: $$i"; \ + else \ + echo "FAIL: $$i"; \ + failed=$$((failed + 1)); \ + fi; \ + done; \ + if [ "$$failed" != 0 ]; then \ + echo "$$failed out of $$total tests failed "; \ + exit 1; \ + fi + +.PHONY: check installcheck From 3560f52cc427a4eb368815ae7dd9badffba84f3f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:22:08 +0100 Subject: [PATCH 02/24] dryclean: Show what actual files would be deleted --- mk/clean.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mk/clean.mk b/mk/clean.mk index 3287ac87..703e32e2 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -1,7 +1,7 @@ clean_files := clean: - rm -fv $(clean_files) + $(QUIET) rm -fv -- $(clean_files) dryclean: - @echo $(clean_files) + @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done From dfcc64f556295481bfea0b68cab11604ec131189 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:22:25 +0100 Subject: [PATCH 03/24] Only provide 'make dist' if PACKAGE_NAME is set --- mk/dist.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mk/dist.mk b/mk/dist.mk index 3e89aec8..444c58b3 100644 --- a/mk/dist.mk +++ b/mk/dist.mk @@ -1,3 +1,5 @@ +ifdef PACKAGE_NAME + dist_name = $(PACKAGE_NAME)-$(PACKAGE_VERSION) dist_files := @@ -8,3 +10,5 @@ $(dist_name).tar.bz2: $(dist_files) $(QUIET) tar cvfj $@ $(dist_files) --transform 's,^,$(dist_name)/,' clean_files += $(dist_name).tar.bz2 + +endif From c34f3c5ba4f353d67ec4a88a32c3aa688347aa4d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:22:57 +0100 Subject: [PATCH 04/24] Handle *.cpp extension --- mk/patterns.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mk/patterns.mk b/mk/patterns.mk index 87d90955..77e17213 100644 --- a/mk/patterns.mk +++ b/mk/patterns.mk @@ -1,5 +1,8 @@ %.o: %.cc $(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP +%.o: %.cpp + $(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + %.o: %.c $(QUIET) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP From 45131da736f21975e5b6d03f508b49f10621a30e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:24:03 +0100 Subject: [PATCH 05/24] Get rid of whitespace in $(d) --- mk/lib.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/lib.mk b/mk/lib.mk index 60b6815e..f093ee8e 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -47,7 +47,7 @@ include mk/tests.mk # Include all sub-Makefiles. define include-sub-makefile = - d := $$(patsubst %/, %, $$(dir $(1))) + d := $$(patsubst %/,%,$$(dir $(1))) include $(1) endef From 034bbcafafdbec0b2c4d29b1d5018bec20120e77 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:27:47 +0100 Subject: [PATCH 06/24] Add 'make help' --- mk/lib.mk | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mk/lib.mk b/mk/lib.mk index f093ee8e..0b469a13 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -65,3 +65,27 @@ $(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) all: $(programs_list) $(libs_list) + + +help: + @echo "The following targets are available:" + @echo "" + @echo " default: Build default targets" + @echo " install: Install into \$$(prefix) (currently set to '$(prefix)')" + @echo " clean: Delete generated files" + @echo " dryclean: Show what files would be deleted by 'make clean'" +ifdef PACKAGE_NAME + @echo " dist: Generate a source distribution" +endif +ifdef programs_list + @echo "" + @echo "The following programs can be built:" + @echo "" + @for i in $(programs_list); do echo " $$i"; done +endif +ifdef libs_list + @echo "" + @echo "The following libraries can be built:" + @echo "" + @for i in $(libs_list); do echo " $$i"; done +endif From 4da804651378b612313c8fb71688f71a4717a26e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 Dec 2013 11:39:58 +0100 Subject: [PATCH 07/24] Don't include all *.dep files --- mk/libraries.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mk/libraries.mk b/mk/libraries.mk index 58c67063..bea68449 100644 --- a/mk/libraries.mk +++ b/mk/libraries.mk @@ -89,9 +89,11 @@ define build-library = # Propagate CXXFLAGS to the individual object files. $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) - include $$(wildcard $$(_d)/*.dep) + # Include .dep files, if they exist. + $(1)_DEPS := $$(addsuffix .dep, $$(basename $$(_srcs))) + -include $$($(1)_DEPS) libs_list += $$($(1)_PATH) - clean_files += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep + clean_files += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) dist_files += $$(_srcs) endef From a630635d7f0e63a865ddd3b0a3cf2d44c603c0e5 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 16 Dec 2013 16:49:41 +0100 Subject: [PATCH 08/24] No longer interpret $(..._SOURCES) relative to $(..._DIR) --- mk/libraries.mk | 11 ++++++++--- mk/programs.mk | 15 ++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mk/libraries.mk b/mk/libraries.mk index bea68449..bc258b79 100644 --- a/mk/libraries.mk +++ b/mk/libraries.mk @@ -6,11 +6,13 @@ libs_list := # - $(1)_NAME: the name of the library (e.g. ‘libfoo’); defaults to # $(1). # -# - $(1)_DIR: the directory containing the sources of the library, and -# where the (non-installed) library will be placed. +# - $(1)_DIR: the directory where the (non-installed) library will be +# placed. # # - $(1)_SOURCES: the source files of the library. # +# - $(1)_CXXFLAGS: additional C++ compiler flags. +# # - $(1)_LIBS: the symbolic names of other libraries on which this # library depends. # @@ -33,7 +35,7 @@ libs_list := define build-library = $(1)_NAME ?= $(1) _d := $$(strip $$($(1)_DIR)) - _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) + _srcs := $$(foreach src, $$($(1)_SOURCES), $$(src)) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) @@ -89,6 +91,9 @@ define build-library = # Propagate CXXFLAGS to the individual object files. $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) + # Make each object file depend on the common dependencies. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS))) + # Include .dep files, if they exist. $(1)_DEPS := $$(addsuffix .dep, $$(basename $$(_srcs))) -include $$($(1)_DEPS) diff --git a/mk/programs.mk b/mk/programs.mk index 648a6053..52e55598 100644 --- a/mk/programs.mk +++ b/mk/programs.mk @@ -3,8 +3,8 @@ programs_list := # Build a program with symbolic name $(1). The program is defined by # various variables prefixed by ‘$(1)_’: # -# - $(1)_DIR: the directory containing the sources of the program, and -# where the (non-installed) program will be placed. +# - $(1)_DIR: the directory where the (non-installed) program will be +# placed. # # - $(1)_SOURCES: the source files of the program. # @@ -17,7 +17,7 @@ programs_list := # installed; defaults to $(bindir). define build-program = _d := $$($(1)_DIR) - _srcs := $$(foreach src, $$($(1)_SOURCES), $$(_d)/$$(src)) + _srcs := $$(foreach src, $$($(1)_SOURCES), $$(src)) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_PATH := $$(_d)/$(1) @@ -49,9 +49,14 @@ define build-program = # Propagate CXXFLAGS to the individual object files. $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS))) - include $$(wildcard $$(_d)/*.dep) + # Make each object file depend on the common dependencies. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS))) + + # Include .dep files, if they exist. + $(1)_DEPS := $$(addsuffix .dep, $$(basename $$(_srcs))) + -include $$($(1)_DEPS) programs_list += $$($(1)_PATH) - clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/*.dep + clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) dist_files += $$(_srcs) endef From e81b82a2cf0c7e460d02c554c597a6cf9a144e8e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 16 Dec 2013 16:51:05 +0100 Subject: [PATCH 09/24] make dryclean: Sort names --- mk/clean.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/clean.mk b/mk/clean.mk index 703e32e2..7dba76c5 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -4,4 +4,4 @@ clean: $(QUIET) rm -fv -- $(clean_files) dryclean: - @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done + @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done | sort From 088552b319d8f5896e6cfd6a8e449b4239696ea2 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 17 Dec 2013 12:13:48 +0100 Subject: [PATCH 10/24] Set default installation paths --- mk/lib.mk | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mk/lib.mk b/mk/lib.mk index 0b469a13..cec4eee1 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -1,11 +1,6 @@ default: all -# Include Autoconf variables. -template_files += Makefile.config -include Makefile.config - - # Get rid of default suffixes. FIXME: is this a good idea? .SUFFIXES: @@ -16,8 +11,18 @@ bin_SCRIPTS := noinst_SCRIPTS := +# Default installation paths. +prefix ?= /usr/local +libdir ?= $(prefix)/lib +bindir ?= $(prefix)/bin +libexecdir ?= $(prefix)/libexec +datadir ?= $(prefix)/share +localstatedir ?= $(prefix)/var +sysconfdir ?= $(prefix)/etc + + # Pass -fPIC if we're building dynamic libraries. -BUILD_SHARED_LIBS = 1 +BUILD_SHARED_LIBS ?= 1 ifeq ($(BUILD_SHARED_LIBS), 1) GLOBAL_CFLAGS += -fPIC @@ -27,7 +32,7 @@ endif # Pass -g if we want debug info. -BUILD_DEBUG = 1 +BUILD_DEBUG ?= 1 ifeq ($(BUILD_DEBUG), 1) GLOBAL_CFLAGS += -g From 99ed25accfd968003d3b0d294720828a1348ce47 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Dec 2013 15:01:14 +0100 Subject: [PATCH 11/24] Add a function for doing recursive wildcard searches Source: http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html --- mk/lib.mk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mk/lib.mk b/mk/lib.mk index cec4eee1..1d2f0516 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -40,6 +40,11 @@ ifeq ($(BUILD_DEBUG), 1) endif +# Utility function for recursively finding files, e.g. +# ‘$(call rwildcard, path/to/dir, *.c *.h)’. +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + + include mk/clean.mk include mk/dist.mk include mk/install.mk From 259086de841d155f7951c2cc50f799a4631aa512 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Dec 2013 16:40:48 +0100 Subject: [PATCH 12/24] Add support for building JARs from Java sources --- mk/jars.mk | 29 +++++++++++++++++++++++++++++ mk/lib.mk | 11 ++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 mk/jars.mk diff --git a/mk/jars.mk b/mk/jars.mk new file mode 100644 index 00000000..5d459c0a --- /dev/null +++ b/mk/jars.mk @@ -0,0 +1,29 @@ +define build-jar = + $(1)_NAME ?= $(1) + + _d := $$(strip $$($(1)_DIR)) + + $(1)_PATH := $$(_d)/$$($(1)_NAME).jar + + $(1)_TMPDIR := $$(_d)/.$$($(1)_NAME).jar.tmp + + $$($(1)_PATH): $$($(1)_SOURCES) + @rm -rf $$($(1)_TMPDIR) + @mkdir -p $$($(1)_TMPDIR) + $(QUIET) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) $$($(1)_SOURCES) + $(QUIET) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) . + @rm -rf $$($(1)_TMPDIR) + + $(1)_INSTALL_DIR ?= $$(libdir)/java + + $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).jar + + $$(eval $$(call install-file-as, $$($(1)_PATH), $$($(1)_INSTALL_PATH), 0644)) + + install: $$($(1)_INSTALL_PATH) + + jars_list += $$($(1)_PATH) + + clean_files += $$($(1)_PATH) + +endef diff --git a/mk/lib.mk b/mk/lib.mk index 1d2f0516..2d8ceef5 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -37,6 +37,7 @@ BUILD_DEBUG ?= 1 ifeq ($(BUILD_DEBUG), 1) GLOBAL_CFLAGS += -g GLOBAL_CXXFLAGS += -g + GLOBAL_JAVACFLAGS += -g endif @@ -50,6 +51,7 @@ include mk/dist.mk include mk/install.mk include mk/libraries.mk include mk/programs.mk +include mk/jars.mk include mk/patterns.mk include mk/templates.mk include mk/tests.mk @@ -67,6 +69,7 @@ $(foreach mf, $(SUBS), $(eval $(call include-sub-makefile, $(mf)))) # Instantiate stuff. $(foreach lib, $(LIBS), $(eval $(call build-library,$(lib)))) $(foreach prog, $(PROGRAMS), $(eval $(call build-program,$(prog)))) +$(foreach jar, $(JARS), $(eval $(call build-jar,$(jar)))) $(foreach script, $(bin_SCRIPTS), $(eval $(call install-program-in,$(script),$(bindir)))) $(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script))) $(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script))) @@ -74,7 +77,7 @@ $(foreach template, $(template_files), $(eval $(call instantiate-template,$(temp $(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) -all: $(programs_list) $(libs_list) +all: $(programs_list) $(libs_list) $(jars_list) help: @@ -99,3 +102,9 @@ ifdef libs_list @echo "" @for i in $(libs_list); do echo " $$i"; done endif +ifdef jars_list + @echo "" + @echo "The following JARs can be built:" + @echo "" + @for i in $(jars_list); do echo " $$i"; done +endif From 55c9a40613fefda6622aa9acd22cce4006fd1077 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Jan 2014 16:12:02 +0100 Subject: [PATCH 13/24] Move stuff to top-level This makes it easier to use with "git subtree". --- mk/clean.mk => clean.mk | 0 mk/dist.mk => dist.mk | 0 mk/install.mk => install.mk | 0 mk/jars.mk => jars.mk | 0 mk/lib.mk => lib.mk | 0 mk/libraries.mk => libraries.mk | 0 mk/patterns.mk => patterns.mk | 0 mk/programs.mk => programs.mk | 0 mk/templates.mk => templates.mk | 0 mk/tests.mk => tests.mk | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename mk/clean.mk => clean.mk (100%) rename mk/dist.mk => dist.mk (100%) rename mk/install.mk => install.mk (100%) rename mk/jars.mk => jars.mk (100%) rename mk/lib.mk => lib.mk (100%) rename mk/libraries.mk => libraries.mk (100%) rename mk/patterns.mk => patterns.mk (100%) rename mk/programs.mk => programs.mk (100%) rename mk/templates.mk => templates.mk (100%) rename mk/tests.mk => tests.mk (100%) diff --git a/mk/clean.mk b/clean.mk similarity index 100% rename from mk/clean.mk rename to clean.mk diff --git a/mk/dist.mk b/dist.mk similarity index 100% rename from mk/dist.mk rename to dist.mk diff --git a/mk/install.mk b/install.mk similarity index 100% rename from mk/install.mk rename to install.mk diff --git a/mk/jars.mk b/jars.mk similarity index 100% rename from mk/jars.mk rename to jars.mk diff --git a/mk/lib.mk b/lib.mk similarity index 100% rename from mk/lib.mk rename to lib.mk diff --git a/mk/libraries.mk b/libraries.mk similarity index 100% rename from mk/libraries.mk rename to libraries.mk diff --git a/mk/patterns.mk b/patterns.mk similarity index 100% rename from mk/patterns.mk rename to patterns.mk diff --git a/mk/programs.mk b/programs.mk similarity index 100% rename from mk/programs.mk rename to programs.mk diff --git a/mk/templates.mk b/templates.mk similarity index 100% rename from mk/templates.mk rename to templates.mk diff --git a/mk/tests.mk b/tests.mk similarity index 100% rename from mk/tests.mk rename to tests.mk From 814a73227f9571d8fbd831fedced5e87cd9c926b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Jan 2014 16:54:01 +0100 Subject: [PATCH 14/24] Remove duplicate elements from *_SOURCES This is useful when you do: foo_SOURCES := $(wildcard *.cc) foo.cc where foo.cc is a generated file. In this case, if foo.cc already exists, you get foo.cc twice in foo_SOURCES, leading to a link error. --- libraries.mk | 2 +- programs.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries.mk b/libraries.mk index bc258b79..98cc9f36 100644 --- a/libraries.mk +++ b/libraries.mk @@ -35,7 +35,7 @@ libs_list := define build-library = $(1)_NAME ?= $(1) _d := $$(strip $$($(1)_DIR)) - _srcs := $$(foreach src, $$($(1)_SOURCES), $$(src)) + _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) diff --git a/programs.mk b/programs.mk index 52e55598..a97a5163 100644 --- a/programs.mk +++ b/programs.mk @@ -17,7 +17,7 @@ programs_list := # installed; defaults to $(bindir). define build-program = _d := $$($(1)_DIR) - _srcs := $$(foreach src, $$($(1)_SOURCES), $$(src)) + _srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) $(1)_PATH := $$(_d)/$(1) From 70d8e8fdded9e21995fecc3ecc68e14cf4f53be7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Jan 2014 16:57:38 +0100 Subject: [PATCH 15/24] Declare template_files as a simply expanded variable --- templates.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates.mk b/templates.mk index fa91e250..01b9d9d7 100644 --- a/templates.mk +++ b/templates.mk @@ -1,3 +1,5 @@ +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 = From e991ab942b6ed1bc50a63afafe55ffe5cae8cbad Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 9 Jan 2014 22:14:34 +0100 Subject: [PATCH 16/24] Add support for building shared libraries on Mac OS X --- lib.mk | 5 ++++- libraries.mk | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib.mk b/lib.mk index 2d8ceef5..5b0d2633 100644 --- a/lib.mk +++ b/lib.mk @@ -9,6 +9,7 @@ default: all QUIET = @ bin_SCRIPTS := noinst_SCRIPTS := +OS = $(shell uname -s) # Default installation paths. @@ -27,7 +28,9 @@ BUILD_SHARED_LIBS ?= 1 ifeq ($(BUILD_SHARED_LIBS), 1) GLOBAL_CFLAGS += -fPIC GLOBAL_CXXFLAGS += -fPIC - GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries + ifneq ($(OS), Darwin) + GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries + endif endif diff --git a/libraries.mk b/libraries.mk index 98cc9f36..818c3d21 100644 --- a/libraries.mk +++ b/libraries.mk @@ -1,5 +1,11 @@ libs_list := +ifeq ($(OS), Darwin) + SO_EXT = dylib +else + SO_EXT = so +endif + # Build a library with symbolic name $(1). The library is defined by # various variables prefixed by ‘$(1)_’: # @@ -46,18 +52,24 @@ define build-library = ifeq ($(BUILD_SHARED_LIBS), 1) - ifndef $(1)_ALLOW_UNDEFINED - $(1)_LDFLAGS += -z defs + ifdef $(1)_ALLOW_UNDEFINED + ifeq ($(OS), Darwin) + $(1)_LDFLAGS += -undefined suppress -flat_namespace + endif + else + ifneq ($(OS), Darwin) + $(1)_LDFLAGS += -z defs + endif endif - $(1)_PATH := $$(_d)/$$($(1)_NAME).so + $(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT) $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) $(QUIET) $(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))) - $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).so + $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT) _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) @@ -99,6 +111,6 @@ define build-library = -include $$($(1)_DEPS) libs_list += $$($(1)_PATH) - clean_files += $$(_d)/*.a $$(_d)/*.so $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) + clean_files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) dist_files += $$(_srcs) endef From ca73c0102fc68ece171d7cc062e464b4d418d07c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 10 Jan 2014 22:31:38 +0100 Subject: [PATCH 17/24] Nicer Make output E.g. CXX src/nix-log2xml/log2xml.o CC src/bsdiff-4.3/bsdiff.o GEN scripts/nix-channel LD src/libmain/libnixmain.so --- clean.mk | 2 +- dist.mk | 2 +- install.mk | 6 +++--- jars.mk | 4 ++-- lib.mk | 2 +- libraries.mk | 6 +++--- patterns.mk | 6 +++--- programs.mk | 4 ++-- templates.mk | 2 +- tracing.mk | 16 ++++++++++++++++ 10 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 tracing.mk diff --git a/clean.mk b/clean.mk index 7dba76c5..f45d578a 100644 --- a/clean.mk +++ b/clean.mk @@ -1,7 +1,7 @@ clean_files := clean: - $(QUIET) rm -fv -- $(clean_files) + $(suppress) rm -fv -- $(clean_files) dryclean: @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done | sort diff --git a/dist.mk b/dist.mk index 444c58b3..bf97b697 100644 --- a/dist.mk +++ b/dist.mk @@ -7,7 +7,7 @@ dist_files := dist: $(dist_name).tar.bz2 $(dist_name).tar.bz2: $(dist_files) - $(QUIET) tar cvfj $@ $(dist_files) --transform 's,^,$(dist_name)/,' + $(suppress) tar cvfj $@ $(dist_files) --transform 's,^,$(dist_name)/,' clean_files += $(dist_name).tar.bz2 diff --git a/install.mk b/install.mk index c5eb8eb3..aee4bf38 100644 --- a/install.mk +++ b/install.mk @@ -4,7 +4,7 @@ define create-dir = ifndef $(1)_SEEN $(1)_SEEN = 1 $(1): - $(QUIET) install -d $(1) + $$(trace-install) install -d $(1) endif endef @@ -18,7 +18,7 @@ define install-file-as = $$(eval $$(call create-dir,$$(dir $(2)))) $(2): $(1) | $$(dir $(2)) - $(QUIET) install -m $(3) $(1) $(2) + $$(trace-install) install -m $(3) $(1) $(2) endef @@ -48,6 +48,6 @@ define install-symlink = $$(eval $$(call create-dir,$$(dir $(2)))) $(2): | $$(dir $(2)) - $(QUIET) ln -sfn $(1) $(2) + $$(trace-install) ln -sfn $(1) $(2) endef diff --git a/jars.mk b/jars.mk index 5d459c0a..c8075cde 100644 --- a/jars.mk +++ b/jars.mk @@ -10,8 +10,8 @@ define build-jar = $$($(1)_PATH): $$($(1)_SOURCES) @rm -rf $$($(1)_TMPDIR) @mkdir -p $$($(1)_TMPDIR) - $(QUIET) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) $$($(1)_SOURCES) - $(QUIET) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) . + $$(trace-javac) javac $(GLOBAL_JAVACFLAGS) $$($(1)_JAVACFLAGS) -d $$($(1)_TMPDIR) $$($(1)_SOURCES) + $$(trace-jar) jar cf $$($(1)_PATH) -C $$($(1)_TMPDIR) . @rm -rf $$($(1)_TMPDIR) $(1)_INSTALL_DIR ?= $$(libdir)/java diff --git a/lib.mk b/lib.mk index 5b0d2633..8894d530 100644 --- a/lib.mk +++ b/lib.mk @@ -6,7 +6,6 @@ default: all # Initialise some variables. -QUIET = @ bin_SCRIPTS := noinst_SCRIPTS := OS = $(shell uname -s) @@ -49,6 +48,7 @@ endif rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) +include mk/tracing.mk include mk/clean.mk include mk/dist.mk include mk/install.mk diff --git a/libraries.mk b/libraries.mk index 818c3d21..1e0fe49a 100644 --- a/libraries.mk +++ b/libraries.mk @@ -65,7 +65,7 @@ define build-library = $(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT) $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) - $(QUIET) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) + $$(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))) @@ -76,7 +76,7 @@ define build-library = $$(eval $$(call create-dir,$$($(1)_INSTALL_DIR))) $$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $$($(1)_INSTALL_DIR) - $(QUIET) $(CXX) -o $$@ -shared $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) + $$(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))) @@ -89,7 +89,7 @@ define build-library = $(1)_PATH := $$(_d)/$$($(1)_NAME).a $$($(1)_PATH): $$($(1)_OBJS) - $(QUIET) ar crs $$@ $$? + $(trace-ar) ar crs $$@ $$? $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) diff --git a/patterns.mk b/patterns.mk index 77e17213..91a758f3 100644 --- a/patterns.mk +++ b/patterns.mk @@ -1,8 +1,8 @@ %.o: %.cc - $(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP %.o: %.cpp - $(QUIET) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP %.o: %.c - $(QUIET) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP + $(trace-cc) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP diff --git a/programs.mk b/programs.mk index a97a5163..c608a6f2 100644 --- a/programs.mk +++ b/programs.mk @@ -23,7 +23,7 @@ define build-program = $(1)_PATH := $$(_d)/$(1) $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) - $(QUIET) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) + $$(trace-ld) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $(1)_INSTALL_DIR ?= $$(bindir) $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1) @@ -37,7 +37,7 @@ define build-program = _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) $$($(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)) + $$(trace-ld) $(CXX) -o $$@ $(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED)) else diff --git a/templates.mk b/templates.mk index 01b9d9d7..82f9d602 100644 --- a/templates.mk +++ b/templates.mk @@ -9,4 +9,4 @@ define instantiate-template = endef %: %.in - $(QUIET) ./config.status --quiet --file $@ + $(trace-gen) ./config.status --quiet --file $@ diff --git a/tracing.mk b/tracing.mk new file mode 100644 index 00000000..08c4ec10 --- /dev/null +++ b/tracing.mk @@ -0,0 +1,16 @@ +V ?= 0 + +ifeq ($(V), 0) + + trace-gen = @echo " GEN " $@; + trace-cc = @echo " CC " $@; + trace-cxx = @echo " CXX " $@; + trace-ld = @echo " LD " $@; + trace-ar = @echo " AR " $@; + trace-install = @echo " INST " $@; + trace-javac = @echo " JAVAC " $@; + trace-jar = @echo " JAR " $@; + + suppress = @ + +endif From 5311b2b25084e53ff132df96d66ab06efead0853 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 23 Jan 2014 10:49:53 +0100 Subject: [PATCH 18/24] Clang doesn't know the "-z defs" flag --- libraries.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries.mk b/libraries.mk index 1e0fe49a..90eb125a 100644 --- a/libraries.mk +++ b/libraries.mk @@ -58,7 +58,7 @@ define build-library = endif else ifneq ($(OS), Darwin) - $(1)_LDFLAGS += -z defs + $(1)_LDFLAGS += -Wl,-z,defs endif endif From 4271927c5be2c5b87ca83682d1f2bd71d5ce4a66 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 31 Jan 2014 15:33:12 +0100 Subject: [PATCH 19/24] Add support for installing man-pages --- lib.mk | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib.mk b/lib.mk index 8894d530..cbed773f 100644 --- a/lib.mk +++ b/lib.mk @@ -8,6 +8,7 @@ default: all # Initialise some variables. bin_SCRIPTS := noinst_SCRIPTS := +man-pages := OS = $(shell uname -s) @@ -19,6 +20,7 @@ libexecdir ?= $(prefix)/libexec datadir ?= $(prefix)/share localstatedir ?= $(prefix)/var sysconfdir ?= $(prefix)/etc +mandir ?= $(prefix)/share/man # Pass -fPIC if we're building dynamic libraries. @@ -78,9 +80,14 @@ $(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script))) $(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script))) $(foreach template, $(template_files), $(eval $(call instantiate-template,$(template)))) $(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) +$(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file)))))) -all: $(programs_list) $(libs_list) $(jars_list) +.PHONY: all man help + +all: $(programs_list) $(libs_list) $(jars_list) $(man-pages) + +man: $(man-pages) help: @@ -93,6 +100,9 @@ help: ifdef PACKAGE_NAME @echo " dist: Generate a source distribution" endif +ifdef man-pages + @echo " man: Generate manual pages" +endif ifdef programs_list @echo "" @echo "The following programs can be built:" From f324b49ea19e606f84b89ecb499f0e961646cd50 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2014 11:31:25 +0100 Subject: [PATCH 20/24] Change dependency file names from foo.dep to .foo.o.dep --- dist.mk | 2 ++ install.mk | 4 ++++ lib.mk | 6 +----- libraries.mk | 4 ++-- patterns.mk | 6 +++--- programs.mk | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dist.mk b/dist.mk index bf97b697..cd11463e 100644 --- a/dist.mk +++ b/dist.mk @@ -11,4 +11,6 @@ $(dist_name).tar.bz2: $(dist_files) clean_files += $(dist_name).tar.bz2 +print-top-help += echo " dist: Generate a source distribution"; + endif diff --git a/install.mk b/install.mk index aee4bf38..093f30b8 100644 --- a/install.mk +++ b/install.mk @@ -51,3 +51,7 @@ define install-symlink = $$(trace-install) ln -sfn $(1) $(2) endef + + +print-top-help += \ + echo " install: Install into \$$(prefix) (currently set to '$(prefix)')"; diff --git a/lib.mk b/lib.mk index cbed773f..f43fdd56 100644 --- a/lib.mk +++ b/lib.mk @@ -45,11 +45,7 @@ ifeq ($(BUILD_DEBUG), 1) endif -# Utility function for recursively finding files, e.g. -# ‘$(call rwildcard, path/to/dir, *.c *.h)’. -rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) - - +include mk/functions.mk include mk/tracing.mk include mk/clean.mk include mk/dist.mk diff --git a/libraries.mk b/libraries.mk index 90eb125a..461a3e9a 100644 --- a/libraries.mk +++ b/libraries.mk @@ -107,10 +107,10 @@ define build-library = $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS))) # Include .dep files, if they exist. - $(1)_DEPS := $$(addsuffix .dep, $$(basename $$(_srcs))) + $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) -include $$($(1)_DEPS) libs_list += $$($(1)_PATH) - clean_files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) + clean_files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) dist_files += $$(_srcs) endef diff --git a/patterns.mk b/patterns.mk index 91a758f3..f5674d40 100644 --- a/patterns.mk +++ b/patterns.mk @@ -1,8 +1,8 @@ %.o: %.cc - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP %.o: %.cpp - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(basename $@).dep -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP %.o: %.c - $(trace-cc) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(basename $@).dep -MP + $(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 c608a6f2..0478e16d 100644 --- a/programs.mk +++ b/programs.mk @@ -53,10 +53,10 @@ define build-program = $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS))) # Include .dep files, if they exist. - $(1)_DEPS := $$(addsuffix .dep, $$(basename $$(_srcs))) + $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) -include $$($(1)_DEPS) programs_list += $$($(1)_PATH) - clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/*.dep $$($(1)_DEPS) $$($(1)_OBJS) + clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) dist_files += $$(_srcs) endef From 35107038f7c726f5ef8d7ab014ad45c73970e65d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2014 11:47:34 +0100 Subject: [PATCH 21/24] Support adding "make help" text --- clean.mk | 4 ++++ lib.mk | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/clean.mk b/clean.mk index f45d578a..51bfd3bc 100644 --- a/clean.mk +++ b/clean.mk @@ -5,3 +5,7 @@ clean: dryclean: @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done | sort + +print-top-help += \ + echo " clean: Delete generated files"; \ + echo " dryclean: Show what files would be deleted by 'make clean'"; diff --git a/lib.mk b/lib.mk index f43fdd56..649c3b50 100644 --- a/lib.mk +++ b/lib.mk @@ -79,7 +79,7 @@ $(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) $(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file)))))) -.PHONY: all man help +.PHONY: default all man help all: $(programs_list) $(libs_list) $(jars_list) $(man-pages) @@ -90,15 +90,10 @@ help: @echo "The following targets are available:" @echo "" @echo " default: Build default targets" - @echo " install: Install into \$$(prefix) (currently set to '$(prefix)')" - @echo " clean: Delete generated files" - @echo " dryclean: Show what files would be deleted by 'make clean'" -ifdef PACKAGE_NAME - @echo " dist: Generate a source distribution" -endif ifdef man-pages @echo " man: Generate manual pages" endif + @$(print-top-help) ifdef programs_list @echo "" @echo "The following programs can be built:" @@ -117,3 +112,13 @@ ifdef jars_list @echo "" @for i in $(jars_list); do echo " $$i"; done endif + @echo "" + @echo "The following variables control the build:" + @echo "" + @echo " BUILD_SHARED_LIBS ($(BUILD_SHARED_LIBS)): Whether to build shared libraries" + @echo " BUILD_DEBUG ($(BUILD_DEBUG)): Whether to include debug symbols" + @echo " CC ($(CC)): C compiler to be used" + @echo " CFLAGS: Flags for the C compiler" + @echo " CXX ($(CXX)): C++ compiler to be used" + @echo " CXXFLAGS: Flags for the C++ compiler" + @$(print-var-help) From ec1738589a3aa1dd59e476de09ae2721d51b3e6e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2014 12:20:06 +0100 Subject: [PATCH 22/24] Make variable names more regular --- clean.mk | 6 +++--- dist.mk | 12 ++++++------ jars.mk | 4 ++-- lib.mk | 37 +++++++++++++++++++------------------ libraries.mk | 8 ++++---- programs.mk | 8 ++++---- templates.mk | 4 ++-- tests.mk | 6 +++--- 8 files changed, 43 insertions(+), 42 deletions(-) diff --git a/clean.mk b/clean.mk index 51bfd3bc..ce9afb3b 100644 --- a/clean.mk +++ b/clean.mk @@ -1,10 +1,10 @@ -clean_files := +clean-files := clean: - $(suppress) rm -fv -- $(clean_files) + $(suppress) rm -fv -- $(clean-files) dryclean: - @for i in $(clean_files); do if [ -e $$i ]; then echo $$i; fi; done | sort + @for i in $(clean-files); do if [ -e $$i ]; then echo $$i; fi; done | sort print-top-help += \ echo " clean: Delete generated files"; \ diff --git a/dist.mk b/dist.mk index cd11463e..0ce4377a 100644 --- a/dist.mk +++ b/dist.mk @@ -1,15 +1,15 @@ ifdef PACKAGE_NAME -dist_name = $(PACKAGE_NAME)-$(PACKAGE_VERSION) +dist-name = $(PACKAGE_NAME)-$(PACKAGE_VERSION) -dist_files := +dist-files := -dist: $(dist_name).tar.bz2 +dist: $(dist-name).tar.bz2 -$(dist_name).tar.bz2: $(dist_files) - $(suppress) tar cvfj $@ $(dist_files) --transform 's,^,$(dist_name)/,' +$(dist-name).tar.bz2: $(dist-files) + $(suppress) tar cvfj $@ $(dist-files) --transform 's,^,$(dist-name)/,' -clean_files += $(dist_name).tar.bz2 +clean-files += $(dist-name).tar.bz2 print-top-help += echo " dist: Generate a source distribution"; diff --git a/jars.mk b/jars.mk index c8075cde..9595c1c4 100644 --- a/jars.mk +++ b/jars.mk @@ -22,8 +22,8 @@ define build-jar = install: $$($(1)_INSTALL_PATH) - jars_list += $$($(1)_PATH) + jars-list += $$($(1)_PATH) - clean_files += $$($(1)_PATH) + clean-files += $$($(1)_PATH) endef diff --git a/lib.mk b/lib.mk index 649c3b50..d930b0ef 100644 --- a/lib.mk +++ b/lib.mk @@ -6,9 +6,10 @@ default: all # Initialise some variables. -bin_SCRIPTS := -noinst_SCRIPTS := +bin-scripts := +noinst-scripts := man-pages := +install-tests := OS = $(shell uname -s) @@ -64,24 +65,24 @@ define include-sub-makefile = include $(1) endef -$(foreach mf, $(SUBS), $(eval $(call include-sub-makefile, $(mf)))) +$(foreach mf, $(makefiles), $(eval $(call include-sub-makefile, $(mf)))) # Instantiate stuff. -$(foreach lib, $(LIBS), $(eval $(call build-library,$(lib)))) -$(foreach prog, $(PROGRAMS), $(eval $(call build-program,$(prog)))) -$(foreach jar, $(JARS), $(eval $(call build-jar,$(jar)))) -$(foreach script, $(bin_SCRIPTS), $(eval $(call install-program-in,$(script),$(bindir)))) -$(foreach script, $(bin_SCRIPTS), $(eval programs_list += $(script))) -$(foreach script, $(noinst_SCRIPTS), $(eval programs_list += $(script))) -$(foreach template, $(template_files), $(eval $(call instantiate-template,$(template)))) -$(foreach test, $(INSTALL_TESTS), $(eval $(call run-install-test,$(test)))) +$(foreach lib, $(libraries), $(eval $(call build-library,$(lib)))) +$(foreach prog, $(programs), $(eval $(call build-program,$(prog)))) +$(foreach jar, $(jars), $(eval $(call build-jar,$(jar)))) +$(foreach script, $(bin-scripts), $(eval $(call install-program-in,$(script),$(bindir)))) +$(foreach script, $(bin-scripts), $(eval programs-list += $(script))) +$(foreach script, $(noinst-scripts), $(eval programs-list += $(script))) +$(foreach template, $(template-files), $(eval $(call instantiate-template,$(template)))) +$(foreach test, $(install-tests), $(eval $(call run-install-test,$(test)))) $(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file)))))) .PHONY: default all man help -all: $(programs_list) $(libs_list) $(jars_list) $(man-pages) +all: $(programs-list) $(libs-list) $(jars-list) $(man-pages) man: $(man-pages) @@ -94,23 +95,23 @@ ifdef man-pages @echo " man: Generate manual pages" endif @$(print-top-help) -ifdef programs_list +ifdef programs-list @echo "" @echo "The following programs can be built:" @echo "" - @for i in $(programs_list); do echo " $$i"; done + @for i in $(programs-list); do echo " $$i"; done endif -ifdef libs_list +ifdef libs-list @echo "" @echo "The following libraries can be built:" @echo "" - @for i in $(libs_list); do echo " $$i"; done + @for i in $(libs-list); do echo " $$i"; done endif -ifdef jars_list +ifdef jars-list @echo "" @echo "The following JARs can be built:" @echo "" - @for i in $(jars_list); do echo " $$i"; done + @for i in $(jars-list); do echo " $$i"; done endif @echo "" @echo "The following variables control the build:" diff --git a/libraries.mk b/libraries.mk index 461a3e9a..a6965325 100644 --- a/libraries.mk +++ b/libraries.mk @@ -1,4 +1,4 @@ -libs_list := +libs-list := ifeq ($(OS), Darwin) SO_EXT = dylib @@ -110,7 +110,7 @@ define build-library = $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) -include $$($(1)_DEPS) - libs_list += $$($(1)_PATH) - clean_files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) - dist_files += $$(_srcs) + libs-list += $$($(1)_PATH) + clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) + dist-files += $$(_srcs) endef diff --git a/programs.mk b/programs.mk index 0478e16d..30539d12 100644 --- a/programs.mk +++ b/programs.mk @@ -1,4 +1,4 @@ -programs_list := +programs-list := # Build a program with symbolic name $(1). The program is defined by # various variables prefixed by ‘$(1)_’: @@ -56,7 +56,7 @@ define build-program = $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) -include $$($(1)_DEPS) - programs_list += $$($(1)_PATH) - clean_files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) - dist_files += $$(_srcs) + programs-list += $$($(1)_PATH) + clean-files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS) + dist-files += $$(_srcs) endef diff --git a/templates.mk b/templates.mk index 82f9d602..6d7b1034 100644 --- a/templates.mk +++ b/templates.mk @@ -1,10 +1,10 @@ -template_files := +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 = - clean_files += $(1) + clean-files += $(1) endef diff --git a/tests.mk b/tests.mk index 8a3bff66..339abd58 100644 --- a/tests.mk +++ b/tests.mk @@ -6,15 +6,15 @@ define run-install-test = # Run the test in its own directory to mimick Automake behaviour. $1.run: $1 $(_PREV_TEST) - _installcheck_list += $1 + _installcheck-list += $1 endef installcheck: install - @total=0; failed=0; for i in $(_installcheck_list); do \ + @total=0; failed=0; for i in $(_installcheck-list); do \ total=$$((total + 1)); \ echo "running test $$i"; \ - if (cd $$(dirname $$i) && $(TESTS_ENVIRONMENT) $$(basename $$i)); then \ + if (cd $$(dirname $$i) && $(tests-environment) $$(basename $$i)); then \ echo "PASS: $$i"; \ else \ echo "FAIL: $$i"; \ From 6f8aa145d43d0453d74e70d1d33cfa6e21fddf89 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2014 14:22:08 +0100 Subject: [PATCH 23/24] Improve "make dist" --- dist.mk | 11 ++++++----- lib.mk | 5 ++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dist.mk b/dist.mk index 0ce4377a..794b2777 100644 --- a/dist.mk +++ b/dist.mk @@ -2,14 +2,15 @@ ifdef PACKAGE_NAME dist-name = $(PACKAGE_NAME)-$(PACKAGE_VERSION) -dist-files := - -dist: $(dist-name).tar.bz2 +dist: $(dist-name).tar.bz2 $(dist-name).tar.xz $(dist-name).tar.bz2: $(dist-files) - $(suppress) tar cvfj $@ $(dist-files) --transform 's,^,$(dist-name)/,' + $(trace-gen) tar cfj $@ $(sort $(dist-files)) --transform 's,^,$(dist-name)/,' -clean-files += $(dist-name).tar.bz2 +$(dist-name).tar.xz: $(dist-files) + $(trace-gen) tar cfJ $@ $(sort $(dist-files)) --transform 's,^,$(dist-name)/,' + +clean-files += $(dist-name).tar.bz2 $(dist-name).tar.xz print-top-help += echo " dist: Generate a source distribution"; diff --git a/lib.mk b/lib.mk index d930b0ef..6e02bc91 100644 --- a/lib.mk +++ b/lib.mk @@ -10,6 +10,7 @@ bin-scripts := noinst-scripts := man-pages := install-tests := +dist-files := OS = $(shell uname -s) @@ -49,7 +50,6 @@ endif include mk/functions.mk include mk/tracing.mk include mk/clean.mk -include mk/dist.mk include mk/install.mk include mk/libraries.mk include mk/programs.mk @@ -80,6 +80,9 @@ $(foreach test, $(install-tests), $(eval $(call run-install-test,$(test)))) $(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file)))))) +include mk/dist.mk + + .PHONY: default all man help all: $(programs-list) $(libs-list) $(jars-list) $(man-pages) From 1eff3ad37fdb9dcf9f8528fdacea0ebf0e79d545 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 1 Feb 2014 14:36:44 +0100 Subject: [PATCH 24/24] Add missing file --- functions.mk | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 functions.mk diff --git a/functions.mk b/functions.mk new file mode 100644 index 00000000..51f64570 --- /dev/null +++ b/functions.mk @@ -0,0 +1,7 @@ +# Utility function for recursively finding files, e.g. +# ‘$(call rwildcard, path/to/dir, *.c *.h)’. +rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d)) + +# Given a file name, produce the corresponding dependency file +# (e.g. ‘foo/bar.o’ becomes ‘foo/.bar.o.dep’). +filename-to-dep = $(dir $1).$(notdir $1).dep