From c97d41b6cf5805d18c8541e290344182267be3f8 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Thu, 7 Jun 2012 17:04:26 +0200 Subject: [PATCH] [ng] cleanup: after enabling of subdir-objects unconditionally Few minor cleanups made possible by earlier changes, plus other minor cleanups triggered in cascade. No semantic change is intended. * automake.in (LANG_IGNORE, LANG_SUBDIR): Remove. (register_language ('name' => 'vala', ...)): Add '.vapi' to the entry 'extensions', and simplify the entry 'output_extensions' to point to a dummy subroutine (since it wasn't really used anyway). (handle_single_transform): Don't expect the 'lang_*_rewrite' subroutines to return a 'LANG_*' constant anymore, but only a transformed extension, if required. To decide whether further processing of the source file should be stopped, rely on a new set of 'lang_*_ignore' subroutines, defaulting to a subroutine that returns false. Accordingly, don't special case the handling of '.vapi' files anymore, instead relying on ... (lang_vala_ignore, lang_header_ignore): ... these new subroutines to avoid extra processing of C/C++ headers and Vala '.vapi' headers. (lang_c_rewrite): Adjust to explicitly return an undefined value. (lang_java_rewrite): Remove. Remove an outdated comment. Signed-off-by: Stefano Lattarini --- automake.in | 105 ++++++++++++++++++++++------------------------------ 1 file changed, 44 insertions(+), 61 deletions(-) diff --git a/automake.in b/automake.in index 14b328af8..21a02a68d 100644 --- a/automake.in +++ b/automake.in @@ -281,13 +281,6 @@ my $gen_copyright = "\ # PARTICULAR PURPOSE. "; -# These constants are returned by the lang_*_rewrite functions. -# LANG_SUBDIR means that the resulting object file should be in a -# subdir if the source file is. In this case the file name cannot -# have '..' components. -use constant LANG_IGNORE => 0; -use constant LANG_SUBDIR => 2; - # These are used when keeping track of whether an object can be built # by two different paths. use constant COMPILE_LIBTOOL => 1; @@ -801,7 +794,7 @@ register_language ('name' => 'header', # Nothing to do. '_finish' => sub { }); -# Vala +# Vala. register_language ('name' => 'vala', 'Name' => 'Vala', 'config_vars' => ['VALAC'], @@ -809,9 +802,10 @@ register_language ('name' => 'vala', 'compile' => '$(VALAC) $(AM_VALAFLAGS) $(VALAFLAGS)', 'ccer' => 'VALAC', 'compiler' => 'VALACOMPILE', - 'extensions' => ['.vala'], - 'output_extensions' => sub { (my $ext = $_[0]) =~ s/vala$/c/; - return ($ext,) }, + 'extensions' => ['.vala', '.vapi'], + # Vala compilation must be handled in a special way, so + # nothing to do or return here. + 'output_extensions' => sub { }, 'rule_file' => 'vala', '_finish' => \&lang_vala_finish, '_target_hook' => \&lang_vala_target_hook, @@ -1666,20 +1660,24 @@ sub handle_single_transform ($$$$$%) } } - # Note: computed subr call. The language rewrite function - # should return one of the LANG_* constants. It could - # also return a list whose first value is such a constant - # and whose second value is a new source extension which - # should be applied. This means this particular language - # generates another source file which we must then process - # further. - my $subr = \&{'lang_' . $lang->name . '_rewrite'}; - defined &$subr or $subr = sub { return LANG_SUBDIR; }; - my ($r, $source_extension) - = &$subr ($directory, $base, $extension, - $obj, $have_per_exec_flags, $var); - # Skip this entry if we were asked not to process it. - next if $r == LANG_IGNORE; + # NOTE: computed subr calls here. + + # The language ignore function can ask not to preprocess + # a source file further. + my $subr_ignore = \&{'lang_' . $lang->name . '_ignore'}; + next if defined &$subr_ignore + and &$subr_ignore ($directory, $base, $extension); + # The language rewrite function can return a new source + # extension which should be applied. This means this + # particular language generates another source file which + # we must then process further. This happens, for example, + # with yacc and lex. + my $subr_rewrite = \&{'lang_' . $lang->name . '_rewrite'}; + $subr_rewrite = sub { } unless defined &$subr_rewrite; + my $source_extension = &$subr_rewrite ($directory, $base, + $extension, $obj, + $have_per_exec_flags, + $var); # Now extract linker and other info. $linker = $lang->linker; @@ -1729,10 +1727,8 @@ sub handle_single_transform ($$$$$%) # If rewrite said it was ok, put the object into a # subdir. - if ($r == LANG_SUBDIR && $directory ne '') - { - $object = $directory . '/' . $object; - } + $object = $directory . '/' . $object + unless $directory eq ''; # If the object file has been renamed (because per-target # flags are used) we cannot compile the file with an @@ -1789,12 +1785,6 @@ sub handle_single_transform ($$$$$%) [@specifics, %transform]); } } - elsif ($extension eq '.vapi') - { - # Explicitly pass vala headers through. This is a bit of an - # hack, but good enough FTM. - next; - } else { # Assume the user has defined a proper explicit or pattern @@ -5068,11 +5058,6 @@ sub check_gnits_standards # # Functions to handle files of each language. -# Each 'lang_X_rewrite($DIRECTORY, $BASE, $EXT)' function follows a -# simple formula: Return value is LANG_SUBDIR if the resulting object -# file should be in a subdir if the source file is, LANG_PROCESS if -# file is to be dealt with, LANG_IGNORE otherwise. - # Much of the actual processing is handled in # handle_single_transform. These functions exist so that # auxiliary information can be recorded for a later cleanup pass. @@ -5105,33 +5090,38 @@ sub lang_c_rewrite uniq_part => 'AM_PROG_CC_C_O per-target'); } } - - return LANG_SUBDIR; + # Not a useless use of return: the caller of this subroutine will + # behave differently if a value is actually returned, and since perl + # returns the value of the last expressions seen by default, we + # need to explicitly return and undefined value. + return undef; } -# Rewrite a single header file. -sub lang_header_rewrite +# Header files are simply ignored. +sub lang_header_ignore { 1; } + +# Vala '.vapi' are a kind of header files as well, and should +# not be processed into compilation rules. + sub lang_vala_ignore { - # Header files are simply ignored. - return LANG_IGNORE; + my ($directory, $base, $ext) = @_; + return ($ext =~ m/\.vapi$/ ? 1 : 0); } # Rewrite a single Vala source file. sub lang_vala_rewrite { my ($directory, $base, $ext) = @_; - - (my $newext = $ext) =~ s/vala$/c/; - return (LANG_SUBDIR, $newext); + $ext =~ s/vala$/c/; + return $ext; } # Rewrite a single yacc/yacc++ file. sub lang_yacc_rewrite { my ($directory, $base, $ext) = @_; - - (my $newext = $ext) =~ tr/y/c/; - return (LANG_SUBDIR, $newext); + $ext =~ tr/y/c/; + return $ext; } sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); }; @@ -5139,18 +5129,11 @@ sub lang_yaccxx_rewrite { lang_yacc_rewrite (@_); }; sub lang_lex_rewrite { my ($directory, $base, $ext) = @_; - - (my $newext = $ext) =~ tr/l/c/; - return (LANG_SUBDIR, $newext); + $ext =~ tr/l/c/; + return $ext; } sub lang_lexxx_rewrite { lang_lex_rewrite (@_); }; -# Rewrite a single Java file. -sub lang_java_rewrite -{ - return LANG_SUBDIR; -} - # The lang_X_finish functions are called after all source file # processing is done. Each should handle defining rules for the # language, etc. A finish function is only called if a source file of -- 2.47.2