]> arthur.barton.de Git - ngircd-alex.git/blob - autogen.sh
Enhanced autogen.sh script; added "inline" documentation.
[ngircd-alex.git] / autogen.sh
1 #!/bin/sh
2 #
3 # ngIRCd -- The Next Generation IRC Daemon
4 # Copyright (c)2001-2004 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 # $Id: autogen.sh,v 1.10 2004/03/15 20:32:31 alex Exp $
13 #
14
15 #
16 # Usage: [VAR=<value>] ./autogen.sh [<configure-args>]
17 #
18 # This script generates the ./configure script using GNU automake and
19 # GNU autoconf. It tries to be smart in finding the correct/usable/available
20 # installed versions of these tools on your system.
21 #
22 # The following strategy is used for each of aclocal, autoheader, automake,
23 # and autoconf: first, "tool" (the regular name of the tool, e. g. "autoconf"
24 # or "automake") is checked. If this fails, "tool<major><minor>" (for example
25 # "automake16") and "tool-<major>.<minor>" (e. g. "autoconf-2.54") are tried
26 # with <major> being 2 for tool of GNU autoconf and 1 for tools of automake;
27 # <minor> is tried from 99 to 0. The first occurrence will be used.
28 #
29 # When you pass <configure-args> to autogen.sh it will call the generated
30 # ./configure script on success and pass these parameters to it.
31 #
32 # You can tweak the behaviour using these environment variables:
33 #
34 # - ALICA=<cmd>, AUTOHEADER=<cmd>, AUTOMAKE=<cmd>, AUTOCONF=<cmd>
35 #   Name and optionally path to the particular tool.
36 # - PREFIX=<path>
37 #   Search the GNU autoconf and GNU automake tools in <path> first. If the
38 #   generated ./configure script will be called, pass "--prefix=<path>" to it.
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                 type "${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                         type "${name}${major}${minor}" >/dev/null 2>&1
79                         if [ $? -eq 0 ]; then
80                                 echo "${name}${major}${minor}"
81                                 return 0
82                         fi
83                         type "${name}-${major}.${minor}" >/dev/null 2>&1
84                         if [ $? -eq 0 ]; then
85                                 echo "${name}-${major}.${minor}" >/dev/null 2>&1
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 # We want to use GNU automake 1.7, if available (WANT_AUTOMAKE is used by
106 # the wrapper scripts of Gentoo Linux):
107 WANT_AUTOMAKE=1.7
108 export WANT_AUTOMAKE
109
110 # Try to detect the needed tools when no environment variable already
111 # spezifies one:
112 echo "Searching tools ..."
113 [ -z "$ACLOCAL" ] && ACLOCAL=`Search aclocal 1`
114 [ -z "$AUTOHEADER" ] && AUTOHEADER=`Search autoheader 2`
115 [ -z "$AUTOMAKE" ] && AUTOMAKE=`Search automake 1`
116 [ -z "$AUTOCONF" ] && AUTOCONF=`Search autoconf 2`
117
118 # Some debugging output ...
119 if [ -n "$VERBOSE" ]; then
120         echo "ACLOCAL=$ACLOCAL"
121         echo "AUTOHEADER=$AUTOHEADER"
122         echo "AUTOMAKE=$AUTOMAKE"
123         echo "AUTOCONF=$AUTOCONF"
124 fi
125
126 # Verify that all tools have been found
127 [ -z "$AUTOCONF" ] && Notfounf autoconf
128 [ -z "$AUTOHEADER" ] && Notfound autoheader
129 [ -z "$AUTOMAKE" ] && Notfound automake
130 [ -z "$AUTOCONF" ] && Notfound autoconf
131
132 export AUTOCONF AUTOHEADER AUTOMAKE AUTOCONF
133
134 # Generate files
135 echo "Generating files ..."
136 $ACLOCAL && \
137         $AUTOHEADER && \
138         $AUTOMAKE --add-missing && \
139         $AUTOCONF
140
141 if [ $? -eq 0 -a -x ./configure ]; then
142         # Success: if we got some parameters we call ./configure and pass
143         # all of them to it.
144         if [ -n "$*" -o -n "$GO" ]; then
145                 [ -n "$PREFIX" ] && p=" --prefix=$PREFIX" || p=""
146                 [ -n "$*" ] && a=" $*" || a=""
147                 c="./configure${p}${a}"
148                 echo "Calling \"$c\" ..."
149                 $c
150                 exit $?
151         else
152                 echo "Okay, autogen.sh done; now run the \"configure\" script."
153                 exit 0
154         fi
155 else
156         # Failure!?
157         echo "Error! Check your installation of GNU automake and autoconf!"
158         exit 1
159 fi
160
161 # -eof-