home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / automake-1.8 / Automake / Options.pm < prev    next >
Encoding:
Perl POD Document  |  2005-10-16  |  8.3 KB  |  364 lines

  1. # Copyright (C) 2003  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, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. # 02111-1307, USA.
  17.  
  18. package Automake::Options;
  19.  
  20. use strict;
  21. use Exporter;
  22. use Automake::Config;
  23. use Automake::ChannelDefs;
  24. use Automake::Channels;
  25. use Automake::Version;
  26.  
  27. use vars qw (@ISA @EXPORT);
  28.  
  29. @ISA = qw (Exporter);
  30. @EXPORT = qw (option global_option
  31.           set_option set_global_option
  32.           unset_option unset_global_option
  33.           process_option_list process_global_option_list
  34.           set_strictness $strictness $strictness_name
  35.           &FOREIGN &GNU &GNITS);
  36.  
  37. =head1 NAME
  38.  
  39. Automake::Options - keep track of Automake options
  40.  
  41. =head1 SYNOPSIS
  42.  
  43.   use Automake::Options;
  44.  
  45.   # Option lookup and setting.
  46.   $opt = option 'name';
  47.   $opt = global_option 'name';
  48.   set_option 'name', 'value';
  49.   set_global_option 'name', 'value';
  50.   unset_option 'name';
  51.   unset_global_option 'name';
  52.  
  53.   # Batch option setting.
  54.   process_option_list $location, @names;
  55.   process_global_option_list $location, @names;
  56.  
  57.   # Strictness lookup and setting.
  58.   set_strictness 'foreign';
  59.   set_strictness 'gnu';
  60.   set_strictness 'gnits';
  61.   if ($strictness >= GNU) { ... }
  62.   print "$strictness_name\n";
  63.  
  64. =head1 DESCRIPTION
  65.  
  66. This packages manages Automake's options and strictness settings.
  67. Options can be either local or global.  Local options are set using an
  68. C<AUTOMAKE_OPTIONS> variable in a F<Makefile.am> and apply only to
  69. this F<Makefile.am>.  Global options are set from the command line or
  70. passed as an argument to C<AM_INIT_AUTOMAKE>, they apply to all
  71. F<Makefile.am>s.
  72.  
  73. =cut
  74.  
  75. # Values are the Automake::Location of the definition, except
  76. # for 'ansi2knr' whose value is a pair [filename, Location].
  77. use vars '%_options';        # From AUTOMAKE_OPTIONS
  78. use vars '%_global_options';    # from AM_INIT_AUTOMAKE or the command line.
  79.  
  80. =head2 Constants
  81.  
  82. =over 4
  83.  
  84. =item FOREIGN
  85.  
  86. =item GNU
  87.  
  88. =item GNITS
  89.  
  90. Strictness constants used as values for C<$strictness>.
  91.  
  92. =back
  93.  
  94. =cut
  95.  
  96. # Constants to define the "strictness" level.
  97. use constant FOREIGN => 0;
  98. use constant GNU     => 1;
  99. use constant GNITS   => 2;
  100.  
  101. =head2 Variables
  102.  
  103. =over 4
  104.  
  105. =item C<$strictness>
  106.  
  107. The current stricness.  One of C<FOREIGN>, C<GNU>, or C<GNITS>.
  108.  
  109. =item C<$strictness_name>
  110.  
  111. The current stricness name.  One of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
  112.  
  113. =back
  114.  
  115. =cut
  116.  
  117. # Strictness levels.
  118. use vars qw ($strictness $strictness_name);
  119.  
  120. # Strictness level as set on command line.
  121. use vars qw ($_default_strictness $_default_strictness_name);
  122.  
  123.  
  124. =head2 Functions
  125.  
  126. =over 4
  127.  
  128. =item C<Automake::Options::reset>
  129.  
  130. Reset the options variables for the next F<Makefile.am>.
  131.  
  132. In other words, this gets rid of all local options in use by the
  133. previous F<Makefile.am>.
  134.  
  135. =cut
  136.  
  137. sub reset ()
  138. {
  139.   %_options = %_global_options;
  140.   # The first time we are run,
  141.   # remember the current setting as the default.
  142.   if (defined $_default_strictness)
  143.     {
  144.       $strictness = $_default_strictness;
  145.       $strictness_name = $_default_strictness_name;
  146.     }
  147.   else
  148.     {
  149.       $_default_strictness = $strictness;
  150.       $_default_strictness_name = $strictness_name;
  151.     }
  152. }
  153.  
  154. =item C<$value = option ($name)>
  155.  
  156. =item C<$value = global_option ($name)>
  157.  
  158. Query the state of an option.  If the option is unset, this
  159. returns the empty list.  Otherwise it returns the option's value,
  160. as set by C<set_option> or C<set_global_option>.
  161.  
  162. Not that C<global_option> should be used only when it is
  163. important to make sure an option hasn't been set locally.
  164. Otherwise C<option> should be the standard function to
  165. check for options (be they global or local).
  166.  
  167. =cut
  168.  
  169. sub option ($)
  170. {
  171.   my ($name) = @_;
  172.   return () unless defined $_options{$name};
  173.   return $_options{$name};
  174. }
  175.  
  176. sub global_option ($)
  177. {
  178.   my ($name) = @_;
  179.   return () unless defined $_global_options{$name};
  180.   return $_global_options{$name};
  181. }
  182.  
  183. =item C<set_option ($name, $value)>
  184.  
  185. =item C<set_global_option ($name, $value)>
  186.  
  187. Set an option.  By convention, C<$value> is usually the location
  188. of the option definition.
  189.  
  190. =cut
  191.  
  192. sub set_option ($$)
  193. {
  194.   my ($name, $value) = @_;
  195.   $_options{$name} = $value;
  196. }
  197.  
  198. sub set_global_option ($$)
  199. {
  200.   my ($name, $value) = @_;
  201.   $_global_options{$name} = $value;
  202. }
  203.  
  204.  
  205. =item C<unset_option ($name)>
  206.  
  207. =item C<unset_global_option ($name)>
  208.  
  209. Unset an option.
  210.  
  211. =cut
  212.  
  213. sub unset_option ($)
  214. {
  215.   my ($name) = @_;
  216.   delete $_options{$name};
  217. }
  218.  
  219. sub unset_global_option ($)
  220. {
  221.   my ($name) = @_;
  222.   delete $_global_options{$name};
  223. }
  224.  
  225.  
  226. =item C<process_option_list ($where, @options)>
  227.  
  228. =item C<process_global_option_list ($where, @options)>
  229.  
  230. Process Automake's option lists.  C<@options> should be a list of
  231. words, as they occur in C<AUTOMAKE_OPTIONS> or C<AM_INIT_AUTOMAKE>.
  232.  
  233. Return 1 on error, 0 otherwise.
  234.  
  235. =cut
  236.  
  237. # $BOOL
  238. # _process_option_list (\%OPTIONS, $WHERE, @OPTIONS)
  239. # -------------------------------------------------
  240. # Process a list of options.  Return 1 on error, 0 otherwise.
  241. # \%OPTIONS is the hash to fill with options data, $WHERE is
  242. # the location where @OPTIONS occured.
  243. sub _process_option_list (\%$@)
  244. {
  245.   my ($options, $where, @list) = @_;
  246.  
  247.   foreach (@list)
  248.     {
  249.       $options->{$_} = $where;
  250.       if ($_ eq 'gnits' || $_ eq 'gnu' || $_ eq 'foreign')
  251.     {
  252.       set_strictness ($_);
  253.     }
  254.       elsif (/^(.*\/)?ansi2knr$/)
  255.     {
  256.       # An option like "../lib/ansi2knr" is allowed.  With no
  257.       # path prefix, we assume the required programs are in this
  258.       # directory.  We save the actual option for later.
  259.       $options->{'ansi2knr'} = [$_, $where];
  260.     }
  261.       elsif ($_ eq 'no-installman' || $_ eq 'no-installinfo'
  262.          || $_ eq 'dist-shar' || $_ eq 'dist-zip'
  263.          || $_ eq 'dist-tarZ' || $_ eq 'dist-bzip2'
  264.          || $_ eq 'no-dist-gzip' || $_ eq 'no-dist'
  265.          || $_ eq 'dejagnu' || $_ eq 'no-texinfo.tex'
  266.          || $_ eq 'readme-alpha' || $_ eq 'check-news'
  267.          || $_ eq 'subdir-objects' || $_ eq 'nostdinc'
  268.          || $_ eq 'no-exeext' || $_ eq 'no-define'
  269.          || $_ eq 'std-options'
  270.          || $_ eq 'cygnus' || $_ eq 'no-dependencies')
  271.     {
  272.       # Explicitly recognize these.
  273.     }
  274.       elsif (/^\d+\.\d+(?:\.\d+)?[a-z]?(?:-[A-Za-z0-9]+)?$/)
  275.     {
  276.       # Got a version number.
  277.       if (Automake::Version::check ($VERSION, $&))
  278.         {
  279.           error ($where, "require Automake $_, but have $VERSION",
  280.              uniq_scope => US_GLOBAL);
  281.           return 1;
  282.         }
  283.     }
  284.       elsif (/^(?:--warnings=|-W)(.*)$/)
  285.     {
  286.       foreach my $cat (split (',', $1))
  287.         {
  288.           msg 'unsupported', $where, "unknown warning category `$cat'"
  289.         if switch_warning $cat;
  290.         }
  291.     }
  292.       else
  293.     {
  294.       error ($where, "option `$_' not recognized",
  295.          uniq_scope => US_GLOBAL);
  296.       return 1;
  297.     }
  298.     }
  299.   return 0;
  300. }
  301.  
  302. sub process_option_list ($@)
  303. {
  304.   my ($where, @list) = @_;
  305.   return _process_option_list (%_options, $where, @list);
  306. }
  307.  
  308. sub process_global_option_list ($@)
  309. {
  310.   my ($where, @list) = @_;
  311.   return _process_option_list (%_global_options, $where, @list);
  312. }
  313.  
  314. =item C<set_strictness ($name)>
  315.  
  316. Set the current strictness level.
  317. C<$name> should be one of C<'foreign'>, C<'gnu'>, or C<'gnits'>.
  318.  
  319. =cut
  320.  
  321. # Set strictness.
  322. sub set_strictness ($)
  323. {
  324.   $strictness_name = $_[0];
  325.  
  326.   Automake::ChannelDefs::set_strictness ($strictness_name);
  327.  
  328.   if ($strictness_name eq 'gnu')
  329.     {
  330.       $strictness = GNU;
  331.     }
  332.   elsif ($strictness_name eq 'gnits')
  333.     {
  334.       $strictness = GNITS;
  335.     }
  336.   elsif ($strictness_name eq 'foreign')
  337.     {
  338.       $strictness = FOREIGN;
  339.     }
  340.   else
  341.     {
  342.       prog_error "level `$strictness_name' not recognized\n";
  343.     }
  344. }
  345.  
  346. 1;
  347.  
  348. ### Setup "GNU" style for perl-mode and cperl-mode.
  349. ## Local Variables:
  350. ## perl-indent-level: 2
  351. ## perl-continued-statement-offset: 2
  352. ## perl-continued-brace-offset: 0
  353. ## perl-brace-offset: 0
  354. ## perl-brace-imaginary-offset: 0
  355. ## perl-label-offset: -2
  356. ## cperl-indent-level: 2
  357. ## cperl-brace-offset: 0
  358. ## cperl-continued-brace-offset: 0
  359. ## cperl-label-offset: -2
  360. ## cperl-extra-newline-before-brace: t
  361. ## cperl-merge-trailing-else: nil
  362. ## cperl-continued-statement-offset: 2
  363. ## End:
  364.