gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Makefile directory organisation

#36876 - Mucca - Wed Mar 02, 2005 7:34 pm

Im banging my head off the desk trying to get my makefile work as Id like. For various reasons, my source files, makefiles, and vstudio project files are all in different locations. Thats obviously no problem. The problem I have is I cant get the source files to compile to object files in yet another directory.

I call make as such:

Code:
make -C ../makefiles -f proj1.mak


Then in the make file I have a list of source files listed like this:

Code:
SRCDIR = ../src

CPPFILES = $(SRCDIR)/gfx/foo.cpp\
                   etc.



and the correct object files derived like this:

Code:
OFILES := $(notdir $(CPPFILES:.cpp=.o))


Obviously theres a problem here as the o files have no path, therefore I wanted to move into a build directory and have the o files compile to there.

The problem is theres seems to be then no link between src/gfx/foo.cpp and bld/foo.o.

Ive tried many things - eg compiling the files into source directory, then moving them to build directory, however this destroys the usefullness of make, as every time I compile it has to compile every source file again. Also tried to get work-directory switching going but was faced problems (I also need to create the build directory if it does not exist).

The makefile that comes with devkit advance was similar to what I need, except it works on source directories and not individual source files. Plus it does one or two things that I dont really get and that irks me.

I guess what I need is a solution for redirecting the object files compiled from source files.

Any help welcome :)

#36888 - Mucca - Thu Mar 03, 2005 12:20 am

Ok I got it to work.

What im doing now is moving into the desired build directory, and creating a list of the desired object files by using a substition on .s and .c files to .o files into an intermediate list, then selecting the notdir from each element in that list. Then I alter the VPATH to include the paths of the source files ie

Code:
.O_AT_SRC := $(.CPPFILES:.cpp=.o) $(.SFILES:.s=.o)
.OFILES       := $(notdir $(.O_AT_SRC))

VPATH := $(dir $(.O_AT_SRC))



Problem I have now is some strange multiple definition stuff at linking which wasnt there before. Im hoping when I wake up tomorrow the problem will have vanished. Oh the struggle goes on.

Apologies for posting a query then the answer, just got a little desperate I guess, before finding some more clarity.

#36894 - tepples - Thu Mar 03, 2005 3:25 am

Mucca wrote:
Apologies for posting a query then the answer, just got a little desperate I guess, before finding some more clarity.

There's nothing wrong with answering your own question, as it lets others with the same problem learn from what you did.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#36906 - wintermute - Thu Mar 03, 2005 8:51 am

you might also care to look at the makefiles provided with the examples in the devkitPro CVS.

http://cvs.sourceforge.net/viewcvs.py/*checkout*/devkitpro/examples/gba/PCXView/Makefile?rev=1.3

the makefile for libogc may be a little closer to what you're looking for

http://cvs.sourceforge.net/viewcvs.py/*checkout*/devkitpro/libogc/Makefile?rev=1.33

some useful reading material

http://make.paulandlesley.org/

#36910 - Mucca - Thu Mar 03, 2005 11:08 am

Thanks for the links, consider them bookmarked.

I have one last query on this topic - Im creating two archives from two different vstudio makefile projects using two different makefiles, which are nigh-on identical apart from the source files and stuff, and both now do what I want them to do, yet one crashes at the end with a make exception 1000 STATUS_ACCESS_VIOLATION, and the other doesnt.

What are the likely causes for this exception, and what are the recommended fixes? I fear it could be due to the fact that Im using an older version of make and gcc etc. Anyway if anyone's heard of something like this before, information would be appreciated.