7

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.

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192

2 Answers2

8

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:

Community
  • 1
  • 1
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
  • Note that if you add indentation befor `AC_SUBST`, it'll show up in the generated `configure` code. I don't know if there is a shell that cannot handle that, but safety I'll just leave the indentation away. – Lekensteyn Jan 04 '12 at 22:46
  • 2
    The `AC_` namespace belongs to autoconf, so I suggest you use `AX_DEFINE_SUBST`. – Jack Kelly Jan 13 '12 at 12:01
7

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.

thiton
  • 35,651
  • 4
  • 70
  • 100
  • Looks promising, I'm going to try it. Reference to docs: http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.68/html_node/Macro-Definitions.html#index-AC_005fDEFUN-1585 – Lekensteyn Jan 04 '12 at 20:10
  • 2
    I needed to add another param to `AC_SUBST`, otherwise the keyword was replaced by an empty string. The single quotes are necessary to prevent shell interpretation. +1 for getting me in the right direction. – Lekensteyn Jan 04 '12 at 22:44