1#! /bin/sh
2# libtoolize - Prepare a package to use libtool.
3# @configure_input@
4# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005
5# Free Software Foundation, Inc.
6# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful, but
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21#
22# As a special exception to the GNU General Public License, if you
23# distribute this file as part of a program that contains a
24# configuration script generated by Autoconf, you may include it under
25# the same distribution terms that you use for the rest of that program.
26
27# The name of this program.
28progname=`echo "$0" | sed 's%^.*/%%'`
29
30# Constants.
31PROGRAM=libtoolize
32PACKAGE=@PACKAGE@
33VERSION=@VERSION@
34
35# Directory names.
36prefix=@prefix@
37datarootdir=@datarootdir@
38datadir=@datadir@
39pkgdatadir=@pkgdatadir@
40aclocaldir=@aclocaldir@
41
42libtool_m4="$aclocaldir/libtool.m4"
43ltdl_m4="$aclocaldir/ltdl.m4"
44
45dry_run=no
46help="Try \`$progname --help' for more information."
47rm="rm -f"
48ln_s="@LN_S@"
49cp="cp -f -p"
50mkdir="mkdir"
51tar="tar"
52
53# Global variables.
54automake=
55copy=
56force=
57ltdl=
58ltdl_tar=
59configure_ac=
60status=0
61
62for arg
63do
64  case "$arg" in
65  --help)
66    cat <<EOF
67Usage: $progname [OPTION]...
68
69Prepare a package to use libtool.
70
71    --automake        work silently, and assume that Automake is in use
72-c, --copy            copy files rather than symlinking them
73    --debug           enable verbose shell tracing
74-n, --dry-run         print commands rather than running them
75-f, --force           replace existing files
76    --help            display this message and exit
77    --ltdl            install libltdl in a subdirectory
78    --ltdl-tar        install the libltdl tarball
79    --version         print version information and exit
80
81You must \`cd' to the top directory of your package before you run
82\`$progname'.
83
84Report bugs to <bug-libtool@gnu.org>.
85EOF
86    exit $?
87    ;;
88
89  --version)
90    echo "$PROGRAM (GNU $PACKAGE) $VERSION"
91    echo
92    echo "Copyright (C) 2005 Free Software Foundation, Inc."
93    echo "This is free software; see the source for copying conditions.  There is NO"
94    echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
95    exit $?
96    ;;
97
98  --automake)
99    automake=yes
100    ;;
101
102  -c | --copy)
103    ln_s=
104    ;;
105
106  --debug)
107    echo "$progname: enabling shell trace mode"
108    set -x
109    ;;
110
111  -n | --dry-run)
112    if test "$dry_run" != yes; then
113      dry_run=yes
114      rm="echo $rm"
115      test -n "$ln_s" && ln_s="echo $ln_s"
116      cp="echo $cp"
117      mkdir="echo mkdir"
118      tar="echo $tar"
119    fi
120    ;;
121
122  -f | --force)
123    force=yes
124    ;;
125
126  --ltdl)
127    ltdl=yes
128    ;;
129
130  --ltdl-tar)
131    ltdl_tar=yes
132    ;;
133
134  -*)
135    echo "$progname: unrecognized option \`$arg'" 1>&2
136    echo "$help" 1>&2
137    exit 1
138    ;;
139
140  *)
141    echo "$progname: too many arguments" 1>&2
142    echo "$help" 1>&2
143    exit 1
144    ;;
145  esac
146done
147
148if test -f configure.ac; then
149  configure_ac=configure.ac
150elif test -f configure.in; then
151  configure_ac=configure.in
152else
153  echo "$progname: \`configure.ac' does not exist" 1>&2
154  echo "$help" 1>&2
155  exit 1
156fi
157
158
159files=`cd $pkgdatadir && ls`
160if test -z "$files"; then
161  echo "$progname: cannot list files in \`$pkgdatadir'" 1>&2
162  exit 1
163fi
164files='config.guess config.sub ltmain.sh'
165
166auxdir=.
167auxdirline=`grep '^AC_CONFIG_AUX_DIR' $configure_ac 2>/dev/null`
168if test -n "$auxdirline"; then
169  # Handle explicit AC_CONFIG_AUX_DIR settings.
170  auxdir=`echo "$auxdirline" | sed 's/^AC_CONFIG_AUX_DIR(\([^)]*\)).*$/\1/'`
171
172  if test "$auxdir" = "$auxdirline"; then
173    echo "$progname: invalid AC_CONFIG_AUX_DIR syntax: $auxdirline" 1>&2
174    exit 1
175  else
176    # Strip any quote brackets.
177    auxdir=`echo "$auxdir" | sed 's/^\[\(.*\)\]$/\1/g'`
178    case "$auxdir" in
179    *\$*)
180      echo "$progname: cannot handle variables in AC_CONFIG_AUX_DIR" 1>&2
181      exit 1
182      ;;
183    *)
184    ;;
185    esac
186  fi
187else
188  # Try to discover auxdir the same way it is discovered by configure.
189  # Note that we default to the current directory.
190  for dir in . .. ../..; do
191    if test -f $dir/install-sh; then
192      auxdir=$dir
193      break
194    elif test -f $dir/install.sh; then
195      auxdir=$dir
196      break
197    fi
198  done
199fi
200
201if test -z "$automake"; then
202  if grep '^A[MC]_PROG_LIBTOOL' $configure_ac >/dev/null 2>&1; then :
203  else
204    echo "Remember to add \`AC_PROG_LIBTOOL' to \`$configure_ac'."
205  fi
206
207  if grep '^AC_PROG_RANLIB' $configure_ac >/dev/null 2>&1; then
208    echo "Using \`AC_PROG_RANLIB' is rendered obsolete by \`AC_PROG_LIBTOOL'"
209  fi
210
211  if grep 'generated automatically by aclocal' aclocal.m4 >/dev/null 2>&1; then
212    updatemsg="update your \`aclocal.m4' by running aclocal"
213  else
214    updatemsg="add the contents of \`$libtool_m4' to \`aclocal.m4'"
215  fi
216
217  if grep '^AC_DEFUN(\[A[MC]_PROG_LIBTOOL' aclocal.m4 >/dev/null 2>&1; then
218    # Check the version number on libtool.m4 and the one used in aclocal.m4.
219    instserial=`grep '^# serial ' $libtool_m4 | grep 'A[MC]_PROG_LIBTOOL' | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`
220
221    if test -z "$instserial"; then
222      echo "$progname: warning: no serial number on \`$libtool_m4'" 1>&2
223    else
224      # If the local macro has no serial number, we assume it's ancient.
225      localserial=`grep '^# serial ' aclocal.m4 | grep 'A[MC]_PROG_LIBTOOL' | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`
226
227      test -z "$localserial" && localserial=0
228
229      if test "$localserial" -lt "$instserial"; then
230	echo "You should $updatemsg."
231      elif test "$localserial" -gt "$instserial"; then
232	echo "$progname: \`$libtool_m4' is serial $instserial, less than $localserial in \`aclocal.m4'" 1>&2
233	if test -z "$force"; then
234	  echo "Use \`--force' to replace newer libtool files with this version." 1>&2
235	  exit 1
236	fi
237	echo "To remain compatible, you should $updatemsg."
238      fi
239    fi
240  else
241    echo "You should $updatemsg."
242  fi
243
244  if grep '^AC_LIB_LTDL' $configure_ac >/dev/null 2>&1; then
245    if grep 'generated automatically by aclocal' aclocal.m4 >/dev/null 2>&1; then
246      updatemsg="update your \`aclocal.m4' by running aclocal"
247    else
248      updatemsg="add the contents of \`$ltdl_m4' to \`aclocal.m4'"
249    fi
250
251    if grep '^AC_DEFUN(AC_LIB_LTDL' aclocal.m4 >/dev/null 2>&1; then
252      # Check the version number on ltdl.m4 and the one used in aclocal.m4.
253      instserial=`grep '^# serial ' $ltdl_m4 | grep 'AC_LIB_LTDL' | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`
254
255      if test -z "$instserial"; then
256	echo "$progname: warning: no serial number on \`$ltdl_m4'" 1>&2
257      else
258	# If the local macro has no serial number, we assume it's ancient.
259	localserial=`grep '^# serial ' aclocal.m4 | grep 'AC_LIB_LTDL' | sed -e 's/^# serial \([0-9][0-9]*\).*$/\1/; q'`
260
261	test -z "$localserial" && localserial=0
262
263	if test "$localserial" -lt "$instserial"; then
264	  echo "You should $updatemsg."
265	elif test "$localserial" -gt "$instserial"; then
266	  echo "$progname: \`$ltld_m4' is serial $instserial, less than $localserial in \`aclocal.m4'" 1>&2
267	  if test -z "$force"; then
268	    echo "Use \`--force' to replace newer libtool files with this version." 1>&2
269	    exit 1
270	  fi
271	  echo "To remain compatible, you should $updatemsg."
272	fi
273      fi
274    else
275      echo "You should $updatemsg."
276    fi
277  fi
278fi
279
280
281if test "x$ltdl" = xyes; then
282  test -d libltdl || $mkdir libltdl
283  ltdlfiles=`cd $pkgdatadir && ls libltdl/*`
284else
285  ltdlfiles=
286fi
287
288for file in $ltdlfiles; do
289  if test -f "$file" && test -z "$force"; then
290    test -z "$automake" && echo "$progname: \`$file' exists: use \`--force' to overwrite" 1>&2
291    continue
292  fi
293
294  $rm $file
295  if test -n "$ln_s" && $ln_s $pkgdatadir/$file $file; then :
296  elif { ( cd $pkgdatadir 2>/dev/null && $tar chf - $file 2> /dev/null; ) \
297      | ( umask 0 && $tar xf - > /dev/null 2>&1; ); } ; then :
298  elif $cp $pkgdatadir/$file $file; then :
299  else
300    echo "$progname: cannot copy \`$pkgdatadir/$file' to \`$file'" 1>&2
301    status=1
302  fi
303done
304
305if test "x$ltdl_tar" = x"yes"; then
306  if test "x$dry_run" = x"yes"; then
307    echo "tar -cf - libltdl | gzip --best > libltdl.tar.gz"
308  elif test -f libltdl.tar.gz && test -z "$force"; then
309    test -z "$automake" && echo "$progname: \`libltdl.tar.gz' exists: use \`--force' to overwrite" 1>&2
310  else
311    test -d libltdl && ${rm}r libltdl
312    $mkdir libltdl
313    ltdlfiles=`cd $pkgdatadir && ls libltdl/*`
314    for file in $ltdlfiles; do
315      if { ( cd $pkgdatadir 2>/dev/null && $tar chf - $file 2> /dev/null; ) \
316          | ( umask 0 && $tar xf - > /dev/null 2>&1; ); } ; then :
317      elif $cp $pkgdatadir/$file $file; then :
318      else
319	echo "$progname: cannot copy \`$pkgdatadir/$file' to \`$file'" 1>&2
320	status=1
321	break
322      fi
323    done
324    for file in $files; do
325      if { ( cd $pkgdatadir 2>/dev/null && $tar chf - $file 2> /dev/null; ) \
326          | ( umask 0 && cd libltdl 2>/dev/null && $tar xf - > /dev/null 2>&1; ); } ; then :
327      elif $cp $pkgdatadir/$file libltdl/$file; then :
328      else
329	echo "$progname: cannot copy \`$pkgdatadir/$file' to \`libltdl/$file'" 1>&2
330	status=1
331	break
332      fi
333    done
334    tar -cf - libltdl | gzip --best > libltdl.tar.gz
335    ${rm}r libltdl
336  fi
337fi
338
339# Change to the auxiliary directory.
340if test "$auxdir" != .; then
341  test -z "$automake" && echo "Putting files in AC_CONFIG_AUX_DIR, \`$auxdir'."
342  test "x$dry_run" = x"yes" && echo "cd $auxdir"
343  cd $auxdir || exit 1
344fi
345
346for file in $files; do
347  if test -f "$file" && test -z "$force"; then
348    test -z "$automake" && echo "$progname: \`$file' exists: use \`--force' to overwrite" 1>&2
349    continue
350  fi
351
352  $rm $file
353  if test -n "$ln_s" && $ln_s $pkgdatadir/$file $file; then :
354  elif { ( cd $pkgdatadir 2>/dev/null && $tar chf - $file 2> /dev/null; ) \
355      | ( umask 0 && $tar xf - > /dev/null 2>&1; ); } ; then :
356  elif $cp $pkgdatadir/$file $file; then :
357  else
358    echo "$progname: cannot copy \`$pkgdatadir/$file' to \`$file'" 1>&2
359    status=1
360  fi
361done
362
363exit $status
364
365# Local Variables:
366# mode:shell-script
367# sh-indentation:2
368# End:
369