Hello,
Attached is my attempt at such patch, based on your suggestion.
On 07/19/2014 02:27 PM, Sami Kerola wrote:
On 17 July 2014 06:58, Assaf Gordon <[email protected]> wrote:
Hello,
I've encountered a problem where GNU Hello build fails with a cross
compiler, after the switch to non-recursive make
(of course there's no reason to need GNU hello cross-compiled, but my
project is based on GNU hello's build system).
<...>
I suspect this rule needs to be a bit more complicated, to accommodate few
possibilities:
1. Native compiling from GIT repository, where "hello.1" doesn't exist (yet)
and "hello" can be executed - then "hello.1" can be generated.
This seems right.
2. Native compiling from tarball, where "hello.1" already exists (due to
'make dist') and "hello" can be executed - then either re-generate "hello.1"
or not ?
Output at this point the content of the manual is fixed, so I am voting
for not re-generating.
3. Cross-compiling from GIT repository, "hello.1" doesn't exist but "hello"
*can not* be executed - ignore and use empty "hello.1" ?
Distributing empty manuals sounds wrong. When cross-compiling from git
the segment requiring manuals needs to be suppressed from Makefile.am.
4. Cross-compiling from tarball, where "hello.1" exists but "hello" *can
not* be executed - use existing "hello.1" (despite it being older than
"hello", which might confuse the make target?) .
This makes sense.
<...>
The change looks good. Only one AM_CONDITIONAL is needed to make 3.
exclude the manuals when creating one is impossible or the least quite
difficult.
I haven't tested the following, but it might work.
<...>
Few differences from your suggestion:
1. If building from tarball (as opposed to from .git), I've changed the build to never
generate, and never clean the "hello.1" manpage. The downside is that if a
developer works from a tarball and changes the help screen, the manpage will be stale.
This is the "BUILD_FROM_GIT" in Makefile.am .
I think that's reasonable, but I could be wrong.
2. If building from GIT and cross-compiling, don't add a rule to the makefile to generate
the man-page (this is the "!GIT_CROSS_COMPILING" in Makefile.am).
3. I've read somewhere (can't find the link now) that AM_CONDITIONAL should not be nested
- so it is outside the "AS_IF".
4. To detect the ".git" directory, I've used "$srcdir/.git" (not just ".git") -
as this could be problematic in out of tree builds?
I've tested it on several systems (including cross-compiling), but more testing
is always good.
Comments are welcomed,
-Assaf
>From c81611edbcf05201bb017eb08494d4a00ece30b9 Mon Sep 17 00:00:00 2001
From: "A. Gordon" <[email protected]>
Date: Wed, 23 Jul 2014 21:27:48 -0400
Subject: [PATCH] build: generate man-page only when appropriate
* configure.ac: detect compilation under git (vs tarball), and
cross-compilation.
* Makefile.am:
1) re-generate (and clean) man-page only when building from git.
2) if building from git AND cross-compiling, don't add target for
man-page - there's no way to generate it.
Possible future improvement: If cross-compliing from git, AND user have
'binfmt' configured to run non-native binaries, then the man-page can be
generated.
Reference:
http://lists.gnu.org/archive/html/bug-hello/2014-07/msg00001.html
---
Makefile.am | 9 ++++++++-
configure.ac | 7 +++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 44957a4..352898b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -43,15 +43,22 @@ hello_LDADD = $(LIBINTL) $(top_builddir)/lib/lib$(PACKAGE).a
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+CLEANFILES =
+
+if !GIT_CROSS_COMPILING
man_MANS = hello.1
EXTRA_DIST += $(man_MANS)
-CLEANFILES = $(man_MANS)
+endif
+if BUILD_FROM_GIT
hello.1: hello
$(HELP2MAN) --include=$(top_srcdir)/man/hello.x $(top_builddir)/hello -o $@-t
chmod a=r $@-t
mv -f $@-t $@
+CLEANFILES += $(man_MANS)
+endif
+
TESTS = \
tests/greeting-1 \
tests/greeting-2 \
diff --git a/configure.ac b/configure.ac
index 6b32fb5..2ac1fa2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -43,6 +43,13 @@ dnl Copyright will apply as long as these sources are in use, e.g., are
dnl being compiled, which is reasonable year to claim the copyright.
AC_DEFINE([COPYRIGHT_YEAR], [m4_esyscmd([date +%Y])], [year in copyright message])
+dnl Are we building from git checked-out sources, or a tarball ?
+dnl This is used in "Makefile.am" to avoid re-generating the manpage
+dnl when building from tarballs.
+AM_CONDITIONAL([BUILD_FROM_GIT], [test -d "$srcdir/.git"])
+AM_CONDITIONAL([GIT_CROSS_COMPILING],
+ [test -d "$srcdir/.git" && test $cross_compiling = yes])
+
dnl GNU help2man creates man pages from --help output; in many cases, this
dnl is sufficient, and obviates the need to maintain man pages separately.
dnl However, this means invoking executables, which we generally cannot do
--
1.9.1