File Coverage

File:/usr/local/share/automake-1.11/Automake/Rule.pm
Coverage:33.6%

linestmtbrancondsubpodtimecode
1# Copyright (C) 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2, or (at your option)
6# any later version.
7
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16package Automake::Rule;
17
1
1
1
5
1
5
use strict;
18
1
1
1
6
11
3
use Carp;
19
20
1
1
1
4
1
3
use Automake::Item;
21
1
1
1
16
1
6
use Automake::RuleDef;
22
1
1
1
4
0
3
use Automake::ChannelDefs;
23
1
1
1
4
1
3
use Automake::Channels;
24
1
1
1
4
1
4
use Automake::Options;
25
1
1
1
4
1
4
use Automake::Condition qw (TRUE FALSE);
26
1
1
1
4
1
3
use Automake::DisjConditions;
27require Exporter;
28
1
1
1
3
1
3
use vars '@ISA', '@EXPORT', '@EXPORT_OK';
29@ISA = qw/Automake::Item Exporter/;
30@EXPORT = qw (reset register_suffix_rule suffix_rules_count
31              suffixes rules $suffix_rules $KNOWN_EXTENSIONS_PATTERN
32              depend %dependencies %actions register_action
33              accept_extensions
34              reject_rule msg_rule msg_cond_rule err_rule err_cond_rule
35              rule rrule ruledef rruledef);
36
37 - 94
=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<Automake::Rule> is a rule name associated to possibly
many conditional definitions.  These definitions are instances
of C<Automake::RuleDef>.

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<r> variants of the C<rule>, C<def>, and C<ruledef> 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
95
96my $_SUFFIX_RULE_PATTERN =
97  '^(\.[a-zA-Z0-9_(){}$+@\-]+)(\.[a-zA-Z0-9_(){}$+@\-]+)' . "\$";
98
99# Suffixes found during a run.
100
1
1
1
7
1
3
use vars '@_suffixes';
101
102# Same as $suffix_rules (declared below), but records only the
103# default rules supplied by the languages Automake supports.
104
1
1
1
3
1
2
use vars '$_suffix_rules_default';
105
106 - 114
=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
115
116
1
1
1
4
1
2
use vars '%dependencies';
117
118 - 123
=item <%actions>

Holds the factored actions.  Tied to C<%dependencies>, i.e., filled
only when keys exists in C<%dependencies>.

=cut
124
125
1
1
1
3
1
2
use vars '%actions';
126
127 - 153
=item <$suffix_rules>

This maps the source extension for all suffix rule seen to
a C<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 C<.foo> can be transformed to
C<.$(OBJEXT)> by checking whether
C<$suffix_rules{'.foo'}{'.$(OBJEXT)'}> exists.  This will work even if
transforming C<.foo> to C<.$(OBJEXT)> involves a chain of several
suffix rules.

The value of C<$suffix_rules{$ext1}{$ext2}> is a pair
C<[ $next_sfx, $dist ]> where C<$next_sfx> is target suffix
for the next rule to use to reach C<$ext2>, and C<$dist> the
distance to C<$ext2'>.

The content of this variable should be updated via the
C<register_suffix_rule> function.

=cut
154
155
1
1
1
4
1
2
use vars '$suffix_rules';
156
157 - 166
=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<accept_extensions>.

=cut
167
168
1
1
1
4
4
2
use vars qw ($KNOWN_EXTENSIONS_PATTERN @_known_extensions_list);
169$KNOWN_EXTENSIONS_PATTERN = "";
170@_known_extensions_list = ();
171
172=back
173
174 - 185
=head2 Error reporting functions

In these functions, C<$rule> can be either a rule name, or
an instance of C<Automake::Rule>.

=over 4

=item C<err_rule ($rule, $message, [%options])>

Uncategorized errors about rules.

=cut
186
187sub err_rule ($$;%)
188{
189
0
1
0
  msg_rule ('error', @_);
190}
191
192 - 196
=item C<err_cond_rule ($cond, $rule, $message, [%options])>

Uncategorized errors about conditional rules.

=cut
197
198sub err_cond_rule ($$$;%)
199{
200
0
1
0
  msg_cond_rule ('error', @_);
201}
202
203 - 207
=item C<msg_cond_rule ($channel, $cond, $rule, $message, [%options])>

Messages about conditional rules.

