Makefile setup
I'm still working on green-engine and I'm having trouble setting up the Makefiles. I have a main /src directory with a Makefile and a Makedefs (with some global defines, such as CFLAGS and the like). And I also have subfolders each with their own Makefile (I'm required to do this by my professor for the class). However, I cannot seem to get make to correctly handle all the dependencies in this setup.
Here is the Makefile in the /src directory:
Here is the Makedefs file in the /src directory:
And here is a sample Makefile from one of the subdirectories:
Any idea how to do this the correct way?
Regards,
JeroMiya
Here is the Makefile in the /src directory:
Code:
include Makedefs
UTIL = util
ENGINE = engine
MAIN = main
BACKEND = backend
OBJS = $(BACKEND)/glutApp.o \
$(MAIN)/main.o \
$(UTIL)/DrawStuff.o
UT_OBJS = $(UTIL)/utest_Error.o \
$(ENGINE)/utest_Variable.o \
$(ENGINE)/utest_VariableTableInstance.o \
$(MAIN)/testmain.o \
$(ENGINE)/utest_VariableTableTemplate.o \
$(ENGINE)/utest_KeyNameTable.o \
$(ENGINE)/utest_TemplateTable.o \
$(ENGINE)/utest_InstancePool.o
all : $(OUT)
$(UT_OUT) :
cd $(BACKEND) ; make $(UT_OUT)
cd $(ENGINE) ; make $(UT_OUT)
cd $(MAIN) ; make $(UT_OUT)
cd $(UTIL) ; make $(UT_OUT)
$(CC) -o $(UT_OUT) $(LDFLAGS) $(UT_OBJS) $(UT_LIBS)
$(OUT) :
cd $(BACKEND) ; make $(OUT)
cd $(ENGINE) ; make $(OUT)
cd $(MAIN) ; make $(OUT)
cd $(UTIL) ; make $(OUT)
$(CC) -o $(OUT) $(LDFLAGS) $(OBJS) $(LIBS)
clean:
rm -f $(UT_OUT) $(OUT) *.o
cd $(BACKEND) ; make clean
cd $(ENGINE) ; make clean
cd $(MAIN) ; make clean
cd $(UTIL) ; make clean
cleantemp:
rm -f $(UTIL)/*~ $(ENGINE)/*~ $(BACKEND)/*~ *~ $(MAIN)/*~
cleandepend:
rm -f $(BACKEND)/.depend
rm -f $(UTIL)/.depend
rm -f $(MAIN)/.depend
rm -f $(ENGINE)/.depend
depend:
cd $(BACKEND) ; make depend
cd $(MAIN) ; make depend
cd $(UTIL) ; make depend
cd $(ENGINE) ; make dependHere is the Makedefs file in the /src directory:
Code:
# the default compiler
CC = g++
# CFLAGS for engine and test runner
CFLAGS = -g -Wall -I.. -I/usr/local/include -DUSE_GLUT_HEADERS
# LDFLAGS for both unit test runner and engine
LDFLAGS = -g -L/usr/local/lib -L/usr/lib
# library files for OpenGL
GL_LIBS = -lglut
# Library flags for grun and test runner
LIBS = $(GL_LIBS)
UT_LIBS = -lcppunit -ldl
# the output file names
OUT = grun
UT_OUT = utest
# default rule
.cpp.o:
$(CC) -c -o $@ $(CFLAGS) $<And here is a sample Makefile from one of the subdirectories:
Code:
include ../Makedefs
SRCS =
OBJS = $(SRCS:.cpp=.o)
UT_SRCS = utest_InstancePool.cpp \
utest_KeyNameTable.cpp \
utest_TemplateTable.cpp \
utest_Variable.cpp \
utest_VariableTableInstance.cpp \
utest_VariableTableTemplate.cpp
UT_OBJS = $(UT_SRCS:.cpp=.o)
all : $(OUT) $(UT_OUT)
$(OUT) : $(OBJS) .depend
$(UT_OUT) : $(UT_OBJS) .depend
depend : .depend
.depend :
$(CC) -M $(CFLAGS) $(SRCS) $(UT_SRCS) > .depend
clean :
rm -f *.o
cleandepend :
rm -f .depend
-include .dependAny idea how to do this the correct way?
Regards,
JeroMiya
WARNING-NO ACTUAL MAKEFILE HELP IN THIS POST.
If you don't really need Makefiles, I'd switch to another make system i.e. rake, scons, CMake, or something else. Alternatively, you could use auto* tools.
Sorry I can't be more help; I dumped Makefiles a long time ago
If you don't really need Makefiles, I'd switch to another make system i.e. rake, scons, CMake, or something else. Alternatively, you could use auto* tools.
Sorry I can't be more help; I dumped Makefiles a long time ago
It's not magic, it's Ruby.
SCons FTW 
When I've written Makefiles in the past, I've found this to be incredibly helpful:
http://www.gnu.org/software/make/manual/make.html

When I've written Makefiles in the past, I've found this to be incredibly helpful:
http://www.gnu.org/software/make/manual/make.html
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Makefile help | caffeinated | 3 | 2,414 |
May 21, 2008 09:22 PM Last Post: OneSadCookie |
|
| Configuring a makefile for OpenGL / GLUT | zed_katarn | 4 | 3,940 |
Feb 15, 2006 03:45 PM Last Post: zed_katarn |
|

