Support Vala in non-recursive builds; more tests and fixes.
authorMathias Hasselmann <mathias.hasselmann@gmx.de>
Fri, 10 Oct 2008 05:38:12 +0000 (07:38 +0200)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Fri, 10 Oct 2008 05:38:12 +0000 (07:38 +0200)
* automake.in: Support Vala in non-recursive builds. Make sure
foo_VALAFLAGS really use used. Inject --library switch when building
Vala libraries.
* doc/automake.texi, NEWS: Document Vala support.
* m4/vala.m4: Rename AC_PROG_VALAC to AM_PROG_VALAC.
* tests/Makefile.am: Additional Vala tests.
* tests/vala.test: Also test VALAFLAGS support.
* tests/vala1.test: Test non-recursive Vala support.
* tests/vala2.test: Test _PKGNAME variables.
* tests/vala3.test: Test compiling of C code generated by Vala.

Signed-off-by: Mathias Hasselmann <mathias.hasselmann@gmx.de>
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
ChangeLog
NEWS
automake.in
doc/automake.texi
m4/vala.m4
tests/Makefile.am
tests/Makefile.in
tests/vala.test
tests/vala1.test [new file with mode: 0755]
tests/vala2.test [new file with mode: 0755]
tests/vala3.test [new file with mode: 0755]

index d81a06a..73bdf3f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2008-10-09  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
 
+       * automake.in: Support Vala in non-recursive builds. Make sure
+       foo_VALAFLAGS really use used. Inject --library switch when building
+       Vala libraries.
+       * doc/automake.texi, NEWS: Document Vala support.
+       * m4/vala.m4: Rename AC_PROG_VALAC to AM_PROG_VALAC.
+       * tests/Makefile.am: Additional Vala tests.
+       * tests/vala.test: Also test VALAFLAGS support.
+       * tests/vala1.test: Test non-recursive Vala support.
+       * tests/vala2.test: Test _PKGNAME variables.
+       * tests/vala3.test: Test compiling of C code generated by Vala.
+
+2008-10-09  Mathias Hasselmann  <mathias.hasselmann@gmx.de>
+
        Initial support for the vala programming language.
        * automake.in: Add %known_libraries, lang_vala_rewrite,
        lang_vala_finish and lang_vala_target_hook to support the Vala
diff --git a/NEWS b/NEWS
index 1a14ec6..7142c4a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ New in 1.10a:
 
   - Files with extension .sx are also treated as preprocessed assembler.
 
+  - Vala source files are recognized now.
+
 * Miscellaneous changes:
 
   - Automake development is done in a git repository on Savannah now, see
index 4e66ae0..4693704 100755 (executable)
@@ -111,7 +111,7 @@ sub finish ($)
   my ($self) = @_;
   if (defined $self->_finish)
     {
-      &{$self->_finish} ();
+      &{$self->_finish} (@_);
     }
 }
 
@@ -2553,8 +2553,6 @@ sub handle_libraries
     {
       my ($where, $onelib) = @$pair;
 
-      $known_libraries{$onelib} = $where;
-
       my $seen_libobjs = 0;
       # Check that the library fits the standard naming convention.
       my $bn = basename ($onelib);
@@ -2568,6 +2566,8 @@ sub handle_libraries
               . "did you mean `$suggestion'?")
        }
 
+      ($known_libraries{$onelib} = $bn) =~ s/\.a$//;
+
       $where->push_context ("while processing library `$onelib'");
       $where->set (INTERNAL->get);
 
@@ -2730,8 +2730,6 @@ sub handle_ltlibraries
     {
       my ($where, $onelib) = @$pair;
 
-      $known_libraries{$onelib} = $where;
-
       my $seen_libobjs = 0;
       my $obj = get_object_extension '.lo';
 
@@ -2771,6 +2769,8 @@ sub handle_ltlibraries
               . "did you mean `$suggestion'?")
        }
 
+      ($known_libraries{$onelib} = $bn) =~ s/\.la$//;
+
       $where->push_context ("while processing Libtool library `$onelib'");
       $where->set (INTERNAL->get);
 
@@ -5470,9 +5470,8 @@ sub lang_vala_rewrite
 {
     my ($directory, $base, $ext) = @_;
 
-    my $r = &lang_sub_obj;
     (my $newext = $ext) =~ s/vala$/c/;
-    return ($r, $newext);
+    return (LANG_SUBDIR, $newext);
 }
 
 # Rewrite a single yacc file.
