2014-02-01 13:20:06 +02:00
|
|
|
|
programs-list :=
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2024-01-11 18:14:13 +02:00
|
|
|
|
ifdef HOST_WINDOWS
|
|
|
|
|
EXE_EXT = .exe
|
|
|
|
|
else
|
|
|
|
|
EXE_EXT =
|
|
|
|
|
endif
|
|
|
|
|
|
2013-12-10 16:54:34 +02:00
|
|
|
|
# Build a program with symbolic name $(1). The program is defined by
|
2016-11-26 01:37:43 +02:00
|
|
|
|
# various variables prefixed by ‘$(1)_’:
|
2013-12-10 16:54:34 +02:00
|
|
|
|
#
|
2023-01-29 19:31:34 +02:00
|
|
|
|
# - $(1)_NAME: the name of the program (e.g. ‘foo’); defaults to
|
|
|
|
|
# $(1).
|
|
|
|
|
#
|
2013-12-16 17:49:41 +02:00
|
|
|
|
# - $(1)_DIR: the directory where the (non-installed) program will be
|
|
|
|
|
# placed.
|
2013-12-10 16:54:34 +02:00
|
|
|
|
#
|
|
|
|
|
# - $(1)_SOURCES: the source files of the program.
|
|
|
|
|
#
|
2014-02-11 15:15:57 +02:00
|
|
|
|
# - $(1)_CFLAGS: additional C compiler flags.
|
|
|
|
|
#
|
|
|
|
|
# - $(1)_CXXFLAGS: additional C++ compiler flags.
|
|
|
|
|
#
|
2014-08-07 17:10:23 +03:00
|
|
|
|
# - $(1)_ORDER_AFTER: a set of targets on which the object files of
|
|
|
|
|
# this program will have an order-only dependency.
|
|
|
|
|
#
|
2013-12-10 16:54:34 +02:00
|
|
|
|
# - $(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).
|
2014-02-04 12:02:49 +02:00
|
|
|
|
define build-program
|
2023-01-29 19:31:34 +02:00
|
|
|
|
$(1)_NAME ?= $(1)
|
2014-09-05 15:17:05 +03:00
|
|
|
|
_d := $(buildprefix)$$($(1)_DIR)
|
2014-01-09 17:54:01 +02:00
|
|
|
|
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
|
2014-09-05 15:17:05 +03:00
|
|
|
|
$(1)_OBJS := $$(addprefix $(buildprefix), $$(addsuffix .o, $$(basename $$(_srcs))))
|
2023-02-14 16:54:19 +02:00
|
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$(foreach lib2, $$($$(lib)_LIB_CLOSURE), $$($$(lib2)_PATH)))
|
2024-01-11 18:14:13 +02:00
|
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME)$(EXE_EXT)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-02-07 16:06:21 +02:00
|
|
|
|
$$(eval $$(call create-dir, $$(_d)))
|
2014-02-06 11:59:58 +02:00
|
|
|
|
|
2014-02-18 14:35:35 +02:00
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
2021-12-21 20:34:40 +02:00
|
|
|
|
+$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
|
$(1)_INSTALL_DIR ?= $$(bindir)
|
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
ifdef $(1)_INSTALL_DIR
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2024-01-11 18:14:13 +02:00
|
|
|
|
$(1)_INSTALL_PATH := $$($(1)_INSTALL_DIR)/$$($(1)_NAME)$(EXE_EXT)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
install: $(DESTDIR)$$($(1)_INSTALL_PATH)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
|
|
|
|
|
|
|
|
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
|
|
|
|
|
|
|
|
|
$(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
2021-12-21 20:34:40 +02:00
|
|
|
|
+$$(trace-ld) $(CXX) -o $$@ $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
else
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
$(DESTDIR)$$($(1)_INSTALL_PATH): $$($(1)_PATH) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
2023-02-14 16:54:19 +02:00
|
|
|
|
+$$(trace-install) install -t $(DESTDIR)$$($(1)_INSTALL_DIR) $$<
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2020-05-08 13:03:27 +03:00
|
|
|
|
endif
|
2013-12-10 16:54:34 +02:00
|
|
|
|
endif
|
|
|
|
|
|
2014-02-11 15:15:57 +02:00
|
|
|
|
# Propagate CFLAGS and CXXFLAGS to the individual object files.
|
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CFLAGS=$$($(1)_CFLAGS)))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
|
|
|
|
|
2013-12-16 17:49:41 +02:00
|
|
|
|
# Make each object file depend on the common dependencies.
|
2014-02-28 13:01:42 +02:00
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS) $$(GLOBAL_COMMON_DEPS)))
|
2013-12-16 17:49:41 +02:00
|
|
|
|
|
2014-08-07 17:10:23 +03:00
|
|
|
|
# Make each object file have order-only dependencies on the common
|
|
|
|
|
# order-only dependencies. This includes the order-only dependencies
|
|
|
|
|
# of libraries we're depending on.
|
|
|
|
|
$(1)_ORDER_AFTER_CLOSED = $$($(1)_ORDER_AFTER) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_ORDER_AFTER_CLOSED))
|
|
|
|
|
|
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): | $$($(1)_ORDER_AFTER_CLOSED) $$(GLOBAL_ORDER_AFTER)))
|
|
|
|
|
|
2013-12-16 17:49:41 +02:00
|
|
|
|
# Include .dep files, if they exist.
|
2014-02-01 12:31:25 +02:00
|
|
|
|
$(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn)))
|
2013-12-16 17:49:41 +02:00
|
|
|
|
-include $$($(1)_DEPS)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-02-01 13:20:06 +02:00
|
|
|
|
programs-list += $$($(1)_PATH)
|
|
|
|
|
clean-files += $$($(1)_PATH) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
|
2020-05-08 12:49:40 +03:00
|
|
|
|
|
|
|
|
|
# Phony target to run this program (typically as a dependency of 'check').
|
|
|
|
|
.PHONY: $(1)_RUN
|
|
|
|
|
$(1)_RUN: $$($(1)_PATH)
|
2023-08-25 17:20:28 +03:00
|
|
|
|
$(trace-test) $$($(1)_ENV) $$($(1)_PATH)
|
2020-05-08 12:49:40 +03:00
|
|
|
|
|
2013-12-10 16:54:34 +02:00
|
|
|
|
endef
|