嵌套的for循环在makefile中不起作用 [英] Nested for loop not working in makefile

查看:604
本文介绍了嵌套的for循环在makefile中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用嵌套的for循环在makefile中的目标之一的配方中搜索和复制一些文件:

I am trying to use a nested for loop for searching and copying some files inside the recipe of one of the targets inside a makefile:

DIR = $(DIR_A) $(DIR_B)

install:
      for dirs in $(DIR); do \
        for file in $(shell find $(dirs) -type f -and -not -path "*/.svn*" | sed -e "s|$(dirs)||"); do \
        folder=$${file%/*}; \
          $(INSTALL) -d $(DEST_DIR)$$folder/log; \
          $(INSTALL) $(dirs)/$$file $(DEST_DIR)$$folder/log; \
        done \
      done

但是$(dirs)变量在第二个for循环内始终为空,并且当前工作目录被传递到"find",而不是$(DIR)的第一个目录路径.

However $(dirs) variable always evaluates to empty inside the second for loop and the current working directory gets passed to "find" instead of first directory path from $(DIR).

有人可以建议我是否想念东西吗?

Can someone please suggest if I am missing something ?

谢谢.

推荐答案

find命令中的$(dirs)由make扩展为未设置的make变量dirs,因此为空字符串.要引用shell变量,您需要转义$:

The $(dirs) in the find command is being expanded by make to the make variable dirs which is unset and thus the empty string. To reference the shell variable, you need to escape the $:

 for file in $$(find $${dirs} -type f -and \
      -not -path "*/.svn*" | sed -e "s|$${dirs}||"); do

但是不要这样做.显式列出要安装的文件要干净得多.如果有很多,最好编写一个脚本来生成Makefile.您正在做的是一个脆弱的烂摊子.

But don't do this. It is much cleaner to explicitly list the files you intend to install. If there are many, it is fine to write a script to generate the Makefile. What you are doing is a fragile mess.

这篇关于嵌套的for循环在makefile中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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