Automake Variables整理Makefile.am

w00*_*00d 13 c++ configuration automake makefile gnu-make

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

/BuildDirectory
- - /src
- - /bin
- - configure
- - Makefile.am
- - configure.ac 
- - ... 
Run Code Online (Sandbox Code Playgroud)

现在在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
Run Code Online (Sandbox Code Playgroud)

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

$BIN = bin
$SRC = src 
Run Code Online (Sandbox Code Playgroud)

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

谢谢

Dip*_*tch 4

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

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

x_SOURCES = x.cpp
y_SOURCES = y.cpp
z_SOURCES = z.cpp
Run Code Online (Sandbox Code Playgroud)

现在将当前的 Makefile.am 替换为以下内容:

SUBDIRS = bin
Run Code Online (Sandbox Code Playgroud)

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

AC_CONFIG_FILES([Makefile
        bin/Makefile])
Run Code Online (Sandbox Code Playgroud)

你应该为生活做好准备。