Automake 变量来整理 Makefile.am

发布于 2024-11-17 02:25:31 字数 510 浏览 3 评论 0原文

我有一个目录 /src 包含所有源文件, /bin 用来在运行 make 命令后存储所有二进制文件。该目录如下所示:

/BuildDirectory
- - /src
- - /bin
- - configure
- - Makefile.am
- - configure.ac 
- - ... 

现在在 Makefile.am 中,我必须指定:

bin_PROGRAMS = bin/x bin/y bin/z bin/k ...

bin_x_SOURCES = src/x.cpp
bin_y_SOURCES = src/y.cpp
bin_z_SOURCES = src/z.cpp

是否有任何变量可以帮助摆脱所有“bin/”和“src/”? 例如,我只是指定:

$BIN = bin
$SRC = src 

他们将在正确的文件夹中查找正确的文件并将其编译到正确的位置。

谢谢

I have a directory /src containing all of my source files, and /bin to store all binary after running make command. The directory is something like below:

/BuildDirectory
- - /src
- - /bin
- - configure
- - Makefile.am
- - configure.ac 
- - ... 

Now in Makefile.am, I have to specified:

bin_PROGRAMS = bin/x bin/y bin/z bin/k ...

bin_x_SOURCES = src/x.cpp
bin_y_SOURCES = src/y.cpp
bin_z_SOURCES = src/z.cpp

Is there any variable that can help to get rid of all "bin/" and "src/" ?
For example I just specify:

$BIN = bin
$SRC = src 

And they will look for the correct files in correct folders and compile it to the correct places.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

孤凫 2024-11-24 02:25:31

您可以利用远程构建。将此 makefile 放入 bin 目录中:

VPATH = ../src
bin_PROGRAMS = x y z k ...

x_SOURCES = x.cpp
y_SOURCES = y.cpp
z_SOURCES = z.cpp

现在用此替换当前的 Makefile.am:

SUBDIRS = bin

现在调整您的configure.ac 以也生成 bin/Makefile,

AC_CONFIG_FILES([Makefile
        bin/Makefile])

并且您应该终身设置。

You could take advantage of remote building. Place this makefile in the bin dir:

VPATH = ../src
bin_PROGRAMS = x y z k ...

x_SOURCES = x.cpp
y_SOURCES = y.cpp
z_SOURCES = z.cpp

Now replace the current Makefile.am with this one:

SUBDIRS = bin

Now tweak your configure.ac to also generate bin/Makefile

AC_CONFIG_FILES([Makefile
        bin/Makefile])

and you should be set for life.

天冷不及心凉 2024-11-24 02:25:31

据我所知。如果您希望将编译后的文件与源文件分开,请记住您可以在树之外构建:

$ cd foo-1.2.3
$ mkdir build
$ cd build
$ ../configure
$ make
$ make install

如果这是您想要做的,您可以创建 Makefile.am通过创建没有目录前缀的二进制文件(并且仍然手动引用 src/ 中的内容)来更简单。

Not to my knowledge. If you're looking to separate your compiled files from your source files, remember that you can build outside of the tree:

$ cd foo-1.2.3
$ mkdir build
$ cd build
$ ../configure
$ make
$ make install

If this is what you're looking to do, you can make the Makefile.am simpler by creating binaries without a directory prefix (and still referencing things in src/ by hand).

爱格式化 2024-11-24 02:25:31

如果你想做的就是我认为你想做的,那么你正在尝试实现类似的目标:

SRCDIR  = src
BINDIR  = bin

bin_PROGRAMS = $(BINDIR)/x $(BINDIR)/y $(BINDIR)/z

bin_x_SOURCES = $(SRCDIR)/x.cpp
bin_y_SOURCES = $(SRCDIR)/y.cpp
bin_z_SOURCES = $(SRCDIR)/z.cpp

我已经以各种形式测试了几次,并且它不会编译代码以你为例;我以某种方式确信它在某个阶段编译了 C:

gmake[1]: *** No rule to make target `bin/x.c', needed by `x.o'.  Stop.

因此我相当确定这是不可能的。对不起。

If what you're trying to do is what I think you're trying to do, you're trying to achieve something like:

SRCDIR  = src
BINDIR  = bin

bin_PROGRAMS = $(BINDIR)/x $(BINDIR)/y $(BINDIR)/z

bin_x_SOURCES = $(SRCDIR)/x.cpp
bin_y_SOURCES = $(SRCDIR)/y.cpp
bin_z_SOURCES = $(SRCDIR)/z.cpp

I've tested this a few times in various forms, and it won't compile the code as it would with your example; I somehow convinced it that it was compiling C at one stage:

gmake[1]: *** No rule to make target `bin/x.c', needed by `x.o'.  Stop.

I'm thus fairly certain that it's not possible. Sorry.

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