Subject: bug#13002: Fwd: Bug fix patch

From: Daniel Espinosa <[email-masked]>
Date: Thu, 28 Jul 2016 10:18:05 -0500

Sorry this is the correct but this patch belongs to.

---------- Forwarded message ----------
From: Daniel Espinosa <[email-masked]>
Date: 2016-07-28 10:16 GMT-05:00
Subject: Bug fix patch
To: [email-masked]

Attached you'll find a patch for this bug, including some improvements to
Vala support.

-- 
This electronic message may contain privileged and confidential information
intended only for the use of the addressees named above.  If you are not
the intended recipient of this email, we kindly ask you to delete this
message and any attachment. You are hereby notified that any use,
dissemination, distribution, reproduction of this email is prohibited.  If
you have received this email in error, please notify sender immediately.

Any document, image or any other form of electronic representation of any
work attached to this email, is suitable to be protected by copyright
enforcement by applicable law in your or sender's Country's and
International Legislation

Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los
cuates: LIBRE)

-- 
This electronic message may contain privileged and confidential information
intended only for the use of the addressees named above.  If you are not
the intended recipient of this email, we kindly ask you to delete this
message and any attachment. You are hereby notified that any use,
dissemination, distribution, reproduction of this email is prohibited.  If
you have received this email in error, please notify sender immediately.

Any document, image or any other form of electronic representation of any
work attached to this email, is suitable to be protected by copyright
enforcement by applicable law in your or sender's Country's and
International Legislation

Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (en trámite, pero para los
cuates: LIBRE)
From b4062c4be36728c07d79660305b96ed3d697243d Mon Sep 17 00:00:00 2001
From: Daniel Espinosa <[email-masked]>
Date: Thu, 28 Jul 2016 00:39:44 -0500
Subject: [PATCH] Vala support: improvements bug fixes

* Fixed bug #13002, now Automake generate stamps on
  build directory and use correctly VPATH for all source files

* Automake now add vapi generated files for distribution and
  make vapi depends on stamp

* Improved and added new test cases for Vala libs
---
 bin/automake.in          |  37 ++++++---
 t/vala-libs-distcheck.sh | 196 +++++++++++++++++++++++++++++++++++++++++++++++
 t/vala-libs-vpath.sh     | 108 ++++++++++++++++++++++++++
 t/vala-libs.sh           |  51 +++++++-----
 t/vala-vpath.sh          |   1 +
 5 files changed, 361 insertions(+), 32 deletions(-)
 create mode 100644 t/vala-libs-distcheck.sh
 create mode 100644 t/vala-libs-vpath.sh

diff --git a/bin/automake.in b/bin/automake.in
index 3abee49..32fcf6e 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -5405,11 +5405,11 @@ sub lang_vala_finish_target
       my $c_file = $vala_file;
       if ($c_file =~ s/(.*)\.vala$/$1.c/)
         {
-          $c_file = "\$(srcdir)/$c_file";
-          $output_rules .= "$c_file: \$(srcdir)/${derived}_vala.stamp\n"
-            . "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
+          $c_file = "\$(builddir)/$c_file";
+          $output_rules .= "$c_file: \$(builddir)/${derived}_vala.stamp\n"
+            . "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
             . "\t\@if test -f \$@; then :; else \\\n"
-            . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
+            . "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
             . "\tfi\n";
 	  $clean_files{$c_file} = MAINTAINER_CLEAN;
         }
@@ -5425,11 +5425,11 @@ sub lang_vala_finish_target
 	  if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header',
 	                          '--vapi', '--internal-vapi', '--gir')))
 	    {
-	      my $headerfile = "\$(srcdir)/$flag";
-	      $output_rules .= "$headerfile: \$(srcdir)/${derived}_vala.stamp\n"
-		. "\t\@if test -f \$@; then :; else rm -f \$(srcdir)/${derived}_vala.stamp; fi\n"
+	      my $headerfile = "\$(builddir)/$flag";
+	      $output_rules .= "$headerfile: \$(builddir)/${derived}_vala.stamp\n"
+		. "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
 		. "\t\@if test -f \$@; then :; else \\\n"
-		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(srcdir)/${derived}_vala.stamp; \\\n"
+		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
 		. "\tfi\n";
 
 	      # valac is not used when building from dist tarballs
@@ -5437,6 +5437,21 @@ sub lang_vala_finish_target
 	      push_dist_common ($headerfile);
 	      $clean_files{$headerfile} = MAINTAINER_CLEAN;
 	    }
