2014-02-01 13:20:06 +02:00
|
|
|
|
libs-list :=
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifdef HOST_DARWIN
|
2014-01-09 23:14:34 +02:00
|
|
|
|
SO_EXT = dylib
|
|
|
|
|
else
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifdef HOST_CYGWIN
|
2014-12-09 13:22:12 +02:00
|
|
|
|
SO_EXT = dll
|
|
|
|
|
else
|
|
|
|
|
SO_EXT = so
|
|
|
|
|
endif
|
2014-01-09 23:14:34 +02:00
|
|
|
|
endif
|
|
|
|
|
|
2013-12-10 16:54:34 +02:00
|
|
|
|
# Build a library with symbolic name $(1). The library is defined by
|
2016-11-26 01:37:43 +02:00
|
|
|
|
# various variables prefixed by ‘$(1)_’:
|
2013-12-10 16:54:34 +02:00
|
|
|
|
#
|
2016-11-26 01:37:43 +02:00
|
|
|
|
# - $(1)_NAME: the name of the library (e.g. ‘libfoo’); defaults to
|
2013-12-10 16:54:34 +02:00
|
|
|
|
# $(1).
|
|
|
|
|
#
|
2013-12-16 17:49:41 +02:00
|
|
|
|
# - $(1)_DIR: the directory where the (non-installed) library will be
|
|
|
|
|
# placed.
|
2013-12-10 16:54:34 +02:00
|
|
|
|
#
|
|
|
|
|
# - $(1)_SOURCES: the source files of the library.
|
|
|
|
|
#
|
2014-02-11 15:15:57 +02:00
|
|
|
|
# - $(1)_CFLAGS: additional C compiler flags.
|
|
|
|
|
#
|
2013-12-16 17:49:41 +02:00
|
|
|
|
# - $(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 libraries will have an order-only dependency.
|
|
|
|
|
#
|
2013-12-10 16:54:34 +02: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).
|
|
|
|
|
#
|
2018-02-08 18:26:18 +02:00
|
|
|
|
# - $(1)_EXCLUDE_FROM_LIBRARY_LIST: if defined, the library will not
|
|
|
|
|
# be automatically marked as a dependency of the top-level all
|
|
|
|
|
# target andwill not be listed in the make help output. This is
|
|
|
|
|
# useful for libraries built solely for testing, for example.
|
|
|
|
|
#
|
2016-11-26 01:37:43 +02:00
|
|
|
|
# - BUILD_SHARED_LIBS: if equal to ‘1’, a dynamic library will be
|
2013-12-10 16:54:34 +02:00
|
|
|
|
# built, otherwise a static library.
|
2014-02-04 12:02:49 +02:00
|
|
|
|
define build-library
|
2013-12-10 16:54:34 +02:00
|
|
|
|
$(1)_NAME ?= $(1)
|
2014-09-05 15:17:05 +03:00
|
|
|
|
_d := $(buildprefix)$$(strip $$($(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))))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
_libs := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_PATH))
|
|
|
|
|
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifdef HOST_CYGWIN
|
2014-12-09 13:22:12 +02:00
|
|
|
|
$(1)_INSTALL_DIR ?= $$(bindir)
|
|
|
|
|
else
|
|
|
|
|
$(1)_INSTALL_DIR ?= $$(libdir)
|
|
|
|
|
endif
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
|
$(1)_LDFLAGS_USE :=
|
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED :=
|
|
|
|
|
|
2014-02-07 16:06:21 +02:00
|
|
|
|
$$(eval $$(call create-dir, $$(_d)))
|
2014-02-06 11:59:58 +02:00
|
|
|
|
|
2013-12-10 16:54:34 +02:00
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
|
|
|
|
|
2014-01-09 23:14:34 +02:00
|
|
|
|
ifdef $(1)_ALLOW_UNDEFINED
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifdef HOST_DARWIN
|
2014-01-09 23:14:34 +02:00
|
|
|
|
$(1)_LDFLAGS += -undefined suppress -flat_namespace
|
|
|
|
|
endif
|
|
|
|
|
else
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifndef HOST_DARWIN
|
|
|
|
|
ifndef HOST_CYGWIN
|
2014-12-09 13:22:12 +02:00
|
|
|
|
$(1)_LDFLAGS += -Wl,-z,defs
|
|
|
|
|
endif
|
2014-01-09 23:14:34 +02:00
|
|
|
|
endif
|
2013-12-10 16:54:34 +02:00
|
|
|
|
endif
|
|
|
|
|
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifndef HOST_DARWIN
|
2014-03-03 16:29:58 +02:00
|
|
|
|
$(1)_LDFLAGS += -Wl,-soname=$$($(1)_NAME).$(SO_EXT)
|
|
|
|
|
endif
|
|
|
|
|
|
2014-01-09 23:14:34 +02:00
|
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).$(SO_EXT)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-02-18 14:35:35 +02:00
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) $$(_libs) | $$(_d)/
|
2022-02-09 15:00:53 +02:00
|
|
|
|
$$(trace-ld) $(CXX) -o $$(abspath $$@) -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE)) $$($(1)_LDFLAGS_UNINSTALLED)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifndef HOST_DARWIN
|
2014-12-10 14:01:10 +02:00
|
|
|
|
$(1)_LDFLAGS_USE += -Wl,-rpath,$$(abspath $$(_d))
|
|
|
|
|
endif
|
|
|
|
|
$(1)_LDFLAGS_USE += -L$$(_d) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-02-07 16:06:21 +02:00
|
|
|
|
$(1)_INSTALL_PATH := $(DESTDIR)$$($(1)_INSTALL_DIR)/$$($(1)_NAME).$(SO_EXT)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
|
_libs_final := $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_INSTALL_PATH))
|
|
|
|
|
|
2014-02-07 16:06:21 +02:00
|
|
|
|
$$(eval $$(call create-dir, $$($(1)_INSTALL_DIR)))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-02-18 14:35:35 +02:00
|
|
|
|
$$($(1)_INSTALL_PATH): $$($(1)_OBJS) $$(_libs_final) | $(DESTDIR)$$($(1)_INSTALL_DIR)/
|
2022-02-09 15:00:53 +02:00
|
|
|
|
$$(trace-ld) $(CXX) -o $$@ -shared $$(LDFLAGS) $$(GLOBAL_LDFLAGS) $$($(1)_OBJS) $$($(1)_LDFLAGS) $$($(1)_LDFLAGS_PROPAGATED) $$(foreach lib, $$($(1)_LIBS), $$($$(lib)_LDFLAGS_USE_INSTALLED))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2014-03-03 16:19:04 +02:00
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += -L$$(DESTDIR)$$($(1)_INSTALL_DIR) -l$$(patsubst lib%,%,$$(strip $$($(1)_NAME)))
|
Apply OS checks to host platform, not build
Previously, the build system used uname(1) output when it wanted to
check the operating system it was being built for, which meant that it
didn't take into-account cross-compilation when the build and host
operating systems were different.
To fix this, instead of consulting uname output, we consult the host
triple, specifically the third "kernel" part.
For "kernel"s with stable ABIs, like Linux or Cygwin, we can use a
simple ifeq to test whether we're compiling for that system, but for
other platforms, like Darwin, FreeBSD, or Solaris, we have to use a
more complicated check to take into account the version numbers at the
end of the "kernel"s. I couldn't find a way to just strip these
version numbers in GNU Make without shelling out, which would be even
more ugly IMO. Because these checks differ between kernels, and the
patsubst ones are quite fiddly, I've added variables for each host OS
we might want to check to make them easier to reuse.
2021-06-01 10:58:21 +03:00
|
|
|
|
ifndef HOST_DARWIN
|
2014-12-10 14:01:10 +02:00
|
|
|
|
ifeq ($(SET_RPATH_TO_LIBS), 1)
|
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath,$$($(1)_INSTALL_DIR)
|
|
|
|
|
else
|
|
|
|
|
$(1)_LDFLAGS_USE_INSTALLED += -Wl,-rpath-link,$$($(1)_INSTALL_DIR)
|
|
|
|
|
endif
|
2014-03-03 16:19:04 +02:00
|
|
|
|
endif
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
|
ifdef $(1)_FORCE_INSTALL
|
|
|
|
|
install: $$($(1)_INSTALL_PATH)
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
$(1)_PATH := $$(_d)/$$($(1)_NAME).a
|
|
|
|
|
|
2014-02-18 14:35:35 +02:00
|
|
|
|
$$($(1)_PATH): $$($(1)_OBJS) | $$(_d)/
|
2021-10-09 00:57:42 +03:00
|
|
|
|
$$(trace-ld) $(LD) -Ur -o $$(_d)/$$($(1)_NAME).o $$?
|
|
|
|
|
$$(trace-ar) $(AR) crs $$@ $$(_d)/$$($(1)_NAME).o
|
2013-12-10 16:54:34 +02: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 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-12 12:39:58 +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-12 12:39:58 +02:00
|
|
|
|
-include $$($(1)_DEPS)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
2018-02-08 18:26:18 +02:00
|
|
|
|
ifndef $(1)_EXCLUDE_FROM_LIBRARY_LIST
|
2014-02-01 13:20:06 +02:00
|
|
|
|
libs-list += $$($(1)_PATH)
|
2018-02-08 18:26:18 +02:00
|
|
|
|
endif
|
2014-02-01 13:20:06 +02:00
|
|
|
|
clean-files += $$(_d)/*.a $$(_d)/*.$(SO_EXT) $$(_d)/*.o $$(_d)/.*.dep $$($(1)_DEPS) $$($(1)_OBJS)
|
2013-12-10 16:54:34 +02:00
|
|
|
|
endef
|