diff options
author | Matthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr> | 2018-06-06 15:46:24 +0200 |
---|---|---|
committer | Matthias Paulmier <matthias.paulmier@etu.u-bordeaux.fr> | 2018-06-22 14:18:34 +0200 |
commit | 3d672eb1ef8572ac257652cab0ab416bd32be024 (patch) | |
tree | d76bcdce3ed92705b608efd54be35ae0482df7e1 /bin | |
parent | 9a93513b42a698ba9ac46a88ccb5fbcceea4daac (diff) | |
download | automake-3d672eb1ef8572ac257652cab0ab416bd32be024.tar.gz |
lib: fix Automake::Variable
Some methods added to this module were not working properly because they
depend on others which stayed in automake.in
* ConfVars.pm: Added this module to put the methods in question.
* CondStack.pm: Module that takes care of the conditional stack.
* Utils.pm: Added some needed utility functions for the above to run properly.
* File.pm: Methods that looks at files' content.
* local.mk: Added the new modules.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/automake.in | 320 |
1 files changed, 3 insertions, 317 deletions
diff --git a/bin/automake.in b/bin/automake.in index fb9779882..18a6fbf3e 100755 --- a/bin/automake.in +++ b/bin/automake.in @@ -57,6 +57,7 @@ use Automake::Channels; use Automake::ChannelDefs; use Automake::Configure_ac; use Automake::FileUtils; +use Automake::File; use Automake::Location; use Automake::Condition qw/TRUE FALSE/; use Automake::DisjConditions; @@ -68,6 +69,8 @@ use Automake::RuleDef; use Automake::Wrap 'makefile_wrap'; use Automake::Language; use Automake::Utils; +use Automake::CondStack; +use Automake::ConfVars; use File::Basename; use File::Spec; use Carp; @@ -5528,132 +5531,6 @@ sub pretty_print_rule ################################################################ -## -------------------------------- ## -## Handling the conditional stack. ## -## -------------------------------- ## - - -# $STRING -# make_conditional_string ($NEGATE, $COND) -# ---------------------------------------- -sub make_conditional_string -{ - my ($negate, $cond) = @_; - $cond = "${cond}_TRUE" - unless $cond =~ /^TRUE|FALSE$/; - $cond = Automake::Condition::conditional_negate ($cond) - if $negate; - return $cond; -} - - -my %_am_macro_for_cond = - ( - AMDEP => "one of the compiler tests\n" - . " AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,\n" - . " AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC", - am__fastdepCC => 'AC_PROG_CC', - am__fastdepCCAS => 'AM_PROG_AS', - am__fastdepCXX => 'AC_PROG_CXX', - am__fastdepGCJ => 'AM_PROG_GCJ', - am__fastdepOBJC => 'AC_PROG_OBJC', - am__fastdepOBJCXX => 'AC_PROG_OBJCXX', - am__fastdepUPC => 'AM_PROG_UPC' - ); - -# $COND -# cond_stack_if ($NEGATE, $COND, $WHERE) -# -------------------------------------- -sub cond_stack_if -{ - my ($negate, $cond, $where) = @_; - - if (! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/) - { - my $text = "$cond does not appear in AM_CONDITIONAL"; - my $scope = US_LOCAL; - if (exists $_am_macro_for_cond{$cond}) - { - my $mac = $_am_macro_for_cond{$cond}; - $text .= "\n The usual way to define '$cond' is to add "; - $text .= ($mac =~ / /) ? $mac : "'$mac'"; - $text .= "\n to '$configure_ac' and run 'aclocal' and 'autoconf' again"; - # These warnings appear in Automake files (depend2.am), - # so there is no need to display them more than once: - $scope = US_GLOBAL; - } - error $where, $text, uniq_scope => $scope; - } - - push (@cond_stack, make_conditional_string ($negate, $cond)); - - return new Automake::Condition (@cond_stack); -} - - -# $COND -# cond_stack_else ($NEGATE, $COND, $WHERE) -# ---------------------------------------- -sub cond_stack_else -{ - my ($negate, $cond, $where) = @_; - - if (! @cond_stack) - { - error $where, "else without if"; - return FALSE; - } - - $cond_stack[$#cond_stack] = - Automake::Condition::conditional_negate ($cond_stack[$#cond_stack]); - - # If $COND is given, check against it. - if (defined $cond) - { - $cond = make_conditional_string ($negate, $cond); - - error ($where, "else reminder ($negate$cond) incompatible with " - . "current conditional: $cond_stack[$#cond_stack]") - if $cond_stack[$#cond_stack] ne $cond; - } - - return new Automake::Condition (@cond_stack); -} - - -# $COND -# cond_stack_endif ($NEGATE, $COND, $WHERE) -# ----------------------------------------- -sub cond_stack_endif -{ - my ($negate, $cond, $where) = @_; - my $old_cond; - - if (! @cond_stack) - { - error $where, "endif without if"; - return TRUE; - } - - # If $COND is given, check against it. - if (defined $cond) - { - $cond = make_conditional_string ($negate, $cond); - - error ($where, "endif reminder ($negate$cond) incompatible with " - . "current conditional: $cond_stack[$#cond_stack]") - if $cond_stack[$#cond_stack] ne $cond; - } - - pop @cond_stack; - - return new Automake::Condition (@cond_stack); -} - - - - - ## ------------------------ ## ## Handling the variables. ## ## ------------------------ ## @@ -6111,197 +5988,6 @@ sub read_main_am_file ################################################################ -# $STRING -# flatten ($ORIGINAL_STRING) -# -------------------------- -sub flatten -{ - $_ = shift; - - s/\\\n//somg; - s/\s+/ /g; - s/^ //; - s/ $//; - - return $_; -} - - -# transform_token ($TOKEN, \%PAIRS, $KEY) -# --------------------------------------- -# Return the value associated to $KEY in %PAIRS, as used on $TOKEN -# (which should be ?KEY? or any of the special %% requests).. -sub transform_token ($\%$) -{ - my ($token, $transform, $key) = @_; - my $res = $transform->{$key}; - prog_error "Unknown key '$key' in '$token'" unless defined $res; - return $res; -} - - -# transform ($TOKEN, \%PAIRS) -# --------------------------- -# If ($TOKEN, $VAL) is in %PAIRS: -# - replaces %KEY% with $VAL, -# - enables/disables ?KEY? and ?!KEY?, -# - replaces %?KEY% with TRUE or FALSE. -sub transform ($\%) -{ - my ($token, $transform) = @_; - - # %KEY%. - # Must be before the following pattern to exclude the case - # when there is neither IFTRUE nor IFFALSE. - if ($token =~ /^%([\w\-]+)%$/) - { - return transform_token ($token, %$transform, $1); - } - # %?KEY%. - elsif ($token =~ /^%\?([\w\-]+)%$/) - { - return transform_token ($token, %$transform, $1) ? 'TRUE' : 'FALSE'; - } - # ?KEY? and ?!KEY?. - elsif ($token =~ /^ \? (!?) ([\w\-]+) \? $/x) - { - my $neg = ($1 eq '!') ? 1 : 0; - my $val = transform_token ($token, %$transform, $2); - return (!!$val == $neg) ? '##%' : ''; - } - else - { - prog_error "Unknown request format: $token"; - } -} - -# $TEXT -# preprocess_file ($MAKEFILE, [%TRANSFORM]) -# ----------------------------------------- -# Load a $MAKEFILE, apply the %TRANSFORM, and return the result. -# No extra parsing or post-processing is done (i.e., recognition of -# rules declaration or of make variables definitions). -sub preprocess_file -{ - my ($file, %transform) = @_; - - # Complete %transform with global options. - # Note that %transform goes last, so it overrides global options. - %transform = ( 'MAINTAINER-MODE' - => $seen_maint_mode ? subst ('MAINTAINER_MODE_TRUE') : '', - - 'XZ' => !! option 'dist-xz', - 'LZIP' => !! option 'dist-lzip', - 'BZIP2' => !! option 'dist-bzip2', - 'COMPRESS' => !! option 'dist-tarZ', - 'GZIP' => ! option 'no-dist-gzip', - 'SHAR' => !! option 'dist-shar', - 'ZIP' => !! option 'dist-zip', - - 'INSTALL-INFO' => ! option 'no-installinfo', - 'INSTALL-MAN' => ! option 'no-installman', - 'CK-NEWS' => !! option 'check-news', - - 'SUBDIRS' => !! var ('SUBDIRS'), - 'TOPDIR_P' => $relative_dir eq '.', - - 'BUILD' => ($seen_canonical >= AC_CANONICAL_BUILD), - 'HOST' => ($seen_canonical >= AC_CANONICAL_HOST), - 'TARGET' => ($seen_canonical >= AC_CANONICAL_TARGET), - - 'LIBTOOL' => !! var ('LIBTOOL'), - 'NONLIBTOOL' => 1, - %transform); - - if (! defined ($_ = $am_file_cache{$file})) - { - verb "reading $file"; - # Swallow the whole file. - my $fc_file = new Automake::XFile "< $file"; - my $saved_dollar_slash = $/; - undef $/; - $_ = $fc_file->getline; - $/ = $saved_dollar_slash; - $fc_file->close; - # Remove ##-comments. - # Besides we don't need more than two consecutive new-lines. - s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom; - # Remember the contents of the just-read file. - $am_file_cache{$file} = $_; - } - - # Substitute Automake template tokens. - s/(?: % \?? [\w\-]+ % - | \? !? [\w\-]+ \? - )/transform($&, %transform)/gex; - # transform() may have added some ##%-comments to strip. - # (we use '##%' instead of '##' so we can distinguish ##%##%##% from - # ####### and do not remove the latter.) - s/^[ \t]*(?:##%)+.*\n//gm; - - return $_; -} - - -# @PARAGRAPHS -# make_paragraphs ($MAKEFILE, [%TRANSFORM]) -# ----------------------------------------- -# Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of -# paragraphs. -sub make_paragraphs -{ - my ($file, %transform) = @_; - $transform{FIRST} = !$transformed_files{$file}; - $transformed_files{$file} = 1; - - my @lines = split /(?<!\\)\n/, preprocess_file ($file, %transform); - my @res; - - while (defined ($_ = shift @lines)) - { - my $paragraph = $_; - # If we are a rule, eat as long as we start with a tab. - if (/$RULE_PATTERN/smo) - { - while (defined ($_ = shift @lines) && $_ =~ /^\t/) - { - $paragraph .= "\n$_"; - } - unshift (@lines, $_); - } - - # If we are a comments, eat as much comments as you can. - elsif (/$COMMENT_PATTERN/smo) - { - while (defined ($_ = shift @lines) - && $_ =~ /$COMMENT_PATTERN/smo) - { - $paragraph .= "\n$_"; - } - unshift (@lines, $_); - } - - push @res, $paragraph; - } - - return @res; -} - - -# $CONTENTS -# file_contents ($BASENAME, $WHERE, [%TRANSFORM]) -# ----------------------------------------------- -# Return contents of a file from $libdir/am, automatically skipping -# macros or rules which are already known. -sub file_contents -{ - my ($basename, $where, %transform) = @_; - my ($comments, $variables, $rules) = - file_contents_internal (1, "$libdir/am/$basename.am", $where, - %transform); - return "$comments$variables$rules"; -} - # @PREFIX # am_primary_prefixes ($PRIMARY, $CAN_DIST, @PREFIXES) |