diff options
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | citools/jenkins-build.sh | 16 | ||||
-rw-r--r-- | makefiles/Makefile.clang | 20 | ||||
-rw-r--r-- | makefiles/Makefile.gcc | 37 | ||||
-rw-r--r-- | makefiles/Makefile.open64 | 2 | ||||
-rw-r--r-- | makefiles/Makefile.tools | 78 | ||||
-rw-r--r-- | makefiles/Makefile.top | 38 | ||||
-rw-r--r-- | testtools/testrunner.pl | 4 |
8 files changed, 164 insertions, 33 deletions
@@ -6,7 +6,7 @@ # Component settings COMPONENT := buildsystem -COMPONENT_VERSION := 1.5 +COMPONENT_VERSION := 1.10 .PHONY:all usage install dist clean distclean test diff --git a/citools/jenkins-build.sh b/citools/jenkins-build.sh index db406f8..2da910e 100755 --- a/citools/jenkins-build.sh +++ b/citools/jenkins-build.sh @@ -32,6 +32,7 @@ # static - perform a static analysis # coverity - perform a coverity scan # docs - build doxygen docs +# sanitize - Run the test suite under ASAN and UBSAN # HOST must be in the environment and set correctly if [ "x${HOST}" = "x" ];then @@ -100,6 +101,11 @@ case "$1" in TARGET_DOCS=${HOST} ;; + "sanitize") + TARGET_SANITIZE=${HOST} + VARIANT="debug" + ;; + "") # default is test only on Linux and install # Currently most tests do not work on targets except for Linux @@ -109,7 +115,7 @@ case "$1" in *) cat <<EOF -Usage: jenkins-build.sh [install|test-install|coverage|static|docs] +Usage: jenkins-build.sh [install|test-install|coverage|static|docs|sanitize] install build and install test-install build, test and install @@ -117,6 +123,7 @@ Usage: jenkins-build.sh [install|test-install|coverage|static|docs] static perform a static anaysis coverity perform a coverity scan docs generate doxygen docs + sanitize run the tests under ASAN/UBSAN EOF exit 1 ;; @@ -130,6 +137,10 @@ case ${BUILD} in MAKE=gmake ;; + x86_64-unknown-openbsd*) + MAKE=gmake + ;; + x86_64-unknown-freebsd*) MAKE=gmake ;; @@ -216,6 +227,9 @@ elif [ "x${HOST}" = "x${TARGET_DOCS}" ]; then # Documentation build ${MAKE} Q= HOST=${HOST} VARIANT=${VARIANT} docs +elif [ "x${HOST}" = "x${TARGET_SANITIZE}" ]; then + # Sanitize build + env UBSAN_OPTIONS=print_stacktrace=1 ${MAKE} Q= HOST=${HOST} VARIANT=${VARIANT} sanitize else # Normal build diff --git a/makefiles/Makefile.clang b/makefiles/Makefile.clang index 4006a92..bcd14e3 100644 --- a/makefiles/Makefile.clang +++ b/makefiles/Makefile.clang @@ -21,12 +21,28 @@ CXXSHR := -fPIC LDDBG := -g # Reevaluation is required here -LDSHR = -shared -Wl,-soname,$(SONAME) +ifeq ($(findstring darwin,$(HOST)),darwin) + LDSHR = -dynamiclib -install_name $(SONAME) +else + LDSHR = -shared -Wl,-soname,$(SONAME) +endif + ARFLG := cru # Definitions of various attributes -CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" +CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" -DSTMTEXPR=1 + +# Extensions for sanitize target +ifeq ($(MAKECMDGOALS),sanitize) + SANCFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + SANCXXFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + SANLDFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + + CFLAGS := $(CFLAGS) $(SANCFLAGS) + CXXFLAGS := $(CXXFLAGS) $(SANCXXFLAGS) + LDFLAGS := $(LDFLAGS) $(SANLDFLAGS) +endif ############################################################################### # Mac OS X Universal Binaries diff --git a/makefiles/Makefile.gcc b/makefiles/Makefile.gcc index 5f2bd4d..0ce0d9b 100644 --- a/makefiles/Makefile.gcc +++ b/makefiles/Makefile.gcc @@ -20,12 +20,16 @@ CXXSHR := -fPIC LDDBG := -g # Reevaluation is required here -LDSHR = -shared -Wl,-soname,$(SONAME) +ifeq ($(findstring darwin,$(HOST)),darwin) + LDSHR = -dynamiclib -install_name $(SONAME) +else + LDSHR = -shared -Wl,-soname,$(SONAME) +endif ARFLG := cru # Definitions for various attributes -CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" +CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" -DSTMTEXPR=1 # Extensions for coverage target ifeq ($(MAKECMDGOALS),coverage) @@ -49,10 +53,24 @@ ifeq ($(MAKECMDGOALS),profile) LDFLAGS := $(LDFLAGS) $(PROFLDFLAGS) endif +# Extensions for sanitize target +ifeq ($(MAKECMDGOALS),sanitize) + SANCFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + SANCXXFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + SANLDFLAGS ?= -fsanitize=address -fsanitize=undefined -fno-sanitize-recover + + CFLAGS := $(CFLAGS) $(SANCFLAGS) + CXXFLAGS := $(CXXFLAGS) $(SANCXXFLAGS) + LDFLAGS := $(LDFLAGS) $(SANLDFLAGS) +endif + # RISC OS module extensions ifeq ($(COMPONENT_TYPE),riscos-module) ifneq ($(HOST),arm-unknown-riscos) - $(error Attempting to build a RISC OS module for a non-RISC OS target) + # Note: this also rejects the gnueabi(hf) RISC OS hosts, too, as the + # tooling for those is not able to generate code compatible with RISC OS + # module environments. + $(error Attempting to build a RISC OS module for a non-RISC OS host) endif CFLAGS := $(CFLAGS) -mmodule @@ -60,6 +78,17 @@ ifeq ($(COMPONENT_TYPE),riscos-module) LDFLAGS := $(LDFLAGS) -mmodule endif +# RISC OS backtrace extensions +ifneq ($(findstring -riscos,$(HOST)),) + CFLAGS := $(CFLAGS) -mpoke-function-name + CXXFLAGS := $(CXXFLAGS) -mpoke-function-name + ifneq ($(findstring -gnueabi,$(HOST)),) + # Note: this assumes we're not generating RISC OS module code (see above) + CFLAGS := $(CFLAGS) -funwind-tables + CXXFLAGS := $(CXXFLAGS) -funwind-tables + endif +endif + ############################################################################### # Mac OS X Universal Binaries ############################################################################### @@ -82,7 +111,7 @@ endif ############################################################################### # Determine if the compiler supports simultaneous build & dep. -ccvsn := $(shell $(CC) -dumpversion) +ccvsn := $(shell $(CC) -dumpversion -dumpfullversion) # ccvsn = x.y.z GCCVER := $(word 1,$(subst ., ,$(ccvsn))) # GCCVER = x diff --git a/makefiles/Makefile.open64 b/makefiles/Makefile.open64 index b58569c..142474a 100644 --- a/makefiles/Makefile.open64 +++ b/makefiles/Makefile.open64 @@ -27,7 +27,7 @@ LDFLAGS := $(LDFLAGS) -ipa ARFLG := cru # Definitions for various attributes -CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" +CFLAGS := $(CFLAGS) -D_ALIGNED="__attribute__((aligned))" -DSTMTEXPR=1 # Extensions for coverage target ifeq ($(MAKECMDGOALS),coverage) diff --git a/makefiles/Makefile.tools b/makefiles/Makefile.tools index 86fac4c..40e4d10 100644 --- a/makefiles/Makefile.tools +++ b/makefiles/Makefile.tools @@ -121,12 +121,17 @@ ifeq ($(BUILD),$(HOST)) else # Cross compiling - # Make first-stab at identity of CC - CC__ := $(CC) - # Improve our guess at the identity of CC - # (only if CC was not specified by the user) - ifeq ($(origin CC),default) - CC__ := $(HOST)-gcc + ifneq ($(NS_ENV_CC),) + # If we have a CC specified by env.sh, start with that + CC__ := $(NS_ENV_CC) + else + # Make first-stab at identity of CC + CC__ := $(CC) + # Improve our guess at the identity of CC + # (only if CC was not specified by the user) + ifeq ($(origin CC),default) + CC__ := $(HOST)-gcc + endif endif # Search the path for the compiler @@ -139,7 +144,7 @@ else else CC__ := $(realpath $(toolpath_)) toolpath_ := $(dir $(CC__)) - toolprefix_ := $(subst :,/,$(dir $(subst -,/,$(subst /,:,$(CC__))))) + toolprefix_ := $(subst :,/,$(subst /,-,$(patsubst %/,%,$(dir $(subst -,/,$(subst /,:,$(CC__))))))) ifeq ($(origin AR),default) AR__ := $(toolprefix_)-ar endif @@ -153,26 +158,35 @@ else GCCSDK_INSTALL_ENV := $(realpath $(toolpath_)../../env) endif - ifeq ($(HOST),arm-unknown-riscos) + ifeq ($(findstring -riscos,$(HOST)),-riscos) # Cross compiling for RISC OS - CMHG ?= PATH="$(GCCSDK_INSTALL_CROSSBIN):$(PATH)" $(GCCSDK_INSTALL_CROSSBIN)/cmunge + ifeq ($(findstring gnueabi,$(HOST)),gnueabi) + # Can't build modules with this [arm-riscos-gnueabi(hf)] toolchain + CMHG ?= echo + else + CMHG ?= PATH="$(GCCSDK_INSTALL_CROSSBIN):$(PATH)" $(GCCSDK_INSTALL_CROSSBIN)/cmunge + endif GENHTML ?= echo LCOV ?= echo PKGCONFIG ?= PKG_CONFIG_LIBDIR="$(PREFIX)/lib/pkgconfig:$(GCCSDK_INSTALL_ENV)/lib/pkgconfig:$(GCCSDK_INSTALL_ENV)/share/pkgconfig" pkg-config ifneq ($(COMPONENT_TYPE),riscos-module) + EXEEXT := ,ff8 ifneq ($(findstring arm-unknown-riscos-gcc,$(CC__)),) EXEEXT := ,e1f - else - EXEEXT := ,ff8 + endif + ifneq ($(findstring arm-riscos-gnueabi-gcc,$(CC__)),) + EXEEXT := ,e1f + endif + ifneq ($(findstring arm-riscos-gnueabihf-gcc,$(CC__)),) + EXEEXT := ,e1f endif else EXEEXT := ,ffa endif - # TODO: this assumes GCC - CFLAGS := $(CFLAGS) -mpoke-function-name -I$(GCCSDK_INSTALL_ENV)/include - CXXFLAGS := $(CXXFLAGS) -mpoke-function-name -I$(GCCSDK_INSTALL_ENV)/include + CFLAGS := $(CFLAGS) -I$(GCCSDK_INSTALL_ENV)/include + CXXFLAGS := $(CXXFLAGS) -I$(GCCSDK_INSTALL_ENV)/include LDFLAGS := $(LDFLAGS) -L$(GCCSDK_INSTALL_ENV)/lib CMHGFLAGS := -p -tgcc -32bit -apcs 3/32/nonreent/fpe2/noswst/nofpr/nofp @@ -206,6 +220,10 @@ else CXXFLAGS := $(CXXFLAGS) -U__STRICT_ANSI__ -I$(GCCSDK_INSTALL_ENV)/include LDFLAGS := $(LDFLAGS) -L$(GCCSDK_INSTALL_ENV)/lib + ifeq ($(HOST),m68k-unknown-amigaos) + CFLAGS += -fomit-frame-pointer -m68020 + endif + PREFIX ?= $(GCCSDK_INSTALL_ENV) endif @@ -267,7 +285,7 @@ GENHTML ?= genhtml BUILD_CXX ?= c++ -INSTALL ?= install +INSTALL ?= install -C LCOV ?= lcov @@ -369,6 +387,11 @@ else endif endif + ifeq ($(findstring lcc:,$(ccvsn)),lcc:) + # MCST LCC pretends to be gcc + toolchain := gcc + endif + # "Norcroft ..." ifeq ($(word 1,$(ccvsn)),Norcroft) toolchain := norcroft @@ -399,6 +422,25 @@ ifeq ($(toolchain),) $(error Unable to detect toolchain) endif +# Detect if the toolchain ought to support sanitizers +SANITIZE_OK=no +ifeq ($(toolchain),gcc) + GCC_VERSION := $(shell $(CC) -dumpversion -dumpfullversion) + GCC_MAJOR := $(word 1,$(subst ., ,$(GCC_VERSION))) + ifeq ($(shell expr $(GCC_MAJOR) \>= 6),1) + SANITIZE_OK=yes + endif +else ifeq ($(toolchain),clang) + SANITIZE_OK=yes +endif + +# And fail if we can't sanitize and yet the user asked for it +ifeq ($(MAKECMDGOALS),sanitize) + ifeq ($(SANITIZE_OK),no) + $(error Unable to build with sanitizers enabled, compiler not compatible + endif +endif + # TODO: It would be nice to avoid this hard-coded path include $(NSBUILD)/Makefile.$(toolchain) @@ -435,7 +477,11 @@ LDFLAGS := $(LDFLAGS) $(OPTLDFLAGS) ifeq ($(COMPONENT_TYPE),lib-static) LIBEXT ?= .a else - LIBEXT ?= .so + ifeq ($(findstring darwin,$(HOST)),darwin) + LIBEXT ?= .dylib + else + LIBEXT ?= .so + endif endif # If we're building a shared library, modify the flags appropriately diff --git a/makefiles/Makefile.top b/makefiles/Makefile.top index 9d3c680..c1a8490 100644 --- a/makefiles/Makefile.top +++ b/makefiles/Makefile.top @@ -48,6 +48,7 @@ # test Build and run test suite, using current settings. # coverage Determine test suite coverage (requires lcov) # profile Build with profiling support enabled (requires gprof) +# sanitize Build and run test suite, using ASAN and UBSAN # docs Produce documentation (requires doxygen) # dist Produce release tarball from latest git tag # clean Clean the build @@ -123,6 +124,8 @@ else ifeq ($(MAKECMDGOALS),profile) WANT_TEST := yes else ifeq ($(MAKECMDGOALS),coverage) WANT_TEST := yes +else ifeq ($(MAKECMDGOALS),sanitize) + WANT_TEST := yes else WANT_TEST := no endif @@ -186,9 +189,17 @@ endif # Determine the output filename ifeq ($(findstring lib,$(COMPONENT_TYPE)),lib) ifeq ($(findstring lib-shared,$(COMPONENT_TYPE)),lib-shared) - SHAREDLIBNAME := lib$(COMPONENT)$(LIBEXT) - SONAME := $(SHAREDLIBNAME).$(major-version) - OUTPUT := $(BUILDDIR)/$(SHAREDLIBNAME).$(COMPONENT_VERSION) + ifeq ($(findstring darwin,$(HOST)),darwin) + # In macOS, shared lib filenames are of the form libfoo.dylib, + # libfoo.1.dylib, or libfoo.1.2.3.dylib + SONAME := lib$(COMPONENT).$(major-version)$(LIBEXT) + SHAREDLIBNAME := lib$(COMPONENT)$(LIBEXT) + OUTPUT := $(BUILDDIR)/lib$(COMPONENT).$(COMPONENT_VERSION)$(LIBEXT) + else + SHAREDLIBNAME := lib$(COMPONENT)$(LIBEXT) + SONAME := $(SHAREDLIBNAME).$(major-version) + OUTPUT := $(BUILDDIR)/$(SHAREDLIBNAME).$(COMPONENT_VERSION) + endif else OUTPUT := $(BUILDDIR)/lib$(COMPONENT)$(LIBEXT) endif @@ -205,10 +216,6 @@ endif ifeq ($(COMPONENT_TYPE),lib-shared) POST_TARGETS := __postshared $(POST_TARGETS) - -__postshared: - $(Q)$(LN) $(LNFLAGS) -f -s $(notdir $(OUTPUT)) $(BUILDDIR)/$(SONAME) - $(Q)$(LN) $(LNFLAGS) -f -s $(notdir $(OUTPUT)) $(BUILDDIR)/$(SHAREDLIBNAME) endif # Default target @@ -218,6 +225,10 @@ all: $(PRE_TARGETS) $(OUTPUT) $(POST_TARGETS) test: all $(TEST_PREREQS) $(TEST_BINARIES) $(TEST_TARGETS) $(VQ)$(ECHO) $(ECHOFLAGS) " TEST: Testing complete" +__postshared: + $(Q)$(LN) $(LNFLAGS) -f -s $(notdir $(OUTPUT)) $(BUILDDIR)/$(SONAME) + $(Q)$(LN) $(LNFLAGS) -f -s $(notdir $(OUTPUT)) $(BUILDDIR)/$(SHAREDLIBNAME) + # Compute coverage __precov: __partial_clean $(Q)$(LCOV) --directory . --zerocounters @@ -231,6 +242,9 @@ coverage: __precov test $(Q)$(GENHTML) -o $(COVERAGEDIR) --num-spaces 2 \ $(COVERAGEDIR)/$(COMPONENT).info +# Build and test sanitizers +sanitize: test + # Build for profiling profile: __partial_clean test @@ -408,6 +422,16 @@ else endif endif +ifneq ($(PRE_TARGETS),) +# Ensure that PRE_TARGETS are built before OBJECTS. +$(OBJECTS): $(PRE_TARGETS) +endif + +ifneq ($(POST_TARGETS),) +# Ensure that POST_TARGETS are built after OBJECTS. +$(POST_TARGETS): $(OBJECTS) +endif + ############################################################################### # Autogenerated, implied rules ############################################################################### diff --git a/testtools/testrunner.pl b/testtools/testrunner.pl index fe55ebe..ad6fcdc 100644 --- a/testtools/testrunner.pl +++ b/testtools/testrunner.pl @@ -86,7 +86,7 @@ while (my $line = <TINDEX>) { # Run testcase run_test("$builddir/$test", "$directory/data/$data/$dtest"); - } + } close(DINDEX); } else { @@ -148,6 +148,8 @@ sub run_test # EOF, so remove handle $selector->remove($fh); next; + } elsif ($len == 1 && $input eq "\n") { + # Skip bare new line. } else { # Split into lines my @lines = split('\n', $input); |