0

I have two different directories with two different C++ source codes each of them execute different program. Directories have their own Makefiles each of them builds scripts with certain environment variables set.

Now, I want to put both directories' contents into a single directory as I want to mix both C++ source codes in order to develop a new C++ source code that utilizes both programs capabilities.

So far, I placed all files in a single directory, and I can successfully build each of the original source codes when I place the corresponding Makefile. Now, I want to have a single Makefile that allows me to build each of the original source codes (without replacing the Makefile), and hopefully this would allow me to build the new mixed C++ source file...

I tried a trivial solution and I placed the contents of both Makefiles into a single Makefile and this didn't work ...

I think it is useful to post my two Makefiles

Here is the first one

# A simple $(MAKE)file to cause make to go look in the top directory. A simple
# convenience.

all: lib 
    $(MAKE) -C .. examples

lib:
    $(MAKE) -C .. lib/libAria.so

%.so: ../lib/libAria.so %.cpp 
    $(MAKE) -C .. examples/$@

%: ../lib/libAria.so %.cpp 
    $(MAKE) -C .. examples/$@

%Static: ../lib/libAria.a %.cpp 
    $(MAKE) -C .. examples/$@

clean: 
    $(MAKE) -C .. cleanExamples

../lib/libAria.so: FORCE
    $(MAKE) -C .. dirs lib/libAria.so

../lib/libAria.a: FORCE 
    $(MAKE) -C .. dirs lib/libAria.a

FORCE:

.PHONY: all FORCE clean lib

And the second Makefile is

LDLIBS = -lm 
CXXFLAGS = -O3 -finline-functions -I. -I./qpoases/INCLUDE -I./qpoases/SRC
CFLAGS = -O3
CC     = g++

OBJECTS = \
    ./qpoases/SRC/QProblemB.o       \
    ./qpoases/SRC/Bounds.o          \
    ./qpoases/SRC/Constraints.o     \
    ./qpoases/SRC/SubjectTo.o       \
    ./qpoases/SRC/Indexlist.o       \
    ./qpoases/SRC/CyclingManager.o  \
    ./qpoases/SRC/Utils.o           \
    ./qpoases/SRC/MessageHandling.o \
    ./qpoases/solver.o              \
    integrator.o                    \
    condensing.o                    \
    gauss_newton_method.o 

.PHONY: all
all: test libacado_exported_rti.a

test: ${OBJECTS} test.o

./qpoases/solver.o    : ./qpoases/solver.hpp
integrator.o          : acado.h
condensing.o          : acado.h
gauss_newton_method.o : acado.h   ./qpoases/solver.hpp
test.o                : acado.h   ./qpoases/solver.hpp

libacado_exported_rti.a: ${OBJECTS}
    ar r $@ $?

${OBJECTS} : ./qpoases/solver.hpp

.PHONY : clean
clean :
    -rm -f *.o *.a ./qpoases/SRC/*.o ./qpoases/SRC/*.a test

I check all stackoverflow questions related to my question and the only closest situation to mine is a question titled (multiple makefiles in one directory);however, this is not exactly what I want to do...

Thanks a lot !

user2056096
  • 85
  • 1
  • 5
  • Make one makefile that runs make on the other two? Unless you specifically NEED to have a single makefile, for some reason, of course. – Mats Petersson Feb 09 '13 at 00:38

1 Answers1

0

Why would you want to merge your source directories? I assume they are seperated for a reason. Instead, I'd leave them be and create a new make file in the directory above them that calls each of the sub makes files below it - either via includes or via shelling directly to each makefile. I would not mix the code just to make it "easier" to get inheritance or whatever working.

BTW, here's a link for you:Stack Overflow shows you how

Community
  • 1
  • 1
Michael Dorgan
  • 12,453
  • 3
  • 31
  • 61
  • Well, this may allow me to build each of the original source codes, but will not allow me to build a mixed source code as I referred above. Mixing the codes into a single file is necessary for me as this compiled file will be transferred uploaded onto a robot platform. – user2056096 Feb 09 '13 at 00:49
  • Why not? Your linker should take care of this for you yes? #include's will catch your declares and your good. Or am I missing something else? – Michael Dorgan Feb 09 '13 at 00:59
  • Let me put it this way ... My new mixed code will be finally something like a big while loop. Inside this loop I will need to use operations from the two original source codes and each of these operations will need its own (environment variables set) ... So, if I follow your recommendation, would I be able to do something like that? – user2056096 Feb 09 '13 at 01:07
  • Michael Dorgan ... I am explaining what I really want to do in this question – user2056096 Feb 11 '13 at 20:47
  • http://stackoverflow.com/questions/14814950/how-to-compile-a-two-mixed-c-source-codes-from-different-packages-in-a-single – user2056096 Feb 11 '13 at 20:47