Caching pkgdatadir in configure

View: New views
7 Messages — Rating Filter:   Alert me  

Caching pkgdatadir in configure

by Alberto Luaces :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I wrote a program that uses data files at runtime. I store them in
$pkgdatadir, and it works fine.

Sometimes I want to execute the program without installing it. To do
this, I change the value of the $pkgdatadir variable at make time:

make pkgdatadir=...

I wonder if I could modify and cache $pkgdatadir variable when running
configure, to avoid having to specify the value of pkgdatadir every time
I am recompiling.

I tried to use AC_SUBST(pkgdatadir), but this makes that the $pkgdatadir
value is void if I don't define it when configuring because it overrides
the Automake definition $datadir/$packagename.

Is it possible to do what I want?

1. If pkgdatadir is not specified at configure time, follow the FHS or
GNU guidelines.
2. If pkgdatadir is specified, store its value in the configure cache.

Thank you,

Alberto


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: Caching pkgdatadir in configure

by Mike Frysinger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 14 October 2009 07:37:33 Alberto Luaces wrote:

> I wrote a program that uses data files at runtime. I store them in
> $pkgdatadir, and it works fine.
>
> Sometimes I want to execute the program without installing it. To do
> this, I change the value of the $pkgdatadir variable at make time:
>
> make pkgdatadir=...
>
> I wonder if I could modify and cache $pkgdatadir variable when running
> configure, to avoid having to specify the value of pkgdatadir every time
> I am recompiling.
>
> I tried to use AC_SUBST(pkgdatadir), but this makes that the $pkgdatadir
> value is void if I don't define it when configuring because it overrides
> the Automake definition $datadir/$packagename.
>
> Is it possible to do what I want?
>
> 1. If pkgdatadir is not specified at configure time, follow the FHS or
> GNU guidelines.
> 2. If pkgdatadir is specified, store its value in the configure cache.
a lot of people muck around with path vars in configure when they shouldnt.  
their code tends to be pretty fragile as they have to check multiple vars and
expand them manually.

what i do is append the CPPFLAGS in the configure.ac like so:
CPPFLAGS=$CPPFLAGS' -DMY_DATA_PATH="\"$(pkgdatadir)\""'
-mike


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (853 bytes) Download Attachment

Re: Caching pkgdatadir in configure

by Alberto Luaces :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Frysinger writes:

> On Wednesday 14 October 2009 07:37:33 Alberto Luaces wrote:
>> Is it possible to do what I want?
>>
>> 1. If pkgdatadir is not specified at configure time, follow the FHS or
>> GNU guidelines.
>> 2. If pkgdatadir is specified, store its value in the configure cache.
>
> a lot of people muck around with path vars in configure when they shouldnt.  
> their code tends to be pretty fragile as they have to check multiple vars and
> expand them manually.
>
> what i do is append the CPPFLAGS in the configure.ac like so:
> CPPFLAGS=$CPPFLAGS' -DMY_DATA_PATH="\"$(pkgdatadir)\""'

This is a great idea, thank you. I also think that the simpler the configure.ac,
the better.

Regards,

Alberto


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: Caching pkgdatadir in configure

by Alberto Luaces :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Alberto Luaces writes:

> Mike Frysinger writes:
>
>> On Wednesday 14 October 2009 07:37:33 Alberto Luaces wrote:
>>> Is it possible to do what I want?
>>>
>>> 1. If pkgdatadir is not specified at configure time, follow the FHS or
>>> GNU guidelines.
>>> 2. If pkgdatadir is specified, store its value in the configure cache.
>>
>> a lot of people muck around with path vars in configure when they shouldnt.  
>> their code tends to be pretty fragile as they have to check multiple vars and
>> expand them manually.
>>
>> what i do is append the CPPFLAGS in the configure.ac like so:
>> CPPFLAGS=$CPPFLAGS' -DMY_DATA_PATH="\"$(pkgdatadir)\""'
>
> This is a great idea, thank you. I also think that the simpler the configure.ac,
> the better.

Ooops, I read too fast. I thought that you were recommending me to
define MY_DATA_PATH in the configure call:

