makefile中的错误 [英] error in makefile

查看:434
本文介绍了makefile中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个规则设置目录之间的依赖关系。

  OBJDIR = .. / obj 

$(objdir)/%。o:%.C
$(COMPILE) MT $(objdir)/ $(notdir $ @)$< -o $(DEPDIR)/ $(notdir $(basename $<)。d)
$(COMPILE)-o $(objdir)/ $(notdir $ @)-c $<

为了做到这一点,obj目录必须存在。
我想以目录mkdir作为先决条件

  $(objdir)/%。o:%.C $ (objdir)
$(COMPILE)-MM -MT $(objdir)/ $(notdir $ @)$< -o $(DEPDIR)/ $(notdir $(basename $<)。d)
$(COMPILE)-o $(objdir)/ $(notdir $ @)-c $<

$(objdir):
mkdir $(objdir)

这不工作,因为当目录在那里失败,然后make停止
我尝试了shell

 如果[! -d $(objdir)];然后\ 
mkdir $(objdir)\
fi

但显然我有错误这样做的最好方法是什么?

解决方案

一个简单的方法是使用:

  mkdir -p ../obj 

当目录存在时,它不会失败。



我通常为此创建一个宏,MKPATH:

  MKPATH = mkdir -p 

然后引用宏规则:

  $(objdir):
$(MKPATH)$(objdir)

这样,如果需要,我可以改变行为而不改变makefile。






您的shell片段:

  if [! -d $(objdir)];那么
mkdir $(objdir)
fi

make执行每一行。



你可以写(注意添加的分号):

 如果[! -d $(objdir)];然后\ 
$(MKPATH)$(objdir); \
fi

或:

 如果[! -d $(objdir)];然后$(MKPATH)$(objdir); fi 

或:

  [-d $(objdir)] || $(MKPATH)$(objdir)

请注意,命令行必须整体成功,所以不要尝试:

  [! -d $(objdir)]&& $(MKPATH)$(objdir)

如果目录存在,第一个替代方法失败,但是shell退出非零状态,因此失败...并导致构建失败。


I am using gnu Make 3.82 and have an annoying problem.

I have a rule setting dependencies between directories.

OBJDIR=../obj

$(objdir)/%.o: %.C
    $(COMPILE) -MM -MT$(objdir)/$(notdir $@) $< -o $(DEPDIR)/$(notdir $(basename $<).d )
$(COMPILE) -o $(objdir)/$(notdir $@ ) -c $<

In order to do this, the obj directory must exist. I want to mkdir the directory as a prerequisite

$(objdir)/%.o: %.C $(objdir)
    $(COMPILE) -MM -MT$(objdir)/$(notdir $@) $< -o $(DEPDIR)/$(notdir $(basename $<).d )
$(COMPILE) -o $(objdir)/$(notdir $@ ) -c $<

$(objdir):
    mkdir $(objdir)

This doesn't work, because it fails when the directory is there and then the make stops I tried shell

if [ ! -d $(objdir) ] ; then  \
  mkdir $(objdir)             \
fi

but obviously I've got something wrong. What's the best way of doing this?

解决方案

One simple way is to use:

mkdir -p ../obj

It doesn't fail when the directory exists.

I usually create a macro, MKPATH, for this:

MKPATH = mkdir -p

and then reference the macro in the rule:

$(objdir):
    $(MKPATH) $(objdir)

That way, I can change the behaviour without changing the makefile if it becomes necessary.


Your shell fragment:

if [ ! -d $(objdir) ] ; then
  mkdir $(objdir)
fi

does not work as written because make executes each line separately.

You could write (note the added semi-colon):

if [ ! -d $(objdir) ] ; then \
  $(MKPATH) $(objdir) ; \
fi

Or:

if [ ! -d $(objdir) ] ; then $(MKPATH) $(objdir); fi

Or:

[ -d $(objdir) ] || $(MKPATH) $(objdir)

Note that the command line must be successful overall, so do not try:

[ ! -d $(objdir) ] && $(MKPATH) $(objdir)

If the directory exists, the first alternative fails, but the shell exits with a non-zero status, thus failing...and causing the build to fail.

这篇关于makefile中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