>From 4e643fb45e6f7b87ebb6e8c8a68452d809630cb7 Mon Sep 17 00:00:00 2001 From: Mathias Hasselmann Date: Fri, 10 Oct 2008 07:38:12 +0200 Subject: [PATCH 2/4] Support Vala in non-recursive builds; more tests and fixes. * 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 Signed-off-by: Ralf Wildenhues --- ChangeLog | 13 ++++++++ NEWS | 4 ++ automake.in | 83 ++++++++++++++++++++++++++++++++++++++-------------- doc/automake.texi | 56 +++++++++++++++++++++++++++++++++++ m4/vala.m4 | 4 +- tests/Makefile.am | 3 ++ tests/Makefile.in | 3 ++ tests/vala.test | 23 ++++++++------ tests/vala1.test | 61 +++++++++++++++++++++++++++++++++++++++ tests/vala2.test | 54 ++++++++++++++++++++++++++++++++++ tests/vala3.test | 67 ++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 336 insertions(+), 35 deletions(-) create mode 100755 tests/vala1.test create mode 100755 tests/vala2.test create mode 100755 tests/vala3.test diff --git a/ChangeLog b/ChangeLog index 96b8a6e..4a41898 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2008-10-09 Mathias Hasselmann + * 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 + 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 1f88963..fd45cc0 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ New in 1.10c: +* Languages changes: + + - Vala 0.7.0 and later is supported now. + * Miscellaneous Changes: - In 1.10b, the `parallel-tests' driver introduced per-extension test diff --git a/automake.in b/automake.in index b8fd750..195b1fe 100755 --- a/automake.in +++ b/automake.in @@ -115,7 +115,7 @@ sub finish ($) my ($self) = @_; if (defined $self->_finish) { - &{$self->_finish} (); + &{$self->_finish} (@_); } } @@ -2707,8 +2707,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); @@ -2722,6 +2720,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); @@ -2888,8 +2888,6 @@ sub handle_ltlibraries { my ($where, $onelib) = @$pair; - $known_libraries{$onelib} = $where; - my $seen_libobjs = 0; my $obj = get_object_extension '.lo'; @@ -2929,6 +2927,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); @@ -5745,9 +5745,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. @@ -5908,28 +5907,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 address@hidden"; +} + # 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 address@hidden"; + while (my ($name, $pkgname) = each %known_libraries) + { + lang_vala_finish_target ($self, $name, $pkgname); } } diff --git a/doc/automake.texi b/doc/automake.texi index 77beee3..36814d1 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -224,6 +224,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 @@ -4533,6 +4534,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 @@ -6594,6 +6596,60 @@ using the @option{--main=} option. The easiest way to do this is to use the @code{_LDFLAGS} variable for the program. address@hidden Vala Support address@hidden node-name, next, previous, up address@hidden Vala Support + address@hidden Vala Support address@hidden Support for Vala + +Automake provides support for Vala compilation. + address@hidden +foo_SOURCES = foo.vala bar.vala zardoc.c address@hidden 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. + address@hidden AM_PROG_VALAC (address@hidden) + +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. + address@hidden +AM_PROG_VALAC([0.1.3]) address@hidden example + address@hidden defmac + +There are a few variables that are used when compiling Vala sources: + address@hidden @code + address@hidden VALAC +Path to the the Vala compiler. + address@hidden VALAFLAGS +Additional arguments for the Vala compiler. + address@hidden PKGNAME +The pkg-config and VAPI name to use when building Vala based library. + address@hidden +lib_LTLIBRARIES = libfoo.la +libfoo_la_PKGNAME = foo-2.0 +libfoo_la_SOURCES = foo.vala address@hidden example + address@hidden vtable + + @node Support for Other Languages @comment node-name, next, previous, up @section Support for Other Languages diff --git a/m4/vala.m4 b/m4/vala.m4 index ce2474e..57aae60 100644 --- a/m4/vala.m4 +++ b/m4/vala.m4 @@ -14,9 +14,9 @@ # # Author: Mathias Hasselmann # -# 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) diff --git a/tests/Makefile.am b/tests/Makefile.am index 3f95483..36a8983 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -691,6 +691,9 @@ upc.test \ upc2.test \ upc3.test \ vala.test \ +vala1.test \ +vala2.test \ +vala3.test \ vars.test \ vars3.test \ vartar.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 34de9b4..ea4bc8c 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -923,6 +923,9 @@ upc.test \ upc2.test \ upc3.test \ vala.test \ +vala1.test \ +vala2.test \ +vala3.test \ vars.test \ vars3.test \ vartar.test \ diff --git a/tests/vala.test b/tests/vala.test index adbf2af..d709cb2 100755 --- a/tests/vala.test +++ b/tests/vala.test @@ -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 index 0000000..086b312 --- /dev/null +++ b/tests/vala1.test @@ -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 index 0000000..03ce33c --- /dev/null +++ b/tests/vala2.test @@ -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 index 0000000..70aca27 --- /dev/null +++ b/tests/vala3.test @@ -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 + -- 1.6.2