maint: sync from Automake
[autoconf.git] / lib / Autom4te / Configure_ac.pm
blob93dae5782d7cfd06fc16c3c15d9fef70479da5f4
1 # Copyright (C) 2003-2017 Free Software Foundation, Inc.
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.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 ###############################################################
17 # The main copy of this file is in Automake's git repository. #
18 # Updates should be sent to automake-patches@gnu.org. #
19 ###############################################################
21 package Autom4te::Configure_ac;
23 use 5.006;
24 use strict;
25 use Exporter;
26 use Autom4te::Channels;
27 use Autom4te::ChannelDefs;
29 use vars qw (@ISA @EXPORT);
31 @ISA = qw (Exporter);
32 @EXPORT = qw (&find_configure_ac &require_configure_ac);
34 =head1 NAME
36 Autom4te::Configure_ac - Locate configure.ac or configure.in.
38 =head1 SYNOPSIS
40 use Autom4te::Configure_ac;
42 # Try to locate configure.in or configure.ac in the current
43 # directory. It may be absent. Complain if both files exist.
44 my $file_name = find_configure_ac;
46 # Likewise, but bomb out if the file does not exist.
47 my $file_name = require_configure_ac;
49 # Likewise, but in $dir.
50 my $file_name = find_configure_ac ($dir);
51 my $file_name = require_configure_ac ($dir);
53 =over 4
55 =back
57 =head2 Functions
59 =over 4
61 =item C<$configure_ac = find_configure_ac ([$directory])>
63 Find a F<configure.ac> or F<configure.in> file in C<$directory>,
64 defaulting to the current directory. Complain if both files are present.
65 Return the name of the file found, or the former if neither is present.
67 =cut
69 sub find_configure_ac (;@)
71 my ($directory) = @_;
72 $directory ||= '.';
73 my $configure_ac =
74 File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.ac'));
75 my $configure_in =
76 File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.in'));
78 if (-f $configure_in)
80 msg ('obsolete', "autoconf input should be named 'configure.ac'," .
81 " not 'configure.in'");
82 if (-f $configure_ac)
84 msg ('unsupported',
85 "'$configure_ac' and '$configure_in' both present.\n"
86 . "proceeding with '$configure_ac'");
87 return $configure_ac
89 else
91 return $configure_in;
94 return $configure_ac;
98 =item C<$configure_ac = require_configure_ac ([$directory])>
100 Like C<find_configure_ac>, but fail if neither is present.
102 =cut
104 sub require_configure_ac (;$)
106 my $res = find_configure_ac (@_);
107 fatal "'configure.ac' is required" unless -f $res;
108 return $res