---
name: "Config::AutoConf"
section: "3pm"
platform: "linux"
package: "perl-config-autoconf"
version: "0.320-7"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Config::AutoConf"
---

# Config::AutoConf(3pm)

A module to implement some of AutoConf macros in pure perl.

## NAME

Config::AutoConf - A module to implement some of AutoConf macros in pure perl.

## ABSTRACT

With this module I pretend to simulate some of the tasks AutoConf macros do. To detect a command, to detect a library, etc.

## 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
```

## DESCRIPTION

Config::AutoConf is intended to provide the same opportunities to Perl developers as GNU Autoconf \<http://www.gnu.org/software/autoconf/\> does for Shell developers.

As Perl is the second most deployed language (mind: every Unix comes with Perl, several mini-computers have Perl and even lot's of Windows machines run Perl software - which requires deployed Perl there, too), this gives wider support than Shell based probes.

The API is leaned against GNU Autoconf, but we try to make the API (especially optional arguments) more Perl'ish than m4 abilities allow to the original.

## CONSTRUCTOR

### new

This function instantiates a new instance of Config::AutoConf, e.g. to configure child components. The constructor adds also values set via environment variable `"PERL5_AUTOCONF_OPTS"`.

## METHODS

### 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.

### check\_files

This function checks if a set of files exist in the system and are readable by the user. Returns a boolean.

### check\_prog( $prog, \\@dirlist?, \\%options? )

This function checks for a program with the supplied name. In success returns the full path for the executable;

An optional array reference containing a list of directories to be searched instead of `$PATH` is gracefully honored.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively.

### check\_progs(progs, \[dirlist\])

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.

An optional array reference containing a list of directories to be searched instead of `$PATH` is gracefully honored.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. The name of the *$prog* to check and the found full path are passed as first and second argument to the *action\_on\_true* callback.

### check\_prog\_yacc

From the GNU Autoconf \<https://www.gnu.org/software/autoconf/autoconf.html\> documentation,

```
  If `bison' is found, set [...] `bison -y'.
  Otherwise, if `byacc' is found, set [...] `byacc'.
  Otherwise set [...] `yacc'.  The result of this test can be influenced
  by setting the variable YACC or the cache variable ac_cv_prog_YACC.
```

Returns the full path, if found.

### check\_prog\_awk

From the GNU Autoconf \<https://www.gnu.org/software/autoconf/autoconf.html\> 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.
  The result can be overridden by setting the variable AWK or the
  cache variable ac_cv_prog_AWK.
```

Note that it returns the full path, if found.

### check\_prog\_egrep

From the GNU Autoconf \<https://www.gnu.org/software/autoconf/autoconf.html\> documentation,

```
  Check for `grep -E' and `egrep', in that order, and [...] output
  [...] the first one that is found.  The result can be overridden by
  setting the EGREP variable and is cached in the ac_cv_path_EGREP
  variable.
```

Note that it returns the full path, if found.

### check\_prog\_lex

From the GNU Autoconf \<https://www.gnu.org/software/autoconf/autoconf.html\> documentation,

```
  If flex is found, set output [...] to ‘flex’ and [...] to -lfl, if that
  library is in a standard place. Otherwise set output [...] to ‘lex’ and
  [...] to -ll, if found. If [...] packages [...] ship the generated
  file.yy.c alongside the source file.l, this [...] allows users without a
  lexer generator to still build the package even if the timestamp for
  file.l is inadvertently changed.
```

Note that it returns the full path, if found.

The structure `$self`-\>{lex} is set with attributes

```
  prog => $LEX
  lib => $LEXLIB
  root => $lex_root
```

### check\_prog\_sed

From the GNU Autoconf \<https://www.gnu.org/software/autoconf/autoconf.html\> documentation,

```
  Set output variable [...] to a Sed implementation that conforms to Posix
  and does not have arbitrary length limits. Report an error if no
  acceptable Sed is found. See Limitations of Usual Tools, for more
  information about portability problems with Sed.
  The result of this test can be overridden by setting the SED variable and
  is cached in the ac_cv_path_SED variable.
