Autotools cross compilation and generated sources

孤街浪徒 提交于 2019-12-02 01:40:39
ldav1s

If you're using AX_PROG_CXX_FOR_BUILD, then the EXEEXT you should be using is BUILD_EXEEXT which is defined in the macro AX_PROG_CC_FOR_BUILD (which AX_PROG_CXX_FOR_BUILD requires). Using EXEEXT for something built by CXX_FOR_BUILD would be an error, since that's the extension for the host toolchain. So in this case you'll need something more like:

configure.ac

#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.68])
AC_INIT([libfoobar], [0.1.0], [<NOBUGS>])
AM_INIT_AUTOMAKE([foreign])
LT_INIT
AC_CANONICAL_BUILD
AC_CANONICAL_HOST

AC_CONFIG_SRCDIR([src/bar.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_FILES([Makefile
                 src/Makefile])

# Checks for programs.
AC_PROG_CXX
AX_PROG_CXX_FOR_BUILD

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_OUTPUT

src/Makefile.am

noinst_PROGRAMS = bar
lib_LTLIBRARIES = libfoo.la

bar_SOURCES = bar.cpp

LINK_FOR_BUILD.cpp = $(CXX_FOR_BUILD) $(CXXFLAGS_FOR_BUILD) $(CPPFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) $(TARGET_ARCH_FOR_BUILD)

bar$(BUILD_EXEEXT) : $(bar_OBJECTS)
            $(LINK_FOR_BUILD.cpp) $^ $(LOADLIBES_FOR_BUILD) $(LDLIBS_FOR_BUILD) -o $@

$(bar_OBJECTS) : CC=$(CC_FOR_BUILD)
$(bar_OBJECTS) : CXXFLAGS=$(CXXFLAGS_FOR_BUILD)
$(bar_OBJECTS) : CPPFLAGS=$(CPPFLAGS_FOR_BUILD)

libfoo_la_SOURCES = foo.cpp
nodist_libfoo_la_SOURCES = foobar.h

BUILT_SOURCES: foobar.h

foobar.h: bar$(BUILD_EXEEXT) Makefile
    ./$< >$@
CLEANFILES = foobar.h

It would help but partially. Autotools still suffix --host's $(EXEEXT) to _PROGRAMS so I couldn't use autotools features anyway during cross-compilation.

I found another solution thou. It is really dirty hack but works. I created autotools sub-project where appropriate sources and being linked and added to my configure.ac something like this at the very bottom of the file:

if [[ "x$cross_compiling" != "xyes" ]]; then
  AC_CONFIG_SUBDIRS(src/tools)
fi

AC_OUTPUT

if [[ "x$cross_compiling" = "xyes" ]]; then
  mkdir -p src/tools
  cd src/tools && ../../"$srcdir"/src/tools/configure --cache-file=/dev/null --host=$build --target=$host
fi

And in Makefile.am I reference binaries in the tools directory directly:

SUBDIRS = tools

foobar.h: tools/gencpu$(BUILD_EXEEXT)
    ./$< >$@

BUILT_SOURCES: foobar.h

CLEANFILES = foobar.h

Unless I find better and more "elegant" solution I'm gonna stick to that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!