2 # libtoolize (GNU @PACKAGE@@TIMESTAMP@) @VERSION@
3 # Written by Gary V. Vaughan <gary@gnu.org>
5 # Copyright (C) 2003, 2004 Free Software Foundation, Inc.
6 # This is free software; see the source for copying conditions. There is NO
7 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, a copy can be downloaded from
21 # http://www.gnu.org/copyleft/gpl.html, or by writing to the Free
22 # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 # As a special exception to the GNU General Public License, if you
26 # distribute this file as part of a program that contains a
27 # configuration script generated by Autoconf, you may include it under
28 # the same distribution terms that you use for the rest of that program.
30 # Usage: $progname [OPTION]...
32 # Prepare a package to use libtool.
34 # -c, --copy copy files rather than symlinking them
35 # --debug enable verbose shell tracing
36 # -n, --dry-run print commands rather than running them
37 # -f, --force replace existing files
38 # --help display this message and exit
39 # -i, --install copy missing auxiliary files
40 # --ltdl install libltdl in a subdirectory
41 # --ltdl-tar install the libltdl tarball
42 # -q, --quiet work silently
43 # -v, --verbose verbosely report processing
44 # --version print version information and exit
46 # You must `cd' to the top directory of your package before you run
49 # Report bugs to <bug-libtool@gnu.org>.
56 # The name of this program:
57 progname
=`echo "$0" | sed 's%^.*/%%'`
75 # Locations for important files:
78 pkgdatadir
=@pkgdatadir@
79 pkgmacrodir
="$pkgdatadir/m4"
82 configure_ac
=configure.
in
84 sed_dirname
='s,/[^/]*$,,'
87 # Echo program name prefixed message.
90 echo $progname: ${1+"$@"}
94 # Echo program name prefixed message in verbose mode only.
97 $verbose_opt && func_echo
${1+"$@"}
101 # Echo program name prefixed message to standard error.
104 echo $progname: ${1+"$@"} 1>&2
107 # func_fatal_error arg...
108 # Echo program name prefixed message to standard error, and exit.
115 # func_fatal_help arg...
116 # Echo program name prefixed message to standard error, followed by
117 # a help hint, and exit.
121 func_fatal_error
"Try \`$progname --help' for more information."
125 # Parse options once, thoroughly. This comes as soon as possible in
126 # the script to make things like `libtoolize --version' happen quickly.
129 my_sed_single_opt
='1s/^\(..\).*$/\1/;q'
130 my_sed_single_rest
='1s/^..\(.*\)$/\1/;q'
131 my_sed_help
='/^# Usage:/,/# Report bugs to/ {
133 s/\$progname/'$progname'/;
136 my_sed_version
='/^# '$PROGRAM' (GNU /,/# warranty; / {
138 s/\((C)\)[ 0-9,-]*\( [1-9][0-9]*\)/\1\2/;
143 while test "$#" -gt 0; do
145 --copy |
-c) shift; link_opt
=false
;;
148 func_echo
"enabling shell trace mode"
152 --dry-run |
-n) shift
153 if $dry_run_opt; then :; else
156 test -n "$LN_S" && LN_S
="echo $LN_S"
162 --force |
-f) shift; force_opt
=: ;;
163 --install |
-i) shift; install_opt
=: ;;
164 --ltdl) shift; ltdl_opt
=: ;;
165 --ltdl-tar) shift; ltdl_tar_opt
=: ;;
166 --quiet |
--automake |
-q) # --automake is for 1.5 compatibility
167 shift; quiet_opt
=: ;;
168 --verbose |
-v) shift; verbose_opt
=: ;;
170 -c*|
-i*|
-f*|
-n*|
-q*|
-v*)
171 opt
=`echo "$1" |sed "$my_sed_single_opt"`
172 rest
=`echo "$1" |sed "$my_sed_single_rest"`
174 set -- "$opt" "-$rest" ${1+"$@"}
177 --version) sed "$my_sed_version" < $0; exit 0 ;;
178 --help) sed "$my_sed_help" < $0; exit 0 ;;
180 -*) func_fatal_help
"unrecognized option \`$1'" ;;
181 *) func_fatal_help
"too many arguments" ;;
187 # Make sure the entire path to DIR is available.
193 while test ! -d "$my_dir"; do
194 my_dirs
="$my_dir $my_dirs"
195 case $my_dir in */*) ;; *) break ;; esac
196 my_dir
=`echo "$my_dir" | sed "$sed_dirname"`
198 test ! -n "$my_dirs" ||
$MKDIR $my_dirs
201 # func_copy srcfile destfile
202 # If option `--copy' was specified, or soft-linking SRCFILE to DESTFILE fails,
203 # then try to copy SRCFILE to DESTFILE.
210 func_mkdir_p
`echo "$my_destfile" | sed "$sed_dirname"`
213 if $link_opt && $LN_S "$my_srcfile" "$my_destfile"; then
214 $quiet_opt || func_echo
"copying file \`$my_destfile'"
216 elif $CP "$my_srcfile" "$my_destfile"; then
217 $quiet_opt || func_echo
"copying file \`$my_destfile'"
220 func_error
"can not copy \`$my_srcfile' to \`$my_destfile'"
224 return $my_return_status
227 # func_copy_all_files srcdir destdir [glob_exclude] [copy_cb=func_copy]
228 # For each file in SRCDIR, then try to copy the file to DESTDIR by calling
229 # COPY_CB with the src and dest files. If GLOB_EXCLUDE is given, exclude
230 # any matching filenames from the copy. If COPY_CB is passed, then the
231 # check for overwriting without force_opt is the callbacks responsibility:
232 # This allows using callbacks like func_serial_update, which perform their
233 # own checks to decide whether to overwrite the dest file.
234 func_copy_all_files
()
239 my_copy_cb
=${4-func_copy}
241 for my_filename
in `cd "$my_srcdir" && ls`; do
243 # ignore excluded filenames
244 if test -n "$my_glob_exclude"; then
245 eval 'case $my_filename in '$my_glob_exclude') continue ;; esac'
248 if test -f "$my_srcdir/$my_filename"; then
249 if test "X$my_copy_cb" = Xfunc_copy
; then
250 $force_opt ||
if test -f "$my_destdir/$my_filename"; then
252 || func_error
"\`$my_destdir/$my_filename' exists: use \`--force' to overwrite"
261 $my_copy_cb "$my_srcdir/$my_filename" "$my_destdir/$my_filename"
265 # func_grep expression filename
266 # Check whether EXPRESSION matches any line of FILENAME, without output.
269 grep "$1" "$2" >/dev
/null
2>&1
273 # Scan configure.(ac|in) and aclocal.m4 (if present) for use of libltdl
274 # and libtool. Possibly running some of these tools if necessary.
275 # Libtoolize affects the contents of aclocal.m4, and should be run before
276 # aclocal, so we can't use configure --trace which relies on a consistent
277 # configure.(ac|in) and aclocal.m4.
280 # Prefer configure.ac to configure.in
281 test -f configure.ac
&& configure_ac
=configure.ac
282 test -f "$configure_ac" \
283 || func_fatal_help
"\`$configure_ac' does not exist"
285 test -n "`cd $pkgdatadir && ls`" \
286 || func_fatal_error
"can not list files in \`$pkgdatadir'"
289 # Set local variables to reflect contents of configure.ac
290 my_uses_autoconf
=false
291 my_sed_scan_configure_ac
='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
292 /AC_INIT/ { s,^.*$,my_uses_autoconf=:,; p; };
294 eval `sed "$my_sed_scan_configure_ac" "$configure_ac"`
296 $my_uses_autoconf ||
{
297 func_verbose
"$configure_ac: not using Autoconf"
301 # ---------------------------------------------------- #
302 # Probe macro usage in configure.ac and/or aclocal.m4. #
303 # ---------------------------------------------------- #
305 my_sed_traces
='s,#.*$,,; s,^dnl .*$,,; s, dnl .*$,,;
306 /AC_CONFIG_AUX_DIR[^_]/ {
307 s,^.*AC_CONFIG_AUX_DIR([[ ]*\([^])]*\).*$,auxdir=\1,; p;
309 /AC_CONFIG_MACRO_DIR/ {
310 s,^.*AC_CONFIG_MACRO_DIR([[ ]*\([^])]*\).*$,m4dir=\1,; p;
312 /A[CM]_PROG_LIBTOOL/ { s,^.*$,seen_libtool=:,; p; };
313 /AC_LIB_LTDL/ { s,^.*$,seen_ltdl=:,; p; };
315 eval `cat aclocal.m4 "$configure_ac" | sed "$my_sed_traces" 2>/dev/null`
322 if test -n "$auxdir"; then
323 # If $configure_ac contains AC_CONFIG_AUX_DIR, check that it was
324 # not given in terms of a shell variable!
327 func_fatal_error
"can not handle variables in AC_CONFIG_AUX_DIR"
332 # Try to discover auxdir the same way it is discovered by configure.
333 # Note that we default to the current directory.
334 for dir
in . .. ..
/..
; do
335 if test -f "$dir/install-sh"; then
338 elif test -f "$dir/install.sh"; then
345 # Just use the current directory if all else fails.
346 test -n "$auxdir" || auxdir
=.
349 # ------------------------------ #
350 # Find local m4 macro directory. #
351 # ------------------------------ #
353 # If AC_CONFIG_MACRO_DIR turned nothing up, we hunt for ACLOCAL_AMFLAGS
354 # in `Makefile.am' for a `-I' argument.
356 my_sed_aclocal_flags
='/^[ ]*ACLOCAL_[A-Z_]*FLAGS[ ]*=/ {
357 s,^[^=]*=[ ]*\(.*\), \1,; q; }; d'
358 if test ! -n "$m4dir" && test -f Makefile.am
; then
359 my_m4dir_is_next
=false
360 for arg
in `sed "$my_sed_aclocal_flags" Makefile.am`; do
361 if $my_m4dir_is_next; then
365 if test "X$arg" = "X-I"; then
368 my_m4dir_is_next
=false
374 # Just use the current directory if all else fails.
375 test -n "$m4dir" || m4dir
=.
378 # func_included_files searchfile
379 # Output INCLUDEFILE if SEARCHFILE m4_includes it, else output SEARCHFILE.
380 func_included_files
()
386 /^m4_include(\[.*\])$/ { s,^m4_include(\[\(.*\)\])$,\1,; p; };
389 test -f "$my_searchfile" && echo "$my_searchfile"
391 # Only recurse when we don't care if all the variables we use get
392 # trashed, since they are in global scope.
393 for my_filename
in `sed "$my_sed_include" "$my_searchfile"`; do
394 func_included_files
$my_filename
398 # func_serial filename [macro_regex]
399 # Output the value of the serial number comment in FILENAME, where the
400 # comment line must also match MACRO_REGEX, if given.
405 my_sed_serial
='/^# serial [1-9][0-9]*[ ]*'"$my_macro_regex"'[ ]*$/ {
406 s,^# serial \([1-9][0-9]*\).*$,\1,; q;
409 # Search FILENAME and all the files it m4_includes for a serial number
410 # in the file that AC_DEFUNs MACRO_REGEX.
412 for my_file
in `func_included_files "$my_filename"`; do
413 if func_grep
'^AC_DEFUN(\['"$my_macro_regex" "$my_file"; then
414 my_serial
=`sed -e "$my_sed_serial" "$my_file"`
419 # If the file has no serial number, we assume it's ancient.
420 test -n "$my_serial" || my_serial
=0
425 # func_serial_update srcfile destfile [macro_regex]
426 # Copy SRCFILE to DESTFILE provided SRCFILE has a newer serial number, or
427 # DESTFILE does not yet exist, or the user specified `--force'. If given,
428 # MACRO_REGEX must match any text after "# serial N" in the both files.
429 func_serial_update
()
438 if test -f "$my_destfile"; then
439 my_src_serial
=`func_serial "$my_srcfile" "$my_macro_regex"`
440 my_dest_serial
=`func_serial "$my_destfile" "$my_macro_regex"`
442 test "$my_src_serial" -eq 0 && {
443 func_error
"warning: no serial number on \`$my_srcfile', not copying."
447 # Only perform the file update if the destination has an older serial.
448 test "$my_src_serial" -gt "$my_dest_serial" || my_update_p
=false
450 test "$my_src_serial" -gt "$my_dest_serial" \
451 && func_verbose
"\`$my_srcfile' is serial $my_srcserial, greater than $my_destserial in \`$my_destfile'"
453 if test "$my_src_serial" -lt "$my_dest_serial"; then
454 func_error
"\`$my_srcfile' is serial $my_srcserial, less than $my_destserial in \`$my_destfile'"
456 || func_fatal_error
"Use \`--force' to replace newer libtool files with this version."
460 if $my_update_p ||
$force_opt; then
461 func_copy
"$my_srcfile" "$my_destfile"
465 || func_echo
"\`$my_destfile' is already up to date."
468 # Do this after the copy for hand maintained `aclocal.m4', incase
469 # it has `m4_include([DESTFILE])', so the copy effectively already
470 # updated `aclocal.m4'.
471 $use_aclocal ||
if test -f aclocal.
m4; then
472 test "$my_src_serial" -gt `func_serial aclocal.m4 "$my_macro_regex"` \
473 && func_echo
"You should add the contents of \'$my_destfile' to \`aclocal.m4'."
476 return $my_return_status
480 # Sanity check macros from aclocal.m4 against installed versions.
483 # Don't trace for this, we're just checking the user didn't invoke it
484 # directly from configure.ac.
485 sed 's,dnl .*$,,; s,# .*$,,' "$configure_ac" |
grep AC_PROG_RANLIB \
486 && func_echo
"\`AC_PROG_RANLIB' is rendered obsolete by \`AC_PROG_LIBTOOL'"
489 || func_echo
"Remember to add \`AC_PROG_LIBTOOL' to \`$configure_ac'."
491 # FIXME: Ensure ltmain.sh, libtool.m4 and ltdl.m4 are from the same release
494 # func_ltmain_update srcfile destfile
495 # Copy SRCFILE to DESTFILE provided SRCFILE has a newer VERSION/TIMESTAMP,
496 # or DESTFILE does not yet exist, or the user specified `--force'.
497 func_ltmain_update
()
502 s,^VERSION=[^0-9]*\(.*\)[ ]*$,\1,; t
503 s,^TIMESTAMP=[^0-9]*\([.0-9]*\) .*$,\1,; t
506 if test -f "$my_srcfile"; then :
508 func_error
"\`$my_srcfile' does not exist."
512 # FIXME: check versions, and only downgrade with --force
513 cmp -s "$my_srcfile" "$my_destfile"
514 if test "$?" -ne 0 ||
$force_opt; then
515 func_copy
"$my_srcfile" "$my_destfile"
518 || func_echo
"\`$my_destfile' is already up to date."
522 # func_config_update srcfile destfile
523 # Copy SRCFILE to DESTFILE provided SRCFILE has a newer TIMESTAMP,
524 # or DESTFILE does not yet exist, or the user specified `--force'.
525 func_config_update
()
529 my_sed_config
='s,^timestamp=[^0-9]*\([.0-9-]*\)[^0-9].*$,\1,; t; d'
531 if test -f "$my_srcfile"; then :
533 func_error
"\`$my_srcfile' does not exist."
537 # FIXME: check versions, and only downgrade with --force
538 cmp -s "$my_srcfile" "$my_destfile"
539 if test "$?" -ne 0 ||
$force_opt; then
540 func_copy
"$my_srcfile" "$my_destfile"
543 || func_echo
"\`$my_destfile' is already up to date."
556 re_pkgaux_files
='config\.guess|config\.sub|ltmain\.sh'
557 re_pkgmacro_files
='libtool\.m4|ltdl\.m4'
560 $quiet_opt || func_check_macros
562 # Copy all the files from installed libltdl to this project, if the
563 # user specified `--with-ltdl'.
564 $ltdl_opt && eval func_copy_all_files
"$pkgdatadir/libltdl" libltdl
566 # Copy all the files from installed libltdl to a tarball in this project,
567 # if the user specified `--with-ltdl-tar'.
569 if test -f libltdl.
tar.gz
; then
571 test -d libltdl
&& ${RM}r libltdl
572 func_copy_all_files
"$pkgdatadir/libltdl" libltdl
573 tar -chof - libltdl |
gzip --best > libltdl.
tar.gz
576 func_error
"\`libltdl.tar.gz' exists: use \`--force' to overwrite"
581 # Copy all the installed utility files to the auxiliary directory if
582 # `--install' was passed, or else copy just ltmain.sh.
583 $quiet_opt ||
if test "$auxdir" != .
; then
584 func_echo
"putting files in AC_CONFIG_AUX_DIR, \`$auxdir'."
586 if $install_opt ||
$force_opt; then
587 func_copy_all_files
"$pkgdatadir" "$auxdir" "$re_pkgaux_files"
588 func_config_update
"$pkgdatadir/config.guess" "$auxdir/config.guess"
589 test -f "$pkgdatadir/config.sub" \
590 && func_config_update
"$pkgdatadir/config.sub" "$auxdir/config.sub"
592 func_ltmain_update
"$pkgdatadir/ltmain.sh" "$auxdir/ltmain.sh"
594 # Copy libtool's m4 macros to the macro directory, if they are newer.
595 $quiet_opt ||
if test "$m4dir" != .
; then
596 func_echo
"putting macros in AC_CONFIG_MACRO_DIR, \`$m4dir'."
599 libtool_m4
="$pkgmacrodir/libtool.m4"
600 ltdl_m4
="$pkgmacrodir/ltdl.m4"
602 func_copy_all_files
"$pkgmacrodir" "$m4dir" \
603 "$re_pkgmacro_files" func_serial_update
604 func_serial_update
"$libtool_m4" "$m4dir/libtool.m4" 'A[CM]_PROG_LIBTOOL'
607 func_serial_update
"$ltdl_m4" "$m4dir/ltdl.m4" 'AC_LIB_LTDL'
609 func_verbose
"Not copying \`$ltdl_m4', AC_LIB_LTDL not used."