�ɲɾ�����ӯ�����һ��ˣ��������С���˴��ͣ�������P���ҹ��ñ˽��ά�Բ��������˸߸ԣ�������ơ��ҹ��ñ�����ά�Բ���ˡ���˳^�ӣ������ӡ� ���ͯj�ӣ��ƺ���ӣ� ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!PKJ24]g hWrap.pmnu[# Copyright (C) 2003-2018 Free Software Foundation, Inc. # This program 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. # This program 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 this program. If not, see . package Automake::Wrap; use 5.006; use strict; require Exporter; use vars '@ISA', '@EXPORT_OK'; @ISA = qw/Exporter/; @EXPORT_OK = qw/wrap makefile_wrap/; =head1 NAME Automake::Wrap - a paragraph formatter =head1 SYNOPSIS use Automake::Wrap 'wrap', 'makefile_wrap'; print wrap ($first_ident, $next_ident, $end_of_line, $max_length, @values); print makefile_wrap ("VARIABLE = ", " ", @values); =head1 DESCRIPTION This modules provide facility to format list of strings. It is comparable to Perl's L, however we can't use L because some versions will abort when some word to print exceeds the maximum length allowed. (Ticket #17141, fixed in Perl 5.8.0.) =head2 Functions =over 4 =cut # _tab_length ($TXT) # ------------------ # Compute the length of TXT, counting tab characters as 8 characters. sub _tab_length($) { my ($txt) = @_; my $len = length ($txt); $len += 7 * ($txt =~ tr/\t/\t/); return $len; } =item C Format C<@values> as a block of text that starts with C<$head>, followed by the strings in C<@values> separated by spaces or by C<"$eol\n$fill"> so that the length of each line never exceeds C<$max_len>. The C<$max_len> constraint is ignored for C<@values> items which are too big to fit alone one a line. The constructed paragraph is C<"\n">-terminated. =cut sub wrap($$$$@) { my ($head, $fill, $eol, $max_len, @values) = @_; my $result = $head; my $column = _tab_length ($head); my $fill_len = _tab_length ($fill); my $eol_len = _tab_length ($eol); my $not_first_word = 0; foreach (@values) { my $len = _tab_length ($_); # See if the new variable fits on this line. # (The + 1 is for the space we add in front of the value.). if ($column + $len + $eol_len + 1 > $max_len # Do not break before the first word if it does not fit on # the next line anyway. && ($not_first_word || $fill_len + $len + $eol_len + 1 <= $max_len)) { # Start a new line. $result .= "$eol\n" . $fill; $column = $fill_len; } elsif ($not_first_word) { # Add a space only if result does not already end # with a space. $_ = " $_" if $result =~ /\S\z/; ++$len; } $result .= $_; $column += $len; $not_first_word = 1; } $result .= "\n"; return $result; } =item C Format C<@values> in a way which is suitable for Fs. This is comparable to C, except C<$eol> is known to be C<" \\">, and the maximum length has been hardcoded to C<72>. A space is appended to C<$head> when this is not already the case. This can be used to format variable definitions or dependency lines. makefile_wrap ('VARIABLE =', "\t", @values); makefile_wrap ('rule:', "\t", @dependencies); =cut sub makefile_wrap ($$@) { my ($head, $fill, @values) = @_; if (@values) { $head .= ' ' if $head =~ /\S\z/; return wrap $head, $fill, " \\", 72, @values; } return "$head\n"; } 1; PKJ24]S=''XFile.pmnu[# Copyright (C) 2001-2018 Free Software Foundation, Inc. # This program 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. # This program 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 this program. If not, see . # Written by Akim Demaille . ############################################################### # The main copy of this file is in Automake's git repository. # # Updates should be sent to automake-patches@gnu.org. # ############################################################### package Automake::XFile; =head1 NAME Automake::XFile - supply object methods for filehandles with error handling =head1 SYNOPSIS use Automake::XFile; $fh = new Automake::XFile; $fh->open ("file", "<"); # No need to check $FH: we died if open failed. print <$fh>; $fh->close; # No need to check the return value of close: we died if it failed. $fh = new Automake::XFile "file", ">"; # No need to check $FH: we died if new failed. print $fh "bar\n"; $fh->close; $fh = new Automake::XFile "file", "r"; # No need to check $FH: we died if new failed. defined $fh print <$fh>; undef $fh; # automatically closes the file and checks for errors. $fh = new Automake::XFile "file", O_WRONLY | O_APPEND; # No need to check $FH: we died if new failed. print $fh "corge\n"; $pos = $fh->getpos; $fh->setpos ($pos); undef $fh; # automatically closes the file and checks for errors. autoflush STDOUT 1; =head1 DESCRIPTION C inherits from C. It provides the method C returning the file name. It provides dying versions of the methods C, C (corresponding to C), C, C, C, and C. It also overrides the C and C methods to translate C<\r\n> to C<\n>. =cut use 5.006; use strict; use vars qw($VERSION @EXPORT @EXPORT_OK $AUTOLOAD @ISA); use Carp; use Errno; use IO::File; use File::Basename; use Automake::ChannelDefs; use Automake::Channels qw(msg); use Automake::FileUtils; require Exporter; require DynaLoader; @ISA = qw(IO::File Exporter DynaLoader); $VERSION = "1.2"; @EXPORT = @IO::File::EXPORT; eval { # Make all Fcntl O_XXX and LOCK_XXX constants available for importing require Fcntl; my @O = grep /^(LOCK|O)_/, @Fcntl::EXPORT, @Fcntl::EXPORT_OK; Fcntl->import (@O); # first we import what we want to export push (@EXPORT, @O); }; =head2 Methods =over =item C<$fh = new Automake::XFile ([$expr, ...]> Constructor a new XFile object. Additional arguments are passed to C, if any. =cut sub new { my $type = shift; my $class = ref $type || $type || "Automake::XFile"; my $fh = $class->SUPER::new (); if (@_) { $fh->open (@_); } $fh; } =item C<$fh-Eopen ([$file, ...])> Open a file, passing C<$file> and further arguments to C. Die if opening fails. Store the name of the file. Use binmode for writing. =cut sub open { my $fh = shift; my ($file, $mode) = @_; # WARNING: Gross hack: $FH is a typeglob: use its hash slot to store # the 'name' of the file we are opening. See the example with # io_socket_timeout in IO::Socket for more, and read Graham's # comment in IO::Handle. ${*$fh}{'autom4te_xfile_file'} = "$file"; if (!$fh->SUPER::open (@_)) { fatal "cannot open $file: $!"; } # In case we're running under MSWindows, don't write with CRLF. # (This circumvents a bug in at least Cygwin bash where the shell # parsing fails on lines ending with the continuation character '\' # and CRLF). # Correctly recognize usages like: # - open ($file, "w") # - open ($file, "+<") # - open (" >$file") binmode $fh if (defined $mode && $mode =~ /^[+>wa]/ or $file =~ /^\s*>/); } =item C<$fh-Eclose> Close the file, handling errors. =cut sub close { my $fh = shift; if (!$fh->SUPER::close (@_)) { my $file = $fh->name; Automake::FileUtils::handle_exec_errors $file unless $!; fatal "cannot close $file: $!"; } } =item C<$line = $fh-Egetline> Read and return a line from the file. Ensure C<\r\n> is translated to C<\n> on input files. =cut # Some native Windows/perl installations fail to translate \r\n to \n on # input so we do that here. sub getline { local $_ = $_[0]->SUPER::getline; # Perform a _global_ replacement: $_ may can contains many lines # in slurp mode ($/ = undef). s/\015\012/\n/gs if defined $_; return $_; } =item C<@lines = $fh-Egetlines> Slurp lines from the files. =cut sub getlines { my @res = (); my $line; push @res, $line while $line = $_[0]->getline; return @res; } =item C<$name = $fh-Ename> Return the name of the file. =cut sub name { my $fh = shift; return ${*$fh}{'autom4te_xfile_file'}; } =item C<$fh-Elock> Lock the file using C. If locking fails for reasons other than C being unsupported, then error out if C<$ENV{'MAKEFLAGS'}> indicates that we are spawned from a parallel C. =cut sub lock { my ($fh, $mode) = @_; # Cannot use @_ here. # Unless explicitly configured otherwise, Perl implements its 'flock' with the # first of flock(2), fcntl(2), or lockf(3) that works. These can fail on # NFS-backed files, with ENOLCK (GNU/Linux) or EOPNOTSUPP (FreeBSD); we # usually ignore these errors. If $ENV{MAKEFLAGS} suggests that a parallel # invocation of 'make' has invoked the tool we serve, report all locking # failures and abort. # # On Unicos, flock(2) and fcntl(2) over NFS hang indefinitely when 'lockd' is # not running. NetBSD NFS clients silently grant all locks. We do not # attempt to defend against these dangers. # # -j is for parallel BSD make, -P is for parallel HP-UX make. if (!flock ($fh, $mode)) { my $make_j = (exists $ENV{'MAKEFLAGS'} && " -$ENV{'MAKEFLAGS'}" =~ / (-[BdeikrRsSw]*[jP]|--[jP]|---?jobs)/); my $note = "\nforgo \"make -j\" or use a file system that supports locks"; my $file = $fh->name; msg ($make_j ? 'fatal' : 'unsupported', "cannot lock $file with mode $mode: $!" . ($make_j ? $note : "")) if $make_j || !($!{ENOLCK} || $!{EOPNOTSUPP}); } } =item C<$fh-Eseek ($position, [$whence])> Seek file to C<$position>. Die if seeking fails. =cut sub seek { my $fh = shift; # Cannot use @_ here. if (!seek ($fh, $_[0], $_[1])) { my $file = $fh->name; fatal "cannot rewind $file with @_: $!"; } } =item C<$fh-Etruncate ($len)> Truncate the file to length C<$len>. Die on failure. =cut sub truncate { my ($fh, $len) = @_; if (!truncate ($fh, $len)) { my $file = $fh->name; fatal "cannot truncate $file at $len: $!"; } } =back =head1 SEE ALSO L, L, L L L =head1 HISTORY Derived from IO::File.pm by Akim Demaille EFE. =cut 1; PKJ24]S6 Version.pmnu[# Copyright (C) 2001-2018 Free Software Foundation, Inc. # This program 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. # This program 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 this program. If not, see . package Automake::Version; use 5.006; use strict; use Automake::ChannelDefs; =head1 NAME Automake::Version - version comparison =head1 SYNOPSIS use Automake::Version; print "Version $version is older than required version $required\n" if Automake::Version::check ($version, $required); =head1 DESCRIPTION This module provides support for comparing versions string as they are used in Automake. A version is a string that looks like C where C, C, and C are digits, C is a character, and C any alphanumeric word. Usually, C is used to label alpha releases or intermediate snapshots, C is used for git branches or patched releases, and C is used for bug fixes releases on the C branch. For the purpose of ordering, C<1.4> is the same as C<1.4.0>, but C<1.4g> is the same as C<1.4.99g>. The C identifier is ignored in the ordering, except when it looks like C<-pMINOR[ALPHA]>: some versions were labeled like C<1.4-p3a>, this is the same as an alpha release labeled C<1.4.3a>. Yes, it's horrible, but Automake did not support two-dot versions in the past. =head2 FUNCTIONS =over 4 =item C Split the string C<$version> into the corresponding C<(MAJOR, MINOR, MICRO, ALPHA, FORK)> tuple. For instance C<'1.4g'> would be split into C<(1, 4, 99, 'g', '')>. Return C<()> on error. =cut sub split ($) { my ($ver) = @_; # Special case for versions like 1.4-p2a. if ($ver =~ /^(\d+)\.(\d+)(?:-p(\d+)([a-z]+)?)$/) { return ($1, $2, $3, $4 || '', ''); } # Common case. elsif ($ver =~ /^(\d+)\.(\d+)(?:\.(\d+))?([a-z])?(?:-([A-Za-z0-9]+))?$/) { return ($1, $2, $3 || (defined $4 ? 99 : 0), $4 || '', $5 || ''); } return (); } =item C Compare two version tuples, as returned by C. Return 1, 0, or -1, if C is found to be respectively greater than, equal to, or less than C. =cut sub compare (\@\@) { my @l = @{$_[0]}; my @r = @{$_[1]}; for my $i (0, 1, 2) { return 1 if ($l[$i] > $r[$i]); return -1 if ($l[$i] < $r[$i]); } for my $i (3, 4) { return 1 if ($l[$i] gt $r[$i]); return -1 if ($l[$i] lt $r[$i]); } return 0; } =item C Handles the logic of requiring a version number in Automake. C<$VERSION> should be Automake's version, while C<$REQUIRED> is the version required by the user input. Return 0 if the required version is satisfied, 1 otherwise. =cut sub check ($$) { my ($version, $required) = @_; my @version = Automake::Version::split ($version); my @required = Automake::Version::split ($required); prog_error "version is incorrect: $version" if $#version == -1; # This should not happen, because process_option_list and split_version # use similar regexes. prog_error "required version is incorrect: $required" if $#required == -1; # If we require 3.4n-foo then we require something # >= 3.4n, with the 'foo' fork identifier. return 1 if ($required[4] ne '' && $required[4] ne $version[4]); return 0 > compare (@version, @required); } 1; PKJ24]T Language.pmnu[# Copyright (C) 2013-2018 Free Software Foundation, Inc. # This program 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. # This program 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 this program. If not, see . package Automake::Language; use 5.006; use strict; use Class::Struct (); Class::Struct::struct ( # Short name of the language (c, f77...). 'name' => "\$", # Nice name of the language (C, Fortran 77...). 'Name' => "\$", # List of configure variables which must be defined. 'config_vars' => '@', # 'pure' is '1' or ''. A 'pure' language is one where, if # all the files in a directory are of that language, then we # do not require the C compiler or any code to call it. 'pure' => "\$", 'autodep' => "\$", # Name of the compiling variable (COMPILE). 'compiler' => "\$", # Content of the compiling variable. 'compile' => "\$", # Flag to require compilation without linking (-c). 'compile_flag' => "\$", 'extensions' => '@', # A subroutine to compute a list of possible extensions of # the product given the input extensions. # (defaults to a subroutine which returns ('.$(OBJEXT)', '.lo')) 'output_extensions' => "\$", # A list of flag variables used in 'compile'. # (defaults to []) 'flags' => "@", # Any tag to pass to libtool while compiling. 'libtool_tag' => "\$", # The file to use when generating rules for this language. # The default is 'depend2'. 'rule_file' => "\$", # Name of the linking variable (LINK). 'linker' => "\$", # Content of the linking variable. 'link' => "\$", # Name of the compiler variable (CC). 'ccer' => "\$", # Name of the linker variable (LD). 'lder' => "\$", # Content of the linker variable ($(CC)). 'ld' => "\$", # Flag to specify the output file (-o). 'output_flag' => "\$", '_finish' => "\$", # This is a subroutine which is called whenever we finally # determine the context in which a source file will be # compiled. '_target_hook' => "\$", # If TRUE, nodist_ sources will be compiled using specific rules # (i.e. not inference rules). The default is FALSE. 'nodist_specific' => "\$"); sub finish ($) { my ($self) = @_; if (defined $self->_finish) { &{$self->_finish} (@_); } } sub target_hook ($$$$%) { my ($self) = @_; if (defined $self->_target_hook) { $self->_target_hook->(@_); } } 1; PKJ24]j o^o^Rule.pmnu[# Copyright (C) 2003-2018 Free Software Foundation, Inc. # This program 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. # This program 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 this program. If not, see . package Automake::Rule; use 5.006; use strict; use Carp; use Automake::Item; use Automake::RuleDef; use Automake::ChannelDefs; use Automake::Channels; use Automake::Options; use Automake::Condition qw (TRUE FALSE); use Automake::DisjConditions; require Exporter; use vars '@ISA', '@EXPORT', '@EXPORT_OK'; @ISA = qw/Automake::Item Exporter/; @EXPORT = qw (reset register_suffix_rule next_in_suffix_chain suffixes rules $KNOWN_EXTENSIONS_PATTERN depend %dependencies %actions register_action accept_extensions reject_rule msg_rule msg_cond_rule err_rule err_cond_rule rule rrule ruledef rruledef); =head1 NAME Automake::Rule - support for rules definitions =head1 SYNOPSIS use Automake::Rule; use Automake::RuleDef; =head1 DESCRIPTION This package provides support for Makefile rule definitions. An C is a rule name associated to possibly many conditional definitions. These definitions are instances of C. Therefore obtaining the value of a rule under a given condition involves two lookups. One to look up the rule, and one to look up the conditional definition: my $rule = rule $name; if ($rule) { my $def = $rule->def ($cond); if ($def) { return $def->location; } ... } ... when it is known that the rule and the definition being looked up exist, the above can be simplified to return rule ($name)->def ($cond)->location; # do not write this. but is better written return rrule ($name)->rdef ($cond)->location; or even return rruledef ($name, $cond)->location; The I variants of the C, C, and C methods add an extra test to ensure that the lookup succeeded, and will diagnose failures as internal errors (with a message which is much more informative than Perl's warning about calling a method on a non-object). =head2 Global variables =over 4 =cut my $_SUFFIX_RULE_PATTERN = '^(\.[a-zA-Z0-9_(){}$+@\-]+)(\.[a-zA-Z0-9_(){}$+@\-]+)' . "\$"; my @_suffixes = (); my @_known_extensions_list = (); my %_rule_dict = (); # See comments in the implementation of the 'next_in_suffix_chain()' # variable for details. my %_suffix_rules; # Same as $suffix_rules, but records only the default rules # supplied by the languages Automake supports. my %_suffix_rules_builtin; =item C<%dependencies> Holds the dependencies of targets which dependencies are factored. Typically, C<.PHONY> will appear in plenty of F<*.am> files, but must be output once. Arguably all pure dependencies could be subject to this factoring, but it is not unpleasant to have paragraphs in Makefile: keeping related stuff altogether. =cut use vars '%dependencies'; =item <%actions> Holds the factored actions. Tied to C<%dependencies>, i.e., filled only when keys exists in C<%dependencies>. =cut use vars '%actions'; =item C<$KNOWN_EXTENSIONS_PATTERN> Pattern that matches all know input extensions (i.e. extensions used by the languages supported by Automake). Using this pattern (instead of '\..*$') to match extensions allows Automake to support dot-less extensions. New extensions should be registered with C. =cut use vars qw ($KNOWN_EXTENSIONS_PATTERN); $KNOWN_EXTENSIONS_PATTERN = ""; =back =head2 Error reporting functions In these functions, C<$rule> can be either a rule name, or an instance of C. =over 4 =item C Uncategorized errors about rules. =cut sub err_rule ($$;%) { msg_rule ('error', @_); } =item C Uncategorized errors about conditional rules. =cut sub err_cond_rule ($$$;%) { msg_cond_rule ('error', @_); } =item C Messages about conditional rules. =cut sub msg_cond_rule ($$$$;%) { my ($channel, $cond, $rule, $msg, %opts) = @_; my $r = ref ($rule) ? $rule : rrule ($rule); msg $channel, $r->rdef ($cond)->location, $msg, %opts; } =item C Messages about rules. =cut sub msg_rule ($$$;%) { my ($channel, $rule, $msg, %opts) = @_; my $r = ref ($rule) ? $rule : rrule ($rule); # Don't know which condition is concerned. Pick any. my $cond = $r->conditions->one_cond; msg_cond_rule ($channel, $cond, $r, $msg, %opts); } =item C<$bool = reject_rule ($rule, $error_msg)> Bail out with C<$error_msg> if a rule with name C<$rule> has been defined. Return true iff C<$rule> is defined. =cut sub reject_rule ($$) { my ($rule, $msg) = @_; if (rule ($rule)) { err_rule $rule, $msg; return 1; } return 0; } =back =head2 Administrative functions =over 4 =item C Update C<$KNOWN_EXTENSIONS_PATTERN> to recognize the extensions listed in C<@exts>. Extensions should contain a dot if needed. =cut sub accept_extensions (@) { push @_known_extensions_list, @_; $KNOWN_EXTENSIONS_PATTERN = '(?:' . join ('|', map (quotemeta, @_known_extensions_list)) . ')'; } =item C Return the list of all L instances. (I.e., all rules defined so far.) =cut sub rules () { return values %_rule_dict; } =item C Append the C<$action> to C<$actions{$target}> taking care of special cases. =cut sub register_action ($$) { my ($target, $action) = @_; if ($actions{$target}) { $actions{$target} .= "\n$action" if $action; } else { $actions{$target} = $action; } } =item C The I function. Clears all known rules and resets some other internal data. =cut sub reset() { %_rule_dict = (); @_suffixes = (); %_suffix_rules = %_suffix_rules_builtin; %dependencies = ( # Texinfoing. 'dvi' => [], 'dvi-am' => [], 'pdf' => [], 'pdf-am' => [], 'ps' => [], 'ps-am' => [], 'info' => [], 'info-am' => [], 'html' => [], 'html-am' => [], # Installing/uninstalling. 'install-data-am' => [], 'install-exec-am' => [], 'uninstall-am' => [], 'install-man' => [], 'uninstall-man' => [], 'install-dvi' => [], 'install-dvi-am' => [], 'install-html' => [], 'install-html-am' => [], 'install-info' => [], 'install-info-am' => [], 'install-pdf' => [], 'install-pdf-am' => [], 'install-ps' => [], 'install-ps-am' => [], 'installcheck-am' => [], # Cleaning. 'clean-am' => [], 'mostlyclean-am' => [], 'maintainer-clean-am' => [], 'distclean-am' => [], 'clean' => [], 'mostlyclean' => [], 'maintainer-clean' => [], 'distclean' => [], # Tarballing. 'dist-all' => [], '.PHONY' => [], '.PRECIOUS' => [], # Recursive install targets (so "make -n install" works for BSD Make). '.MAKE' => [], ); %actions = (); } =item C Return the target suffix for the next rule to use to reach C<$ext2> from C<$ext1>, or C if no such rule exists. =cut sub next_in_suffix_chain ($$) { my ($ext1, $ext2) = @_; return undef unless (exists $_suffix_rules{$ext1} and exists $_suffix_rules{$ext1}{$ext2}); return $_suffix_rules{$ext1}{$ext2}[0]; } =item C Register a suffix rule defined on C<$where> that transforms files ending in C<$src> into files ending in C<$dest>. =cut sub register_suffix_rule ($$$) { my ($where, $src, $dest) = @_; my $suffix_rules = $where->{'position'} ? \%_suffix_rules : \%_suffix_rules_builtin; verb "Sources ending in $src become $dest"; push @_suffixes, $src, $dest; # When transforming sources to objects, Automake uses the # %suffix_rules to move from each source extension to # '.$(OBJEXT)', not to '.o' or '.obj'. However some people # define suffix rules for '.o' or '.obj', so internally we will # consider these extensions equivalent to '.$(OBJEXT)'. We # CANNOT rewrite the target (i.e., automagically replace '.o' # and '.obj' by '.$(OBJEXT)' in the output), or warn the user # that (s)he'd better use '.$(OBJEXT)', because Automake itself # output suffix rules for '.o' or '.obj' ... $dest = '.$(OBJEXT)' if ($dest eq '.o' || $dest eq '.obj'); # ---------------------------------------------------------------------- # The $suffix_rules variable maps the source extension for all suffix # rules seen to a hash whose keys are the possible output extensions. # # Note that this is transitively closed by construction: # if we have # # exists $suffix_rules{$ext1}{$ext2} # && exists $suffix_rules{$ext2}{$ext3} # # then we also have # # exists $suffix_rules{$ext1}{$ext3} # # So it's easy to check whether '.foo' can be transformed to # '.$(OBJEXT)' by checking whether $suffix_rules{'.foo'}{'.$(OBJEXT)'} # exists. This will work even if transforming '.foo' to '.$(OBJEXT)' # involves a chain of several suffix rules. # # The value of $suffix_rules{$ext1}{$ext2} is a pair [$next_sfx, $dist] # where $next_sfx is target suffix for the next rule to use to reach # $ext2, and $dist the distance to $ext2. # ---------------------------------------------------------------------- # Register $dest as a possible destination from $src. # We might have the create the \hash. if (exists $suffix_rules->{$src}) { $suffix_rules->{$src}{$dest} = [ $dest, 1 ]; } else { $suffix_rules->{$src} = { $dest => [ $dest, 1 ] }; } # If we know how to transform $dest in something else, then # we know how to transform $src in that "something else". if (exists $suffix_rules->{$dest}) { for my $dest2 (keys %{$suffix_rules->{$dest}}) { my $dist = $suffix_rules->{$dest}{$dest2}[1] + 1; # Overwrite an existing $src->$dest2 path only if # the path via $dest which is shorter. if (! exists $suffix_rules->{$src}{$dest2} || $suffix_rules->{$src}{$dest2}[1] > $dist) { $suffix_rules->{$src}{$dest2} = [ $dest, $dist ]; } } } # Similarly, any extension that can be derived into $src # can be derived into the same extensions as $src can. my @dest2 = keys %{$suffix_rules->{$src}}; for my $src2 (keys %$suffix_rules) { if (exists $suffix_rules->{$src2}{$src}) { for my $dest2 (@dest2) { my $dist = $suffix_rules->{$src}{$dest2} + 1; # Overwrite an existing $src2->$dest2 path only if # the path via $src is shorter. if (! exists $suffix_rules->{$src2}{$dest2} || $suffix_rules->{$src2}{$dest2}[1] > $dist) { $suffix_rules->{$src2}{$dest2} = [ $src, $dist ]; } } } } } =item C<@list = suffixes> Return the list of known suffixes. =cut sub suffixes () { return @_suffixes; } =item C Return the C object for the rule named C<$rulename> if defined. Return 0 otherwise. =cut sub rule ($) { my ($name) = @_; # Strip $(EXEEXT) from $name, so we can diagnose # a clash if 'ctags$(EXEEXT):' is redefined after 'ctags:'. $name =~ s,\$\(EXEEXT\)$,,; return $_rule_dict{$name} || 0; } =item C Return the C object for the rule named C<$rulename> if defined in condition C<$cond>. Return false if the condition or the rule does not exist. =cut sub ruledef ($$) { my ($name, $cond) = @_; my $rule = rule $name; return $rule && $rule->def ($cond); } =item C object for the variable named C<$rulename>. Abort with an internal error if the variable was not defined. The I in front of C stands for I. One should call C to assert the rule's existence. =cut sub rrule ($) { my ($name) = @_; my $r = rule $name; prog_error ("undefined rule $name\n" . &rules_dump) unless $r; return $r; } =item C Return the C object for the rule named C<$rulename> if defined in condition C<$cond>. Abort with an internal error if the condition or the rule does not exist. =cut sub rruledef ($$) { my ($name, $cond) = @_; return rrule ($name)->rdef ($cond); } # Create the variable if it does not exist. # This is used only by other functions in this package. sub _crule ($) { my ($name) = @_; my $r = rule $name; return $r if $r; return _new Automake::Rule $name; } sub _new ($$) { my ($class, $name) = @_; # Strip $(EXEEXT) from $name, so we can diagnose # a clash if 'ctags$(EXEEXT):' is redefined after 'ctags:'. (my $keyname = $name) =~ s,\$\(EXEEXT\)$,,; my $self = Automake::Item::new ($class, $name); $_rule_dict{$keyname} = $self; return $self; } sub _rule_defn_with_exeext_awareness ($$$) { my ($target, $cond, $where) = @_; # For now 'foo:' will override 'foo$(EXEEXT):'. This is temporary, # though, so we emit a warning. (my $noexe = $target) =~ s/\$\(EXEEXT\)$//; my $noexerule = rule $noexe; my $tdef = $noexerule ? $noexerule->def ($cond) : undef; if ($noexe ne $target && $tdef && $noexerule->name ne $target) { # The no-exeext option enables this feature. if (! option 'no-exeext') { msg ('obsolete', $tdef->location, "deprecated feature: target '$noexe' overrides " . "'$noexe\$(EXEEXT)'\n" . "change your target to read '$noexe\$(EXEEXT)'", partial => 1); msg ('obsolete', $where, "target '$target' was defined here"); } } return $tdef; } sub _maybe_warn_about_duplicated_target ($$$$$$) { my ($target, $tdef, $source, $owner, $cond, $where) = @_; my $oldowner = $tdef->owner; # Ok, it's the name target, but the name maybe different because # 'foo$(EXEEXT)' and 'foo' have the same key in our table. my $oldname = $tdef->name; # Don't mention true conditions in diagnostics. my $condmsg = $cond == TRUE ? '' : (" in condition '" . $cond->human . "'"); if ($owner == RULE_USER) { if ($oldowner == RULE_USER) { # Ignore '%'-style pattern rules. We'd need the # dependencies to detect duplicates, and they are # already diagnosed as unportable by -Wportability. if ($target !~ /^[^%]*%[^%]*$/) { ## FIXME: Presently we can't diagnose duplicate user rules ## because we don't distinguish rules with commands ## from rules that only add dependencies. E.g., ## .PHONY: foo ## .PHONY: bar ## is legitimate. This is checked in the 'phony.sh' test. # msg ('syntax', $where, # "redefinition of '$target'$condmsg ...", partial => 1); # msg_cond_rule ('syntax', $cond, $target, # "... '$target' previously defined here"); } } else { # Since we parse the user Makefile.am before reading # the Automake fragments, this condition should never happen. prog_error ("user target '$target'$condmsg seen after Automake's" . " definition\nfrom " . $tdef->source); } } else # $owner == RULE_AUTOMAKE { if ($oldowner == RULE_USER) { # -am targets listed in %dependencies support a -local # variant. If the user tries to override TARGET or # TARGET-am for which there exists a -local variant, # just tell the user to use it. my $hint = 0; my $noam = $target; $noam =~ s/-am$//; if (exists $dependencies{"$noam-am"}) { $hint = "consider using $noam-local instead of $target"; } msg_cond_rule ('override', $cond, $target, "user target '$target' defined here" . "$condmsg ...", partial => 1); msg ('override', $where, "... overrides Automake target '$oldname' defined here", partial => $hint); msg_cond_rule ('override', $cond, $target, $hint) if $hint; } else # $oldowner == RULE_AUTOMAKE { # Automake should ignore redefinitions of its own # rules if they came from the same file. This makes # it easier to process a Makefile fragment several times. # However it's an error if the target is defined in many # files. E.g., the user might be using bin_PROGRAMS = ctags # which clashes with our 'ctags' rule. # (It would be more accurate if we had a way to compare # the *content* of both rules. Then $targets_source would # be useless.) my $oldsource = $tdef->source; if (not ($source eq $oldsource && $target eq $oldname)) { msg ('syntax', $where, "redefinition of '$target'$condmsg ...", partial => 1); msg_cond_rule ('syntax', $cond, $target, "... '$oldname' previously defined here"); } } } } # Return the list of conditionals in which the rule was defined. In case # an ambiguous conditional definition is detected, return the empty list. sub _conditionals_for_rule ($$$$) { my ($rule, $owner, $cond, $where) = @_; my $target = $rule->name; my @conds; my ($message, $ambig_cond) = $rule->conditions->ambiguous_p ($target, $cond); return $cond if !$message; # No ambiguity. if ($owner == RULE_USER) { # For user rules, just diagnose the ambiguity. msg 'syntax', $where, "$message ...", partial => 1; msg_cond_rule ('syntax', $ambig_cond, $target, "... '$target' previously defined here"); return (); } # FIXME: for Automake rules, we can't diagnose ambiguities yet. # The point is that Automake doesn't propagate conditions # everywhere. For instance &handle_PROGRAMS doesn't care if # bin_PROGRAMS was defined conditionally or not. # On the following input # if COND1 # foo: # ... # else # bin_PROGRAMS = foo # endif # &handle_PROGRAMS will attempt to define a 'foo:' rule # in condition TRUE (which conflicts with COND1). Fixing # this in &handle_PROGRAMS and siblings seems hard: you'd # have to explain &file_contents what to do with a # condition. So for now we do our best *here*. If 'foo:' # was already defined in condition COND1 and we want to define # it in condition TRUE, then define it only in condition !COND1. # (See cond14.sh and cond15.sh for some test cases.) @conds = $rule->not_always_defined_in_cond ($cond)->conds; # No conditions left to define the rule. # Warn, because our workaround is meaningless in this case. if (scalar @conds == 0) { msg 'syntax', $where, "$message ...", partial => 1; msg_cond_rule ('syntax', $ambig_cond, $target, "... '$target' previously defined here"); return (); } return @conds; } =item C<@conds = define ($rulename, $source, $owner, $cond, $where)> Define a new rule. C<$rulename> is the list of targets. C<$source> is the filename the rule comes from. C<$owner> is the owner of the rule (C or C). C<$cond> is the C under which the rule is defined. C<$where> is the C where the rule is defined. Returns a (possibly empty) list of Cs where the rule's definition should be output. =cut sub define ($$$$$) { my ($target, $source, $owner, $cond, $where) = @_; prog_error "$where is not a reference" unless ref $where; prog_error "$cond is not a reference" unless ref $cond; # Don't even think about defining a rule in condition FALSE. return () if $cond == FALSE; my $tdef = _rule_defn_with_exeext_awareness ($target, $cond, $where); # A GNU make-style pattern rule has a single "%" in the target name. msg ('portability', $where, "'%'-style pattern rules are a GNU make extension") if $target =~ /^[^%]*%[^%]*$/; # See whether this is a duplicated target declaration. if ($tdef) { # Diagnose invalid target redefinitions, if any. Note that some # target redefinitions are valid (e.g., for multiple-targets # pattern rules). _maybe_warn_about_duplicated_target ($target, $tdef, $source, $owner, $cond, $where); # Return so we don't redefine the rule in our tables, don't check # for ambiguous condition, etc. The rule will be output anyway # because '&read_am_file' ignores the return code. return (); } my $rule = _crule $target; # Conditions for which the rule should be defined. Due to some # complications in the automake internals, this aspect is not as # obvious as it might be, and in come cases this list must contain # other entries in addition to '$cond'. See the comments in # '_conditionals_for_rule' for a rationale. my @conds = _conditionals_for_rule ($rule, $owner, $cond, $where); # Stop if we had ambiguous conditional definitions. return unless @conds; # Finally define this rule. for my $c (@conds) { my $def = new Automake::RuleDef ($target, '', $where->clone, $owner, $source); $rule->set ($c, $def); } # We honor inference rules with multiple targets because many # makes support this and people use it. However this is disallowed # by POSIX. We'll print a warning later. my $target_count = 0; my $inference_rule_count = 0; for my $t (split (' ', $target)) { ++$target_count; # Check if the rule is a suffix rule: either it's a rule for # two known extensions... if ($t =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/ # ...or it's a rule with unknown extensions (i.e., the rule # looks like '.foo.bar:' but '.foo' or '.bar' are not # declared in SUFFIXES and are not known language # extensions). Automake will complete SUFFIXES from # @suffixes automatically (see handle_footer). || ($t =~ /$_SUFFIX_RULE_PATTERN/o && accept_extensions($1))) { ++$inference_rule_count; register_suffix_rule ($where, $1, $2); } } # POSIX allows multiple targets before the colon, but disallows # definitions of multiple inference rules. It's also # disallowed to mix plain targets with inference rules. msg ('portability', $where, "inference rules can have only one target before the colon (POSIX)") if $inference_rule_count > 0 && $target_count > 1; return @conds; } =item C Adds C<@deps> to the dependencies of target C<$target>. This should be used only with factored targets (those appearing in C<%dependees>). =cut sub depend ($@) { my ($category, @dependees) = @_; push (@{$dependencies{$category}}, @dependees); } =back =head1 SEE ALSO L, L, L, L. =cut 1; PKJ24]. package Automake::Options; use 5.006; use strict; use Exporter; use Automake::Config; use Automake::ChannelDefs; use Automake::Channels; use Automake::Version; use vars qw (@ISA @EXPORT); @ISA = qw (Exporter); @EXPORT = qw (option global_option set_option set_global_option unset_option unset_global_option process_option_list process_global_option_list set_strictness $strictness $strictness_name &FOREIGN &GNU &GNITS); =head1 NAME Automake::Options - keep track of Automake options =head1 SYNOPSIS use Automake::Options; # Option lookup and setting. $opt = option 'name'; $opt = global_option 'name'; set_option 'name', 'value'; set_global_option 'name', 'value'; unset_option 'name'; unset_global_option 'name'; # Batch option setting. process_option_list $location, @names; process_global_option_list $location, @names; # Strictness lookup and setting. set_strictness 'foreign'; set_strictness 'gnu'; set_strictness 'gnits'; if ($strictness >= GNU) { ... } print "$strictness_name\n"; =head1 DESCRIPTION This packages manages Automake's options and strictness settings. Options can be either local or global. Local options are set using an C variable in a F and apply only to this F. Global options are set from the command line or passed as an argument to C, they apply to all Fs. =cut # Values are the Automake::Location of the definition. use vars '%_options'; # From AUTOMAKE_OPTIONS use vars '%_global_options'; # From AM_INIT_AUTOMAKE or the command line. # Whether process_option_list has already been called for the current # Makefile.am. use vars '$_options_processed'; # Whether process_global_option_list has already been called. use vars '$_global_options_processed'; =head2 Constants =over 4 =item FOREIGN =item GNU =item GNITS Strictness constants used as values for C<$strictness>. =back =cut # Constants to define the "strictness" level. use constant FOREIGN => 0; use constant GNU => 1; use constant GNITS => 2; =head2 Variables =over 4 =item C<$strictness> The current strictness. One of C, C, or C. =item C<$strictness_name> The current strictness name. One of C<'foreign'>, C<'gnu'>, or C<'gnits'>. =back =cut # Strictness levels. use vars qw ($strictness $strictness_name); # Strictness level as set on command line. use vars qw ($_default_strictness $_default_strictness_name); =head2 Functions =over 4 =item C Reset the options variables for the next F. In other words, this gets rid of all local options in use by the previous F. =cut sub reset () { $_options_processed = 0; %_options = %_global_options; # The first time we are run, # remember the current setting as the default. if (defined $_default_strictness) { $strictness = $_default_strictness; $strictness_name = $_default_strictness_name; } else { $_default_strictness = $strictness; $_default_strictness_name = $strictness_name; } } =item C<$value = option ($name)> =item C<$value = global_option ($name)> Query the state of an option. If the option is unset, this returns the empty list. Otherwise it returns the option's value, as set by C or C. Note that C should be used only when it is important to make sure an option hasn't been set locally. Otherwise C