0

In Makefile.am, I have:

lib_LTLIBRARIES = libmyproject.la
libmyproject_la_LDFLAGS = -shared
libmyproject_la_SOURCES = \
    sample1.cpp \
    sample1.h \
    sample2.cpp \
    sample2.h
AM_CPPFLAGS = \
    -Wall \
    -Wextra
INCLUDES = \
    $(OPENSSL_CFLAGS)
LIBS = \
    -L/usr/lib/openssl-1.0.0/ \
    -lssl
EXTRA_DIST = xxxxxx

This works fine and I'm getting .lo and .o files in the same path.

What can I do to have all .lo and .o files moved to a separate subfolder after compilation?

набиячлэвэли
  • 4,099
  • 4
  • 29
  • 40
Srujan
  • 91
  • 2
  • 11
  • I never used automake before, but I have acompleshed this in [my post](http://stackoverflow.com/questions/31974007/geting-source-code-structure-in-makefile), but with regular makefiles. I do not know if there is some difference with automake. –  Oct 08 '15 at 17:14

2 Answers2

0

For one thing you can mix in ordinary make rules into your Makefile.am.

So adding the following to Makefile.am should do what you want:

.PHONY: copy_obj
# when building 'all', we *also* want the 'copy_obj' target
all: copy_obj
# but the 'copy_obj' target can only be executed once 'libmyproject.la' is done
copy_obj: libmyproject.la
      mkdir -p objdir
      cp *.lo *.o objdir

or even:

.PHONY: copy_obj

all: copy_obj
copy_obj: $(libmyproject_la_OBJECT)
      mkdir -p objdir
      cp $^ objdir

But the real question is: why would you actually want to do that? What do you try to accomplish?

umläute
  • 28,885
  • 9
  • 68
  • 122
0

You could try a VPATH build. Having some insight as to why the .lo and .o files need to be elsewhere would help answer your question.

A somewhat different variation on this is the DESTDIR install where the libs, etc. get copied and the .o files don't.

ldav1s
  • 15,885
  • 2
  • 53
  • 56