如何使用 GNU Autotools 配置源文件目录和安装位置
我想要一个像这样的项目目录:
app/ | src/ Makefile
所有.cpp和.hpp、.h文件都在src
子目录中。如何配置Makefile.am
或configure.ac
让生成的Makefile使用目录/src
作为源目录?以及如何让生成的可执行文件进入到指定目录如/usr/opt
?
另一个问题是,如果我想让我的程序作为.so库,如何实现我的目标,使其安装到 /usr/lib
或 /usr/local/lib
代码>?以及如何将头文件做成/usr/local/include/app
?
I want a project directory like this:
app/ | src/ Makefile
All of the .cpp and .hpp, .h files are in the src
subdirectory. How can I configure Makefile.am
or configure.ac
to let the generated Makefile using the directory /src
as the source directory? And how to let the generated executable into a specified directory like /usr/opt
?
Another question is that If I want to make my program as a .so library, how to achieve my goal to make it install into /usr/lib
or /usr/local/lib
? And how to make the header files into like /usr/local/include/app
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常,您只需添加
到顶层 Makefile.am,并在 AC_CONFIG_FILES 中提及 src/Makefile。关于递归 make 有一些合理的抱怨,但如果所有源代码都在 src 中,那么 make 中的单级递归并不是真正的问题。将可执行文件放入 /usr/opt 是由用户在配置时设置前缀时完成的,在构建包时不应该考虑。要构建可执行文件,请在 Makefile.am 中使用 bin_PROGRAMS,要构建库,您应该使用 lib_LIBRARIES 或 lib_LTLIBRARIES (就个人而言,我倾向于使用 libtool 并使用后者。)
我认为您对安装在 /usr/ 中的问题lib 或 /usr/opt 中表示一个根本性的误解。在构建包时,你绝对不关心这一点。作为软件包维护者,您指示程序应安装在 $(prefix)/bin (或 $exec_prefix/bin 或 $bindir)中,并且库应位于 $libdir 中,但用户确定 $prefix 和$libdir 和 $bindir 运行配置时。 (通常,人们只是设置前缀,bindir 默认为 $prefix/bin,而 libdir 默认为 $prefix/lib。)
Usually, you just add
to the toplevel Makefile.am, and mention src/Makefile in AC_CONFIG_FILES. There are some reasonable complaints about recursive make, but if all of your source is in src then the single level of recursion in make is not really an issue. Putting the executable in /usr/opt is done by the user when setting prefix at configure time, and should not be a consideration when building the package. To build an executable, use bin_PROGRAMS in the Makefile.am, and to build a library you should use either lib_LIBRARIES or lib_LTLIBRARIES (personally, I tend to use libtool and go with the latter.)
I think your questions about installing in /usr/lib or in /usr/opt indicate a fundamental misunderstanding. When building the package, you absolutely do not care about that. As the package maintainer, you indicate that the program should be installed in $(prefix)/bin (or $exec_prefix/bin, or $bindir) and that libraries should be in $libdir, but the user determines the location of $prefix and $libdir and $bindir when they run configure. (Usually, people just set prefix, and bindir defaults to $prefix/bin while libdir defaults to $prefix/lib.)
通常,对于可执行文件,您将拥有类似以下内容:
这将安装在前缀目录的 /bin 目录中,尽管这不是您想要的,但它是您用户所期望的。
要执行您想要的操作,您需要执行以下操作:
其中 foo_SOURCES 如上所述。
对于库,它只是:
它将安装在前缀目录的 /lib 目录中。设置 lib 安装位置并不由您(直接)决定,但无论谁调用configure:
都将在 /usr/lib 中进行 lib 安装(当调用 make install 时)
或
将进行 lib 安装在 /usr/local/lib 中。
Typically for executable files you'll have something like:
This will install in the prefix directory's /bin directory, though which isn't what you want, but it's kind of what you users will expect.
To do what you want you'll need to do this:
where foo_SOURCES is as above.
For libraries it's just:
and it will install in the prefix directory's /lib directory. Setting up where the lib installs isn't up to you (directly) but whoever invokes configure:
will make the lib install (when make install is called) in /usr/lib
or
will make the lib install in /usr/local/lib.
将 autoconf 和 automake 文件 configure.ac 和 Makefile.am 放入“src”目录中,并在文档中写入“./configure”命令应在此处运行而不是在顶级目录中?否则,您实际上无法避免至少有一些 autoconf/automake 文件位于顶层。
Put the autoconf and automake files configure.ac and Makefile.am in the "src" directory and write in your documentation that the "./configure" command should be run there instead of in the top level directory? Otherwise you can not really avoid having at least some of the autoconf/automake files at the top level.