3
votes

I am building a small library and I am using autotools. The code is in c++, and it outputs some html code. There is a lot of stylesheets and javascript code associated with the html code. Since the latter is fixed, the code copies these files to the folder where the html output (dynamic) is written. The output path is an argument to a function.

The problem is that, to copy the javascript and stylesheets, I need to know the full path of the source directory. Some of the code is based on templates and the code is directly inside the header file. So defining a variable (compiler flags) in Makefile wont work for me.

I was planning to define a variable in config.h so that, if config.h is included in the original header files, I will get the path.

I tried by using

AC_DEFINE_UNQUOTED([DATA_PATH], ["$srcdir"], "data path"

after autoconf is run, the config.h file defines DATA_PATH as "." . But I require full installation path.

What is the correct/best way to do this

1

1 Answers

3
votes

You are looking for the absolute path of srcdir. It can be easily done by using:

 readlink -f $srcdir

Recall that the configure.ac file is actually a shell script with m4 macros. So virtually every standard command will be accessible: Here is a possible way to deal with your problem:

srcdir2=`readlink -f $srcdir`
AC_DEFINE_UNQUOTED([DATA_PATH], ["$srcdir2"], [data path])