]> git.ipfire.org Git - ipfire-3.x.git/blob - tools/make-check
f92566389ac88fcb6d09386661c5c83b943fbe86
[ipfire-3.x.git] / tools / make-check
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 check_common() {
23 local NAME=$1
24 if [ -n "$3" ]; then
25 local RVER=$2
26 local COMMAND=$3
27 else
28 local COMMAND=$2
29 fi
30
31 local EXTRA=$4
32
33 RANDOM=$$
34 TMPFILE=/tmp/ipfire-check-$RANDOM
35
36 echo -ne "${BOLD}Checking for $NAME${NORMAL}"
37
38 [ -n "$RVER" ] && echo -n " (Requires at least $RVER)"
39
40 bash -c "$COMMAND" >$TMPFILE 2>&1
41
42 if ! grep -q "command not found" < $TMPFILE; then
43 beautify message DONE
44 else
45 rm -f $TMPFILE 2>/dev/null
46 exiterror "$NAME not found!"
47 fi
48
49 [ -n "$EXTRA" ] && echo -n "$EXTRA"
50
51 cat $TMPFILE
52 rm -f $TMPFILE 2>/dev/null
53 echo # Empty line
54 }
55
56 check_toolchain() {
57 check_common "GNU autoconf" "2.63" "autoconf --version | head -n1"
58 check_common "GNU Bash" "2.05a" "bash --version | head -n1 | cut -d\" \" -f2-4"
59 check_common "/bin/sh links bash?" "if ! which sh; then echo \"command not found\"; fi"
60 check_common "GNU Binutils" "2.12" "ld --version | head -n1 | cut -d\" \" -f3-" "Binutils: "
61 check_common "GNU Bison" "1.875" "bison --version | head -n1"
62 #check_common "/usr/bin/yacc links bison?" "if ! which yacc; then echo \"command not found\"; fi"
63 check_common "Bzip2" "1.0.2" "bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d\" \" -f1,6-"
64 check_common "Coreutils" "5.0" "chown --version | head -n1 | cut -d\")\" -f2" "Coreutils:"
65 check_common "Diffutils" "2.8" "diff --version | head -n1"
66 check_common "Findutils" "4.1.20" "find --version | head -n1"
67 check_common "GNU awk" "3.0" "gawk --version | head -n1"
68 check_common "/bin/awk links gawk?" "if ! which awk; then echo \"command not found\"; fi"
69 check_common "GNU CC" "3.0.1" "gcc --version | head -n1"
70 check_common "GNU C++" "3.0.1" "g++ --version | head -n1"
71 check_common "GNU libc" "2.2.5" "/lib/libc.so.6 | head -n1 | cut -d\" \" -f1-7"
72 check_common "GNU Grep" "2.5" "grep --version | head -n1"
73 check_common "GNU zip" "1.2.4" "gzip --version | head -n1"
74 check_common "Linux 2.6" "2.6.x" "uname -r" "Linux: "
75 check_common "GNU make" "3.79.1" "make --version | head -n1"
76 check_common "Patch" "2.5.4" "patch --version | head -n1"
77 check_common "GNU sed" "3.0.2" "sed --version | head -n1"
78 check_common "GNU tar" "1.14" "tar --version | head -n1"
79 check_common "GNU Texinfo" "4.8" "makeinfo --version | head -n1"
80 check_common "GNU m4" "1.4.8" "m4 --version | head -n1"
81 check_common "GNU libtool" "libtool --version | head -n1"
82 }
83
84 check_build() {
85 check_common "Python" "python -V"
86 check_common "GNU make" "3.79.1" "make --version | head -n1"
87 check_common "Git" "git --version"
88 check_common "GNU which" "which --version | head -n1"
89 }
90
91 check_code() {
92 ACTION=$1
93 ARGS="--recurse"
94
95 echo -n " Running code checks"
96
97 case "$ACTION" in
98 --fix)
99 echo -n " and fix"
100 ;;
101 "")
102 ARGS+=" --dryrun"
103 ;;
104 *)
105 exiterror "This is not a valid option: $ACTION"
106 ;;
107 esac
108
109 echo -n "..." # End the line
110
111 python $BASEDIR/tools/code-beautify $ARGS $BASEDIR/{config,doc,lfs,src,tools}
112 if [ "$?" -eq "0" ]; then
113 beautify message DONE
114 else
115 beautify message FAIL
116 exit 1
117 fi
118 }
119
120 check_sanity() {
121
122 echo "Checking sanity of working directory..."
123
124 rootfiles_check $*
125 check_code $*
126
127 }
128
129 check_user() {
130 if [ -z $IPFIRE_USER ]; then
131 echo -n "You have to setup IPFIRE_USER first. See .config for details."
132 beautify message FAIL
133 exit 1
134 fi
135 }
136
137 check_loop() {
138 for i in $(seq 0 7); do
139 if [ -e /dev/loop/$i ] || [ -e /dev/loop$i ]; then
140 return 0
141 fi
142 done
143 return 1
144 }
145
146 CPU_FLAGS=$(grep ^flags /proc/cpuinfo)
147 check_cpu() {
148 FLAG=$1;
149 grep -q $FLAG <<< $CPU_FLAGS
150 return $?
151 }
152
153 check_supported_target() {
154 local FLAGS
155 if [ "$1" = "via-c7" ]; then
156 FLAGS="sse sse2 pni"
157 elif [ "$1" = "via-c3" ]; then
158 FLAGS="3dnow"
159 elif [ "$1" = "atom" ]; then
160 FLAGS="mmx sse sse2 pni ssse3"
161 elif [ "$1" = "core2duo" ]; then
162 FLAGS="sse2"
163 fi
164 for j in $FLAGS; do
165 if ! check_cpu $j; then
166 echo "Your system doesn't support needed cpu feature \"$j\" to build target $1." >&2
167 return 1
168 fi
169 done
170 return 0
171 }
172
173 check_supported_targets() {
174 for i in ${1-$POSSIBLE_TARGETS}; do
175 check_supported_target $i 2>/dev/null
176 [ "$?" -eq "0" ] && echo -n "$i "
177 done
178 echo # new line
179 }