src.dualinventive.com/dinet/common/mk/common.mk

230 lines
7.4 KiB
Makefile

CLANG_VERSION?=3.8
CLANG_CC=clang-$(CLANG_VERSION)
CLANG_CXX=clang++-$(CLANG_VERSION)
# Be more quiet
ifneq ($(V),1)
Q := @
NQMAKE := $(MAKE) --no-print-directory
MAKE := $(Q)$(MAKE) --no-print-directory
NULL := 2>/dev/null
endif
ANALYZER_CHECKS = alpha.core.BoolAssignment,alpha.core.CallAndMessageUnInitRefArg,alpha.core.CastSize,alpha.core.CastToStruct,alpha.core.DynamicTypeChecker,alpha.core.FixedAddr,alpha.core.IdenticalExpr,alpha.core.PointerArithm,alpha.core.PointerSub,alpha.core.SizeofPtr,alpha.core.TestAfterDivZero,alpha.osx.cocoa.Dealloc,alpha.osx.cocoa.DirectIvarAssignment,alpha.osx.cocoa.DirectIvarAssignmentForAnnotatedFunctions,alpha.osx.cocoa.InstanceVariableInvalidation,alpha.osx.cocoa.MissingInvalidationMethod,alpha.osx.cocoa.localizability.PluralMisuseChecker,alpha.security.ArrayBound,alpha.security.ArrayBoundV2,alpha.security.MallocOverflow,alpha.security.ReturnPtrRange,alpha.security.taint.TaintPropagation,alpha.unix.Chroot,alpha.unix.PthreadLock,alpha.unix.SimpleStream,alpha.unix.Stream,alpha.unix.cstring.BufferOverlap,alpha.unix.cstring.NotNullTerminated,alpha.unix.cstring.OutOfBounds,llvm.Conventions,nullability.NullableDereferenced,nullability.NullablePassedToNonnull,optin.osx.cocoa.localizability.EmptyLocalizationContextChecker,optin.osx.cocoa.localizability.NonLocalizedStringChecker,osx.API,osx.SecKeychainAPI,osx.cocoa.AtSync,osx.cocoa.ClassRelease,osx.cocoa.IncompatibleMethodTypes,osx.cocoa.Loops,osx.cocoa.MissingSuperCall,osx.cocoa.NSAutoreleasePool,osx.cocoa.NSError,osx.cocoa.NilArg,osx.cocoa.NonNilReturnValue,osx.cocoa.ObjCGenerics,osx.cocoa.RetainCount,osx.cocoa.SelfInit,osx.cocoa.UnusedIvars,osx.cocoa.VariadicMethodTypes,osx.coreFoundation.CFError,osx.coreFoundation.CFNumber,osx.coreFoundation.CFRetainRelease,osx.coreFoundation.containers.OutOfBounds,osx.coreFoundation.containers.PointerSizedValues,security.FloatLoopCounter,security.insecureAPI.rand,security.insecureAPI.strcpy
ANALYZER ?= no
REPORT ?= no
LEGACY ?= no
CLANG ?= yes
LINTER ?= yes
PACKAGE ?= yes
COVERAGE ?= yes
DOC ?= yes
DIST ?= yes
STM32_CHIP ?= none
CMAKE_OPTS = -Wno-dev
ifeq ($(LEGACY),yes)
CMAKE_OPTS += -DDI_LEGACY_APPLICATION=TRUE
else
CMAKE_OPTS += -DDI_LEGACY_APPLICATION=FALSE
endif
ifneq ($(STM32_CHIP),none)
STM32_TOOLCHAIN_PREFIX ?= /data/tools/toolchains/gcc-arm-none-eabi-6-2017-q1-update
COVERAGE = no
CMAKE_OPTS += -DSTM32_CHIP=$(STM32_CHIP)
CMAKE_OPTS += -DCMAKE_MODULE_PATH="$(shell pwd)/common/cmake/modules_fw"
CMAKE_OPTS += -DTOOLCHAIN_PREFIX=$(STM32_TOOLCHAIN_PREFIX)
CMAKE_OPTS += -DTARGET_TRIPLET=arm-none-eabi
CMAKE_OPTS += -DCMAKE_TOOLCHAIN_FILE=common/cmake/modules_fw/gcc_stm32.cmake
CMAKE_OPTS += -DCMAKE_CXX_FLAGS_RELEASE=""
CMAKE_OPTS += -DCMAKE_C_FLAGS_RELEASE=""
endif
debug: build/Debug/Makefile
$(Q)echo " [BUILD] Debug"
$(MAKE) -C build/Debug
debug-analyze: build/Debug-analyze/Makefile
$(Q)echo " [BUILD] Debug"
$(MAKE) -C build/Debug-analyze
debug-pt: build/Debug-pt/Makefile
$(Q)echo " [BUILD] Debug Production Test"
$(MAKE) -C build/Debug-pt
ifeq ($(CLANG),yes)
debug-clang: build/Debug-clang/Makefile
$(Q)echo " [BUILD] Debug clang $(CLANG_VERSION)"
$(MAKE) CC=$(CLANG_CC) CXX=$(CLANG_CXX) -C build/Debug-clang
else
debug-clang:
$(Q)echo " [SKIP] Debug clang"
endif
analyze:
ifeq ($(ANALYZER),yes)
$(Q)echo " [TEST] Clang analyzer"
$(Q)rm -rf clangScanBuildReports
$(Q)scan-build-$(CLANG_VERSION) -enable-checker $(ANALYZER_CHECKS) -o clangScanBuildReports make debug-analyze
$(MAKE) clean
else
$(Q)echo " [SKIP] Clang analyzer"
endif
help:
$(Q)echo "doc: Generate doxygen source code documentation"
$(Q)echo "debug: Build debug target"
$(Q)echo "debug-clang: Build debug target with clang"
$(Q)echo "release: Build release target"
$(Q)echo "analyze: Build debug with clang analyzer"
$(Q)echo "package: Build release package"
$(Q)echo "lint: Run lint"
$(Q)echo "test: Run test"
$(Q)echo "test-report: Generate test report (html)"
$(Q)echo "test-clang: Run test build with clang"
$(Q)echo "memcheck: Run memcheck test(s)"
$(Q)echo "coverage: Generate test coverage html and xml"
$(Q)echo "codereview: Generate code review pdf"
$(Q)echo "ci: Target for Continuous Integration"
ci:
$(MAKE) clean
$(MAKE) lint
$(MAKE) analyze
$(MAKE) debug-clang
$(MAKE) debug
$(MAKE) coverage
$(MAKE) test-report
$(MAKE) memcheck
$(MAKE) doc
$(MAKE) release
$(MAKE) package
$(MAKE) dist
release: build/Release/Makefile
$(Q)echo " [BUILD] Release"
$(MAKE) -C build/Release
release-pt: build/Release-pt/Makefile
$(Q)echo " [BUILD] Release Production Test"
$(MAKE) -C build/Release-pt
doc: build/Debug/Makefile
ifeq ($(DOC),yes)
$(Q)echo " [GEN] Doxygen source code documentation"
$(MAKE) -C build/Debug di-doc
else
$(Q)echo " [SKIP] Doxygen source code documentation"
endif
package: build/Release/Makefile
ifeq ($(PACKAGE),yes)
$(Q)echo " [GEN] package"
$(MAKE) -C build/Release package
else
$(Q)echo " [SKIP] package"
endif
dist:
ifeq ($(PACKAGE),yes)
$(Q)./common/mk/dist.sh
else ifneq ($(STM32_CHIP),none)
ifeq ($(DIST),yes)
$(Q)./common/mk/dist-hex.sh
else
$(Q)echo " [SKIP] dist"
endif
else
$(Q)echo " [SKIP] dist"
endif
ifeq ($(LINTER),yes)
lint: build/Debug/Makefile
$(Q)echo " [CHECK] Lint"
$(MAKE) -C build/Debug lint
else
lint:
$(Q)echo " [SKIP] Lint"
endif
build/Debug/.tested: build/Debug/Makefile
$(Q)echo " [TEST]"
$(MAKE) -C build/Debug test
$(Q)touch build/Debug/.tested
test: build/Debug/.tested
ifeq ($(REPORT),yes)
test-report: build/Debug/.tested
$(Q)echo " [GEN] Report (pdf)"
$(MAKE) -C build/Debug test-report
$(MAKE) -C build/Debug test-report-pdf
else
test-report:
$(Q)echo " [SKIP] Report (pdf)"
endif
test-clang: build/Debug-clang/Makefile
ifeq ($(CLANG),yes)
$(Q)echo " [TEST] Clang test $(CLANG_VERSION)"
$(Q)export CC=$(CLANG_CC) && \
export CXX=$(CLANG_CXX) && \
$(NQMAKE) -C build/Debug-clang && \
$(NQMAKE) -C build/Debug-clang test
else
$(Q)echo " [SKIP] Clang test"
endif
memcheck: build/Debug/Makefile
$(Q)echo " [TEST] ExperimentalMemCheck"
$(MAKE) -C build/Debug ExperimentalMemCheck
coverage: build/Debug/.tested
ifeq ($(COVERAGE),yes)
$(Q)echo " [GEN] Code coverage (cobertura xml)"
$(MAKE) -C build/Debug coverage-xml
else
$(Q)echo " [SKIP] Code coverage"
endif
codereview: build/Debug/Makefile
$(Q)echo " [GEN] Code review"
$(MAKE) -C build/Debug di-review
clean:
$(Q)echo " [CLEAN]"
$(Q)rm -rf build
build/Release/Makefile: build/Release
$(Q)echo " [GEN] $@"
$(Q)cd build/Release && cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Release ../..
build/Debug/Makefile: build/Debug
$(Q)echo " [GEN] $@"
$(Q)cd build/Debug && cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Debug ../..
build/Debug-analyze/Makefile: build/Debug-analyze
$(Q)echo " [GEN] $@"
$(Q)cd build/Debug-analyze && cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Debug ../..
build/Debug-pt/Makefile: build/Debug-pt
$(Q)echo " [GEN] $@"
$(Q)cd build/Debug-pt && cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Debug-pt ../..
build/Release-pt/Makefile: build/Release-pt
$(Q)echo " [GEN] $@"
$(Q)cd build/Release-pt && cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Release-pt ../..
build/Debug-clang/Makefile: build/Debug-clang
$(Q)echo " [GEN] $@"
$(Q)cd build/Debug-clang && \
export CC=$(CLANG_CC) && \
export CXX=$(CLANG_CXX) && \
cmake $(CMAKE_OPTS) -DCMAKE_BUILD_TYPE=Debug ../..
build/Release build/Debug build/Debug-clang build/Debug-analyze build/Debug-pt build/Release-pt:
$(Q)mkdir -p $@