/usr/share/perl5/Config/AutoConf.pm is in libconfig-autoconf-perl 0.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | package Config::AutoConf;
use ExtUtils::CBuilder;
use 5.008002;
use Config;
use File::Temp qw/tempfile/;
use File::Spec;
use base 'Exporter';
our @EXPORT = ('$LIBEXT', '$EXEEXT');
use warnings;
use strict;
our $LIBEXT = ($^O =~ /darwin/i) ? ".dylib" : ( ($^O =~ /mswin32/i) ? ".dll" : ".so" );
our $EXEEXT = ($^O =~ /mswin32/i) ? ".exe" : "";
=head1 NAME
Config::AutoConf - A module to implement some of AutoConf macros in pure perl.
=cut
our $VERSION = '0.16';
=head1 ABSTRACT
With this module I pretend to simulate some of the tasks AutoConf
macros do. To detect a command, to detect a library, etc.
=head1 SYNOPSIS
use Config::AutoConf;
Config::AutoConf->check_prog("agrep");
my $grep = Config::AutoConf->check_progs("agrep", "egrep", "grep");
Config::AutoConf->check_header("ncurses.h");
my $curses = Config::AutoConf->check_headers("ncurses.h","curses.h");
Config::AutoConf->check_prog_awk;
Config::AutoConf->check_prog_egrep;
Config::AutoConf->check_cc();
Config::AutoConf->check_lib("ncurses", "tgoto");
Config::AutoConf->check_file("/etc/passwd"); # -f && -r
=head1 FUNCTIONS
=head2 check_file
This function checks if a file exists in the system and is readable by
the user. Returns a boolean. You can use '-f $file && -r $file' so you
don't need to use a function call.
=cut
sub check_file {
my $class = shift;
my $file = shift;
return (-f $file && -r $file);
}
=head2 check_files
This function checks if a set of files exist in the system and are
readable by the user. Returns a boolean.
=cut
sub check_files {
my $class = shift;
for (@_) {
return 0 unless check_file($class, $_)
}
return 1;
}
=head2 check_prog
This function checks for a program with the supplied name. In success
returns the full path for the executable;
=cut
sub check_prog {
my $class = shift;
# sanitize ac_prog
my $ac_prog = _sanitize(shift());
my $PATH = $ENV{PATH};
my $p;
my $ext = "";
$ext = ".exe" if $^O =~ /mswin/i;
for $p (split /$Config{path_sep}/,$PATH) {
my $cmd = File::Spec->catfile($p,$ac_prog.$ext);
return $cmd if -x $cmd;
}
return undef;
}
=head2 check_progs
This function takes a list of program names. Returns the full path for
the first found on the system. Returns undef if none was found.
=cut
sub check_progs {
my $class = shift;
my @progs = @_;
for (@progs) {
my $ans = check_prog($class, $_);
return $ans if $ans;
}
return undef;
}
=head2 check_prog_yacc
From the autoconf documentation,
If `bison' is found, set [...] `bison -y'.
Otherwise, if `byacc' is found, set [...] `byacc'.
Otherwise set [...] `yacc'.
Returns the full path, if found.
=cut
sub check_prog_yacc {
my $class = shift;
my $binary = check_progs(qw/$class bison byacc yacc/);
$binary .= " -y" if ($binary =~ /bison$/);
return $binary;
}
=head2 check_prog_awk
From the autoconf documentation,
Check for `gawk', `mawk', `nawk', and `awk', in that order, and
set output [...] to the first one that is found. It tries
`gawk' first because that is reported to be the best
implementation.
Note that it returns the full path, if found.
=cut
sub check_prog_awk {
my $class = shift;
return check_progs(qw/$class gawk mawk nawk awk/);
}
=head2 check_prog_egrep
From the autoconf documentation,
Check for `grep -E' and `egrep', in that order, and [...] output
[...] the first one that is found.
Note that it returns the full path, if found.
=cut
sub check_prog_egrep {
my $class = shift;
my $grep;
if ($grep = check_prog($class,"grep")) {
my $ans = `echo a | ($grep -E '(a|b)') 2>/dev/null`;
return "$grep -E" if $ans eq "a\n";
}
if ($grep = check_prog($class, "egrep")) {
return $grep;
}
return undef;
}
=head2 check_cc
This function checks if you have a running C compiler.
=cut
sub check_cc {
ExtUtils::CBuilder->new(quiet => 1)->have_compiler;
}
=head2 check_headers
This function uses check_header to check if a set of include files exist in the system and can
be included and compiled by the available compiler. Returns the name of the first header file found.
=cut
sub check_headers {
my $class = shift;
for (@_) {
return $_ if check_header($class, $_)
}
return undef;
}
=head2 check_header
This function is used to check if a specific header file is present in
the system: if we detect it and if we can compile anything with that
header included. Note that normally you want to check for a header
first, and then check for the corresponding library (not all at once).
The standard usage for this module is:
Config::AutoConf->check_header("ncurses.h");
This function will return a true value (1) on success, and a false value
if the header is not present or not available for common usage.
=cut
sub check_header {
my $class = shift;
my $header = shift;
my $cbuilder = ExtUtils::CBuilder->new(quiet => 1);
return 0 unless $header;
# print STDERR "Trying to compile a test program to check [$header] availability...\n";
my $conftest = <<"_ACEOF";
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
#include <$header>
int
main ()
{
return 0;
}
_ACEOF
my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c');
$filename =~ m!^(.*).c$!;
my $base = $1;
print {$fh} $conftest;
close $fh;
my $obj_file = eval{ $cbuilder->compile(source => $filename) };
if ($@ || !$obj_file) {
unlink $filename;
unlink $obj_file if $obj_file;
return 0
}
my $exe_file = eval { $cbuilder->link_executable(objects => $obj_file) };
unlink $filename;
unlink $obj_file if $obj_file;
unlink $exe_file if $exe_file;
return 0 if $@;
return 0 unless $exe_file;
return 1;
}
=head2 check_lib
This function is used to check if a specific library includes some
function. Call it with the library name (without the lib portion), and
the name of the function you want to test:
Config::AutoConf->check_lib("z", "gzopen");
It returns 1 if the function exist, 0 otherwise.
=cut
sub check_lib {
my $class = shift;
my $lib = shift;
my $func = shift;
my $cbuilder = ExtUtils::CBuilder->new(quiet => 1);
return 0 unless $lib;
return 0 unless $func;
# print STDERR "Trying to compile test program to check [$func] on [$lib] library...\n";
my $LIBS = "-l$lib";
my $conftest = <<"_ACEOF";
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char $func ();
int
main ()
{
$func ();
return 0;
}
_ACEOF
my ($fh, $filename) = tempfile( "testXXXXXX", SUFFIX => '.c');
$filename =~ m!(.*).c$!;
my $base = $1;
print {$fh} $conftest;
close $fh;
my $obj_file = eval{ $cbuilder->compile(source => $filename) };
if ($@ || !$obj_file) {
unlink $filename;
unlink $obj_file if $obj_file;
return 0
}
my $exe_file = eval { $cbuilder->link_executable(objects => $obj_file,
extra_linker_flags => $LIBS) };
unlink $filename;
unlink $obj_file if $obj_file;
unlink $exe_file if $exe_file;
return 0 if $@;
return 0 unless $exe_file;
return 1;
}
#
#
# Auxiliary funcs
#
sub _sanitize {
# This is hard coded, and maybe a little stupid...
my $x = shift;
$x =~ s/ //g;
$x =~ s/\///g;
$x =~ s/\\//g;
return $x;
}
=head1 AUTHOR
Alberto Simões, C<< <ambs@cpan.org> >>
=head1 NEXT STEPS
Although a lot of work needs to be done, this is the next steps I
intent to take.
- detect flex/lex
- detect yacc/bison/byacc
- detect ranlib (not sure about its importance)
These are the ones I think not too much important, and will be
addressed later, or by request.
- detect an 'install' command
- detect a 'ln -s' command -- there should be a module doing
this kind of task.
=head1 BUGS
A lot. Portability is a pain. B<<Patches welcome!>>.
Please report any bugs or feature requests to
C<bug-extutils-autoconf@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>. I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.
=head1 ACKNOWLEDGEMENTS
Michael Schwern for kind MacOS X help.
Ken Williams for ExtUtils::CBuilder
=head1 COPYRIGHT & LICENSE
Copyright 2004-2005 Alberto Simões, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 SEE ALSO
ExtUtils::CBuilder(3)
=cut
1; # End of Config::AutoConf
|