# Automake to compile objects in a specific directory

Hi,

How could I get automake to compile object in an object directory, and not in the source folder?

Here is what I have so far:

|-- configure.ac
|-- include
|   -- Makefile.am
|-- Makefile.am
|-- obj
|   --
-- src
|-- Makefile.am
|-- main.cc
|-- snd.cc
|-- Makefile.am
-- USBdiscovery.cc


I've read things about "AUTOMAKE_OPTIONS = subdir-objects" (to include in a Makefile.am?) but I don't know how to tell that I want my .o files in obj/.

edit retag close merge delete

Sort by » oldest newest most voted

What I found so far is the Parallel Build Trees (a.k.a. VPATH Builds).

We just have to run our default configure script in a subdirectory, that will create a new tree. We would then have the sources tree and the build tree.

If configure is executed in its own directory, the source and build trees are combined: derived files are constructed in the same directories as their sources.

I new where to create object files in my own makefile, now it is more convenient to create the build tree.

My tree is like above, with the empied obj dir (we should not create it obj as BSD don't like that)

cd obj
../configure
make


That's it, I now have a clean source tree and a build tree completly out of my repo.

.
|-- configure.ac
|-- include
|   -- Makefile.am
|-- Makefile.am
|-- obj
|   -- config.log
|   |-- config.status
|   |-- include
|   |   -- Makefile
|   |-- Makefile
|   -- src
|       |-- main.o
|       |-- snd.o
|       -- Makefile
-- src
|-- Makefile.am
|-- main.cc
|-- snd.cc
|-- Makefile.am
-- USBdiscovery.cc
`
more

Not sure if this is what you want, but probably if yes you can use pathsubst() function to store your object files (.o files) in obj. You can refer below link for description -

Storing *.o in obj

more