Makefiles, building source from another folder with obj files > subfolder of current?
Hi all,
I've been stuck on this one for a while now so really hoping someone can help! I have an array of folders of C/C++ source that are common code to several projects, and some more folders (by the side of the others) that contain projects themselves. When I build a project, I want to be able to include a sources.mk from an external folder, and have the objects for those included sources go into a subfolder of the project directory so as not to clutter the common folder up with project-specific objects (each project can have different flags, optimisations etc.) As an example, here's a folder structure: source/common.mk source/common/stuff/aaa.c source/common/stuff/sources.mk source/projects/thing/main.c source/projects/thing/Makefile The Makefile in projects/thing will include common/stuff/sources.mk to get a list of the sources in that folder (appended to the list of sources already in Makefile). Sources in sources.mk are prepended with the relative path between Makefile and sources.mk as follows: Code:
THIS_TOP := $(dir $(lastword $(MAKEFILE_LIST))) cd projects/thing; make creates: projects/thing/objdir/main.o projects/thing/objdir/common/stuff/aaa.o I make a list of object files and strip the ../ out of the relative path as follows: Code:
__OBJECTS=$(SOURCES_C:.c=.o) $(SOURCES_CPP:.cpp=.o) Code:
.SECOND_EXPANSION: Any help greatly appreciated! Thanks, -- Olly |
I use something similar to the following when I develop C++ projects:
Code:
OBJDIR = .srcobjs Code:
$(OBJDIR)/%.o: %.cpp |
All times are GMT -5. The time now is 10:16 PM. |