caaad0701a35bc1e003ed8246c56e613d45aca5d
[platform/upstream/automake.git] / lib / Automake / Configure_ac.pm
1 # Copyright (C) 2003, 2005, 2006  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., 51 Franklin Street, Fifth Floor, Boston, MA
16 # 02110-1301, USA.
17
18 ###############################################################
19 # The main copy of this file is in Automake's CVS repository. #
20 # Updates should be sent to automake-patches@gnu.org.         #
21 ###############################################################
22
23 package Automake::Configure_ac;
24
25 use strict;
26 use Exporter;
27 use Automake::Channels;
28 use Automake::ChannelDefs;
29
30 use vars qw (@ISA @EXPORT);
31
32 @ISA = qw (Exporter);
33 @EXPORT = qw (&find_configure_ac &require_configure_ac);
34
35 =head1 NAME
36
37 Automake::Configure_ac - Locate configure.ac or configure.in.
38
39 =head1 SYNOPSIS
40
41   use Automake::Configure_ac;
42
43   # Try to locate configure.in or configure.ac in the current
44   # directory.  It may be absent.  Complain if both files exist.
45   my $file_name = find_configure_ac;
46
47   # Likewise, but bomb out if the file does not exist.
48   my $file_name = require_configure_ac;
49
50   # Likewise, but in $dir.
51   my $file_name = find_configure_ac ($dir);
52   my $file_name = require_configure_ac ($dir);
53
54 =cut
55
56 sub find_configure_ac (;@)
57 {
58   my ($directory) = @_;
59   $directory ||= '.';
60   my $configure_ac =
61     File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.ac'));
62   my $configure_in =
63     File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.in'));
64
65   if (-f $configure_ac)
66     {
67       if (-f $configure_in)
68         {
69           msg ('unsupported',
70                "`$configure_ac' and `$configure_in' both present.\n"
71                . "proceeding with `$configure_ac'.");
72         }
73       return $configure_ac
74     }
75   elsif (-f $configure_in)
76     {
77       return $configure_in;
78     }
79   return $configure_ac;
80 }
81
82
83 sub require_configure_ac (;$)
84 {
85   my $res = find_configure_ac (@_);
86   fatal "`configure.ac' or `configure.in' is required"
87     unless -f $res;
88   return $res
89 }
90
91 1;
92
93 ### Setup "GNU" style for perl-mode and cperl-mode.
94 ## Local Variables:
95 ## perl-indent-level: 2
96 ## perl-continued-statement-offset: 2
97 ## perl-continued-brace-offset: 0
98 ## perl-brace-offset: 0
99 ## perl-brace-imaginary-offset: 0
100 ## perl-label-offset: -2
101 ## cperl-indent-level: 2
102 ## cperl-brace-offset: 0
103 ## cperl-continued-brace-offset: 0
104 ## cperl-label-offset: -2
105 ## cperl-extra-newline-before-brace: t
106 ## cperl-merge-trailing-else: nil
107 ## cperl-continued-statement-offset: 2
108 ## End: