Taking substring from pathname in Makefile
I currently have the following rule in a Makefile:
../obj/%.o: %.cpp
mkdir -p ../obj/$<
$(CXX) $(CXXFLAG开发者_运维百科S) $(INCLUDES) $(LIBS) -c $< -o $@
rmdir ../obj/$<
It takes a cpp file and builds an object file from it, storing the object file under the obj directory. I have multilpe folder hierarchies and this stores the object files within this heirarchy, e.g:
log/internal/log_level.cpp = ../obj/log/internal/log_level.o
As is clear i have hacked make to build the required folders under ../obj. Is there a way I can use make, perhaps through patsubst, whereby I could mkdir with the value of $< not including the filename?
How about $(<D)
? Manual.
精彩评论