Initial support for the vala programming language.
authorMathias Hasselmann <mathias.hasselmann@gmx.de>
Thu, 9 Oct 2008 18:06:20 +0000 (20:06 +0200)
committerRalf Wildenhues <Ralf.Wildenhues@gmx.de>
Thu, 9 Oct 2008 18:07:07 +0000 (20:07 +0200)
* automake.in: Add %known_libraries, lang_vala_rewrite,
lang_vala_finish and lang_vala_target_hook to support the Vala
programming language. Register Vala language hooks.
* lib/am/vala.am: Empty rules file to prevent creation of depend2
based rules for Vala code.
* lib/am/Makefile.am (dist_am_DATA): Add vala.am.
* m4/vala.m4: Provide AC_PROG_VALAC for detecting the Vala compiler.
* m4/Makefile.am (dist_m4data_DATA): Add vala.m4.
* tests/vala.test: Test Vala support.
* tests/Makefile.am: Update.

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

index cff858f..d81a06a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+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
+       programming language. Register Vala language hooks.
+       * lib/am/vala.am: Empty rules file to prevent creation of depend2
+       based rules for Vala code.
+       * lib/am/Makefile.am (dist_am_DATA): Add vala.am.
+       * m4/vala.m4: Provide AC_PROG_VALAC for detecting the Vala compiler.
+       * m4/Makefile.am (dist_m4data_DATA): Add vala.m4.
+       * tests/vala.test: Test Vala support.
+       * tests/Makefile.am: Update.
+
 2008-10-08  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
 
        Require texi2dvi in tests, makeinfo may not be enough.
index 4e53484..4e66ae0 100755 (executable)
@@ -545,6 +545,7 @@ my @dist_targets;
 # Keep track of all programs declared in this Makefile, without
 # $(EXEEXT).  @substitution@ are not listed.
 my %known_programs;
+my %known_libraries;
 
 # Keys in this hash are the basenames of files which must depend on
 # ansi2knr.  Values are either the empty string, or the directory in
@@ -666,6 +667,7 @@ sub initialize_per_input ()
     @dist_targets = ();
 
     %known_programs = ();
+    %known_libraries= ();
 
     %de_ansi_files = ();
 
@@ -776,6 +778,22 @@ register_language ('name' => 'header',
                   # Nothing to do.
                   '_finish' => sub { });
 
+# Vala
+register_language ('name' => 'vala',
+                  'Name' => 'Vala',
+                  'config_vars' => ['VALAC'],
+                  'flags' => ['VALAFLAGS'],
+                  'compile' => '$(VALAC) $(VALAFLAGS) $(AM_VALAFLAGS)',
+                  'compiler' => 'VALACOMPILE',
+                  'extensions' => ['.vala'],
+                  'output_extensions' => sub { (my $ext1 = $_[0]) =~ s/vala$/c/;
+                                               (my $ext2 = $_[0]) =~ s/vala$/h/;
+                                               return ($ext1, $ext2) },
+                  'rule_file' => 'vala',
+                  '_finish' => \&lang_vala_finish,
+                  '_target_hook' => \&lang_vala_target_hook,
+                  'nodist_specific' => 1);
+
 # Yacc (C & C++).
 register_language ('name' => 'yacc',
                   'Name' => 'Yacc',
@@ -2535,6 +2553,8 @@ 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);
@@ -2710,6 +2730,8 @@ sub handle_ltlibraries
     {
       my ($where, $onelib) = @$pair;
 
+      $known_libraries{$onelib} = $where;
+
       my $seen_libobjs = 0;
       my $obj = get_object_extension '.lo';
 
@@ -5443,6 +5465,16 @@ sub lang_header_rewrite
     return LANG_IGNORE;
 }
 
+# Rewrite a single Vala source file.
+sub lang_vala_rewrite
+{
+    my ($directory, $base, $ext) = @_;
+
+    my $r = &lang_sub_obj;
+    (my $newext = $ext) =~ s/vala$/c/;
+    return ($r, $newext);
+}
+
 # Rewrite a single yacc file.
 sub lang_yacc_rewrite
 {
@@ -5601,6 +5633,46 @@ sub lang_c_finish
     }
 }
 