```

Note that it returns the full path, if found.

### check\_prog\_pkg\_config

Checks for `"pkg-config"` program. No additional tests are made for it ...

### check\_prog\_cc

Determine a C compiler to use. Currently the probe is delegated to ExtUtils::CBuilder.

### check\_cc

(Deprecated) Old name of "check\_prog\_cc".

### check\_valid\_compiler

This function checks for a valid compiler for the currently active language. At the very moment only `"C"` is understood (corresponding to your compiler default options, e.g. -std=gnu89).

### check\_valid\_compilers(;\\@)

Checks for valid compilers for each given language. When unspecified defaults to `"[ "C" ]"`.

### msg\_checking

Prints "Checking `@_` ..."

### msg\_result

Prints result \\n

### msg\_notice

Prints "configure: " `@_` to stdout

### msg\_warn

Prints "configure: " `@_` to stderr

### msg\_error

Prints "configure: " `@_` to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment)

### msg\_failure

Prints "configure: " `@_` to stderr and exits with exit code 0 (tells toolchain to stop here and report unsupported environment). Additional details are provides in config.log (probably more information in a later stage).

### define\_var( $name, $value \[, $comment \] )

Defines a check variable for later use in further checks or code to compile. Returns the value assigned value

### write\_config\_h( \[$target\] )

Writes the defined constants into given target:

```
  Config::AutoConf->write_config_h( "config.h" );
```

### push\_lang(lang \[, implementor \])

Puts the current used language on the stack and uses specified language for subsequent operations until ending pop\_lang call.

### pop\_lang(\[ lang \])

Pops the currently used language from the stack and restores previously used language. If *lang* specified, it's asserted that the current used language equals to specified language (helps finding control flow bugs).

### lang\_build\_program( prologue, body )

Builds program for current chosen language. If no prologue is given (*undef*), the default headers are used. If body is missing, default body is used.

Typical call of

```
  Config::AutoConf->lang_build_program( "const char hw[] = \"Hello, World\\n\";",
                                        "fputs (hw, stdout);" )
```

will create

```
  const char hw[] = "Hello, World\n";
  /* Override any gcc2 internal prototype to avoid an error.  */
  #ifdef __cplusplus
  extern "C" {
  #endif
  int
  main (int argc, char **argv)
  {
    (void)argc;
    (void)argv;
    fputs (hw, stdout);;
    return 0;
  }
  #ifdef __cplusplus
  }
  #endif
```

### lang\_call( \[prologue\], function )

Builds program which simply calls given function. When given, prologue is prepended otherwise, the default includes are used.

### lang\_builtin( \[prologue\], builtin )

Builds program which simply proves whether a builtin is known to language compiler.

### lang\_build\_bool\_test (prologue, test, \[@decls\])

Builds a static test which will fail to compile when test evaluates to false. If `@decls` is given, it's prepended before the test code at the variable definition place.

### push\_includes

Adds given list of directories to preprocessor/compiler invocation. This is not proved to allow adding directories which might be created during the build.

### push\_preprocess\_flags

Adds given flags to the parameter list for preprocessor invocation.

### push\_compiler\_flags

Adds given flags to the parameter list for compiler invocation.

### push\_libraries

Adds given list of libraries to the parameter list for linker invocation.

### push\_library\_paths

Adds given list of library paths to the parameter list for linker invocation.

### push\_link\_flags

Adds given flags to the parameter list for linker invocation.

### compile\_if\_else( $src, \\%options? )

This function tries to compile specified code and returns a boolean value containing check success state.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively.

### link\_if\_else( $src, \\%options? )

This function tries to compile and link specified code and returns a boolean value containing check success state.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively.

### check\_cached( $cache-key, $check-title, \\&check-call, \\%options? )

Retrieves the result of a previous "check\_cached" invocation from `"cache-key"`, or (when called for the first time) populates the cache by invoking `"\&check_call"`.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed on **every** call to check\_cached (not just the first cache-populating invocation), respectively.

### cache\_val

This function returns the value of a previously check\_cached call.

### check\_decl( $symbol, \\%options? )

This method actually tests whether symbol is defined as a macro or can be used as an r-value, not whether it is really declared, because it is much safer to avoid introducing extra declarations when they are not needed. In order to facilitate use of C++ and overloaded function declarations, it is possible to specify function argument types in parentheses for types which can be zero-initialized:

```
  Config::AutoConf->check_decl("basename(char *)")