=cut
208
209sub msg_cond_rule ($$$$;%)
210{
211
0
1
0
  my ($channel, $cond, $rule, $msg, %opts) = @_;
212
0
0
  my $r = ref ($rule) ? $rule : rrule ($rule);
213
0
0
  msg $channel, $r->rdef ($cond)->location, $msg, %opts;
214}
215
216 - 220
=item C<msg_rule ($channel, $targetname, $message, [%options])>

Messages about rules.

=cut
221
222sub msg_rule ($$$;%)
223{
224
0
1
0
  my ($channel, $rule, $msg, %opts) = @_;
225
0
0
  my $r = ref ($rule) ? $rule : rrule ($rule);
226  # Don't know which condition is concerned. Pick any.
227
0
0
  my $cond = $r->conditions->one_cond;
228
0
0
  msg_cond_rule ($channel, $cond, $r, $msg, %opts);
229}
230
231
232 - 239
=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
240
241sub reject_rule ($$)
242{
243
0
1
0
  my ($rule, $msg) = @_;
244
0
0
  if (rule ($rule))
245    {
246
0
0
      err_rule $rule, $msg;
247
0
0
      return 1;
248    }
249
0
0
  return 0;
250}
251
252=back
253
254 - 263
=head2 Administrative functions

=over 4

=item C<accept_extensions (@exts)>

Update C<$KNOWN_EXTENSIONS_PATTERN> to recognize the extensions
listed C<@exts>.  Extensions should contain a dot if needed.

=cut
264
265sub accept_extensions (@)
266{
267
18
1
32
    push @_known_extensions_list, @_;
268
18
286
    $KNOWN_EXTENSIONS_PATTERN =
269        '(?:' . join ('|', map (quotemeta, @_known_extensions_list)) . ')';
270}
271
272 - 277
=item C<rules>

Return the list of all L<Automake::Rule> instances.  (I.e., all
rules defined so far.)

=cut
278
279
1
1
1
5
4
2
use vars '%_rule_dict';
280sub rules ()
281{
282
0
1
0
  return values %_rule_dict;
283}
284
285
286 - 291
=item C<register_action($target, $action)>

Append the C<$action> to C<$actions{$target}> taking care of special
cases.

=cut
292
293sub register_action ($$)
294{
295
0
1
0
  my ($target, $action) = @_;
296
0
0
  if ($actions{$target})
297    {
298
0
0
      $actions{$target} .= "\n$action" if $action;
299    }
300  else
301    {
302
0
0
      $actions{$target} = $action;
303    }
304}
305
306
307 - 312
=item C<Automake::Rule::reset>

The I<forget all> function.  Clears all know rules and reset some
other internal data.

=cut
313
314sub reset()
315{
316
0
1
0
  %_rule_dict = ();
317
0
0
  @_suffixes = ();
318  # The first time we initialize the variables,
319  # we save the value of $suffix_rules.
320
0
0
  if (defined $_suffix_rules_default)
321    {
322
0
0
      $suffix_rules = $_suffix_rules_default;
323    }
324  else
325    {
326
0
0
      $_suffix_rules_default = $suffix_rules;
327    }
328
329
0
0
  %dependencies =
330    (
331     # Texinfoing.
332     'dvi' => [],
333     'dvi-am' => [],
334     'pdf' => [],
335     'pdf-am' => [],
336     'ps' => [],
337     'ps-am' => [],
338     'info' => [],
339     'info-am' => [],
340     'html' => [],
341     'html-am' => [],
342
343     # Installing/uninstalling.
344     'install-data-am' => [],
345     'install-exec-am' => [],
346     'uninstall-am' => [],
347
348     'install-man' => [],
349     'uninstall-man' => [],
350
351     'install-dvi' => [],
352     'install-dvi-am' => [],
353     'install-html' => [],
354     'install-html-am' => [],
355     'install-info' => [],
356     'install-info-am' => [],
357     'install-pdf' => [],
358     'install-pdf-am' => [],
359     'install-ps' => [],
360     'install-ps-am' => [],
361
362     'installcheck-am' => [],
363
364     # Cleaning.
365     'clean-am' => [],
366     'mostlyclean-am' => [],
367     'maintainer-clean-am' => [],
368     'distclean-am' => [],
369     'clean' => [],
370     'mostlyclean' => [],
371     'maintainer-clean' => [],
372     'distclean' => [],
373
374     # Tarballing.
375     'dist-all' => [],
376
377     # Phoning.
378     '.PHONY' => [],
379     # Recursive install targets (so `make -n install' works for BSD Make).
380     '.MAKE' => [],
381     );
382
0
0
  %actions = ();
383}
384
385 - 392
=item C<register_suffix_rule ($where, $src, $dest)>

