I'm trying to create a library using autotools (autoconf, automake, libtool) as a build system. The library has to be cross-compileable, but one of the steps of building it is to generate sources by executable built from sources during the whole process.
The problem is I cannot use automake's system to build the intermediate binary because when it's cross compile it wouldn't run on '--build' to generate sources.
One way to work this around it to create separate autools project to build intermediate binaries but I want to avoid it because there are many headers and other "data" files common for intermediate executable and final library so I want to keep it in one place, besides those intermediate binaries should be "noinst".
Is there any other way to make it work properly and retain portability? I was trying to use ax_prog_cxx_for_build but I couldn't find --build's EXEEXT when cross compiling.
Here's an example of the issue just to illustrate my problem:
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_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
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_OUTPUT
Makefile.am
ACLOCAL_AMFLAGS = -I m4
SUBDIRS = src
src/Makefile.am
bin_PROGRAMS = bar
lib_LTLIBRARIES = libfoo.la
noinst_bar_SOURCES = bar.cpp
libfoo_la_SOURCES = foo.cpp
nodist_libfoo_la_SOURCES = foobar.h
BUILT_SOURCES: foobar.h
foobar.h: bar$(EXEEXT) Makefile
./$< >$@
CLEANFILES = foobar.h
src/foo.cpp
#include "foobar.h"
extern "C" int foo() {
return foobar_value;
}
src/bar.cpp
#include <iostream>
int main() {
std::cout << "#ifndef FOOBAR_H" << std::endl;
std::cout << "#define FOOBAR_H" << std::endl;
std::cout << std::endl;
std::cout << "static const int foobar_value = 0xdeadbeef;" << std::endl;
std::cout << std::endl;
std::cout << "#endif" << std::endl;
}
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:
And in Makefile.am I reference binaries in the tools directory directly:
Unless I find better and more "elegant" solution I'm gonna stick to that.
If you're using
AX_PROG_CXX_FOR_BUILD
, then theEXEEXT
you should be using isBUILD_EXEEXT
which is defined in the macroAX_PROG_CC_FOR_BUILD
(whichAX_PROG_CXX_FOR_BUILD
requires). UsingEXEEXT
for something built byCXX_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
src/Makefile.am