2013-12-10 16:54:34 +02:00
|
|
|
default: all
|
|
|
|
|
|
|
|
|
|
|
|
# Get rid of default suffixes. FIXME: is this a good idea?
|
|
|
|
.SUFFIXES:
|
|
|
|
|
|
|
|
|
|
|
|
# Initialise some variables.
|
2014-02-01 13:20:06 +02:00
|
|
|
bin-scripts :=
|
|
|
|
noinst-scripts :=
|
2014-01-31 16:33:12 +02:00
|
|
|
man-pages :=
|
2014-02-01 13:20:06 +02:00
|
|
|
install-tests :=
|
2023-07-10 05:24:51 +03:00
|
|
|
install-tests-groups :=
|
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_OS
|
|
|
|
HOST_KERNEL = $(firstword $(subst -, ,$(HOST_OS)))
|
2023-09-02 23:21:44 +03:00
|
|
|
ifeq ($(patsubst mingw%,,$(HOST_KERNEL)),)
|
|
|
|
HOST_MINGW = 1
|
|
|
|
HOST_WINDOWS = 1
|
|
|
|
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
|
|
|
ifeq ($(HOST_KERNEL), cygwin)
|
|
|
|
HOST_CYGWIN = 1
|
2023-09-02 23:21:44 +03:00
|
|
|
HOST_WINDOWS = 1
|
|
|
|
HOST_UNIX = 1
|
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
|
|
|
endif
|
|
|
|
ifeq ($(patsubst darwin%,,$(HOST_KERNEL)),)
|
|
|
|
HOST_DARWIN = 1
|
2023-09-02 23:21:44 +03:00
|
|
|
HOST_UNIX = 1
|
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
|
|
|
endif
|
|
|
|
ifeq ($(patsubst freebsd%,,$(HOST_KERNEL)),)
|
|
|
|
HOST_FREEBSD = 1
|
2023-09-02 23:21:44 +03:00
|
|
|
HOST_UNIX = 1
|
|
|
|
endif
|
|
|
|
ifeq ($(patsubst netbsd%,,$(HOST_KERNEL)),)
|
|
|
|
HOST_NETBSD = 1
|
|
|
|
HOST_UNIX = 1
|
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
|
|
|
endif
|
|
|
|
ifeq ($(HOST_KERNEL), linux)
|
|
|
|
HOST_LINUX = 1
|
2023-09-02 23:21:44 +03:00
|
|
|
HOST_UNIX = 1
|
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
|
|
|
endif
|
|
|
|
ifeq ($(patsubst solaris%,,$(HOST_KERNEL)),)
|
|
|
|
HOST_SOLARIS = 1
|
2023-09-02 23:21:44 +03:00
|
|
|
HOST_UNIX = 1
|
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
|
|
|
endif
|
|
|
|
endif
|
2013-12-10 16:54:34 +02:00
|
|
|
|
2014-09-11 16:28:30 +03:00
|
|
|
# Hack to define a literal space.
|
|
|
|
space :=
|
|
|
|
space +=
|
|
|
|
|
|
|
|
|
2014-09-11 16:47:31 +03:00
|
|
|
# Hack to define a literal newline.
|
|
|
|
define newline
|
|
|
|
|
|
|
|
|
|
|
|
endef
|
|
|
|
|
|
|
|
|
2013-12-10 16:54:34 +02:00
|
|
|
# Pass -fPIC if we're building dynamic libraries.
|
2013-12-17 13:13:48 +02:00
|
|
|
BUILD_SHARED_LIBS ?= 1
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
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
|
2017-04-21 17:27:27 +03:00
|
|
|
GLOBAL_CFLAGS += -U__STRICT_ANSI__ -D_GNU_SOURCE
|
|
|
|
GLOBAL_CXXFLAGS += -U__STRICT_ANSI__ -D_GNU_SOURCE
|
2014-12-09 13:20:27 +02:00
|
|
|
else
|
|
|
|
GLOBAL_CFLAGS += -fPIC
|
|
|
|
GLOBAL_CXXFLAGS += -fPIC
|
|
|
|
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
|
|
|
|
ifndef HOST_SOLARIS
|
|
|
|
ifndef HOST_FREEBSD
|
2015-10-02 15:19:00 +03:00
|
|
|
GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries
|
|
|
|
endif
|
2014-04-03 18:35:16 +03:00
|
|
|
endif
|
2014-01-09 23:14:34 +02:00
|
|
|
endif
|
2014-03-03 16:19:04 +02:00
|
|
|
SET_RPATH_TO_LIBS ?= 1
|
2013-12-10 16:54:34 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Pass -g if we want debug info.
|
2013-12-17 13:13:48 +02:00
|
|
|
BUILD_DEBUG ?= 1
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
ifeq ($(BUILD_DEBUG), 1)
|
|
|
|
GLOBAL_CFLAGS += -g
|
|
|
|
GLOBAL_CXXFLAGS += -g
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2023-11-25 07:33:21 +02:00
|
|
|
include mk/build-dir.mk
|
|
|
|
include mk/install-dirs.mk
|
2014-02-01 12:31:25 +02:00
|
|
|
include mk/functions.mk
|
2014-01-10 23:31:38 +02:00
|
|
|
include mk/tracing.mk
|
2013-12-10 16:54:34 +02:00
|
|
|
include mk/clean.mk
|
|
|
|
include mk/install.mk
|
|
|
|
include mk/libraries.mk
|
|
|
|
include mk/programs.mk
|
|
|
|
include mk/patterns.mk
|
|
|
|
include mk/templates.mk
|
2023-05-15 17:38:11 +03:00
|
|
|
include mk/cxx-big-literal.mk
|
2013-12-10 16:54:34 +02:00
|
|
|
include mk/tests.mk
|
|
|
|
|
|
|
|
|
|
|
|
# Include all sub-Makefiles.
|
2014-02-04 12:02:49 +02:00
|
|
|
define include-sub-makefile
|
2013-12-12 12:24:03 +02:00
|
|
|
d := $$(patsubst %/,%,$$(dir $(1)))
|
2013-12-10 16:54:34 +02:00
|
|
|
include $(1)
|
|
|
|
endef
|
|
|
|
|
2023-11-25 07:33:21 +02:00
|
|
|
$(foreach mf, $(makefiles), $(eval $(call include-sub-makefile,$(mf))))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Instantiate stuff.
|
2014-02-01 13:20:06 +02:00
|
|
|
$(foreach lib, $(libraries), $(eval $(call build-library,$(lib))))
|
|
|
|
$(foreach prog, $(programs), $(eval $(call build-program,$(prog))))
|
|
|
|
$(foreach script, $(bin-scripts), $(eval $(call install-program-in,$(script),$(bindir))))
|
|
|
|
$(foreach script, $(bin-scripts), $(eval programs-list += $(script)))
|
|
|
|
$(foreach script, $(noinst-scripts), $(eval programs-list += $(script)))
|
|
|
|
$(foreach template, $(template-files), $(eval $(call instantiate-template,$(template))))
|
2023-11-08 07:30:55 +02:00
|
|
|
install_test_init=tests/functional/init.sh
|
2023-07-10 05:24:51 +03:00
|
|
|
$(foreach test, $(install-tests), \
|
2023-11-08 07:30:55 +02:00
|
|
|
$(eval $(call run-test,$(test),$(install_test_init))) \
|
2023-07-10 05:24:51 +03:00
|
|
|
$(eval installcheck: $(test).test))
|
|
|
|
$(foreach test-group, $(install-tests-groups), \
|
2023-11-08 07:30:55 +02:00
|
|
|
$(eval $(call run-test-group,$(test-group),$(install_test_init))) \
|
2023-07-10 05:24:51 +03:00
|
|
|
$(eval installcheck: $(test-group).test-group) \
|
|
|
|
$(foreach test, $($(test-group)-tests), \
|
2023-11-08 07:30:55 +02:00
|
|
|
$(eval $(call run-test,$(test),$(install_test_init))) \
|
2023-07-10 05:24:51 +03:00
|
|
|
$(eval $(test-group).test-group: $(test).test)))
|
|
|
|
|
2014-01-31 16:33:12 +02:00
|
|
|
$(foreach file, $(man-pages), $(eval $(call install-data-in, $(file), $(mandir)/man$(patsubst .%,%,$(suffix $(file))))))
|
2013-12-10 16:54:34 +02:00
|
|
|
|
|
|
|
|
2014-02-01 12:47:34 +02:00
|
|
|
.PHONY: default all man help
|
2014-01-31 16:33:12 +02:00
|
|
|
|
2021-02-26 23:42:51 +02:00
|
|
|
all: $(programs-list) $(libs-list) $(man-pages)
|
2014-01-31 16:33:12 +02:00
|
|
|
|
|
|
|
man: $(man-pages)
|
2013-12-12 12:27:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
help:
|
|
|
|
@echo "The following targets are available:"
|
|
|
|
@echo ""
|
|
|
|
@echo " default: Build default targets"
|
2014-01-31 16:33:12 +02:00
|
|
|
ifdef man-pages
|
|
|
|
@echo " man: Generate manual pages"
|
|
|
|
endif
|
2014-02-01 12:47:34 +02:00
|
|
|
@$(print-top-help)
|
2014-02-01 13:20:06 +02:00
|
|
|
ifdef programs-list
|
2013-12-12 12:27:47 +02:00
|
|
|
@echo ""
|
|
|
|
@echo "The following programs can be built:"
|
|
|
|
@echo ""
|
2014-02-01 13:20:06 +02:00
|
|
|
@for i in $(programs-list); do echo " $$i"; done
|
2013-12-12 12:27:47 +02:00
|
|
|
endif
|
2014-02-01 13:20:06 +02:00
|
|
|
ifdef libs-list
|
2013-12-12 12:27:47 +02:00
|
|
|
@echo ""
|
|
|
|
@echo "The following libraries can be built:"
|
|
|
|
@echo ""
|
2014-02-01 13:20:06 +02:00
|
|
|
@for i in $(libs-list); do echo " $$i"; done
|
2023-07-10 05:24:51 +03:00
|
|
|
endif
|
|
|
|
ifdef install-tests-groups
|
|
|
|
@echo ""
|
|
|
|
@echo "The following groups of functional tests can be run:"
|
|
|
|
@echo ""
|
|
|
|
@for i in $(install-tests-groups); do echo " $$i.test-group"; done
|
|
|
|
@echo ""
|
|
|
|
@echo "(installcheck includes tests in test groups too.)"
|
2013-12-18 17:40:48 +02:00
|
|
|
endif
|
2014-02-01 12:47:34 +02:00
|
|
|
@echo ""
|
|
|
|
@echo "The following variables control the build:"
|
|
|
|
@echo ""
|
|
|
|
@echo " BUILD_SHARED_LIBS ($(BUILD_SHARED_LIBS)): Whether to build shared libraries"
|
|
|
|
@echo " BUILD_DEBUG ($(BUILD_DEBUG)): Whether to include debug symbols"
|
|
|
|
@echo " CC ($(CC)): C compiler to be used"
|
|
|
|
@echo " CFLAGS: Flags for the C compiler"
|
|
|
|
@echo " CXX ($(CXX)): C++ compiler to be used"
|
|
|
|
@echo " CXXFLAGS: Flags for the C++ compiler"
|
2021-02-26 23:48:41 +02:00
|
|
|
@echo " CPPFLAGS: C preprocessor flags, used for both CC and CXX"
|
2014-02-01 12:47:34 +02:00
|
|
|
@$(print-var-help)
|