Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I combine AC_SUBST and AC_DEFINE?

Tags:

autoconf

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.

like image 886
Lekensteyn Avatar asked Jan 04 '12 18:01

Lekensteyn


2 Answers

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
like image 103
Lekensteyn Avatar answered Sep 28 '22 03:09

Lekensteyn


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.

like image 41
thiton Avatar answered Sep 28 '22 04:09

thiton