Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automake generating binaries to bin/ instead of in src/

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.

like image 944
Vitor Baptista Avatar asked Jan 26 '10 14:01

Vitor Baptista


3 Answers

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.

like image 69
Braden Avatar answered Nov 05 '22 09:11

Braden


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.

like image 42
ptomato Avatar answered Nov 05 '22 10:11

ptomato


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...

like image 18
Niels Lohmann Avatar answered Nov 05 '22 09:11

Niels Lohmann