2014-02-01 11:20:06 +00:00
|
|
|
|
libs-list :=
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
2014-01-09 21:14:34 +00:00
|
|
|
|
ifeq ($(OS), Darwin)
|
|
|
|
|
SO_EXT = dylib
|
|
|
|
|
else
|
2014-12-09 11:22:12 +00:00
|
|
|
|
ifeq (CYGWIN,$(findstring CYGWIN,$(OS)))
|
|
|
|
|
SO_EXT = dll
|
|
|
|
|
else
|
|
|
|
|
SO_EXT = so
|
|
|
|
|
endif
|
2014-01-09 21:14:34 +00:00
|
|
|
|
endif
|
|
|
|
|
|
2013-12-10 14:54:34 +00:00
|
|
|
|
# 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).
|
|
|
|
|
#
|
2013-12-16 15:49:41 +00:00
|
|
|
|
# - $(1)_DIR: the directory where the (non-installed) library will be
|
|
|
|
|
# placed.
|
2013-12-10 14:54:34 +00:00
|
|
|
|
#
|
|
|
|
|
# - $(1)_SOURCES: the source files of the library.
|
|
|
|
|
#
|
2014-02-11 13:15:57 +00:00
|
|
|
|
# - $(1)_CFLAGS: additional C compiler flags.
|
|
|
|
|
#
|
2013-12-16 15:49:41 +00:00
|
|
|
|
# - $(1)_CXXFLAGS: additional C++ compiler flags.
|
|
|
|
|
#
|
2014-08-07 14:10:23 +00:00
|
|
|
|
# - $(1)_ORDER_AFTER: a set of targets on which the object files of
|
|
|
|
|
# this libraries will have an order-only dependency.
|
|
|
|
|
#
|
2013-12-10 14:54:34 +00:00
|
|
|
|
# - $(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.
|
2014-02-04 10:02:49 +00:00
|
|
|
|
define build-library
|
2013-12-10 14:54:34 +00:00
|
|
|
|
$(1)_NAME ?= $(1)
|
|
|
|
|
_d := $$(strip $$($(1)_DIR))
|
2014-01-09 15:54:01 +00:00
|
|
|
|
_srcs := $$(sort $$(foreach src, $$($(1)_SOURCES), $$(src)))
|
2013-12-10 14:54:34 +00:00
|
|
|
|
$(1)_OBJS := $$(addsuffix .o, $$(basename $$(_srcs)))
|
|
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
|
|
|
|
|
|
2014-12-09 11:22:12 +00:00
|
|
|
|
ifeq (CYGWIN,$(findstring CYGWIN,$(OS)))
|
|
|
|
|
$(1)_INSTALL_DIR ?= $$(bindir)
|
|
|
|
|
else
|
|
|
|
|
$(1)_INSTALL_DIR ?= $$(libdir)
|
|
|
|
|
endif
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
|
|
|
|
$(1)_LDFLAGS_USE :=
|
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED :=
|
|
|
|
|
|
2014-02-07 14:06:21 +00:00
|
|
|
|
$$(eval $$(call create-dir, $$(_d)))
|
2014-02-06 09:59:58 +00:00
|
|
|
|
|
2013-12-10 14:54:34 +00:00
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
|
|
|
|
|
2014-01-09 21:14:34 +00:00
|
|
|
|
ifdef $(1)_ALLOW_UNDEFINED
|
|
|
|
|
ifeq ($(OS), Darwin)
|
|
|
|
|
$(1)_LDFLAGS += -undefined suppress -flat_namespace
|
|
|
|
|
endif
|
|
|
|
|
else
|
|
|
|
|
ifneq ($(OS), Darwin)
|
2014-12-09 11:22:12 +00:00
|
|
|
|
ifneq (CYGWIN,$(findstring CYGWIN,$(OS)))
|
|
|
|
|
$(1)_LDFLAGS += -Wl,-z,defs
|
|
|
|
|
endif
|
2014-01-09 21:14:34 +00:00
|
|
|
|
endif
|
2013-12-10 14:54:34 +00:00
|
|
|
|
endif
|
|
|
|
|
|
2014-03-03 14:29:58 +00:00
|
|
|
|
ifneq ($(OS), Darwin)
|
|
|
|
|
$(1)_LDFLAGS += -Wl,-soname=$$($(1)_NAME).$(SO_EXT)
|
|
|
|
|
endif
|
|
|
|
|
|
2014-01-09 21:14:34 +00:00
|
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT)
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
2014-02-18 12:35:35 +00:00
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
2014-03-03 14:19:04 +00:00
|
|
|
|
$$(trace-ld) $(CXX) -o $$@ -shared $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE))
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
|
|
|
|
$(1)_LDFLAGS_USE += -L$$(_d) -Wl,-rpath,$$(abspath $$(_d)) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
|
|
|
|
|
2014-02-07 14:06:21 +00:00
|
|
|
|
$(1)_INSTALL_PATH := $(DESTDIR)$$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT)
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
|
|
|
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
|
|
|
|
|
2014-02-07 14:06:21 +00:00
|
|
|
|
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
2014-02-18 12:35:35 +00:00
|
|
|
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
2014-03-03 14:19:04 +00:00
|
|
|
|
$$(trace-ld) $(CXX) -o $$@ -shared $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
2014-03-03 14:19:04 +00:00
|
|
|
|
$(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)
|
2014-08-07 14:10:23 +00:00
|
|
|
|
else
|
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath-link,$$($(1)_INSTALL_DIR)
|
2014-03-03 14:19:04 +00:00
|
|
|
|
endif
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
|
|
|
|
ifdef $(1)_FORCE_INSTALL
|
|
|
|
|
install: $$($(1)_INSTALL_PATH)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
|
|
|
|
|
|
2014-02-18 12:35:35 +00:00
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/
|
2014-01-10 21:31:38 +00:00
|
|
|
|
$(trace-ar) ar crs $$@ $$?
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
|
|
|
|
$(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)
|
|
|
|
|
|
2014-02-11 13:15:57 +00:00
|
|
|
|
# Propagate CFLAGS and CXXFLAGS to the individual object files.
|
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CFLAGS=$$($(1)_CFLAGS)))
|
2013-12-10 14:54:34 +00:00
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj)_CXXFLAGS=$$($(1)_CXXFLAGS)))
|
|
|
|
|
|
2013-12-16 15:49:41 +00:00
|
|
|
|
# Make each object file depend on the common dependencies.
|
2014-02-28 11:01:42 +00:00
|
|
|
|
$$(foreach obj, $$($(1)_OBJS), $$(eval $$(obj): $$($(1)_COMMON_DEPS) $$(GLOBAL_COMMON_DEPS)))
|
2013-12-16 15:49:41 +00:00
|
|
|
|
|
2014-08-07 14:10:23 +00: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-12 10:39:58 +00:00
|
|
|
|
# Include .dep files, if they exist.
|
2014-02-01 10:31:25 +00:00
|
|
|
|
$(1)_DEPS := $$(foreach fn, $$($(1)_OBJS), $$(call filename-to-dep, $$(fn)))
|
2013-12-12 10:39:58 +00:00
|
|
|
|
-include $$($(1)_DEPS)
|
2013-12-10 14:54:34 +00:00
|
|
|
|
|
2014-02-01 11:20:06 +00:00
|
|
|
|
libs-list += $$($(1)_PATH)
|
|
|
|
|
clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
|
|
|
|
|
dist-files += $$(_srcs)
|
2013-12-10 14:54:34 +00:00
|
|
|
|
endef
|