autoconf: Generating Sources
1
1 6.2.3 Generating Sources
1 ------------------------
1
1 Autoconf provides a set of macros that can be used to generate test
1 source files. They are written to be language generic, i.e., they
1 actually depend on the current language (⇒Language Choice) to
1 "format" the output properly.
1
1 -- Macro: AC_LANG_CONFTEST (SOURCE)
1 Save the SOURCE text in the current test source file:
1 `conftest.EXTENSION' where the EXTENSION depends on the current
1 language. As of Autoconf 2.63b, the source file also contains the
1 results of all of the `AC_DEFINE' performed so far.
1
1 Note that the SOURCE is evaluated exactly once, like regular
1 Autoconf macro arguments, and therefore (i) you may pass a macro
1 invocation, (ii) if not, be sure to double quote if needed.
1
1 This macro issues a warning during `autoconf' processing if SOURCE
1 does not include an expansion of the macro
1 `AC_LANG_DEFINES_PROVIDED' (note that both `AC_LANG_SOURCE' and
1 `AC_LANG_PROGRAM' call this macro, and thus avoid the warning).
1
1 This macro is seldom called directly, but is used under the hood
1 by more common macros such as `AC_COMPILE_IFELSE' and
1 `AC_RUN_IFELSE'.
1
1 -- Macro: AC_LANG_DEFINES_PROVIDED
1 This macro is called as a witness that the file
1 `conftest.EXTENSION' appropriate for the current language is
1 complete, including all previously determined results from
1 `AC_DEFINE'. This macro is seldom called directly, but exists if
1 you have a compelling reason to write a conftest file without using
1 `AC_LANG_SOURCE', yet still want to avoid a syntax warning from
1 `AC_LANG_CONFTEST'.
1
1 -- Macro: AC_LANG_SOURCE (SOURCE)
1 Expands into the SOURCE, with the definition of all the
1 `AC_DEFINE' performed so far. This macro includes an expansion of
1 `AC_LANG_DEFINES_PROVIDED'.
1
1 In many cases, you may find it more convenient to use the wrapper
1 `AC_LANG_PROGRAM'.
1
1 For instance, executing (observe the double quotation!):
1
1 AC_INIT([Hello], [1.0], [bug-hello@example.org], [],
1 [http://www.example.org/])
1 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
1 [Greetings string.])
1 AC_LANG([C])
1 AC_LANG_CONFTEST(
1 [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
1 gcc -E -dD conftest.c
1
1 on a system with `gcc' installed, results in:
1
1 ...
1 # 1 "conftest.c"
1
1 #define PACKAGE_NAME "Hello"
1 #define PACKAGE_TARNAME "hello"
1 #define PACKAGE_VERSION "1.0"
1 #define PACKAGE_STRING "Hello 1.0"
1 #define PACKAGE_BUGREPORT "bug-hello@example.org"
1 #define PACKAGE_URL "http://www.example.org/"
1 #define HELLO_WORLD "Hello, World\n"
1
1 const char hw[] = "Hello, World\n";
1
1 When the test language is Fortran, Erlang, or Go, the `AC_DEFINE'
1 definitions are not automatically translated into constants in the
1 source code by this macro.
1
1 -- Macro: AC_LANG_PROGRAM (PROLOGUE, BODY)
1 Expands into a source file which consists of the PROLOGUE, and
1 then BODY as body of the main function (e.g., `main' in C). Since
1 it uses `AC_LANG_SOURCE', the features of the latter are available.
1
1 For instance:
1
1 AC_INIT([Hello], [1.0], [bug-hello@example.org], [],
1 [http://www.example.org/])
1 AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
1 [Greetings string.])
1 AC_LANG_CONFTEST(
1 [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
1 [[fputs (hw, stdout);]])])
1 gcc -E -dD conftest.c
1
1 on a system with `gcc' installed, results in:
1
1 ...
1 # 1 "conftest.c"
1
1 #define PACKAGE_NAME "Hello"
1 #define PACKAGE_TARNAME "hello"
1 #define PACKAGE_VERSION "1.0"
1 #define PACKAGE_STRING "Hello 1.0"
1 #define PACKAGE_BUGREPORT "bug-hello@example.org"
1 #define PACKAGE_URL "http://www.example.org/"
1 #define HELLO_WORLD "Hello, World\n"
1
1 const char hw[] = "Hello, World\n";
1 int
1 main ()
1 {
1 fputs (hw, stdout);
1 ;
1 return 0;
1 }
1
1 In Erlang tests, the created source file is that of an Erlang module
1 called `conftest' (`conftest.erl'). This module defines and exports at
1 least one `start/0' function, which is called to perform the test. The
1 PROLOGUE is optional code that is inserted between the module header and
1 the `start/0' function definition. BODY is the body of the `start/0'
1 function without the final period (⇒Runtime, about constraints
1 on this function's behavior).
1
1 For instance:
1
1 AC_INIT([Hello], [1.0], [bug-hello@example.org])
1 AC_LANG(Erlang)
1 AC_LANG_CONFTEST(
1 [AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],
1 [[io:format("~s~n", [?HELLO_WORLD])]])])
1 cat conftest.erl
1
1 results in:
1
1 -module(conftest).
1 -export([start/0]).
1 -define(HELLO_WORLD, "Hello, world!").
1 start() ->
1 io:format("~s~n", [?HELLO_WORLD])
1 .
1
1 -- Macro: AC_LANG_CALL (PROLOGUE, FUNCTION)
1 Expands into a source file which consists of the PROLOGUE, and
1 then a call to the FUNCTION as body of the main function (e.g.,
1 `main' in C). Since it uses `AC_LANG_PROGRAM', the feature of the
1 latter are available.
1
1 This function will probably be replaced in the future by a version
1 which would enable specifying the arguments. The use of this
1 macro is not encouraged, as it violates strongly the typing system.
1
1 This macro cannot be used for Erlang tests.
1
1 -- Macro: AC_LANG_FUNC_LINK_TRY (FUNCTION)
1 Expands into a source file which uses the FUNCTION in the body of
1 the main function (e.g., `main' in C). Since it uses
1 `AC_LANG_PROGRAM', the features of the latter are available.
1
1 As `AC_LANG_CALL', this macro is documented only for completeness.
1 It is considered to be severely broken, and in the future will be
1 removed in favor of actual function calls (with properly typed
1 arguments).
1
1 This macro cannot be used for Erlang tests.
1