我将编译的所有目标文件转储到一个名为
objfiles
在编译时,我想检查目录 objfiles 是否存在,如果它不存在(表示重新编译整个项目),我想创建它。
这是我的 Makefile 和对问题的尝试
SHELL := /bin/zsh
#All object files are dumped into OBJDIR
OBJDIR=objfiles
OBJECTS=$(OBJDIR)/main.o \
$(OBJDIR)/printdata.o \
#...
#...
COMPILER=nvcc -arch=sm_20
exec: objdir_exist $(OBJECTS)
$(COMPILER) $(OBJECTS) -o exec
@printf "\nExecutable updated!\n\n"
$(OBJDIR)/main.o: main.cu octree.h
$(COMPILER) -c $< -o $@
$(OBJDIR)/printdata.o: printdata.cu
$(COMPILER) -c $< -o $@
...
#Clean-up executables and object files
.PHONY=clean objdir_exist
clean:
rm exec
rm -r $(OBJDIR)
# Check for the existence of object files.
# If it does not exist, then create another object_file directory to dump data to.
# If it exists do nothing
objdir_exist:
if [ ! -d "$(OBJDIR)" ] then mkdir $(OBJDIR) fi
我收到以下错误。
if [ ! -d "objfiles" ] then mkdir objfiles fi
zsh:[:1: ']' expected
nvcc -arch=sm_20 -c main.cu -o objfiles/main.o
Assembler messages:
Fatal error: can't create objfiles/main.o: No such file or directory
make: *** [objfiles/main.o] Error 1
我哪里错了?