]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
Add more penalty times
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2013 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 # Usage:
13 #   [VAR=<value>] ./autogen.sh [<configure-args>]
14 #
15 # This script generates the ./configure script using GNU automake and
16 # GNU autoconf. It tries to be smart in finding the correct/usable/available
17 # installed versions of these tools on your system.
18 #
19 # In addition, it enables or disables the "de-ANSI-fication" support of GNU
20 # automake, which is supported up to autoconf 1.11.x an has been removed
21 # in automake 1.12 -- make sure to use a version of automake supporting it
22 # when generating distribution archives!
23 #
24 # The following strategy is used for each of aclocal, autoheader, automake,
25 # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
26 # or "automake") is checked. If this fails, "tool<major><minor>" (for example
27 # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
28 # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
29 # <minor> is tried from 99 to 0. The first occurrence will be used.
30 #
31 # When you pass <configure-args> to autogen.sh it will call the generated
32 # ./configure script on success and pass these parameters to it.
33 #
34 # You can tweak the behaviour using these environment variables:
35 #
36 # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
37 #   Name and optionally path to the particular tool.
38 # - PREFIX=<path>
39 #   Search the GNU autoconf and GNU automake tools in <path> first. If the
40 #   generated ./configure script will be called, pass "--prefix=<path>" to it.
41 # - EXIST=<tool>
42 #   Use <tool> to test for aclocal, autoheader etc. pp. ...
43 #   When not specified, either "type" or "which" is used.
44 # - VERBOSE=1
45 #   Output the detected names of the GNU automake and GNU autoconf tools.
46 # - GO=1
47 #   Call ./configure even if no arguments have been passed to autogen.sh.
48 #
49 # Examples:
50 #
51 # - ./autogen.sh
52 #   Generates the ./configure script.
53 # - GO=1 ./autogen.sh
54 #   Generates the ./configure script and runs it as "./configure".
55 # - VERBOSE=1 ./autogen.sh --with-ident
56 #   Show tool names, generates the ./configure script, and runs it with
57 #   these arguments: "./configure --with-ident".
58 # - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
59 #   Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
60 #   and runs it with these arguments: "./configure --prefix=$HOME".
61 #
62
63 Search()
64 {
65         [ $# -eq 2 ] || exit 1
66
67         searchlist="$1"
68         major="$2"
69         minor=99
70
71         [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
72
73         for name in $searchlist; do
74                 $EXIST "${name}" >/dev/null 2>&1
75                 if [ $? -eq 0 ]; then
76                         "${name}" --version 2>&1 \
77                          | grep -v "environment variable" >/dev/null 2>&1
78                         if [ $? -eq 0 ]; then
79                                 echo "${name}"
80                                 return 0
81                         fi
82                 fi
83         done
84
85         while [ $minor -ge 0 ]; do
86                 for name in $searchlist; do
87                         $EXIST "${name}${major}${minor}" >/dev/null 2>&1
88                         if [ $? -eq 0 ]; then
89                                 echo "${name}${major}${minor}"
90                                 return 0
91                         fi
92                         $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
93                         if [ $? -eq 0 ]; then
94                                 echo "${name}-${major}.${minor}"
95                                 return 0
96                         fi
97                 done
98                 minor=`expr $minor - 1`
99         done
100         return 1
101 }
102
103 Notfound()
104 {
105         echo "Error: $* not found!"
106         echo "Please install recent versions of GNU autoconf and GNU automake."
107         exit 1
108 }
109
110 Run()
111 {
112         [ "$VERBOSE" = "1" ] && echo " - running \"$@\" ..."
113         $@
114 }
115
116 # Reset locale settings to suppress warning messages of Perl
117 unset LC_ALL
118 unset LANG
119
120 # Which command should be used to detect the automake/autoconf tools?
121 [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
122 EXIST=""
123 for t in $existlist; do
124         $t /bin/ls >/dev/null 2>&1
125         if [ $? -eq 0 ]; then
126                 rm -f /tmp/test.$$
127                 $t /tmp/test.$$ >/dev/null 2>&1
128                 [ $? -ne 0 ] && EXIST="$t"
129         fi
130         [ -n "$EXIST" ] && break
131 done
132 if [ -z "$EXIST" ]; then
133         echo "Didn't detect a working command to test for the autoconf/automake tools!"
134         echo "Searchlist: $existlist"
135         exit 1
136 fi
137 [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
138
139 # Try to detect the needed tools when no environment variable already
140 # specifies one:
141 echo "Searching for required tools ..."
142 [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
143 [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
144 [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
145 [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
146 [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
147 [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
148 [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
149 [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
150
151 AUTOCONF_VERSION=`echo $AUTOCONF | cut -d'-' -f2-`
152 [ -n "$AUTOCONF_VERSION" -a "$AUTOCONF_VERSION" != "autoconf" ] \
153         && export AUTOCONF_VERSION || unset AUTOCONF_VERSION
154 [ "$VERBOSE" = "1" ] && echo " - AUTOCONF_VERSION=$AUTOCONF_VERSION"
155 AUTOMAKE_VERSION=`echo $AUTOMAKE | cut -d'-' -f2-`
156 [ -n "$AUTOMAKE_VERSION" -a "$AUTOMAKE_VERSION" != "automake" ] \
157         && export AUTOMAKE_VERSION || unset AUTOMAKE_VERSION
158 [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE_VERSION=$AUTOMAKE_VERSION"
159
160 [ $# -gt 0 ] && CONFIGURE_ARGS=" $@" || CONFIGURE_ARGS=""
161 [ -z "$GO" -a -n "$CONFIGURE_ARGS" ] && GO=1
162
163 # Verify that all tools have been found
164 [ -z "$ACLOCAL" ] && Notfound aclocal
165 [ -z "$AUTOHEADER" ] && Notfound autoheader
166 [ -z "$AUTOMAKE" ] && Notfound automake
167 [ -z "$AUTOCONF" ] && Notfound autoconf
168
169 AM_VERSION=`$AUTOMAKE --version | head -n 1 | sed -e 's/.* //g'`
170 ifs=$IFS; IFS="."; set $AM_VERSION; IFS=$ifs
171 AM_MAJOR="$1"; AM_MINOR="$2"; AM_PATCHLEVEL="$3"
172 echo "Detected automake $AM_VERSION ..."
173
174 AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
175
176 # De-ANSI-fication?
177 if [ "$AM_MAJOR" -eq "1" -a "$AM_MINOR" -lt "12" ]; then
178         # automake < 1.12 => automatic de-ANSI-fication support available
179         echo " - Enabling de-ANSI-fication support."
180         sed -e "s|^__ng_PROTOTYPES__|AM_C_PROTOTYPES|g" configure.ng >configure.ac
181         DEANSI_START=""
182         DEANSI_END=""
183 else
184         # automake >= 1.12 => no de-ANSI-fication support available
185         echo " - Disabling de-ANSI-fication support."
186         sed -e "s|^__ng_PROTOTYPES__|AC_C_PROTOTYPES|g" configure.ng >configure.ac
187         DEANSI_START="#"
188         DEANSI_END=" (disabled by ./autogen.sh script)"
189 fi
190 # Serial test harness?
191 if [ "$AM_MAJOR" -eq "1" -a "$AM_MINOR" -ge "13" ]; then
192         # automake >= 1.13 => enforce "serial test harness"
193         echo " - Enforcing serial test harness."
194         SERIAL_TESTS="serial-tests"
195 else
196         # automake < 1.13 => no new test harness, nothing to do
197         SERIAL_TEST=""
198 fi
199
200 sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}ansi2knr${DEANSI_END}|g" \
201         src/portab/Makefile.ng >src/portab/Makefile.am
202 for makefile_ng in $AM_MAKEFILES; do
203         makefile_am=`echo "$makefile_ng" | sed -e "s|\.ng\$|\.am|g"`
204         sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}../portab/ansi2knr${DEANSI_END}|g" \
205                 $makefile_ng >$makefile_am
206 done
207
208 export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
209
210 # Generate files
211 echo "Generating files using \"$AUTOCONF\" and \"$AUTOMAKE\" ..."
212 Run $ACLOCAL && \
213         Run $AUTOCONF && \
214         Run $AUTOHEADER && \
215         Run $AUTOMAKE --add-missing --no-force
216
217 if [ $? -eq 0 -a -x ./configure ]; then
218         # Success: if we got some parameters we call ./configure and pass
219         # all of them to it.
220         NAME=`grep PACKAGE_STRING= configure | cut -d"'" -f2`
221         if [ "$GO" = "1" ]; then
222                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
223                 c="./configure${p}${CONFIGURE_ARGS}"
224                 echo "Okay, autogen.sh for $NAME done."
225                 echo "Calling \"$c\" ..."
226                 $c
227                 exit $?
228         else
229                 echo "Okay, autogen.sh for $NAME done."
230                 echo "Now run the \"./configure\" script."
231                 exit 0
232         fi
233 else
234         # Failure!?
235         echo "Error! Check your installation of GNU automake and autoconf!"
236         exit 1
237 fi
238
239 # -eof-