xref: /illumos-gate/usr/src/tools/smatch/src/smatch_scripts/build_generic_data.sh (revision f34e64d88f694155255ac1c93990904dbfa28af3)
1#!/bin/bash
2
3# This is a generic script to parse --info output.  For the kernel, don't use
4# this script, use build_kernel_data.sh instead.
5
6NR_CPU=$(cat /proc/cpuinfo | grep ^processor | wc -l)
7SCRIPT_DIR=$(dirname $0)
8DATA_DIR=smatch_data
9PROJECT=smatch_generic
10TARGET=""
11
12function usage {
13    echo
14    echo "Usage:  $0"
15    echo "Updates the smatch_data/ directory and builds the smatch database"
16    echo " -p <project> (default = $PROJECT)"
17    echo
18    exit 1
19}
20
21while true ; do
22    if [[ "$1" == "--target" ]] ; then
23        shift
24        TARGET="$1"
25        shift
26    elif [ "$1" == "-p" ] || [ "$1" == "--project" ] ; then
27        shift
28        PROJECT="$1"
29        shift
30    elif [ "$1" == "--help" ] || [ "$1" = "-h" ] ; then
31        usage
32    else
33        break
34    fi
35done
36
37if [ -e $SCRIPT_DIR/../smatch ] ; then
38    BIN_DIR=$SCRIPT_DIR/../
39else
40    echo "This script should be located in the smatch_scripts/ subdirectory of the smatch source."
41    exit 1
42fi
43
44# If someone is building the database for the first time then make sure all the
45# required packages are installed
46if [ ! -e smatch_db.sqlite ] ; then
47    [ -e smatch_warns.txt ] || touch smatch_warns.txt
48    if ! $SCRIPT_DIR/../smatch_data/db/create_db.sh -p=$PROJECT smatch_warns.txt ; then
49        echo "Hm... Not working.  Make sure you have all the sqlite3 packages"
50        echo "And the sqlite3 libraries for Perl and Python"
51        exit 1
52    fi
53fi
54
55if [[ ! -z $ARCH ]]; then
56	KERNEL_ARCH="ARCH=$ARCH"
57fi
58if [[ ! -z $CROSS_COMPILE ]] ; then
59	KERNEL_CROSS_COMPILE="CROSS_COMPILE=$CROSS_COMPILE"
60fi
61
62make $KERNEL_ARCH $KERNEL_CROSS_COMPILE -j${NR_CPU} CHECK="$BIN_DIR/smatch --call-tree --info --spammy --file-output" $TARGET
63
64find -name \*.c.smatch -exec cat \{\} \; -exec rm \{\} \; > smatch_warns.txt
65
66for i in $SCRIPT_DIR/gen_* ; do
67        $i smatch_warns.txt -p=${PROJECT}
68done
69
70mkdir -p $DATA_DIR
71mv $PROJECT.* $DATA_DIR
72
73$SCRIPT_DIR/../smatch_data/db/create_db.sh -p=$PROJECT smatch_warns.txt
74
75