Add regression test for build directory handling to make lint target
[coreboot.git] / util / lint / lint-002-build-dir-handling
1 #!/bin/sh
2 # This file is part of the coreboot project.
3 #
4 # Copyright (C) 2011 Patrick Georgi <patrick@georgi-clan.de>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #
19 # DESCR: Check that build directories can be chosen freely
20
21 # $1: command to test for GNU make
22 search_make() {
23 if [ -n "`$1 --version 2>&1 |grep GNU`" ]; then MAKE=$1; fi
24 }
25
26 # if $1 and $2 differ, exit with failure
27 compare_output() {
28 if ! [ "$1" = "$2" ]; then
29         echo \'$1\' should be \'$2\'
30         exit 1
31 fi
32 }
33
34 # $1: object directory
35 run_printall() {
36 $MAKE NOMKDIR=1 DOTCONFIG=$TMPCONFIG obj=$1 printall |sed -e "s,^ *,," -e "s, ,\n,g" -e "s,^ramstage-objs:=,," -e "s,mainboard/[^/]*/[^/]*/,.../," |grep "/static.*\.[co]" |sort |tr '\012\015' '  ' |sed -e "s,  *, ,g" -e "s, *$,,"
37 }
38
39 # find GNU make
40 search_make make
41 search_make gmake
42 search_make gnumake
43
44 if [ "$MAKE" = "" ]; then
45         echo Could not identify GNU make
46         exit 1
47 fi
48
49 # prepare a config to use
50 TMPCONFIG=`mktemp`
51 rm -f $TMPCONFIG
52 $MAKE NOMKDIR=1 DOTCONFIG=$TMPCONFIG allyesconfig >/dev/null
53
54 # look up parent directory
55 PARENTDIR=`dirname $PWD`
56
57 compare_output "`run_printall build`" "build/.../static.c build/.../static.ramstage.o"
58 compare_output "`run_printall ../obj`" "$PARENTDIR/obj/.../static.c $PARENTDIR/obj/.../static.ramstage.o"
59 compare_output "`run_printall /tmp`" "/tmp/.../static.c /tmp/.../static.ramstage.o"
60 compare_output "`run_printall /../tmp`" "/tmp/.../static.c /tmp/.../static.ramstage.o"
61
62 rm -f $TMPCONFIG
63