Locating $pkgdatadir defined by autotools from a script
My application uses autotools
to install data files that are needed at runtime in $pkgdatadir
. Part of the application is written in C, and the path to the data directory is set by the following stateme开发者_JAVA技巧nt in Makefile.am
:
AM_CPPFLAGS = -DAM_DATADIR='"$(pkgdatadir)"'
But I also need to have access to this data directory from various Perl and shell scripts. Is there a common approach to this problem other modifying the scripts during installation?
This problem is mentioned in the autoconf documentation, and the recommended solution is to build the scripts during make time (before install). It's not clear to me if this solution is what you mean by "modifying the scripts during installation", but this is really the only viable solution since pkgdatadir is only defined in the Makefile, so make must be used (unless you want to adopt the extremely fragile approach of attempting to duplicate the definition of pkgdatadir outside of the Makefile.)
This is the best link I could find just now: http://www.delorie.com/gnu/docs/autoconf/autoconf_24.html. The relevant portion describes the following sample make snippet to build autoconf and 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
精彩评论