```

This method caches its result in the `"ac_cv_decl_<set lang>"`\_symbol variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_decls( symbols, \\%options? )

For each of the symbols (with optional function argument types for C++ overloads), run check\_decl.

Contrary to **GNU Autoconf**, this method does not declare `"HAVE_DECL_symbol"` macros for the resulting `"confdefs.h"`, because it differs as `"check_decl"` between compiling languages.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively. Given callbacks for *action\_on\_symbol\_true* or *action\_on\_symbol\_false* are called for each symbol checked using "check\_decl" receiving the symbol as first argument.

### check\_func( $function, \\%options? )

This method actually tests whether *$funcion* can be linked into a program trying to call *$function*.  This method caches its result in the ac\_cv\_func\_FUNCTION variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

Returns: True if the function was found, false otherwise

### check\_funcs( \\@functions-list, $action-if-true?, $action-if-false? )

The same as check\_func, but takes a list of functions in *\\@functions-list* to look for and checks for each in turn. Define HAVE\_FUNCTION for each function that was found.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.  Given callbacks for *action\_on\_function\_true* or *action\_on\_function\_false* are called for each symbol checked using "check\_func" receiving the symbol as first argument.

### check\_builtin( $builtin, \\%options? )

This method actually tests whether *$builtin* is a supported built-in known by the compiler. Either, by giving us the type of the built-in or by taking the value from `"__has_builtin"`.  This method caches its result in the ac\_cv\_builtin\_FUNCTION variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

Returns: True if the function was found, false otherwise

### check\_type( $symbol, \\%options? )

Check whether type is defined. It may be a compiler builtin type or defined by the includes.  In C, type must be a type-name, so that the expression `"sizeof (type)"` is valid (but `"sizeof ((type))"` is not).

If *type* type is defined, preprocessor macro HAVE\_*type* (in all capitals, with "\*" replaced by "P" and spaces and dots replaced by underscores) is defined.

This method caches its result in the `"ac_cv_type_"`type variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_types( \\@type-list, \\%options? )

For each type in *@type-list*, call check\_type is called to check for type and return the accumulated result (accumulation op is binary and).

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively. Given callbacks for *action\_on\_type\_true* or *action\_on\_type\_false* are called for each symbol checked using "check\_type" receiving the symbol as first argument.

### compute\_int( $expression, @decls?, \\%options )

Returns the value of the integer *expression*. The value should fit in an initializer in a C variable of type signed long.  It should be possible to evaluate the expression at compile-time. If no includes are specified, the default includes are used.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_sizeof\_type( $type, \\%options? )

Checks for the size of the specified type by compiling and define `"SIZEOF_type"` using the determined size.

In opposition to GNU AutoConf, this method can determine size of structure members, e.g.

```
  $ac->check_sizeof_type( "SV.sv_refcnt", { prologue => $include_perl } );
  # or
  $ac->check_sizeof_type( "struct utmpx.ut_id", { prologue => "#include <utmpx.h>" } );
```

This method caches its result in the `"ac_cv_sizeof_<set lang>"`\_type variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_sizeof\_types( type, \\%options? )

For each type check\_sizeof\_type is called to check for size of type.

If *action-if-found* is given, it is additionally executed when all of the sizes of the types could determined. If *action-if-not-found* is given, it is executed when one size of the types could not determined.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively. Given callbacks for *action\_on\_size\_true* or *action\_on\_size\_false* are called for each symbol checked using "check\_sizeof\_type" receiving the symbol as first argument.

### check\_alignof\_type( type, \\%options? )

Define ALIGNOF\_type to be the alignment in bytes of type. *type* must be valid as a structure member declaration or *type* must be a structure member itself.

This method caches its result in the `"ac_cv_alignof_<set lang>"`\_type variable, with *\** mapped to `"p"` and other characters not suitable for a variable name mapped to underscores.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_alignof\_types (type, \[action-if-found\], \[action-if-not-found\], \[prologue = default includes\])

For each type check\_alignof\_type is called to check for align of type.

If *action-if-found* is given, it is additionally executed when all of the aligns of the types could determined. If *action-if-not-found* is given, it is executed when one align of the types could not determined.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively. Given callbacks for *action\_on\_align\_true* or *action\_on\_align\_false* are called for each symbol checked using "check\_alignof\_type" receiving the symbol as first argument.

### check\_member( member, \\%options? )

Check whether *member* is in form of *aggregate*.*member* and *member* is a member of the *aggregate* aggregate.

which are used prior to the aggregate under test.

```
  Config::AutoConf->check_member(
    "struct STRUCT_SV.sv_refcnt",
    {
      action_on_false => sub { Config::AutoConf->msg_failure( "sv_refcnt member required for struct STRUCT_SV" ); },
      prologue => "#include <EXTERN.h>\n#include <perl.h>"
    }
  );
