diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-02-01 14:38:28 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-02-01 14:38:28 +0100 |
commit | 74ca70da3a6d2f110a9dccf15c46422b1b078e3f (patch) | |
tree | c21ca3aa2acb4cfb6b669edb43cb4c4fa33ff482 /mk/programs.mk | |
parent | 6ef32bddc1f10034322966b3a5b85af7b9cdc4d8 (diff) | |
parent | 1eff3ad37fdb9dcf9f8528fdacea0ebf0e79d545 (diff) |
Add 'mk/' from commit '1eff3ad37fdb9dcf9f8528fdacea0ebf0e79d545'
git-subtree-dir: mk
git-subtree-mainline: 6ef32bddc1f10034322966b3a5b85af7b9cdc4d8
git-subtree-split: 1eff3ad37fdb9dcf9f8528fdacea0ebf0e79d545
Diffstat (limited to 'mk/programs.mk')
-rw-r--r-- | mk/programs.mk | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/mk/programs.mk b/mk/programs.mk new file mode 100644 index 000000000..30539d129 --- /dev/null +++ b/mk/programs.mk @@ -0,0 +1,62 @@ +programs-list := + +# Build a program with symbolic name $(1). The program is defined by +# various variables prefixed by ‘$(1)_’: +# +# - $(1)_DIR: the directory 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 := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src))) + $(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs))) + _libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH)) + $(1)_PATH := $$(_d)/$(1) + + $$($(1)_PATH): $$($(1)_OBJS) $$(_libs) + $$(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) + + $$(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) + $$(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) + install -t $$($(1)_INSTALL_DIR) $$< + + endif + + # 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 := $$(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) +endef |