[Geany-Users] Makefile redirction for Make Command

Chow Loong Jin hyperair at xxxxx
Wed Jan 22 08:53:40 UTC 2014


On Wed, Jan 22, 2014 at 08:24:36AM +0000, Tim Black wrote:
> Hello
> 
> In the Manual there is talk of Makefile redirection that is used for "out of tree" compilation.
> 
> I am using Geany and have recently migrated a project that uses an Automake
> VPATH build(s) and now my apps will not build without the use of this Makefile
> redirection.

Out-of-tree compilation with autotools is usually fairly straightforward -- just
cd into your build tree, and call configure from there, e.g.

To build:
$ mkdir -p build-tree
$ cd build-tree
$ ../configure
$ make

And to clean:
$ cd .. && rm -rf build-tree

With an autotools project, the autoconf/automake files (configure.ac,
Makefile.am, Makefile.in) are in the source tree, whereas your Makefile, and a
couple of other auxiliary files, are in your build tree.

> Has anyone got an example of this Makefile redirection. Basically I need to
> fire off the makefile that now exists in my build tree. I have two versions of
> build tree that have different targets and use different versions of gcc so it
> would also be good to pass an argument that would select one of the targets.

TL;DR:
Simply put, don't use VPATH directly. In your Makefile.am, use $(srcdir) to
refer to the directory, and $(builddir) to refer to the build directory.
$(top_srcdir) and $(top_builddir) refer to the root of your source tree and
build tree respectively.

In an in-tree build, $(srcdir) == $(builddir) and
$(top_srcdir) == $(top_builddir).

In an out-of-tree build, $(srcdir) != $(builddir) and
$(top_srcdir) != $(top_builddir). Your binaries go into $(builddir), while your
sources remain in $(srcdir).

During `make distcheck`, one of the tests done is to make the entire $(srcdir)
read-only, and to do the entire build in a separate directory using this
feature. So, any files generated by your build (from ./configure onwards) should
not modify anything in your source tree.


Explanation on VPATH:
VPATH is a Make feature that affects the lookup of the dependencies, but not the
target. When using VPATH, your target is relative to your current directory,
whereas your dependencies are looked up in ., and failing which, in VPATH.
However, make does not know how to mangle your rules, so...

This is correct:
| foobar.o: foobar.c
| 	$(CC) -c $< -o $@

If VPATH=../src, then this automatically expands to:
$ cc -c ../src/foobar.c -o foobar

This is wrong:
| foobar.o: foobar.c
| 	$(CC) -c foobar.c -o foobar

Because this expands (regardless of VPATH) to:
$ cc -c foobar.c -o foobar

-- 
Kind regards,
Loong Jin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.geany.org/pipermail/users/attachments/20140122/0e6cee2f/attachment.pgp>


More information about the Users mailing list