[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] feature enhancement for gnulib-tool
From: |
Charles Wilson |
Subject: |
[patch] feature enhancement for gnulib-tool |
Date: |
Fri, 20 Oct 2006 00:16:41 -0400 |
User-agent: |
Thunderbird 1.5.0.7 (Windows/20060909) |
When you call gnulib-tool --import/--update, it autogenerates a
Makefile.am for the library. Sometimes it is desirable to customize
that Makefile's behavior -- but those customizations will be lost upon
the next --update.
The attached patch is not complete; it needs more work and some feedback
first. But it works for me(tm), which is a good first step.
The attached patch implements a mechanism where small Makefile.am
fragments in the target directory can be incorporated into the generated
Makefile.am. If present in the target dir when gnulib-tool is invoked,
the following files will be included by the Makefile.am:
Makefile.am.top
Makefile.am.before
Makefile.am.after
Makefile.am.bottom
The structure of the generated Makefile.am will be:
------------top of file----------------
<comment block>
include Makefile.am.top : this line only if Makefile.am.top
detected at gnulib-tool invokation
<libgnu preamble sutff>
include Makefile.am.before : this line only if Makefile.am.before
detected at gnulib-tool invokation
<snippets from each module's Makefile.am: section>
include Makefile.am.after : this line only if Makefile.am.after
detected at gnulib-tool invokation
<final gnulib-tool stuff> : at present, just the mostlyclean-local
rule
include Makefile.am.bottom : this line only if Makefile.am.bottom
detected at gnulib-tool invokation
-------------- bottom of file ---------------
This allows the end-user to customize
(a) the very first part of the makefile
(b) the very last part of the makefile
(c) two other locations sorta in the middle
I needed this because I wanted to specify -DNO_XMALLOC when compiling
libgnu, but I didn't want to pollute the namespace of the enclosing
project with that symbol. I also needed to customize the
DEFAULT_INCLUDES (long story). So, I put the following two files in my
libgnu directory:
Makefile.am.top
------------ >% -----------
DEFAULT_INCLUDES = -I. -I$(srcdir) \
-I$(top_builddir)/lib -I$(top_srcdir)/lib
------------ >% -----------
Makefile.am.before
------------ >% -----------
AM_CPPFLAGS += -DNO_XMALLOC
------------ >% -----------
before invoking gnulib-tool --import.
What's missing:
------------------------------
Doesn't handle --dir=(anything other than .) Should be easy to
incorporate, but I didn't need it for this proof-of-concept.
Doesn't work in test mode. Since in that mode the entire target
hierarchy is created on-the-fly, the end user obviously can't
pre-position Makefile.am fragments inside $testdir/$sourcebase. OTOH,
in test mode you probably don't care: since gnulib-tool creates a whole
project with its own configure.ac and everything, the end user probably
doesn't need the level of customization granularity provided by this patch.
If it is desired to have this functionality present in test mode...well,
then I've got some more work to do.
What's ugly:
------------------------------
Because Makefile generation is done via "call a function and redirect
its output", the function (func_emit_lib_Makefile_am) doesn't know where
the target directory is, so it can't look for those fragments. So, we
get stuff that looks like this:
func_dest_tmpfilename $sourcebase/$makefile_am
lib_Makefile_am_target_dir="$sourcebase"
func_emit_lib_Makefile_am > "$tmpfile"
lib_Makefile_am_target_dir=""
where func_emit_lib_Makefile_am() uses the value of
$lib_Makefile_am_target_dir.
So, it this a good idea? Would a more complete patch along these lines
-- one which addressed the 'what's missing' stuff above, and any other
missing items this mailing list generates -- be an acceptable addition
to gnulib-tool? Is there a better way of handling the 'what's ugly'
stuff mentioned above? Does this facility need to be available in test
mode?
--
Chuck
2006-10-18 Charles Wilson < cygwin at cwilson dot fastmail dot fm >
* gnulib-tool (func_maybe_emit_lib_Makefile_am_hook): new
function.
* gnulib-tool (func_maybe_emit_lib_Makefile_am_top): ditto
* gnulib-tool (func_maybe_emit_lib_Makefile_am_before): ditto
* gnulib-tool (func_maybe_emit_lib_Makefile_am_after): ditto
* gnulib-tool (func_maybe_emit_lib_Makefile_am_bottom): ditto
* gnulib-tool (func_emit_lib_Makefile_am): use the new functions
* gnulib-tool (func_import): set up lib_Makefile_am_target_dir
variable before calling func_emit_lib_Makefile_am().
* gnulib-tool (func_create_testdir): ditto
Index: gnulib-tool
===================================================================
RCS file: /sources/gnulib/gnulib/gnulib-tool,v
retrieving revision 1.182
diff -u -r1.182 gnulib-tool
--- gnulib-tool 19 Oct 2006 13:24:55 -0000 1.182
+++ gnulib-tool 19 Oct 2006 21:39:46 -0000
@@ -1105,6 +1105,47 @@
files=`for f in $files; do echo $f; done | LC_ALL=C sort -u`
}
+# func_maybe_emit_lib_Makefile_am_hook
+# emits a stanza that will include an external Makefile.am fragment
+# but only if (a) the variable lib_Makefile_am_target_dir is non-empty
+# and (b) the appropriate named fragment already exists in that target dir.
+# Input arguments
+# - argument $1 - name of fragment to include
+# Input variables
+# - lib_Makefile_am_target_dir (optional)
+# Input files
+# - file: $(lib_Makefile_am_target_dir)/${1}
+func_maybe_emit_lib_Makefile_am_hook ()
+{
+ if test -n "${lib_Makefile_am_target_dir}" ; then
+ if test -n "${1}" ; then
+ if test -f "${lib_Makefile_am_target_dir}/${1}" ; then
+ echo "include ${1}"
+ fi
+ fi
+ fi
+}
+
+func_maybe_emit_lib_Makefile_am_top ()
+{
+ func_maybe_emit_lib_Makefile_am_hook Makefile.am.top
+}
+
+func_maybe_emit_lib_Makefile_am_before_snippets ()
+{
+ func_maybe_emit_lib_Makefile_am_hook Makefile.am.before
+}
+
+func_maybe_emit_lib_Makefile_am_after_snippets ()
+{
+ func_maybe_emit_lib_Makefile_am_hook Makefile.am.after
+}
+
+func_maybe_emit_lib_Makefile_am_bottom ()
+{
+ func_maybe_emit_lib_Makefile_am_hook Makefile.am.bottom
+}
+
# func_emit_lib_Makefile_am
# emits the contents of library makefile to standard output.
# Input:
@@ -1115,6 +1156,7 @@
# - libtool true if libtool will be used, false or blank otherwise
# - macro_prefix prefix of gl_LIBOBJS macros to use
# - actioncmd (optional) command that will reproduce this invocation
+# - lib_Makefile_am_target_dir (optional) hook for external includes
func_emit_lib_Makefile_am ()
{
# When creating an includable Makefile.am snippet, augment variables with
@@ -1140,6 +1182,9 @@
echo "# Reproduce by: $actioncmd"
fi
echo
+
+ func_maybe_emit_lib_Makefile_am_top
+
if test -z "$makefile_name"; then
echo "AUTOMAKE_OPTIONS = 1.5 gnits"
fi
@@ -1211,8 +1256,16 @@
echo "AM_CPPFLAGS ="
fi
echo
+
+ func_maybe_emit_lib_Makefile_am_before_snippets
+
+ echo
cat allsnippets.tmp
echo
+
+ func_maybe_emit_lib_Makefile_am_after_snippets
+
+ echo
echo "mostlyclean-local: mostlyclean-generic"
echo " @test -z \"\$(MOSTLYCLEANDIRS)\" || \\"
echo " for dir in \$(MOSTLYCLEANDIRS); do \\"
@@ -1220,6 +1273,10 @@
echo " echo \"rmdir \$\$dir\"; rmdir \$\$dir; \\"
echo " fi; \\"
echo " done"
+ echo
+
+ func_maybe_emit_lib_Makefile_am_bottom
+
rm -f allsnippets.tmp
}
@@ -1847,7 +1904,9 @@
# Create library makefile.
func_dest_tmpfilename $sourcebase/$makefile_am
+ lib_Makefile_am_target_dir="$sourcebase"
func_emit_lib_Makefile_am > "$tmpfile"
+ lib_Makefile_am_target_dir=""
if test -f "$destdir"/$sourcebase/$makefile_am; then
if cmp "$destdir"/$sourcebase/$makefile_am "$tmpfile" > /dev/null; then
rm -f "$tmpfile"
@@ -2231,7 +2290,10 @@
# Create $sourcebase/Makefile.am.
mkdir -p "$testdir/$sourcebase"
+ lib_Makefile_am_target_dir="$testdir/$sourcebase"
+ # FIXME: copy fragments from $sourcebase to $testdir/$sourcebase ?
func_emit_lib_Makefile_am > "$testdir/$sourcebase/Makefile.am"
+ lib_Makefile_am_target_dir=""
# Create $m4base/Makefile.am.
mkdir -p "$testdir/$m4base"
- [patch] feature enhancement for gnulib-tool,
Charles Wilson <=