```

This function will return a true value (1) if the member is found.

If *aggregate* aggregate has *member* member, preprocessor macro HAVE\_*aggregate*\_*MEMBER* (in all capitals, with spaces and dots replaced by underscores) is defined.

This macro caches its result in the `"ac_cv_"`aggr\_member variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### check\_members( members, \\%options? )

For each member check\_member is called to check for member of aggregate.

This function will return a true value (1) if at least one member is found.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be favored over `"default includes"` (represented by "\_default\_includes"). If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively. Given callbacks for *action\_on\_member\_true* or *action\_on\_member\_false* are called for each symbol checked using "check\_member" receiving the symbol as first argument.

### check\_header( $header, \\%options? )

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.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. When a *prologue* exists in the optional hash at end, it will be prepended to the tested header. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

### 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.

Passes an optional \\%options hash to each "check\_header" call.

### check\_all\_headers

This function checks each given header for usability and returns true when each header can be used -- otherwise false.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. Each of existing key/value pairs using *prologue*, *action\_on\_cache\_true* or *action\_on\_cache\_false* as key are passed-through to each call of "check\_header". Given callbacks for *action\_on\_header\_true* or *action\_on\_header\_false* are called for each symbol checked using "check\_header" receiving the symbol as first argument.

### check\_stdc\_headers

Checks for standard C89 headers, namely stdlib.h, stdarg.h, string.h and float.h. If those are found, additional all remaining C89 headers are checked: assert.h, ctype.h, errno.h, limits.h, locale.h, math.h, setjmp.h, signal.h, stddef.h, stdio.h and time.h.

Returns a false value if it fails.

Passes an optional \\%options hash to each "check\_all\_headers" call.

### check\_default\_headers

This function checks for some default headers, the std c89 headers and sys/types.h, sys/stat.h, memory.h, strings.h, inttypes.h, stdint.h and unistd.h

Passes an optional \\%options hash to each "check\_all\_headers" call.

### check\_dirent\_header

Check for the following header files. For the first one that is found and defines 'DIR', define the listed C preprocessor macro:

```
  dirent.h      HAVE_DIRENT_H
  sys/ndir.h    HAVE_SYS_NDIR_H
  sys/dir.h     HAVE_SYS_DIR_H
  ndir.h        HAVE_NDIR_H
```

The directory-library declarations in your source code should look something like the following:

```
  #include <sys/types.h>
  #ifdef HAVE_DIRENT_H
  # include <dirent.h>
  # define NAMLEN(dirent) strlen ((dirent)->d_name)
  #else
  # define dirent direct
  # define NAMLEN(dirent) ((dirent)->d_namlen)
  # ifdef HAVE_SYS_NDIR_H
  #  include <sys/ndir.h>
  # endif
  # ifdef HAVE_SYS_DIR_H
  #  include <sys/dir.h>
  # endif
  # ifdef HAVE_NDIR_H
  #  include <ndir.h>
  # endif
  #endif
