Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get fully expanded variables out of configure?

I created a configure.ac file like this:

AC_INIT()
set

the purpose of this is to print every available environment variable the configure script creates using set, so I do this:

user@host:~$ autoconf
user@host:~$ ./configure

which prints a bunch of variables like

build=
cache_file=/dev/null
IFS='   
'
LANG=C
LANGUAGE=C
datarootdir='${prefix}/share'
mandir='${datarootdir}/man'
no_create=

So far so good. The problem is:

  1. I want to expand the variables like ${prefix}/share - but piping everything to a file example.sh and executing it using bash doesn't work, because bash complains about modifying read-only variables like UID and expansion itself doesn't seem to work either.
  2. I tried using a makefile for this where expansion works, but it complains about newlines in strings, like in the above output the line IFS=' causes an error message Makefile:24: *** missing separator. Stop.

Does anyone have an idea how to get a fully expanded version of configure's output?

like image 213
John Doe Avatar asked Sep 17 '09 19:09

John Doe


1 Answers

The Autoconf manual (I cannot recall or find exactly where) recommends to "manually" do such a kind of variable substitution from within a Makefile.in (or .am if you happen to use Automake):

Makefile.in

[...]
foo.sh: foo.sh.in
        $(SED) \
            -e 's|[@]prefix@|$(prefix)|g' \
            -e 's|[@]exec_prefix@|$(exec_prefix)|g' \
            -e 's|[@]bindir@|$(bindir)|g' \
            -e 's|[@]datarootdir@|$(datarootdir)|g' \
            < "$<" > "$@"
[...]

foo.sh.in

#!/bin/sh
datarootdir=@datarootdir@
du "$datarootdir"
like image 68
ndim Avatar answered Sep 18 '22 17:09

ndim