我的应用程序使用 autotools
在 $pkgdatadir
中安装运行时所需的数据文件。应用程序的部分内容是用 C 编写的,数据目录的路径由 Makefile.am
中的以下语句设置:
AM_CPPFLAGS = -DAM_DATADIR='"$(pkgdatadir)"'
但我还需要从各种 Perl 和 shell 脚本访问此数据目录。除了在安装过程中修改脚本之外,是否有解决此问题的通用方法?
最佳答案
autoconf 文档中提到了这个问题,建议的解决方案是在 make 时(安装之前)构建脚本。我不清楚这个解决方案是否是您所说的“在安装过程中修改脚本”的意思,但这确实是唯一可行的解决方案,因为 pkgdatadir 仅在 Makefile 中定义,因此必须使用 make (除非您想采用尝试在 Makefile 之外复制 pkgdatadir 的定义是极其脆弱的方法。)
这是我现在能找到的最好的链接:http://www.delorie.com/gnu/docs/autoconf/autoconf_24.html 。相关部分描述了以下示例 make 片段来构建 autoconf 和 autoheader:
edit = sed \ -e 's,@datadir[@],$(pkgdatadir),g' \ -e 's,@prefix[@],$(prefix),g' autoconf: Makefile $(srcdir)/autoconf.in rm -f autoconf autoconf.tmp $(edit) $(srcdir)/autoconf.in >autoconf.tmp chmod +x autoconf.tmp mv autoconf.tmp autoconf autoheader: Makefile $(srcdir)/autoheader.in rm -f autoheader autoheader.tmp $(edit) $(srcdir)/autoconf.in >autoheader.tmp chmod +x autoheader.tmp mv autoheader.tmp autoheader
关于autotools - 从脚本中查找由 autotools 定义的 $pkgdatadir,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6428989/