0

Having scripts in autotools project that are using some paths I want to forward prefix that is entered by user during ./configure to those scripts. Lets say I have a bash script that echo file in directory that is set during ./configure. What is the best way to do it? I am thinking about having myscript.sh.hpp that will be used by preprocessor and passing -DMYPATH to preprocessor to substitute it into myscript.sh.hpp to generate myscript.sh with appropriate path. Is that right direction?

Artem
  • 1
  • I don't understand your question, can you give a more specific example? – ptomato Jul 09 '12 at 08:13
  • I have bash script like #!/bin/bash ls /usr/sbin I don't want to hardcode the path, I want It to be /usr/sbin by default, but available to be overwritten when installing. I.e. ./configure --prefix=/usr/local/sbin && make will generate such file #!/bin/bash ls /usr/local/sbin – Artem Jul 09 '12 at 16:42
  • It's difficult know what's being asked here - is it a shell script substitution or 'hpp' source? (ha ha) - but it sounds like you need to use [AC_SUBST](http://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.69/html_node/Setting-Output-Variables.html#Setting-Output-Variables) – Brett Hale Jul 09 '12 at 17:25
  • You do not want to use prefix to determine the path of bash. prefix is the location your own software is being installed to, and it is unlikely that your package is installing bash. – William Pursell Jul 17 '12 at 12:34

1 Answers1

1

prefix is the location to which your software is installed, and is not really the correct place to look for things like bash. It would be better to provide the user the ability to specify a bash interpreter or to probe PATH to find bash and use that value. However, it is often desirable to reference prefix in a script. The easiest way is to let config.status expand it. In configure.ac:

AC_CONFIG_FILES([foo])

and in foo.in

@prefix@
William Pursell
  • 204,365
  • 48
  • 270
  • 300