Import bsd.clang-analyze.mk based on NetBSD's version.
This allows 'make analyze' or 'make OBJ.clang-analyzer' to run the Clang static analyzer and present results on stdout. Obtained from: NetBSD (CVS Rev. 1.3) Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D5449
This commit is contained in:
parent
b29980a63f
commit
aae63957af
@ -24,7 +24,7 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 21, 2015
|
||||
.Dd February 26, 2016
|
||||
.Dt BUILD 7
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -107,6 +107,8 @@ section below, and by the variables documented in
|
||||
The following list provides the names and actions for the targets
|
||||
supported by the build system:
|
||||
.Bl -tag -width ".Cm cleandepend"
|
||||
.It Cm analyze
|
||||
Run Clang static analyzer against all objects and present output on stdout.
|
||||
.It Cm check
|
||||
Run tests for a given subdirectory.
|
||||
The default directory used is
|
||||
|
@ -17,6 +17,7 @@ FILES= \
|
||||
auto.obj.mk \
|
||||
bsd.README \
|
||||
bsd.arch.inc.mk \
|
||||
bsd.clang-analyze.mk \
|
||||
bsd.compiler.mk \
|
||||
bsd.confs.mk \
|
||||
bsd.cpu.mk \
|
||||
|
105
share/mk/bsd.clang-analyze.mk
Normal file
105
share/mk/bsd.clang-analyze.mk
Normal file
@ -0,0 +1,105 @@
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Support Clang static analyzer on SRCS.
|
||||
#
|
||||
#
|
||||
# +++ variables +++
|
||||
#
|
||||
# CLANG_ANALYZE_CHECKERS Which checkers to run for all sources.
|
||||
#
|
||||
# CLANG_ANALYZE_CXX_CHECKERS Which checkers to run for C++ sources.
|
||||
#
|
||||
# CLANG_ANALYZE_OUTPUT Output format for generated files.
|
||||
# text - don't generate extra files.
|
||||
# html - generate html in obj.plist/ directories.
|
||||
# plist - generate xml obj.plist files.
|
||||
# See also:
|
||||
# contrib/llvm/tools/clang/include/clang/StaticAnalyzer/Core/Analyses.def
|
||||
#
|
||||
# CLANG_ANALYZE_OUTPUT_DIR Sets which directory output set by
|
||||
# CLANG_ANALYZE_OUTPUT is placed into.
|
||||
#
|
||||
# +++ targets +++
|
||||
#
|
||||
# analyze:
|
||||
# Run the Clang static analyzer against all sources and present
|
||||
# output on stdout.
|
||||
|
||||
.if !target(__<bsd.clang-analyze.mk>__)
|
||||
__<bsd.clang-analyze.mk>__:
|
||||
|
||||
.include <bsd.compiler.mk>
|
||||
|
||||
.if ${COMPILER_TYPE} != "clang" && (make(analyze) || make(*.clang-analyzer))
|
||||
.error Clang static analyzer requires clang but found that compiler '${CC}' is ${COMPILER_TYPE}
|
||||
.endif
|
||||
|
||||
CLANG_ANALYZE_OUTPUT?= text
|
||||
CLANG_ANALYZE_OUTPUT_DIR?= clang-analyze
|
||||
CLANG_ANALYZE_FLAGS+= --analyze \
|
||||
-Xanalyzer -analyzer-output=${CLANG_ANALYZE_OUTPUT} \
|
||||
-o ${CLANG_ANALYZE_OUTPUT_DIR}
|
||||
|
||||
CLANG_ANALYZE_CHECKERS+= core deadcode security unix
|
||||
CLANG_ANALYZE_CXX_CHECKERS+= cplusplus
|
||||
|
||||
.for checker in ${CLANG_ANALYZE_CHECKERS}
|
||||
CLANG_ANALYZE_FLAGS+= -Xanalyzer -analyzer-checker=${checker}
|
||||
.endfor
|
||||
CLANG_ANALYZE_CXX_FLAGS+= ${CLANG_ANALYZE_FLAGS}
|
||||
.for checker in ${CLANG_ANALYZE_CXX_CHECKERS}
|
||||
CLANG_ANALYZE_CXX_FLAGS+= -Xanalyzer -analyzer-checker=${checker}
|
||||
.endfor
|
||||
|
||||
.SUFFIXES: .c .cc .cpp .cxx .C .clang-analyzer
|
||||
|
||||
CLANG_ANALYZE_CFLAGS= ${CFLAGS:N-Wa,--fatal-warnings}
|
||||
CLANG_ANALYZE_CXXFLAGS= ${CXXFLAGS:N-Wa,--fatal-warnings}
|
||||
|
||||
.c.clang-analyzer:
|
||||
${CC:N${CCACHE_BIN}} ${CLANG_ANALYZE_FLAGS} \
|
||||
${CLANG_ANALYZE_CFLAGS} ${CPPFLAGS} \
|
||||
${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
|
||||
${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
|
||||
.cc.clang-analyzer .cpp.clang-analyzer .cxx.clang-analyzer .C.clang-analyzer:
|
||||
${CXX:N${CCACHE_BIN}} ${CLANG_ANALYZE_CXX_FLAGS} \
|
||||
${CLANG_ANALYZE_CXXFLAGS} ${CPPFLAGS} \
|
||||
${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
|
||||
${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
|
||||
|
||||
CLANG_ANALYZE_SRCS= \
|
||||
${SRCS:M*.[cC]} ${SRCS:M*.cc} \
|
||||
${SRCS:M*.cpp} ${SRCS:M*.cxx} \
|
||||
${DPSRCS:M*.[cC]} ${DPSRCS:M*.cc} \
|
||||
${DPSRCS:M*.cpp} ${DPSRCS:M*.cxx}
|
||||
.if !empty(CLANG_ANALYZE_SRCS)
|
||||
CLANG_ANALYZE_OBJS= ${CLANG_ANALYZE_SRCS:O:u:R:S,$,.clang-analyzer,}
|
||||
.NOPATH: ${CLANG_ANALYZE_OBJS}
|
||||
.endif
|
||||
|
||||
# .depend files aren't relevant here since they reference obj.o rather than
|
||||
# obj.clang-analyzer, so add in some guesses in case 'make depend' wasn't ran,
|
||||
# for when directly building 'obj.clang-analyzer'.
|
||||
.for __obj in ${CLANG_ANALYZE_OBJS}
|
||||
${__obj}: ${OBJS_DEPEND_GUESS}
|
||||
${__obj}: ${OBJS_DEPEND_GUESS.${__obj}}
|
||||
.endfor
|
||||
|
||||
.if ${MK_FAST_DEPEND} == "yes"
|
||||
beforeanalyze: depend
|
||||
.endif
|
||||
beforeanalyze: .PHONY
|
||||
.if !defined(_RECURSING_PROGS) && !empty(CLANG_ANALYZE_SRCS) && \
|
||||
${CLANG_ANALYZE_OUTPUT} != "text"
|
||||
mkdir -p ${CLANG_ANALYZE_OUTPUT_DIR}
|
||||
.endif
|
||||
|
||||
.if !target(analyze)
|
||||
analyze: beforeanalyze .WAIT ${CLANG_ANALYZE_OBJS}
|
||||
.endif
|
||||
|
||||
.if exists(${CLANG_ANALYZE_OUTPUT_DIR})
|
||||
CLEANDIRS+= ${CLANG_ANALYZE_OUTPUT_DIR}
|
||||
.endif
|
||||
|
||||
.endif # !target(__<bsd.clang-analyze.mk>__)
|
@ -83,7 +83,7 @@ tags: ${SRCS}
|
||||
# Skip reading .depend when not needed to speed up tree-walks
|
||||
# and simple lookups.
|
||||
.if !empty(.MAKEFLAGS:M-V${_V_READ_DEPEND}) || make(obj) || make(clean*) || \
|
||||
make(install*)
|
||||
make(install*) || make(analyze)
|
||||
_SKIP_READ_DEPEND= 1
|
||||
.if ${MK_DIRDEPS_BUILD} == "no"
|
||||
.MAKE.DEPENDFILE= /dev/null
|
||||
|
@ -441,5 +441,6 @@ ${_S:R}.So: ${OBJS_DEPEND_GUESS.${_S:R}.So}
|
||||
.endif
|
||||
|
||||
.include <bsd.dep.mk>
|
||||
.include <bsd.clang-analyze.mk>
|
||||
.include <bsd.obj.mk>
|
||||
.include <bsd.sys.mk>
|
||||
|
@ -283,5 +283,6 @@ ${OBJS}: ${OBJS_DEPEND_GUESS}
|
||||
.endif
|
||||
|
||||
.include <bsd.dep.mk>
|
||||
.include <bsd.clang-analyze.mk>
|
||||
.include <bsd.obj.mk>
|
||||
.include <bsd.sys.mk>
|
||||
|
@ -39,7 +39,7 @@
|
||||
__<bsd.subdir.mk>__:
|
||||
|
||||
SUBDIR_TARGETS+= \
|
||||
all all-man buildconfig buildfiles buildincludes \
|
||||
all all-man analyze buildconfig buildfiles buildincludes \
|
||||
checkdpadd clean cleandepend cleandir cleanilinks \
|
||||
cleanobj depend distribute files includes installconfig \
|
||||
installfiles installincludes realinstall lint maninstall \
|
||||
|
@ -176,7 +176,7 @@ CXXFLAGS+= ${CXXFLAGS.${COMPILER_TYPE}}
|
||||
|
||||
# Tell bmake not to mistake standard targets for things to be searched for
|
||||
# or expect to ever be up-to-date.
|
||||
PHONY_NOTMAIN = afterdepend afterinstall all beforedepend beforeinstall \
|
||||
PHONY_NOTMAIN = analyze afterdepend afterinstall all beforedepend beforeinstall \
|
||||
beforelinking build build-tools buildconfig buildfiles \
|
||||
buildincludes check checkdpadd clean cleandepend cleandir \
|
||||
cleanobj configure depend distclean distribute exe \
|
||||
|
@ -461,5 +461,6 @@ ${OBJS}: ${OBJS_DEPEND_GUESS}
|
||||
.endif
|
||||
|
||||
.include <bsd.dep.mk>
|
||||
.include <bsd.clang-analyze.mk>
|
||||
.include <bsd.obj.mk>
|
||||
.include "kern.mk"
|
||||
|
Loading…
x
Reference in New Issue
Block a user