```

Using the above declarations, the program would declare variables to be of type `"struct dirent"`, not `"struct direct"`, and would access the length of a directory entry name by passing a pointer to a `"struct dirent"` to the `"NAMLEN"` macro.

For the found header, the macro HAVE\_DIRENT\_IN\_${header} is defined.

This method might be obsolescent, as all current systems with directory libraries have `"<dirent.h>"`. Programs supporting only newer OS might not need to use this method.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. Each of existing key/value pairs using *prologue*, *action\_on\_header\_true* (as *action\_on\_true* having the name of the tested header as first argument) or *action\_on\_header\_false* (as *action\_on\_false* having the name of the tested header as first argument) as key are passed-through to each call of "\_check\_header". Given callbacks for *action\_on\_cache\_true* or *action\_on\_cache\_false* are passed to the call of "check\_cached".

### \_check\_perlapi\_program

This method provides the program source which is suitable to do basic compile/link tests to prove perl development environment.

### \_check\_compile\_perlapi

This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, reasonable basic checks - types, etc.)

### check\_compile\_perlapi

This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, reasonable basic checks - types, etc.)

### check\_compile\_perlapi\_or\_die

Dies when not being able to compile using the Perl API

### check\_linkable\_xs\_so

Checks whether a dynamic loadable object containing an XS module can be linked or not. Due the nature of the beast, this test currently always succeed.

### check\_linkable\_xs\_so\_or\_die

Dies when "check\_linkable\_xs\_so" fails.

### check\_loadable\_xs\_so

Checks whether a dynamic loadable object containing an XS module can be loaded or not. Due the nature of the beast, this test currently always succeed.

### check\_loadable\_xs\_so\_or\_die

Dies when "check\_loadable\_xs\_so" fails.

### \_check\_link\_perlapi

This method can be used from other checks to prove whether we have a perl development environment including a suitable libperl or not (perl.h, reasonable basic checks - types, etc.)

Caller must ensure that the linker flags are set appropriate (`"-lperl"` or similar).

### check\_link\_perlapi

This method can be used from other checks to prove whether we have a perl development environment or not (perl.h, libperl.la, reasonable basic checks - types, etc.)

### check\_lib( lib, func, @other-libs?, \\%options? )

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.

In case of function found, the HAVE\_LIBlibrary (all in capitals) preprocessor macro is defined with 1 and `$lib` together with `@other_libs` are added to the list of libraries to link with.

If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the *other-libs* argument: e.g., `"[qw(Xt X11)]"`. Otherwise, this routine may fail to detect that library is present, because linking the test program can fail with unresolved symbols. The other-libraries argument should be limited to cases where it is desirable to test for one library in the presence of another that is not already in LIBS.

This method caches its result in the `"ac_cv_lib_"`lib\_func variable.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.

It's recommended to use search\_libs instead of check\_lib these days.

### search\_libs( function, search-libs, @other-libs?, @extra\_link\_flags?, \\%options? )

```
    Config::AutoConf->search_libs("gethostent", "nsl", [qw(socket net)], {
        action_on_true => sub { ... }
    });
    Config::AutoConf->search_libs("log4cplus_initialize", ["log4cplus"],
        [[qw(stdc++)], [qw(stdc++ unwind)]],
        [qw(-pthread -thread)]
    );
```

Search for a library defining function if it's not already available. This equates to calling

```
    Config::AutoConf->link_if_else(
        Config::AutoConf->lang_call( "", "$function" ) );
