hookenz
hookenz

Reputation: 38889

Using autotools to generate application specific *.conf files

I'm new to using autotools so forgive me if this sounds a little bit basic but googling didn't show up much.

How would I go about generating a custom conf file with autotools.

Seeing as configure based on m4 contains the necessary macros and generates the required files.

Some hunting and reading seems to suggest I could do something like add:

AC_CONFIG_FILES([appname.conf])

To my configure.am.

Then create an appname.conf.in file.

What I'm not clear on is how I populate custom macros i.e.

LOG_DIR=@log_dir@
CACHE_DIR=@cache_dir@

to

So when configure gets run it produces

LOG_DIR=/var/log
CACHE_DIR=/mycachedir

etc...

Upvotes: 3

Views: 118

Answers (1)

The information you seem to be missing is AC_SUBST, which sets up the substitutions.

E.g. in configure.ac:

TEST_SUB="hello world"
AC_SUBST(TEST_SUB)

AC_CONFIG_FILES(test.conf)

In test.conf.in:

TEST_VAR=@TEST_SUB@

Gives test.conf:

TEST_VAR=hello world

(If you're curious have a look in the Makefile.in files that automake generates to see how it uses this mechanism. The AM_CONDITIONALs get turned into two things, one for each case, one of which gets made into a comment by a substitution)

Upvotes: 3

Related Questions