Automake Variables整理Makefile.am

时间:2021-11-10 12:41:23

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:

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

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

Now in Makefile.am, I have to specified:

现在在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

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

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

$BIN = bin
$SRC = src 

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

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

Thanks

谢谢

3 个解决方案

#1


4  

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

你可以利用远程建设。将此makefile放在bin目录中:

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:

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

SUBDIRS = bin

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

现在调整你的configure.ac以生成bin / Makefile

AC_CONFIG_FILES([Makefile
        bin/Makefile])

and you should be set for life.

你应该为生活做好准备。

#2


2  

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

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

#3


1  

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:

我已经以各种形式对它进行了几次测试,它不会像你的例子那样编译代码;我以某种方式确信它是在一个阶段编译C:

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.

因此,我很确定这是不可能的。抱歉。

#1


4  

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

你可以利用远程建设。将此makefile放在bin目录中:

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:

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

SUBDIRS = bin

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

现在调整你的configure.ac以生成bin / Makefile

AC_CONFIG_FILES([Makefile
        bin/Makefile])

and you should be set for life.

你应该为生活做好准备。

#2


2  

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

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

#3


1  

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:

我已经以各种形式对它进行了几次测试,它不会像你的例子那样编译代码;我以某种方式确信它是在一个阶段编译C:

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.

因此,我很确定这是不可能的。抱歉。