```

first with no libraries, then for each library listed in search-libs. *search-libs* must be specified as an array reference to avoid confusion in argument order.

Prepend -llibrary to LIBS for the first library found to contain function.

If linking with library results in unresolved symbols that would be resolved by linking with additional libraries, give those libraries as the *other-libraries* argument: e.g., `"[qw(Xt X11)]"` or `"[qw(intl),` `qw(intl iconv)]"`. Otherwise, this method fails to detect that function is present, because linking the test program always fails with unresolved symbols.

The result of this test is cached in the ac\_cv\_search\_function variable as "none required" if function is already available, as `0` if no library containing function was found, otherwise as the -llibrary option that needs to be prepended to LIBS.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to `"check_cached"`, respectively.  Given callbacks for *action\_on\_lib\_true* or *action\_on\_lib\_false* are called for each library checked using "link\_if\_else" receiving the library as first argument and all `@other_libs` subsequently.

### check\_lm( \\%options? )

This method is used to check if some common `"math.h"` functions are available, and if `"-lm"` is needed. Returns the empty string if no library is needed, or the "-lm" string if libm is needed.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. Each of existing key/value pairs using *action\_on\_func\_true* (as *action\_on\_true* having the name of the tested functions as first argument), *action\_on\_func\_false* (as *action\_on\_false* having the name of the tested functions as first argument), *action\_on\_func\_lib\_true* (as *action\_on\_lib\_true* having the name of the tested functions as first argument), *action\_on\_func\_lib\_false* (as *action\_on\_lib\_false* having the name of the tested functions as first argument) as key are passed- through to each call of "search\_libs". Given callbacks for *action\_on\_lib\_true*, *action\_on\_lib\_false*, *action\_on\_cache\_true* or *action\_on\_cache\_false* are passed to the call of "search\_libs".

**Note** that *action\_on\_lib\_true* and *action\_on\_func\_lib\_true* or *action\_on\_lib\_false* and *action\_on\_func\_lib\_false* cannot be used at the same time, respectively.

### pkg\_config\_package\_flags($package, \\%options?)

```
  use Config::AutoConf

  my $c = Config::AutoConf->new;
  $c->pkg_config_package_flags('log4cplus');
  WriteMakefile(
    ...
    INC  => $c->_get_extra_compiler_flags,
    LIBS => $c->_get_extra_linker_flags,
  );
```

Search for `"pkg-config"` flags for package as specified. The flags which are extracted are `"--cflags"` and `"--libs"`. The extracted flags are appended to the global `"extra_preprocess_flags"`, `"extra_link_flags"` or `"extra_libs"`, respectively. Distinguishing between `"extra_link_flags"` and `"extra_libs"` is essential to avoid conflicts with search\_libs function and family.  In case, no *package configuration* matching given criteria could be found, return a `"false"` value (`0`).

The `"pkg-config"` flags are taken from *environment variables* `"${package}_CFLAGS"` or `"${package}_LIBS"` when defined, respectively. It will be a nice touch to document the particular environment variables for your build procedure - as for above example it should be

```
  $ env log4cplus_CFLAGS="-I/opt/coolapp/include" \
        log4cplus_LIBS="-L/opt/coolapp/lib -Wl,-R/opt/coolapp/lib -llog4cplus" \
    perl Makefile.PL
```

Call `"pkg_config_package_flags"` with the package you're looking for and optional callback whether found or not.

To support stage compiling properly (`"rpath"` vs. library file location), the internal representation is a moving target. Do not use the result directly - the getters \_get\_extra\_compiler\_flags and \_get\_extra\_linker\_flags are strongly encouraged. In case this is not possible, please open a ticket to get informed on invasive changes.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively. If any of *action\_on\_cache\_true*, *action\_on\_cache\_false* is defined, both callbacks are passed to "check\_cached" as *action\_on\_true* or *action\_on\_false* to "check\_cached", respectively.

### \_check\_mm\_pureperl\_build\_wanted

This method proves the `"_argv"` attribute and (when set) the `"PERL_MM_OPT"` whether they contain *PUREPERL\_ONLY=(0\|1)* or not. The attribute `"_force_xs"` is set as appropriate, which allows a compile test to bail out when `"Makefile.PL"` is called with *PUREPERL\_ONLY=0*.

### \_check\_mb\_pureperl\_build\_wanted

This method proves the `"_argv"` attribute and (when set) the `"PERL_MB_OPT"` whether they contain *--pureperl-only* or not.

### \_check\_pureperl\_required

This method calls `"_check_mm_pureperl_build_wanted"` when running under ExtUtils::MakeMaker (`"Makefile.PL"`) or `"_check_mb_pureperl_build_wanted"` when running under a `"Build.PL"` (Module::Build compatible) environment.

When neither is found (`$0` contains neither `"Makefile.PL"` nor `"Build.PL"`), simply 0 is returned.

### check\_pureperl\_required

This check method proves whether a pure perl build is wanted or not by cached-checking `"$self->_check_pureperl_required"`.

### check\_produce\_xs\_build

This routine checks whether XS can be produced. Therefore it does following checks in given order:

- •

  check pure perl environment variables ("check\_pureperl\_required") or command line arguments and return false when pure perl is requested

- •

  check whether a compiler is available ("check\_valid\_compilers") and return false if none found

- •

  check whether a test program accessing Perl API can be compiled and die with error if not

When all checks passed successfully, return a true value.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively.

### check\_produce\_loadable\_xs\_build

This routine proves whether XS should be built and it's possible to create a dynamic linked object which can be loaded using Perl's Dynaloader.

The extension over "check\_produce\_xs\_build" can be avoided by adding the `"notest_loadable_xs"` to `$ENV{PERL5_AC_OPTS}`.

If the very last parameter contains a hash reference, `"CODE"` references to *action\_on\_true* or *action\_on\_false* are executed, respectively.

### \_set\_argv

Intended to act as a helper for evaluating given command line arguments. Stores given arguments in instances `"_argv"` attribute.

Call once at very begin of `"Makefile.PL"` or `"Build.PL"`:

```
  Your::Pkg::Config::AutoConf->_set_args(@ARGV);
