Hello, I ran into the issue/bug of having source files in my project that are not supposed to be handled by the valac compiler but Automake tries to pass them anyway. The attached patch now generates rules per file to compile .vala to .c. I think that some of the output rules can be moved to vala.am, but I need feedback on the general patch functionality before I make any further changes. I since it still passes all of the old tests and the new ones I created as well, I think there should be minimal impact as is, but I don't know about the other vala projects using Automake. I've read the automake 2009 mailing list threads on how vala handles code, and I'm not sure I understand why automake was trying to pass all the files at once and create a stamp (maybe I'm using a newer version of valac that works "correctly"?).
Basically, the patch takes code from yacc header output function, and changes it to support vala header file generation in lang_vala_target_hook. The per-file rules for converting .vala to .c are added at the end of lang_vala_target_hook as well. Per-library/program header file and vapi generation is handled by copying all of the vala specific source code to a temporary build directory where valac is used to generate a whole target .h or .vapi file. The .h/.vapi is then copied to the output directory and the temporary directory is removed. This is the cleanest way I could think of to do it and not have to worry about .c files being generated in the source code directory if you are trying to do a split build. Some other things to notice in the patch is the addition of the no_unique_rename flag in the language settings. I added this and some code to handle_single_transform to ensure that the output c source files were not renamed since that breaks the output rule generation currently. This rewrite may allow for renamed sources though, at which point this extra language flag can be removed. To generate headers now, you can pass a general -H,-h,--header,--internal-header flag in the AM_VALAFLAGS or <target>_VALAFLAGS and it will generate per file headers. It also allows a per-target header if you put one of the header flags with a filename after it, but it will report an error if you try to put a named header in the AM_VALAFLAGS or VALAFLAGS varaible. Same functionality goes for vapi generation. Thanks, Jason
From 0c6090e10a18704a48eca27e0de7e63190fad0b3 Mon Sep 17 00:00:00 2001 From: Jason Childs <obliv...@users.sourceforge.net> Date: Fri, 9 Jul 2010 14:47:15 -0400 Subject: [PATCH] Update Vala support. * automake.in: Rearchitect the vala code to split out .c source generation per-file rather than passing the _SOURCES all at once. This fixes handling of other file types that vala doesn't accept on its command line (e.g. yacc files). lang_vala_rewrite changed to match the generic way of handling sub objects. Modified lang_vala_finish_target and lang_vala_finish to be the handler for generating vapi and header files for programs and libraries. lang_vala_target_hook now provides headers per .vala file output rules. No longer generate stamp files since generated c source has its own rules. * doc/automake.texi: Add documentation for new AM_PROG_VAPIGEN macro. * m4/vala.m4: Add new AM_PROG_VAPIGEN macro that is used to find the path of the vapigen program used to generate vala api files for non vala projects. * tests/Makefile.am: Add new vala tests. * tests/Makefile.in: Generated from tests/Makefile.am. * tests/vala.test: Removed unnecessary .stamp file checks. * tests/vala1.test: Removed unnecessary .stamp file checks. * tests/vala6.test: Test AM_PROG_VAPIGEN macro. * tests/vala7.test: New test to check that other file types don't effect vala compilation. * tests/vala8.test: Test Vala header file generation. * tests/vala9.test: Test Vala API Generation. --- ChangeLog | 28 ++++ automake.in | 417 ++++++++++++++++++++++++++++++++++++++++------------- doc/automake.texi | 13 ++ m4/vala.m4 | 21 +++ tests/Makefile.am | 4 + tests/Makefile.in | 4 + tests/vala.test | 2 - tests/vala1.test | 2 - tests/vala6.test | 67 +++++++++ tests/vala7.test | 95 ++++++++++++ tests/vala8.test | 133 +++++++++++++++++ tests/vala9.test | 164 +++++++++++++++++++++ 12 files changed, 845 insertions(+), 105 deletions(-) create mode 100755 tests/vala6.test create mode 100755 tests/vala7.test create mode 100755 tests/vala8.test create mode 100755 tests/vala9.test diff --git a/ChangeLog b/ChangeLog index 4366381..a335bb4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2010-07-09 Jason Childs <obliv...@users.sourceforge.net> + + Update Vala support. + + * automake.in: Rearchitect the vala code to split out .c source + generation per-file rather than passing the _SOURCES all at once. + This fixes handling of other file types that vala doesn't accept on + its command line (e.g. yacc files). + lang_vala_rewrite changed to match the generic way of handling + sub objects. Modified lang_vala_finish_target and lang_vala_finish to + be the handler for generating vapi and header files for programs and + libraries. lang_vala_target_hook now provides headers per .vala + file output rules. No longer generate stamp files since generated + c source has its own rules. + * doc/automake.texi: Add documentation for new AM_PROG_VAPIGEN macro. + * m4/vala.m4: Add new AM_PROG_VAPIGEN macro that is used to find the + path of the vapigen program used to generate vala api files for non + vala projects. + * tests/Makefile.am: Add new vala tests. + * tests/Makefile.in: Generated from tests/Makefile.am. + * tests/vala.test: Removed unnecessary .stamp file checks. + * tests/vala1.test: Removed unnecessary .stamp file checks. + * tests/vala6.test: Test AM_PROG_VAPIGEN macro. + * tests/vala7.test: New test to check that other file types don't + effect vala compilation. + * tests/vala8.test: Test Vala header file generation. + * tests/vala9.test: Test Vala API Generation. + 2010-06-26 Ralf Wildenhues <ralf.wildenh...@gmx.de> Update program --help output to match current GCS. diff --git a/automake.in b/automake.in index 97280a9..bc05021 100644 --- a/automake.in +++ b/automake.in @@ -107,7 +107,12 @@ struct (# Short name of the language (c, f77...). # If TRUE, nodist_ sources will be compiled using specific rules # (i.e. not inference rules). The default is FALSE. - 'nodist_specific' => "\$"); + 'nodist_specific' => "\$", + + # Don't rename intermediate files. This allows a language to + # stop intermediate files that are not object files from being + # renamed. + 'no_unique_rename' => "\$"); sub finish ($) @@ -214,6 +219,13 @@ my $DASH_D_PATTERN = "(^|\\s)-d(\\s|\$)"; my $EXEC_DIR_PATTERN = '^(?:bin|sbin|libexec|sysconf|localstate|lib|pkglib|.*exec.*)' . "\$"; +# Match vala header command-line argument in a string. +my $DASH_H_PATTERN = "\\s?(-H|-h|--header|--internal-header)(\\s|=)?(\\S*\\.h)?"; + +# Match vala vapi commands-line arguments in a string. +my $DASH_VAPI_PATTERN = "\\s?(--vapi|--internal-vapi)(\\s|=)(\\S*\\.(vapi))"; + + # Values for AC_CANONICAL_* use constant AC_CANONICAL_BUILD => 1; use constant AC_CANONICAL_HOST => 2; @@ -815,7 +827,7 @@ register_language ('name' => 'header', register_language ('name' => 'vala', 'Name' => 'Vala', 'config_vars' => ['VALAC'], - 'flags' => [], + 'flags' => ['VALAFLAGS'], 'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)', 'ccer' => 'VALAC', 'compiler' => 'VALACOMPILE', @@ -825,7 +837,8 @@ register_language ('name' => 'vala', 'rule_file' => 'vala', '_finish' => \&lang_vala_finish, '_target_hook' => \&lang_vala_target_hook, - 'nodist_specific' => 1); + 'nodist_specific' => 1, + 'no_unique_rename' => 1); # Yacc (C & C++). register_language ('name' => 'yacc', @@ -1893,32 +1906,36 @@ sub handle_single_transform ($$$$$%) if ($have_per_exec_flags) { - # We have a per-executable flag in effect for this - # object. In this case we rewrite the object's - # name to ensure it is unique. - - # We choose the name `DERIVED_OBJECT' to ensure - # (1) uniqueness, and (2) continuity between - # invocations. However, this will result in a - # name that is too long for losing systems, in - # some situations. So we provide _SHORTNAME to - # override. - - my $dname = $derived; - my $var = var ($derived . '_SHORTNAME'); - if ($var) + if (! $lang->no_unique_rename) { - # FIXME: should use the same Condition as - # the _SOURCES variable. But this is really - # silly overkill -- nobody should have - # conditional shortnames. - $dname = $var->variable_value; - } - $object = $dname . '-' . $object; - - prog_error ($lang->name . " flags defined without compiler") - if ! defined $lang->compile; + # We have a per-executable flag in effect for this + # object. In this case we rewrite the object's + # name to ensure it is unique. + + # We choose the name `DERIVED_OBJECT' to ensure + # (1) uniqueness, and (2) continuity between + # invocations. However, this will result in a + # name that is too long for losing systems, in + # some situations. So we provide _SHORTNAME to + # override. + + my $dname = $derived; + my $var = var ($derived . '_SHORTNAME'); + if ($var) + { + # FIXME: should use the same Condition as + # the _SOURCES variable. But this is really + # silly overkill -- nobody should have + # conditional shortnames. + $dname = $var->variable_value; + } + $object = $dname . '-' . $object; + prog_error ($lang->name . " flags defined without compiler") + if ! defined $lang->compile; + } + # Still set renamed for no_unique_rename languages so that + # follow on processing still works the same. $renamed = 1; } @@ -5816,9 +5833,10 @@ sub lang_header_rewrite sub lang_vala_rewrite { my ($directory, $base, $ext) = @_; - + + my $r = &lang_sub_obj; (my $newext = $ext) =~ s/vala$/c/; - return (LANG_SUBDIR, $newext); + return ($r, $newext); } # Rewrite a single yacc file. @@ -5979,98 +5997,216 @@ sub lang_c_finish } } -sub lang_vala_finish_target ($$) +# parse and return flags and files associated with AM_, target and file +sub vala_parse_flags +{ + my ($target, $file) = @_; + + my $am_valaflags = var 'AM_VALAFLAGS' + if $target ne "AM_"; + my $target_valaflags = var ($target . '_VALAFLAGS'); + my $valaflags = var 'VALAFLAGS'; + (my $file_base = $file) =~ s/[\.-\/\\]/_/g + if $file; + my $file_valaflags = var ($file_base . '_VALAFLAGS') + if $file_base; + + # Grab headers that are per-target or per-file + (my $am_header = $am_valaflags->variable_value) =~ + s/$DASH_H_PATTERN/defined($3)?$3:q{}/e + if $am_valaflags && $am_valaflags->variable_value =~ /$DASH_H_PATTERN/o; + (my $user_header = $valaflags->variable_value) =~ + s/$DASH_H_PATTERN/defined($3)?$3:q{}/e + if $valaflags && $valaflags->variable_value =~ /$DASH_H_PATTERN/o; + my $target_header; + ($target_header = $target_valaflags->variable_value) =~ + s/$DASH_H_PATTERN/defined($3)?$3:q{}/e + if $target_valaflags && $target_valaflags->variable_value =~ + /$DASH_H_PATTERN/o; + my $header; + ($header = $file_valaflags->variable_value) =~ + s/$DASH_H_PATTERN/defined($3)?$3:q{}/e + if $file_valaflags && $file_valaflags->variable_value =~ + /$DASH_H_PATTERN/o; + + # Grab vapi files that are per-target or per-file + (my $am_vapi = $am_valaflags->variable_value) =~ + s/$DASH_VAPI_PATTERN/defined($3)?$3:q{}/e + if $am_valaflags && $am_valaflags->variable_value =~ + /$DASH_VAPI_PATTERN/o; + (my $user_vapi = $valaflags->variable_value) =~ + s/$DASH_VAPI_PATTERN/defined($3)?$3:q{}/e + if $valaflags && $valaflags->variable_value =~ /$DASH_VAPI_PATTERN/o; + my $target_vapi; + ($target_vapi = $target_valaflags->variable_value) =~ + s/$DASH_VAPI_PATTERN/defined($3)?$3:q{}/e + if $target_valaflags && $target_valaflags->variable_value =~ + /$DASH_VAPI_PATTERN/o; + my $vapi; + ($vapi = $file_valaflags->variable_value) =~ + s/$DASH_VAPI_PATTERN/defined($3)?$3:q{}/e + if $file_valaflags && $file_valaflags->variable_value =~ + /$DASH_VAPI_PATTERN/o; + + # Perform sanity checks + if ($am_header || $user_header || + ($target eq "AM_" && $target_header)) + { + err_am "Vala header file name cannot appear in AM_VALAFLAGS " . + "or VALAFLAGS"; + } + if ($am_vapi || $user_vapi || $vapi || + ($target eq "AM_" && $target_vapi)) + { + err_am "Vala VAPI file name cannot appear in AM_VALAFLAGS " . + ", VALAFLAGS or individual file VALAFLAGS"; + } + + # Create combined output flags for this target + my $output_flags = ""; + $output_flags .= " " . $am_valaflags->variable_value + if $am_valaflags; + $output_flags .= " " . $target_valaflags->variable_value + if $target_valaflags; + $output_flags .= " " . $valaflags->variable_value + if $valaflags; + $output_flags .= " " . $file_valaflags->variable_value + if $file_valaflags; + + my %info = ( 'OUTPUT_FLAGS' => $output_flags, + 'TARGET_HEADER' => $target_header, + 'FILE_HEADER' => $header, + 'TARGET_VAPI' => $target_vapi ); + + return %info; +} + +sub lang_vala_finish_target { - my ($self, $name) = @_; + my ($name) = @_; - my $derived = canonicalize ($name); - my $varname = $derived . '_SOURCES'; - my $var = var ($varname); + my $derived = canonicalize ($name); + my %info = vala_parse_flags ($derived); + my $var = var $derived . '_SOURCES'; + my @sources = $var->value_as_list_recursive; - if ($var) - { - foreach my $file ($var->value_as_list_recursive) - { - $output_rules .= "\$(srcdir)/$file: \$(srcdir)/${derived}_vala.stamp\n". - "\...@if test -f \$@; then :; else \\\n". - "\t rm -f \$(srcdir)/${derived}_vala.stamp; \\\n". - "\t \$(am__cd) \$(srcdir) && \$(MAKE) \$(AM_MAKEFLAGS) ${derived}_vala.stamp; \\\n". - "\tfi\n" - if $file =~ s/(.*)\.vala$/$1.c/; - } - } + my $output_header = $info{'TARGET_HEADER'}; + my $output_vapi = $info{'TARGET_VAPI'}; + my $output_flags = $info{'OUTPUT_FLAGS'}; + my $has_header_flags = ($output_flags =~ /$DASH_H_PATTERN/o); + my $distribute_header = ($output_flags =~ /(-H|--header)/o); + my $has_vapi_flags = ($output_flags =~ /$DASH_VAPI_PATTERN/o); + my $distribute_vapi = ($output_flags =~ /--vapi(\s|=|$)/o); + $output_flags =~ s/$DASH_H_PATTERN//g; + $output_flags =~ s/$DASH_VAPI_PATTERN//g; + + my $target_dir = dirname ($name); + (my $target_base = $name) =~ s/${target_dir}\/(\S*)\.\S*$/$1/; - # Add rebuild rules for generated header and vapi files - my $flags = var ($derived . '_VALAFLAGS'); - if ($flags) + # Build the header if a target header was specified + if ($output_header) { - my $lastflag = ''; - foreach my $flag ($flags->value_as_list_recursive) + # Found a header flag that applies to the compilation of this file. + # Add a dependency for the generated header file, and arrange + # for that file to be included in the distribution. + foreach my $cond (Automake::Rule::define (${output_header}, 'internal', + RULE_AUTOMAKE, TRUE, + INTERNAL)) { - if (grep (/$lastflag/, ('-H', '-h', '--header', '--internal-header', - '--vapi', '--internal-vapi', '--gir'))) + my $condstr = $cond->subst_string; + + # Distribute the generated file, unless its .vala source was + # listed in a nodist_ variable or it was defined as an internal + # header. (&handle_source_transform will set DIST_SOURCE.) + if ($distribute_header) { - my $headerfile = $flag; - $output_rules .= "\$(srcdir)/$headerfile: \$(srcdir)/${derived}_vala.stamp\n". - "\...@if test -f \$@; then :; else \\\n". - "\t rm -f \$(srcdir)/${derived}_vala.stamp; \\\n". - "\t \$(am__cd) \$(srcdir) && \$(MAKE) \$(AM_MAKEFLAGS) ${derived}_vala.stamp; \\\n". - "\tfi\n"; - - # valac is not used when building from dist tarballs - # distribute the generated files - push_dist_common ($headerfile); - $clean_files{$headerfile} = MAINTAINER_CLEAN; + &push_dist_common ($output_header); + # Append the header file to be built + $output_flags .= " -H " . $output_header; + } + else + { + # Append the internal header file flag + $output_flags .= " -h " . $output_header; } - $lastflag = $flag; - } - } - - my $compile = $self->compile; - - # Rewrite each occurrence of `AM_VALAFLAGS' in the compile - # rule into `${derived}_VALAFLAGS' if it exists. - my $val = "${derived}_VALAFLAGS"; - $compile =~ s/\(AM_VALAFLAGS\)/\($val\)/ - if set_seen ($val); - - # VALAFLAGS is a user variable (per GNU Standards), - # it should not be overridden in the Makefile... - check_user_variables ['VALAFLAGS']; - - my $dirname = dirname ($name); - # Only generate C code, do not run C compiler - $compile .= " -C"; + $output_rules .= "$condstr${output_header}:"; + foreach my $src (@sources) + { + if ($src =~ /(\.vala|\.c)$/o) + { + $output_rules .= " " . $src; + } + } + $output_rules .= "\n"; + $output_rules .= + "\tdir=`pwd`; tmp=`(umask 077 && mktemp -d \"\$(builddir)/.valaXXXXXX\") 2>/dev/null`; \\\n" . + "\tcp \$^ \$\$tmp; cd \$\$tmp; \\\n" . + "\t\$(VALAC) ${output_flags} -C \$^; \\\n" . + "\tcd \$\$dir; mv \$\$tmp/${output_header} .; \\\n" . + "\tif test -d \$\$tmp; then rm -r \$\$tmp; fi\n"; + } - my $verbose = verbose_flag ('VALAC'); - my $silent = silent_flag (); + # If the files are built in the build directory, then we want + # to remove them with `make clean'. If they are in srcdir + # they shouldn't be touched. However, we can't determine this + # statically, and the GNU rules say that vala output files + # should be removed by maintainer-clean. So that's what we + # do. + $clean_files{$output_header} = MAINTAINER_CLEAN; + } - $output_rules .= - "${derived}_vala.stamp: \$(${derived}_SOURCES)\n". - "\t${verbose}${compile} \$(${derived}_SOURCES)\n". - "\t${silent}touch \...@\n"; + if (! $output_vapi) + { + $output_vapi = $target_base . ".vapi"; + } + + if ($has_vapi_flags) + { + if ($distribute_vapi) + { + &push_dist_common ($output_vapi); + $output_flags .= " --vapi=${output_vapi}"; + } + else + { + $output_flags .= " --internal-vapi=${output_vapi}"; + } - push_dist_common ("${derived}_vala.stamp"); + $output_rules .= "${output_vapi}:"; + foreach my $src (@sources) + { + if ($src =~ /(\.vala|\.c)$/o) + { + $output_rules .= " " . $src; + } + } + $output_rules .= "\n"; + $output_rules .= + "\tdir=`pwd`; tmp=`(umask 077 && mktemp -d \"\$(builddir)/.valaXXXXXX\") 2>/dev/null`; \\\n" . + "\tcp \$^ \$\$tmp; cd \$\$tmp; \\\n" . + "\t\$(VALAC) ${output_flags} -C \$^; \\\n" . + "\tcd \$\$dir; mv \$\$tmp/${output_vapi} .; \\\n" . + "\tif test -d \$\$tmp; then rm -r \$\$tmp; fi\n"; - $clean_files{"${derived}_vala.stamp"} = MAINTAINER_CLEAN; + $clean_files{$output_vapi} = DIST_CLEAN; + } } -# Add output rules to invoke valac and create stamp file as a witness -# to handle multiple outputs. This function is called after all source -# file processing is done. +# Add output rules to invoke valac for api and combined header file generation. +# This function is called after all source file processing is done. sub lang_vala_finish { - my ($self) = @_; + my ($self) = @_; - foreach my $prog (keys %known_programs) + foreach my $prog (keys %known_programs) { - lang_vala_finish_target ($self, $prog); + lang_vala_finish_target ($prog); } - while (my ($name) = each %known_libraries) + foreach my $lib (keys %known_libraries) { - lang_vala_finish_target ($self, $name); + lang_vala_finish_target ($lib); } } @@ -6079,9 +6215,88 @@ sub lang_vala_finish # .vala source file. sub lang_vala_target_hook { - my ($self, $aggregate, $output, $input, %transform) = @_; + my ($self, $aggregate, $output, $input, %transform) = @_; + + my %info = vala_parse_flags ($aggregate, $input); + + # Grab headers that are user defined, per-target or per-file + my $header = $info{'FILE_HEADER'}; + my $output_flags = $info{'OUTPUT_FLAGS'}; + + # Grab header state and clear all header and api flags from output_flags. + my $has_header_flags = ($output_flags =~ /$DASH_H_PATTERN/o); + my $distribute_header = ($output_flags =~ /(-H|--header)/o); + $output_flags =~ s/$DASH_H_PATTERN//g; + $output_flags =~ s/$DASH_VAPI_PATTERN//g; + - $clean_files{$output} = MAINTAINER_CLEAN; + # Only build per-file headers if the target header was not specified + if ($has_header_flags && !$info{'TARGET_HEADER'}) + { + (my $output_base = $output) =~ s/$KNOWN_EXTENSIONS_PATTERN$//; + # Only redefine if the header name was not passed as a flag option. + $header = $output_base . '.h' + if ! $header; + + # Found a header flag that applies to the compilation of this file. + # Add a dependency for the generated header file, and arrange + # for that file to be included in the distribution. + foreach my $cond (Automake::Rule::define (${header}, 'internal', + RULE_AUTOMAKE, TRUE, + INTERNAL)) + { + my $condstr = $cond->subst_string; + $output_rules .= + "$condstr${header}: $output\n" + # Recover from removal of $header + . "$condstr...@if test ! -f \$@; then \\\n" + . "$condstr\t rm -f $output; \\\n" + . "$condstr\t \$(MAKE) \$(AM_MAKEFLAGS) $output; \\\n" + . "$condstr\telse :; fi\n"; + } + # Distribute the generated file, unless its .vala source was + # listed in a nodist_ variable or it was defined as an internal + # header. (&handle_source_transform will set DIST_SOURCE.) + if ($distribute_header) + { + &push_dist_common ($header) + if $transform{'DIST_SOURCE'}; + # Append the header file to be built + $output_flags .= " -H " . $header; + } + else + { + # Append the internal header file flag + $output_flags .= " -h " . $header; + } + + # If the files are built in the build directory, then we want + # to remove them with `make clean'. If they are in srcdir + # they shouldn't be touched. However, we can't determine this + # statically, and the GNU rules say that vala output files + # should be removed by maintainer-clean. So that's what we + # do. + $clean_files{$header} = MAINTAINER_CLEAN; + } + + $output_rules .= + "${output}: ${input}\n" . + "\t\$(VALAC) ${output_flags} -C \$<\n"; + + # Check if we need to move the output file since vala puts it + # wherever the .vala source is. + (my $new_output = $input) =~ s/.vala$/.c/; + if ($new_output ne $output) + { + $output_rules .= + "\tif test -f \$(top_builddir)/${new_output}; then \\\n" . + "\t \$(am__mv) \$(top_builddir)/${new_output} \$(top_builddir)/${output}; \\\n" . + "\tfi\n"; + } + + # Erase $OUTPUT on `make maintainer-clean' (by GNU standards). + # See the comment above for $HEADER. + $clean_files{$output} = MAINTAINER_CLEAN; } # This is a yacc helper which is called whenever we have decided to diff --git a/doc/automake.texi b/doc/automake.texi index 9f5b3bd..0bed166 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -6651,6 +6651,16 @@ AM_PROG_VALAC([0.7.0]) @end example @end defmac +...@defmac AM_PROG_VAPIGEN (@ovar{minimum-version}) +Try to find the Vala API Generator in @env{PATH}. If it is found, the +variable @code{VAPIGEN} is set. Optionally a minimum release number of +the api generator can be requested: + +...@example +AM_PROG_VAPIGEN([0.7.0]) +...@end example +...@end defmac + There are a few variables that are used when compiling Vala sources: @vtable @code @@ -6663,6 +6673,9 @@ Additional arguments for the Vala compiler. @item AM_VALAFLAGS The maintainer's variant of @code{VALAFLAGS}. +...@item VAPIGEN +Path to the Vala API Generator. + @example lib_LTLIBRARIES = libfoo.la libfoo_la_SOURCES = foo.vala diff --git a/m4/vala.m4 b/m4/vala.m4 index d95734a..0c79c8b 100644 --- a/m4/vala.m4 +++ b/m4/vala.m4 @@ -27,3 +27,24 @@ AC_DEFUN([AM_PROG_VALAC], [AC_MSG_RESULT([no]) AC_MSG_ERROR([Vala $1 not found.])])])]) ]) + +# Check whether the Vala api generator exists in `PATH'. If it is found, the +# variable VAPIGEN is set. Optionally a minimum release number of the +# api generator can be requested. +# +# AM_PROG_VAPIGEN([MINIMUM-VERSION]) +# -------------------------------- +AC_DEFUN([AM_PROG_VAPIGEN], +[AC_PATH_PROG([VAPIGEN], [vapigen], []) + AS_IF([test -z "$VAPIGEN"], + [AC_MSG_WARN([No Vala api generator found. You will not be able to generate vala api files for non vala projects.])], + [AS_IF([test -n "$1"], + [AC_MSG_CHECKING([$VAPIGEN is at least version $1]) + am__vapigen_version=`$VAPIGEN --version | sed 's/Vala API Generator *//'` + AS_VERSION_COMPARE([$1], ["$am__vapigen_version"], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([yes])], + [AC_MSG_RESULT([no]) + AC_MSG_ERROR([Vala api generator $1 not found.])])])]) +]) + diff --git a/tests/Makefile.am b/tests/Makefile.am index af20d3e..518b2c5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -773,6 +773,10 @@ vala2.test \ vala3.test \ vala4.test \ vala5.test \ +vala6.test \ +vala7.test \ +vala8.test \ +vala9.test \ vars.test \ vars3.test \ vartar.test \ diff --git a/tests/Makefile.in b/tests/Makefile.in index 592faa0..e09de10 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -984,6 +984,10 @@ vala2.test \ vala3.test \ vala4.test \ vala5.test \ +vala6.test \ +vala7.test \ +vala8.test \ +vala9.test \ vars.test \ vars3.test \ vartar.test \ diff --git a/tests/vala.test b/tests/vala.test index 3e9ae36..02018b8 100755 --- a/tests/vala.test +++ b/tests/vala.test @@ -52,8 +52,6 @@ $AUTOMAKE -a grep 'VALAC' Makefile.in grep 'am_zardoz_OBJECTS' Makefile.in grep 'am_libzardoz_la_OBJECTS' Makefile.in -grep 'zardoz_vala.stamp' Makefile.in -grep 'libzardoz_la_vala.stamp' Makefile.in grep 'zardoz\.c' Makefile.in grep 'zardoz-foo\.c' Makefile.in diff --git a/tests/vala1.test b/tests/vala1.test index d0cc241..d620c0c 100755 --- a/tests/vala1.test +++ b/tests/vala1.test @@ -52,7 +52,5 @@ $AUTOMAKE -a grep 'VALAC' Makefile.in grep 'src_zardoz_OBJECTS' Makefile.in grep 'src_libzardoz_la_OBJECTS' Makefile.in -grep 'src_zardoz_vala.stamp' Makefile.in -grep 'src_libzardoz_la_vala.stamp' Makefile.in grep 'zardoz\.c' Makefile.in grep 'src/zardoz-foo\.c' Makefile.in diff --git a/tests/vala6.test b/tests/vala6.test new file mode 100755 index 0000000..228d4f8 --- /dev/null +++ b/tests/vala6.test @@ -0,0 +1,67 @@ +#! /bin/sh +# Copyright (C) 2008, 2009 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 2, 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 AM_PROG_VAPIGEN. + +required=libtoolize +. ./defs || Exit 1 + +set -e + +cat >> configure.in << 'END' +AC_PROG_CC +AC_PROG_LIBTOOL +AM_PROG_VALAC([0.7.0]) +AM_PROG_VAPIGEN([0.0.1]) +AC_OUTPUT +END + +: > Makefile.am + +cat > vapigen << 'END' +#! /bin/sh +if test "x$1" = x--version; then + echo 1.2.3 +fi +exit 0 +END +chmod +x vapigen + +cwd=`pwd` + +# Use $cwd instead of `pwd` in the && list below to avoid a bug in +# the way Solaris/Heirloom Sh handles `set -e'. + +libtoolize +$ACLOCAL +$AUTOMAKE -a +$AUTOCONF +./configure "VAPIGEN=$cwd/vapigen" + +sed 's/AM_PROG_VAPIGEN.*/AM_PROG_VAPIGEN([9999.9])/' < configure.in >t +mv -f t configure.in +$AUTOCONF --force +./configure "VAPIGEN=$cwd/vapigen" && Exit 1 + +sed 's/AM_PROG_VAPIGEN.*/AM_PROG_VAPIGEN([1.2.3])/' < configure.in >t +mv -f t configure.in +$AUTOCONF --force +./configure "VAPIGEN=$cwd/vapigen" +: diff --git a/tests/vala7.test b/tests/vala7.test new file mode 100755 index 0000000..0df969e --- /dev/null +++ b/tests/vala7.test @@ -0,0 +1,95 @@ +#! /bin/sh +# Copyright (C) 1996, 2001, 2002, 2006, 2008, 2009 +# 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 2, 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 other files types in source are not passed to valac. + +required='libtool libtoolize pkg-config valac bison gcc' +. ./defs || Exit 1 + +set -e + +mkdir src + +cat >> configure.in << 'END' +AC_PROG_CC +AM_PROG_CC_C_O +AC_PROG_LIBTOOL +AC_PROG_YACC +AM_PROG_VALAC([0.7.0]) +PKG_PROG_PKG_CONFIG +PKG_CHECK_MODULES([GOBJECT],[gobject-2.0 >= 2.10]) +AC_CONFIG_FILES([src/Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +SUBDIRS = src +END + +cat > src/Makefile.am << 'END' +AM_YFLAGS = -d +AM_VALAFLAGS = -H +bin_PROGRAMS = zardoz +zardoz_CFLAGS = $(GOBJECT_CFLAGS) +zardoz_LDADD = $(GOBJECT_LIBS) +zardoz_SOURCES = parse.y zardoz.vala +END + +# Vala source. +cat > src/zardoz.vala << 'END' +using GLib; + +public class Zardoz { + public static void main () { + stdout.printf ("Zardoz!\n"); + } +} +END + +# First parser. +cat > src/parse.y << 'END' +%{ +int yylex() {return 0;} +void yyerror (char *s) {} +%} +%% +foobar : 'f' 'o' 'o' 'b' 'a' 'r' {}; +END + +libtoolize + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +grep '^#.*/src/\.\./' src/parse.c && Exit 1 + +grep 'VALAC' src/Makefile.in +grep 'am_zardoz_OBJECTS' src/Makefile.in +grep 'zardoz\.c' src/Makefile.in +grep 'AM_YFLAGS.*' src/Makefile.in + +test -x src/zardoz + +Exit 0 diff --git a/tests/vala8.test b/tests/vala8.test new file mode 100755 index 0000000..83ef176 --- /dev/null +++ b/tests/vala8.test @@ -0,0 +1,133 @@ +#! /bin/sh +# Copyright (C) 1996, 2001, 2002, 2006, 2008, 2009 +# 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 2, 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 vala header file generation. + +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([0.7.0]) +AM_PROG_VAPIGEN([0.7.0]) +PKG_PROG_PKG_CONFIG +PKG_CHECK_MODULES([GOBJECT],[gobject-2.0 >= 2.10]) +AC_CONFIG_FILES([libzardoz-1.0.pc src/Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +SUBDIRS = src +END + +cat > libzardoz-1.0.pc.in << 'END' +pref...@prefix@ +exec_pref...@exec_prefix@ +libd...@libdir@ +included...@includedir@ + +Name: LibZardoz +Description: Zardoz test library. +Requires: gobject-2.0 +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lzardoz-1.0 +Cflags: -I${includedir}/libzardoz-1.0 -I${libdir}/libzardoz-1.0/include +END + +cat > src/Makefile.am << 'END' +AM_VALAFLAGS = -H + +lib_LTLIBRARIES = libzardoz.la +libzardoz_la_CFLAGS = $(GOBJECT_CFLAGS) +libzardoz_la_LIBADD = $(GOBJECT_LIBS) +libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala +END + +# Vala source. +cat > src/zardoz-foo.vala << 'END' +using GLib; + +public class ZardozFoo { + public ZardozFoo() {} + public void do () { + stdout.printf ("ZardozFoo!\n"); + } +} +END + +cat > src/zardoz-bar.vala << 'END' +using GLib; + +public class ZardozBar { + public ZardozBar() {} + public void do () { + stdout.printf ("ZardozBar!\n"); + } +} +END + +libtoolize + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +grep 'VALAC' src/Makefile.in +grep 'am_libzardoz_la_OBJECTS' src/Makefile.in +grep 'zardoz-foo\.h' src/Makefile.in +grep 'zardoz-bar\.h' src/Makefile.in + +test -f src/libzardoz.la +test -f src/zardoz-foo.h +test -f src/zardoz-bar.h + +# Test target VALAFLAGS for header + +cat > src/Makefile.am << 'END' +lib_LTLIBRARIES = libzardoz.la +BUILT_SOURCES = libzardoz.h +libzardoz_la_CFLAGS = $(GOBJECT_CFLAGS) +libzardoz_la_LIBADD = $(GOBJECT_LIBS) +libzardoz_la_VALAFLAGS = --header libzardoz.h +libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala +END + +libtoolize + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +test -f src/libzardoz.h + +Exit 0 diff --git a/tests/vala9.test b/tests/vala9.test new file mode 100755 index 0000000..bdfeffd --- /dev/null +++ b/tests/vala9.test @@ -0,0 +1,164 @@ +#! /bin/sh +# Copyright (C) 1996, 2001, 2002, 2006, 2008, 2009 +# 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 2, 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 vala api generation. + +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([0.7.0]) +AM_PROG_VAPIGEN([0.7.0]) +PKG_PROG_PKG_CONFIG +PKG_CHECK_MODULES([GOBJECT],[gobject-2.0 >= 2.10]) +AC_CONFIG_FILES([libzardoz-1.0.pc src/Makefile]) +AC_OUTPUT +END + +cat > Makefile.am << 'END' +SUBDIRS = src +END + +cat > libzardoz-1.0.pc.in << 'END' +pref...@prefix@ +exec_pref...@exec_prefix@ +libd...@libdir@ +included...@includedir@ + +Name: LibZardoz +Description: Zardoz test library. +Requires: gobject-2.0 +Version: @PACKAGE_VERSION@ +Libs: -L${libdir} -lzardoz-1.0 +Cflags: -I${includedir}/libzardoz-1.0 -I${libdir}/libzardoz-1.0/include +END + +cat > src/Makefile.am << 'END' +AM_VALAFLAGS = -H +bin_PROGRAMS = zardoz +zardoz_CFLAGS = $(GOBJECT_CFLAGS) +zardoz_LDFLAGS = $(GOBJECT_LIBS) -lzardoz +zardoz_SOURCES = zardoz.vala +zardoz_VALAFLAGS = --vapidir=. --pkg zardoz + +lib_LTLIBRARIES = libzardoz.la +BUILT_SOURCES = zardoz.vapi +libzardoz_la_CFLAGS = $(GOBJECT_CFLAGS) +libzardoz_la_LIBADD = $(GOBJECT_LIBS) +libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala +libzardoz_la_VALAFLAGS = --vapi=zardoz.vapi +END + +# Vala source. +cat > src/zardoz.vala << 'END' +using GLib; + +public class Zardoz { + public static void main () { + ZardozFoo foo = new ZardozFoo(); + ZardozBar bar = new ZardozBar(); + + foo.do(); + bar.do(); + stdout.printf ("Zardoz!\n"); + } +} +END + +cat > src/zardoz-foo.vala << 'END' +using GLib; + +public class ZardozFoo { + public ZardozFoo() {} + public void do () { + stdout.printf ("ZardozFoo!\n"); + } +} +END + +cat > src/zardoz-bar.vala << 'END' +using GLib; + +public class ZardozBar { + public ZardozBar() {} + public void do () { + stdout.printf ("ZardozBar!\n"); + } +} +END + +libtoolize + +$ACLOCAL +$AUTOCONF +$AUTOMAKE -a + +./configure +$MAKE + +grep 'VALAC' src/Makefile.in +grep 'am_zardoz_OBJECTS' src/Makefile.in +grep 'am_libzardoz_la_OBJECTS' src/Makefile.in + +test -f src/libzardoz.la +test -f src/zardoz.vapi +test -x src/zardoz + +rm src/zardoz.vapi +rm src/zardoz + +cat > src/Makefile.am << 'END' +AM_VALAFLAGS = -H +bin_PROGRAMS = zardoz +zardoz_CFLAGS = $(GOBJECT_CFLAGS) +zardoz_LDFLAGS = $(GOBJECT_LIBS) -lzardoz +zardoz_SOURCES = zardoz.vala +zardoz_VALAFLAGS = zardoz.vapi + +lib_LTLIBRARIES = libzardoz.la +BUILT_SOURCES = zardoz.vapi +libzardoz_la_CFLAGS = $(GOBJECT_CFLAGS) +libzardoz_la_LIBADD = $(GOBJECT_LIBS) +libzardoz_la_SOURCES = zardoz-foo.vala zardoz-bar.vala +libzardoz_la_VALAFLAGS = --vapi=zardoz.vapi +END + +$AUTOMAKE -a + +./configure +$MAKE + +grep 'VALAC' src/Makefile.in +grep 'am_zardoz_OBJECTS' src/Makefile.in +grep 'am_libzardoz_la_OBJECTS' src/Makefile.in + +test -f src/libzardoz.la +test -f src/zardoz.vapi +test -x src/zardoz + +Exit 0 -- 1.7.0.4