3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2024 Alexander Barton (alex@barton.de) and Contributors
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.
13 # [VAR=<value>] ./autogen.sh [<configure-args>]
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.
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!
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.
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.
34 # You can tweak the behaviour using these environment variables:
36 # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
37 # Name and optionally path to the particular tool.
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.
42 # Use <tool> to test for aclocal, autoheader etc. pp. ...
43 # When not specified, either "type" or "which" is used.
45 # Output the detected names of the GNU automake and GNU autoconf tools.
47 # Call ./configure even if no arguments have been passed to autogen.sh.
52 # Generates the ./configure script.
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".
69 for name in $searchlist; do
70 $EXIST "${name}${major}${minor}" >/dev/null 2>&1
72 echo "${name}${major}${minor}"
75 $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
77 echo "${name}-${major}.${minor}"
86 [ $# -lt 2 ] && return 1
87 [ $# -gt 3 ] && return 1
94 [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
96 if [ -n "$minor_pref" ]; then
97 Check_Tool "$searchlist" "$major" "$minor_pref" && return 0
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
112 while [ $minor -ge 0 ]; do
113 Check_Tool "$searchlist" "$major" "$minor" && return 0
114 minor=$(expr $minor - 1)
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.'
129 [ "$VERBOSE" = "1" ] && echo " - running \"$*\" ..."
133 # Reset locale settings to suppress warning messages of Perl
137 # Which command should be used to detect the automake/autoconf tools?
138 [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
140 for t in $existlist; do
141 $t /bin/ls >/dev/null 2>&1
142 if [ $? -eq 0 ]; then
144 $t /tmp/test.$$ >/dev/null 2>&1
145 [ $? -ne 0 ] && EXIST="$t"
147 [ -n "$EXIST" ] && break
149 if [ -z "$EXIST" ]; then
150 echo "Didn't detect a working command to test for the autoconf/automake tools!"
151 echo "Searchlist: $existlist"
154 [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
156 # Try to detect the needed tools when no environment variable already
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"
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"
177 [ $# -gt 0 ] && CONFIGURE_ARGS=" $*" || CONFIGURE_ARGS=""
178 [ -z "$GO" ] && [ -n "$CONFIGURE_ARGS" ] && GO=1
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
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 ..."
192 AM_MAKEFILES="src/ipaddr/Makefile.ng src/ngircd/Makefile.ng src/testsuite/Makefile.ng src/tool/Makefile.ng"
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
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
206 DEANSI_END=" (disabled by ./autogen.sh script)"
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"
214 # automake < 1.13 => no new test harness, nothing to do
215 # shellcheck disable=SC2034
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
227 export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
230 echo "Generating files using \"$AUTOCONF\" and \"$AUTOMAKE\" ..."
234 Run $AUTOMAKE --add-missing --no-force
236 if [ $? -eq 0 ] && [ -x ./configure ]; then
237 # Success: if we got some parameters we call ./configure and pass
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\" ..."
248 echo "Okay, autogen.sh for $NAME done."
249 echo "Now run the \"./configure\" script."
254 echo "Error! Check your installation of GNU automake and autoconf!"