]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
Update NEWS and ChangeLog files
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2008 Alexander Barton <alex@barton.de>
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 # The following strategy is used for each of aclocal, autoheader, automake,
20 # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
21 # or "automake") is checked. If this fails, "tool<major><minor>" (for example
22 # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
23 # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
24 # <minor> is tried from 99 to 0. The first occurrence will be used.
25 #
26 # When you pass <configure-args> to autogen.sh it will call the generated
27 # ./configure script on success and pass these parameters to it.
28 #
29 # You can tweak the behaviour using these environment variables:
30 #
31 # - ACLOCAL=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
32 #   Name and optionally path to the particular tool.
33 # - PREFIX=<path>
34 #   Search the GNU autoconf and GNU automake tools in <path> first. If the
35 #   generated ./configure script will be called, pass "--prefix=<path>" to it.
36 # - EXIST=<tool>
37 #   Use <tool> to test for aclocal, autoheader etc. pp. ...
38 #   When not specified, either "type" or "which" is used.
39 # - VERBOSE=1
40 #   Output the detected names of the GNU automake and GNU autoconf tools.
41 # - GO=1
42 #   Call ./configure even if no arguments have been passed to autogen.sh.
43 #
44 # Examples:
45 #
46 # - ./autogen.sh
47 #   Generates the ./configure script.
48 # - GO=1 ./autogen.sh
49 #   Generates the ./configure script and runs it as "./configure".
50 # - VERBOSE=1 ./autogen.sh --with-ident
51 #   Show tool names, generates the ./configure script, and runs it with
52 #   these arguments: "./configure --with-ident".
53 # - ACLOCAL=aclocal-1.6 GO=1 PREFIX=$HOME ./autogen.sh
54 #   Uses "aclocal-1.6" as aclocal tool, generates the ./configure script,
55 #   and runs it with these arguments: "./configure --prefix=$HOME".
56 #
57
58 Search()
59 {
60         [ $# -eq 2 ] || exit 1
61
62         searchlist="$1"
63         major="$2"
64         minor=99
65
66         [ -n "$PREFIX" ] && searchlist="${PREFIX}/$1 ${PREFIX}/bin/$1 $searchlist"
67
68         for name in $searchlist; do
69                 $EXIST "${name}" >/dev/null 2>&1
70                 if [ $? -eq 0 ]; then
71                         echo "${name}"
72                         return 0
73                 fi
74         done
75
76         while [ $minor -ge 0 ]; do
77                 for name in $searchlist; do
78                         $EXIST "${name}${major}${minor}" >/dev/null 2>&1
79                         if [ $? -eq 0 ]; then
80                                 echo "${name}${major}${minor}"
81                                 return 0
82                         fi
83                         $EXIST "${name}-${major}.${minor}" >/dev/null 2>&1
84                         if [ $? -eq 0 ]; then
85                                 echo "${name}-${major}.${minor}"
86                                 return 0
87                         fi
88                 done
89                 minor=`expr $minor - 1`
90         done
91         return 1
92 }
93
94 Notfound()
95 {
96         echo "Error: $* not found!"
97         echo "Please install recent versions of GNU autoconf and GNU automake."
98         exit 1
99 }
100
101 # Reset locale settings to suppress warning messages of Perl
102 unset LC_ALL
103 unset LANG
104
105 # Which command should be used to detect the automake/autoconf tools?
106 [ -z "$EXIST" ] && existlist="type which" || existlist="$EXIST"
107 EXIST=""
108 for t in $existlist; do
109         $t /bin/ls >/dev/null 2>&1
110         if [ $? -eq 0 ]; then
111                 rm -f /tmp/test.$$
112                 $t /tmp/test.$$ >/dev/null 2>&1
113                 [ $? -ne 0 ] && EXIST="$t"
114         fi
115         [ -n "$EXIST" ] && break
116 done
117 if [ -z "$EXIST" ]; then
118         echo "Didn't detect a working command to test for the autoconf/automake tools!"
119         echo "Searchlist: $existlist"
120         exit 1
121 fi
122 [ "$VERBOSE" = "1" ] && echo "Using \"$EXIST\" to test for tools."
123
124 # Try to detect the needed tools when no environment variable already
125 # specifies one:
126 echo "Searching tools ..."
127 [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
128 [ "$VERBOSE" = "1" ] && echo "ACLOCAL=$ACLOCAL"
129 [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
130 [ "$VERBOSE" = "1" ] && echo "AUTOHEADER=$AUTOHEADER"
131 [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
132 [ "$VERBOSE" = "1" ] && echo "AUTOMAKE=$AUTOMAKE"
133 [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
134 [ "$VERBOSE" = "1" ] && echo "AUTOCONF=$AUTOCONF"
135
136 # Call ./configure when parameters have been passed to this script and
137 # GO isn't already defined.
138 [ -z "$GO" -a $# -gt 0 ] && GO=1
139
140 # Verify that all tools have been found
141 [ -z "$ACLOCAL" ] && Notfound aclocal
142 [ -z "$AUTOHEADER" ] && Notfound autoheader
143 [ -z "$AUTOMAKE" ] && Notfound automake
144 [ -z "$AUTOCONF" ] && Notfound autoconf
145
146 export ACLOCAL AUTOHEADER AUTOMAKE AUTOCONF
147
148 # Generate files
149 echo "Generating files ..."
150 $ACLOCAL && \
151         $AUTOHEADER && \
152         $AUTOMAKE --add-missing && \
153         $AUTOCONF --force
154
155 if [ $? -eq 0 -a -x ./configure ]; then
156         # Success: if we got some parameters we call ./configure and pass
157         # all of them to it.
158         NAME=`grep PACKAGE_STRING= configure | cut -d"'" -f2`
159         if [ "$GO" = "1" ]; then
160                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
161                 [ -n "$*" ] && a=" $*" || a=""
162                 c="./configure${p}${a}"
163                 echo "Okay, autogen.sh for $NAME done."
164                 echo "Calling \"$c\" ..."
165                 $c
166                 exit $?
167         else
168                 echo "Okay, autogen.sh for $NAME done."
169                 echo "Now run the \"./configure\" script."
170                 exit 0
171         fi
172 else
173         # Failure!?
174         echo "Error! Check your installation of GNU automake and autoconf!"
175         exit 1
176 fi
177
178 # -eof-