platformtest.sh: New option "-x", don't renegerate build system
[ngircd-alex.git] / contrib / platformtest.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2014 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_RUN=
31
32 [ -n "$MAKE" ] || MAKE="make"
33 export MAKE CC
34
35 while [ $# -gt 0 ]; do
36         case "$1" in
37                 "-v")
38                         VERBOSE=1
39                         ;;
40                 "-x")
41                         CLEAN=
42                         ;;
43                 *)
44                         echo "Usage: $NAME [-v] [-x]"
45                         echo
46                         echo "  -v   Verbose output"
47                         echo "  -x   Don't regenerate build system, even when possible"
48                         echo
49                         exit 2
50         esac
51         shift
52 done
53
54 echo "$NAME: Checking ngIRCd base source directory ..."
55 grep "ngIRCd" ./ChangeLog >/dev/null 2>&1
56 if [ $? -ne 0 ]; then
57         grep "ngIRCd" ../ChangeLog >/dev/null 2>&1
58         if [ $? -ne 0 ]; then
59                 echo "$NAME: ngIRCd base source directory not found!?"
60                 exit 1
61         fi
62         cd ..
63 fi
64
65 echo "$NAME: Checking for GIT tree ..."
66 if [ -d .git ]; then
67         echo "$NAME: Checking for \"git\" command ..."
68         git version >/dev/null 2>&1
69         if [ $? -eq 0 -a -n "$CLEAN" ]; then
70                 echo "$NAME: Running \"git clean\" ..."
71                 [ -n "$VERBOSE" ] && git clean -dxf || git clean -dxf >/dev/null
72         fi
73 fi
74
75 echo "$NAME: Checking for \"./configure\" script ..."
76 if [ ! -r ./configure ]; then
77         echo "$NAME: Running \"./autogen.sh\" ..."
78         [ -n "$VERBOSE" ] && ./autogen.sh || ./autogen.sh >/dev/null
79 fi
80
81 if [ -r ./configure ]; then
82         echo "$NAME: Running \"./configure\" script ..."
83         [ -n "$VERBOSE" ] && ./configure || ./configure >/dev/null
84         if [ $? -eq 0 -a -r ./Makefile ]; then
85                 R_CONFIGURE=1
86                 echo "$NAME: Running \"$MAKE\" ..."
87                 [ -n "$VERBOSE" ] && "$MAKE" || "$MAKE" >/dev/null
88                 if [ $? -eq 0 -a -x src/ngircd/ngircd ]; then
89                         R_MAKE=1
90                         echo "$NAME: Running \"$MAKE check\" ..."
91                         [ -n "$VERBOSE" ] && "$MAKE" check || "$MAKE" check >/dev/null
92                         if [ $? -eq 0 ]; then
93                                 R_CHECK=1
94                                 R_RUN=$R_CHECK
95                         else
96                                 ./src/ngircd/ngircd --help 2>/dev/null \
97                                  | grep "^ngIRCd" >/dev/null
98                                 [ $? -eq 0 ] && R_RUN=1
99                         fi
100                 fi
101         fi
102 fi
103
104 # Get target platform information
105 if [ -r "src/config.h" ]; then
106         CPU=`grep "HOST_CPU" "src/config.h" | cut -d'"' -f2`
107         OS=`grep "HOST_OS" "src/config.h" | cut -d'"' -f2`
108         VENDOR=`grep "HOST_VENDOR" "src/config.h" | cut -d'"' -f2`
109         PLATFORM="$CPU/$VENDOR/$OS"
110 fi
111 if [ -z "$PLATFORM" ]; then
112         PLATFORM="`uname 2>/dev/null` `uname -r 2>/dev/null`, `uname -m 2>/dev/null`"
113 fi
114
115 # Get compiler information
116 if [ -r "Makefile" ]; then
117         CC=$(grep "^CC = " Makefile | cut -d' ' -f3)
118         $CC --version 2>&1 | grep -i "GCC" >/dev/null
119         if [ $? -eq 0 ]; then
120                 # GCC, or compiler that mimics GCC
121                 $CC --version 2>&1 | grep -i "Open64" >/dev/null
122                 if [ $? -eq 0 ]; then
123                         COMPILER="Open64"
124                 else
125                         COMPILER=$($CC --version | head -1 \
126                           | cut -d')' -f2 | cut -d' ' -f2)
127                         COMPILER="gcc $COMPILER"
128                 fi
129         else
130                 # Non-GCC compiler
131                 $CC --version 2>&1 | grep -i "clang" >/dev/null
132                 if [ $? -eq 0 ]; then
133                         COMPILER=$($CC --version 2>/dev/null | head -1 \
134                           | cut -d'(' -f1 | cut -d'-' -f1 \
135                           | sed -e 's/version //g' | sed -e 's/Apple /A-/g' \
136                           | sed -e 's/Debian //g' | sed -e 's/LLVM /clang /g')
137                 fi
138                 $CC -version 2>&1 | grep -i "tcc" >/dev/null
139                 if [ $? -eq 0 ]; then
140                         COMPILER=$($CC -version 2>/dev/null | head -1 \
141                           | cut -d'(' -f1 | sed -e 's/version //g')
142                 fi
143                 if [ "$COMPILER" = "unknown" ]; then
144                         v="`$CC --version 2>/dev/null | head -1`"
145                         [ -z "$v" ] && v="`$CC -version 2>/dev/null | head -1`"
146                         [ -n "$v" ] && COMPILER="$v"
147                 fi
148         fi
149 fi
150
151 # Get ngIRCd version information
152 eval $(grep "^VERSION = " Makefile | sed -e 's/ //g')
153 case "$VERSION" in
154         *-*-*)
155                 VERSION=`echo "$VERSION" | cut -d'-' -f3 | cut -b2-`
156                 ;;
157 esac
158 [ -n "$VERSION" ] || VERSION="unknown"
159
160 # Get IO interface information
161 if [ "$OS" = "linux-gnu" ]; then
162         COMMENT="1"
163 else
164         grep "^#define HAVE_SYS_DEVPOLL_H 1" src/config.h >/dev/null 2>&1
165         [ $? -eq 0 ] && COMMENT="4"
166         grep "^#define HAVE_EPOLL_CREATE 1" src/config.h >/dev/null 2>&1
167         [ $? -eq 0 ] && COMMENT="5"
168         grep "^#define HAVE_KQUEUE 1" src/config.h >/dev/null 2>&1
169         [ $? -eq 0 ] && COMMENT="3"
170 fi
171
172 [ -n "$R_CONFIGURE" ] && C="Y" || C="N"
173 [ -n "$R_MAKE" ] && M="Y" || M="N"
174 [ -n "$R_CHECK" ] && T="Y" || T="N"
175 [ -n "$R_RUN" ] && R="Y" || R="N"
176 [ -n "$COMMENT" ] && COMMENT=" $COMMENT"
177
178 echo
179 echo "                                the executable works (\"runs\") as expected --+"
180 echo "                                  tests run successfully (\"make check\") --+ |"
181 echo "                                             ngIRCd compiles (\"make\") --+ | |"
182 echo "                                                  ./configure works --+ | | |"
183 echo "                                                                      | | | |"
184 echo "Platform                    Compiler     ngIRCd     Date     Tester   C M T R *"
185 echo "--------------------------- ------------ ---------- -------- -------- - - - - -"
186 type printf >/dev/null 2>&1
187 if [ $? -eq 0 ]; then
188         printf "%-27s %-12s %-10s %s %-8s %s %s %s %s%s" \
189          "$PLATFORM" "$COMPILER" "$VERSION" "$DATE" "$USER" \
190          "$C" "$M" "$T" "$R" "$COMMENT"
191 else
192         echo "$PLATFORM $COMPILER $VERSION $DATE $USER" \
193          "$C" "$M" "$T" "$R" "$COMMENT"
194 fi
195 echo; echo