Discussion:
How to use PREFIX created by autoconf in source file
Adam Jiang
2014-02-09 12:17:19 UTC
Permalink
Autoconf could help to generate configure script which accepts an option
called --prefix in general. In this way, users could specific a path where
programs/data installed.

In my program, I'd like to refer the location where data files are
installed. In plain Makefile, it could be done like

gcc -DPREFIX "/usr/share"

and in the source file, data path is generated in

#define DATAPATH PREFIX "/data"

with autoconf, how could I use the path specified by --prefix in source
code? Is there a pre-defined MACRO for this?
Ralf Corsepius
2014-02-09 17:17:12 UTC
Permalink
Post by Adam Jiang
Autoconf could help to generate configure script which accepts an option
called --prefix in general. In this way, users could specific a path where
programs/data installed.
In my program, I'd like to refer the location where data files are
installed. In plain Makefile, it could be done like
gcc -DPREFIX "/usr/share"
and in the source file, data path is generated in
#define DATAPATH PREFIX "/data"
with autoconf, how could I use the path specified by --prefix in source
code? Is there a pre-defined MACRO for this?
Autoconf has no business in handling Makefiles.

I.e. the answer to your question depends upon your way to propagate
autoconf variables to your Makefile-system.

Ralf
Peter Johansson
2014-02-09 23:14:04 UTC
Permalink
Post by Adam Jiang
Autoconf could help to generate configure script which accepts an option
called --prefix in general. In this way, users could specific a path where
programs/data installed.
In my program, I'd like to refer the location where data files are
installed. In plain Makefile, it could be done like
gcc -DPREFIX "/usr/share"
and in the source file, data path is generated in
#define DATAPATH PREFIX "/data"
with autoconf, how could I use the path specified by --prefix in source
code? Is there a pre-defined MACRO for this?
Have a look in the manual

http://www.gnu.org/software/autoconf/manual/autoconf.html#Defining-Directories
--
Peter Johansson
Eric Blake
2014-02-10 13:54:42 UTC
Permalink
Post by Adam Jiang
Autoconf could help to generate configure script which accepts an option
called --prefix in general. In this way, users could specific a path where
programs/data installed.
ALL configure scripts generated by autoconf accept --prefix.

It sounds like what you want to do is turn ${prefix} (substituted at
autoconf time) into PREFIX (a C preprocessor macro at compilation time),
using Makefile as the place to do the expansion so as to cover nested
definitions (for example, ${exec_prefix)\} defaults to being defined in
terms of ${prefix}).

That is easy to do; in fact, the gnulib configmake module does just that.

http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=modules/configmake
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Adam Jiang
2014-02-10 16:05:52 UTC
Permalink
Actually, the problem could be resolved by

AM_CFLAGS = -DPKGDATA=$(pkgdata)

just like the manual described. Paths of all files in $(pkgdata) could be
referred with PKGDATA + basename.

Thank you.
Post by Eric Blake
Post by Adam Jiang
Autoconf could help to generate configure script which accepts an option
called --prefix in general. In this way, users could specific a path
where
Post by Adam Jiang
programs/data installed.
ALL configure scripts generated by autoconf accept --prefix.
It sounds like what you want to do is turn ${prefix} (substituted at
autoconf time) into PREFIX (a C preprocessor macro at compilation time),
using Makefile as the place to do the expansion so as to cover nested
definitions (for example, ${exec_prefix)\} defaults to being defined in
terms of ${prefix}).
That is easy to do; in fact, the gnulib configmake module does just that.
http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=modules/configmake
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Ralf Corsepius
2014-02-10 16:11:11 UTC
Permalink
Post by Adam Jiang
Actually, the problem could be resolved by
AM_CFLAGS = -DPKGDATA=$(pkgdata)
just like the manual described. Paths of all files in $(pkgdata) could be
referred with PKGDATA + basename.
AM_CFLAGS => automake

You are off-topic for this list

Loading...