免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: captivated
打印 上一主题 下一主题

我一直没弄明白makefile里面的eval函数,哪位大侠详细讲讲? [复制链接]

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
11 [报告]
发表于 2011-05-23 04:36 |只看该作者
回复 10# shimmey


    手册我查了... 就是查了仍然不解, 所以才问... 没有查GNUmake原英文文档, 我想我也应该查一下(一时间不知道哪里有这个,不过应该能google到,呵呵)... 但是估计英文文档的说明可能令我更不明...

    当然了... 如果您能帮助查这个问题并给予回复和例示, 那真是非常感谢... 这个问题着实困扰了我许久, 现在仍然...

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
12 [报告]
发表于 2011-05-23 11:17 |只看该作者
查了GNUmake英文文档, 其意思跟中文文档一样的, 给的示例也一样.

一下是GNUmake 原英文文档对eval函数的解释:

8.8 The eval Function

The eval function is very special: it allows you to define new makefile constructs that are not constant; which are the result of evaluating other variables and functions. The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax. The expanded results can define new make variables, targets, implicit or explicit rules, etc.

The result of the eval function is always the empty string; thus, it can be placed virtually anywhere in a makefile without causing syntax errors.

It's important to realize that the eval argument is expanded twice; first by the eval function, then the results of that expansion are expanded again when they are parsed as makefile syntax. This means you may need to provide extra levels of escaping for "$" characters when using eval. The value function (see section 8.7 The value Function) can sometimes be useful in these situations, to circumvent unwanted expansions.

Here is an example of how eval can be used; this example combines a number of concepts and other functions. Although it might seem overly complex to use eval in this example, rather than just writing out the rules, consider two things: first, the template definition (in PROGRAM_template) could need to be much more complex than it is here; and second, you might put the complex, "generic" part of this example into another makefile, then include it in all the individual makefiles. Now your individual makefiles are quite straightforward.

...... 一句话, 仍然不明白.

论坛徽章:
0
13 [报告]
发表于 2011-05-23 11:41 |只看该作者
这两句应该是关键
The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.

It's important to realize that the eval argument is expanded twice; first by the eval function, then the results of that expansion are expanded again when they are parsed as makefile syntax. This means you may need to provide extra levels of escaping for "$" characters when using eval.

如果你期望的结果是$(aa)  那么 这样的表达式$($($(xx))) 两次展开后 剩下的结果才是

兄弟 你太好玩了

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
14 [报告]
发表于 2011-05-23 14:38 |只看该作者
回复 13# huxk


    呵呵, 多谢捧场啦. 不过eval的二次展开不是你说的那个意思.

    $($($(xx)))这种, 只是变量递归展开而已, 就是说变量会在使用时递归展开.

    比如你写一个Makefile:
  1. xx = asdfg

  2. .PHONY: all
  3. all:
  4.         @echo $($($(xx)))~~~
复制代码
上面的代码执行,结果会是显示"~~~". 因为$($($(xx)))是一个空值: $(xx) = asdfg, $($(xx)) = $(asdfg) = null, $($($(xx))) = $(null) = null.

     eval函数不是那个意思...

论坛徽章:
0
15 [报告]
发表于 2011-05-23 15:46 |只看该作者
啊 这个难道不是说 让 eval 建立 形如 server : $(server_OBJS) –l$(server_LIBS) 这样的依赖规则的么

另外你的那个 示例makefile和官方文档似乎不一样吧 $(1): $($(1)_OBJ) $($(1)_LIBS:%=-l%) 少了个 $ 吧

论坛徽章:
3
15-16赛季CBA联赛之山东
日期:2016-10-30 08:47:3015-16赛季CBA联赛之佛山
日期:2016-12-17 00:06:31CU十四周年纪念徽章
日期:2017-12-03 01:04:02
16 [报告]
发表于 2011-05-23 17:57 |只看该作者
回复 15# huxk


    哦, 多谢提醒. 少的那个$补上了. 被该死的CU代码引用吞掉了一个... 奇怪...

    回头仔细看了下... 嗯, 其实并不困难. 我基本了解了. TKS...

论坛徽章:
0
17 [报告]
发表于 2012-04-11 00:27 |只看该作者
多谢楼主,我自己也弄明白了,我发现其实这些东西都不难,多看几遍,多体会几次,上机练一练,就能明白

论坛徽章:
0
18 [报告]
发表于 2012-04-11 07:51 |只看该作者
回复 11# captivated


    原来大叔也有这么一段

论坛徽章:
1
白羊座
日期:2013-08-22 17:30:33
19 [报告]
发表于 2012-04-11 08:15 |只看该作者
解释不了,顶一下

论坛徽章:
0
20 [报告]
发表于 2012-04-11 08:45 |只看该作者
个人感觉eval挺像c++的模板的,make处理到eval时先把eval按规则展开,然后再把展开内容处理一遍。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP