如果您是通过搜索引擎找到这儿来的,我想您应该也是正在读 《Autotools: a practitioner's guide to GNU autoconf, automake, and libool》 这本书
我在这儿列出了一些书中我目前不太能理解的片段,如果您能留言解释,实在是感谢!
我自己也会不定期更新我对这些内容的理解。
Page 50:
----------------------------------------------------------------------------------------------------
%install
make prefix=/usr DESTDIR=%BUILDROOT install
----------------------------------------------------------------------------------------------------
You may be wondering why the prefix variable couldn’t provide this
functionality. For one thing, not every path in a system-level installation is
defined relative to the prefix variable. The system configuration directory
(sysconfdir), for instance, is often defined as /etc by packagers. You can see
in Table 2-1 that the default definition of sysconfdir is $(prefix)/etc, so the
only way sysconfdir would resolve to /etc would be if you explicitly set it to do
so on the configure or make command line. If you configured it that way, only
a variable like DESTDIR would affect the base location of sysconfdir during
staged installation. Other reasons for this will become clearer as we talk
about project configuration later on in this chapter, and then again in the
next two chapters.
GCS的文档对DESTDIR的介绍:
http://www.gnu.org/prep/standards/html_node/DESTDIR.html
DESTDIR只应该被用在install和uninstall对应的命令中
假设有如下规则: (这个规则不支持DESTDIR)
install:
cp aaa $(bindir)/aaa
cp bbb $(sysconfdir)/bbb
根据GCS的规定,prefix默认是 /usr/local, bindir通常是被定义为 $(prefix)/bin , sysconfdir通常被定义为 $(prefix)/etc
如果packager(即负责制作RPM包的人)打算把aaa安装到 /usr/local/bin ,而把bbb安装到 /etc , 他只能这样:
make install sysconfdir=/etc
接下来考虑支持staged install。把规则加上对DESTDIR的支持:
install:
cp aaa $(DESTDIR)/$(bindir)/aaa
cp bbb $(DESTDIR)/$(sysconfdir)/bbb
所谓staged install,我的理解是,允许packager将软件安装到他所指定的一个临时目录,然后再根据spec文件的描述,把临时目录中的文件拷贝出来生成RPM包。
因为packager并不需要在他的本机安装你的软件,他只是要做一个二进制的RPM包提供给end user使用。
(----- 待确认)
packager执行:
make install prefix=/usr/local/ sysconfdir=/etc DESTDIR=/tmp/build
aaa将会被安装到 /tmp/build/usr/local/bin/ 目录下
bbb将会被安装到 /tmp/build/etc 目录下
支持DESTDIR 的意义就是,保证所有要安装的文件,都会被安装在DESTDIR目录下,不会污染packager的系统。
要做到这一点,仅靠prefix是不够的,假设在不支持DESTDIR的情况下,packager执行了:
make install prefix=/usr/local/ sysconfdir=/etc
bbb就会被安装到/etc/ 目录下,就有可能污染packager的系统。