autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: including autoconf paths in source


From: Jan Engelhardt
Subject: Re: including autoconf paths in source
Date: Thu, 11 Dec 2008 22:08:58 +0100 (CET)
User-agent: Alpine 1.10 (LNX 962 2008-03-14)

On Thursday 2008-12-11 21:38, Monty Taylor wrote:

>Hey all,
>
>I'm wondering if there is a best practice for getting paths such as
>locaeldir or datadir into source code. As it stands now in the Makefile
>I've got:
>
>prefix= /usr/local
>datarootdir= ${prefix}/share
>localedir = ${datarootdir}/locale
>
>To get localedir into a source file, I've got a section in Makefile.am like:
>
>DEFS = -DLOCALEDIR="\"$(localedir)\"" @DEFS@

This is the preferred solution indeed. Not that I see a need for @DEFS@
though:

---8<--- (configure.ac)
...
AC_ARG_WITH([gamedatadir], AS_HELP_STRING([--with-gamedatadir=PATH],
        [Path to textures and sounds [[DATADIR/games]]]),
        [gamedatadir="$withval"], 
[gamedatadir='${gamesdir}/${PACKAGE_NAME}-data'])
AC_SUBST([gamedatadir])
...
--->8---

---8<--- (Makefile.am)
AM_CFLAGS           = ${regular_CFLAGS} -DDATADIR='"$(gamedatadir)"'
games_PROGRAMS      = asteroids3D
---8>---

>(except that I've actually got several - localedir is just a convenient
>example) It makes things a little ugly.
>
>If I just do AC_DEFINE(LOCALEDIR,"${localedir}") I only get
>#define LOCALEDIR "${datarootdir}/locale"
>
>is there a cantrip I'm missing, or a decent way to deal with this?

See automake.info: "Installation Directory Variables":

   A corollary is that you should not use these variables except in
makefiles.  For instance, instead of trying to evaluate `datadir' in
`configure' and hard-coding it in makefiles using e.g.,
`AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])', you
should add `-DDATADIR='$(datadir)'' to your makefile's definition of
`CPPFLAGS' (`AM_CPPFLAGS' if you are also using Automake).

Reason being that people may want to override datadir on the
make command line for specific .o files (or thereabouts as I read)

        make foo.o datadir=/somewhere/else

With hardcoding it into an AC this is unlikely to work.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]