Carles Araguz
Carles Araguz

Reputation: 1177

How can I use "test STRING1 = STRING2" inside an AC_TRY_RUN?

I'm trying to patch a configure.in file in order to enable cross-compilation for a certain package. By now I'm just patching AC_TRY_RUN macros as to enable them to skip the execution of the compiled code and use a predefined variable that contains the result of the test, which should be run a priori.

At the beginning of the file, I inserted lines like this:

dnl -- The following block is used to allow cross-compilation:
CROSSCTEST00=yes dnl -- the result of test 0
CROSSCTEST01=yes dnl -- the result of test 1 
...
CROSSCTESTNN=yes dnl -- the result of test N 
dnl --

dnl This is where this file started previously:
AC_INIT(pl-wam.c)
AC_PREREQ([2.66])

AC_CONFIG_HEADER(config.h)
AC_SUBST(COFLAGS)
AC_SUBST(CWFLAGS)
... 

An then, I'm using the fourth argument of AC_TRY_RUN like this:

AC_TRY_RUN([ // piece of C code ],
    [actions if exit(0)],
    [actions if exit(1)],
    if test "x$CROSSCTEST00" = xyes; then
        dnl same actions if exit(0)
    else
        dnl same actions if exit(1)
    fi)

But it does not work. Despite $CROSSCTEST being yes, the test ... is never true. I also tried this other approach:

AC_TRY_RUN([ // piece of C code ],
    [actions if exit(0)],
    [actions if exit(1)],
    AS_IF([test "x$CROSSCTEST00" = xyes],
        [same actions if exit(0)],
        [dnl same actions if exit(1)]))

...and it doesn't work either. Am I missing something here? Do you think there's a better way to patch a configure.in as to enable cross-compilation?

Upvotes: 0

Views: 181

Answers (1)

William Pursell
William Pursell

Reputation: 212248

Lines in configure.ac or configure.in that are written before AC_INIT do not make it into the configure script. (Look through the resulting configure script to see if your assignments are made.) You can probably just move your assignments to be after the invocation of AC_INIT. But that call to AC_INIT is extremely obsolete, and it seems odd to be requiring autoconf 2.66 while using such an out-dated call. (The name configure.in is also very old-fashioned). You probably want to consider going through the file and looking for out dated cruft, since it probably requires a complete overhaul. (And definitely rename the file configure.ac)

Upvotes: 1

Related Questions