diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-03T15·37+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-04-03T15·37+0200 |
commit | daa16cca11304a0e91a188176959e2af28be1f57 (patch) | |
tree | 5eec8af63571cc622799bd9593a371daf1534ea1 /mk | |
parent | f0de86357c18e18eccd814c8bea3bfdaf10f75f5 (diff) | |
parent | 7191a7394a3091ed2856508674f84f3a87eda5a6 (diff) |
Sync with make-rules repo
Diffstat (limited to 'mk')
-rw-r--r-- | mk/functions.mk | 7 | ||||
-rw-r--r-- | mk/install.mk | 2 | ||||
-rw-r--r-- | mk/lib.mk | 3 | ||||
-rw-r--r-- | mk/libraries.mk | 26 | ||||
-rw-r--r-- | mk/patterns.mk | 4 | ||||
-rw-r--r-- | mk/programs.mk | 19 |
6 files changed, 43 insertions, 18 deletions
diff --git a/mk/functions.mk b/mk/functions.mk index 51f6457016e7..45d917399391 100644 --- a/mk/functions.mk +++ b/mk/functions.mk @@ -5,3 +5,10 @@ rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst # 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 + +# Return the full path to a program by looking it up in $PATH, or the +# 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. +add-trailing-slash = $(patsubst %/,%,$(1))/ diff --git a/mk/install.mk b/mk/install.mk index e4bc734e11fb..dad0fd8533ab 100644 --- a/mk/install.mk +++ b/mk/install.mk @@ -1,7 +1,7 @@ # Add a rule for creating $(1) as a directory. This template may be # called multiple times for the same directory. define create-dir - _i := $(DESTDIR)$$(strip $(1)) + _i := $$(call add-trailing-slash, $(DESTDIR)$$(strip $(1))) ifndef $$(_i)_SEEN $$(_i)_SEEN = 1 $$(_i): diff --git a/mk/lib.mk b/mk/lib.mk index 6bcd83a06e5f..56e162d5007c 100644 --- a/mk/lib.mk +++ b/mk/lib.mk @@ -32,8 +32,11 @@ ifeq ($(BUILD_SHARED_LIBS), 1) GLOBAL_CFLAGS += -fPIC GLOBAL_CXXFLAGS += -fPIC ifneq ($(OS), Darwin) + ifneq ($(OS), SunOS) GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries + endif endif + SET_RPATH_TO_LIBS ?= 1 endif diff --git a/mk/libraries.mk b/mk/libraries.mk index c41694794b60..4b8292cc20d2 100644 --- a/mk/libraries.mk +++ b/mk/libraries.mk @@ -17,6 +17,8 @@ endif # # - $(1)_SOURCES: the source files of the library. # +# - $(1)_CFLAGS: additional C compiler flags. +# # - $(1)_CXXFLAGS: additional C++ compiler flags. # # - $(1)_LIBS: the symbolic names of other libraries on which this @@ -64,10 +66,14 @@ define build-library endif endif + ifneq ($(OS), Darwin) + $(1)_LDFLAGS += -Wl,-soname=$$($(1)_NAME).$(SO_EXT) + endif + $(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)) + $$($(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))) @@ -77,10 +83,13 @@ define build-library $$(eval $$(call create-dir, $$($(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)_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$$(DESTDIR)$$($(1)_INSTALL_DIR) -Wl,-rpath,$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME))) + $(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) + endif ifdef $(1)_FORCE_INSTALL install: $$($(1)_INSTALL_PATH) @@ -90,7 +99,7 @@ define build-library $(1)_PATH := $$(_d)/$$($(1)_NAME).a - $$($(1)_PATH): $$($(1)_OBJS) | $$(_d) + $$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/ $(trace-ar) ar crs $$@ $$? $(1)_LDFLAGS_USE += $$($(1)_PATH) $$($(1)_LDFLAGS) @@ -102,11 +111,12 @@ define build-library $(1)_LDFLAGS_USE += $$($(1)_LDFLAGS_PROPAGATED) $(1)_LDFLAGS_USE_INSTALLED += $$($(1)_LDFLAGS_PROPAGATED) - # Propagate CXXFLAGS to the individual object files. + # Propagate CFLAGS and CXXFLAGS to the individual object files. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CFLAGS=$$($(1)_CFLAGS))) $$(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))) + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS) $$(GLOBAL_COMMON_DEPS))) # Include .dep files, if they exist. $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) diff --git a/mk/patterns.mk b/mk/patterns.mk index f5674d40436c..6b2cfd017050 100644 --- a/mk/patterns.mk +++ b/mk/patterns.mk @@ -1,8 +1,8 @@ %.o: %.cc - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP %.o: %.cpp - $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP + $(trace-cxx) $(CXX) -o $@ -c $< $(GLOBAL_CXXFLAGS) $(GLOBAL_CXXFLAGS_PCH) $(CXXFLAGS) $($@_CXXFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP %.o: %.c $(trace-cc) $(CC) -o $@ -c $< $(GLOBAL_CFLAGS) $(CFLAGS) $($@_CFLAGS) -MMD -MF $(call filename-to-dep, $@) -MP diff --git a/mk/programs.mk b/mk/programs.mk index ab04ff93e910..b6de0689404c 100644 --- a/mk/programs.mk +++ b/mk/programs.mk @@ -8,6 +8,10 @@ programs-list := # # - $(1)_SOURCES: the source files of the program. # +# - $(1)_CFLAGS: additional C compiler flags. +# +# - $(1)_CXXFLAGS: additional C++ compiler flags. +# # - $(1)_LIBS: the symbolic names of libraries on which this program # depends. # @@ -24,8 +28,8 @@ define build-program $$(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)_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) $(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$(1) @@ -38,21 +42,22 @@ define build-program _libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH)) - $(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)) + $(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 - $(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR) + $(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR)/ install -t $$($(1)_INSTALL_DIR) $$< endif - # Propagate CXXFLAGS to the individual object files. + # Propagate CFLAGS and CXXFLAGS to the individual object files. + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CFLAGS=$$($(1)_CFLAGS))) $$(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))) + $$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS) $$(GLOBAL_COMMON_DEPS))) # Include .dep files, if they exist. $(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn))) |