build: make scan-build work again

This drops the scan-build related Kconfig options
since it's now possible to simply run

    scan-build [-o outdir] make

and get coreboot built with its report.

There's also no inner make process anymore, and the way
things work should be clearer now.

Also adapt abuild to this new reality.

Change-Id: I03e03334761ec83f718b3235ebf811834cd2e3e3
Signed-off-by: Patrick Georgi <patrick@georgi-clan.de>
Reviewed-on: http://review.coreboot.org/5774
Tested-by: build bot (Jenkins)
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
diff --git a/Makefile b/Makefile
index 5c4484a..ddacdc37 100644
--- a/Makefile
+++ b/Makefile
@@ -30,19 +30,9 @@
 ## SUCH DAMAGE.
 ##
 
-ifeq ($(INNER_SCANBUILD),y)
-CC_real:=$(CC)
-endif
-
 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile $(XGCCPATH) > .xcompile)))
 include .xcompile
 
-ifeq ($(INNER_SCANBUILD),y)
-CC:=$(CC_real)
-HOSTCC:=$(CC_real) --hostcc
-HOSTCXX:=$(CC_real) --hostcxx
-endif
-
 export top := $(CURDIR)
 export src := src
 export srck := $(top)/util/kconfig
@@ -119,12 +109,10 @@
 
 include toolchain.inc
 
-ifneq ($(INNER_SCANBUILD),y)
 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
 CC:=clang -m32 -mno-mmx -mno-sse -no-integrated-as
 HOSTCC:=clang
 endif
-endif
 
 ifeq ($(CONFIG_CCACHE),y)
 CCACHE:=$(word 1,$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH)))))
@@ -143,25 +131,7 @@
 # The primary target needs to be here before we include the
 # other files
 
-ifeq ($(INNER_SCANBUILD),y)
-CONFIG_SCANBUILD_ENABLE:=
-endif
-
-ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
-ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
-CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
-endif
-real-all:
-	echo '#!/bin/sh' > .ccwrap
-	echo 'CC="$(CC)"' >> .ccwrap
-	echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
-	echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
-	echo 'eval $$CC $$*' >> .ccwrap
-	chmod +x .ccwrap
-	scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
-else
 real-all: real-target
-endif
 
 # must come rather early
 .SECONDEXPANSION:
diff --git a/src/Kconfig b/src/Kconfig
index 30f996d..53a23bb 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -80,29 +80,6 @@
 	  we'll have to assume that they use their distro compiler by mistake.
 	  Make sure that using patched compilers is a conscious decision.
 
-config SCANBUILD_ENABLE
-	bool "Build with scan-build for static code analysis"
-	default n
-	help
-	  Changes the build process to use scan-build (a utility for
-	  running the clang static code analyzer from the command line).
-
-	  Requires the scan-build utility in your system $PATH.
-
-	  For details see http://clang-analyzer.llvm.org/scan-build.html.
-
-config SCANBUILD_REPORT_LOCATION
-	string "Directory for the scan-build report(s)"
-	default ""
-	depends on SCANBUILD_ENABLE
-	help
-	  Directory where the scan-build reports should be stored in. The
-	  reports are stored in subdirectories of the form 'yyyy-mm-dd-*'
-	  in the specified directory.
-
-	  If this setting is left empty, the coreboot top-level directory
-	  will be used to store the report subdirectories.
-
 config CCACHE
 	bool "Use ccache to speed up (re)compilation"
 	default n
diff --git a/toolchain.inc b/toolchain.inc
index 9417a73..bfa604b 100644
--- a/toolchain.inc
+++ b/toolchain.inc
@@ -19,6 +19,22 @@
 
 ARCH_SUPPORTED := armv7 x86_32
 
+
+# scan-build integration
+ifneq ($(CCC_ANALYZER_OUTPUT_FORMAT),)
+
+ifeq ($(CCC_ANALYZER_ANALYSIS),)
+export CCC_ANALYZER_ANALYSIS := -analyzer-opt-analyze-headers
+endif
+
+$(foreach arch,$(ARCH_SUPPORTED), \
+	$(eval CC_$(arch):=CCC_CC=$(CC_$(arch)) $(CC) ))
+
+HOSTCC:=CCC_CC="$(HOSTCC)" $(CC)
+HOSTCXX:=CCC_CXX="$(HOSTCXX)" $(CXX)
+ROMCC=CCC_CC="$(ROMCC_BIN)" $(CC)
+endif
+
 COREBOOT_STANDARD_STAGES := bootblock romstage ramstage
 
 ARCHDIR-i386    := x86
diff --git a/util/abuild/abuild b/util/abuild/abuild
index 434bcc6..d4ee752 100755
--- a/util/abuild/abuild
+++ b/util/abuild/abuild
@@ -238,7 +238,7 @@
 	CURR=$( pwd )
 	#stime=`perl -e 'print time();' 2>/dev/null || date +%s`
 	build_dir=$TARGET/${VENDOR}_${MAINBOARD}
