我有一个configure脚本生成一个config.inc包含一些变量定义的文件,并使用makefile它来导入这些配置
include config.inc
Run Code Online (Sandbox Code Playgroud)
困扰我的是,如果用户尝试直接运行makefile而没有先运行configure,则会收到一条无用的错误消息:
makefile:2: config.inc: No such file or directory
make: *** No rule to make target 'config.inc'. Stop.
Run Code Online (Sandbox Code Playgroud)
有没有办法让我产生一个更好的错误信息,指示用户首先运行配置脚本,而不采取从内部生成完整的makefile的autoconf策略configure?
好没问题; 做这样的事情:
atarget:
echo here is a target
ifeq ($(wildcard config.inc),)
$(error Please run configure first!)
endif
another:
echo here is another target
include config.inc
final:
echo here is a final target
Run Code Online (Sandbox Code Playgroud)
注意这绝对是GNU make特有的; 没有可移植的方法来做到这一点.
编辑:以上示例将正常工作.如果该文件config.inc存在,则将包含该文件.如果该文件config.inc不存在,则make将在读取makefile时退出(作为该error函数的结果)并且永远不会到达该include行,因此不会有关于缺少包含文件的模糊错误.这就是原始海报所要求的.
EDIT2:这是一个示例运行:
$ cat Makefile
all:
@echo hello world
ifeq ($(wildcard config.inc),)
$(error Please run configure first!)
endif
include config.inc
$ touch config.inc
$ make
hello world
$ rm config.inc
$ make
Makefile:5: *** Please run configure first!. Stop.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1811 次 |
| 最近记录: |