Q:

How do I combine AC_SUBST and AC_DEFINE?

I've a configure.ac file containing lines like:
AC_DEFINE(CONF_XDISP, ":8", "X screen number")

These constants are used in the C source for setting compile defaults. I also have a configuration file conf/bumblebee.conf in which these defaults need to be set. I'm told that AC_SUBST can be used to get @CONF_XDISP@ substituted for ":8" such that the below line:
VGL_DISPLAY=@CONF_XDISP@

becomes:
VGL_DISPLAY=":8"

Making an AC_SUBST line for each AC_DEFINE does not look the best way to me as it includes a lot duplication of lines. How can I combine these options, such that I can use something like AC_DEFINE_SUBST? Other ideas and suggestions to improve this are welcome too.

A:

m4 is a macro language, after all, so something like
 AC_DEFUN([AC_DEFINE_SUBST], 
   [AC_DEFINE($1,$2,$3) 
    AC_SUBST($1)])

should do the trick. You might have to fiddle with [ a little to get escaping right.

A:

Thanks to thinton, I could cook up the below code:
# AC_DEFINE_SUBST(NAME, VALUE, DESCRIPTION)
# -----------------------------------------
AC_DEFUN([AC_DEFINE_SUBST], [
AC_DEFINE([$1], [$2], [$3])
AC_SUBST([$1], ['$2'])
])

For AC_DEFINE_SUBST(CONF_XDISP, ":8", "X screen number"), this generates a configure file containing:
$as_echo "#define CONF_XDISP \":8 \$PWD\"" >>confdefs.h

CONF_XDISP='":8"'

Related docs:

http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.68/html_node/Setting-Output-Variables.html
http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.68/html_node/Macro-Definitions.html

