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