3 # Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2, or (at your option)
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # This program is meant for authors or maintainers which want to import
21 # modules from gnulib into their packages.
25 cvsdatestamp='$Date: 2004-08-12 20:47:12 $'
26 last_checkin_date=`echo "$cvsdatestamp" | sed -e 's,^\$[D]ate: ,,'`
27 version=`echo "$last_checkin_date" | sed -e 's/ .*$//' -e 's,/,-,g'`
29 # You can set AUTOCONFPATH to empty if autoconf 2.57 is already in your PATH.
33 AUTOCONFBINDIR=/packages/gnu-inst-autoconf/2.57/bin
34 AUTOCONFPATH="eval env PATH=${AUTOCONFBINDIR}:\$PATH "
38 AUTOCONF="${AUTOCONFPATH}autoconf"
39 AUTOHEADER="${AUTOCONFPATH}autoheader"
40 AUTOMAKE="${AUTOCONFPATH}automake-1.7"
44 # outputs to stdout the --help usage message.
48 Usage: gnulib-tool --list
49 gnulib-tool --import [MODULE...]
50 gnulib-tool --create-testdir --dir=directory module1 ... moduleN
51 gnulib-tool --create-megatestdir --dir=directory [module1 ... moduleN]
52 gnulib-tool --test --dir=directory module1 ... moduleN
53 gnulib-tool --megatest --dir=directory [module1 ... moduleN]
54 gnulib-tool --extract-description module
55 gnulib-tool --extract-filelist module
56 gnulib-tool --extract-dependencies module
57 gnulib-tool --extract-autoconf-snippet module
58 gnulib-tool --extract-automake-snippet module
59 gnulib-tool --extract-include-directive module
60 gnulib-tool --extract-maintainer module
63 --list print the available module names
64 --import import the given modules into the current package
65 --create-testdir create a scratch package with the given modules
66 --create-megatestdir create a mega scratch package with the given modules
67 one by one and all together
68 --test test the combination of the given modules
69 (recommended to use CC=\"gcc -Wall\" here)
70 --megatest test the given modules one by one and all together
71 (recommended to use CC=\"gcc -Wall\" here)
72 --extract-description extract the description
73 --extract-filelist extract the list of files
74 --extract-dependencies extract the dependencies
75 --extract-autoconf-snippet extract the snippet for configure.ac
76 --extract-automake-snippet extract the snippet for lib/Makefile.am
77 --extract-include-directive extract the #include directive
78 --extract-maintainer report the maintainer(s) inside gnulib
81 --dir=DIRECTORY specify the target directory
82 For --import, this specify where your
83 configure.ac can be found. Defaults to current
85 --lib=LIBRARY Specify the library name. Defaults to 'libgnu'.
86 --source-base=DIRECTORY
87 Directory relative --dir where source code is
88 placed (default \"lib\"), for --import.
89 --m4-base=DIRECTORY Directory relative --dir where *.m4 macros are
90 placed (default \"m4\"), for --import.
91 --libtool Use libtool rules, for --import.
92 --no-changelog don't update or create ChangeLog files
94 Report bugs to <bug-gnulib@gnu.org>."
98 # outputs to stdout the --version message.
101 echo "$progname (GNU $package) $version"
102 echo "Copyright (C) 2002 Free Software Foundation, Inc.
103 This is free software; see the source for copying conditions. There is NO
104 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
105 echo "Written by" "Bruno Haible"
108 # func_fatal_error message
109 # outputs to stderr a fatal error message, and terminates the program.
112 echo "gnulib-tool: *** $1" 1>&2
113 echo "gnulib-tool: *** Stop." 1>&2
117 # Command-line option processing.
118 # Removes the OPTIONS from the arguments. Sets the variables:
119 # - mode list or import or create-testdir or create-megatestdir
120 # - destdir from --dir
121 # - libname from --lib
122 # - sourcebase from --source-base
123 # - m4base from --m4-base
124 # - libtool true if --libtool was given, blank otherwise
125 # - do_changelog false if --no-changelog was given, : otherwise
135 while test $# -gt 0; do
140 --import | --impor | --impo | --imp | --im | --i )
143 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
146 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
147 mode=create-megatestdir
149 --test | --tes | --te | --t )
152 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
156 mode=`echo "X$1" | sed -e 's/^X--//'`
161 func_fatal_error "missing argument for --dir"
166 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
171 func_fatal_error "missing argument for --lib"
176 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
181 func_fatal_error "missing argument for --source-base"
186 sourcebase=`echo "X$1" | sed -e 's/^X--source-base=//'`
191 func_fatal_error "missing argument for --m4-base"
196 m4base=`echo "X$1" | sed -e 's/^X--m4-base=//'`
201 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
204 --help | --hel | --he | --h )
207 --version | --versio | --versi | --vers | --ver | --ve | --v )
211 # Stop option prcessing
215 echo "gnulib-tool: unknown option $1" 1>&2
216 echo "Try 'gnulib-tool --help' for more information." 1>&2
225 /*) self_abspathname="$0" ;;
226 */*) self_abspathname=`pwd`/"$0" ;;
227 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
228 if test -x "$d/$0" && test ! -d "$d/$0"; then
229 self_abspathname="$d/$0"
233 if test -z "$self_abspathname"; then
234 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
238 while test -h "$self_abspathname"; do
239 # Resolve symbolic link.
240 sedexpr1='s, -> ,#%%#,'
241 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
242 linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
243 test -n "$linkval" || break
245 /* ) self_abspathname="$linkval" ;;
246 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
249 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
254 (cd "$gnulib_dir/modules" && ls -1) \
255 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^TEMPLATE$/d' -e '/~$/d' \
260 # verifies a module name
261 func_verify_module ()
263 if test ! -f "$gnulib_dir/modules/$module" \
264 || test "CVS" = "$module" \
265 || test "ChangeLog" = "$module" \
266 || test "TEMPLATE" = "$module"; then
267 echo "gnulib-tool: module $module doesn't exist" 1>&2
272 sed_extract_prog=':[ ]*$/ {
275 s/^Description:[ ]*$//
277 s/^Depends-on:[ ]*$//
278 s/^configure\.ac:[ ]*$//
279 s/^Makefile\.am:[ ]*$//
281 s/^Maintainer:[ ]*$//
288 # func_get_description module
289 func_get_description ()
291 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
294 # func_get_filelist module
297 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
299 echo m4/onceonly_2_57.m4
302 # func_get_dependencies module
303 func_get_dependencies ()
305 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
308 # func_get_autoconf_snippet module
309 func_get_autoconf_snippet ()
311 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
314 # func_get_automake_snippet module
315 func_get_automake_snippet ()
317 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
320 # func_get_include_directive module
321 func_get_include_directive ()
323 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
324 sed -e 's/^\(["<]\)/#include \1/'
327 # func_get_maintainer module
328 func_get_maintainer ()
330 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
333 # func_create_testdir testdir modules
334 func_create_testdir ()
338 modules=`for m in $modules; do echo $m; done | sort | uniq`
340 # Determine final module list.
343 for module in $modules; do
345 if test -n "$module"; then
346 # Duplicate dependenies are harmless, but Jim wants a warning.
347 duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
348 if test -n "$duplicated_deps"; then
349 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
351 xmodules="$xmodules $module "`func_get_dependencies $module`
354 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
355 if test "$xmodules" = "$modules"; then
360 echo "Module list with included dependencies:"
361 echo "$modules" | sed -e 's/^/ /'
363 # Determine final file list.
365 for module in $modules; do
367 if test -n "$module"; then
368 files="$files "`func_get_filelist $module`
371 files=`for f in $files; do echo $f; done | sort | uniq`
373 echo "$files" | sed -e 's/^/ /'
375 # Create directories.
376 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
377 if test "$d" != config; then
378 mkdir -p "$testdir/$d"
385 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
388 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
389 cp -p "$gnulib_dir/$f" "$testdir/$g"
392 # Create lib/Makefile.am.
393 mkdir -p "$testdir/lib"
394 (echo "## Process this file with automake to produce Makefile.in."
396 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
398 echo "noinst_LIBRARIES = $libname.a"
400 echo "$libname"'_a_SOURCES ='
401 echo "$libname"'_a_LIBADD = @LIBOBJS@'
402 echo '#'"$libname"'_la_LIBADD = @LTLIBOBJS@'
404 echo "BUILT_SOURCES ="
406 echo "MOSTLYCLEANFILES ="
408 echo "DISTCLEANFILES ="
409 echo "MAINTAINERCLEANFILES ="
410 for module in $modules; do
412 if test -n "$module"; then
413 func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,$libname"'_a_SOURCES,g' -e "s,lib_OBJECTS,$libname"'_a_OBJECTS,g'
414 if test "$module" = 'alloca'; then
415 echo "$libname"'_a_LIBADD += @ALLOCA@'
416 echo '#'"$libname"'_la_LIBADD += @LTALLOCA@'
420 ) > "$testdir/lib/Makefile.am"
422 # Create m4/Makefile.am.
423 mkdir -p "$testdir/m4"
424 (echo "## Process this file with automake to produce Makefile.in."
430 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
433 ) > "$testdir/m4/Makefile.am"
437 if test -f "$testdir"/m4/gettext.m4; then
438 # Avoid stupid error message from automake:
439 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
440 mkdir -p "$testdir/po"
441 (echo "## Process this file with automake to produce Makefile.in."
442 ) > "$testdir/po/Makefile.am"
443 subdirs="$subdirs po"
446 # Create Makefile.am.
447 (echo "## Process this file with automake to produce Makefile.in."
449 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
451 echo "SUBDIRS = $subdirs"
453 echo "ACLOCAL_AMFLAGS = -I m4"
454 ) > "$testdir/Makefile.am"
456 # Create configure.ac.
457 (echo "# Process this file with autoconf to produce a configure script."
458 echo "AC_INIT(dummy,0)"
459 echo "AM_INIT_AUTOMAKE"
461 echo "AM_CONFIG_HEADER(config.h)"
464 echo "AC_PROG_INSTALL"
465 echo "AC_PROG_MAKE_SET"
466 echo "AC_PROG_RANLIB"
468 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
472 if grep gl_USE_SYSTEM_EXTENSIONS "$testdir"/m4/*.m4 > /dev/null; then
473 echo "gl_USE_SYSTEM_EXTENSIONS"
476 for module in $modules; do
478 if test -n "$module"; then
479 func_get_autoconf_snippet "$module"
484 for d in $subdirs; do
485 makefiles="$makefiles $d/Makefile"
487 echo "AC_OUTPUT([$makefiles])"
488 ) > "$testdir/configure.ac"
490 # Create autogenerated files.
492 echo "executing ${ACLOCAL} -I m4"
494 echo "executing ${AUTOHEADER}"
496 echo "executing ${AUTOCONF}"
498 echo "executing ${AUTOMAKE} --add-missing --copy"
499 ${AUTOMAKE} --add-missing --copy
501 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
505 built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
506 if test -n "$built_sources"; then
515 # func_create_megatestdir megatestdir allmodules
516 func_create_megatestdir ()
520 if test -z "$allmodules"; then
521 allmodules=`func_all_modules`
525 # First, all modules one by one.
526 for onemodule in $allmodules; do
527 func_create_testdir "$megatestdir/$onemodule" $onemodule
528 megasubdirs="${megasubdirs}$onemodule "
530 # Then, all modules all together.
531 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
532 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
533 func_create_testdir "$megatestdir/ALL" "$allmodules"
534 megasubdirs="${megasubdirs}ALL"
536 # Create Makefile.am.
537 (echo "## Process this file with automake to produce Makefile.in."
539 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
541 echo "SUBDIRS = $megasubdirs"
542 ) > "$megatestdir/Makefile.am"
544 # Create configure.ac.
545 (echo "# Process this file with autoconf to produce a configure script."
546 echo "AC_INIT(dummy,0)"
547 echo "AM_INIT_AUTOMAKE"
549 echo "AC_PROG_MAKE_SET"
551 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
552 echo "AC_OUTPUT([Makefile])"
553 ) > "$megatestdir/configure.ac"
555 # Create autogenerated files.
557 echo "executing ${ACLOCAL}"
559 echo "executing ${AUTOCONF}"
561 echo "executing ${AUTOMAKE} --add-missing --copy Makefile"
562 ${AUTOMAKE} --add-missing --copy Makefile
568 func_fatal_error "no mode specified" ;;
575 if test -z "$destdir"; then
579 || func_fatal_error "destination directory does not exist: $destdir"
580 sourcebase=`cd $destdir; $AUTOCONF --trace=gl_SOURCE_BASE | sed 's,^.*:,,g'`
581 test -d "$destdir/$sourcebase" || \
582 mkdir "$destdir/$sourcebase" || \
584 "could not create source base directory: $destdir/$sourcebase"
585 m4base=`cd $destdir; $AUTOCONF --trace=gl_M4_BASE | sed 's,^.*:,,g'`
586 test -d "$destdir/$m4base" || \
587 mkdir "$destdir/$m4base" || \
589 "could not create m4 base directory: $destdir/$m4base"
590 supplied_modules="$*"
591 modules=`for m in $supplied_modules; do echo $m; done | sort | uniq`
592 if test -z "$modules"; then
593 modules=`cd $destdir; $AUTOCONF --trace=gl_MODULES | sed 's,^.*:,,g'`
595 if test x`cd $destdir; $AUTOCONF --trace=AC_PROG_LIBTOOL` != x; then
599 # Determine final module list.
602 for module in $modules; do
604 if test -n "$module"; then
605 # Duplicate dependenies are harmless, but Jim wants a warning.
606 duplicated_deps=`func_get_dependencies $module | sort | uniq -d`
607 if test -n "$duplicated_deps"; then
608 echo "warning: module $module has duplicated dependencies: "`echo $duplicated_deps` 1>&2
610 xmodules="$xmodules $module "`func_get_dependencies $module`
613 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
614 if test "$xmodules" = "$modules"; then
619 echo "Module list with included dependencies:"
620 echo "$modules" | sed -e 's/^/ /'
622 # Determine final file list.
624 for module in $modules; do
626 if test -n "$module"; then
627 files="$files "`func_get_filelist $module`
630 files=`for f in $files; do echo $f; done | sort | uniq`
632 echo "$files" | sed -e 's/^/ /'
637 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
638 lib/*) g=`echo "$f" | sed -e "s,^lib/,$sourcebase/,"` ;;
639 m4/*) g=`echo "$f" | sed -e "s,^m4/,$m4base/,"` ;;
642 cp -p "$gnulib_dir/$f" "$destdir/$g"
645 # Create lib/Makefile.am.
646 if test -n "$libtool"; then
653 (echo "## Process this file with automake to produce Makefile.in."
654 echo "# Copyright (C) 2004 Free Software Foundation, Inc."
656 echo "# This file is free software, distributed under the terms of the GNU"
657 echo "# General Public License. As a special exception to the GNU General"
658 echo "# Public License, this file may be distributed as part of a program"
659 echo "# that contains a configuration script generated by Automake, under"
660 echo "# the same distribution terms as the rest of that program."
662 echo "# Generated by gnulib-tool."
665 if test -n "$libtool"; then
666 opt_libtool="--libtool"
668 echo "# gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base $opt_libtool $supplied_modules"
670 echo "AUTOMAKE_OPTIONS = 1.8 gnits"
672 echo "noinst_${perhapsLT}LIBRARIES = $libname.$libext"
674 echo "${libname}_${libext}_SOURCES ="
675 echo "${libname}_${libext}_LIBADD = @${perhapsLT}LIBOBJS@"
677 echo "BUILT_SOURCES ="
679 echo "MOSTLYCLEANFILES ="
681 echo "DISTCLEANFILES ="
682 echo "MAINTAINERCLEANFILES ="
683 for module in $modules; do
685 if test -n "$module"; then
686 func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,${libname}_${libext}_SOURCES,g" -e "s,lib_OBJECTS,${libname}_${libext}_OBJECTS,g"
687 if test "$module" = 'alloca'; then
688 echo "${libname}_${libext}_LIBADD += @ALLOCA@"
692 ) > "$destdir/$sourcebase/Makefile.am"
695 (echo "# Copyright (C) 2004 Free Software Foundation, Inc."
696 echo "# This file is free software, distributed under the terms of the GNU"
697 echo "# General Public License. As a special exception to the GNU General"
698 echo "# Public License, this file may be distributed as part of a program"
699 echo "# that contains a configuration script generated by Autoconf, under"
700 echo "# the same distribution terms as the rest of that program."
702 echo "# Generated by gnulib-tool."
705 if test -n "$libtool"; then
706 opt_libtool="--libtool"
708 echo "# gnulib-tool --import --dir=$destdir --lib=$libname --source-base=$sourcebase --m4-base=$m4base $opt_libtool $supplied_modules"
710 echo "AC_DEFUN([gl_EARLY],"
712 if grep AC_GNU_SOURCE "$destdir"/$m4base/*.m4 > /dev/null; then
713 echo " AC_GNU_SOURCE"
715 if grep gl_USE_SYSTEM_EXTENSIONS "$destdir"/$m4base/*.m4 > /dev/null; then
716 echo " gl_USE_SYSTEM_EXTENSIONS"
720 echo "AC_DEFUN([gl_INIT],"
722 for module in $modules; do
724 if test -n "$module"; then
725 func_get_autoconf_snippet "$module" | sed -e '/^$/d;' -e 's/^/ /' -e 's/AM_GNU_GETTEXT(\[external\])/dnl you must add AM_GNU_GETTEXT([external]) or similar to configure.ac./'
730 echo "dnl Usage: gl_MODULES(module1 module2 ...)"
731 echo "AC_DEFUN([gl_MODULES], [])"
733 echo "dnl Usage: gl_SOURCE_BASE(DIR)"
734 echo "AC_DEFUN([gl_SOURCE_BASE], [])"
736 echo "dnl Usage: gl_M4_BASE(DIR)"
737 echo "AC_DEFUN([gl_M4_BASE], [])"
738 ) > "$destdir/$m4base/gnulib.m4"
742 if test -z "$destdir"; then
743 func_fatal_error "please specify --dir option"
747 || func_fatal_error "could not create destination directory"
748 func_create_testdir "$destdir" "$*"
752 if test -z "$destdir"; then
753 func_fatal_error "please specify --dir option"
755 mkdir "$destdir" || func_fatal_error "could not create destination directory"
756 func_create_megatestdir "$destdir" "$*"
760 test -n "$destdir" || destdir=testdir$$
761 mkdir "$destdir" || func_fatal_error "could not create destination directory"
762 func_create_testdir "$destdir" "$*"
770 remaining=`find . -type f -print`
771 if test -n "$remaining"; then
772 echo "Remaining files:" $remaining 1>&2
773 echo "gnulib-tool: *** Stop." 1>&2
782 test -n "$destdir" || destdir=testdir$$
783 mkdir "$destdir" || func_fatal_error "could not create destination directory"
784 func_create_megatestdir "$destdir" "$*"
792 remaining=`find . -type f -print`
793 if test -n "$remaining"; then
794 echo "Remaining files:" $remaining 1>&2
795 echo "gnulib-tool: *** Stop." 1>&2
803 extract-description )
807 if test -n "$module"; then
808 func_get_description "$module"
817 if test -n "$module"; then
818 func_get_filelist "$module"
823 extract-dependencies )
827 if test -n "$module"; then
828 func_get_dependencies "$module"
833 extract-autoconf-snippet )
837 if test -n "$module"; then
838 func_get_autoconf_snippet "$module"
843 extract-automake-snippet )
847 if test -n "$module"; then
848 func_get_automake_snippet "$module"
853 extract-include-directive )
857 if test -n "$module"; then
858 func_get_include_directive "$module"
867 if test -n "$module"; then
868 func_get_maintainer "$module"
874 func_fatal_error "unknown operation mode --$mode" ;;