]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
ngIRCd Release 27
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2024 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 Check_Tool()
64 {
65         searchlist="$1"
66         major="$2"
67         minor="$3"
68
69         for name in $searchlist; do
70                 $EXIST "${name}${major}${minor}" >/dev/null 2>&1
71                 if [ $? -eq 0 ]; then
72                         echo "${name}${major}${minor}"
73                         return 0
74                 fi
75                 $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
76                 if [ $? -eq 0 ]; then
77                         echo "${name}-${major}.${minor}"
78                         return 0
79                 fi
80         done
81         return 1
82 }
83
84 Search()
85 {
86         [ $# -lt 2 ] && return 1
87         [ $# -gt 3 ] && return 1
88
89         searchlist="$1"
90         major="$2"
91         minor_pref="$3"
92         minor=99
93
94         [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
95
96         if [ -n "$minor_pref" ]; then
97                 Check_Tool "$searchlist" "$major" "$minor_pref" && return 0
98         fi
99
100         for name in $searchlist; do
101                 $EXIST "${name}" >/dev/null 2>&1
102                 if [ $? -eq 0 ]; then
103                         "${name}" --version 2>&1 \
104                          | grep -v "environment variable" >/dev/null 2>&1
105                         if [ $? -eq 0 ]; then
106                                 echo "${name}"
107                                 return 0
108                         fi
109                 fi
110         done
111
112         while [ $minor -ge 0 ]; do
113                 Check_Tool "$searchlist" "$major" "$minor" && return 0
114                 minor=$(expr $minor - 1)
115         done
116         return 1
117 }
118
119 Notfound()
120 {
121         echo "Error: $* not found!"
122         echo 'Please install supported versions of GNU autoconf, GNU automake'
123         echo 'and pkg-config: see the INSTALL file for details.'
124         exit 1
125 }
126
127 Run()
128 {
129         [ "$VERBOSE" = "1" ] && echo " - running \"$*\" ..."
130         "$@"
131 }
132
133 # Reset locale settings to suppress warning messages of Perl
134 unset LC_ALL
135 unset LANG
136
137 # Which command should be used to detect the automake/autoconf tools?
138 [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
139 EXIST=""
140 for t in $existlist; do
141         $t /bin/ls >/dev/null 2>&1
142         if [ $? -eq 0 ]; then
143                 rm -f /tmp/test.$$
144                 $t /tmp/test.$$ >/dev/null 2>&1
145                 [ $? -ne 0 ] && EXIST="$t"
146         fi
147         [ -n "$EXIST" ] && break
148 done
149 if [ -z "$EXIST" ]; then
150         echo "Didn't detect a working command to test for the autoconf/automake tools!"
151         echo "Searchlist: $existlist"
152         exit 1
153 fi
154 [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
155
156 # Try to detect the needed tools when no environment variable already
157 # specifies one:
158 echo "Searching for required tools ..."
159 [ -z "$ACLOCAL" ] && ACLOCAL=$(Search aclocal 1 11)
160 [ "$VERBOSE" = "1" ] && echo " - ACLOCAL=$ACLOCAL"
161 [ -z "$AUTOHEADER" ] && AUTOHEADER=$(Search autoheader 2)
162 [ "$VERBOSE" = "1" ] && echo " - AUTOHEADER=$AUTOHEADER"
163 [ -z "$AUTOMAKE" ] && AUTOMAKE=$(Search automake 1 11)
164 [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE=$AUTOMAKE"
165 [ -z "$AUTOCONF" ] && AUTOCONF=$(Search autoconf 2)
166 [ "$VERBOSE" = "1" ] && echo " - AUTOCONF=$AUTOCONF"
167
168 AUTOCONF_VERSION=$(echo "$AUTOCONF" | cut -d'-' -f2-)
169 [ -n "$AUTOCONF_VERSION" ] && [ "$AUTOCONF_VERSION" != "autoconf" ] \
170         && export AUTOCONF_VERSION || unset AUTOCONF_VERSION
171 [ "$VERBOSE" = "1" ] && echo " - AUTOCONF_VERSION=$AUTOCONF_VERSION"
172 AUTOMAKE_VERSION=$(echo $AUTOMAKE | cut -d'-' -f2-)
173 [ -n "$AUTOMAKE_VERSION" ] && [ "$AUTOMAKE_VERSION" != "automake" ] \
174         && export AUTOMAKE_VERSION || unset AUTOMAKE_VERSION
175 [ "$VERBOSE" = "1" ] && echo " - AUTOMAKE_VERSION=$AUTOMAKE_VERSION"
176
177 [ $# -gt 0 ] && CONFIGURE_ARGS=" $*" || CONFIGURE_ARGS=""
178 [ -z "$GO" ] && [ -n "$CONFIGURE_ARGS" ] && GO=1
179
180 # Verify that all tools have been found
181 command -v pkg-config >/dev/null || Notfound pkg-config
182 [ -z "$ACLOCAL" ] && Notfound aclocal
183 [ -z "$AUTOHEADER" ] && Notfound autoheader
184 [ -z "$AUTOMAKE" ] && Notfound automake
185 [ -z "$AUTOCONF" ] && Notfound autoconf
186
187 AM_VERSION=$($AUTOMAKE --version | head -n 1 | sed -e 's/.* //g')
188 ifs=$IFS; IFS="."; set $AM_VERSION; IFS=$ifs
189 AM_MAJOR="$1"; AM_MINOR="$2"
190 echo "Detected automake $AM_VERSION ..."
191
192 AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
193
194 # De-ANSI-fication?
195 if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -lt "12" ]; then
196         # automake < 1.12 => automatic de-ANSI-fication support available
197         echo " - Enabling de-ANSI-fication support."
198         sed -e "s|^__ng_PROTOTYPES__|AM_C_PROTOTYPES|g" configure.ng >configure.ac
199         DEANSI_START=""
200         DEANSI_END=""
201 else
202         # automake >= 1.12 => no de-ANSI-fication support available
203         echo " - Disabling de-ANSI-fication support."
204         sed -e "s|^__ng_PROTOTYPES__|AC_C_PROTOTYPES|g" configure.ng >configure.ac
205         DEANSI_START="#"
206         DEANSI_END=" (disabled by ./autogen.sh script)"
207 fi
208 # Serial test harness?
209 if [ "$AM_MAJOR" -eq "1" ] && [ "$AM_MINOR" -ge "13" ]; then
210         # automake >= 1.13 => enforce "serial test harness"
211         echo " - Enforcing serial test harness."
212         SERIAL_TESTS="serial-tests"
213 else
214         # automake < 1.13 => no new test harness, nothing to do
215         # shellcheck disable=SC2034
216         SERIAL_TEST=""
217 fi
218
219 sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}ansi2knr${DEANSI_END}|g" \
220         src/portab/Makefile.ng >src/portab/Makefile.am
221 for makefile_ng in $AM_MAKEFILES; do
222         makefile_am=$(echo "$makefile_ng" | sed -e "s|\.ng\$|\.am|g")
223         sed -e "s|^__ng_Makefile_am_template__|AUTOMAKE_OPTIONS = ${SERIAL_TESTS} ${DEANSI_START}../portab/ansi2knr${DEANSI_END}|g" \
224                 $makefile_ng >$makefile_am
225 done
226
227 export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
228
229 # Generate files
230 echo "Generating files using \"$AUTOCONF\" and \"$AUTOMAKE\" ..."
231 Run $ACLOCAL && \
232         Run $AUTOCONF && \
233         Run $AUTOHEADER && \
234         Run $AUTOMAKE --add-missing --no-force
235
236 if [ $? -eq 0 ] && [ -x ./configure ]; then
237         # Success: if we got some parameters we call ./configure and pass
238         # all of them to it.
239         NAME=$(grep PACKAGE_STRING= configure | cut -d"'" -f2)
240         if [ "$GO" = "1" ]; then
241                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
242                 c="./configure${p}${CONFIGURE_ARGS}"
243                 echo "Okay, autogen.sh for $NAME done."
244                 echo "Calling \"$c\" ..."
245                 $c
246                 exit $?
247         else
248                 echo "Okay, autogen.sh for $NAME done."
249                 echo "Now run the \"./configure\" script."
250                 exit 0
251         fi
252 else
253         # Failure!?
254         echo "Error! Check your installation of GNU automake and autoconf!"
255         exit 1
256 fi
257
258 # -eof-