make-it-quick/rules.mk

469 lines
18 KiB
Makefile
Raw Normal View History

2017-03-25 06:57:50 +08:00
#******************************************************************************
# rules.mk Recorder project
2017-03-25 06:57:50 +08:00
#******************************************************************************
#
# File Description:
#
# Common rules for building the targets
#
#
#
#
#
#
#
#******************************************************************************
# (C) 1992-2017 Christophe de Dinechin <christophe@dinechin.org>
# This software is licensed under the GNU General Public License v3
# See file COPYING for details.
#******************************************************************************
# Include the Makefile configuration and local variables
include $(BUILD)config.mk
# Default build settings (definitions in specific config..mkXYZ)
XINCLUDES= $(INCLUDES) $(INCLUDES_$(BUILDENV)) $(INCLUDES_$(TARGET)) $(INCLUDES_EXTRA)
XDEFINES= $(DEFINES) $(DEFINES_$(BUILDENV)) $(DEFINES_$(TARGET)) $(DEFINES_EXTRA)
CPPFLAGS+= $(CPPFLAGS_$(BUILDENV)) $(CPPFLAGS_$(TARGET)) $(CPPFLAGS_EXTRA) $(XDEFINES:%=-D%) $(XINCLUDES:%=-I%)
CFLAGS+= $(CPPFLAGS) $(CFLAGS_STD) $(CFLAGS_PKGCONFIG) $(CFLAGS_$(BUILDENV)) $(CFLAGS_$(TARGET)) $(CFLAGS_EXTRA)
CXXFLAGS+= $(CPPFLAGS) $(CXXFLAGS_STD) $(CFLAGS_PKGCONFIG) $(CXXFLAGS_$(BUILDENV)) $(CXXFLAGS_$(TARGET)) $(CFLAGS_EXTRA) $(CXXFLAGS_EXTRA)
LDFLAGS+= $(CFLAGS_STD) $(CXXFLAGS_STD) $(LDFLAGS_PKGCONFIG) $(LDFLAGS_$(BUILDENV)) $(LDFLAGS_$(TARGET)) $(CFLAGS_EXTRA) $(LDFLAGS_EXTRA)
2017-03-25 06:57:50 +08:00
ifndef DIR
FULLDIR:= $(abspath .)/
DIR:= $(subst $(TOP),,$(FULLDIR))
2017-11-29 01:06:21 +08:00
PRETTY_DIR:= $(subst $(TOP),[top],$(FULLDIR)$(VARIANT:%=[%]))
2017-03-25 06:57:50 +08:00
BUILD_DATE:= $(shell /bin/date '+%Y%m%d-%H%M%S')
OBJROOT:= $(OBJFILES)$(BUILDENV)/$(CROSS_COMPILE:%=%-)$(TARGET)$(BASE_EXTRA_DEPTH)
BUILD_LOG:= $(LOGS)build-$(BUILDENV)-$(CROSS_COMPILE:%=%-)$(TARGET)-$(BUILD_DATE).log
2017-03-25 06:57:50 +08:00
endif
# Configuration variables
2017-11-28 22:03:35 +08:00
OBJDIR:= $(OBJROOT)/$(DIR)
OBJECTS= $(SOURCES:%=$(OBJDIR)%$(OBJ_EXT))
PRODUCTS_EXE= $(patsubst %.exe,%$(EXE_EXT),$(filter %.exe,$(PRODUCTS)))
PRODUCTS_LIB= $(patsubst %.lib,%$(LIB_EXT),$(filter %.lib,$(PRODUCTS)))
PRODUCTS_DLL= $(patsubst %.dll,%$(DLL_EXT),$(filter %.dll,$(PRODUCTS)))
PRODUCTS_OTHER= $(filter-out %.exe %.lib %.dll %$(EXE_EXT) %$(LIB_EXT) %$(DLL_EXT), $(PRODUCTS))
2017-11-28 22:03:35 +08:00
PRODUCTS_LIBS= $(filter %.lib %.dll,$(PRODUCTS))
OUTPUT_EXE= $(PRODUCTS_EXE:%=$(OUTPUT)$(EXE_PFX)%)
OUTPUT_LIB= $(PRODUCTS_LIB:%=$(OUTPUT)$(LIB_PFX)%)
OUTPUT_DLL= $(PRODUCTS_DLL:%=$(OUTPUT)$(DLL_PFX)%)
OUTPUT_OTHER= $(PRODUCTS_OTHER:%=$(OUTPUT)%)
OBJPRODUCTS= $(OUTPUT_EXE) $(OUTPUT_LIB) $(OUTPUT_DLL) $(OUTPUT_OTHER)
# Check a common mistake with PRODUCTS= not being set or set without extension
# Even on Linux / Unix, the PRODUCTS variable must end in .exe for executables,
# in .lib for static libraries, and in .dll for dynamic libraries.
# This is to help executable build rules be more robust and not catch
# unknown extensions by mistake. The extension is replaced with the
# correct platform extension, i.e. .a for static libraries on Linux
2017-11-07 00:18:14 +08:00
ifneq ($(PRODUCTS),)
ifeq ($(PRODUCTS_EXE)$(PRODUCTS_LIB)$(PRODUCTS_DLL),)
$(error Error: Variable PRODUCTS must end in .exe, .lib or .dll)
endif
2017-11-07 00:18:14 +08:00
endif
ALL_LIBS= $(LIBRARIES) $(LINK_LIBS)
LIBNAMES= $(filter %.lib, $(notdir $(ALL_LIBS)))
DLLNAMES= $(filter %.dll, $(notdir $(ALL_LIBS)))
2017-11-28 01:16:05 +08:00
OBJLIBS= $(LIBNAMES:%.lib=$(OUTPUT)$(LIB_PFX)%$(LIB_EXT))
OBJDLLS= $(DLLNAMES:%.dll=$(OUTPUT)$(DLL_PFX)%$(DLL_EXT))
LINK_PATHS:= $(OUTPUT:%=$(LINK_DIR_OPT)%)
LINK_XLIBS= $(LIBNAMES:%.lib=$(LINK_LIB_OPT)%) \
$(DLLNAMES:%.dll=$(LINK_DLL_OPT)%)
LINK_INPUTS= $(OBJECTS) $(OBJLIBS) $(OBJDLLS)
LINK_CMDLINE= $(OBJECTS) $(LINK_PATHS) $(LINK_XLIBS)
2017-03-25 06:57:50 +08:00
ifneq ($(words $(LINK_INPUTS)),0)
LINK_WINPUTS= $(patsubst %,"%", $(shell cygpath -aw $(LINK_INPUTS)))
2017-03-25 06:57:50 +08:00
endif
PRINT_DIR= --no-print-directory
2017-03-25 06:57:50 +08:00
RECURSE_BUILDENV=$(BUILDENV)
RECURSE_CMD= $(MAKE) $(PRINT_DIR) TARGET=$(TARGET) BUILDENV=$(RECURSE_BUILDENV) BUILD="$(abspath $(BUILD))/" TOP="$(abspath $(TOP))/" $(RECURSE) COLORIZE=
MAKEFILE_DEPS:= $(MAKEFILE_LIST)
NOT_PARALLEL?= .NOTPARALLEL
BUILD_LOW?= 0
BUILD_HIGH?= 100
BUILD_INDEX:= 1
BUILD_COUNT:= $(words $(SOURCES))
GIT_REVISION:= $(shell git rev-parse --short HEAD 2> /dev/null || echo "unknown")
PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OUTPUT_EXE))_prof_$(GIT_REVISION).vsp
2017-03-25 06:57:50 +08:00
#------------------------------------------------------------------------------
# User targets
#------------------------------------------------------------------------------
all: $(TARGET)
debug opt release profile: logs.mkdir
$(PRINT_COMMAND) $(TIME) $(MAKE) TARGET=$@ RECURSE=build LOG_COMMANDS= build $(LOG_COMMANDS)
# Testing
test tests check: $(TARGET)
2017-11-09 01:03:54 +08:00
$(PRINT_COMMAND) $(MAKE) RECURSE=test $(TESTS:%=%.test) LOG_COMMANDS= TIME= $(LOG_COMMANDS)
2017-03-25 06:57:50 +08:00
# Clean builds
2017-03-25 06:57:50 +08:00
startup restart rebuild: clean all
# Installation
2017-11-28 19:50:32 +08:00
install: install-all
2017-03-25 06:57:50 +08:00
2017-11-29 01:06:21 +08:00
clean: $(SUBDIRS:%=%.clean) $(VARIANTS:%=%.variant-clean)
2017-11-30 16:41:50 +08:00
-$(PRINT_CLEAN) rm -f $(TO_CLEAN) $(OBJECTS) $(DEPENDENCIES) $(OBJPRODUCTS) $(LINK_INPUTS) config.h
2017-11-28 18:16:36 +08:00
%.clean:
$(PRINT_COMMAND) cd $* && $(RECURSE_CMD) clean $(COLORIZE)
2017-11-29 01:06:21 +08:00
%.variant-clean:
$(PRINT_COMMAND) $(RECURSE_CMD) VARIANT=$* VARIANTS= clean $(COLORIZE)
2017-03-25 06:57:50 +08:00
2017-11-28 18:16:36 +08:00
distclean nuke: clean
-$(PRINT_CLEAN) rm -rf $(OBJPRODUCTS) $(OBJFILES) $(LOGS)
2017-03-25 06:57:50 +08:00
help:
@$(ECHO) "Available targets:"
@$(ECHO) " make : Build default target (TARGET=$(TARGET))"
@$(ECHO) " make all : Same"
2017-11-28 19:50:32 +08:00
@$(ECHO) " make debug : Debug build"
@$(ECHO) " make opt : Optimized build with debug info"
@$(ECHO) " make release : Release build without debug info"
@$(ECHO) " make profile : Profile build"
2017-03-25 06:57:50 +08:00
@$(ECHO) " make clean : Clean build results (only BUILDENV=$(BUILDENV))"
@$(ECHO) " make rebuild : Clean before building"
@$(ECHO) " make nuke : Clean build directory"
@$(ECHO) " make test : Run sanity tests (run only tests)"
@$(ECHO) " make check : Build product, then run tests"
@$(ECHO) " make benchmark : Build product, then run benchmarks"
@$(ECHO) " make install : Build and install result"
@$(ECHO) " make v-[target] : Build target in 'verbose' mode"
@$(ECHO) " make d-[target] : Deep-checking of library dependencies"
@$(ECHO) " make top-[target] : Rebuild from top-level directory"
#------------------------------------------------------------------------------
# Internal targets
#------------------------------------------------------------------------------
build: hello config libraries prebuild recurse objects product postbuild goodbye
2017-03-25 06:57:50 +08:00
hello:
2017-11-29 01:06:21 +08:00
@$(INFO) "[BEGIN]" $(TARGET) $(BUILDENV) in "$(PRETTY_DIR)"
2017-03-25 06:57:50 +08:00
goodbye:
2017-11-29 01:06:21 +08:00
@$(INFO) "[END]" $(TARGET) $(BUILDENV) in "$(PRETTY_DIR)"
2017-03-25 06:57:50 +08:00
# Sequencing build steps and build step hooks
config: hello
config: $(VARIANTS:%=%.variant)
ifeq ($(VARIANTS),)
config: $(CONFIG:%=config.h)
2017-11-28 00:58:00 +08:00
config: $(NORM_CONFIG:%=$(OBJDIR)CFG_HAVE_%.mk)
endif
libraries: config
libraries: $(OBJLIBS) $(OBJDLLS)
prebuild: config
objects: prebuild
2017-11-28 01:19:58 +08:00
objects:$(OBJDIR:%=%.mkdir) $(OBJECTS)
product:$(OBJPRODUCTS)
2017-11-28 19:50:32 +08:00
postbuild: product $(DO_INSTALL)
do_install: $(TO_INSTALL)
goodbye: postbuild
2017-03-25 06:57:50 +08:00
# Run the test (in the object directory)
product.test: product .ALWAYS
$(PRINT_TEST) $(TEST_ENV) $(OUTPUT_EXE) $(PRODUCTS_OPTS)
2017-03-25 06:57:50 +08:00
# Run a test from a C or C++ file to link against current library
%.c.test: $(OUTPUT_LIB) .ALWAYS
2017-11-28 22:03:35 +08:00
$(PRINT_BUILD) $(MAKE) SOURCES=$*.c LINK_LIBS="$(PRODUCTS_LIBS)" PRODUCTS=$*.exe $(TARGET)
2017-11-28 01:16:05 +08:00
$(PRINT_TEST) $(TEST_ENV) $(TEST_CMD_$*) $(OUTPUT)$*$(EXE_EXT) $(TEST_ARGS_$*)
%.cpp.test: $(OUTPUT_LIB) .ALWAYS
2017-11-28 22:03:35 +08:00
$(PRINT_BUILD) $(MAKE) SOURCES=$*.cpp LINK_LIBS="$(PRODUCTS_LIBS)" PRODUCTS=$*.exe $(TARGET)
2017-11-28 01:16:05 +08:00
$(PRINT_TEST) $(TEST_ENV) $(TEST_CMD_$*) $(OUTPUT)$*$(EXE_EXT) $(TEST_ARGS_$*)
2017-03-25 06:57:50 +08:00
# Installing the product: always need to build it first
2017-11-28 19:50:32 +08:00
%.install_exe: $(PREFIX_BIN).mkdir-only product
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_BIN)
2017-11-28 19:50:32 +08:00
%.install_lib: $(PREFIX_LIB).mkdir-only product
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_LIB)
2017-11-28 19:50:32 +08:00
%.install_dll: $(PREFIX_DLL).mkdir-only product
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_DLL)
2017-11-28 19:50:32 +08:00
%.install_hdr: $(PREFIX_HDR).mkdir-only
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_HDR)
2017-03-25 06:57:50 +08:00
# Benchmarking (always done with profile target)
benchmark: $(BENCHMARK:%=%.benchmark) $(BENCHMARKS:%=%.benchmark)
product.benchmark: product .ALWAYS
$(PRINT_TEST) gprof
2017-03-25 06:57:50 +08:00
2017-11-28 18:16:36 +08:00
.PHONY: hello goodbye
.PHONY: all debug opt release profile build test install
.PHONY: config libraries recurse prebuild objects product postbuild
2017-03-25 06:57:50 +08:00
.PHONY: .ALWAYS
#------------------------------------------------------------------------------
# Build target modifiers
#------------------------------------------------------------------------------
# Make from the top-level directory (useful from child directories)
top-%:
cd $(TOP); $(MAKE) $*
2017-03-25 06:57:50 +08:00
# Verbose build (show all commands as executed)
v-% verbose-%:
$(PRINT_COMMAND) $(MAKE) $* V=1
2017-03-25 06:57:50 +08:00
# Timed build (show the time for each step)
t-% time-%:
$(PRINT_COMMAND) time $(MAKE) $*
2017-11-28 19:50:32 +08:00
# Timed build (show the time for each step)
notime-%:
$(PRINT_COMMAND) $(MAKE) TIME= $*
# Installation build
install-%:
$(PRINT_COMMAND) $(MAKE) DO_INSTALL=do_install
2017-03-25 06:57:50 +08:00
# Deep build (re-check all libraries instead of just resulting .a)
d-% deep-%:
$(PRINT_COMMAND) $(MAKE) $* DEEP_BUILD=deep_build
# Silent build (logs errors only to build.err)
s-% silent-%:
$(PRINT_COMMAND) $(MAKE) -s --no-print-directory $* 2> build.err
# Logged build (show results and record them in build.log)
l-% log-%:
$(PRINT_COMMAND) $(MAKE) $*
nolog-% nl-%:
$(PRINT_COMMAND) $(MAKE) $* LOG_COMMANDS=
# No colorization
nocolor-% nocol-% bw-%:
$(PRINT_COMMAND) $(MAKE) $* COLORIZE=
# For debug-install, run 'make TARGET=debug install'
debug-% opt-% release-% profile-%:
@$(MAKE) TARGET=$(@:-$*=) $*
#------------------------------------------------------------------------------
# Subdirectories and requirements
#------------------------------------------------------------------------------
recurse: $(SUBDIRS:%=%.recurse)
%.dll.recurse: | hello prebuild
+$(PRINT_COMMAND) $(MAKE) $*.recurse BUILD_DLL=dll
%.project.recurse: | hello prebuild
+$(PRINT_COMMAND) $(MAKE) PROJECT=$*
%.recurse: | hello prebuild
+$(PRINT_COMMAND) cd $* && $(RECURSE_CMD)
# If LIBRARIES=foo/bar, go to directory foo/bar, which should build bar.a
2017-11-28 01:16:05 +08:00
$(OUTPUT)$(LIB_PFX)%$(LIB_EXT): $(DEEP_BUILD)
+$(PRINT_COMMAND) cd $(firstword $(dir $(filter %$*, $(LIBRARIES:.lib=) $(SUBDIRS))) .) && $(RECURSE_CMD)
2017-11-28 01:16:05 +08:00
$(OUTPUT)$(DLL_PFX)%$(DLL_EXT): $(DEEP_BUILD)
+$(PRINT_COMMAND) cd $(firstword $(dir $(filter %$*, $(LIBRARIES:.dll=) $(SUBDIRS))) .) && $(RECURSE_CMD)
%/.test:
2017-03-25 06:57:50 +08:00
+$(PRINT_TEST) cd $* && $(MAKE) TARGET=$(TARGET) test
deep_build:
2017-11-20 21:36:06 +08:00
%.variant:
$(PRINT_VARIANT) $(MAKE) VARIANTS= VARIANT=$* RECURSE=build build
2017-03-25 06:57:50 +08:00
#------------------------------------------------------------------------------
# Progress printout
#------------------------------------------------------------------------------
INCR_INDEX= $(eval BUILD_INDEX:=$(shell echo $$(($(BUILD_INDEX)+1))))
PRINT_COUNT= $(shell printf "%3d/%d" $(BUILD_INDEX) $(BUILD_COUNT))$(INCR_INDEX)
PRINT_PCT= $(shell printf "%3d%%" $$(( ($(BUILD_HIGH) - $(BUILD_LOW)) * $(BUILD_INDEX) / $(BUILD_COUNT) + $(BUILD_LOW))))$(INCR_INDEX)
# Printing out various kinds of statements
ifndef V
2017-03-25 06:57:50 +08:00
PRINT_COMMAND= @
PRINT_COMPILE= $(PRINT_COMMAND) $(INFO) "[COMPILE$(PRINT_COUNT)] " $<;
PRINT_BUILD= $(PRINT_COMMAND) $(INFO) "[BUILD]" $(shell basename $@);
PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" "$(shell basename "$@")";
2017-11-20 21:36:06 +08:00
PRINT_VARIANT= $(PRINT_COMMAND) $(INFO) "[VARIANT]" "$*";
2017-11-28 19:50:32 +08:00
PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL] " $(*F) in $(<D) $(COLORIZE);
2017-11-28 18:16:36 +08:00
PRINT_CLEAN= $(PRINT_COMMAND) $(INFO) "[CLEAN] " $@ $(PRETTY_DIR) $(COLORIZE);
2017-04-05 05:01:19 +08:00
PRINT_COPY= $(PRINT_COMMAND) $(INFO) "[COPY]" $< '=>' $@ ;
2017-03-25 06:57:50 +08:00
PRINT_DEPEND= $(PRINT_COMMAND) $(INFO) "[DEPEND] " $< ;
PRINT_TEST= $(PRINT_COMMAND) $(INFO) "[TEST]" $(@:.test=) ;
PRINT_CONFIG= $(PRINT_COMMAND) $(INFO) "[CONFIG]" "$(ORIG_TARGET)" ;
PRINT_PKGCONFIG=$(PRINT_COMMAND) $(INFO) "[PKGCONFIG]" "$*" ;
PRINT_LIBCONFIG=$(PRINT_COMMAND) $(INFO) "[LIBCONFIG]" "lib$*" ;
endif
2017-03-25 06:57:50 +08:00
logs.mkdir: $(LOGS).mkdir $(dir $(LAST_LOG))/.mkdir
2017-11-28 19:50:32 +08:00
%/.mkdir-only:
$(PRINT_COMMAND) $(MAKE_DIR)
2017-03-25 06:57:50 +08:00
%/.mkdir:
$(PRINT_COMMAND) $(MAKE_OBJDIR)
.PRECIOUS: %/.mkdir
#------------------------------------------------------------------------------
# Special for Fabien: make 'Directory'
#------------------------------------------------------------------------------
ifneq ($(filter $(MAKECMDGOALS:/=),$(SUBDIRS)),)
$(MAKECMDGOALS): deep_build
2017-05-01 23:20:29 +08:00
$(PRINT_COMMAND) cd $@ && make
2017-03-25 06:57:50 +08:00
endif
ifdef RECURSE
2017-03-25 06:57:50 +08:00
#------------------------------------------------------------------------------
# Dependencies generation
#------------------------------------------------------------------------------
2017-11-28 00:58:00 +08:00
DEPENDENCIES=$(SOURCES:%=$(OBJDIR)%$(OBJ_EXT).d)
OBJDIR_DEPS=$(OBJDIR)%.deps/.mkdir
2017-03-25 06:57:50 +08:00
ifeq (3.80,$(firstword $(sort $(MAKE_VERSION) 3.80)))
OBJ_DEPS=$(OBJDIR_DEPS) $(MAKEFILE_DEPS) | prebuild
else
OBJ_DEPS=$(OBJDIR_DEPS) $(MAKEFILE_DEPS) prebuild
endif
2017-03-25 06:57:50 +08:00
2017-05-01 23:06:28 +08:00
ifndef DEPFLAGS
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.c$(OBJ_EXT).d: %.c $(OBJ_DEPS)
2017-05-01 23:06:28 +08:00
$(PRINT_DEPEND) ( $(CC_DEPEND)
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.cpp$(OBJ_EXT).d: %.cpp $(OBJ_DEPS)
2017-05-01 23:06:28 +08:00
$(PRINT_DEPEND) ( $(CXX_DEPEND)
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.s$(OBJ_EXT).d: %.s $(OBJ_DEPS)
2017-05-01 23:06:28 +08:00
$(PRINT_DEPEND) ( $(AS_DEPEND)
else
2017-11-28 00:58:00 +08:00
$(OBJDIR)%$(OBJ_EXT).d: $(OBJDIR)%$(OBJ_EXT)
2017-05-01 23:06:28 +08:00
endif
2017-03-25 06:57:50 +08:00
#------------------------------------------------------------------------------
# Inference rules
#------------------------------------------------------------------------------
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.c$(OBJ_EXT): %.c $(OBJ_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_COMPILE) $(MAKE_CC)
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.cpp$(OBJ_EXT): %.cpp $(OBJ_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_COMPILE) $(MAKE_CXX)
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.s$(OBJ_EXT): %.s $(OBJ_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_COMPILE) $(MAKE_AS)
.SECONDEXPANSION:
$(OUTPUT_LIB): $(LINK_INPUTS) $$(LINK_INPUTS) $(MAKEFILE_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_BUILD) $(MAKE_LIB)
$(OUTPUT_DLL): $(LINK_INPUTS) $$(LINK_INPUTS) $(MAKEFILE_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_BUILD) $(MAKE_DLL)
$(OUTPUT_EXE): $(LINK_INPUTS) $$(LINK_INPUTS) $(MAKEFILE_DEPS)
2017-03-25 06:57:50 +08:00
$(PRINT_BUILD) $(MAKE_EXE)
# Include dependencies from current directory
# We only build when the target is set to avoid dependencies on 'clean'
ifeq ($(MAKECMDGOALS),build)
-include $(DEPENDENCIES)
endif
#------------------------------------------------------------------------------
# Package configuration
#------------------------------------------------------------------------------
# Package configuration file
2017-11-28 00:58:00 +08:00
PKG_CFLAGS= $(PKGCONFIGS:%=$(OBJDIR)%.pkg-config.cflags)
PKG_LDFLAGS= $(PKGCONFIGS:%=$(OBJDIR)%.pkg-config.ldflags)
CONFIG_LIBS=
2017-11-28 00:58:00 +08:00
PKG_LIBS= $(patsubst %,$(OBJDIR)%.cfg.ldflags,$(filter lib%,$(CONFIG)))
2017-11-28 00:58:00 +08:00
PKG_DEPS= $(MAKEFILE_DEPS) $(OBJDIR).mkdir
2017-11-28 00:58:00 +08:00
$(OBJDIR)pkg-config.mk: $(PKG_CFLAGS) $(PKG_LDFLAGS) $(PKG_LIBS)
$(PRINT_COMMAND) (echo CFLAGS_PKGCONFIG=`$(CAT) $(PKG_CFLAGS)`; echo LDFLAGS_PKGCONFIG=`$(CAT) $(PKG_LDFLAGS) $(PKG_LIBS)`) > $@
2017-11-28 00:58:00 +08:00
-include $(PKGCONFIGS:%=$(OBJDIR)pkg-config.mk)
2017-11-28 00:58:00 +08:00
$(OBJDIR)%?.pkg-config.cflags: $(PKG_DEPS)
$(PRINT_PKGCONFIG) (pkg-config --cflags $* --silence-errors || true) > $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)%?.pkg-config.ldflags: $(PKG_DEPS)
$(PRINT_COMMAND) (pkg-config --libs $* --silence-errors || true) > $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.pkg-config.cflags: $(PKG_DEPS)
$(PRINT_PKGCONFIG) pkg-config --cflags $* > $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)%.pkg-config.ldflags: $(PKG_DEPS)
$(PRINT_COMMAND) pkg-config --libs $* > $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)lib%.cfg.ldflags: $(OBJDIR)CFG_HAVE_lib%.h $(PKG_DEPS)
$(PRINT_COMMAND) (grep -q 'define ' $< && echo $(LINK_CFG_OPT)$* || true) > $@
#------------------------------------------------------------------------------
# Configuration rules
#------------------------------------------------------------------------------
NORM_CONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG))))
ORIG_TARGET=$(subst .lt.,<,$(subst .gt.,>,$(subst .sl.,/,$*)))
2017-11-28 00:58:00 +08:00
CONFIG_DEPS= $(MAKEFILE_DEPS) $(OBJDIR).mkdir \
$(PKGCONFIGS:%=$(OBJDIR)pkg-config.mk)
2017-11-28 00:58:00 +08:00
config.h: $(NORM_CONFIG:%=$(OBJDIR)CFG_HAVE_%.h)
$(PRINT_GENERATE) cat $^ > $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG_HAVE_%.mk: $(OBJDIR)CFG_HAVE_%.h $(MAKEFILE_DEPS)
$(PRINT_COMMAND) $(MAKE_CONFIG)
2017-11-28 00:58:00 +08:00
-include $(NORM_CONFIG:%=$(OBJDIR)CFG_HAVE_%.mk)
# C standard headers, e.g. HAVE_<stdio.h>
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG_HAVE_.lt.%.h.gt..h: $(OBJDIR)CFG-CH_HAVE_%.c $(CONFIG_DEPS)
$(PRINT_CONFIG) $(CC_CONFIG)
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-CH_HAVE_%.c: $(OBJDIR).mkdir $(CONFIG_DEPS)
$(PRINT_COMMAND) (echo '#include' "<$(ORIG_TARGET).h>" && echo 'int main() { return 0; }') > "$@"
2017-11-28 00:58:00 +08:00
.PRECIOUS: $(OBJDIR)CFG-CH_HAVE_%.c
# C++ Standard headers, e.g. HAVE_<iostream>
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG_HAVE_.lt.%.gt..h: $(OBJDIR)CFG-C++H_HAVE_%.cpp $(CONFIG_DEPS)
$(PRINT_CONFIG) $(CXX_CONFIG)
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-C++H_HAVE_%.cpp: $(OBJDIR).mkdir $(CONFIG_DEPS)
$(PRINT_COMMAND) (echo '#include' "<$(ORIG_TARGET)>" && echo 'int main() { return 0; }') > "$@"
2017-11-28 00:58:00 +08:00
.PRECIOUS: $(OBJDIR)CFG-C++H_HAVE_%.cpp
2017-05-02 22:03:17 +08:00
# Library
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG_HAVE_lib%.h: $(OBJDIR)CFG-LIB_HAVE_lib%.c $(PKG_DEPS)
2017-05-02 22:03:17 +08:00
$(PRINT_LIBCONFIG) $(LIB_CONFIG)
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-LIB_HAVE_lib%.c: $(OBJDIR).mkdir $(PKG_DEPS)
$(PRINT_COMMAND) echo 'int main() { return 0; }' > "$@"
2017-11-28 00:58:00 +08:00
.PRECIOUS: $(OBJDIR)CFG-LIB_HAVE_lib%.c
2017-05-02 22:03:17 +08:00
# Check if a function is present
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG_HAVE_%.h: $(OBJDIR)CFG-FN_HAVE_%.c $(CONFIG_DEPS)
$(PRINT_CONFIG) $(FN_CONFIG)
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-FN_HAVE_%.c: $(BUILD)config/HAVE_%.c $(CONFIG_DEPS)
$(PRINT_COMMAND) cp $< $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-FN_HAVE_%.c: config/HAVE_%.c $(CONFIG_DEPS)
$(PRINT_COMMAND) cp $< $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-FN_HAVE_%.c: $(BUILD)config/check_%.c $(CONFIG_DEPS)
$(PRINT_COMMAND) cp $< $@
2017-11-28 00:58:00 +08:00
$(OBJDIR)CFG-FN_HAVE_%.c: config/check_%.c $(CONFIG_DEPS)
$(PRINT_COMMAND) cp $< $@
2017-11-28 00:58:00 +08:00
.PRECIOUS: $(OBJDIR)CFG-FN_HAVE_%.c
endif
2017-03-25 06:57:50 +08:00
#------------------------------------------------------------------------------
# Makefile optimization tricks
#------------------------------------------------------------------------------
# Disable all built-in rules for performance
.SUFFIXES:
# Build with a single shell for all commands
.ONESHELL:
2017-11-28 19:50:32 +08:00
# Only build the leaf projects in parallel,
# since we don't have proper dependency between independent
# libraries and we may otherwise end up building the same
# library multiple times "in parallel" (wasting energy)
ifneq ($(SUBDIRS)$(VARIANTS),)
$(NOT_PARALLEL):
endif