Makefile 规则依赖项列表中的修饰符
问题很简单。我正在尝试编写一个规则,给定所需文件的名称将能够定制其依赖项。
假设我有两个程序:calc_foo 和 calc_bar,它们生成一个文件,其输出取决于参数。我的目标名称为“target_*_*”;例如,“target_foo_1”将通过运行“./calc_foo 1”生成。
问题是,如何编写一个 makefile 来生成两个程序的一系列参数的输出?
The problem is fairly simple. I am trying to write a rule, that given the name of the required file will be able to tailor its dependencies.
Let's say I have two programs: calc_foo and calc_bar and they generate a file with output dependent on the parameter. My target would have a name 'target_*_*'; for example, 'target_foo_1' would be generated by running './calc_foo 1'.
The question is, how to write a makefile that would generate outputs of the two programs for a range of parameters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果只有几个程序,您可以为每个程序制定一个规则:
如果您想运行一个带有参数列表的程序:
如果您想为每个程序使用一组不同的参数,但有一些共同点,您可以将常见的分开:
如果事实证明您的程序比您想象的要多,但仍然想使用此方法,您只想将其自动化:
If there are just a few programs, you can have a rule for each one:
If you want to run a program with a list of parameters:
If you want a different set of parameters for each program, but with some in common, you can separate the common ones:
If it turns out you have more programs than you thought, but still want to use this method, you just want to automate it:
这似乎或多或少地满足了您的要求 - 假设您正在使用 GNU Make。
Makefile
它可能可以被清理,但我用以下命令测试了它:
calc_bar
calc_foo
显然,如果您想要不同的列表,您可以在命令行上指定:
This seems to do more or less what you are requesting - assuming you are using GNU Make.
Makefile
It can probably be cleaned up, but I tested it with the commands:
calc_bar
calc_foo
Clearly, if you want a different list, you can specify that on the command line: