2019-03-22 23:35:00 +08:00
|
|
|
# ******************************************************************************
|
|
|
|
# rules.mk make-it-quick project
|
|
|
|
# ******************************************************************************
|
2017-03-25 06:57:50 +08:00
|
|
|
#
|
2019-03-22 23:35:00 +08:00
|
|
|
# File description:
|
2017-03-25 06:57:50 +08:00
|
|
|
#
|
|
|
|
# Common rules for building the targets
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
2019-03-22 23:35:00 +08:00
|
|
|
# ******************************************************************************
|
|
|
|
# This software is licensed under the GNU General Public License v3
|
|
|
|
# (C) 2017-2019, Christophe de Dinechin <christophe@dinechin.org>
|
|
|
|
# ******************************************************************************
|
|
|
|
# This file is part of make-it-quick
|
2019-03-16 01:54:07 +08:00
|
|
|
#
|
2019-03-22 23:35:00 +08:00
|
|
|
# make-it-quick is free software: you can r redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
2019-03-16 01:54:07 +08:00
|
|
|
#
|
2019-03-22 23:35:00 +08:00
|
|
|
# make-it-quick is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2019-03-16 01:54:07 +08:00
|
|
|
#
|
2019-03-22 23:35:00 +08:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with make-it-quick, in a file named COPYING.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
# ******************************************************************************
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Include the Makefile configuration and local variables
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ?=make-it-quick/
|
|
|
|
include $(MIQ)config.mk
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Default build settings (definitions in specific config..mkXYZ)
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_INCLUDES= $(INCLUDES) \
|
|
|
|
$(INCLUDES_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(INCLUDES_TARGET_$(TARGET)) \
|
|
|
|
$(INCLUDES_VARIANT_$(VARIANT)) \
|
|
|
|
$(INCLUDES_$*)
|
|
|
|
|
|
|
|
MIQ_DEFINES= $(DEFINES) \
|
|
|
|
$(DEFINES_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(DEFINES_TARGET_$(TARGET)) \
|
|
|
|
$(DEFINES_VARIANT_$(VARIANT)) \
|
|
|
|
$(DEFINES_$*)
|
|
|
|
|
2020-03-05 04:22:56 +08:00
|
|
|
MIQ_CPPFLAGS= $(MIQ_DEFINES:%=-D%) \
|
|
|
|
$(MIQ_INCLUDES:%=-I%) \
|
|
|
|
$(CPPFLAGS) \
|
2018-04-05 23:25:12 +08:00
|
|
|
$(CPPFLAGS_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(CPPFLAGS_TARGET_$(TARGET)) \
|
|
|
|
$(CPPFLAGS_VARIANT_$(VARIANT)) \
|
2020-03-05 04:22:56 +08:00
|
|
|
$(CPPFLAGS_$*)
|
2018-04-05 23:25:12 +08:00
|
|
|
|
|
|
|
MIQ_CFLAGS= $(CFLAGS) \
|
2018-04-11 00:56:25 +08:00
|
|
|
$(CFLAGS_DEPENDENCIES) \
|
2018-04-10 23:43:29 +08:00
|
|
|
$(CFLAGS_STD) \
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_CPPFLAGS) \
|
|
|
|
$(CFLAGS_PKGCONFIG) \
|
|
|
|
$(CFLAGS_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(CFLAGS_TARGET_$(TARGET)) \
|
|
|
|
$(CFLAGS_VARIANT_$(VARIANT)) \
|
|
|
|
$(CFLAGS_$*)
|
|
|
|
|
|
|
|
MIQ_CXXFLAGS= $(CXXFLAGS) \
|
|
|
|
$(MIQ_CPPFLAGS) \
|
|
|
|
$(CFLAGS_PKGCONFIG) \
|
2018-04-11 00:56:25 +08:00
|
|
|
$(CFLAGS_DEPENDENCIES) \
|
2018-04-05 23:25:12 +08:00
|
|
|
$(CXXFLAGS_STD) \
|
|
|
|
$(CXXFLAGS_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(CXXFLAGS_TARGET_$(TARGET)) \
|
|
|
|
$(CXXFLAGS_VARIANT_$(VARIANT)) \
|
|
|
|
$(CXXFLAGS_$*)
|
|
|
|
|
|
|
|
MIQ_LDFLAGS= $(LDFLAGS) \
|
|
|
|
$(LDFLAGS_PKGCONFIG) \
|
|
|
|
$(LDFLAGS_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(LDFLAGS_TARGET_$(TARGET)) \
|
|
|
|
$(LDFLAGS_VARIANT_$(VARIANT)) \
|
2019-04-13 04:37:35 +08:00
|
|
|
$(LDFLAGS_RPATH) \
|
2018-04-05 23:25:12 +08:00
|
|
|
$(LDFLAGS_$*)
|
|
|
|
|
2018-04-06 05:47:28 +08:00
|
|
|
MIQ_PACKAGE= $(PACKAGE_NAME:%=$(MIQ_OBJDIR)%.pc)
|
|
|
|
|
2018-09-20 00:09:25 +08:00
|
|
|
MIQ_INSTALL= $(TO_INSTALL:%=%.$(DO_INSTALL)) \
|
|
|
|
$(MIQ_OUTEXE:%=%.$(DO_INSTALL)_exe) \
|
|
|
|
$(MIQ_OUTLIB:%=%.$(DO_INSTALL)_lib) \
|
|
|
|
$(MIQ_OUTDLL:%=%.$(DO_INSTALL)_dll) \
|
|
|
|
$(EXE_INSTALL:%=%.$(DO_INSTALL)_exe) \
|
|
|
|
$(LIB_INSTALL:%=%.$(DO_INSTALL)_lib) \
|
|
|
|
$(DLL_INSTALL:%=%.$(DO_INSTALL)_dll) \
|
|
|
|
$(HEADERS:%=%.$(DO_INSTALL)_hdr) \
|
|
|
|
$(HDR_INSTALL:%=%.$(DO_INSTALL)_hdr) \
|
2019-03-15 17:13:21 +08:00
|
|
|
$(SHR_INSTALL:%=%.$(DO_INSTALL)_shr) \
|
2019-03-15 19:10:44 +08:00
|
|
|
$(DOC_INSTALL:%=%.$(DO_INSTALL)_doc) \
|
2019-03-11 15:21:52 +08:00
|
|
|
$(MANPAGES:%=%.gz.$(DO_INSTALL)_man) \
|
|
|
|
$(MAN_INSTALL:%=%.gz.$(DO_INSTALL)_man) \
|
|
|
|
$(ETC_INSTALL:%=%.$(DO_INSTALL)_etc) \
|
2018-09-20 00:09:25 +08:00
|
|
|
$(MIQ_PACKAGE:%=%.$(DO_INSTALL)_pc)
|
2018-04-05 23:25:12 +08:00
|
|
|
|
|
|
|
MIQ_SOURCES= $(SOURCES) \
|
|
|
|
$(SOURCES_BUILDENV_$(BUILDENV)) \
|
|
|
|
$(SOURCES_TARGET_$(TARGET)) \
|
|
|
|
$(SOURCES_VARIANT_$(VARIANT)) \
|
|
|
|
$(MIQ_OUT_SOURCES)
|
|
|
|
|
2019-03-11 15:21:52 +08:00
|
|
|
# Automatically put the man pages in the correct section
|
2020-12-19 03:51:12 +08:00
|
|
|
MIQ_MANDIR= $(PACKAGE_INSTALL.man)man$(MIQ_MANSECT)/
|
2019-03-11 15:21:52 +08:00
|
|
|
MIQ_MANSECT= $(subst .,,$(suffix $(*:.gz=)))
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
ifndef MIQ_DIR
|
|
|
|
MIQ_FULLDIR:= $(abspath .)/
|
|
|
|
MIQ_DIR:= $(subst $(abspath $(TOP))/,,$(MIQ_FULLDIR))
|
|
|
|
MIQ_PRETTYDIR:= $(subst $(abspath $(TOP))/,[top],$(MIQ_FULLDIR)$(VARIANT:%=[%]))
|
|
|
|
MIQ_BUILDDATE:= $(shell /bin/date '+%Y%m%d-%H%M%S')
|
2020-09-02 04:11:55 +08:00
|
|
|
MIQ_OBJROOT:= $(BUILD)$(BUILDENV)/$(CROSS_COMPILE:%=%-)$(TARGET)
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_BUILDLOG:= $(LOGS)build-$(BUILDENV)-$(CROSS_COMPILE:%=%-)$(TARGET)-$(MIQ_BUILDDATE).log
|
2017-03-25 06:57:50 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Configuration variables
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_OBJDIR:= $(MIQ_OBJROOT)/$(MIQ_DIR)
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_OBJECTS= $(MIQ_SOURCES:%=$(MIQ_OBJDIR)%$(EXT.obj))
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_PRODEXE= $(filter %.exe,$(PRODUCTS))
|
|
|
|
MIQ_PRODLIB= $(filter %.lib,$(PRODUCTS))
|
|
|
|
MIQ_PRODDLL= $(filter %.dll,$(PRODUCTS))
|
2018-04-10 23:43:29 +08:00
|
|
|
MIQ_PRODLIBS= $(OUTPUT:%=$(LINK_DIR_OPT)%) $(filter %.lib %.dll,$(PRODUCTS))
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_OUTEXE= $(MIQ_PRODEXE:%.exe=$(OUTPUT)$(PFX.exe)%$(EXT.exe))
|
|
|
|
MIQ_OUTLIB= $(MIQ_PRODLIB:%.lib=$(OUTPUT)$(PFX.lib)%$(EXT.lib))
|
|
|
|
MIQ_OUTDLL= $(MIQ_PRODDLL:%.dll=$(OUTPUT)$(PFX.dll)%$(EXT.dll))
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_OUTPRODS= $(MIQ_OUTEXE) $(MIQ_OUTLIB) $(MIQ_OUTDLL)
|
2018-04-10 23:43:29 +08:00
|
|
|
MIQ_BUILDTEST= $(MAKE) SOURCES=$(@:%.test=%) \
|
|
|
|
PRODUCTS=$*_test.exe \
|
|
|
|
RUN_TESTS= \
|
2018-10-27 19:04:50 +08:00
|
|
|
LINK_LIBS="$(MIQ_PRODLIBS)" \
|
|
|
|
.build
|
|
|
|
|
2018-04-10 23:43:29 +08:00
|
|
|
MIQ_RUNTEST= $(TEST_ENV) \
|
|
|
|
$(TEST_CMD_$*) \
|
2020-09-02 04:04:53 +08:00
|
|
|
$(OUTPUT)$(PFX.exe)$*_test$(EXT.exe) \
|
2018-04-10 23:43:29 +08:00
|
|
|
$(TEST_ARGS_$*)
|
2017-04-02 01:11:06 +08:00
|
|
|
|
2018-05-26 17:17:39 +08:00
|
|
|
# Versioning for DLLs
|
|
|
|
MIQ_V_WORDS= $(subst ., ,$(PRODUCTS_VERSION))
|
|
|
|
MIQ_V_MAJOR= $(word 1,$(MIQ_V_WORDS) 0 0 0)
|
|
|
|
MIQ_V_MINOR= $(word 2,$(MIQ_V_WORDS) 0 0 0)
|
|
|
|
MIQ_V_PATCH= $(word 3,$(MIQ_V_WORDS) 0 0 0)
|
|
|
|
MIQ_V_VERSION= $(MIQ_V_MAJOR).$(MIQ_V_MINOR).$(MIQ_V_PATCH)
|
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# 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),)
|
2018-04-05 23:25:12 +08:00
|
|
|
ifeq ($(MIQ_PRODEXE)$(MIQ_PRODLIB)$(MIQ_PRODDLL),)
|
|
|
|
$(error Error: Variable PRODUCTS must contain .exe, .lib or .dll)
|
2017-04-02 01:11:06 +08:00
|
|
|
endif
|
2017-11-07 00:18:14 +08:00
|
|
|
endif
|
2017-04-02 01:11:06 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_LIBS= $(LIBRARIES) $(LINK_LIBS)
|
|
|
|
MIQ_LIBNAMES= $(filter %.lib, $(notdir $(MIQ_LIBS)))
|
|
|
|
MIQ_DLLNAMES= $(filter %.dll, $(notdir $(MIQ_LIBS)))
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_OBJLIBS= $(MIQ_LIBNAMES:%.lib=$(OUTPUT)$(PFX.lib)%$(EXT.lib))
|
|
|
|
MIQ_OBJDLLS= $(MIQ_DLLNAMES:%.dll=$(OUTPUT)$(PFX.dll)%$(EXT.dll))
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_LINKLIBS= $(MIQ_LIBNAMES:%.lib=$(LINK_LIB_OPT)%) \
|
|
|
|
$(MIQ_DLLNAMES:%.dll=$(LINK_DLL_OPT)%)
|
|
|
|
MIQ_TOLINK= $(MIQ_OBJECTS) $(MIQ_OBJLIBS) $(MIQ_OBJDLLS)
|
2018-06-15 15:38:35 +08:00
|
|
|
MIQ_LINKARGS= $(MIQ_OBJECTS) \
|
|
|
|
$(OUTPUT:%=$(LINK_DIR_OPT)%) \
|
|
|
|
$(MIQ_LINKLIBS)
|
2018-05-14 22:14:19 +08:00
|
|
|
MIQ_RECURSE= $(MAKE) TARGET=$(TARGET) \
|
2018-04-05 23:25:12 +08:00
|
|
|
BUILDENV=$(RECURSE_BUILDENV) \
|
|
|
|
TOP="$(abspath $(TOP))/" \
|
2018-05-15 22:29:22 +08:00
|
|
|
VARIANT= \
|
2018-04-05 23:25:12 +08:00
|
|
|
COLOR_FILTER= \
|
|
|
|
$(RECURSE)
|
|
|
|
MIQ_MAKEDEPS:= $(MAKEFILE_LIST)
|
|
|
|
MIQ_INDEX:= 1
|
|
|
|
MIQ_COUNT:= $(words $(MIQ_SOURCES))
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_PROFOUT:= $(subst $(EXT.exe),,$(MIQ_OUTEXE))_prof_$(GIT_REVISION).vsp
|
2018-04-05 23:25:12 +08:00
|
|
|
|
2018-09-20 00:52:54 +08:00
|
|
|
MIQ_TARNAME= $(PACKAGE_NAME)-$(PACKAGE_VERSION)
|
|
|
|
MIQ_TARBALL= $(MIQ_TARNAME).tar.bz2
|
|
|
|
|
2018-05-08 16:47:48 +08:00
|
|
|
ifeq (3.80,$(firstword $(sort $(MAKE_VERSION) 3.80)))
|
|
|
|
MIQ_ORDERONLY=|
|
|
|
|
endif
|
|
|
|
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# User targets
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
all: $(TARGET)
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
debug opt release profile: $(LOGS).mkdir $(dir $(LAST_LOG)).mkdir
|
|
|
|
$(PRINT_COMMAND) $(TIME) $(MAKE) TARGET=$@ RECURSE=.build LOG_COMMANDS= .build $(LOG_COMMANDS)
|
2017-04-02 01:11:06 +08:00
|
|
|
|
|
|
|
# Testing
|
2018-09-20 00:11:46 +08:00
|
|
|
test tests check installcheck: test-$(TARGET)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# Clean builds
|
2018-04-05 23:25:12 +08:00
|
|
|
rebuild: re-$(TARGET)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# Installation
|
2018-04-05 23:25:12 +08:00
|
|
|
install: install-$(TARGET)
|
2018-09-20 00:09:25 +08:00
|
|
|
uninstall: uninstall-$(TARGET)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-11-29 01:06:21 +08:00
|
|
|
clean: $(SUBDIRS:%=%.clean) $(VARIANTS:%=%.variant-clean)
|
2018-04-05 23:25:12 +08:00
|
|
|
-$(PRINT_CLEAN) rm -f $(TO_CLEAN) $(MIQ_OBJECTS) $(DEPENDENCIES) $(MIQ_OUTPRODS) $(MIQ_TOLINK) config.h
|
2017-11-28 18:16:36 +08:00
|
|
|
%.clean:
|
2018-04-05 23:25:12 +08:00
|
|
|
$(PRINT_COMMAND) cd $* && $(MIQ_RECURSE) clean $(COLORIZE)
|
2017-11-29 01:06:21 +08:00
|
|
|
%.variant-clean:
|
2018-04-05 23:25:12 +08:00
|
|
|
$(PRINT_COMMAND) $(MIQ_RECURSE) VARIANT=$* VARIANTS= clean $(COLORIZE)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-09-20 00:52:54 +08:00
|
|
|
dist: $(MIQ_TARBALL)
|
|
|
|
$(MIQ_TARBALL): AUTHORS NEWS
|
|
|
|
$(PRINT_GENERATE) $(GEN_TARBALL)
|
|
|
|
AUTHORS: .ALWAYS
|
|
|
|
$(PRINT_GENERATE) $(GEN_AUTHORS) > $@
|
|
|
|
NEWS: .ALWAYS
|
|
|
|
$(PRINT_GENERATE) $(GEN_NEWS)
|
|
|
|
|
2017-11-28 18:16:36 +08:00
|
|
|
distclean nuke: clean
|
2020-09-02 04:11:55 +08:00
|
|
|
-$(PRINT_CLEAN) rm -rf $(MIQ_OUTPRODS) $(BUILD) $(LOGS) $(MIQ_TARBALL)
|
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"
|
2018-09-20 00:09:25 +08:00
|
|
|
@$(ECHO) " make check / test : Build product and run sanity checks"
|
2017-03-25 06:57:50 +08:00
|
|
|
@$(ECHO) " make benchmark : Build product, then run benchmarks"
|
|
|
|
@$(ECHO) " make install : Build and install result"
|
2018-09-20 00:09:25 +08:00
|
|
|
@$(ECHO) " make uninstall : Remove the installed results"
|
|
|
|
@$(ECHO) " make dist : Create a tarball for packaging"
|
2018-02-15 17:51:15 +08:00
|
|
|
@$(ECHO) " make clang-format : Reformat sources using clang-format"
|
2017-03-25 06:57:50 +08:00
|
|
|
@$(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
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
.build: .hello .config .libraries .prebuild \
|
|
|
|
.recurse .objects .product \
|
2018-11-19 17:30:18 +08:00
|
|
|
.postbuild $(RUN_TESTS:%=.tests) .goodbye
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
.hello:
|
|
|
|
@$(INFO) "[BEGIN]" $(TARGET) $(BUILDENV) in "$(MIQ_PRETTYDIR)"
|
|
|
|
.goodbye:
|
|
|
|
@$(INFO) "[END]" $(TARGET) $(BUILDENV) in "$(MIQ_PRETTYDIR)"
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-11-24 20:17:17 +08:00
|
|
|
# Sequencing build steps and build step hooks
|
2018-04-05 23:25:12 +08:00
|
|
|
.config: .hello
|
|
|
|
.config: $(VARIANTS:%=%.variant)
|
2017-11-28 01:55:15 +08:00
|
|
|
ifeq ($(VARIANTS),)
|
2018-04-05 23:25:12 +08:00
|
|
|
.config: $(CONFIG:%=config.h)
|
|
|
|
.config: $(MIQ_NORMCONFIG:%=$(MIQ_OBJDIR)CFG_HAVE_%.mk)
|
2017-11-28 01:55:15 +08:00
|
|
|
endif
|
2018-04-05 23:25:12 +08:00
|
|
|
.libraries: .config
|
|
|
|
.libraries: $(MIQ_OBJLIBS) $(MIQ_OBJDLLS)
|
|
|
|
.prebuild: .config
|
|
|
|
.objects: .prebuild
|
|
|
|
.objects: $(MIQ_OBJDIR:%=%.mkdir)
|
|
|
|
.product: $(MIQ_OUTPRODS)
|
2018-09-20 00:09:25 +08:00
|
|
|
.postbuild: .product .install
|
|
|
|
.install: $(DO_INSTALL:%=$(MIQ_INSTALL))
|
2018-11-19 17:30:18 +08:00
|
|
|
.tests: $(TESTS:%=%.test)
|
2018-04-05 23:25:12 +08:00
|
|
|
.goodbye: .postbuild
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: all debug opt release profile build test install rebuild
|
|
|
|
.PHONY: .hello .config .libraries .prebuild \
|
|
|
|
.recurse .objects .product \
|
|
|
|
.postbuild .goodbye
|
2017-03-25 06:57:50 +08:00
|
|
|
.PHONY: .ALWAYS
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Build target modifiers
|
|
|
|
#------------------------------------------------------------------------------
|
2018-04-05 23:25:12 +08:00
|
|
|
# These are only defined when RECURSE is not set so that we can have
|
|
|
|
# files that contain the patterns, e.g. log-file.c
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
ifndef RECURSE
|
2017-03-25 06:57:50 +08:00
|
|
|
# Make from the top-level directory (useful from child directories)
|
|
|
|
top-%:
|
2017-11-27 23:38:31 +08:00
|
|
|
cd $(TOP); $(MAKE) $*
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-10 23:43:29 +08:00
|
|
|
# Test build
|
|
|
|
test-%:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) RUN_TESTS=yes $*
|
|
|
|
|
2017-03-25 06:57:50 +08:00
|
|
|
# Verbose build (show all commands as executed)
|
|
|
|
v-% verbose-%:
|
2017-11-08 19:02:39 +08:00
|
|
|
$(PRINT_COMMAND) $(MAKE) $* V=1
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Timed build (show the time for each step)
|
2018-04-05 23:25:12 +08:00
|
|
|
time-%:
|
|
|
|
$(PRINT_COMMAND) time $(MAKE) TIME= $*
|
|
|
|
|
|
|
|
# Clean build
|
|
|
|
re-%: clean
|
|
|
|
$(PRINT_COMMAND) $(MAKE) $*
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-11-28 19:50:32 +08:00
|
|
|
# Timed build (show the time for each step)
|
|
|
|
notime-%:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) TIME= $*
|
|
|
|
|
|
|
|
# Installation build
|
|
|
|
install-%:
|
2018-04-05 23:25:12 +08:00
|
|
|
$(PRINT_COMMAND) $(MAKE) $* DO_INSTALL=install
|
2018-09-20 00:09:25 +08:00
|
|
|
uninstall-%:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) TARGET=$* DO_INSTALL=uninstall .install
|
2017-11-28 19:50:32 +08:00
|
|
|
|
2017-03-25 06:57:50 +08:00
|
|
|
# Deep build (re-check all libraries instead of just resulting .a)
|
2018-04-05 23:25:12 +08:00
|
|
|
deep-%:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) $* DEEP_BUILD=.ALWAYS
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Silent build (logs errors only to build log
|
|
|
|
silent-%:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) $* -s --no-print-directory 2> $(MIQ_BUILDLOG)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Logged build (show results and record them in build.log)
|
2018-04-05 23:25:12 +08:00
|
|
|
log-%:
|
2017-03-25 06:57:50 +08:00
|
|
|
$(PRINT_COMMAND) $(MAKE) $*
|
2018-04-05 23:25:12 +08:00
|
|
|
nolog-%:
|
2017-03-25 06:57:50 +08:00
|
|
|
$(PRINT_COMMAND) $(MAKE) $* LOG_COMMANDS=
|
|
|
|
|
|
|
|
# No colorization
|
2018-04-05 23:25:12 +08:00
|
|
|
nocolor-%:
|
2017-03-25 06:57:50 +08:00
|
|
|
$(PRINT_COMMAND) $(MAKE) $* COLORIZE=
|
|
|
|
|
|
|
|
# For debug-install, run 'make TARGET=debug install'
|
|
|
|
debug-% opt-% release-% profile-%:
|
|
|
|
@$(MAKE) TARGET=$(@:-$*=) $*
|
2018-04-05 23:25:12 +08:00
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Subdirectories and requirements
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
.recurse: $(SUBDIRS:%=%.recurse)
|
2018-05-08 16:47:48 +08:00
|
|
|
%.recurse: $(MIQ_ORDERONLY:%=% .hello .prebuild)
|
2019-04-02 05:11:00 +08:00
|
|
|
+$(PRINT_COMMAND) cd $* && $(MIQ_RECURSE) $(RECURSE_FLAGS_$*)
|
2018-04-05 23:25:12 +08:00
|
|
|
|
|
|
|
%.variant:
|
|
|
|
$(PRINT_VARIANT) $(MAKE) VARIANTS= VARIANT=$* RECURSE=.build .build
|
|
|
|
|
|
|
|
%/.mkdir-only:
|
|
|
|
$(PRINT_COMMAND) $(MAKE_DIR)
|
|
|
|
%/.mkdir:
|
|
|
|
$(PRINT_COMMAND) $(MAKE_OBJDIR)
|
|
|
|
.PRECIOUS: %/.mkdir
|
2017-04-02 01:11:06 +08:00
|
|
|
|
|
|
|
# If LIBRARIES=foo/bar, go to directory foo/bar, which should build bar.a
|
2020-09-02 04:04:53 +08:00
|
|
|
$(OUTPUT)$(PFX.lib)%$(EXT.lib): $(DEEP_BUILD)
|
2018-04-05 23:25:12 +08:00
|
|
|
+$(PRINT_COMMAND) cd $(firstword $(dir $(filter %$*, $(LIBRARIES:.lib=) $(SUBDIRS))) .nonexistent) && $(MIQ_RECURSE)
|
2020-09-02 04:04:53 +08:00
|
|
|
$(OUTPUT)$(PFX.dll)%$(EXT.dll): $(DEEP_BUILD)
|
2018-04-05 23:25:12 +08:00
|
|
|
+$(PRINT_COMMAND) cd $(firstword $(dir $(filter %$*, $(LIBRARIES:.dll=) $(SUBDIRS))) .nonexistent) && $(MIQ_RECURSE)
|
2017-11-20 21:36:06 +08:00
|
|
|
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Progress printout
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_INCRIDX= $(eval MIQ_INDEX:=$(shell echo $$(($(MIQ_INDEX)+1))))
|
|
|
|
MIQ_START= $(eval MIQ_INDEX:=1) $(eval MIQ_COUNT:=$(words $?))
|
|
|
|
MIQ_PRINTCOUNT= $(shell printf "%3d/%d" $(MIQ_INDEX) $(MIQ_COUNT))$(MIQ_INCRIDX)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Printing out various kinds of statements
|
2017-11-08 19:02:39 +08:00
|
|
|
ifndef V
|
2017-03-25 06:57:50 +08:00
|
|
|
PRINT_COMMAND= @
|
2018-04-05 23:25:12 +08:00
|
|
|
PRINT_COMPILE= $(PRINT_COMMAND) $(INFO) "[COMPILE$(MIQ_PRINTCOUNT)] " $<;
|
2020-09-02 06:53:45 +08:00
|
|
|
PRINT_LINK= $(PRINT_COMMAND) $(INFO) "[LINK]" $(shell basename $@);
|
2017-05-02 17:08:14 +08:00
|
|
|
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);
|
2018-09-20 00:09:25 +08:00
|
|
|
PRINT_UNINSTALL=$(PRINT_COMMAND) $(INFO) "[UNINSTALL] " $(*F) $(COLORIZE);
|
2018-04-05 23:25:12 +08:00
|
|
|
PRINT_CLEAN= $(PRINT_COMMAND) $(INFO) "[CLEAN] " $@ $(MIQ_PRETTYDIR) $(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] " $< ;
|
2017-06-15 21:36:59 +08:00
|
|
|
PRINT_TEST= $(PRINT_COMMAND) $(INFO) "[TEST]" $(@:.test=) ;
|
2018-06-01 21:43:36 +08:00
|
|
|
PRINT_CONFIG= $(PRINT_COMMAND) $(INFO_NONL) "[CONFIG]" "$(MIQ_ORIGTARGET)" ;
|
2017-11-07 22:19:52 +08:00
|
|
|
PRINT_PKGCONFIG=$(PRINT_COMMAND) $(INFO) "[PKGCONFIG]" "$*" ;
|
|
|
|
PRINT_LIBCONFIG=$(PRINT_COMMAND) $(INFO) "[LIBCONFIG]" "lib$*" ;
|
2018-02-15 17:51:15 +08:00
|
|
|
PRINT_REFORMAT= $(PRINT_COMMAND) $(INFO) "[REFORMAT]" "$*" $(COLORIZE);
|
2017-11-08 19:02:39 +08:00
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Special for Fabien: make 'Directory'
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ifneq ($(filter $(MAKECMDGOALS:/=),$(SUBDIRS)),)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MAKECMDGOALS): .ALWAYS
|
2017-05-01 23:20:29 +08:00
|
|
|
$(PRINT_COMMAND) cd $@ && make
|
2017-03-25 06:57:50 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
|
2017-11-28 01:46:13 +08:00
|
|
|
ifdef RECURSE
|
2017-03-25 06:57:50 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Dependencies generation
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_DEPENDENCIES=$(MIQ_SOURCES:%=$(MIQ_OBJDIR)%$(EXT.obj).d)
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_OBJDIR_DEPS=$(MIQ_OBJDIR)%.deps/.mkdir
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-05-08 16:47:48 +08:00
|
|
|
MIQ_OBJDEPS=$(MIQ_OBJDIR_DEPS) $(MIQ_MAKEDEPS) $(MIQ_ORDERONLY:%=% .prebuild)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Check if the compiler supports dependency flags (if not, do it the hard way)
|
2018-04-11 00:56:25 +08:00
|
|
|
ifndef CFLAGS_DEPENDENCIES
|
2018-11-20 01:59:32 +08:00
|
|
|
|
|
|
|
# The following is a trick to avoid errors if a header file appears in a
|
|
|
|
# generated dependency but no longer in the source code.
|
|
|
|
# The trick is quite ugly, but fortunately documented here:
|
|
|
|
# http://scottmcpeak.com/autodepend/autodepend.html
|
|
|
|
POSTPROCESS_DEPENDENCY?= \
|
|
|
|
( sed -e 's/.*://' -e 's/\\$$//' < $@ | \
|
|
|
|
fmt -1 | \
|
|
|
|
sed -e 's/^ *//' -e 's/$$/:/' >> $@ )
|
|
|
|
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.c$(EXT.obj).d: %.c $(MIQ_OBJDEPS)
|
2018-11-20 01:59:32 +08:00
|
|
|
$(PRINT_DEPEND) ( $(CC_DEPEND) && $(POSTPROCESS_DEPENDENCY) )
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.cpp$(EXT.obj).d: %.cpp $(MIQ_OBJDEPS)
|
2018-11-20 01:59:32 +08:00
|
|
|
$(PRINT_DEPEND) ( $(CXX_DEPEND) && $(POSTPROCESS_DEPENDENCY) )
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.cc$(EXT.obj).d: %.cc $(MIQ_OBJDEPS)
|
2018-11-20 01:59:32 +08:00
|
|
|
$(PRINT_DEPEND) ( $(CXX_DEPEND) && $(POSTPROCESS_DEPENDENCY) )
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.s$(EXT.obj).d: %.s $(MIQ_OBJDEPS)
|
2018-11-20 01:59:32 +08:00
|
|
|
$(PRINT_DEPEND) ( $(AS_DEPEND) && $(POSTPROCESS_DEPENDENCY) )
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.asm$(EXT.obj).d: %.asm $(MIQ_OBJDEPS)
|
2018-11-20 01:59:32 +08:00
|
|
|
$(PRINT_DEPEND) ( $(AS_DEPEND) && $(POSTPROCESS_DEPENDENCY) )
|
|
|
|
|
2017-05-01 23:06:28 +08:00
|
|
|
else
|
2018-11-20 01:59:32 +08:00
|
|
|
|
|
|
|
# Compiler has decent support for dependency generation
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%$(EXT.obj).d: $(MIQ_OBJDIR)%$(EXT.obj)
|
2018-11-20 01:59:32 +08:00
|
|
|
|
2017-05-01 23:06:28 +08:00
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
2018-04-05 23:25:12 +08:00
|
|
|
# Build inference rules
|
2017-03-25 06:57:50 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Compilation
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.c$(EXT.obj): %.c $(MIQ_OBJDEPS)
|
2020-09-02 06:44:09 +08:00
|
|
|
$(PRINT_COMPILE) $(COMPILE.c)
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.cpp$(EXT.obj): %.cpp $(MIQ_OBJDEPS)
|
2020-09-02 06:44:09 +08:00
|
|
|
$(PRINT_COMPILE) $(COMPILE.cpp)
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.cc$(EXT.obj): %.cc $(MIQ_OBJDEPS)
|
2020-09-02 06:44:09 +08:00
|
|
|
$(PRINT_COMPILE) $(COMPILE.cc)
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.s$(EXT.obj): %.s $(MIQ_OBJDEPS)
|
2020-09-02 06:44:09 +08:00
|
|
|
$(PRINT_COMPILE) $(COMPILE.s)
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.asm$(EXT.obj): %.asm $(MIQ_OBJDEPS)
|
2020-09-02 06:44:09 +08:00
|
|
|
$(PRINT_COMPILE) $(COMPILE.asm)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Skip headers
|
2020-09-02 04:04:53 +08:00
|
|
|
$(MIQ_OBJDIR)%.h$(EXT.obj):
|
|
|
|
$(MIQ_OBJDIR)%.hpp$(EXT.obj):
|
|
|
|
$(MIQ_OBJDIR)%.hh$(EXT.obj):
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Include dependencies from current directory
|
|
|
|
# We only build when the target is set to avoid dependencies on 'clean'
|
2018-04-05 23:25:12 +08:00
|
|
|
ifeq ($(MAKECMDGOALS),.build)
|
|
|
|
-include $(MIQ_DEPENDENCIES)
|
2017-03-25 06:57:50 +08:00
|
|
|
endif
|
|
|
|
|
2018-05-17 20:17:20 +08:00
|
|
|
# Create output directory if necessary
|
2019-04-02 04:58:47 +08:00
|
|
|
$(MIQ_OUTPRODS): | $(OUTPUT).mkdir-only
|
2018-05-17 20:17:20 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Link
|
|
|
|
.SECONDEXPANSION:
|
|
|
|
MIQ_NOSRC= $(@:$(OUTPUT)%=%)
|
2020-09-02 04:04:53 +08:00
|
|
|
MIQ_NOEXE= $(MIQ_NOSRC:$(PFX.exe)%$(EXT.exe)=%)
|
|
|
|
MIQ_NOLIB= $(MIQ_NOEXE:$(PFX.lib)%$(EXT.lib)=%)
|
|
|
|
MIQ_NODLL= $(MIQ_NOLIB:$(PFX.dll)%$(EXT.dll)=%)
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_OUT_SOURCES=$(SOURCES_$(MIQ_NODLL))
|
|
|
|
$(MIQ_OUTLIB): $(MIQ_TOLINK) $$(MIQ_TOLINK) $(MIQ_MAKEDEPS)
|
2020-09-02 06:53:45 +08:00
|
|
|
$(PRINT_LINK) $(LINK.lib)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OUTDLL): $(MIQ_TOLINK) $$(MIQ_TOLINK) $(MIQ_MAKEDEPS)
|
2020-09-02 06:53:45 +08:00
|
|
|
$(PRINT_LINK) $(LINK.dll)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OUTEXE): $(MIQ_TOLINK) $$(MIQ_TOLINK) $(MIQ_MAKEDEPS)
|
2020-09-02 06:53:45 +08:00
|
|
|
$(PRINT_LINK) $(LINK.exe)
|
2018-04-05 23:25:12 +08:00
|
|
|
|
2017-11-24 17:43:30 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Package configuration
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Package configuration file
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_PKGCFLAGS= $(PKGCONFIGS:%=$(MIQ_OBJDIR)%.pkg-config.cflags)
|
|
|
|
MIQ_PKGLDFLAGS= $(PKGCONFIGS:%=$(MIQ_OBJDIR)%.pkg-config.ldflags)
|
2018-04-11 04:15:28 +08:00
|
|
|
MIQ_PKGCONFIGS= $(PKGCONFIGS:%?=%)
|
|
|
|
MIQ_PKGCFG= $(MIQ_PKGONFIGS:%=$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%.h)
|
|
|
|
MIQ_PKGLIBS= $(patsubst %,$(MIQ_OBJDIR)%.cfg.ldflags,$(filter lib%,$(CONFIG)))
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_PKGDEPS= $(MIQ_MAKEDEPS) $(MIQ_OBJDIR).mkdir
|
2017-11-24 22:44:04 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Build the package config from cflags, ldflags and libs config
|
|
|
|
$(MIQ_OBJDIR)pkg-config.mk: $(MIQ_PKGCFLAGS) $(MIQ_PKGLDFLAGS) $(MIQ_PKGLIBS)
|
2018-06-01 21:43:36 +08:00
|
|
|
$(PRINT_COMMAND) $(MIQ_PKGCONFIG_BUILDMK)
|
2017-11-24 22:44:04 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Include rules for makefiles
|
|
|
|
-include $(PKGCONFIGS:%=$(MIQ_OBJDIR)pkg-config.mk)
|
|
|
|
-include $(MIQ_PKGLIBS:%=$(MIQ_OBJDIR)pkg-config.mk)
|
2017-11-24 17:43:30 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Optional packages end with ?, e.g. PKGCONFIG=openssl?
|
|
|
|
$(MIQ_OBJDIR)%?.pkg-config.cflags: $(MIQ_PKGDEPS)
|
2018-06-01 21:43:36 +08:00
|
|
|
$(PRINT_PKGCONFIG) $(MIQ_PKGCONFIG_CFLAGS_OPTIONAL)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)%?.pkg-config.ldflags: $(MIQ_PKGDEPS)
|
2018-06-01 21:43:36 +08:00
|
|
|
$(PRINT_COMMAND) $(MIQ_PKGCONFIG_LIBS_OPTIONAL)
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Non-optional packages
|
|
|
|
$(MIQ_OBJDIR)%.pkg-config.cflags: $(MIQ_PKGDEPS)
|
2018-06-01 21:43:36 +08:00
|
|
|
$(PRINT_PKGCONFIG) $(MIQ_PKGCONFIG_CFLAGS_CHECK)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)%.pkg-config.ldflags: $(MIQ_PKGDEPS)
|
2018-06-01 21:43:36 +08:00
|
|
|
$(PRINT_COMMAND) $(MIQ_PKGCONFIG_LIBS_CHECK)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)lib%.cfg.ldflags: $(MIQ_OBJDIR)CFG_HAVE_lib%.h $(MIQ_PKGDEPS)
|
2017-11-24 22:44:04 +08:00
|
|
|
$(PRINT_COMMAND) (grep -q 'define ' $< && echo $(LINK_CFG_OPT)$* || true) > $@
|
2017-11-24 17:43:30 +08:00
|
|
|
|
|
|
|
|
2017-05-02 17:08:14 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Configuration rules
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Normalize header configuration name (turn <foo.h> into .lt.foo.h.gt. and back)
|
2018-04-11 04:15:28 +08:00
|
|
|
MIQ_NORMCONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG) $(PKGCONFIGS:%=PACKAGE_%))))
|
2018-04-05 23:25:12 +08:00
|
|
|
MIQ_ORIGTARGET=$(subst .lt.,<,$(subst .gt.,>,$(subst .sl.,/,$*)))
|
|
|
|
MIQ_CONFIGDEPS= $(MIQ_PKGDEPS) \
|
|
|
|
$(PKGCONFIGS:%=$(MIQ_OBJDIR)pkg-config.mk) \
|
2018-05-08 16:49:22 +08:00
|
|
|
$(MIQ_PKGLIBS:%=$(MIQ_OBJDIR)pkg-config.mk) \
|
|
|
|
$(MIQ_ORDERONLY:%=% .hello)
|
2017-06-16 16:34:22 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Generate the config.h by concatenating all the indiviual config files
|
|
|
|
config.h: $(MIQ_NORMCONFIG:%=$(MIQ_OBJDIR)CFG_HAVE_%.h)
|
2017-06-16 16:34:22 +08:00
|
|
|
$(PRINT_GENERATE) cat $^ > $@
|
2017-05-02 17:46:14 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Build makefile configuration files from generated .h files
|
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_%.mk: $(MIQ_OBJDIR)CFG_HAVE_%.h $(MIQ_MAKEDEPS)
|
2018-04-11 04:15:28 +08:00
|
|
|
$(PRINT_COMMAND) $(MIQ_MK_CFG)
|
2018-04-05 23:25:12 +08:00
|
|
|
-include $(MIQ_NORMCONFIG:%=$(MIQ_OBJDIR)CFG_HAVE_%.mk)
|
2017-11-21 01:49:41 +08:00
|
|
|
|
2017-05-02 17:46:14 +08:00
|
|
|
# C standard headers, e.g. HAVE_<stdio.h>
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_.lt.%.h.gt..h: $(MIQ_OBJDIR)CFGCH%.c $(MIQ_CONFIGDEPS)
|
2018-04-11 04:15:28 +08:00
|
|
|
$(PRINT_CONFIG) $(MIQ_CC_CFG)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFGCH%.c: $(MIQ_OBJDIR).mkdir $(MIQ_CONFIGDEPS)
|
|
|
|
$(PRINT_COMMAND) (echo '#include' "<$(MIQ_ORIGTARGET).h>" && echo 'int main() { return 0; }') > "$@"
|
|
|
|
.PRECIOUS: $(MIQ_OBJDIR)CFGCH%.c
|
2017-05-02 17:46:14 +08:00
|
|
|
|
|
|
|
# C++ Standard headers, e.g. HAVE_<iostream>
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_.lt.%.gt..h: $(MIQ_OBJDIR)CFGCPPH%.cpp $(MIQ_CONFIGDEPS)
|
2018-04-11 04:15:28 +08:00
|
|
|
$(PRINT_CONFIG) $(MIQ_CXX_CFG)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFGCPPH%.cpp: $(MIQ_OBJDIR).mkdir $(MIQ_CONFIGDEPS)
|
|
|
|
$(PRINT_COMMAND) (echo '#include' "<$(MIQ_ORIGTARGET)>" && echo 'int main() { return 0; }') > "$@"
|
|
|
|
.PRECIOUS: $(MIQ_OBJDIR)CFGCPPH%.cpp
|
2017-05-02 21:27:41 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Library, e.g. libm
|
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_lib%.h: $(MIQ_OBJDIR)CFGLIB%.c $(MIQ_PKGDEPS)
|
2018-04-11 04:15:28 +08:00
|
|
|
$(PRINT_CONFIG) $(MIQ_LIB_CFG)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFGLIB%.c: $(MIQ_PKGDEPS)
|
2017-11-21 17:45:50 +08:00
|
|
|
$(PRINT_COMMAND) echo 'int main() { return 0; }' > "$@"
|
2018-04-05 23:25:12 +08:00
|
|
|
.PRECIOUS: $(MIQ_OBJDIR)CFGLIB%.c
|
2017-05-02 22:03:17 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
# Check if a function is present (code to test in config/check_foo.c)
|
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_%.h: $(MIQ_OBJDIR)CFGFN%.c $(MIQ_CONFIGDEPS)
|
2018-04-11 04:15:28 +08:00
|
|
|
$(PRINT_CONFIG) $(MIQ_FN_CFG)
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFGFN%.c: $(CONFIG_SOURCES)check_%.c $(MIQ_CONFIGDEPS)
|
2017-11-21 18:58:56 +08:00
|
|
|
$(PRINT_COMMAND) cp $< $@
|
2018-05-17 21:50:41 +08:00
|
|
|
$(MIQ_OBJDIR)CFGFN%.c: $(MIQ)config/check_%.c $(MIQ_CONFIGDEPS)
|
|
|
|
$(PRINT_COMMAND) cp $< $@
|
2018-04-05 23:25:12 +08:00
|
|
|
$(MIQ_OBJDIR)CFGFN%.c: config/check_%.c $(MIQ_CONFIGDEPS)
|
2017-11-22 00:24:18 +08:00
|
|
|
$(PRINT_COMMAND) cp $< $@
|
2018-04-05 23:25:12 +08:00
|
|
|
.PRECIOUS: $(MIQ_OBJDIR)CFGFN%.c
|
2017-05-02 21:27:41 +08:00
|
|
|
|
2018-04-11 04:15:28 +08:00
|
|
|
# Packages
|
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%?.h: $(MIQ_CONFIGDEPS)
|
|
|
|
$(PRINT_CONFIG) $(MIQ_PK_CFG)
|
|
|
|
$(MIQ_OBJDIR)CFG_HAVE_PACKAGE_%.h: $(MIQ_CONFIGDEPS)
|
|
|
|
$(PRINT_CONFIG) $(MIQ_PK_CFG)
|
2018-05-08 16:49:22 +08:00
|
|
|
|
2017-11-28 01:46:13 +08:00
|
|
|
endif
|
2017-05-02 17:08:14 +08:00
|
|
|
|
2018-02-15 17:51:15 +08:00
|
|
|
|
2019-03-11 15:21:52 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Documentation generation
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Man pages
|
|
|
|
man/%.gz: man/%
|
|
|
|
$(PRINT_GENERATE) gzip -9 < $< > $@
|
|
|
|
man/%.[1-9]: man/%.pod
|
|
|
|
$(PRINT_GENERATE) pod2man $< $@
|
|
|
|
|
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Test targets
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Run the test (in the object directory)
|
2018-04-10 23:43:29 +08:00
|
|
|
product.test: .product
|
2018-04-05 23:25:12 +08:00
|
|
|
$(PRINT_TEST) $(TEST_ENV) $(TEST_CMD) $(MIQ_OUTEXE) $(TEST_ARGS)
|
|
|
|
|
|
|
|
# Run a test from a C or C++ file to link against current library
|
2018-04-10 23:43:29 +08:00
|
|
|
%.c.test %.cpp.test: $(MIQ_OUTPRODS)
|
|
|
|
$(PRINT_TEST) $(MIQ_BUILDTEST) && $(MIQ_RUNTEST)
|
2018-04-05 23:25:12 +08:00
|
|
|
%/.test:
|
2018-05-17 20:30:19 +08:00
|
|
|
+$(PRINT_TEST) cd $* && $(MIQ_RECURSE) RUN_TESTS=yes .build
|
2018-04-05 23:25:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Benchmark targets
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Benchmarking (always done with profile target)
|
|
|
|
benchmark: $(BENCHMARKS:%=%.benchmark)
|
|
|
|
%.benchmark:
|
|
|
|
$(PRINT_COMMAND) $(MAKE) TEST_ENV=$(BENCHMARK_TEST_ENV) $*.test
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Install targets
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Installing the product: always need to build it first
|
2019-03-15 01:44:53 +08:00
|
|
|
%.install: $(PACKAGE_INSTALL).mkdir-only %
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_INSTALL) $(INSTALL.data) $* $(PACKAGE_INSTALL)
|
|
|
|
%.install_exe: $(PACKAGE_INSTALL.bin).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.bin) $* $(PACKAGE_INSTALL.bin)
|
|
|
|
%.install_lib: $(PACKAGE_INSTALL.lib).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.lib) $* $(PACKAGE_INSTALL.lib)
|
|
|
|
%.install_dll: $(PACKAGE_INSTALL.dll).mkdir-only %
|
2020-12-19 03:02:58 +08:00
|
|
|
$(PRINT_INSTALL) $(INSTALL.dll)
|
2020-12-19 03:51:12 +08:00
|
|
|
%.install_hdr: $(PACKAGE_INSTALL.h).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.h) $* $(PACKAGE_INSTALL.h)
|
|
|
|
%.install_shr: $(PACKAGE_INSTALL.share).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.share) $* $(PACKAGE_INSTALL.share)
|
|
|
|
%.install_man: $(PACKAGE_INSTALL.man).mkdir-only %
|
2019-03-11 15:21:52 +08:00
|
|
|
$(PRINT_COMMAND) $(MKDIR) -p $(MIQ_MANDIR)
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_INSTALL) $(INSTALL.man) $* $(MIQ_MANDIR)
|
|
|
|
%.install_doc: $(PACKAGE_INSTALL.doc).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.doc) $* $(PACKAGE_INSTALL.doc)
|
|
|
|
%.install_etc: $(PACKAGE_INSTALL.sysconfig).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.etc) $* $(PACKAGE_INSTALL.sysconfig)
|
|
|
|
%.install_pc: $(PACKAGE_INSTALL.pkgconfig).mkdir-only %
|
|
|
|
$(PRINT_INSTALL) $(INSTALL.data) $* $(PACKAGE_INSTALL.pkgconfig)
|
2018-04-06 05:47:28 +08:00
|
|
|
|
2018-09-20 00:09:25 +08:00
|
|
|
# Uninstalling the product
|
|
|
|
%.uninstall:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_exe:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.bin)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.bin) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_lib:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.lib)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.lib) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_dll:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.dll)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.dll) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_hdr:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.h)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.h) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_shr:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.share)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.share) $(UNINSTALL.ok)
|
2019-03-15 19:10:44 +08:00
|
|
|
%.uninstall_doc:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.doc)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.doc) $(UNINSTALL.ok)
|
2019-03-11 15:21:52 +08:00
|
|
|
%.uninstall_man:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.man)%)
|
2019-03-11 15:21:52 +08:00
|
|
|
%.uninstall_etc:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.sysconfig)%)
|
2018-09-20 00:09:25 +08:00
|
|
|
%.uninstall_pc:
|
2020-12-19 03:51:12 +08:00
|
|
|
$(PRINT_UNINSTALL) $(UNINSTALL) $(*F:%=$(PACKAGE_INSTALL.pkgconfig)%) ; $(UNINSTALL.dir) $(PACKAGE_INSTALL.pkgconfig) $(UNINSTALL.ok)
|
2018-09-20 00:09:25 +08:00
|
|
|
|
2018-04-06 05:47:28 +08:00
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Generation of pkg-config data file
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-06-20 00:38:00 +08:00
|
|
|
MIQ_PACKAGELIBS=$(MIQ_PACKAGELDPATH) \
|
|
|
|
$(PACKAGE_LIBS:%.lib=$(LINK_LIB_OPT)%) \
|
2018-04-06 05:47:28 +08:00
|
|
|
$(PACKAGE_DLLS:%.dll=$(LINK_DLL_OPT)%)
|
2018-06-20 00:38:00 +08:00
|
|
|
MIQ_PACKAGELDPATH=$(firstword \
|
|
|
|
$(PACKAGE_LIBS:%=-L$${libdir}) \
|
|
|
|
$(PACKAGE_DLLS:%=-L$${libdir}))
|
|
|
|
|
2018-04-06 05:47:28 +08:00
|
|
|
MIQ_GENPC= \
|
2020-12-19 03:51:12 +08:00
|
|
|
(echo 'prefix=$(PREFIX.bin)' ;\
|
2018-04-06 05:47:28 +08:00
|
|
|
echo 'exec_prefix=$${prefix}' ;\
|
2020-12-19 03:51:12 +08:00
|
|
|
echo 'libdir=$(PREFIX.lib)' ;\
|
|
|
|
echo 'includedir=$(PREFIX.h)' ;\
|
2018-04-06 05:47:28 +08:00
|
|
|
echo 'Name: $(PACKAGE_NAME)' ;\
|
|
|
|
echo 'Description: $(PACKAGE_DESCRIPTION)' ;\
|
|
|
|
echo 'Version: $(PACKAGE_VERSION)' ;\
|
|
|
|
echo 'URL: $(PACKAGE_URL)' ;\
|
|
|
|
echo 'Requires: $(PACKAGE_REQUIRES)' ;\
|
|
|
|
echo 'Conflicts: $(PACKAGE_CONFLICTS)' ;\
|
2018-06-20 00:38:00 +08:00
|
|
|
echo 'Libs: $(MIQ_PACKAGELIBS)' ;\
|
2018-04-06 05:47:28 +08:00
|
|
|
echo 'Cflags: -I$${includedir}' )
|
|
|
|
|
|
|
|
$(MIQ_PACKAGE): $(MIQ_MAKEDEPS)
|
2020-09-02 06:53:45 +08:00
|
|
|
$(PRINT_GENERATE) $(MIQ_GENPC) > $@
|
2018-04-06 05:47:28 +08:00
|
|
|
|
2018-04-05 23:25:12 +08:00
|
|
|
|
2018-02-15 17:51:15 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Clang format
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2018-02-15 18:11:10 +08:00
|
|
|
reformat clang-format: $(CLANG_FORMAT_SOURCES:%=%.clang-format)
|
2018-02-15 17:51:15 +08:00
|
|
|
%.clang-format:
|
|
|
|
$(PRINT_REFORMAT) clang-format $* > $*.tmp && mv $*.tmp $*
|
|
|
|
|
|
|
|
|
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
|