+	  if (grep (/$lastflag/, ('--library')))
+	    {
+	      my $headerfile = "\$(builddir)/$flag";
+	      $output_rules .= "$headerfile.vapi: \$(builddir)/${derived}_vala.stamp\n"
+		. "\t\@if test -f \$@; then :; else rm -f \$(builddir)/${derived}_vala.stamp; fi\n"
+		. "\t\@if test -f \$@; then :; else \\\n"
+		. "\t  \$(MAKE) \$(AM_MAKEFLAGS) \$(builddir)/${derived}_vala.stamp; \\\n"
+		. "\tfi\n";
+
+	      # valac is not used when building from dist tarballs
+	      # distribute the generated files
+	      my $vapi = "$headerfile.vapi";
+	      push_dist_common ($vapi);
+	      $clean_files{$headerfile.'.vapi'} = MAINTAINER_CLEAN;
+	    }
 	  $lastflag = $flag;
 	}
     }
@@ -5460,10 +5475,10 @@ sub lang_vala_finish_target
 
   my $verbose = verbose_flag ('VALAC');
   my $silent = silent_flag ();
-  my $stampfile = "\$(srcdir)/${derived}_vala.stamp";
+  my $stampfile = "\$(builddir)/${derived}_vala.stamp";
 
   $output_rules .=
-    "\$(srcdir)/${derived}_vala.stamp: @vala_sources\n".
+    "\$(builddir)/${derived}_vala.stamp: @vala_sources\n".
 # Since the C files generated from the vala sources depend on the
 # ${derived}_vala.stamp file, we must ensure its timestamp is older than
 # those of the C files generated by the valac invocation below (this is
@@ -5471,7 +5486,7 @@ sub lang_vala_finish_target
 # Thus we need to create the stamp file *before* invoking valac, and to
 # move it to its final location only after valac has been invoked.
     "\t${silent}rm -f \$\@ && echo stamp > \$\@-t\n".
-    "\t${verbose}\$(am__cd) \$(srcdir) && $compile @vala_sources\n".
+    "\t${verbose} $compile \$^\n".
     "\t${silent}mv -f \$\@-t \$\@\n";
 
   push_dist_common ($stampfile);
