Subject: bug#8753: unable to build VALA project out-of-tree

From: Stefano Lattarini <[email-masked]>
Date: Sun, 08 Jan 2012 12:54:58 +0100

On 01/07/2012 07:21 AM, Ryan Lortie wrote:
> hi,
Hi Ryan, and thanks for the patches.

> Here are a pair of patches that should fix this issue.
>
I must admit I dont' like very much the idea of having the stamp file created
in the $(srcdir) ...  but I see that the .c files generated by Vala are already
being placed in the $(srcdir) -- so you are just following the existing trend,
and you changes are a definite improvement over the existing broken situation.
So I think they are definitely good to apply.

I've edited your patches a bit to fix a couple of minor blunders and to
improve conformance to the GNU Coding Standards; since I was at it, I've
thrown in (into the second patch) an additional fix for another pre-existing
VPATH-related bug.  I've also added a tiny new patch to fix an independent
testsuite weakness (missing requirement of GNU make in vala-vpath.test).

Attached is what I'll pushed to maint in 72 hours, if there is no objection.

Thanks again for tackling this issue!

Best regards,
  Stefano

>From c7ee8c6db00ddc4cd90b9d44c5ccf3a90d26663b Mon Sep 17 00:00:00 2001
Message-Id: <c7ee8c6db[email-masked]>
From: Ryan Lortie <[email-masked]>
Date: Sat, 7 Jan 2012 01:06:37 -0500
Subject: [PATCH 1/3] tests: fix some bugs in the vala-vpath test

* tests/vala-vpath.test: There are (trivial) problems in this
testcase that would cause the build to fail even if the core
issue were resolved.  Fix those.

Copyright-paperwork-exempt: yes
---
 tests/vala-vpath.test |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/tests/vala-vpath.test b/tests/vala-vpath.test
index 98e0f43..99e30db 100755
--- a/tests/vala-vpath.test
+++ b/tests/vala-vpath.test
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2011 Free Software Foundation, Inc.
+# Copyright (C) 2011, 2012 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,8 +22,6 @@ required="valac"
 
 set -e
 
-mkdir src
-
 cat >> configure.in << 'END'
 AC_CONFIG_SRCDIR([hello.vala])
 AC_PROG_CC
@@ -31,9 +29,9 @@ AM_PROG_VALAC([0.7])
 AC_OUTPUT
 END
 
-
 cat > Makefile.am <<'END'
 bin_PROGRAMS = foo
+foo_VALAFLAGS = --profile=posix
 foo_SOURCES = hello.vala
 END
 
@@ -41,7 +39,6 @@ cat > hello.vala <<'END'
 void main ()
 {
   stdout.printf ("foo\n");
-  return 0;
 }
 END
 
-- 
1.7.7.3

>From 72f7e5de24468adfeded4b14eae97a839ae3b531 Mon Sep 17 00:00:00 2001
Message-Id: <72f7e5de2[email-masked]>
In-Reply-To: <c7ee8c6db[email-masked]>
References: <c7ee8c6db[email-masked]>
From: Ryan Lortie <[email-masked]>
Date: Sat, 7 Jan 2012 01:08:11 -0500
Subject: [PATCH 2/3] vala: fix VPATH builds

This change fixes automake bug#9859.

* automake.in (lang_vala_finish_target): Create the stamp file
'${derived}_vala.stamp' in $(srcdir), not in $(builddir).
Also, don't try to chdir to the $(srcdir) to trigger the rebuild
rules, since that is just wrong in a VPATH setup.
* tests/vala-vpath.test, tests/vala2.test: Extend to catch more
possible VPATH issues.
* tests/Makefile.am (XFAIL_TESTS): Remove 'vala-vpath.test'.
* NEWS, THANKS: Update.

Co-authored-by: Stefano Lattarini <[email-masked]>
Copyright-paperwork-exempt: yes
---
 NEWS                  |    2 ++
 THANKS                |    1 +
 automake.in           |    8 ++++----
 tests/Makefile.am     |    1 -
 tests/vala-vpath.test |   19 ++++++++++++++++++-
 tests/vala2.test      |   11 +++++++++--
 6 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 2b09bb5..9f2c6a1 100644
--- a/NEWS
+++ b/NEWS
@@ -129,6 +129,8 @@ Bugs fixed in 1.11.0a:
 
 * Long-standing bugs:
 
