1#!/bin/sh
2
3# Using this script should be identical to the resulto of "autoreconf -fi".
4# Some code taken from the gnome macros/autogen.sh scripts.
5
6# $Id$
7
8
9###############################################################################
10# utility functions
11###############################################################################
12
13# Not all echo versions allow -n, so we check what is possible. This test is
14# based on the one in autoconf.
15ECHO_C=
16ECHO_N=
17case `echo -n x` in
18-n*)
19  case `echo 'x\c'` in
20  *c*) ;;
21  *)   ECHO_C='\c';;
22  esac;;
23*)
24  ECHO_N='-n';;
25esac
26
27# some terminal codes ...
28boldface="`tput bold 2>/dev/null`"
29normal="`tput sgr0 2>/dev/null`"
30
31printbold() {
32  echo $ECHO_N "$boldface" $ECHO_C
33  echo "$@"
34  echo $ECHO_N "$normal" $ECHO_C
35}
36
37printerr() {
38  echo "$@" >&2
39}
40
41# Usage:
42#     compare_versions MIN_VERSION ACTUAL_VERSION
43# returns true if ACTUAL_VERSION >= MIN_VERSION
44compare_versions() {
45  ch_min_version=$1
46  ch_actual_version=$2
47  ch_status=0
48  IFS="${IFS=         }"; ch_save_IFS="$IFS"; IFS="."
49  set $ch_actual_version
50  for ch_min in $ch_min_version; do
51    ch_cur=`echo $1 | sed 's/[^0-9].*$//'`; shift # remove letter suffixes
52    if [ -z "$ch_min" ]; then break; fi
53    if [ -z "$ch_cur" ]; then ch_status=1; break; fi
54    if [ $ch_cur -gt $ch_min ]; then break; fi
55    if [ $ch_cur -lt $ch_min ]; then ch_status=1; break; fi
56  done
57  IFS="$ch_save_IFS"
58  return $ch_status
59}
60
61# Usage:
62#     version_check PACKAGE VARIABLE CHECKPROGS MIN_VERSION
63# checks to see if the package is available
64version_check() {
65  vc_package=$1
66  vc_variable=$2
67  vc_checkprogs=$3
68  vc_min_version=$4
69  vc_status=1
70
71  vc_checkprog=`eval echo "\\$$vc_variable"`
72  if [ -n "$vc_checkprog" ]; then
73	  printbold "Using $vc_checkprog for $vc_package"
74  	return 0
75  fi
76
77  vc_comparator=">="
78
79  printbold "Checking for $vc_package $vc_comparator $vc_min_version..."
80
81  for vc_checkprog in $vc_checkprogs; do
82	  echo $ECHO_N "  testing $vc_checkprog... " $ECHO_C
83    	if $vc_checkprog --version < /dev/null > /dev/null 2>&1; then
84	      vc_actual_version=`$vc_checkprog --version | head -n 1 | \
85                            sed 's/^[^0-9]*\([0-9.]*\).*$/\1/'`
86	      if compare_versions $vc_min_version $vc_actual_version; then
87		      echo "found $vc_actual_version"
88		      # set variables
89      		eval "$vc_variable=$vc_checkprog; \
90			          ${vc_variable}_VERSION=$vc_actual_version"
91       		vc_status=0
92      		break
93	      else
94    	  	echo "too old (found version $vc_actual_version)"
95	      fi
96    	else
97	      echo "not found."
98     	fi
99  done
100
101  if [ "$vc_status" != 0 ]; then
102	  printerr "***Error***: $vc_package $vc_comparator $vc_min_version not found."
103  fi
104
105  return $vc_status
106}
107
108###############################################################################
109# main section
110###############################################################################
111
112configure_ac="configure.ac"
113
114(test -f $configure_ac && test -f src/torrent.cpp) || {
115  printerr "***Error***: Run this script from the top-level source directory."
116  exit 1
117}
118
119echo
120printbold "Bootstrapping autotools for libtorrent-rasterbar"
121echo
122
123REQUIRED_AUTOCONF_VERSION=`cat $configure_ac | grep '^AC_PREREQ' |
124sed -n -e 's/AC_PREREQ(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
125
126REQUIRED_AUTOMAKE_VERSION=`cat configure.ac | grep '^AM_INIT_AUTOMAKE' |
127sed -n -e 's/AM_INIT_AUTOMAKE(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 's/\(.*\) .*/\1/' | sed -e 1q`
128
129REQUIRED_LIBTOOL_VERSION=`cat $configure_ac | grep '^LT_PREREQ' |
130sed -n -e 's/LT_PREREQ(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
131
132printbold "Checking autotools requirements:"
133echo
134
135version_check autoconf AUTOCONF 'autoconf autoconf2.59 autoconf-2.53 autoconf2.50' $REQUIRED_AUTOCONF_VERSION || exit 1
136AUTOHEADER=`echo $AUTOCONF | sed s/autoconf/autoheader/`
137
138version_check automake AUTOMAKE "automake automake-1.11 automake-1.10" $REQUIRED_AUTOMAKE_VERSION || exit 1
139ACLOCAL=`echo $AUTOMAKE | sed s/automake/aclocal/`
140
141version_check libtool LIBTOOLIZE "libtoolize glibtoolize" $REQUIRED_LIBTOOL_VERSION || exit 1
142
143##########################################
144# Copy config.rpath to build dir
145##########################################
146build_dir=`cat $configure_ac | grep '^AC_CONFIG_AUX_DIR' |
147sed -n -e 's/AC_CONFIG_AUX_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
148
149if [ -n "$build_dir" ]; then
150  mkdir -p $build_dir
151fi
152config_rpath=m4/config.rpath
153echo "Copying $config_rpath to $build_dir"
154cp $config_rpath "$build_dir/"
155
156##########################################
157
158echo
159printbold "Processing $configure_ac"
160echo
161
162if grep "^A[CM]_PROG_LIBTOOL" $configure_ac >/dev/null ||
163    grep "^LT_INIT" $configure_ac >/dev/null; then
164  printbold "Running $LIBTOOLIZE..."
165  $LIBTOOLIZE --force --copy || exit 1
166fi
167
168m4dir=`cat $configure_ac | grep '^AC_CONFIG_MACRO_DIR' |
169sed -n -e 's/AC_CONFIG_MACRO_DIR(\([^()]*\))/\1/p' | sed -e 's/^\[\(.*\)\]$/\1/' | sed -e 1q`
170if [ -n "$m4dir" ]; then
171  m4dir="-I $m4dir"
172fi
173printbold "Running $ACLOCAL..."
174$ACLOCAL $m4dir || exit 1
175
176printbold "Running $AUTOCONF..."
177$AUTOCONF || exit 1
178if grep "^A[CM]_CONFIG_HEADER" $configure_ac >/dev/null; then
179  printbold "Running $AUTOHEADER..."
180	$AUTOHEADER || exit 1
181  # this prevents automake from thinking config.h.in is out of
182  # date, since autoheader doesn't touch the file if it doesn't
183  # change.
184  test -f config.h.in && touch config.h.in
185fi
186
187printbold "Running $AUTOMAKE..."
188$AUTOMAKE --gnu --add-missing --force --copy || exit 1
189
190echo
191printbold "Bootstrap complete, now run \`configure'."
192