]> arthur.barton.de Git - ngircd-alex.git/blob - contrib/platformtest.sh
platformtest.sh: Use $LOGNAME instead of $USER
[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                 [ -n "$VERBOSE" ] && git clean -dxf || git clean -dxf >/dev/null
84                 cd "$MY_D" || exit 1
85         fi
86 fi
87
88 echo "$NAME: Checking for \"$SRC_D/configure\" script ..."
89 if [ ! -r "$SRC_D/configure" ]; then
90         echo "$NAME: Running \"$SRC_D/autogen.sh\" ..."
91         cd "$SRC_D" || exit 1
92         [ -n "$VERBOSE" ] && ./autogen.sh || ./autogen.sh >/dev/null
93         cd "$MY_D" || exit 1
94 fi
95
96 if [ -r "$SRC_D/configure" ]; then
97         echo "$NAME: Running \"$SRC_D/configure\" script ..."
98         [ -n "$VERBOSE" ] && "$SRC_D/configure" -C || "$SRC_D/configure" -C >/dev/null
99         if [ $? -eq 0 ] && [ -r ./Makefile ]; then
100                 R_CONFIGURE=1
101                 echo "$NAME: Running \"$MAKE\" ..."
102                 [ -n "$VERBOSE" ] && "$MAKE" || "$MAKE" >/dev/null
103                 if [ $? -eq 0 ] && [ -x src/ngircd/ngircd ]; then
104                         R_MAKE=1
105                         echo "$NAME: Running \"$MAKE check\" ..."
106                         [ -n "$VERBOSE" ] && "$MAKE" check || "$MAKE" check >/dev/null
107                         if [ $? -eq 0 ]; then
108                                 R_CHECK=1
109                                 R_RUN=$R_CHECK
110                                 [ -r ./src/testsuite/tests-skipped.lst ] \
111                                         && R_CHECK_Y="y" || R_CHECK_Y="Y"
112                         else
113                                 ./src/ngircd/ngircd --help 2>/dev/null \
114                                  | grep "^ngIRCd" >/dev/null
115                                 [ $? -eq 0 ] && R_RUN=1
116                         fi
117                 fi
118         fi
119 fi
120
121 # Get target platform information
122 if [ -r "src/config.h" ]; then
123         CPU=`grep "HOST_CPU" "src/config.h" | cut -d'"' -f2`
124         OS=`grep "HOST_OS" "src/config.h" | cut -d'"' -f2`
125         VENDOR=`grep "HOST_VENDOR" "src/config.h" | cut -d'"' -f2`
126         PLATFORM="$CPU/$VENDOR/$OS"
127 fi
128 if [ -z "$PLATFORM" ]; then
129         PLATFORM="`uname 2>/dev/null` `uname -r 2>/dev/null`, `uname -m 2>/dev/null`"
130 fi
131
132 # Get compiler information
133 if [ -r "Makefile" ]; then
134         CC=$(grep "^CC = " Makefile | cut -d' ' -f3)
135         $CC --version 2>&1 | grep -i "GCC" >/dev/null
136         if [ $? -eq 0 ]; then
137                 # GCC, or compiler that mimics GCC
138                 $CC --version 2>&1 | grep -i "Open64" >/dev/null
139                 if [ $? -eq 0 ]; then
140                         COMPILER="Open64"
141                 else
142                         COMPILER=$($CC --version | head -1 \
143                           | cut -d')' -f2 | cut -d' ' -f2)
144                         COMPILER="gcc $COMPILER"
145                 fi
146         else
147                 # Non-GCC compiler
148                 $CC --version 2>&1 | grep -i "clang" >/dev/null
149                 if [ $? -eq 0 ]; then
150                         COMPILER=$($CC --version 2>/dev/null | head -1 \
151                           | cut -d'(' -f1 | cut -d'-' -f1 \
152                           | sed -e 's/version //g' | sed -e 's/Apple /A-/g' \
153                           | sed -e 's/Debian //g' | sed -e 's/LLVM /clang /g')
154                 fi
155                 $CC -version 2>&1 | grep -i "tcc" >/dev/null
156                 if [ $? -eq 0 ]; then
157                         COMPILER=$($CC -version 2>/dev/null | head -1 \
158                           | cut -d'(' -f1 | sed -e 's/version //g')
159                 fi
160                 if [ "$COMPILER" = "unknown" ]; then
161                         v="`$CC --version 2>/dev/null | head -1`"
162                         [ -z "$v" ] && v="`$CC -version 2>/dev/null | head -1`"
163                         [ -n "$v" ] && COMPILER="$v"
164                 fi
165         fi
166 fi
167
168 # Get ngIRCd version information
169 eval "$(grep "^VERSION = " Makefile | sed -e 's/ //g')"
170 case "$VERSION" in
171         *~*-*)
172                 VERSION=`echo "$VERSION" | cut -b1-10`
173                 ;;
174 esac
175 [ -n "$VERSION" ] || VERSION="unknown"
176
177 # Get IO interface information
178 if [ "$OS" = "linux-gnu" ]; then
179         COMMENT="1"
180 else
181         grep "^#define HAVE_SYS_DEVPOLL_H 1" src/config.h >/dev/null 2>&1
182         [ $? -eq 0 ] && COMMENT="4"
183         grep "^#define HAVE_EPOLL_CREATE 1" src/config.h >/dev/null 2>&1
184         [ $? -eq 0 ] && COMMENT="5"
185         grep "^#define HAVE_KQUEUE 1" src/config.h >/dev/null 2>&1
186         [ $? -eq 0 ] && COMMENT="3"
187 fi
188
189 [ -n "$R_CONFIGURE" ] && C="Y" || C="N"
190 [ -n "$R_MAKE" ] && M="Y" || M="N"
191 [ -n "$R_CHECK" ] && T="$R_CHECK_Y" || T="N"
192 [ -n "$R_RUN" ] && R="Y" || R="N"
193 [ -n "$COMMENT" ] && COMMENT=" $COMMENT"
194
195 echo
196 echo "                                the executable works (\"runs\") as expected --+"
197 echo "                                  tests run successfully (\"make check\") --+ |"
198 echo "                                             ngIRCd compiles (\"make\") --+ | |"
199 echo "                                                  ./configure works --+ | | |"
200 echo "                                                                      | | | |"
201 echo "Platform                    Compiler     ngIRCd     Date     Tester   C M T R *"
202 echo "--------------------------- ------------ ---------- -------- -------- - - - - -"
203 command -v printf >/dev/null 2>&1
204 if [ $? -eq 0 ]; then
205         printf "%-27s %-12s %-10s %s %-8s %s %s %s %s%s\n" \
206          "$PLATFORM" "$COMPILER" "$VERSION" "$DATE" "$LOGNAME" \
207          "$C" "$M" "$T" "$R" "$COMMENT"
208 else
209         echo "$PLATFORM $COMPILER $VERSION $DATE $LOGNAME" \
210          "$C" "$M" "$T" "$R" "$COMMENT"
211 fi
212 echo
213 if [ "$R_CHECK_Y" = "y" ]; then
214         echo "$NAME: WARNING: Some tests have been skipped!"
215         echo
216 fi