]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
add check infrastructure, default sparse
authorKim Phillips <kim.phillips@freescale.com>
Fri, 21 Sep 2012 12:28:17 +0000 (12:28 +0000)
committerTom Rini <trini@ti.com>
Mon, 15 Oct 2012 18:54:03 +0000 (11:54 -0700)
Add support for running source code checkers on u-boot source, e.g.,
using sparse to aid with typechecking.  This comes in especially
handy as SoC vendors mix and match cores and devices with different
endianness, thus here we add CHECK_ENDIAN to the otherwise linux
kernel default CHECKFLAGS.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Makefile
config.mk

index 09456e090a20e64374fe9d43aea928f200dd113a..7802a0fec8cdaebeda43e43bbb710af359c05215 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -92,6 +92,24 @@ BUILD_DIR := $(O)
 endif
 endif
 
+# Call a source code checker (by default, "sparse") as part of the
+# C compilation.
+#
+# Use 'make C=1' to enable checking of re-compiled files.
+#
+# See the linux kernel file "Documentation/sparse.txt" for more details,
+# including where to get the "sparse" utility.
+
+ifdef C
+ifeq ("$(origin C)", "command line")
+CHECKSRC := $(C)
+endif
+endif
+ifndef CHECKSRC
+  CHECKSRC = 0
+endif
+export CHECKSRC
+
 ifneq ($(BUILD_DIR),)
 saved-output := $(BUILD_DIR)
 
index 51b47838cf53dd85fd928945efa36e2b92d9b975..bb5c69a15d9f67376ca58534b189707dc714db72 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -149,6 +149,7 @@ OBJCOPY = $(CROSS_COMPILE)objcopy
 OBJDUMP = $(CROSS_COMPILE)objdump
 RANLIB = $(CROSS_COMPILE)RANLIB
 DTC    = dtc
+CHECK  = sparse
 
 #########################################################################
 
@@ -275,6 +276,10 @@ ifneq ($(CONFIG_SPL_TEXT_BASE),)
 LDFLAGS_u-boot-spl += -Ttext $(CONFIG_SPL_TEXT_BASE)
 endif
 
+# Linus' kernel sanity checking tool
+CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
+                  -Wbitwise -Wno-return-void -D__CHECK_ENDIAN__ $(CF)
+
 # Location of a usable BFD library, where we define "usable" as
 # "built for ${HOST}, supports ${TARGET}".  Sensible values are
 # - When cross-compiling: the root of the cross-environment
@@ -322,6 +327,9 @@ $(obj)%.s:  %.S
 $(obj)%.o:     %.S
        $(CC)  $(ALL_AFLAGS) -o $@ $< -c
 $(obj)%.o:     %.c
+ifneq ($(CHECKSRC),0)
+       $(CHECK) $(CHECKFLAGS) $(ALL_CFLAGS) $<
+endif
        $(CC)  $(ALL_CFLAGS) -o $@ $< -c
 $(obj)%.i:     %.c
        $(CPP) $(ALL_CFLAGS) -o $@ $< -c