+  - Vala support now works better in VPATH setups.
+
   - The "deleted header file problem" for *.am files is avoided by stub
     rules.  This allows `make' to trigger a rerun of `automake' also if
     some previously needed `.am' file has been removed.
diff --git a/THANKS b/THANKS
index e9c6db8..fbb7eb4 100644
--- a/THANKS
+++ b/THANKS
@@ -315,6 +315,7 @@ Roman Fietze		[email-masked]
 Ronald Landheer		[email-masked]
 Roumen Petrov		[email-masked]
 Rusty Ballinger		[email-masked]
+Ryan Lortie 		[email-masked]
 Ryan T. Sammartino	[email-masked]
 Sam Hocevar		[email-masked]
 Sam Sirlin		[email-masked]
diff --git a/automake.in b/automake.in
index a689b63..e1d6319 100644
--- a/automake.in
+++ b/automake.in
@@ -6023,7 +6023,7 @@ sub lang_vala_finish_target ($$)
           $output_rules .= "\$(srcdir)/$file: \$(srcdir)/${derived}_vala.stamp\n"
             . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
             . "\t\@if test -f \$@; then :; else \\\n"
-            . "\t  \$(am__cd) \$(srcdir) && \$(MAKE) \$(AM_MAKEFLAGS) ${derived}_vala.stamp; \\\n"
+            . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
 	    . "\tfi\n"
             if $file =~ s/(.*)\.vala$/$1.c/;
         }
@@ -6043,7 +6043,7 @@ sub lang_vala_finish_target ($$)
 	      $output_rules .= "\$(srcdir)/$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
 		. "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
 		. "\t\@if test -f \$@; then :; else \\\n"
-		. "\t  \$(am__cd) \$(srcdir) && \$(MAKE) \$(AM_MAKEFLAGS) ${derived}_vala.stamp; \\\n"
+		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
 		. "\tfi\n";
 
 	      # valac is not used when building from dist tarballs
@@ -6076,8 +6076,8 @@ sub lang_vala_finish_target ($$)
   my $silent = silent_flag ();
 
   $output_rules .=
-    "${derived}_vala.stamp: \$(${derived}_SOURCES)\n".
-    "\t${verbose}${compile} \$(${derived}_SOURCES)\n".
+    "\$(srcdir)/${derived}_vala.stamp: \$(${derived}_SOURCES)\n".
+    "\t${verbose}cd \$(srcdir) && ${compile} \$(${derived}_SOURCES)\n".
     "\t${silent}touch \$@\n";
 
   push_dist_common ("${derived}_vala.stamp");
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9db0a03..8817b64 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,7 +30,6 @@ pr8365-remake-timing.test \
 lex-subobj-nodep.test \
 remake-am-pr10111.test \
 remake-m4-pr10111.test \
-vala-vpath.test \
 txinfo5.test
 
 include $(srcdir)/parallel-tests.am
diff --git a/tests/vala-vpath.test b/tests/vala-vpath.test
index 99e30db..9d60dbb 100755
--- a/tests/vala-vpath.test
+++ b/tests/vala-vpath.test
@@ -38,7 +38,7 @@ END
 cat > hello.vala <<'END'
 void main ()
 {
-  stdout.printf ("foo\n");
+  stdout.printf ("foofoofoo\n");
 }
 END
 
@@ -50,6 +50,23 @@ mkdir build
 cd build
 ../configure || Exit 77
 $MAKE
+grep foofoofoo ../hello.c
 $MAKE distcheck
 
+# Rebuild rules work also in VPATH builds.
+cat > ../hello.vala <<'END'
+int main ()
+{
+  stdout.printf ("barbarbar\n");
+  return 0;
+}
+END
+
+$MAKE
+grep barbarbar ../hello.c
+
+# Rebuild rules are not uselessly triggered.
+$MAKE -q
+$MAKE -n | grep '\.stamp' && Exit 1
+
 :
diff --git a/tests/vala2.test b/tests/vala2.test
index e559540..a8a3d90 100755
--- a/tests/vala2.test
+++ b/tests/vala2.test
@@ -81,7 +81,14 @@ cd build
 $MAKE
 $MAKE distcheck
 
-# test rebuild rules from builddir
-touch ../src/zardoz.vala
+# Test rebuild rules from builddir.
+rm -f ../src/zardoz.c
 $MAKE
+grep 'Zardoz!' ../src/zardoz.c
+sed 's/Zardoz!/FooBar!/' ../src/zardoz.c > t
+mv -f t ../src/zardoz.c
+$MAKE
+grep 'FooBar!' ../src/zardoz.c
+grep 'Zardoz!' ../src/zardoz.c && Exit 1
 
+:
-- 
1.7.7.3

>From d850165e6c9722adf2b80442974f3ca014c35298 Mon Sep 17 00:00:00 2001
Message-Id: <d850165e6[email-masked]>
In-Reply-To: <c7ee8c6db[email-masked]>
References: <c7ee8c6db[email-masked]>
From: Stefano Lattarini <[email-masked]>
Date: Sun, 8 Jan 2012 12:49:57 +0100
Subject: [PATCH 3/3] tests: require GNU make in 'vala-vapth.test'

* vala-vpath.test ($required): Add the "GNUmake" requirement, since
rules generated by vala support are expected to work with GNU make
only.
---
 tests/vala-vpath.test |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/tests/vala-vpath.test b/tests/vala-vpath.test
index 9d60dbb..8f2b677 100755
--- a/tests/vala-vpath.test
+++ b/tests/vala-vpath.test
@@ -17,7 +17,7 @@
 # Test to make sure vala support handles from-scratch VPATH builds.
 # See automake bug#8753.
 
-required="valac"
+required="valac GNUmake"
 . ./defs || Exit 1
 
 set -e
-- 
1.7.7.3