8

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?

Malice
  • 3,927
  • 1
  • 36
  • 52
John Doe
  • 2,746
  • 2
  • 35
  • 50
  • Hi! Could you explain why you'd like to do that? Your question sounds like you are trying to solve another problem the hard way. (For instance if you want to retrieve the expanded value of a variable such as `$datadir`, there are simpler ways to to it.) – adl Sep 20 '09 at 18:35
  • i want to create shell script templates independent of the linux system they are running on so i can create scripts for setting up a server and using the same script for a second instance which only needs modification of a few parameters the template engine im using just search/replace the script's variables to do this i need to initialize the engine with all the variables or they wont get replaced – John Doe Sep 21 '09 at 07:23
  • @adl can you explain what is the 'easy' way to deal with it. I am also struggling with this problem – Vicente Bolea May 13 '15 at 09:24

1 Answers1

8

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"
ndim
  • 35,870
  • 12
  • 47
  • 57