I usually use a typical steps to generate the makefile, and firstly I use the "build.sh init" to generate the configure file, and then I use "configure" to generate the makefile with makefile.am file. Now I want to estiminate the "../../" in some include file like include "../../dirA/dirB/C.h", just write it as include "dirA/dirB/C.h", so the settings of configure.ac or makefile.am must be modified. Who can help to solve this?
The first thing to note, is that the configure system has two top_dir's. A top directory for where the source code resides, and a top directory for where the code gets built. Often these two directories are the same. But there are situations where the source code resides say on a read-only file system, so you need to build the software somewhere else. Below I am going to use the the top build directory, again noting that this may be the same as the top source directory.
autoconf already defines a couple of variables for the top build directory. One of them is called "abs_top_builddir".
Let's say the include file you want to use "abs_top_builddir" is called
x.h. You would create a file called
x.h.in The way you refer to this variable in that file is to surround it with '@'. So you might have:
The other thing you need to do is tell the configure script to create header file
x.h.in. You do this by adding
to the end of configure.ac. You only need one
AC_OUTPUT so if that line is already there, then you don't need to add it again. Now run
autoconf to create the configure script and when you run
configure you should see
configure: creating x.h
x.h and make sure the include line is what you expect.
And having written all of the above, I should also point out this this is what is not what is usually done. Instead, on in
CFLAGS or some similarly named variable, you just include the directory. For example a Makefile.am might have:
AM_CPPFLAGS = -I$(top_srcdir)
Here I am switching to srcdir because I don't have to create the header like I did before. And you probably won't have to add additional lines to configure.ac because those lines will probably already be there.