【发布时间】:2018-03-02 15:11:02
【问题描述】:
背景
我们为 Matlab 和 Octave 构建 .mex 文件。源代码对 Matlab 和 Octave 都是通用的,但在这里和那里稍作修改(通过代码中的宏条件处理)。供参考,源码结构为:
root_dir/
|
---------------------------------------------------
| | | |
configure.ac mex/ Makefile.am non-mex-source/
|
------------------------------
| |
sources/ build/
| |
----------- -------------------------------
| | | | | |
mex1/ ... mexN/ octave/ mex1.am ... mexN.am matlab/
| | |
----------- ------------- -------------
| | | | | |
file1.cc ... fileM.cc configure.ac Makefile.am configure.ac Makefile.am
根configure.ac 和Makefile.am 控制mex/build/matlab/、mex/build/octave/ 和我们在non-mex-source/ 中创建的非mex 二进制文件中的配置和编译。
.mex 源文件位于mex/sources/mex*/,我们编译了多个.mex 文件。
Matlab 构建系统位于mex/build/matlab/。这里的configure.ac和Makefile.am是通过AC_CONFIG_SUBDIRS([mex/build/matlab])从根目录下的configure.ac调用的。同样的设置也适用于/mex/build/octave/,其中configure.ac 已被修改以查找特定于 Octave 的头文件和库。
Matlab 和 Octave 共有的 automake 构建指令(源文件的路径,要构建的 .mex 文件)存在于名为 /mex/build/mex*.am 的文件中,通常如下所示:
mex_PROGRAMS += mexI
nodist_mexI_SOURCES = \
../../sources/mexI/mexI.c \
../../sources/mexI/mexI_file1.c \
../../sources/mexI/mexI_fileN.c
递归make 非常适合我们的设置(我们曾经有名为/mex/build/matlab/mex*/ 和/mex/build/octave/mex*/ 的目录包含Makefile.am 文件;目标文件将在那里编译,输出文件将位于那里)。
问题
鉴于 GNU subdir-objects 所做的更改,我们正在转向非递归构建。我已经提出了一个解决方案,将源软链接到 /mex/build/matlab/mex*/ 和 /mex/build/octave/mex*/ 目录(使用 BUILT_SOURCES = .mexfileslinked 并设置源以依赖于该文件的存在;规则为当第一次编译源代码时,此文件将链接到源代码和touch .mexfileslinked)。这很好用,但我认为必须有一个更优雅的解决方案。
我创建了一个最小的工作示例,它显示了当前设置和运行autoreconf -si 时遇到的警告。文件如下:
root_dir/configure.ac:
AC_PREREQ([2.69])
AC_INIT([soquestion], [2.0])
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE([1.15.1 foreign])
# config stuff for other, non-mex binaries we are building
AC_CONFIG_SUBDIRS([mex/build/matlab])
AC_CONFIG_SUBDIRS([mex/build/octave])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
root_dir/Makefile.am:
SUBDIRS = mex/build/matlab mex/build/octave
root_dir/mex/build/mex1.am:
mex_PROGRAMS = mex1
mexdir = $(libdir)/mex/matlab
nodist_mex1_SOURCES = \
$(top_srcdir)/../../sources/mex1/mex1.cc
root_dir/mex/build/matlab/configure.ac 和
root_dir/mex/build/octave/configure.ac:
AC_PREREQ([2.69])
AC_INIT([soquestion], [2.0])
AC_CONFIG_SRCDIR([configure.ac])
AM_INIT_AUTOMAKE([1.15.1 foreign])
AC_PROG_CXX
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
root_dir/mex/build/matlab/Makefile.am 和root_dir/mex/build/octave/Makefile.am:
include ../mex1.am
从root_dir 运行autoreconf -si 会导致警告:
../mex1.am:5: warning: source file '$(top_srcdir)/../../sources/mex1/mex1.cc' is in a subdirectory,
../mex1.am:5: but option 'subdir-objects' is disabled
Makefile.am:1: '../mex1.am' included from here
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled. For now, the corresponding output
automake: object file(s) will be placed in the top-level directory. However,
automake: this behaviour will change in future Automake versions: they will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.
../mex1.am:5: warning: source file '$(top_srcdir)/../../sources/mex1/mex1.cc' is in a subdirectory,
../mex1.am:5: but option 'subdir-objects' is disabled
Makefile.am:1: '../mex1.am' included from here
automake: warning: possible forward-incompatibility.
automake: At least a source file is in a subdirectory, but the 'subdir-objects'
automake: automake option hasn't been enabled. For now, the corresponding output
automake: object file(s) will be placed in the top-level directory. However,
automake: this behaviour will change in future Automake versions: they will
automake: unconditionally cause object files to be placed in the same subdirectory
automake: of the corresponding sources.
automake: You are advised to start using 'subdir-objects' option throughout your
automake: project, to avoid future incompatibilities.
当然,我可以简单地将subdir-objects 添加到AM_INIT_AUTOMAKE 命令以删除警告。但是,然后我会遇到here 概述的问题,其中 matlab 构建创建的目标文件被 octave 构建视为有效,导致 octave 构建失败(八度构建在 matlab 构建之后运行)。
为了解决这个问题,我想从 mex/build/matlab/objects 构建 Matlab .mex 文件和从 mex/build/octave/objects 构建 Octave .mex 文件(或者,更好的是,mex/build/matlab/objects/mex1 ... mex/build/matlab/objects/mexN )。我知道我们通常可以切换到这些目录然后运行../configure,但我不知道如何从root_dir/configure.ac 执行此操作,因为AC_CONFIG_SUBDIRS 仅将子目录作为参数。
【问题讨论】:
标签: makefile build autotools automake autoconf