How do I combine AC_SUBST and AC_DEFINE?
Asked Answered
O

2

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.

Ombre answered 4/1, 2012 at 18:53 Comment(0)
O
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:

Ombre answered 4/1, 2012 at 22:40 Comment(2)
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.Ombre
The AC_ namespace belongs to autoconf, so I suggest you use AX_DEFINE_SUBST.Repudiate
A
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.

Ankeny answered 4/1, 2012 at 19:10 Comment(2)
Looks promising, I'm going to try it. Reference to docs: gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.68/…Ombre
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.Ombre

© 2022 - 2024 — McMap. All rights reserved.