I have this makefile
appname := fun
srcfiles := $(shell find .. -name "*.cpp")
headerfiles := $(shell find .. -name "*.hpp")
objects := $(patsubst %.cpp, %.o, $(srcfiles))
all: $(srcfiles) $(appname)
$(appname): $(objects)
$(CXX) $(LDFLAGS) -o $(appname) $(objects) $(LDLIBS)
depend: .depend
.depend: $(srcfiles) $(headerfiles)
rm -f ./.depend
$(CXX) $(CXXFLAGS) -MM $^>>./.depend;
clean:
rm -f $(appname) $(objects)
dist-clean: clean
rm -f *~ .depend
include .depend
Where the makefile
's parent directory contain all the code (.hpp
and .cpp
files). Unfortunately, the .o
files are saved in the source code, while I want that they're saved in the same directory of the executable (and makefile
). This is the same of Default
in Eclipse CDT.
How can I modify makefile
in order to do that?
PS: I found similar questions, like this one, but none of them used depend
for defining the $(objects)
task (they're all in `%.o% form).