3 # Copyright (C) 2002, 2003 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: 2003-01-20 10:02:37 $'
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 module1 ... moduleN
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 --lib=libRARY specify the library name
83 --no-changelog don't update or create ChangeLog files
85 Report bugs to <bug-gnulib@gnu.org>."
89 # outputs to stdout the --version message.
92 echo "$progname (GNU $package) $version"
93 echo "Copyright (C) 2002 Free Software Foundation, Inc.
94 This is free software; see the source for copying conditions. There is NO
95 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
96 echo "Written by" "Bruno Haible"
99 # func_fatal_error message
100 # outputs to stderr a fatal error message, and terminates the program.
103 echo "gnulib-tool: *** $1" 1>&2
104 echo "gnulib-tool: *** Stop." 1>&2
108 # Command-line option processing.
109 # Removes the OPTIONS from the arguments. Sets the variables:
110 # - mode list or import or create-testdir or create-megatestdir
111 # - destdir from --dir
112 # - libname from --lib
113 # - do_changelog false if --no-changelog was given, : otherwise
120 while test $# -gt 0; do
125 --import | --impor | --impo | --imp | --im | --i )
128 --create-testdir | --create-testdi | --create-testd | --create-test | --create-tes | --create-te | --create-t )
131 --create-megatestdir | --create-megatestdi | --create-megatestd | --create-megatest | --create-megates | --create-megate | --create-megat | --create-mega | --create-meg | --create-me | --create-m )
132 mode=create-megatestdir
134 --test | --tes | --te | --t )
137 --megatest | --megates | --megate | --megat | --mega | --meg | --me | --m )
141 mode=`echo "X$1" | sed -e 's/^X--//'`
146 func_fatal_error "missing argument for --dir"
151 destdir=`echo "X$1" | sed -e 's/^X--dir=//'`
156 func_fatal_error "missing argument for --lib"
161 libname=`echo "X$1" | sed -e 's/^X--lib=//'`
163 --no-changelog | --no-changelo | --no-changel | --no-change | --no-chang | --no-chan | --no-cha | --no-ch | --no-c )
166 --help | --hel | --he | --h )
169 --version | --versio | --versi | --vers | --ver | --ve | --v )
173 # Stop option prcessing
177 echo "gnulib-tool: unknown option $1" 1>&2
178 echo "Try 'gnulib-tool --help' for more information." 1>&2
187 /*) self_abspathname="$0" ;;
188 */*) self_abspathname=`pwd`/"$0" ;;
189 *) for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`; do
190 if test -x "$d/$0" && test ! -d "$d/$0"; then
191 self_abspathname="$d/$0"
195 if test -z "$self_abspathname"; then
196 func_fatal_error "could not locate the gnulib-tool program - how did you invoke it?"
200 while test -L "$self_abspathname"; do
201 # Resolve symbolic link.
202 sedexpr1='s, -> ,#%%#,'
203 sedexpr2='s,^.*#%%#\(.*\)$,\1,p'
204 linkval=`LC_ALL=C ls -l "$self_abspathname" | sed -e "$sedexpr1" | sed -n -e "$sedexpr2"`
205 test -n "$linkval" || break
207 /* ) self_abspathname="$linkval" ;;
208 * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
211 gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
216 (cd "$gnulib_dir/modules" && ls -1) \
217 | sed -e '/^CVS$/d' -e '/^ChangeLog$/d' -e '/^TEMPLATE$/d' -e '/~$/d' \
222 # verifies a module name
223 func_verify_module ()
225 if test ! -f "$gnulib_dir/modules/$module" \
226 || test "CVS" = "$module" \
227 || test "ChangeLog" = "$module" \
228 || test "TEMPLATE" = "$module"; then
229 echo "gnulib-tool: module $module doesn't exist" 1>&2
234 tags_regexp='\(Description\|Files\|Depends-on\|configure\.ac\|Makefile\.am\|Include\)'
235 sed_extract_prog=':[ ]*$/ {
238 s/^'"$tags_regexp"':[ ]*$//
245 # func_get_description module
246 func_get_description ()
248 sed -n -e "/^Description$sed_extract_prog" < "$gnulib_dir/modules/$1"
251 # func_get_filelist module
254 sed -n -e "/^Files$sed_extract_prog" < "$gnulib_dir/modules/$1"
256 echo m4/onceonly_2_57.m4
259 # func_get_dependencies module
260 func_get_dependencies ()
262 sed -n -e "/^Depends-on$sed_extract_prog" < "$gnulib_dir/modules/$1"
265 # func_get_autoconf_snippet module
266 func_get_autoconf_snippet ()
268 sed -n -e "/^configure\.ac$sed_extract_prog" < "$gnulib_dir/modules/$1"
271 # func_get_automake_snippet module
272 func_get_automake_snippet ()
274 sed -n -e "/^Makefile\.am$sed_extract_prog" < "$gnulib_dir/modules/$1"
277 # func_get_include_directive module
278 func_get_include_directive ()
280 sed -n -e "/^Include$sed_extract_prog" < "$gnulib_dir/modules/$1" | \
281 sed -e 's/^\(["<]\)/#include \1/'
284 # func_get_maintainer module
285 func_get_maintainer ()
287 sed -n -e "/^Maintainer$sed_extract_prog" < "$gnulib_dir/modules/$1"
290 # func_create_testdir testdir modules
291 func_create_testdir ()
295 modules=`for m in $modules; do echo $m; done | sort | uniq`
297 # Determine final module list.
300 for module in $modules; do
302 if test -n "$module"; then
303 xmodules="$xmodules $module "`func_get_dependencies $module`
306 xmodules=`for m in $xmodules; do echo $m; done | sort | uniq`
307 if test "$xmodules" = "$modules"; then
312 echo "Module list with included dependencies:"
313 echo "$modules" | sed -e 's/^/ /'
315 # Determine final file list.
317 for module in $modules; do
319 if test -n "$module"; then
320 files="$files "`func_get_filelist $module`
323 files=`for f in $files; do echo $f; done | sort | uniq`
325 echo "$files" | sed -e 's/^/ /'
327 # Create directories.
328 for d in `echo "$files" | sed -n -e 's,^\(.*\)/[^/]*,\1,p'`; do
329 if test "$d" != config; then
330 mkdir -p "$testdir/$d"
337 config/*) g=`echo "$f" | sed -e 's,^config/,,'` ;;
340 ln "$gnulib_dir/$f" "$testdir/$g" 2>/dev/null ||
341 cp -p "$gnulib_dir/$f" "$testdir/$g"
344 # Create lib/Makefile.am.
345 mkdir -p "$testdir/lib"
346 (echo "## Process this file with automake to produce Makefile.in."
348 echo "AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies"
350 echo "noinst_LIBRARIES = $libname.a"
352 echo "$libname"'_a_SOURCES ='
353 echo "$libname"'_a_LIBADD = @LIBOBJS@'
354 echo '#'"$libname"'_la_LIBADD = @LTLIBOBJS@'
356 echo "BUILT_SOURCES ="
358 echo "MOSTLYCLEANFILES ="
360 echo "DISTCLEANFILES ="
361 echo "MAINTAINERCLEANFILES ="
362 for module in $modules; do
364 if test -n "$module"; then
365 func_get_automake_snippet "$module" | sed -e "s,lib_SOURCES,$libname"'_a_SOURCES,g' -e "s,lib_OBJECTS,$libname"'_a_OBJECTS,g'
366 if test "$module" = 'alloca'; then
367 echo "$libname"'_a_LIBADD += @ALLOCA@'
368 echo '#'"$libname"'_la_LIBADD += @LTALLOCA@'
372 ) > "$testdir/lib/Makefile.am"
374 # Create m4/Makefile.am.
375 mkdir -p "$testdir/m4"
376 (echo "## Process this file with automake to produce Makefile.in."
382 echo "EXTRA_DIST += "`echo "$f" | sed -e 's,^m4/,,'` ;;
385 ) > "$testdir/m4/Makefile.am"
389 if test -f "$testdir"/m4/gettext.m4; then
390 # Avoid stupid error message from automake:
391 # "AM_GNU_GETTEXT used but `po' not in SUBDIRS"
392 mkdir -p "$testdir/po"
393 (echo "## Process this file with automake to produce Makefile.in."
394 ) > "$testdir/po/Makefile.am"
395 subdirs="$subdirs po"
398 # Create Makefile.am.
399 (echo "## Process this file with automake to produce Makefile.in."
401 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
403 echo "SUBDIRS = $subdirs"
405 echo "ACLOCAL_AMFLAGS = -I m4"
406 ) > "$testdir/Makefile.am"
408 # Create configure.ac.
409 (echo "# Process this file with autoconf to produce a configure script."
410 echo "AC_INIT(dummy,0)"
411 echo "AM_INIT_AUTOMAKE"
413 echo "AM_CONFIG_HEADER(config.h)"
416 echo "AC_PROG_INSTALL"
417 echo "AC_PROG_MAKE_SET"
418 echo "AC_PROG_RANLIB"
420 if grep AC_GNU_SOURCE "$testdir"/m4/*.m4 > /dev/null; then
424 for module in $modules; do
426 if test -n "$module"; then
427 func_get_autoconf_snippet "$module"
432 for d in $subdirs; do
433 makefiles="$makefiles $d/Makefile"
435 echo "AC_OUTPUT([$makefiles])"
436 ) > "$testdir/configure.ac"
438 # Create autogenerated files.
440 echo "executing ${ACLOCAL} -I m4"
442 echo "executing ${AUTOHEADER}"
444 echo "executing ${AUTOCONF}"
446 echo "executing ${AUTOMAKE} --add-missing --copy"
447 ${AUTOMAKE} --add-missing --copy
449 if grep '^BUILT_SOURCES *+=' "$testdir/lib/Makefile.am" > /dev/null; then
453 built_sources=`grep '^BUILT_SOURCES *=' Makefile.in | sed -e 's/^BUILT_SOURCES *=//'`
454 if test -n "$built_sources"; then
463 # func_create_megatestdir megatestdir allmodules
464 func_create_megatestdir ()
468 if test -z "$allmodules"; then
469 allmodules=`func_all_modules`
473 # First, all modules one by one.
474 for onemodule in $allmodules; do
475 func_create_testdir "$megatestdir/$onemodule" $onemodule
476 megasubdirs="${megasubdirs}$onemodule "
478 # Then, all modules all together.
479 # Except fnmatch-posix, which conflicts with fnmatch-gnu. FIXME.
480 allmodules=`for m in $allmodules; do if test $m != fnmatch-posix; then echo $m; fi; done`
481 func_create_testdir "$megatestdir/ALL" "$allmodules"
482 megasubdirs="${megasubdirs}ALL"
484 # Create Makefile.am.
485 (echo "## Process this file with automake to produce Makefile.in."
487 echo "AUTOMAKE_OPTIONS = 1.5 foreign"
489 echo "SUBDIRS = $megasubdirs"
490 ) > "$megatestdir/Makefile.am"
492 # Create configure.ac.
493 (echo "# Process this file with autoconf to produce a configure script."
494 echo "AC_INIT(dummy,0)"
495 echo "AM_INIT_AUTOMAKE"
497 echo "AC_PROG_MAKE_SET"
499 echo "AC_CONFIG_SUBDIRS([$megasubdirs])"
500 echo "AC_OUTPUT([Makefile])"
501 ) > "$megatestdir/configure.ac"
503 # Create autogenerated files.
505 echo "executing ${ACLOCAL}"
507 echo "executing ${AUTOCONF}"
509 echo "executing ${AUTOMAKE} --add-missing --copy Makefile"
510 ${AUTOMAKE} --add-missing --copy Makefile
516 func_fatal_error "no mode specified" ;;
523 func_fatal_error "NYI" ;;
526 if test -z "$destdir"; then
527 func_fatal_error "please specify --dir option"
531 || func_fatal_error "could not create destination directory"
532 func_create_testdir "$destdir" "$*"
536 if test -z "$destdir"; then
537 func_fatal_error "please specify --dir option"
539 mkdir "$destdir" || func_fatal_error "could not create destination directory"
540 func_create_megatestdir "$destdir" "$*"
544 test -n "$destdir" || destdir=testdir$$
545 mkdir "$destdir" || func_fatal_error "could not create destination directory"
546 func_create_testdir "$destdir" "$*"
554 remaining=`find . -type f -print`
555 if test -n "$remaining"; then
556 echo "Remaining files:" $remaining 1>&2
557 echo "gnulib-tool: *** Stop." 1>&2
566 test -n "$destdir" || destdir=testdir$$
567 mkdir "$destdir" || func_fatal_error "could not create destination directory"
568 func_create_megatestdir "$destdir" "$*"
576 remaining=`find . -type f -print`
577 if test -n "$remaining"; then
578 echo "Remaining files:" $remaining 1>&2
579 echo "gnulib-tool: *** Stop." 1>&2
587 extract-description )
591 if test -n "$module"; then
592 func_get_description "$module"
601 if test -n "$module"; then
602 func_get_filelist "$module"
607 extract-dependencies )
611 if test -n "$module"; then
612 func_get_dependencies "$module"
617 extract-autoconf-snippet )
621 if test -n "$module"; then
622 func_get_autoconf_snippet "$module"
627 extract-automake-snippet )
631 if test -n "$module"; then
632 func_get_automake_snippet "$module"
637 extract-include-directive )
641 if test -n "$module"; then
642 func_get_include_directive "$module"
651 if test -n "$module"; then
652 func_get_maintainer "$module"
658 func_fatal_error "unknown operation mode --$mode" ;;