+# 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);
+
+      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/);
+            }
+       }
+
+      $output_rules .=
+        "${xname}_vala.stamp: \$(${xname}_SOURCES)\n".
+        "\t\$(VALACOMPILE) \$^ && touch \$@\n";
+    }
+}
+
+# This is a vala helper which is called whenever we have decided to
+# compile a vala file.
+sub lang_vala_target_hook
+{
+  my ($self, $aggregate, $output, $input, %transform) = @_;
+
+  (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//;
+  my $header = $output_base . '.h';
+
+  &push_dist_common ($header);
+
+  $clean_files{$header} = MAINTAINER_CLEAN;
+  $clean_files{$output} = MAINTAINER_CLEAN;
+}
+
 # This is a yacc helper which is called whenever we have decided to
 # compile a yacc file.
 sub lang_yacc_target_hook
index 9767496..f6fdafa 100644 (file)
@@ -59,4 +59,5 @@ tags.am \
 texi-vers.am \
 texibuild.am \
 texinfos.am \
+vala.am \
 yacc.am
index 3454015..847657c 100644 (file)
@@ -201,6 +201,7 @@ tags.am \
 texi-vers.am \
 texibuild.am \
 texinfos.am \
+vala.am \
 yacc.am
 
 all: all-am
diff --git a/lib/am/vala.am b/lib/am/vala.am
new file mode 100644 (file)
index 0000000..e69de29
index 9f5e1c2..fd7c71c 100644 (file)
@@ -55,7 +55,8 @@ sanity.m4 \
 strip.m4 \
 substnot.m4 \
 tar.m4 \
-upc.m4
+upc.m4 \
+vala.m4
 
 EXTRA_DIST = dirlist amversion.in
 
index b2aaa6c..0a81dc9 100644 (file)
@@ -197,7 +197,8 @@ sanity.m4 \
 strip.m4 \
 substnot.m4 \
 tar.m4 \
-upc.m4
+upc.m4 \
+vala.m4
 
 EXTRA_DIST = dirlist amversion.in
 all: all-am
diff --git a/m4/vala.m4 b/m4/vala.m4
new file mode 100644 (file)
index 0000000..ce2474e
--- /dev/null
@@ -0,0 +1,36 @@
+# Autoconf support for the Vala compiler
+
+# Copyright (C) 2007 Free Software Foundation, Inc.
+#
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 2
+
+# 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.
+#
+# Author: Mathias Hasselmann <mathias.hasselmann@gmx.de>
+#
+# AC_PROG_VALAC([MINIMUM-VERSION])
+# --------------------------------------------------------------------------
+AC_DEFUN([AC_PROG_VALAC],[
+  AC_PATH_PROG([VALAC], [valac], [])
+  AC_SUBST(VALAC)
+
+  if test -z "${VALAC}"; then
+    AC_MSG_WARN([No Vala compiler found. You will not be able to recompile .vala source files.])
+  elif test -n "$1"; then
+    AC_REQUIRE([AC_PROG_AWK])
+    AC_MSG_CHECKING([valac is at least version $1])
+
+    if "${VALAC}" --version | "${AWK}" -v r='$1' 'function vn(s) { if (3 == split(s,v,".")) return (v[1]*1000+v[2])*1000+v[3]; else exit 2; } /^Vala / { exit vn(r) > vn($[2]) }'; then
+      AC_MSG_RESULT([yes])
+    else
+      AC_MSG_RESULT([no])
+      AC_MSG_ERROR([Vala $1 not found.])
+    fi
+  fi
+])
index 7f9ff9f..1114b27 100644 (file)
@@ -627,6 +627,7 @@ unused.test \
 upc.test \
 upc2.test \
 upc3.test \
+vala.test \
 vars.test \
 vars3.test \
 vartar.test \
index 5ceb18f..947655b 100644 (file)
@@ -779,6 +779,7 @@ unused.test \
 upc.test \
 upc2.test \
 upc3.test \
+vala.test \
 vars.test \
 vars3.test \
 vartar.test \
diff --git a/tests/vala.test b/tests/vala.test
new file mode 100755 (executable)
index 0000000..adbf2af
--- /dev/null
@@ -0,0 +1,58 @@
+#! /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 source.
+
+required="libtool"
+. ./defs || exit 1
+
+set -e
+
+cat >> 'configure.in' << 'END'
+AC_PROG_CC
+AC_PROG_LIBTOOL
+AC_PROG_VALAC
+AC_OUTPUT
+END
+
+cat > 'Makefile.am' <<'END'
+bin_PROGRAMS = zardoz
+zardoz_SOURCES = zardoz.vala
+
+lib_LTLIBRARIES = libzardoz.la
+libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala
+END
+
+: > ltmain.sh
+: > config.sub
+: > config.guess
+
+$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'