configure CPPFLAGS='-DMY_DATA_PATH="\"$(pkgdatadir)\""'

Luckily it also works, since MY_DATA_PATH is defined twice but the
compiler chooses the last definition, which belongs to the CPPFLAGS
value. It's a great thing for the Autotools that the user configuration
prevails over the developer's :)

Regards,

Alberto


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: Caching pkgdatadir in configure

by Mike Frysinger :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 14 October 2009 10:46:17 Alberto Luaces wrote:

> Alberto Luaces writes:
> > Mike Frysinger writes:
> >> On Wednesday 14 October 2009 07:37:33 Alberto Luaces wrote:
> >>> Is it possible to do what I want?
> >>>
> >>> 1. If pkgdatadir is not specified at configure time, follow the FHS or
> >>> GNU guidelines.
> >>> 2. If pkgdatadir is specified, store its value in the configure cache.
> >>
> >> a lot of people muck around with path vars in configure when they
> >> shouldnt. their code tends to be pretty fragile as they have to check
> >> multiple vars and expand them manually.
> >>
> >> what i do is append the CPPFLAGS in the configure.ac like so:
> >> CPPFLAGS=$CPPFLAGS' -DMY_DATA_PATH="\"$(pkgdatadir)\""'
> >
> > This is a great idea, thank you. I also think that the simpler the
> > configure.ac, the better.
>
> Ooops, I read too fast. I thought that you were recommending me to
> define MY_DATA_PATH in the configure call:
>
> configure CPPFLAGS='-DMY_DATA_PATH="\"$(pkgdatadir)\""'
>
> Luckily it also works, since MY_DATA_PATH is defined twice but the
> compiler chooses the last definition, which belongs to the CPPFLAGS
> value. It's a great thing for the Autotools that the user configuration
> prevails over the developer's :)
if you use the line i mentioned in the configure.ac, then you can change the
default path via the normal --foodir= configure options, or doing:
make clean
make pkgdatadir=/foo

since the pkgdatadir is expanded at the make level, you dont need to re-run
configure.

i'm not entirely sure what you're trying to do, but i guess as long as you
found something that makes you happy it doesnt matter too much
-mike


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

signature.asc (853 bytes) Download Attachment

Re: Caching pkgdatadir in configure

by Ralf Wildenhues :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

* Alberto Luaces wrote on Wed, Oct 14, 2009 at 01:37:33PM CEST:
> I wrote a program that uses data files at runtime. I store them in
> $pkgdatadir, and it works fine.
>
> Sometimes I want to execute the program without installing it.

I prefer to do this without any recompiling or reconfiguring of the
code.  For example, by having a dedicated environment variable or
command line argument that overrides the pkgdatadir value that has been
compiled into the program.  Rationale: I'd like to test, as much as
possible, the exact same code that is later being installed.

The Autoconf package itself does it this way, too: the tools wrappers
in the tests/ directory (generated from tests/wrappers.as) set
autom4te_perllibdir and a few other variables, and use -B aka.
--prepend-include.

Hope that helps.

Cheers,
Ralf


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf

Re: Caching pkgdatadir in configure

by Alberto Luaces :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Frysinger writes:

[...]

> if you use the line i mentioned in the configure.ac, then you can change the
> default path via the normal --foodir= configure options, or doing:
> make clean
> make pkgdatadir=/foo
>
> since the pkgdatadir is expanded at the make level, you dont need to re-run
> configure.
>
> i'm not entirely sure what you're trying to do, but i guess as long as you
> found something that makes you happy it doesnt matter too much
> -mike

Hello Mike,

I was trying to avoid having to type the value of pkgdatadir when
calling make, because in a rebuild some object files could have been
compiled with different value if I mistakenly forget to set it
correctly.

I like Ralf's idea about the enviroment variable. It stops me from
messing with the build system and makes possible to do a final `make
install' without having to rebuild.

Regards,

Alberto


_______________________________________________
Autoconf mailing list
Autoconf@...
http://lists.gnu.org/mailman/listinfo/autoconf