-	eval $MAKE $silent DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
+	eval $BUILDPREFIX $MAKE $silent DOTCONFIG=${build_dir}/config.build obj=${build_dir} objutil=$TARGET/sharedutils \
 		&> ${build_dir}/make.log
 	ret=$?
 	cp .xcompile ${build_dir}/xcompile.build
@@ -291,13 +291,16 @@
 	stime=`perl -e 'print time();' 2>/dev/null || date +%s`
 	create_buildenv $VENDOR $MAINBOARD $CONFIG
 	if [ $? -eq 0  -a  $configureonly -eq 0 ]; then
+		BUILDPREFIX=
 		if [ "$scanbuild" = "true" ]; then
-			rm -rf $TARGET/scan-build-results-tmp
+			scanbuild_out=$TARGET/${VENDOR}_${MAINBOARD}-scanbuild
+			rm -rf ${scanbuild_out}
+			BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
 		fi
 		compile_target $VENDOR $MAINBOARD
 		if [ "$scanbuild" = "true" ]; then
-			rm -rf $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
-			mv `dirname $TARGET/scan-build-results-tmp/*/index.html` $TARGET/${VENDOR}_${MAINBOARD}-scanbuild
+			mv ${scanbuild_out}tmp/* ${scanbuild_out}
+			rmdir ${scanbuild_out}tmp
 		fi
 	fi
 	# Not calculated here because we still print it in compile_target
@@ -386,7 +389,6 @@
 	printf "    [-T|--test]			  submit image(s) to automated test system\n"
 	printf "    [-c|--cpus <numcpus>]         build on <numcpus> at the same time\n"
 	printf "    [-s|--silent]                 omit compiler calls in logs\n"
-	printf "    [-sb|--scan-build]            use clang's static analyzer\n"
 	printf "    [-y|--ccache]                 use ccache\n"
 	printf "    [-C|--config]                 configure-only mode\n"
 	printf "    [-l|--loglevel <num>]         set loglevel\n"
@@ -394,6 +396,7 @@
 	printf "    [-P|--prefix <name>]          file name prefix in CBFS\n"
 	printf "    [-B|--blobs]                  Allow using binary files\n"
 	printf "    [-L|--clang]                  Use clang\n"
+	printf "    [--scan-build]                use clang's static analyzer\n"
 	printf "    [cbroot]			  absolute path to coreboot sources\n"
 	printf "				  (defaults to $ROOT)\n\n"
 }
@@ -468,10 +471,9 @@
 			expr "$1" : '-\?[0-9]\+$' > /dev/null && test 0$1 -gt 1 && cpuconfig="on $1 cpus in parallel"
 			shift;;
 		-s|--silent)    shift; silent="-s";;
-		-sb|--scan-build) shift
+		--scan-build)   shift
 			scanbuild=true
 			customizing="${customizing}, scan-build"
-			configoptions="${configoptions}CONFIG_SCANBUILD_ENABLE=y\nCONFIG_SCANBUILD_REPORT_LOCATION=\"$TARGET/scan-build-results-tmp\""
 			;;
 		-y|--ccache)    shift
 			customizing="${customizing}, ccache"
@@ -546,7 +548,17 @@
 		echo "CONFIG_USE_BLOBS=y" > $TMPCFG
 	fi
 	$MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils allnoconfig
-	$MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils tools || exit 1
+	BUILDPREFIX=
+	if [ "$scanbuild" = "true" ]; then
+		scanbuild_out=$TARGET/sharedutils-scanbuild
+		rm -rf ${scanbuild_out}
+		BUILDPREFIX="scan-build -o ${scanbuild_out}tmp"
+	fi
+	$BUILDPREFIX $MAKE -j $cpus DOTCONFIG=$TMPCFG obj=$TARGET/temp objutil=$TARGET/sharedutils tools || exit 1
+	if [ "$scanbuild" = "true" ]; then
+		mv ${scanbuild_out}tmp/* ${scanbuild_out}
+		rmdir ${scanbuild_out}tmp
+	fi
 	rm -rf $TARGET/temp $TMPCFG
 	for VENDOR in $( vendors ); do
 		for MAINBOARD in $( mainboards $VENDOR ); do
diff --git a/util/lint/lint-stable-002-build-dir-handling b/util/lint/lint-stable-002-build-dir-handling
index 03f0b62..013d84a 100755
--- a/util/lint/lint-stable-002-build-dir-handling
+++ b/util/lint/lint-stable-002-build-dir-handling
@@ -33,7 +33,7 @@
 
 # $1: object directory
 run_printall() {
-$MAKE CONFIG_USE_BLOBS=n CONFIG_CCACHE=n CONFIG_SCANBUILD_ENABLE=n NOMKDIR=1 \
+$MAKE CONFIG_USE_BLOBS=n CONFIG_CCACHE=n NOMKDIR=1 \
 	DOTCONFIG=$TMPCONFIG obj=$1 printall |        \
 	sed -e "s,^ *,," -e "s,^r.mstage-objs:=,,"    \
 	    -e "s,mainboard/[^/]*/[^/]*/,.../,g" |    \