使用make为任意语言添加m4预处理
我们有一个使用 GNU make 构建的 ActionScript (Flex) 项目。我们希望在构建过程中添加 M4 预处理步骤(例如,以便我们可以创建包含文件和行号的 ASSERT() 宏)。
我们遇到了巨大的困难。
我们当前的策略是:
- 创建一个目录“src/build”(假设源代码位于 src/ 及其子目录中)。
- 在 src/build 中,创建一个 Makefile。
- 在 src/build 中运行 make。
期望的行为是,make 将使用我们编写的规则发送 *.as 文件 src/ 及其子目录,在构建下创建新的 *.as 文件。例如:
src/bar.as -> m4 -> src/build/bar.as
src/a/foo.as -> m4 -> src/build/a/foo.as
明显的 make 规则是:
%.as : ../%.as
echo "m4 --args < $< > $@"
这适用于 bar.as 但不适用于 a/foo.as,显然是因为 make 在分割和重新打包目录方面非常“智能”。 make -d 显示:
Trying implicit prerequisite `a/../foo.as'.
Looking for a rule with intermediate file `a/../foo.as'.
但我们希望先决条件是“../a/foo.as”。这(我们不想要的)显然是有记录的行为( http://www.gnu.org/software/make/manual/make.html#Pattern-Match)。
有什么建议吗?是否可以编写一个符合我们要求的模式规则?
我们也尝试过 VPATH,但它不起作用,因为生成的 .as 文件错误地满足了依赖关系(因为 . 在 VPATH 内容之前搜索)。
任何帮助将不胜感激。
We have an ActionScript (Flex) project that we build using GNU make. We would like to add an M4 preprocessing step to the build process (e.g., so that we can create an ASSERT() macro that includes file and line numbers).
We are having remarkable difficulty.
Our current strategy is:
- Create a directory "src/build" (assuming source code is in src/ and subdirectories).
- Within src/build, create a Makefile.
- Run make inside src/build.
The desired behavior is, make would then use the rules we write to send the *.as files src/ and its subdirs, creating new *.as files under build. For example:
src/bar.as -> m4 -> src/build/bar.as
src/a/foo.as -> m4 -> src/build/a/foo.as
The obvious make rule would be:
%.as : ../%.as
echo "m4 --args < lt; > $@"
This works for bar.as but not a/foo.as, apparently because make is being "smart" about splitting and re-packing directories. make -d reveals:
Trying implicit prerequisite `a/../foo.as'.
Looking for a rule with intermediate file `a/../foo.as'.
but we want the prerequisite to be "../a/foo.as". This (what we don't want) is apparently documented behavior (http://www.gnu.org/software/make/manual/make.html#Pattern-Match).
Any suggestions? Is it possible to write a pattern rule that does what we want?
We've tried VPATH also and it does not work because the generated .as files are erroneously satisfying the dependency (because . is searched before the contents of VPATH).
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种选择是对未经预处理的文件使用不同的扩展名。然后你就可以将它们放在同一目录中而不会发生冲突。
One option is to use a different extension for files that haven't been preprocessed. Then you can have them in the same directory without conflict.
正如 Anon 还所说,您的源代码不再是 Flex - 它是“要预处理的 Flex”。因此,对源代码使用诸如“.eas”(用于扩展 ActionScript)之类的扩展名,并创建一个“编译器”脚本,将“.eas”转换为“.as”文件,然后可以像以前一样对其进行处理。
您可能更喜欢让扩展 ActionScript 编译器完成整个编译工作 - 将“.eas”直接转换为编译形式。
需要警惕的主要事情是确保在派生的“.as”文件之前考虑“.eas”文件。否则,您在“.eas”文件中所做的更改将不会被采纳,从而在您尝试调试尚未执行的代码时导致令人抓狂和其他不良行为(例如“用头撞墙”)。即使来源已经改变,也没有改变。
As Anon also said, your source code is no longer Flex - it is 'to be preprocessed Flex'. So, use an extension such as '.eas' (for Extended ActionScript) for the source code, and create a 'compiler' script that converts '.eas' into '.as' files, which can then be processed as before.
You may prefer to have the Extended ActionScript compiler do the whole compilation job - taking the '.eas' direct to the compiled form.
The main thing to be wary of is ensuring that '.eas' files are considered before the derived '.as' files. Otherwise, your changes in the '.eas' files will not be picked up, leading to hair-tearing and other undesirable behaviours (head banging, as in 'banging head against wall', for example) as you try to debug code that hasn't changed even though the source has.