I searched for the answer to this question but couldn't find any good. Maybe they're old and something has changed, so I ask again.
I have a directory structure as:
my_project
src
bin
I want that, when I do make in the root dir, the binaries are put in ./bin, instead of cluttering ./src. But how?
EDIT: I am using C++. My Makefile.am has nothing special. Just the bin_PROGRAM and _SOURCES variables.
When I run make, the binaries generated are put into ./src. I simply want them in ./bin.
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.
Automake doesn't cope very well if you try to set up your directories in a different way than it expects. What you want would involve writing extra rules to move the binaries to ../bin
after compiling them, which is needlessly complicated.
If you don't want to clutter your source directory, try this:
cd my_project
mkdir build
cd build
../configure
make
That will put all the generated files (like makefiles, binaries, object files) in subdirectories of my_project/build
.
One way to tell Automake to create binaries in a certain directory is to add this directory right to the name in the "bin_PROGRAMS" variable.
Consider the following src/Makefile.am:
bin_PROGRAMS = foo
foo_SOURCES = ...
foo_CPPFLAGS = ...
foo_LDFLAGS = ...
It creates a binary "src/foo", but you can tell Automake to use the sources in src to create a binary "bin/foo":
bin_PROGRAMS = $(top_builddir)/bin/foo
__top_builddir__bin_foo_SOURCES = ...
__top_builddir__bin_foo_CPPFLAGS = ...
__top_builddir__bin_foo_LDFLAGS = ...
I tried it with some packages and even "make distcheck" swallows it. Can't be that much of a hack though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With