Hi All,

I'm trying to get a value provided on the ./configure invocation
through to C code so it can be used. I'm trying to do this with
AC_DEFINE but maybe this is a job for something else.

Perhaps this is easiest to understand with some code so here's a dummy
example

== configure.ac ==
AC_PREREQ([2.69])
AC_INIT([test], [0.1], [])
AM_INIT_AU
TOMAKE([foreign])
AC_CONFIG_SRCDIR([test.c])
AC_CONFIG_HEADERS([config.h]
)

AC_PROG_CC
AC_CONFIG_FILES([Makefile])
AC_ARG_ENABLE([entity],
  [AS_HELP_STRING([--enable-entity],
    [Set entity @<:@default=World@:>@])],
  [],
  [enable_enity=World])

AC_DEFINE([ENTITY],[${enable_entity}],[Entity])
AC_OUTPUT

== Makefile.am ==
AM_CPPFLAGS = -include config.h
bin_PROGRAMS = test

== test.c ==
#include <stdio.h>

int main(int argc, char *argv[])
{
       printf("Hello %s!\n", ENTITY);
       return 0;
}

I'd like to be able to run

$ ./configure --enable-entity=Universe
$ make && ./test

And get 

  Hello Universe!

But the value isn't making it through to the code. Instead I get a
compile error

In file included from <command-line>:0:0:
test.c: In function ‘main’:
./config.h:5:16: error: ‘$’ undeclared (first use in this function)
 #define ENTITY ${enable_entity}

Which is a bit too literal. I suspect I'm missing something (like
AC_SUBST). But I can't for all the searching figure out how to get a
value from the ./configure invocation through to the end program.

Any help would be greatly appreciated.

Thanks,
Chris
_______________________________________________
Autoconf mailing list
Autoconf@gnu.org
https://lists.gnu.org/mailman/listinfo/autoconf

Reply via email to