Make test rules more useful, detect error on PRODUCTS extension
This commit is contained in:
parent
c2edd48a05
commit
0dc453c3ac
88
rules.mk
88
rules.mk
|
@ -40,47 +40,57 @@ ifndef DIR
|
||||||
|
|
||||||
# So this is necessary for the substitution to happen correctly. Ugh!
|
# So this is necessary for the substitution to happen correctly. Ugh!
|
||||||
BASEDIR:= $(shell cd ./$(BUILD)/..; pwd)
|
BASEDIR:= $(shell cd ./$(BUILD)/..; pwd)
|
||||||
FULLDIR:= $(shell cd ./; pwd)
|
FULLDIR:= $(shell cd ./; pwd)
|
||||||
DIR:= $(subst $(BASEDIR),,$(FULLDIR))
|
DIR:= $(subst $(BASEDIR),,$(FULLDIR))
|
||||||
PRETTY_DIR:= $(subst $(BASEDIR),[top],$(FULLDIR))
|
PRETTY_DIR:= $(subst $(BASEDIR),[top],$(FULLDIR))
|
||||||
BASENAME_DIR:= $(shell basename $(FULLDIR))
|
BASENAME_DIR:= $(shell basename $(FULLDIR))
|
||||||
BUILD_DATE:= $(shell /bin/date '+%Y%m%d-%H%M%S')
|
BUILD_DATE:= $(shell /bin/date '+%Y%m%d-%H%M%S')
|
||||||
OBJROOT:= $(BUILDOBJ)/$(BUILDENV)/$(TARGET)$(BASE_EXTRA_DEPTH)
|
OBJROOT:= $(BUILDOBJ)/$(BUILDENV)/$(TARGET)$(BASE_EXTRA_DEPTH)
|
||||||
BUILD_LOG:= $(BUILD_LOGS)build-$(BUILDENV)-$(TARGET)-$(BUILD_DATE).log
|
BUILD_LOG:= $(BUILD_LOGS)build-$(BUILDENV)-$(TARGET)-$(BUILD_DATE).log
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Configuration variables
|
# Configuration variables
|
||||||
OBJDIR:= $(OBJROOT)$(DIR)
|
OBJDIR:= $(OBJROOT)$(DIR)
|
||||||
OBJECTS:= $(SOURCES:%=$(OBJDIR)/%$(OBJ_EXT))
|
OBJECTS:= $(SOURCES:%=$(OBJDIR)/%$(OBJ_EXT))
|
||||||
PRODUCTS_EXE:= $(patsubst %.exe,%$(EXE_EXT),$(filter %.exe,$(PRODUCTS)))
|
PRODUCTS_EXE:= $(patsubst %.exe,%$(EXE_EXT),$(filter %.exe,$(PRODUCTS)))
|
||||||
PRODUCTS_LIB:= $(patsubst %.lib,%$(LIB_EXT),$(filter %.lib,$(PRODUCTS)))
|
PRODUCTS_LIB:= $(patsubst %.lib,%$(LIB_EXT),$(filter %.lib,$(PRODUCTS)))
|
||||||
PRODUCTS_DLL:= $(patsubst %.dll,%$(DLL_EXT),$(filter %.dll,$(PRODUCTS)))
|
PRODUCTS_DLL:= $(patsubst %.dll,%$(DLL_EXT),$(filter %.dll,$(PRODUCTS)))
|
||||||
PRODUCTS_OTHER:= $(filter-out %.exe %.lib %.dll %$(EXE_EXT) %$(LIB_EXT) %$(DLL_EXT), $(PRODUCTS))
|
PRODUCTS_OTHER:=$(filter-out %.exe %.lib %.dll %$(EXE_EXT) %$(LIB_EXT) %$(DLL_EXT), $(PRODUCTS))
|
||||||
OBJROOT_EXE:= $(PRODUCTS_EXE:%=$(OBJROOT)/%)
|
OBJROOT_EXE:= $(PRODUCTS_EXE:%=$(OBJROOT)/%)
|
||||||
OBJROOT_LIB:= $(PRODUCTS_LIB:%=$(OBJROOT)/%)
|
OBJROOT_LIB:= $(PRODUCTS_LIB:%=$(OBJROOT)/%)
|
||||||
OBJROOT_DLL:= $(PRODUCTS_DLL:%=$(OBJROOT)/%)
|
OBJROOT_DLL:= $(PRODUCTS_DLL:%=$(OBJROOT)/%)
|
||||||
OBJROOT_OTHER:= $(PRODUCTS_OTHER:%=$(OBJROOT)/%)
|
OBJROOT_OTHER:= $(PRODUCTS_OTHER:%=$(OBJROOT)/%)
|
||||||
OBJPRODUCTS:= $(OBJROOT_EXE) $(OBJROOT_LIB) $(OBJROOT_DLL) $(OBJROOT_OTHER)
|
OBJPRODUCTS:= $(OBJROOT_EXE) $(OBJROOT_LIB) $(OBJROOT_DLL) $(OBJROOT_OTHER)
|
||||||
|
|
||||||
LIBNAMES:= $(notdir $(LIBRARIES))
|
# Check a common mistake with PRODUCTS= not being set or set without extension
|
||||||
OBJLIBRARIES:= $(LIBNAMES:%=$(OBJROOT)/%$(LIB_EXT))
|
# Even on Linux / Unix, the PRODUCTS variable must end in .exe for executables,
|
||||||
LINK_INPUTS:= $(OBJECTS) $(SUBLIBS) $(OBJLIBRARIES)
|
# in .lib for static libraries, and in .dll for dynamic libraries.
|
||||||
ifneq ($(words $(LINK_INPUTS)),0)
|
# This is to help executable build rules be more robust and not catch
|
||||||
LINK_WINPUTS= $(patsubst %,"%", $(shell cygpath -aw $(LINK_INPUTS)))
|
# unknown extensions by mistake. The extension is replaced with the
|
||||||
|
# correct platform extension, i.e. .a for static libraries on Linux
|
||||||
|
ifeq ($(PRODUCTS_EXE)$(PRODUCTS_LIB)$(PRODUCTS_DLL),)
|
||||||
|
$(error Error: Variable PRODUCTS must end in .exe, .lib or .dll)
|
||||||
endif
|
endif
|
||||||
PRINT_DIR= --no-print-directory
|
|
||||||
|
LIBNAMES:= $(notdir $(LIBRARIES))
|
||||||
|
OBJLIBRARIES:= $(LIBNAMES:%=$(OBJROOT)/%$(LIB_EXT))
|
||||||
|
LINK_INPUTS:= $(OBJECTS) $(LINK_LIBS) $(OBJLIBRARIES)
|
||||||
|
ifneq ($(words $(LINK_INPUTS)),0)
|
||||||
|
LINK_WINPUTS= $(patsubst %,"%", $(shell cygpath -aw $(LINK_INPUTS)))
|
||||||
|
endif
|
||||||
|
PRINT_DIR= --no-print-directory
|
||||||
RECURSE_BUILDENV=$(BUILDENV)
|
RECURSE_BUILDENV=$(BUILDENV)
|
||||||
RECURSE_CMD= $(MAKE) $(PRINT_DIR) TARGET=$(TARGET) BUILDENV=$(RECURSE_BUILDENV) $(RECURSE) COLORIZE=
|
RECURSE_CMD= $(MAKE) $(PRINT_DIR) TARGET=$(TARGET) BUILDENV=$(RECURSE_BUILDENV) $(RECURSE) COLORIZE=
|
||||||
MAKEFILE_DEPS:= Makefile \
|
MAKEFILE_DEPS:= Makefile \
|
||||||
$(BUILD)rules.mk \
|
$(BUILD)rules.mk \
|
||||||
$(BUILD)config.mk \
|
$(BUILD)config.mk \
|
||||||
$(BUILD)config.$(BUILDENV).mk
|
$(BUILD)config.$(BUILDENV).mk
|
||||||
NOT_PARALLEL?= .NOTPARALLEL
|
NOT_PARALLEL?= .NOTPARALLEL
|
||||||
BUILD_LOW?= 0
|
BUILD_LOW?= 0
|
||||||
BUILD_HIGH?= 100
|
BUILD_HIGH?= 100
|
||||||
BUILD_INDEX:= 1
|
BUILD_INDEX:= 1
|
||||||
BUILD_COUNT:= $(words $(SOURCES))
|
BUILD_COUNT:= $(words $(SOURCES))
|
||||||
GIT_REVISION:= $(shell git rev-parse --short HEAD 2> /dev/null || echo "unknown")
|
GIT_REVISION:= $(shell git rev-parse --short HEAD 2> /dev/null || echo "unknown")
|
||||||
PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OBJROOT_EXE))_prof_$(GIT_REVISION).vsp
|
PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OBJROOT_EXE))_prof_$(GIT_REVISION).vsp
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
@ -90,12 +100,16 @@ PROFILE_OUTPUT:=$(subst $(EXE_EXT),,$(OBJROOT_EXE))_prof_$(GIT_REVISION).vsp
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
|
|
||||||
debug opt release profile: logs.mkdir
|
debug opt release profile: logs.mkdir
|
||||||
$(PRINT_COMMAND) $(TIME) \
|
$(PRINT_COMMAND) $(TIME) $(MAKE) TARGET=$@ RECURSE=build LOG_COMMANDS= build $(LOG_COMMANDS)
|
||||||
$(MAKE) TARGET=$@ RECURSE=build build $(LOG_COMMANDS)
|
|
||||||
|
|
||||||
check: all test
|
# Testing
|
||||||
|
test tests check:
|
||||||
|
$(PRINT_COMMAND) $(MAKE) RECURSE=test $(TESTS:%=%.runtest) LOG_COMMANDS= $(LOG_COMMANDS)
|
||||||
|
|
||||||
|
# Clean builds
|
||||||
startup restart rebuild: clean all
|
startup restart rebuild: clean all
|
||||||
|
|
||||||
|
# Installation
|
||||||
install: hello.install \
|
install: hello.install \
|
||||||
$(OBJROOT_EXE:%=%.install_exe) \
|
$(OBJROOT_EXE:%=%.install_exe) \
|
||||||
$(OBJROOT_LIB:%=%.install_lib) \
|
$(OBJROOT_LIB:%=%.install_lib) \
|
||||||
|
@ -156,19 +170,16 @@ objects:$(OBJDIR:%=%/.mkdir) $(OBJECTS)
|
||||||
prebuild:
|
prebuild:
|
||||||
postbuild:
|
postbuild:
|
||||||
|
|
||||||
# Testing
|
|
||||||
test tests: $(TESTS:%=%.runtest)
|
|
||||||
|
|
||||||
# Run the test (in the object directory)
|
# Run the test (in the object directory)
|
||||||
product.runtest: product .ALWAYS
|
product.runtest: product .ALWAYS
|
||||||
$(PRINT_TEST) $(OBJROOT_EXE) $(PRODUCTS_OPTS)
|
$(PRINT_TEST) $(OBJROOT_EXE) $(PRODUCTS_OPTS)
|
||||||
|
|
||||||
# Run a test from a C or C++ file
|
# Run a test from a C or C++ file to link against current library
|
||||||
%.c.runtest: product .ALWAYS
|
%.c.runtest: $(OBJROOT_LIB) .ALWAYS
|
||||||
$(PRINT_TEST) $(MAKE) SOURCES=$*.c LIBRARIES=$(PRODUCTS_LIB) PRODUCTS=$*
|
$(PRINT_BUILD) $(MAKE) SOURCES=$*.c LINK_LIBS=$(OBJROOT_LIB) PRODUCTS=$*.exe $(TARGET)
|
||||||
$(PRINT_TEST) $(OBJROOT)/$*
|
$(PRINT_TEST) $(OBJROOT)/$*
|
||||||
%.cpp.runtest: product .ALWAYS
|
%.cpp.runtest: $(OBJROOT_LIB) .ALWAYS
|
||||||
$(PRINT_TEST) $(MAKE) SOURCES=$*.cpp LIBRARIES=$(PRODUCTS_LIB) PRODUCTS=$*
|
$(PRINT_BUILD) $(MAKE) SOURCES=$*.cpp LINK_LIBS=$(OBJROOT_LIB) PRODUCTS=$*.exe $(TARGET)
|
||||||
$(PRINT_TEST) $(OBJROOT)/$*
|
$(PRINT_TEST) $(OBJROOT)/$*
|
||||||
|
|
||||||
# Installing the product: always need to build it first
|
# Installing the product: always need to build it first
|
||||||
|
@ -244,6 +255,8 @@ else
|
||||||
%.recurse: | hello prebuild
|
%.recurse: | hello prebuild
|
||||||
+$(PRINT_COMMAND) cd $* && $(RECURSE_CMD)
|
+$(PRINT_COMMAND) cd $* && $(RECURSE_CMD)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# If LIBRARIES=foo/bar, go to directory foo/bar, which should build bar.a
|
||||||
$(OBJROOT)/%$(LIB_EXT): $(DEEP_BUILD)
|
$(OBJROOT)/%$(LIB_EXT): $(DEEP_BUILD)
|
||||||
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES) $(SUBDIRS)) && $(RECURSE_CMD)
|
+$(PRINT_COMMAND) cd $(filter %$*, $(LIBRARIES) $(SUBDIRS)) && $(RECURSE_CMD)
|
||||||
%/.runtest:
|
%/.runtest:
|
||||||
|
@ -269,7 +282,6 @@ PRINT_COMMAND= @
|
||||||
PRINT_COMPILE= $(PRINT_COMMAND) $(INFO) "[COMPILE$(PRINT_COUNT)] " $<;
|
PRINT_COMPILE= $(PRINT_COMMAND) $(INFO) "[COMPILE$(PRINT_COUNT)] " $<;
|
||||||
PRINT_BUILD= $(PRINT_COMMAND) $(INFO) "[BUILD]" $(shell basename $@);
|
PRINT_BUILD= $(PRINT_COMMAND) $(INFO) "[BUILD]" $(shell basename $@);
|
||||||
PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" $(shell basename $@);
|
PRINT_GENERATE= $(PRINT_COMMAND) $(INFO) "[GENERATE]" $(shell basename $@);
|
||||||
PRINT_TEST= $(PRINT_COMMAND) $(INFO) "[TEST]" $(shell basename $<);
|
|
||||||
PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL] " $(*F) in $(<D);
|
PRINT_INSTALL= $(PRINT_COMMAND) $(INFO) "[INSTALL] " $(*F) in $(<D);
|
||||||
PRINT_COPY= $(PRINT_COMMAND) $(INFO) "[COPY]" $(*F) into $(@D) ;
|
PRINT_COPY= $(PRINT_COMMAND) $(INFO) "[COPY]" $(*F) into $(@D) ;
|
||||||
PRINT_DEPEND= $(PRINT_COMMAND) $(INFO) "[DEPEND] " $< ;
|
PRINT_DEPEND= $(PRINT_COMMAND) $(INFO) "[DEPEND] " $< ;
|
||||||
|
|
Loading…
Reference in New Issue