| 1 |
# Copyright (C) 2003-2025 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 <https://www.gnu.org/licenses/>. |
| 15 |
|
| 16 |
################################################################## |
| 17 |
# The master copy of this file is in Automake's source repository. |
| 18 |
# Please send updates to [email protected]. |
| 19 |
################################################################## |
| 20 |
|
| 21 |
package Autom4te::Configure_ac; |
| 22 |
|
| 23 |
use 5.006; use strict; use warnings; |
| 24 |
|
| 25 |
use Exporter; |
| 26 |
|
| 27 |
use Autom4te::ChannelDefs; |
| 28 |
use Autom4te::Channels; |
| 29 |
|
| 30 |
our @ISA = qw (Exporter); |
| 31 |
our @EXPORT = qw (&find_configure_ac &require_configure_ac); |
| 32 |
|
| 33 |
=head1 NAME |
| 34 |
|
| 35 |
Autom4te::Configure_ac - Locate configure.ac or configure.in. |
| 36 |
|
| 37 |
=head1 SYNOPSIS |
| 38 |
|
| 39 |
use Autom4te::Configure_ac; |
| 40 |
|
| 41 |
# Try to locate configure.in or configure.ac in the current |
| 42 |
# directory. It may be absent. Complain if both files exist. |
| 43 |
my $file_name = find_configure_ac; |
| 44 |
|
| 45 |
# Likewise, but bomb out if the file does not exist. |
| 46 |
my $file_name = require_configure_ac; |
| 47 |
|
| 48 |
# Likewise, but in $dir. |
| 49 |
my $file_name = find_configure_ac ($dir); |
| 50 |
my $file_name = require_configure_ac ($dir); |
| 51 |
|
| 52 |
=over 4 |
| 53 |
|
| 54 |
=back |
| 55 |
|
| 56 |
=head2 Functions |
| 57 |
|
| 58 |
=over 4 |
| 59 |
|
| 60 |
=item C<$configure_ac = find_configure_ac ([$directory])> |
| 61 |
|
| 62 |
Find a F<configure.ac> or F<configure.in> file in C<$directory>, |
| 63 |
defaulting to the current directory. Complain if both files are present. |
| 64 |
Return the name of the file found, or the former if neither is present. |
| 65 |
|
| 66 |
=cut |
| 67 |
|
| 68 |
sub find_configure_ac (;@) |
| 69 |
{ |
| 70 |
my ($directory) = @_; |
| 71 |
$directory ||= '.'; |
| 72 |
my $configure_ac = |
| 73 |
File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.ac')); |
| 74 |
my $configure_in = |
| 75 |
File::Spec->canonpath (File::Spec->catfile ($directory, 'configure.in')); |
| 76 |
|
| 77 |
if (-f $configure_in) |
| 78 |
{ |
| 79 |
msg ('obsolete', "autoconf input should be named 'configure.ac'," . |
| 80 |
" not 'configure.in'"); |
| 81 |
if (-f $configure_ac) |
| 82 |
{ |
| 83 |
msg ('unsupported', |
| 84 |
"'$configure_ac' and '$configure_in' both present.\n" |
| 85 |
. "proceeding with '$configure_ac'"); |
| 86 |
return $configure_ac |
| 87 |
} |
| 88 |
else |
| 89 |
{ |
| 90 |
return $configure_in; |
| 91 |
} |
| 92 |
} |
| 93 |
return $configure_ac; |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
=item C<$configure_ac = require_configure_ac ([$directory])> |
| 98 |
|
| 99 |
Like C<find_configure_ac>, but fail if neither is present. |
| 100 |
|
| 101 |
=cut |
| 102 |
|
| 103 |
sub require_configure_ac (;$) |
| 104 |
{ |
| 105 |
my $res = find_configure_ac (@_); |
| 106 |
fatal "'configure.ac' is required" unless -f $res; |
| 107 |
return $res |
| 108 |
} |
| 109 |
|
| 110 |
1; |