曲径通幽论坛

标题: shell 函数 -- 执行命令行命令 [打印本页]

作者: beyes    时间: 2011-6-20 11:31
标题: shell 函数 -- 执行命令行命令
在 Makefile 中,可以调用 shell 函数来执行 shell 命令,这样就便于 Makefile 和外部进行通信,它和 shell 脚本中的 `command` 的功能相同。在执行 shell 命令返回结果时,可能会包含换行('\n' 或 "\n\r"),但 make 可以将它们去除。一般情况下,make 在读取 Makefile 文件时,函数 shell 就会被扩展,也就是说会执行 shell 函数后面的参数命令并返回结果。

示例代码:
[Plain Text] 纯文本查看 复制代码
cfile := $(shell ls /home/beyes/C/*.c)

all:
    @echo "$(cfile)"

运行输出:
$ make
/home/beyes/C/percpu.c /home/beyes/C/wchar.c





欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) Powered by Discuz! X3.2