I have made an app which uses my own Templates ( see variable
MYTEMPLATES=MYTemplateHDRS/*.hpp )
It also needs some files from root dir of the app and then all the rest from the bagdir ( application directory ) itself, which is a subdir of the root dir of the app ( named bag ).
My problem is that make doesn't leave object files subdir. It puts them to application root directory instead.
This line does compilation from .cpp files to .o files
Code:
.cpp.o: $(MYTEMPLATES) $(DRAWHDR) $(STEERHDR)
@echo mycompile $(CXX) -c $< $(CXXFLAGS)
@echo mytargetname $@ and target dir $(@D)
$(CXX) -c $< $(CXXFLAGS)
Those echo lines show that target file is bagdir/bagobject.o and bagdir/bagtest.o but still those targets are put in root directory.
If I just type g++ -c -o ./bagdir/bagtest.o ./bagdir/bagtest.cpp
bagtest.o is place in bagdir where it should be. What I am missing ?
Here is makefile
Code:
SHELL=/bin/sh
CXX=g++
CXXFLAGS= -g -Wall -ansi -pedantic -IMYTemplateHDRS -I. `sdl-config --cflags`
LIBS=`sdl-config --libs`
OSTYPE=$(shell uname -s)
ifeq ($(OSTYPE),Linux)
GLLIBS=-lGL -lGLU -L/usr/X11/lib
else
CXXFLAGS+=-I/usr/include/g++-3
GLLIBS=-lopengl32 -lglu32
endif
SRCS=$(wildcard bag.cpp )
BINARIES=$(basename $(SRCS))
OBJS=$(subst .cpp,.o,$(SRCS))
MYTEMPLATES=MYTemplateHDRS/*.hpp
BAGDIRC=$(wildcard ./bagdir/*.cpp )
BAGDIRH=$(wildcard ./bagdir/*.hpp )
BAGOBJ=$(subst .cpp,.o,$(BAGDIRC))
DRAWHDR=draw.hpp
DRAWOBJ=draw.o
STEERHDR=Steer.hpp
STEEROBJ=Steer.o
#all:
# @echo $(BINARIES) $(BAGDIRC) $(BAGOBJ)
all: $(BINARIES) $(OBJS) $(DRAWOBJ) $(STEEROBJ) $(BAGOBJ)
#$(BAGOBJ): $(BAGDIRC)
# $(CXX) -c $< $(CXXFLAGS)
# @echo mybagdir $(@D) mybagsources $(BAGDIRC) mybagobjects $(BAGOBJ)
#Compiling
.cpp.o: $(MYTEMPLATES) $(DRAWHDR) $(STEERHDR)
@echo mycompile $(CXX) -c $< $(CXXFLAGS)
@echo mytargetname $@ and target dir $(@D)
$(CXX) -c $< $(CXXFLAGS)
# linking
bag: bag.o $(DRAWOBJ) $(STEEROBJ) $(BAGOBJ)
@echo mylinking $(CXX) $< $(DRAWOBJ) $(STEEROBJ) $(BAGOBJ) -o $@ $(LIBS) $(GLLIBS)
$(CXX) $< $(DRAWOBJ) $(STEEROBJ) $(BAGOBJ) -o $@ $(LIBS) $(GLLIBS)
clean:
rm -f *.o $(BINARIES) *~ stdout.txt stderr.txt
Edit: Removed couple commants from makefile.
New edit. Learned more about makefiles end then made one which has some sense but still problematic.