autogen.sh, ngindent, platformtest.sh: Fix warnings of "shellcheck"
[ngircd-alex.git] / contrib / platformtest.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2016 Alexander Barton (alex@barton.de) and Contributors
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; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
11 #
12
13 # This script analyzes the build process of ngIRCd and generates output
14 # suitable for inclusion in doc/Platforms.txt -- please send reports
15 # to the ngIRCd mailing list: <ngircd-ml@ngircd.barton.de>.
16
17 NAME=$(basename "$0")
18 VERBOSE=
19 CLEAN=1
20
21 PLATFORM=
22 COMPILER="unknown"
23 VERSION="unknown"
24 DATE=$(date "+%y-%m-%d")
25 COMMENT=
26
27 R_CONFIGURE=
28 R_MAKE=
29 R_CHECK=
30 R_CHECK_Y="?"
31 R_RUN=
32
33 SRC_D=$(dirname "$0")
34 MY_D="$PWD"
35
36 [ -n "$MAKE" ] || MAKE="make"
37 export MAKE CC
38
39 while [ $# -gt 0 ]; do
40         case "$1" in
41                 "-v")
42                         VERBOSE=1
43                         ;;
44                 "-x")
45                         CLEAN=
46                         ;;
47                 *)
48                         echo "Usage: $NAME [-v] [-x]"
49                         echo
50                         echo "  -v   Verbose output"
51                         echo "  -x   Don't regenerate build system, even when possible"
52                         echo
53                         exit 2
54         esac
55         shift
56 done
57
58 for cmd in telnet expect; do
59         command -v "$cmd" >/dev/null 2>&1 \
60                 || echo "$NAME: WARNING: $cmd(1) not found, \"make check\" won't run all tests!"
61 done
62
63 echo "$NAME: Checking ngIRCd base source directory ..."
64 grep "ngIRCd" "$SRC_D/ChangeLog" >/dev/null 2>&1
65 if [ $? -ne 0 ]; then
66         grep "ngIRCd" "$SRC_D/../ChangeLog" >/dev/null 2>&1
67         if [ $? -ne 0 ]; then
68                 echo "$NAME: ngIRCd base source directory not found!?"
69                 exit 1
70         fi
71         SRC_D="$SRC_D/.."
72 fi
73 echo "$NAME:  - source directory: $SRC_D"
74 echo "$NAME:  - working directory: $MY_D"
75
76 echo "$NAME: Checking for GIT tree ..."
77 if [ -d "$SRC_D/.git" ]; then
78         echo "$NAME: Checking for \"git\" command ..."
79         git version >/dev/null 2>&1
80         if [ $? -eq 0 ] && [ -n "$CLEAN" ]; then
81                 echo "$NAME: Running \"git clean\" ..."
82                 cd "$SRC_D" || exit 1
83                 if [ -n "$VERBOSE" ]; then
84                         git clean -dxf
85                 else
86                         git clean -dxf >/dev/null
87                 fi
88                 cd "$MY_D" || exit 1
89         fi
90 fi
91
92 echo "$NAME: Checking for \"$SRC_D/configure\" script ..."
93 if [ ! -r "$SRC_D/configure" ]; then
94         echo "$NAME: Running \"$SRC_D/autogen.sh\" ..."
95         cd "$SRC_D" || exit 1
96         if [ -n "$VERBOSE" ]; then
97                 ./autogen.sh
98         else
99                 ./autogen.sh >/dev/null
100         fi
101         cd "$MY_D" || exit 1
102 fi
103
104 if [ -r "$SRC_D/configure" ]; then
105         echo "$NAME: Running \"$SRC_D/configure\" script ..."
106         if [ -n "$VERBOSE" ]; then
107                 "$SRC_D/configure" -C
108         else
109                 "$SRC_D/configure" -C >/dev/null
110         fi
111         if [ $? -eq 0 ] && [ -r ./Makefile ]; then
112                 R_CONFIGURE=1
113                 rm -f "src/ngircd/ngircd"
114                 echo "$NAME: Running \"$MAKE\" ..."
115                 if [ -n "$VERBOSE" ]; then
116                         "$MAKE"
117                 else
118                         "$MAKE" >/dev/null
119                 fi
120                 if [ $? -eq 0 ] && [ -x src/ngircd/ngircd ]; then
121                         R_MAKE=1
122                         echo "$NAME: Running \"$MAKE check\" ..."
123                         if [ -n "$VERBOSE" ]; then
124                                 "$MAKE" check
125                         else
126                                 "$MAKE" check >/dev/null
127                         fi
128                         if [ $? -eq 0 ]; then
129                                 R_CHECK=1
130                                 R_RUN=$R_CHECK
131                                 [ -r ./src/testsuite/tests-skipped.lst ] \
132                                         && R_CHECK_Y="y" || R_CHECK_Y="Y"
133                         else
134                                 ./src/ngircd/ngircd --help 2>/dev/null \
135                                  | grep "^ngIRCd" >/dev/null
136                                 [ $? -eq 0 ] && R_RUN=1
137                         fi
138                 fi
139         fi
140 fi
141
142 # Get target platform information
143 if [ -r "src/config.h" ]; then
144         CPU=$(grep "HOST_CPU" "src/config.h" | cut -d'"' -f2)
145         OS=$(grep "HOST_OS" "src/config.h" | cut -d'"' -f2)
146         VENDOR=$(grep "HOST_VENDOR" "src/config.h" | cut -d'"' -f2)
147         PLATFORM="$CPU/$VENDOR/$OS"
148 fi
149 if [ -z "$PLATFORM" ]; then
150         PLATFORM="$(uname 2>/dev/null) $(uname -r 2>/dev/null), $(uname -m 2>/dev/null)"
151 fi
152
153 # Get compiler information
154 if [ -r "Makefile" ]; then
155         CC=$(grep "^CC = " Makefile | cut -d' ' -f3)
156         $CC --version 2>&1 | grep -i "GCC" >/dev/null
157         if [ $? -eq 0 ]; then
158                 # GCC, or compiler that mimics GCC
159                 $CC --version 2>&1 | grep -i "Open64" >/dev/null
160                 if [ $? -eq 0 ]; then
161                         COMPILER="Open64"
162                 else
163                         COMPILER=$($CC --version | head -1 \
164                           | cut -d')' -f2 | cut -d' ' -f2)
165                         COMPILER="gcc $COMPILER"
166                 fi
167         else
168                 # Non-GCC compiler
169                 $CC --version 2>&1 | grep -i "clang" >/dev/null
170                 if [ $? -eq 0 ]; then
171                         COMPILER=$($CC --version 2>/dev/null | head -1 \
172                           | cut -d'(' -f1 | cut -d'-' -f1 \
173                           | sed -e 's/version //g' | sed -e 's/Apple /A-/g' \
174                           | sed -e 's/Debian //g' | sed -e 's/LLVM /clang /g')
175                 fi
176                 $CC -version 2>&1 | grep -i "tcc" >/dev/null
177                 if [ $? -eq 0 ]; then
178                         COMPILER=$($CC -version 2>/dev/null | head -1 \
179                           | cut -d'(' -f1 | sed -e 's/version //g')
180                 fi
181                 if [ "$COMPILER" = "unknown" ]; then
182                         v="$($CC --version 2>/dev/null | head -1)"
183                         [ -z "$v" ] && v="$($CC -version 2>/dev/null | head -1)"
184                         [ -n "$v" ] && COMPILER="$v"
185                 fi
186         fi
187 fi
188
189 # Get ngIRCd version information
190 eval "$(grep "^VERSION = " Makefile | sed -e 's/ //g')"
191 case "$VERSION" in
192         *~*-*)
193                 VERSION=$(echo "$VERSION" | cut -b1-10)
194                 ;;
195 esac
196 [ -n "$VERSION" ] || VERSION="unknown"
197
198 # Get IO interface information
199 if [ "$OS" = "linux-gnu" ]; then
200         COMMENT="1"
201 else
202         grep "^#define HAVE_SYS_DEVPOLL_H 1" src/config.h >/dev/null 2>&1
203         [ $? -eq 0 ] && COMMENT="4"
204         grep "^#define HAVE_EPOLL_CREATE 1" src/config.h >/dev/null 2>&1
205         [ $? -eq 0 ] && COMMENT="5"
206         grep "^#define HAVE_KQUEUE 1" src/config.h >/dev/null 2>&1
207         [ $? -eq 0 ] && COMMENT="3"
208 fi
209
210 [ -n "$R_CONFIGURE" ] && C="Y" || C="N"
211 [ -n "$R_MAKE" ] && M="Y" || M="N"
212 [ -n "$R_CHECK" ] && T="$R_CHECK_Y" || T="N"
213 if [ -n "$R_RUN" ]; then
214         # Mark "runs" with "Y" only when the test suite succeeded:
215         [ "$T" = "N" ] && R="?" || R="Y"
216 else
217         R="N"
218 fi
219 [ -n "$COMMENT" ] && COMMENT=" $COMMENT"
220
221 echo
222 echo "                                the executable works (\"runs\") as expected --+"
223 echo "                                  tests run successfully (\"make check\") --+ |"
224 echo "                                             ngIRCd compiles (\"make\") --+ | |"
225 echo "                                                  ./configure works --+ | | |"
226 echo "                                                                      | | | |"
227 echo "Platform                    Compiler     ngIRCd     Date     Tester   C M T R *"
228 echo "--------------------------- ------------ ---------- -------- -------- - - - - -"
229 command -v printf >/dev/null 2>&1
230 if [ $? -eq 0 ]; then
231         printf "%-27s %-12s %-10s %s %-8s %s %s %s %s%s\n" \
232          "$PLATFORM" "$COMPILER" "$VERSION" "$DATE" "$LOGNAME" \
233          "$C" "$M" "$T" "$R" "$COMMENT"
234 else
235         echo "$PLATFORM $COMPILER $VERSION $DATE $LOGNAME" \
236          "$C" "$M" "$T" "$R" "$COMMENT"
237 fi
238 echo
239
240 double_check() {
241         echo "Please double check that the ngIRCd daemon starts up, runs and handles IRC"
242         echo "connections successfully!"
243 }
244
245 if [ "$R_CHECK_Y" = "y" ]; then
246         echo "WARNING: Some tests have been skipped!"
247         double_check
248         echo
249 fi
250 if [ "$R" = "?" ]; then
251         echo "WARNING: The resulting binary passed simple tests, but the test suite failed!"
252         double_check
253         echo
254 fi