Blame


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