diff --git a/t/vala-libs-distcheck.sh b/t/vala-libs-distcheck.sh
new file mode 100644
index 0000000..99f1e90
--- /dev/null
+++ b/t/vala-libs-distcheck.sh
@@ -0,0 +1,196 @@
+#! /bin/sh
+# Copyright (C) 2012-2016 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Building libraries (libtool and static) from Vala sources.
+# And use of vapi files to call C code from Vala.
+
+required="valac cc pkg-config libtoolize GNUmake"
+am_create_testdir=empty
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_INIT([atest],[0.1])
+AC_CONFIG_SRCDIR([data/atest.pc.in])
+
+AC_SUBST([API_VERSION],[0])
+
+AM_INIT_AUTOMAKE
+AM_MAINTAINER_MODE([enable])
+
+AC_PROG_CC
+AC_PROG_INSTALL
+AM_PROG_AR
+PKG_PROG_PKG_CONFIG([0.22])
+AM_PROG_VALAC([0.32])
+
+PKG_CHECK_MODULES(ATEST, [gio-2.0])
+
+LT_INIT
+AC_CONFIG_FILES([
+	Makefile
+
+	src/Makefile
+
+	src/atest-$API_VERSION.deps:src/atest.deps.in
+
+	data/Makefile
+	data/atest-$API_VERSION.pc:data/atest.pc.in
+
+],[],
+[API_VERSION='$API_VERSION'])
+AC_OUTPUT
+END
+
+
+cat > Makefile.am << 'END'
+SUBDIRS=data src
+END
+
+mkdir data
+
+cat > data/atest.pc.in << 'END'
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+datarootdir=@datarootdir@
+datadir=@datadir@
+includedir=@includedir@
+
+Name: atest-@API_VERSION@
+Description: atest library
+Version: @VERSION@
+Requires: glib-2.0 gobject-2.0
+Libs: -L${libdir} -latest-@API_VERSION@
+Cflags: -I${includedir}/atest-@API_VERSION@
+END
+
+
+cat > data/Makefile.am << 'END'
+# pkg-config data
+# Note that the template file is called atest.pc.in, but generates a
+# versioned .pc file using some magic in AC_CONFIG_FILES.
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = atest-$(API_VERSION).pc
+
+DISTCLEANFILES = $(pkgconfig_DATA)
+EXTRA_DIST = atest.pc.in
+END
+
+mkdir src
+
+cat > src/atest.deps.in << 'END'
+glib-2.0
+END
+
+
+cat > src/atest.vala << 'END'
+using GLib;
+
+namespace Atest {
+	public class A {
+		public bool foo() { return false; }
+	}
+}
+END
+
+cat > src/Makefile.am << 'END'
+lib_LTLIBRARIES = libatest-@API_VERSION@.la
+
+libatest_@API_VERSION@_la_SOURCES = \
+	atest.vala \
+	cservice.c \
+	cservice.h \
+	$(NULL)
+
+
+libatest_@API_VERSION@_la_CPPFLAGS = \
+	-DOKOKIMDEFINED=1 \
+	$(NULL)
+
+libatest_@API_VERSION@_la_CFLAGS = \
+	$(ATEST_CFLAGS) \
+	$(WARN_CFLAGS) \
+	$(NULL)
+
+libatest_@API_VERSION@_la_LIBADD = \
+	$(ATEST_LIBS) \
+	$(NULL)
+
+libatest_@API_VERSION@_la_LDFLAGS = \
+	$(WARN_LDFLAGS) \
+	$(NULL)
+
+libatest_@API_VERSION@_la_VALAFLAGS = \
+	--vapidir=$(VAPIDIR) \
+	--vapidir=$(srcdir) \
+	--pkg cservice \
+	--thread \
+	--target-glib=2.44 \
+	--pkg glib-2.0 \
+	-H atest.h \
+	--library atest-@API_VERSION@ \
+	$(NULL)
+
+header_DATA=atest.h
+headerdir=$(includedir)/atest-@API_VERSION@/atest
+
+atest-@API_VERSION@.deps:
+	cp atest.deps atest-@API_VERSION@.deps
+
+vapi_DATA=atest-@API_VERSION@.vapi atest-@API_VERSION@.deps
+vapidir=$(VAPIDIR)
+
+CLEANFILES = atest-@API_VERSION@.deps
+END
+
+
+cat > src/cservice.c << 'END'
+#include "cservice.h"
+int c_service_mu_call (void)
+{
+  return OKOKIMDEFINED;
+}
+END
+
+cat > src/cservice.h << 'END'
+int c_service_mu (void);
+END
+
+cat > src/cservice.vapi <<'END'
+namespace CService {
+  public class Mu {
+    [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")]
+    public int call ();
+  }
+}
+END
+
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+
+$MAKE
+test -f src/libatest_0_la_vala.stamp
+test -f src/libatest-0.la
+
+$MAKE distcheck
+
+:
+
diff --git a/t/vala-libs-vpath.sh b/t/vala-libs-vpath.sh
new file mode 100644
index 0000000..330ce23
--- /dev/null
+++ b/t/vala-libs-vpath.sh
@@ -0,0 +1,108 @@
+#! /bin/sh
+# Copyright (C) 2012-2016 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
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Building libraries (libtool and static) from Vala sources.
+# And use of vapi files to call C code from Vala.
+
+required="valac cc pkg-config libtoolize GNUmake"
+am_create_testdir=empty
+. test-init.sh
+
+cat >> configure.ac << 'END'
+AC_INIT([valalibs],[0.1])
+
+AC_CONFIG_MACRO_DIR([m4])
+
+AM_INIT_AUTOMAKE
+AM_PROG_AR
+LT_INIT
+
+AC_PROG_CC
+AC_CONFIG_FILES([Makefile src/Makefile])
+
+AM_PROG_VALAC([0.7.3])
+PKG_CHECK_MODULES([GOBJECT], [gobject-2.0 >= 2.4])
+
+AC_OUTPUT
+END
+
+
+cat > Makefile.am << 'END'
+SUBDIRS=src
+END
+
+mkdir src
+
+cat > src/Makefile.am << 'END'
+AUTOMAKE_OPTIONS = subdir-objects
+lib_LTLIBRARIES = libservice.la
+libservice_la_SOURCES = service.vala cservice.c cservice.h
+libservice_la_CPPFLAGS = -DOKOKIMDEFINED=1
+libservice_la_VALAFLAGS = --vapidir=$(srcdir) --pkg cservice --library service
+AM_CFLAGS = $(GOBJECT_CFLAGS)
+END
+
+libtoolize
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+cat > src/cservice.c << 'END'
+#include "cservice.h"
+int c_service_mu_call (void)
+{
+  return OKOKIMDEFINED;
+}
+END
+
+cat > src/cservice.h << 'END'
+int c_service_mu (void);
+END
+
+cat > src/cservice.vapi <<'END'
+namespace CService {
+  public class Mu {
+    [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")]
+    public int call ();
+  }
+}
+END
+
+cat > src/service.vala << 'END'
+namespace CService {
+public class Generator : Object {
+	public Generator () {
+		stdout.printf ("construct generator");
+	}
+	public void init () {
+		stdout.printf ("init generator");
+	}
+}
+}
+END
+
+mkdir build
+cd build
+../configure
+
+$MAKE
+pwd
+test -f src/libservice_la_vala.stamp
+test -f src/libservice.la
+
+
+:
+
diff --git a/t/vala-libs.sh b/t/vala-libs.sh
index badd538..6251118 100644
--- a/t/vala-libs.sh
+++ b/t/vala-libs.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2012-2015 Free Software Foundation, Inc.
+# Copyright (C) 2012-2016 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
@@ -32,11 +32,11 @@ END
 
 cat > Makefile.am << 'END'
 AUTOMAKE_OPTIONS = subdir-objects
-lib_LIBRARIES = libmu.a
+lib_LIBRARIES = libservice.a
 lib_LTLIBRARIES = src/libzardoz.la
-libmu_a_SOURCES = mu.vala mu2.c mu.vapi mu2.h
-libmu_a_CPPFLAGS = -DOKOKIMDEFINED=1
-libmu_a_VALAFLAGS = --vapidir=$(srcdir)
+libservice_a_SOURCES = service.vala cservice.c cservice.h
+libservice_a_CPPFLAGS = -DOKOKIMDEFINED=1
+libservice_a_VALAFLAGS = --vapidir=$(srcdir) --pkg cservice --library service
 AM_CFLAGS = $(GOBJECT_CFLAGS)
 src_libzardoz_la_LIBADD = $(GOBJECT_LIBS)
 src_libzardoz_la_SOURCES = src/zardoz-foo.vala src/zardoz-bar.vala
@@ -51,28 +51,37 @@ $AUTOMAKE -a
 
 ./configure
 
-cat > mu2.c << 'END'
-#include "mu2.h"
-int mu2 (void)
+cat > cservice.c << 'END'
+#include "cservice.h"
+int c_service_mu_call (void)
 {
   return OKOKIMDEFINED;
 }
 END
 
-cat > mu2.h << 'END'
-int mu2 (void);
+cat > cservice.h << 'END'
+int c_service_mu (void);
 END
 
-cat > mu.vapi <<'END'
-[CCode (cheader_filename = "mu2.h", cname = "mu2")]
-public int c_mu2 ();
+cat > cservice.vapi <<'END'
+namespace CService {
+  public class Mu {
+    [CCode (cheader_filename = "cservice.h", cname = "c_service_mu_call")]
+    public int call ();
+  }
+}
 END
 
-cat > mu.vala << 'END'
-int main ()
-{
-  stdout.printf ("mumumu\n");
-  return c_mu2 ();
+cat > service.vala << 'END'
+namespace CService {
+public class Generator : Object {
+	public Generator () {
+		stdout.printf ("construct generator");
+	}
+	public void init () {
+		stdout.printf ("init generator");
+	}
+}
 }
 END
 
@@ -87,12 +96,12 @@ public class Foo {
 END
 
 $MAKE
-test -f libmu.a
+test -f libservice.a
 test -f src/libzardoz.la
-$FGREP "mumumu" mu.c
+$FGREP "construct generator" service.c
 $FGREP "FooFooFoo" src/zardoz-foo.c
 $FGREP "BarBarBar" src/zardoz-bar.c
-test -f libmu_a_vala.stamp
+test -f libservice_a_vala.stamp
 test -f src_libzardoz_la_vala.stamp
 
 $MAKE distcheck
diff --git a/t/vala-vpath.sh b/t/vala-vpath.sh
index fdb802f..2cb2209 100644
--- a/t/vala-vpath.sh
+++ b/t/vala-vpath.sh
@@ -73,6 +73,7 @@ $MAKE
 test -f ../foo_vala.stamp
 test -f ../bar_vala.stamp
 grep barbarbar ../hello.c
+$MAKE distcheck
 
 # Rebuild rules are not uselessly triggered.
 $MAKE -q
-- 
2.8.1