Blame view

RIOT/makefiles/scan-build.inc.mk 2.53 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
  SCANBUILD_ENV_VARS := \
    APPDIR \
    AR \
    ARFLAGS \
    AS \
    ASFLAGS \
    BINDIR \
    BINDIRBASE \
    BOARD \
    BUILDRELPATH \
    CC \
    CFLAGS \
    CPPMIX \
    CXX \
    CXXEXFLAGS \
    CXXUWFLAGS \
    ELFFILE \
    HEXFILE \
    HOME \
    LINK \
    LINKFLAGPREFIX \
    LINKFLAGS \
    OBJCOPY \
    OFLAGS \
    PATH \
    PREFIX \
    QUIET \
    WERROR \
    RIOT_VERSION \
    SIZE \
    TOOLCHAIN \
    UNDEF \
    USER \
    #
  
  SCANBUILD_ARGS ?= \
    -analyze-headers \
    --use-cc=$(CC) \
    --use-c++=$(CXX) \
    -analyzer-config stable-report-filename=true \
    #
  
  export SCANBUILD_OUTPUTDIR = $(CURDIR)/scan-build/
  
  # Find all variables given on the command line and recreate the command.
  CMDVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \
    $(if $(filter command, $(origin $(varname))), \
    '$(varname)=$(subst ','\'',$($(varname)))', \
    )))
  ENVVARS := $(strip $(foreach varname, $(SCANBUILD_ENV_VARS), \
    $(if $(filter environment, $(origin $(varname))), \
    '$(varname)=$(subst ','\'',$($(varname)))', \
    )))
  
  .PHONY: scan-build scan-build-analyze scan-build-view
  scan-build: scan-build-view scan-build-analyze
  scan-build-view: scan-build-analyze
  ifeq ($(BUILD_IN_DOCKER),1)
  scan-build-analyze: ..in-docker-container
  else # BUILD_IN_DOCKER
  scan-build-analyze: clean
  	@$(COLOR_ECHO) '$(COLOR_GREEN)Performing Clang static code analysis using toolchain "$(TOOLCHAIN)".$(COLOR_RESET)'
  # ccc-analyzer needs to be told the proper -target setting for best results,
  # otherwise false error reports about unknown register names etc will be produced.
  # These kinds of errors can be safely ignored as long as they only come from LLVM
  	@if [ "$${TOOLCHAIN}" != "llvm" -a "$${BOARD}" != "native" ]; then \
  	  $(COLOR_ECHO) '$(COLOR_YELLOW)Recommend using TOOLCHAIN=llvm for best results.$(COLOR_RESET)'; \
  	  $(COLOR_ECHO) '$(COLOR_YELLOW)Ignore any "error: unknown register name '\''rX'\'' in asm" messages.$(COLOR_RESET)'; \
  	fi
  	$(Q)mkdir -p '$(SCANBUILD_OUTPUTDIR)'
  	$(Q)env -i $(ENVVARS) \
  	    scan-build -o '$(SCANBUILD_OUTPUTDIR)' $(SCANBUILD_ARGS) \
  	      make -C $(CURDIR) all $(strip $(CMDVARS)) FORCE_ASSERTS=1;
  endif # BUILD_IN_DOCKER
  
  ifeq (1,$(INSIDE_DOCKER))
  scan-build-view:
  	@
  else
  	@echo "Showing most recent report in your web browser..."
  	@REPORT_FILE="$$(find '$(SCANBUILD_OUTPUTDIR)' -maxdepth 2 -mindepth 2 \
  	            -type f -name 'index.html' 2>/dev/null | sort | tail -n 1)"; \
  	  if [ -n "$${REPORT_FILE}" ]; then \
  	    echo "$(OPEN) $${REPORT_FILE}"; \
  	    $(OPEN) "$${REPORT_FILE}"; \
  	  else \
  	    echo "No report found"; \
  	  fi
  endif
  
  # Reset the default goal.
  .DEFAULT_GOAL :=