How to tell makefile my source is in a subdirectory?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
User avatar
Dormoxx
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Sat Feb 02, 2013 5:53 pm
Has liked: 0
Been liked: 0

How to tell makefile my source is in a subdirectory?

Post by Dormoxx » Tue Apr 23, 2013 8:19 pm

Hey all,

My main source file and makefile is in one folder. I then have a subdirectory named "Framework" where my Entity/Component framework source is. My questions is, as you can tell from the title, how do I tell the makefile that my source is in that "Framework" subdirectory?
#PlaySkullgirls
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5486
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 4 times
Been liked: 25 times
Contact:

Re: How to tell makefile my source is in a subdirectory?

Post by BlueCrab » Tue Apr 23, 2013 8:45 pm

Either specify your source files with the directory as a part of it (so specify them as "Framework/file.c" or whatnot instead of "file.c"), or put a Makefile in your Framework directory to build the source files and make the Makefile in the root directory build the subdirectory (something as simple as this should work):

Code: Select all

all:
	$(MAKE) -C Framework
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1808
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has liked: 0
Been liked: 0
Contact:

Re: How to tell makefile my source is in a subdirectory?

Post by GyroVorbis » Fri Apr 26, 2013 1:49 pm

I usually like to create a SRCDIRS variable at the top of my Makefiles with multiple subdirectories:

Code: Select all

SRCDIRS:=source components/source
Then later populate a list of all .c/.cpp files from these directories:

Code: Select all

CPP_SRC:=$(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.cpp))
C_SRC:= $(foreach dir,$(SRCDIRS),$(wildcard $(dir)/*.c))
Elysian Shadows - "Next-Gen" 2D/3D RPG coming to Sega Dreamcast, Steam, OUYA, and Smartphones
Image
http://www.elysianshadows.com
Ayla
Insane DCEmu
Insane DCEmu
Posts: 140
Joined: Thu Apr 03, 2008 7:01 am
Has liked: 0
Been liked: 1 time
Contact:

Re: How to tell makefile my source is in a subdirectory?

Post by Ayla » Fri Apr 26, 2013 8:14 pm

VPATH=Framework
Post Reply