@@ -5633,28 +5632,66 @@ sub lang_c_finish
     }
 }
 
+sub lang_vala_finish_target ($$$)
+{
+  my ($self, $name, $pkgname) = @_;
+
+  my $derived = canonicalize ($name);
+  my $varname = $derived . '_SOURCES';
+  my $var = var ($varname);
+
+  if ($var)
+    {
+      foreach my $file ($var->value_as_list_recursive)
+        {
+          $output_rules .= "$file: ${derived}_vala.stamp\n"
+            if ($file =~ s/(.*)\.vala$/$1.c $1.h/);
+        }
+    }
+
+  my $compile = $self->compile;
+
+  if (defined ($pkgname))
+    {
+      $varname = $derived . '_PKGNAME';
+      $var = var ($varname);
+
+      $pkgname = $var->variable_value if $var;
+      $compile =~s/\$\(AM_VALAFLAGS\)/--library=$pkgname $&/;
+    }
+
+  # Rewrite each occurrence of `AM_$flag' in the compile
+  # rule into `${derived}_$flag' if it exists.
+  for my $flag (@{$self->flags})
+    {
+      my $val = "${derived}_$flag";
+      $compile =~ s/\(AM_$flag\)/\($val\)/
+        if set_seen ($val);
+    }
+
+  my $dirname = dirname ($name);
+
+  $compile .= " -d $dirname" if $dirname ne '.';
+
+  $output_rules .=
+    "${derived}_vala.stamp: \$(${derived}_SOURCES)\n".
+    "\t${compile} \$^ && touch \$@\n";
+}
+
 # This is a vala helper which is called after all source file
 # processing is done.
 sub lang_vala_finish
 {
-  foreach my $name (keys %known_programs, keys %known_libraries)
-    {
-      my $xname = canonicalize ($name);
-      my $varname = $xname . '_SOURCES';
-      my $var = var ($varname);
+  my ($self) = @_;
 
-      if ($var)
-        {
-          foreach my $file ($var->value_as_list_recursive)
-            {
-              $output_rules .= "$file: ${xname}_vala.stamp\n"
-                if ($file =~ s/(.*)\.vala$/$1.c $1.h/);
-            }
-       }
+  foreach my $prog (keys %known_programs)
+    {
+      lang_vala_finish_target ($self, $prog, 0);
+    }
 
-      $output_rules .=
-        "${xname}_vala.stamp: \$(${xname}_SOURCES)\n".
-        "\t\$(VALACOMPILE) \$^ && touch \$@\n";
+  while (my ($name, $pkgname) = each %known_libraries)
+    {
+      lang_vala_finish_target ($self, $name, $pkgname);
     }
 }
 
index c2e0be5..a5fdc23 100644 (file)
@@ -217,6 +217,7 @@ Building Programs and Libraries
 * Fortran 77 Support::          Compiling Fortran 77 sources
 * Fortran 9x Support::          Compiling Fortran 9x sources
 * Java Support::                Compiling Java sources
+* Vala Support::                Compiling Vala sources
 * Support for Other Languages::  Compiling other languages
 * ANSI::                        Automatic de-ANSI-fication (obsolete)
 * Dependencies::                Automatic dependency tracking
@@ -4447,6 +4448,7 @@ to build programs and libraries.
 * Fortran 77 Support::          Compiling Fortran 77 sources
 * Fortran 9x Support::          Compiling Fortran 9x sources
 * Java Support::                Compiling Java sources
+* Vala Support::                Compiling Vala sources
 * Support for Other Languages::  Compiling other languages
 * ANSI::                        Automatic de-ANSI-fication (obsolete)
 * Dependencies::                Automatic dependency tracking
@@ -6496,6 +6498,60 @@ using the @option{--main=} option.  The easiest way to do this is to use
 the @code{_LDFLAGS} variable for the program.
 
 
+@node Vala Support
+@comment  node-name,  next,  previous,  up
+@section Vala Support
+
+@cindex Vala Support
+@cindex Support for Vala
+
+Automake provides support for Vala compilation.
+
+@example
+foo_SOURCES = foo.vala bar.vala zardoc.c
+@end example
+
+Any .vala file listed in a @code{_SOURCE} variable will be compiled
+into C code by the Vala compiler.
+
+Automake ships with an Autoconf macro called @code{AM_PROG_VALAC}
+that will locate the Vala compiler and optionally check its version
+number.
+
+@defmac AM_PROG_VALAC ([@var{MINIMUM-VERSION}])
+
+Check whether the Vala compiler exists in `PATH'. If it is found the
+variable VALAC is set. Optionally a minimum release number of the compiler
+can be requested.
+
+@example
+AM_PROG_VALAC([0.1.3])
+@end example
+
+@end defmac
+
+There are a few variables that are used when compiling Vala sources:
+
+@vtable @code
+
+@item VALAC
+Path to the the Vala compiler.
+
+@item VALAFLAGS
+Additional arguments for the Vala compiler.
+
+@item PKGNAME
+The pkg-config and VAPI name to use when building Vala based library.
+
+@example
+lib_LTLIBRARIES = libfoo.la
+libfoo_la_PKGNAME = foo-2.0
+libfoo_la_SOURCES = foo.vala
+@end example
+
+@end vtable
+
+
 @node Support for Other Languages
 @comment  node-name,  next,  previous,  up
 @section Support for Other Languages
index ce2474e..57aae60 100644 (file)
@@ -14,9 +14,9 @@
 #
 # Author: Mathias Hasselmann <mathias.hasselmann@gmx.de>
 #
-# AC_PROG_VALAC([MINIMUM-VERSION])
+# AM_PROG_VALAC([MINIMUM-VERSION])
 # --------------------------------------------------------------------------
-AC_DEFUN([AC_PROG_VALAC],[
+AC_DEFUN([AM_PROG_VALAC],[
   AC_PATH_PROG([VALAC], [valac], [])
   AC_SUBST(VALAC)
 
index 1114b27..a0bee69 100644 (file)
@@ -628,6 +628,9 @@ upc.test \
 upc2.test \
 upc3.test \
 vala.test \
+vala1.test \
+vala2.test \
+vala3.test \
 vars.test \
 vars3.test \
 vartar.test \
index 947655b..c986262 100644 (file)
@@ -780,6 +780,9 @@ upc.test \
 upc2.test \
 upc3.test \
 vala.test \
+vala1.test \
+vala2.test \
+vala3.test \
 vars.test \
 vars3.test \
 vartar.test \
index adbf2af..d709cb2 100755 (executable)
@@ -28,13 +28,14 @@ set -e
 cat >> 'configure.in' << 'END'
 AC_PROG_CC
 AC_PROG_LIBTOOL
-AC_PROG_VALAC
+AM_PROG_VALAC
 AC_OUTPUT
 END
 
 cat > 'Makefile.am' <<'END'
 bin_PROGRAMS = zardoz
 zardoz_SOURCES = zardoz.vala
+zardoz_VALAFLAGS = --debug
 
 lib_LTLIBRARIES = libzardoz.la
 libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala
@@ -47,12 +48,14 @@ END
 $ACLOCAL
 $AUTOMAKE -a
 
-grep -w 'am_zardoz_OBJECTS'            'Makefile.in'
-grep -w 'am_libzardoz_la_OBJECTS'      'Makefile.in'
-grep -w 'zardoz_vala.stamp'            'Makefile.in'
-grep -w 'libzardoz_la_vala.stamp'      'Makefile.in'
-grep -w 'VALACOMPILE'                  'Makefile.in'
-grep -w 'zardoz\.c'                    'Makefile.in'
-grep -w 'zardoz\.h'                    'Makefile.in'
-grep -w 'zardoz-foo\.c'                'Makefile.in'
-grep -w 'zardoz-foo\.h'                'Makefile.in'
+grep -w -- 'VALAC'                     'Makefile.in'
+grep -w -- 'am_zardoz_OBJECTS'         'Makefile.in'
+grep -w -- 'am_libzardoz_la_OBJECTS'   'Makefile.in'
+grep -w -- 'zardoz_vala.stamp'         'Makefile.in'
+grep -w -- 'libzardoz_la_vala.stamp'   'Makefile.in'
+grep -w -- '--library=libzardoz'       'Makefile.in'
+grep -w -- 'zardoz\.c'                         'Makefile.in'
+grep -w -- 'zardoz\.h'                         'Makefile.in'
+grep -w -- 'zardoz-foo\.c'             'Makefile.in'
+grep -w -- 'zardoz-foo\.h'             'Makefile.in'
+
diff --git a/tests/vala1.test b/tests/vala1.test
new file mode 100755 (executable)
index 0000000..086b312
--- /dev/null
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 1996, 2001, 2002, 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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 3, or (at your option)
+# any later version.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test to make sure intermediate .c files are built from vala sources
+# in non-recursive automake mode.
+
+required="libtool"
+. ./defs || exit 1
+
+set -e
+
+cat >> 'configure.in' << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AM_PROG_VALAC
+AC_OUTPUT
+END
+
+cat > 'Makefile.am' <<'END'
+bin_PROGRAMS = src/zardoz
+src_zardoz_SOURCES = src/zardoz.vala
+
+lib_LTLIBRARIES = src/libzardoz.la
+src_libzardoz_la_SOURCES = src/zardoz-foo.vala src/zardoz-bar.vala
+END
+
+: > ltmain.sh
+: > config.sub
+: > config.guess
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep -w -- 'VALAC'                             'Makefile.in'
+grep -w -- 'src_zardoz_OBJECTS'                        'Makefile.in'
+grep -w -- 'src_libzardoz_la_OBJECTS'          'Makefile.in'
+grep -w -- 'src_zardoz_vala.stamp'             'Makefile.in'
+grep -w -- 'src_libzardoz_la_vala.stamp'       'Makefile.in'
+grep -w -- '--library=libzardoz'               'Makefile.in'
+grep -w -- 'zardoz\.c'                                 'Makefile.in'
+grep -w -- 'zardoz\.h'                                 'Makefile.in'
+grep -w -- 'src/zardoz-foo\.c'                         'Makefile.in'
+grep -w -- 'src/zardoz-foo\.h'                         'Makefile.in'
+
diff --git a/tests/vala2.test b/tests/vala2.test
new file mode 100755 (executable)
index 0000000..03ce33c
--- /dev/null
@@ -0,0 +1,54 @@
+#! /bin/sh
+# Copyright (C) 1996, 2001, 2002, 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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 3, or (at your option)
+# any later version.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test to make foo_PKGNAME variables are considered.
+
+required="libtool"
+. ./defs || exit 1
+
+set -e
+
+cat >> 'configure.in' << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AM_PROG_VALAC
+AC_OUTPUT
+END
+
+cat > 'Makefile.am' <<'END'
+lib_LTLIBRARIES = src/libzardoz.la
+src_libzardoz_la_SOURCES = src/zardoz-foo.vala src/zardoz-bar.vala
+src_libzardoz_la_PKGNAME = zardoz+-3.0
+END
+
+: > ltmain.sh
+: > config.sub
+: > config.guess
+
+$ACLOCAL
+$AUTOMAKE -a
+
+grep -w -- 'VALAC'                             'Makefile.in'
+grep -w -- 'src_libzardoz_la_OBJECTS'          'Makefile.in'
+grep -w -- 'src_libzardoz_la_vala.stamp'       'Makefile.in'
+grep -w -- '--library=zardoz+-3.0'             'Makefile.in'
+grep -w -- 'src/zardoz-foo\.c'                         'Makefile.in'
+grep -w -- 'src/zardoz-foo\.h'                         'Makefile.in'
+
diff --git a/tests/vala3.test b/tests/vala3.test
new file mode 100755 (executable)
index 0000000..70aca27
--- /dev/null
@@ -0,0 +1,67 @@
+#! /bin/sh
+# Copyright (C) 1996, 2001, 2002, 2006  Free Software Foundation, Inc.
+#
+# This file is part of GNU Automake.
+#
+# GNU Automake 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 3, or (at your option)
+# any later version.
+#
+# GNU Automake 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 Automake; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Test to make sure compiling Vala code really works.
+
+required="libtool libtoolize pkg-config valac gcc"
+. ./defs || exit 1
+
+set -e
+
+mkdir src
+
+cat >> 'configure.in' << 'END'
+AC_PROG_CC
+AM_PROG_CC_C_O
+AC_PROG_LIBTOOL
+
+AM_PROG_VALAC
+
+PKG_CHECK_MODULES(GOBJECT,gobject-2.0 >= 2.10)
+
+AC_OUTPUT
+END
+
+cat > 'Makefile.am' <<'END'
+bin_PROGRAMS = src/zardoz
+src_zardoz_CFLAGS = $(GOBJECT_CFLAGS)
+src_zardoz_LDADD = $(GOBJECT_LIBS)
+src_zardoz_SOURCES = src/zardoz.vala
+END
+
+cat > 'src/zardoz.vala' <<'END'
+using GLib;
+
+public class Zardoz {
+  public static void main () {
+    stdout.printf ("Zardoz!\n");
+  }
+}
+END
+
+libtoolize
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE -a
+
+./configure
+make
+