nix-super/mk/lib.mk

185 lines
4.5 KiB
Makefile
Raw Normal View History

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 :=
install-tests-groups :=
ifdef HOST_OS
HOST_KERNEL = $(firstword $(subst -, ,$(HOST_OS)))
ifeq ($(HOST_KERNEL), cygwin)
HOST_CYGWIN = 1
endif
ifeq ($(patsubst darwin%,,$(HOST_KERNEL)),)
HOST_DARWIN = 1
endif
ifeq ($(patsubst freebsd%,,$(HOST_KERNEL)),)
HOST_FREEBSD = 1
endif
ifeq ($(HOST_KERNEL), linux)
HOST_LINUX = 1
endif
ifeq ($(patsubst solaris%,,$(HOST_KERNEL)),)
HOST_SOLARIS = 1
endif
endif
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-17 13:13:48 +02:00
# Default installation paths.
prefix ?= /usr/local
libdir ?= $(prefix)/lib
bindir ?= $(prefix)/bin
libexecdir ?= $(prefix)/libexec
datadir ?= $(prefix)/share
localstatedir ?= $(prefix)/var
sysconfdir ?= $(prefix)/etc
2014-01-31 16:33:12 +02:00
mandir ?= $(prefix)/share/man
2013-12-17 13:13:48 +02:00
# Initialise support for build directories.
builddir ?=
ifdef builddir
buildprefix = $(builddir)/
else
buildprefix =
endif
# Pass -fPIC if we're building dynamic libraries.
2013-12-17 13:13:48 +02:00
BUILD_SHARED_LIBS ?= 1
ifeq ($(BUILD_SHARED_LIBS), 1)
ifdef HOST_CYGWIN
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
ifndef HOST_DARWIN
ifndef HOST_SOLARIS
ifndef HOST_FREEBSD
GLOBAL_LDFLAGS += -Wl,--no-copy-dt-needed-entries
endif
endif
endif
SET_RPATH_TO_LIBS ?= 1
endif
# Pass -g if we want debug info.
2013-12-17 13:13:48 +02:00
BUILD_DEBUG ?= 1
ifeq ($(BUILD_DEBUG), 1)
GLOBAL_CFLAGS += -g
GLOBAL_CXXFLAGS += -g
endif
include mk/functions.mk
include mk/tracing.mk
include mk/clean.mk
include mk/install.mk
include mk/libraries.mk
include mk/programs.mk
include mk/patterns.mk
include mk/templates.mk
include mk/cxx-big-literal.mk
include mk/tests.mk
# Include all sub-Makefiles.
define include-sub-makefile
2013-12-12 12:24:03 +02:00
d := $$(patsubst %/,%,$$(dir $(1)))
include $(1)
endef
2014-02-01 13:20:06 +02:00
$(foreach mf, $(makefiles), $(eval $(call include-sub-makefile, $(mf))))
# 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))))
install_test_init=tests/functional/init.sh
$(foreach test, $(install-tests), \
$(eval $(call run-test,$(test),$(install_test_init))) \
$(eval installcheck: $(test).test))
$(foreach test-group, $(install-tests-groups), \
$(eval $(call run-test-group,$(test-group),$(install_test_init))) \
$(eval installcheck: $(test-group).test-group) \
$(foreach test, $($(test-group)-tests), \
$(eval $(call run-test,$(test),$(install_test_init))) \
$(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))))))
2014-02-01 12:47:34 +02:00
.PHONY: default all man help
2014-01-31 16:33:12 +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
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.)"
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)