[IMPROVE] remove atomic context for sspt_proc.filter
[kernel/swap-modules.git] / build.sh
1 #!/usr/bin/env bash
2 # NOTE: This requires GNU getopt.  On Mac OS X and FreeBSD, you have to install
3 # this separately; see below.
4
5 IDENT=${0}
6
7 show_usage_and_exit () {
8         echo -e "Usage: ${IDENT} <options> <compile|check|clean>"
9         echo -e "\tOptions:"
10         echo -e "\t--verbose"
11         echo -e "\t--file <config file>"
12 #       echo -e "\t--debug"
13         echo -e "\t--kernel <kernel path>"
14         echo -e "\t--arch <arm|i386>"
15         echo -e "\t[--toolchain <cross compile path>]"
16         exit 1
17 }
18
19 TEMP=`getopt -o vk:t:a:f: --long verbose,kernel:,toolchain:,arch:,file: \
20         -n '${IDENT}' -- "$@"`
21
22 if [ $? != 0 ] ; then
23         show_usage_and_exit
24 fi
25
26 # Note the quotes around `$TEMP': they are essential!
27 eval set -- "$TEMP"
28
29 MDIR=`pwd`
30 VERBOSE=false
31 CONFIG_FILE="build.config"
32 KERNELDIR=""
33 TOOLCHAIN=""
34 ARCH=""
35
36 while true; do
37         case "$1" in
38                 -v | --verbose ) VERBOSE=true; shift ;;
39                 -k | --kernel ) KERNELDIR="$2"; shift 2 ;;
40                 -t | --toolchain ) TOOLCHAIN="$2"; shift 2;;
41                 -a | --arch ) ARCH="$2"; shift 2;;
42                 -f | --file ) CONFIG_FILE="$2"; shift 2;;
43                 -- ) shift; break ;;
44                 * ) break ;;
45         esac
46 done
47
48 if  [ "${1}" != "compile" -a "${1}" != "clean" -a "${1}" != "check"  ] ; then
49         ACTION="compile"
50         ARCH=${2}
51         KERNELDIR=${1}
52         if [ "${3}" != "" ] ; then
53                 TOOLCHAIN=${3}
54         fi
55 else
56         if [ -r ${CONFIG_FILE} ]; then
57                 . ${CONFIG_FILE}
58                 KERNELDIR=${kernel}
59                 TOOLCHAIN=${toolchain}
60                 ARCH=$arch
61         fi
62         ACTION="${1}"
63 fi
64
65 if [ "${KERNELDIR}" = "" ] ; then
66         show_usage_and_exit
67 fi
68
69 if [ "${ARCH}" = "arm" ] ; then
70         LINKNAME="arm"
71 elif [ "${ARCH}" = "i386" ] ; then
72         LINKNAME="x86"
73 else
74         show_usage_and_exit
75 fi
76
77 MCFLAGS="-Werror"
78
79 CMDLINE_ARGS=""
80 CMDLINE_ARGS="CROSS_COMPILE=${TOOLCHAIN} ARCH=${ARCH} -C ${KERNELDIR}"
81 CMDLINE_ARGS="${CMDLINE_ARGS} M=${MDIR} MCFLAGS=${MCFLAGS} LINKNAME=${LINKNAME}"
82
83 if [ "${ACTION}" = "check" ] ; then
84         CMDLINE="make C=2 CF=\"-Wsparse-all\" ${CMDLINE_ARGS} modules"
85 elif [ "${ACTION}" = "clean" ] ; then
86         CMDLINE="make ${CMDLINE_ARGS} clean"
87 else
88         CMDLINE="make ${CMDLINE_ARGS} modules"
89 fi
90
91 if [ ${VERBOSE} = "true" ] ; then
92         CMDLINE="${CMDLINE} V=1"
93 fi
94
95 #echo -n "CMDLINE ${CMDLINE}\n"
96
97 ${CMDLINE} || exit 1
98
99 exit 0
100