返回信息流我想先判断work目录是不是存在,如果存在就删除,如果不存在就建立这个目录,代码如下:
working_dir = ./
find_rst = find $(working_dir) -maxdepth 1 -name "work"
clean:
if($(find_rst)==1)
rm -rf $(working_dir)/work
else
mkdir $(working_dir)/work
endif
但是结果报错:
if(find ./ -maxdepth 1 -name "work"==1)
/bin/sh: -c: line 1:syntax error: unexpected end of file
make: ***[clean] Error 2
请问是什么问题啊?
这是一条镜像帖。来源:北邮人论坛 / cpp / #93528同步于 2016/9/23
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
一个Makefile 有关判断目录师傅存在的问题
whwjez
2016/9/23镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
你在 `clean` 里面是要用 make 的条件判断还是 shell 的?make 的条件判断没有 `if` 吧,参考 [https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax](https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax)。如果是 bash 的话,多行语句末尾加 `\`,参考 [https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html](https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html)。
我用的是csh的判断条件~[ema1]
【 在 Vampire 的大作中提到: 】
: 你在 `clean` 里面是要用 make 的条件判断还是 shell 的?make 的条件判断没有 `if` 吧,参考 [https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax](https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax)。如果是 bash 的话,多行语句末尾加 `\`,参考 [https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html](https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html)。
SHELL=/bin/tcsh
TEST_NAME += NAME1*
WORKING_DIR = ../work
.PHONY: clean
clean:
@echo "begin clean"
@echo "working_dir is $(WORKING_DIR), test_name is $(TEST_NAME)"
if ((test -d $(WORKING_DIR)/$(TEST_NAME)) )then \
echo "work already exists" \
else\
echo "work does not exsit" \
endif
报错如下:
if:Expression Syntax.
make: *** [clean] Error 1
我linux的环境的shell是tcsh
我都快疯了!!!
【 在 Vampire 的大作中提到: 】
: 你在 `clean` 里面是要用 make 的条件判断还是 shell 的?make 的条件判断没有 `if` 吧,参考 [https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax](https://www.gnu.org/software/make/manual/make.html#Conditional-Syntax)。如果是 bash 的话,多行语句末尾加 `\`,参考 [https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html](https://www.gnu.org/software/make/manual/html_node/Splitting-Lines.html)。
试试在 if 和 else 的 echo 后面加个分号(或者你的 shell 对应的断行字符)。
【 在 whwjez 的大作中提到: 】
: SHELL=/bin/tcsh
: TEST_NAME += NAME1*
: WORKING_DIR = ../work
: ...................