86401

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

Question:

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

What I want is one Makefile in the root of the project and several Makefile's for the project itself and the test applications.

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

I'm basing 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'm not very good with these things. What I want is for it to take the .cpp's that are in the src folder, compile them to .o and put them in the intermediate folder and, finally, compile the .o's to the compiled exe and put it in the bin folder.

I've managed to get clean to work like this:

cd intermediate && rm -f *.o

However, I can't get it to retrieve the .cpp's, compile them and put them in the intermediate folder.

I've looked at several other Makefiles, but none do the things I want to do.

Any help is appreciated.

Answer1:

There's more than one way to do this, but the simplest is to run in TestOne, making Intermediate/foo.o out of Src/foo.cpp and test1 out of Intermediate/foo.o, like this:

# 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's 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 $@

Recommend

  • Dependent Combobox in a Datasheet in Access?
  • Java socket sends some data during connection to server 2 [duplicate]
  • Drupal 7 Internationalization / Multi language : redirect to default language if translation missing
  • How do I get different icons for the two versions of my GPS app generated via gradle build variants?
  • Importing SCORM compliant Lesson (imsmanifest.xml)
  • Creating new table in Laravel based on user input?
  • Disabled designer due to inheriting abstract class?
  • How is the best way to delete a tenant in WSO2 carbon?
  • Python Regular Expressions, find Email Domain in Address
  • Mysql delete older duplicates
  • main thread blocked on SCNetworkReachabilityGetFlags
  • Makefiles: Get .cpp from one directory and put the compiled .o in another directory
  • Advantage of find an object using Hibernate's @NaturalId
  • Excel 2007 Change colour of bars in a single series, based on another field
  • Using an R Markdown Document as a source for functions
  • Load environment variables into vue.js
  • How can I find the installation directory of a specific program?
  • Apache Flink Dynamically setting JVM_OPT env.java.opts
  • Dependency conflict in integrating with Cloudera Hbase 1.0.0
  • MySQL wildcard replace
  • How java deals with references to a generic type
  • Conditional render in tagfile depending on whether the attribute is specified or not
  • TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
  • undefined reference error due to use of static variables [duplicate]
  • Reading XML into Datatable gives incorrect DateTime when the time has Time Zone info
  • XNU incudes in Kext
  • Generic classes with Collection getter of other types
  • testing a POST using phpunit in laravel 4
  • Opaque reference instead of PImpl. Is it possible?
  • “mvn clean generate-source” could not resolve dependencies
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • Compiling dlib on OS X
  • how does System.Web.HttpRequest::PathInfo work?
  • bad substitution shell- trying to use variable as name of array
  • Installed module is empty