如何使用 GNU Autotools 配置源文件目录和安装位置

发布于 2024-11-27 10:34:49 字数 395 浏览 2 评论 0原文

我想要一个像这样的项目目录:

app/
 |
  src/
  Makefile 

所有.cpp和.hpp、.h文件都在src子目录中。如何配置Makefile.amconfigure.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

妳是的陽光 2024-12-04 10:34:49

通常,您只需添加

SUBDIRS = src

到顶层 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

SUBDIRS = src

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.)

梦一生花开无言 2024-12-04 10:34:49

通常,对于可执行文件,您将拥有类似以下内容:

bin_PROGRAMS = foo
foo_SOURCES = $(top_srcdir)/src/foo_main.c \
$(top_srcdir)/src/foo_main.h \
$(top_srcdir)/src/something_else.c

这将安装在前缀目录的 /bin 目录中,尽管这不是您想要的,但它是您用户所期望的。

要执行您想要的操作,您需要执行以下操作:

 myexedir = $(prefix)/opt
 myexe_PROGRAMS = foo
 foo_SOURCES = ...

其中 foo_SOURCES 如上所述。

对于库,它只是:

lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = ...

它将安装在前缀目录的 /lib 目录中。设置 lib 安装位置并不由您(直接)决定,但无论谁调用configure:

./configure --prefix=/usr

都将在 /usr/lib 中进行 lib 安装(当调用 make install 时)

./configure

./configure --prefix=/usr/local

将进行 lib 安装在 /usr/local/lib 中。

Typically for executable files you'll have something like:

bin_PROGRAMS = foo
foo_SOURCES = $(top_srcdir)/src/foo_main.c \
$(top_srcdir)/src/foo_main.h \
$(top_srcdir)/src/something_else.c

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:

 myexedir = $(prefix)/opt
 myexe_PROGRAMS = foo
 foo_SOURCES = ...

where foo_SOURCES is as above.

For libraries it's just:

lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = ...

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:

./configure --prefix=/usr

will make the lib install (when make install is called) in /usr/lib

./configure

or

./configure --prefix=/usr/local

will make the lib install in /usr/local/lib.

小傻瓜 2024-12-04 10:34:49

将 autoconf 和 automake 文件 configure.acMakefile.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文