Makefiles: get .cpp from one directory and put the compiled .o in another directory

I am working on a cross-platform 2D engine for mobile devices (Windows Mobile 6 and Android). My version of Windows is pretty much ready, but I still need to make sure that the same features are available on Android.

What I want is one Makefileat the root of the project and several Makefilefor the project and test applications.

Makefile
---Engine
------Makefile
------src
------bin
------intermediate
---Tests
------TestOne
---------Makefile
---------src
---------bin
---------intermediate
------TestTwo
---------Makefile
---------src
---------bin
---------intermediate

I base my attempts on the following Makefile:

 include ../makeinclude

 PROGS = test1
 SOURCES = $(wildcard *.cpp)

 # first compile main.o and start.o, then compile the rest
 OBJECTS = main.o start.o $(SOURCES:.cpp=.o)

 all: $(PROGS)

 clean:
    rm -f *.o src

 test1: $(OBJECTS)
    $(LD) --entry=_start --dynamic-linker system/bin/linker -nostdlib -rpath system/lib -rpath $(LIBS) -L $(LIBS) -lm -lc -lui -lGLESv1_CM $^ -o ../$@ 
    acpy ../$(PROGS)
 .cpp.o:
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $*.cpp $(CLIBS)

However, I am not very good at these things. I want him to take the .cpps that are in the folder src, compile them .o and put them in the folder intermediateand finally compile .o in the compiled exe and put it in the folder bin.

:

cd intermediate && rm -f *.o

, .cpp, intermediate.

Makefiles, , .

.

+3
1

, TestOne, Intermediate/foo.o Src/foo.cpp test1 Intermediate/foo.o, :

# This makefile resides in TestOne, and should be run from there.

include makeinclude # Adjust the path to makeinclude, if need be.

PROG = bin/test1 
SOURCES = $(wildcard Src/*.cpp) 

# Since main.cpp and start.cpp should be in Src/ with the rest of
# the source code, there no need to single them out
OBJECTS = $(patsubst Src/%.cpp,Intermediate/%.o,$(SOURCES))

all: $(PROG)

clean: 
    rm -f Intermediate/*.o bin/*

$(PROG): $(OBJECTS) 
    $(LD) $(BLAH_BLAH_BLAH) $^ -o ../$@  

$(OBJECTS): Intermediate/%.o : Src/%.cpp
    $(CC) $(CFLAGS) -I $(GLES_INCLUDES) -c $&lt $(CLIBS) -o $@
+8

Source: https://habr.com/ru/post/1722958/


All Articles