make 文件中所需的帮助
我只想执行以下声明,
"if bin folder is not available in current directory then make new bin folder &
if bin folder is available then its do nothing"
有人可以告诉我我该怎么做吗?
编辑 : 我不想要任何错误,比如
mkdir: cannot create directory `./bin `./bin': File exists
i just want to implement below statement
"if bin folder is not available in current directory then make new bin folder &
if bin folder is available then its do nothing"
can anybody give me any idea how can i do this?
EDIT :
i dont want any error like
mkdir: cannot create directory `./bin `./bin': File exists
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你可以这样做:
如果
./bin
已经存在,那么mkdir
将默默失败,否则它将创建该目录。You can just do this:
If
./bin
already exists thenmkdir
will fail silently, otherwise it will create the directory.使用如下规则:
然后,不要将
mkdir bin
编写为其他规则的一部分,而是使它们依赖于bin
规则。仅当bin
不存在时才会执行bin
规则。Use a rule like this:
Then instead of writing
mkdir bin
as part of other rules, make them depend on thebin
rule. Thebin
rule will only be executed ifbin
does not exist.根据您的要求,您可以使用如下规则:
请注意,if 语句检查 makefile 所在的当前目录中是否存在名为 bin 的目录,如果名为 bin 的目录不存在,则它将创建它,如果存在,则不执行任何操作,但是如果存在名为 bin 的常规文件(不是目录),则此规则将失败。
建议您使用一个变量(例如 BINDIR)来存储“bin”目录的值,因为这是遵循的一般规范,这有利于 makefile 的维护。
For your requirement you can use the rule as follows:
Please note that if statement checks for existence of directory named bin in the current directory where makefile resides, if directory named bin does not exist then it will create it, if it exists it does nothing, but if there is a regular file (not a directory) with the name bin exists then this rule will fail.
Suggest you to use a variable say BINDIR to store the value of your "bin" directory as that is the general norm followed, it is good for maintenance of makefile.