The GNU Build System does not use obj/
directories, so the autotools are not designed to support that.
However I can think of two ways to work around this.
As an installer, you can build any package out of its source directory by typing
mkdir builddir
cd builddir
../path-to-sourcedir/configure
make
Then any output file will be created in the builddir/
directory. This compilation scheme makes it possible to compile source code out stored in a readonly directory (this made more sense back in the years where the FSF was distributing CDs with uncompressed source code), or to compile the same source with differents settings (or even for different architectures).
As a packager, the only way you could force your package to build everything in obj/
is to put your Makefile.am
in obj/
, and declare all your build rules there. This would mean a obj/Makefile.am
looking like:
bin_PROGRAMS = foo bar
foo_SOURCES = ../src/foo/main.c ../src/foo/help.c ../src/foo/list.c
bar_SOURCES = ../src/bar/bar.c
etc. I remember that 10 years ago, POSE, the Palm OS Emulator, was using a setup like the above. I don't recommend it as it's not really maintainable. It's really better to stick with the philosophy of the tools, and use a build systems that work like the other GNU packages.
For an introduction to the GNU Build System, I recommend reading the introduction of the Automake manual:
http://www.gnu.org/software/automake/manual/automake.html#GNU-Build-System
Especially the Use-Cases section.
If you don't care about these use cases, I think your best course is NOT to use Automake, and build your own Makefiles. Otherwise you will keep trying to force Automake doing something it is not designed for, and you'll quickly hate it.
EDIT 2013-08-26: Note that an Automake project using a subdirectory named using obj/
is not portable to BSD make.
I would use a script to generate a Makefile
fragment that lists all the files:
echo 'subdir_files =' > subfiles.mk
find subdir -type f -print | sed 's/^/ /;$q;s/$/ \\/' >> subfiles.mk
and then include this subfiles.mk
from your main Makefile.am
:
include $(srcdir)/subfiles.mk
nobase_dist_pkgdata_DATA = $(subdir_files)
A second option is to EXTRA_DIST = subdir
, and then to write custom install-data-local
and uninstall-local
rules.
The problem here is that EXTRA_DIST = subdir
will distributes all files in subdir/
, including backup files, configuration files (e.g. from your VCS), and other things you would not want to distribute.
Using a script as above let you filter the files you really want to distribute.
Best Answer
You've got the wrong idea here.
Your build tree is wherever you run
configure
. That's how autoconf is designed to work. Users of your package (who do not want to clutter their source tree) will expect it to work this way.This approach is a more general solution with a lot more flexibility than the organization you're imagining. For instance, it's not terribly unusual to want to maintain sources and build files on separate filesystems.