```

### \_default\_includes

returns a string containing default includes for program prologue taken from `"autoconf/headers.m4"`:

```
  #include <stdio.h>
  #ifdef HAVE_SYS_TYPES_H
  # include <sys/types.h>
  #endif
  #ifdef HAVE_SYS_STAT_H
  # include <sys/stat.h>
  #endif
  #ifdef STDC_HEADERS
  # include <stdlib.h>
  # include <stddef.h>
  #else
  # ifdef HAVE_STDLIB_H
  #  include <stdlib.h>
  # endif
  #endif
  #ifdef HAVE_STRING_H
  # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
  #  include <memory.h>
  # endif
  # include <string.h>
  #endif
  #ifdef HAVE_STRINGS_H
  # include <strings.h>
  #endif
  #ifdef HAVE_INTTYPES_H
  # include <inttypes.h>
  #endif
  #ifdef HAVE_STDINT_H
  # include <stdint.h>
  #endif
  #ifdef HAVE_UNISTD_H
  # include <unistd.h>
  #endif
```

### \_default\_includes\_with\_perl

returns a string containing default includes for program prologue containing *\_default\_includes* plus

```
  #include <EXTERN.h>
  #include <perl.h>
```

### add\_log\_fh

Push new file handles at end of log-handles to allow tee'ing log-output

### delete\_log\_fh

Removes specified log file handles. This method allows you to shoot yourself in the foot - it doesn't prove whether the primary nor the last handle is removed. Use with caution.

### \_get\_extra\_compiler\_flags

Returns the determined flags required to run the compile stage as string

### \_get\_extra\_linker\_flags

Returns the determined flags required to run the link stage as string

## AUTHOR

Alberto Simões, `"<ambs@cpan.org>"`

Jens Rehsack, `"<rehsack@cpan.org>"`

## NEXT STEPS

Although a lot of work needs to be done, these are the next steps I intend 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.
```

## BUGS

A lot. Portability is a pain. **\<Patches welcome!**\>.

Please report any bugs or feature requests to `"bug-Config-AutoConf@rt.cpan.org"`, or through the web interface at \<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-AutoConf\>.  We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.

## SUPPORT

You can find documentation for this module with the perldoc command.

```
    perldoc Config::AutoConf
```

You can also look for information at:

- •

  AnnoCPAN: Annotated CPAN documentation

  \<http://annocpan.org/dist/Config-AutoConf\>

- •

  CPAN Ratings

  \<http://cpanratings.perl.org/dist/Config-AutoConf\>

- •

  MetaCPAN

  \<https://metacpan.org/release/Config-AutoConf\>

- •

  Git Repository

  \<https://github.com/ambs/Config-AutoConf\>

## ACKNOWLEDGEMENTS

Michael Schwern for kind MacOS X help.

Ken Williams for ExtUtils::CBuilder

Peter Rabbitson for help on refactoring and making the API more Perl'ish

## COPYRIGHT & LICENSE

Copyright 2004-2020 by the Authors

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

## SEE ALSO

**ExtUtils::CBuilder**(3)
