SOURCES:=$(shell find $(SRC)/ -type f -name '*.c') #Get all the c files
#Get the files they're gonna be compiled to
OBJECTS:=$(patsubst $(SRC)/%.c, $(OBJ)/%.o, $(SOURCES))
#Get just the paths so you can create them in advance
OBJDIRS:=$(dir $(OBJECTS))
#call mkdir with the directories (using a dummy var because too much
#trouble to deal with priorities) someone could prob do better
#--parents ignores the repeated and already existing errors
DUMMY:=$(shell mkdir --parents $(OBJDIRS))
3条答案
按热度按时间2ledvvac1#
从this post看,似乎没有办法从
gcc
创建目录。对于makefile,我可以使用以下代码片段。
make build
将创建目录,并回显结果。我们也可以使目标文件自动创建而不调用
make build
。guz6ccqo2#
我这样做的方法是我找出路径将是什么,并为他们创建目录:
酱料:https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html
qnakjoqk3#
除了先前的解决方案之外,您还可以在规则中创建目录以构建.o文件