2017-03-25 06:57:50 +08:00
|
|
|
#******************************************************************************
|
2017-06-15 21:36:59 +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%)
|
2017-06-19 16:41:25 +08:00
|
|
|
CFLAGS+= $(CPPFLAGS) $(CFLAGS_STD) $(CFLAGS_$(BUILDENV)) $(CFLAGS_$(TARGET)) $(CFLAGS_EXTRA)
|
|
|
|
CXXFLAGS+= $(CPPFLAGS) $(CXXFLAGS_STD) $(CXXFLAGS_$(BUILDENV)) $(CXXFLAGS_$(TARGET)) $(CFLAGS_EXTRA) $(CXXFLAGS_EXTRA)
|
|
|
|
LDFLAGS+= $(CFLAGS_STD) $(CXXFLAGS_STD) $(LDFLAGS_$(BUILDENV)) $(LDFLAGS_$(TARGET)) $(CFLAGS_EXTRA) $(LDFLAGS_EXTRA)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
# Get BUILDOBJ from the BUILD_OBJECTS environment variable if set
|
|
|
|
BUILDOBJ= $(BUILD_OBJECTS)
|
|
|
|
|
|
|
|
ifndef DIR
|
|
|
|
# The cd ./ in FULLDIR is for a corner case where . is a symbolic link
|
|
|
|
# At least with bash (not sure with other shells), pwd returns me
|
|
|
|
# the symbolic link path (as for BASEDIR), rather than the physical path
|
|
|
|
|
|
|
|
# So this is necessary for the substitution to happen correctly. Ugh!
|
|
|
|
BASEDIR:= $(shell cd ./$(BUILD)/..; pwd)
|
2017-04-02 01:11:06 +08:00
|
|
|
FULLDIR:= $(shell cd ./; pwd)
|
2017-03-25 06:57:50 +08:00
|
|
|
DIR:= $(subst $(BASEDIR),,$(FULLDIR))
|
|
|
|
PRETTY_DIR:= $(subst $(BASEDIR),[top],$(FULLDIR))
|
|
|
|
BASENAME_DIR:= $(shell basename $(FULLDIR))
|
|
|
|
BUILD_DATE:= $(shell /bin/date '+%Y%m%d-%H%M%S')
|
2017-06-19 18:59:10 +08:00
|
|
|
OBJROOT:= $(BUILDOBJ)/$(BUILDENV)/$(CROSS_COMPILE:%=%-)$(TARGET)$(BASE_EXTRA_DEPTH)
|
|
|
|
BUILD_LOG:= $(BUILD_LOGS)build-$(BUILDENV)-$(CROSS_COMPILE:%=%-)$(TARGET)-$(BUILD_DATE).log
|
2017-03-25 06:57:50 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
# Configuration variables
|
2017-04-02 01:11:06 +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-08 23:10:51 +08:00
|
|
|
OBJROOT_EXE:= $(PRODUCTS_EXE:%=$(OBJROOT)/$(EXE_PFX)%)
|
|
|
|
OBJROOT_LIB:= $(PRODUCTS_LIB:%=$(OBJROOT)/$(LIB_PFX)%)
|
|
|
|
OBJROOT_DLL:= $(PRODUCTS_DLL:%=$(OBJROOT)/$(DLL_PFX)%)
|
2017-04-02 01:11:06 +08:00
|
|
|
OBJROOT_OTHER:= $(PRODUCTS_OTHER:%=$(OBJROOT)/%)
|
|
|
|
OBJPRODUCTS:= $(OBJROOT_EXE) $(OBJROOT_LIB) $(OBJROOT_DLL) $(OBJROOT_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),)
|
2017-04-02 01:11:06 +08:00
|
|
|
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
|
2017-04-02 01:11:06 +08:00
|
|
|
|
2017-11-08 18:43:35 +08:00
|
|
|
LIBNAMES:= $(filter %.lib, $(notdir $(LIBRARIES)))
|
|
|
|
DLLNAMES:= $(filter %.dll, $(notdir $(LIBRARIES)))
|
2017-11-08 23:10:51 +08:00
|
|
|
OBJLIBS:= $(LIBNAMES:%.lib=$(OBJROOT)/$(LIB_PFX)%$(LIB_EXT))
|
|
|
|
OBJDLLS:= $(DLLNAMES:%.dll=$(OBJROOT)/$(DLL_PFX)%$(DLL_EXT))
|
|
|
|
LINK_PATHS:= $(OBJROOT:%=$(LINK_DIR_OPT)%)
|
|
|
|
LINK_LIBS:= $(LINK_LIBS) \
|
|
|
|
$(LIBNAMES:%.lib=$(LINK_LIB_OPT)%) \
|
|
|
|
$(DLLNAMES:%.dll=$(LINK_DLL_OPT)%)
|
|
|
|
LINK_INPUTS:= $(OBJECTS) $(OBJLIBS) $(OBJDLLS)
|
|
|
|
LINK_CMDLINE:= $(OBJECTS) $(LINK_PATHS) $(LINK_LIBS)
|
2017-03-25 06:57:50 +08:00
|
|
|
ifneq ($(words $(LINK_INPUTS)),0)
|
2017-04-02 01:11:06 +08:00
|
|
|
LINK_WINPUTS= $(patsubst %,"%", $(shell cygpath -aw $(LINK_INPUTS)))
|
2017-03-25 06:57:50 +08:00
|
|
|
endif
|
2017-04-02 01:11:06 +08:00
|
|
|
PRINT_DIR= --no-print-directory
|
2017-03-25 06:57:50 +08:00
|
|
|
RECURSE_BUILDENV=$(BUILDENV)
|
2017-04-02 01:11:06 +08:00
|
|
|
RECURSE_CMD= $(MAKE) $(PRINT_DIR) TARGET=$(TARGET) BUILDENV=$(RECURSE_BUILDENV) $(RECURSE) COLORIZE=
|
2017-11-07 00:15:26 +08:00
|
|
|
MAKEFILE_DEPS:= $(MAKEFILE_LIST)
|
2017-04-02 01:11:06 +08:00
|
|
|
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")
|
2017-03-25 06:57:50 +08:00
|
|
|
PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OBJROOT_EXE))_prof_$(GIT_REVISION).vsp
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# User targets
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
all: $(TARGET)
|
|
|
|
|
|
|
|
debug opt release profile: logs.mkdir
|
2017-04-02 01:11:06 +08:00
|
|
|
$(PRINT_COMMAND) $(TIME) $(MAKE) TARGET=$@ RECURSE=build LOG_COMMANDS= build $(LOG_COMMANDS)
|
|
|
|
|
|
|
|
# Testing
|
2017-04-02 06:47:48 +08:00
|
|
|
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
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# Clean builds
|
2017-03-25 06:57:50 +08:00
|
|
|
startup restart rebuild: clean all
|
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# Installation
|
2017-11-09 01:03:54 +08:00
|
|
|
install: all
|
|
|
|
$(PRINT_COMMAND) $(MAKE) RECURSE=install install-internal recurse LOG_COMMANDS= TIME= $(LOG_COMMANDS)
|
|
|
|
install-internal: \
|
2017-03-25 06:57:50 +08:00
|
|
|
$(OBJROOT_EXE:%=%.install_exe) \
|
|
|
|
$(OBJROOT_LIB:%=%.install_lib) \
|
|
|
|
$(OBJROOT_DLL:%=%.install_dll) \
|
|
|
|
$(EXE_INSTALL:%=%.install_exe) \
|
|
|
|
$(LIB_INSTALL:%=%.install_lib) \
|
2017-11-09 00:32:08 +08:00
|
|
|
$(DLL_INSTALL:%=%.install_dll) \
|
|
|
|
$(OBJLIBS:%=%.install_lib) \
|
|
|
|
$(OBJDLLS:%=%.install_dll)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
clean: hello.clean
|
2017-05-02 17:48:04 +08:00
|
|
|
-$(PRINT_COMMAND) rm -f $(GARBAGE) $(TOCLEAN) $(OBJECTS) $(DEPENDENCIES) $(OBJPRODUCTS) config.h
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
distclean: nuke clean
|
|
|
|
nuke:
|
|
|
|
-$(PRINT_COMMAND) rm -rf $(BUILDOBJ) $(BUILD_LOGS)build-*.log
|
|
|
|
|
|
|
|
|
|
|
|
help:
|
|
|
|
@$(ECHO) "Available targets:"
|
|
|
|
@$(ECHO) " make : Build default target (TARGET=$(TARGET))"
|
|
|
|
@$(ECHO) " make all : Same"
|
|
|
|
@$(ECHO) " make debug : Force debug build"
|
|
|
|
@$(ECHO) " make opt : Force optimized build"
|
|
|
|
@$(ECHO) " make release : Force release build"
|
|
|
|
@$(ECHO) " make profile : Force profile build"
|
|
|
|
@$(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
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2017-05-02 17:08:14 +08:00
|
|
|
build: hello config libraries recurse prebuild objects product postbuild goodbye
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-11-08 19:02:39 +08:00
|
|
|
ifndef V
|
2017-03-25 06:57:50 +08:00
|
|
|
hello:
|
|
|
|
@$(INFO) "[BEGIN]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
|
|
|
goodbye:
|
|
|
|
@$(INFO) "[END]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
|
|
|
|
|
|
|
hello.install:
|
|
|
|
@$(INFO) "[INSTALL]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
2017-11-08 19:02:39 +08:00
|
|
|
hello.clean:
|
2017-03-25 06:57:50 +08:00
|
|
|
@$(INFO) "[CLEAN]" $(TARGET) $(BUILDENV) in $(PRETTY_DIR)
|
2017-11-08 19:02:39 +08:00
|
|
|
else
|
|
|
|
hello:
|
|
|
|
goodbye:
|
|
|
|
hello.install:
|
|
|
|
hello.clean:
|
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-11-08 18:43:35 +08:00
|
|
|
libraries: $(OBJLIBS) $(OBJDLLS)
|
2017-03-25 06:57:50 +08:00
|
|
|
product:$(OBJPRODUCTS)
|
|
|
|
objects:$(OBJDIR:%=%/.mkdir) $(OBJECTS)
|
|
|
|
|
|
|
|
# "Hooks" for pre and post build steps
|
2017-05-02 17:18:03 +08:00
|
|
|
config: $(CONFIG:%=config.h)
|
2017-03-25 06:57:50 +08:00
|
|
|
prebuild:
|
|
|
|
postbuild:
|
|
|
|
|
|
|
|
# Run the test (in the object directory)
|
2017-06-15 21:36:59 +08:00
|
|
|
product.test: product .ALWAYS
|
2017-11-08 23:10:51 +08:00
|
|
|
$(PRINT_TEST) $(TEST_ENV) $(OBJROOT_EXE) $(PRODUCTS_OPTS)
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-04-02 01:11:06 +08:00
|
|
|
# Run a test from a C or C++ file to link against current library
|
2017-06-15 21:36:59 +08:00
|
|
|
%.c.test: $(OBJROOT_LIB) .ALWAYS
|
2017-04-02 01:11:06 +08:00
|
|
|
$(PRINT_BUILD) $(MAKE) SOURCES=$*.c LINK_LIBS=$(OBJROOT_LIB) PRODUCTS=$*.exe $(TARGET)
|
2017-11-08 23:10:51 +08:00
|
|
|
$(PRINT_TEST) $(TEST_ENV) $(TEST_CMD_$*) $(OBJROOT)/$*$(EXE_EXT) $(TEST_ARGS_$*)
|
2017-06-15 21:36:59 +08:00
|
|
|
%.cpp.test: $(OBJROOT_LIB) .ALWAYS
|
2017-04-02 01:11:06 +08:00
|
|
|
$(PRINT_BUILD) $(MAKE) SOURCES=$*.cpp LINK_LIBS=$(OBJROOT_LIB) PRODUCTS=$*.exe $(TARGET)
|
2017-11-08 23:10:51 +08:00
|
|
|
$(PRINT_TEST) $(TEST_ENV) $(TEST_CMD_$*) $(OBJROOT)/$*$(EXE_EXT) $(TEST_ARGS_$*)
|
2017-04-01 23:10:27 +08:00
|
|
|
|
2017-03-25 06:57:50 +08:00
|
|
|
# Installing the product: always need to build it first
|
2017-11-09 00:56:49 +08:00
|
|
|
%.install_exe: $(PREFIX_BIN).mkdir build
|
|
|
|
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_BIN)
|
|
|
|
%.install_lib: $(PREFIX_LIB).mkdir build
|
|
|
|
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_LIB)
|
|
|
|
%.install_dll: $(PREFIX_DLL).mkdir build
|
|
|
|
$(PRINT_INSTALL) $(INSTALL) $* $(PREFIX_DLL)
|
|
|
|
$(PREFIX)%.mkdir:
|
|
|
|
$(PRINT_COMMAND) mkdir -p $(PREFIX)$*
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
# Benchmarking (always done with profile target)
|
|
|
|
benchmark: $(BENCHMARK:%=%.benchmark) $(BENCHMARKS:%=%.benchmark)
|
|
|
|
product.benchmark: product .ALWAYS
|
2017-06-15 21:36:59 +08:00
|
|
|
$(PRINT_TEST) gprof
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
.PHONY: hello hello.install hello.clean goodbye
|
|
|
|
.PHONY: build libraries product objects prebuild postbuild test
|
|
|
|
.PHONY: .ALWAYS
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Build target modifiers
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Make from the top-level directory (useful from child directories)
|
|
|
|
top-%:
|
|
|
|
cd ./$(BUILD); $(MAKE) $*
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
t-% time-%:
|
|
|
|
$(PRINT_COMMAND) time $(MAKE) $*
|
|
|
|
|
|
|
|
# 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)
|
2017-04-02 01:11:06 +08:00
|
|
|
|
|
|
|
# If LIBRARIES=foo/bar, go to directory foo/bar, which should build bar.a
|
2017-11-08 23:10:51 +08:00
|
|
|
$(OBJROOT)/$(LIB_PFX)%$(LIB_EXT): $(DEEP_BUILD)
|
2017-11-08 18:43:35 +08:00
|
|
|
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES:.lib=) $(SUBDIRS)) && $(RECURSE_CMD)
|
2017-11-08 23:10:51 +08:00
|
|
|
$(OBJROOT)/$(DLL_PFX)%$(DLL_EXT): $(DEEP_BUILD)
|
2017-11-08 18:43:35 +08:00
|
|
|
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES:.dll=) $(SUBDIRS)) && $(RECURSE_CMD)
|
2017-06-15 21:36:59 +08:00
|
|
|
%/.test:
|
2017-03-25 06:57:50 +08:00
|
|
|
+$(PRINT_TEST) cd $* && $(MAKE) TARGET=$(TARGET) test
|
|
|
|
deep_build:
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# 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
|
2017-11-08 19:02:39 +08:00
|
|
|
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 $@);
|
2017-05-02 17:08:14 +08:00
|
|
|
PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" "$(shell basename "$@")";
|
2017-03-25 06:57:50 +08:00
|
|
|
PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL] " $(*F) in $(<D);
|
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=) ;
|
2017-05-02 17:08:14 +08:00
|
|
|
PRINT_CONFIG= $(PRINT_COMMAND) $(INFO) "[CONFIG]" "$*" ;
|
2017-05-02 22:03:17 +08:00
|
|
|
PRINT_LIBCONFIG=$(PRINT_COMMAND) $(INFO) "[CONFIG]" "lib$*" ;
|
2017-11-08 19:02:39 +08:00
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
logs.mkdir: $(dir $(BUILD_LOG))/.mkdir $(dir $(BUILD_SAVED_LOG))/.mkdir
|
|
|
|
%/.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
|
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Dependencies generation
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
ifdef TARGET
|
|
|
|
|
|
|
|
DEPENDENCIES=$(SOURCES:%=$(OBJDIR)/%$(OBJ_EXT).d)
|
|
|
|
OBJDIR_DEPS=$(OBJDIR)/%.deps/.mkdir
|
|
|
|
|
2017-11-09 00:06:52 +08:00
|
|
|
ifeq (3.80,$(firstword $(sort $(MAKE_VERSION) 3.80)))
|
2017-03-25 06:57:50 +08:00
|
|
|
OBJ_DEPS=$(OBJDIR_DEPS) $(MAKEFILE_DEPS) | hello prebuild
|
2017-11-09 00:06:52 +08:00
|
|
|
else
|
|
|
|
OBJ_DEPS=$(OBJDIR_DEPS) $(MAKEFILE_DEPS) hello prebuild
|
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
2017-05-01 23:06:28 +08:00
|
|
|
ifndef DEPFLAGS
|
2017-03-25 06:57:50 +08:00
|
|
|
$(OBJDIR)/%.c$(OBJ_EXT).d: %.c $(OBJ_DEPS)
|
2017-05-01 23:06:28 +08:00
|
|
|
$(PRINT_DEPEND) ( $(CC_DEPEND)
|
2017-03-25 06:57:50 +08:00
|
|
|
$(OBJDIR)/%.cpp$(OBJ_EXT).d: %.cpp $(OBJ_DEPS)
|
2017-05-01 23:06:28 +08:00
|
|
|
$(PRINT_DEPEND) ( $(CXX_DEPEND)
|
2017-03-25 06:57:50 +08:00
|
|
|
$(OBJDIR)/%.s$(OBJ_EXT).d: %.s $(OBJ_DEPS)
|
2017-05-01 23:06:28 +08:00
|
|
|
$(PRINT_DEPEND) ( $(AS_DEPEND)
|
|
|
|
else
|
|
|
|
$(OBJDIR)/%$(OBJ_EXT).d: $(OBJDIR)/%$(OBJ_EXT)
|
|
|
|
endif
|
2017-03-25 06:57:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Inference rules
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
$(OBJDIR)/%.c$(OBJ_EXT): %.c $(OBJ_DEPS)
|
|
|
|
$(PRINT_COMPILE) $(MAKE_CC)
|
|
|
|
$(OBJDIR)/%.cpp$(OBJ_EXT): %.cpp $(OBJ_DEPS)
|
|
|
|
$(PRINT_COMPILE) $(MAKE_CXX)
|
|
|
|
$(OBJDIR)/%.s$(OBJ_EXT): %.s $(OBJ_DEPS)
|
|
|
|
$(PRINT_COMPILE) $(MAKE_AS)
|
|
|
|
|
|
|
|
$(OBJROOT_LIB): $(LINK_INPUTS) $(MAKEFILE_DEPS)
|
|
|
|
$(PRINT_BUILD) $(MAKE_LIB)
|
|
|
|
$(OBJROOT_DLL): $(LINK_INPUTS) $(MAKEFILE_DEPS)
|
|
|
|
$(PRINT_BUILD) $(MAKE_DLL)
|
|
|
|
$(OBJROOT_EXE): $(LINK_INPUTS) $(MAKEFILE_DEPS)
|
|
|
|
$(PRINT_BUILD) $(MAKE_EXE)
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
ifdef SUBDIRS
|
|
|
|
$(NOT_PARALLEL):
|
|
|
|
endif
|
|
|
|
|
|
|
|
# Include dependencies from current directory
|
|
|
|
# We only build when the target is set to avoid dependencies on 'clean'
|
|
|
|
ifeq ($(MAKECMDGOALS),build)
|
|
|
|
-include $(DEPENDENCIES)
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2017-05-02 17:08:14 +08:00
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
# Configuration rules
|
|
|
|
#------------------------------------------------------------------------------
|
|
|
|
|
2017-06-16 16:34:22 +08:00
|
|
|
NORM_CONFIG=$(subst <,.lt.,$(subst >,.gt.,$(subst /,.sl.,$(CONFIG))))
|
|
|
|
ORIG_TARGET=$(subst .lt.,<,$(subst .gt.,>,$(subst .sl.,/,$*)))
|
|
|
|
|
2017-06-17 15:36:07 +08:00
|
|
|
config.h: $(NORM_CONFIG:%=$(OBJDIR)/HAVE_%)
|
2017-06-16 16:34:22 +08:00
|
|
|
$(PRINT_GENERATE) cat $^ > $@
|
2017-05-02 17:46:14 +08:00
|
|
|
|
|
|
|
# C standard headers, e.g. HAVE_<stdio.h>
|
2017-06-16 16:34:22 +08:00
|
|
|
$(OBJDIR)/HAVE_.lt.%.h.gt.: $(OBJDIR)/CONFIG_HAVE_%.c
|
2017-05-02 21:27:41 +08:00
|
|
|
$(PRINT_CONFIG) $(CC_CONFIG)
|
2017-05-02 17:08:14 +08:00
|
|
|
$(OBJDIR)/CONFIG_HAVE_%.c: $(OBJDIR)/.mkdir
|
2017-06-16 16:34:22 +08:00
|
|
|
$(PRINT_GENERATE) echo '#include' "<$(ORIG_TARGET).h>" > "$@"; echo 'int main() { return 0; }' >> "$@"
|
2017-06-17 15:36:07 +08:00
|
|
|
.PRECIOUS: $(OBJDIR)/CONFIG_HAVE_%.c
|
2017-05-02 17:46:14 +08:00
|
|
|
|
|
|
|
# C++ Standard headers, e.g. HAVE_<iostream>
|
2017-06-16 16:34:22 +08:00
|
|
|
$(OBJDIR)/HAVE_.lt.%.gt.: $(OBJDIR)/CONFIG_HAVE_%.cpp
|
2017-05-02 21:27:41 +08:00
|
|
|
$(PRINT_CONFIG) $(CXX_CONFIG)
|
2017-05-02 17:08:14 +08:00
|
|
|
$(OBJDIR)/CONFIG_HAVE_%.cpp: $(OBJDIR)/.mkdir
|
2017-06-16 16:34:22 +08:00
|
|
|
$(PRINT_GENERATE) echo '#include' "<$(ORIG_TARGET)>" > "$@"; echo 'int main() { return 0; }' >> "$@"
|
2017-06-17 15:36:07 +08:00
|
|
|
.PRECIOUS: $(OBJDIR)/CONFIG_HAVE_%.cpp
|
2017-05-02 21:27:41 +08:00
|
|
|
|
2017-05-02 22:03:17 +08:00
|
|
|
# Library
|
|
|
|
$(OBJDIR)/HAVE_lib%: $(OBJDIR)/CONFIG_LIB%.c
|
|
|
|
$(PRINT_LIBCONFIG) $(LIB_CONFIG)
|
2017-06-16 16:34:22 +08:00
|
|
|
$(OBJDIR)/CONFIG_LIB%.c: $(OBJDIR)/.mkdir
|
|
|
|
$(PRINT_GENERATE) echo 'int main() { return 0; }' > "$@"
|
2017-06-17 15:36:07 +08:00
|
|
|
.PRECIOUS: $(OBJDIR)/CONFIG_LIB%.c
|
2017-05-02 22:03:17 +08:00
|
|
|
|
2017-05-02 21:39:45 +08:00
|
|
|
# Check if a function is present
|
|
|
|
$(OBJDIR)/HAVE_%: $(OBJDIR)/CONFIG_CHECK_%.c
|
2017-05-10 13:25:14 +08:00
|
|
|
$(PRINT_CONFIG) $(FN_CONFIG)
|
2017-06-16 16:34:22 +08:00
|
|
|
$(OBJDIR)/CONFIG_CHECK_%.c: $(BUILD)config/check_%.c $(OBJDIR)/.mkdir
|
2017-05-02 21:39:45 +08:00
|
|
|
$(PRINT_COPY) cp $< $@
|
2017-06-17 15:36:07 +08:00
|
|
|
.PRECIOUS: $(OBJDIR)/CONFIG_CHECK_%.c
|
2017-05-02 21:27:41 +08:00
|
|
|
|
2017-05-02 17:08:14 +08:00
|
|
|
|
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:
|