Register a suffix rules defined on C<$where> that transform
files ending in C<$src> into files ending in C<$dest>.

This upgrades the C<$suffix_rules> variables.

=cut
393
394sub register_suffix_rule ($$$)
395{
396
65
1
117
  my ($where, $src, $dest) = @_;
397
398
65
175
  verb "Sources ending in $src become $dest";
399
65
153
  push @_suffixes, $src, $dest;
400
401  # When transforming sources to objects, Automake uses the
402  # %suffix_rules to move from each source extension to
403  # `.$(OBJEXT)', not to `.o' or `.obj'. However some people
404  # define suffix rules for `.o' or `.obj', so internally we will
405  # consider these extensions equivalent to `.$(OBJEXT)'. We
406  # CANNOT rewrite the target (i.e., automagically replace `.o'
407  # and `.obj' by `.$(OBJEXT)' in the output), or warn the user
408  # that (s)he'd better use `.$(OBJEXT)', because Automake itself
409  # output suffix rules for `.o' or `.obj'...
410
65
302
  $dest = '.$(OBJEXT)' if ($dest eq '.o' || $dest eq '.obj');
411
412  # Reading the comments near the declaration of $suffix_rules might
413  # help to understand the update of $suffix_rules that follows...
414
415  # Register $dest as a possible destination from $src.
416  # We might have the create the \hash.
417
65
130
  if (exists $suffix_rules->{$src})
418    {
419
27
76
      $suffix_rules->{$src}{$dest} = [ $dest, 1 ];
420    }
421  else
422    {
423
38
123
      $suffix_rules->{$src} = { $dest => [ $dest, 1 ] };
424    }
425
426  # If we know how to transform $dest in something else, then
427  # we know how to transform $src in that "something else".
428
65
138
  if (exists $suffix_rules->{$dest})
429    {
430
11
11
11
29
      for my $dest2 (keys %{$suffix_rules->{$dest}})
431        {
432
22
50
          my $dist = $suffix_rules->{$dest}{$dest2}[1] + 1;
433          # Overwrite an existing $src->$dest2 path only if
434          # the path via $dest which is shorter.
435
22
69
          if (! exists $suffix_rules->{$src}{$dest2}
436              || $suffix_rules->{$src}{$dest2}[1] > $dist)
437            {
438
22
67
              $suffix_rules->{$src}{$dest2} = [ $dest, $dist ];
439            }
440        }
441    }
442
443  # Similarly, any extension that can be derived into $src
444  # can be derived into the same extensions as $src can.
445
65
65
66
185
  my @dest2 = keys %{$suffix_rules->{$src}};
446
65
200
  for my $src2 (keys %$suffix_rules)
447    {
448
1328
3280
      if (exists $suffix_rules->{$src2}{$src})
449        {
450
0
          for my $dest2 (@dest2)
451            {
452
0
              my $dist = $suffix_rules->{$src}{$dest2} + 1;
453              # Overwrite an existing $src2->$dest2 path only if
454              # the path via $src is shorter.
455
0
              if (! exists $suffix_rules->{$src2}{$dest2}
456                  || $suffix_rules->{$src2}{$dest2}[1] > $dist)
457                {
458
0
                  $suffix_rules->{$src2}{$dest2} = [ $src, $dist ];
459                }
460            }
461        }
462    }
463}
464
465 - 470
=item C<$count = suffix_rules_count>

Return the number of suffix rules added while processing the current
F<Makefile> (excluding predefined suffix rules).

=cut
471
472sub suffix_rules_count ()
473{
474
0
1
  return (scalar keys %$suffix_rules) - (scalar keys %$_suffix_rules_default);
475}
476
477 - 481
=item C<@list = suffixes>

Return the list of known suffixes.

=cut
482
483sub suffixes ()
484{
485
0
1
  return @_suffixes;
486}
487
488 - 493
=item C<rule ($rulename)>

Return the C<Automake::Rule> object for the rule
named C<$rulename> if defined.   Return 0 otherwise.

=cut
494
495sub rule ($)
496{
497
0
1
  my ($name) = @_;
498  # Strip $(EXEEXT) from $name, so we can diagnose
499  # a clash if `ctags$(EXEEXT):' is redefined after `ctags:'.
500
0
  $name =~ s,\$\(EXEEXT\)$,,;
501
0
  return $_rule_dict{$name} || 0;
502}
503
504 - 510
=item C<ruledef ($rulename, $cond)>

Return the C<Automake::RuleDef> 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
511
512sub ruledef ($$)
513{
514
0
1
  my ($name, $cond) = @_;
515
0
  my $rule = rule $name;
516
0
  return $rule && $rule->def ($cond);
517}
518
519 - 528
=item C<rrule ($rulename)

Return the C<Automake::Rule> object for the variable named
C<$rulename>.  Abort with an internal error if the variable was not
defined.

The I<r> in front of C<var> stands for I<required>.  One
should call C<rvar> to assert the rule's existence.

=cut
529
530sub rrule ($)
531{
532
0
1
  my ($name) = @_;
533
0
  my $r = rule $name;
534
0
  prog_error ("undefined rule $name\n" . &rules_dump)
535    unless $r;
536
0
  return $r;
537}
538
539 - 545
=item C<rruledef ($varname, $cond)>

Return the C<Automake::RuleDef> 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
546
547sub rruledef ($$)
548{
549
0
1
  my ($name, $cond) = @_;
550
0
  return rrule ($name)->rdef ($cond);
551}
552
553# Create the variable if it does not exist.
554# This is used only by other functions in this package.
555sub _crule ($)
556{
557
0
  my ($name) = @_;
558
0
  my $r = rule $name;
559
0
  return $r if $r;
560
0
  return _new Automake::Rule $name;
561}
562
563sub _new ($$)
564{
565
0
  my ($class, $name) = @_;
566
567  # Strip $(EXEEXT) from $name, so we can diagnose
568  # a clash if `ctags$(EXEEXT):' is redefined after `ctags:'.
569
0
  (my $keyname = $name) =~ s,\$\(EXEEXT\)$,,;
570
571
0
  my $self = Automake::Item::new ($class, $name);
572
0
  $_rule_dict{$keyname} = $self;
573
0
  return $self;
574}
575
576
577 - 588
=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<RULE_AUTOMAKE> or C<RULE_USER>).  C<$cond> is the
C<Automake::Condition> under which the rule is defined.  C<$where> is
the C<Automake::Location> where the rule is defined.

Returns a (possibly empty) list of C<Automake::Condition>s where the
rule's definition should be output.

=cut
589
590sub define ($$$$$)
591{
592
0
1
  my ($target, $source, $owner, $cond, $where) = @_;
593
594
0
  prog_error "$where is not a reference"
595    unless ref $where;
596
0
  prog_error "$cond is not a reference"
597    unless ref $cond;
598
599  # Don't even think about defining a rule in condition FALSE.
600
0
  return () if $cond == FALSE;
601
602  # For now `foo:' will override `foo$(EXEEXT):'. This is temporary,
603  # though, so we emit a warning.
604
0
  (my $noexe = $target) =~ s,\$\(EXEEXT\)$,,;
605
0
  my $noexerule = rule $noexe;
606
0
  my $tdef = $noexerule ? $noexerule->def ($cond) : undef;
607
608
0
  if ($noexe ne $target
609      && $tdef
610      && $noexerule->name ne $target)
611    {
612      # The no-exeext option enables this feature.
613
0
      if (! option 'no-exeext')
614        {
615
0
          msg ('obsolete', $tdef->location,
616               "deprecated feature: target `$noexe' overrides "
617               . "`$noexe\$(EXEEXT)'\n"
618               . "change your target to read `$noexe\$(EXEEXT)'");
619
0
          msg ('obsolete', $where, "target `$target' was defined here");
620        }
621      # Don't `return ()' now, as this might hide target clashes
622      # detected below.
623    }
624
625
626  # A GNU make-style pattern rule has a single "%" in the target name.
627
0
  msg ('portability', $where,
628       "`%'-style pattern rules are a GNU make extension")
629    if $target =~ /^[^%]*%[^%]*$/;
630
631  # Diagnose target redefinitions.
632
0
  if ($tdef)
633    {
634
0
      my $oldowner = $tdef->owner;
635      # Ok, it's the name target, but the name maybe different because
636      # `foo$(EXEEXT)' and `foo' have the same key in our table.
637
0
      my $oldname = $tdef->name;
638
639      # Don't mention true conditions in diagnostics.
640
0
      my $condmsg =
641        $cond == TRUE ? '' : " in condition `" . $cond->human . "'";
642
643
0
      if ($owner == RULE_USER)
644        {
645
0
          if ($oldowner == RULE_USER)
646            {
647              # Ignore `%'-style pattern rules. We'd need the
648              # dependencies to detect duplicates, and they are
649              # already diagnosed as unportable by -Wportability.
650
0
              if ($target !~ /^[^%]*%[^%]*$/)
651                {
652                  ## FIXME: Presently we can't diagnose duplicate user rules
653                  ## because we don't distinguish rules with commands
654                  ## from rules that only add dependencies. E.g.,
655                  ## .PHONY: foo
656                  ## .PHONY: bar
657                  ## is legitimate. (This is phony.test.)
658
659                  # msg ('syntax', $where,
660                  # "redefinition of `$target'$condmsg...", partial => 1);
661                  # msg_cond_rule ('syntax', $cond, $target,
662                  # "... `$target' previously defined here");
663                }
664              # Return so we don't redefine the rule in our tables,
665              # don't check for ambiguous condition, etc. The rule
666              # will be output anyway because &read_am_file ignore the
667              # return code.
668
0
              return ();
669            }
670          else
671            {
672              # Since we parse the user Makefile.am before reading
673              # the Automake fragments, this condition should never happen.
674
0
              prog_error ("user target `$target'$condmsg seen after Automake's"
675                          . " definition\nfrom " . $tdef->source);
676            }
677        }
678      else # $owner == RULE_AUTOMAKE
679        {
680
0
          if ($oldowner == RULE_USER)
681            {
682              # -am targets listed in %dependencies support a -local
683              # variant. If the user tries to override TARGET or
684              # TARGET-am for which there exists a -local variant,
685              # just tell the user to use it.
686
0
              my $hint = 0;
687
0
              my $noam = $target;
688
0
              $noam =~ s/-am$//;
689
0
              if (exists $dependencies{"$noam-am"})
690                {
691
0
                  $hint = "consider using $noam-local instead of $target";
692                }
693
694
0
              msg_cond_rule ('override', $cond, $target,
695                             "user target `$target' defined here"
696                             . "$condmsg...", partial => 1);
697
0
              msg ('override', $where,
698                   "... overrides Automake target `$oldname' defined here",
699                   partial => $hint);
700
0
              msg_cond_rule ('override', $cond, $target, $hint)
701                if $hint;
702
703              # Don't overwrite the user definition of TARGET.
704
0
              return ();
705            }
706          else # $oldowner == RULE_AUTOMAKE
707            {
708              # Automake should ignore redefinitions of its own
709              # rules if they came from the same file. This makes
710              # it easier to process a Makefile fragment several times.
711              # However it's an error if the target is defined in many
712              # files. E.g., the user might be using bin_PROGRAMS = ctags
713              # which clashes with our `ctags' rule.
714              # (It would be more accurate if we had a way to compare
715              # the *content* of both rules. Then $targets_source would
716              # be useless.)
717
0
              my $oldsource = $tdef->source;
718
0
              return () if $source eq $oldsource && $target eq $oldname;
719
720
0
              msg ('syntax', $where, "redefinition of `$target'$condmsg...",
721                   partial => 1);
722
0
              msg_cond_rule ('syntax', $cond, $target,
723                             "... `$oldname' previously defined here");
724
0
              return ();
725            }
726        }
727      # Never reached.
728
0
      prog_error ("Unreachable place reached.");
729    }
730
731  # Conditions for which the rule should be defined.
732
0
  my @conds = $cond;
733
734  # Check ambiguous conditional definitions.
735
0
  my $rule = _crule $target;
736
0
  my ($message, $ambig_cond) = $rule->conditions->ambiguous_p ($target, $cond);
737
0
  if ($message) # We have an ambiguity.
738    {
739
0
      if ($owner == RULE_USER)
740        {
741          # For user rules, just diagnose the ambiguity.
742
0
          msg 'syntax', $where, "$message ...", partial => 1;
743
0
          msg_cond_rule ('syntax', $ambig_cond, $target,
744                         "... `$target' previously defined here");
745
0
          return ();
746        }
747      else
748        {
749          # FIXME: for Automake rules, we can't diagnose ambiguities yet.
750          # The point is that Automake doesn't propagate conditions
751          # everywhere. For instance &handle_PROGRAMS doesn't care if
752          # bin_PROGRAMS was defined conditionally or not.
753          # On the following input
754          # if COND1
755          # foo:
756          # ...
757          # else
758          # bin_PROGRAMS = foo
759          # endif
760          # &handle_PROGRAMS will attempt to define a `foo:' rule
761          # in condition TRUE (which conflicts with COND1). Fixing
762          # this in &handle_PROGRAMS and siblings seems hard: you'd
763          # have to explain &file_contents what to do with a
764          # condition. So for now we do our best *here*. If `foo:'
765          # was already defined in condition COND1 and we want to define
766          # it in condition TRUE, then define it only in condition !COND1.
767          # (See cond14.test and cond15.test for some test cases.)
768
0
          @conds = $rule->not_always_defined_in_cond ($cond)->conds;
769
770          # No conditions left to define the rule.
771          # Warn, because our workaround is meaningless in this case.
772
0
          if (scalar @conds == 0)
773            {
774
0
              msg 'syntax', $where, "$message ...", partial => 1;
775
0
              msg_cond_rule ('syntax', $ambig_cond, $target,
776                             "... `$target' previously defined here");
777
0
              return ();
778            }
779        }
780    }
781
782  # Finally define this rule.
783
0
  for my $c (@conds)
784    {
785
0
      my $def = new Automake::RuleDef ($target, '', $where->clone,
786                                       $owner, $source);
787
0
      $rule->set ($c, $def);
788    }
789
790  # We honor inference rules with multiple targets because many
791  # make support this and people use it. However this is disallowed
792  # by POSIX. We'll print a warning later.
793
0
  my $target_count = 0;
794
0
  my $inference_rule_count = 0;
795
796
0
  for my $t (split (' ', $target))
797    {
798
0
      ++$target_count;
799      # Check if the rule is a suffix rule: either it's a rule for
800      # two known extensions...
801
0
      if ($t =~ /^($KNOWN_EXTENSIONS_PATTERN)($KNOWN_EXTENSIONS_PATTERN)$/
802          # ...or it's a rule with unknown extensions (i.e., the rule
803          # looks like `.foo.bar:' but `.foo' or `.bar' are not
804          # declared in SUFFIXES and are not known language
805          # extensions). Automake will complete SUFFIXES from
806          # @suffixes automatically (see handle_footer).
807
808
809          || ($t =~ /$_SUFFIX_RULE_PATTERN/o && accept_extensions($1)))
810        {
811
0
          ++$inference_rule_count;
812
0
          register_suffix_rule ($where, $1, $2);
813        }
814    }
815
816  # POSIX allows multiple targets before the colon, but disallows
817  # definitions of multiple inference rules. It's also
818  # disallowed to mix plain targets with inference rules.
819
0
  msg ('portability', $where,
820       "Inference rules can have only one target before the colon (POSIX).")
821    if $inference_rule_count > 0 && $target_count > 1;
822
823
0
  return @conds;
824}
825
826 - 832
=item C<depend ($target, @deps)>

Adds C<@deps> to the dependencies of target C<$target>.  This should
be used only with factored targets (those appearing in
C<%dependees>).

=cut
833
834sub depend ($@)
835{
836
0
1
  my ($category, @dependees) = @_;
837
0
0
  push (@{$dependencies{$category}}, @dependees);
838}
839
840=back
841
842 - 847
=head1 SEE ALSO

L<Automake::RuleDef>, L<Automake::Condition>,
L<Automake::DisjConditions>, L<Automake::Location>.

=cut
848
8491;
850
851### Setup "GNU" style for perl-mode and cperl-mode.
852## Local Variables:
853## perl-indent-level: 2
854## perl-continued-statement-offset: 2
855## perl-continued-brace-offset: 0
856## perl-brace-offset: 0
857## perl-brace-imaginary-offset: 0
858## perl-label-offset: -2
859## cperl-indent-level: 2
860## cperl-brace-offset: 0
861## cperl-continued-brace-offset: 0
862## cperl-label-offset: -2
863## cperl-extra-newline-before-brace: t
864## cperl-merge-trailing-else: nil
865## cperl-continued-statement-offset: 2
866## End: