Using Autotools for a platform-specific source code project

I am developing a project that is currently written in C, but I plan to write some functions in ASM for at least two platforms (x86_64 and arm). So I can have some source files:

  • general /one.c
  • shared /two.c
  • generic /three.c
  • hand /one.s
  • x86_64 / two.s

I would like the configuration script to select.s files over .c files whenever possible. Thus, building on hand will be one.s, two.c, three.c, etc.

It seems difficult or impossible to do it nicely with Automake. But if I give up Automake, I will have to keep track of my own dependencies (fie).

What is the best way to do this?

+6
source share
3 answers

automake . AC_CANONICAL_HOST configure.ac, $host.

automake , . , , - (, subdir-objects AM_INIT_AUTOMAKE:

# Note the $() isn't a shell command substitution.
# The quoting means it'll be expanded by `make'.
MODULE_ONE_OBJ='generic/one.$(OBJEXT)'
MODULE_TWO_OBJ='generic/two.$(OBJEXT)'
case $host in
  # ...
  arm*)
    MODULE_ONE='arm/one.$(OBJEXT)'
    ;;
  x86_64)
    MODULE_TWO='x86/two.$(OBJEXT)'
    ;;
esac
AC_SUBST([MODULE_ONE])
AC_SUBST([MODULE_TWO])

Makefile.am:

bin_PROGRAMS = foo
foo_SOURCES = foo.c
EXTRA_foo_SOURCES = arm/one.s x86/two.c
foo_LDADD = $(MODULE_ONE) $(MODULE_TWO)
foo_DEPENDENCIES = $(MODULE_ONE) $(MODULE_TWO)
+2

.

configure.ac

...
AC_CANONICAL_SYSTEM
AM_PROG_AS
AC_PROG_CC
...
PROC=""
AS_CASE([$host_cpu], [x86_64], [PROC="x86_64"], [arm*], [PROC="arm"])

AM_CONDITIONAL([CPU_X86_64], [test "$PROC" = "x86_64"])
AM_CONDITIONAL([CPU_ARM], [test "$PROC" = "arm"])
AM_CONDITIONAL([CPU_UNDEFINED], [test "x$PROC" = "x"])

Makefile.am

lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = \
$(top_srcdir)/generic/three.c

if CPU_ARM
libfoo_la_SOURCES += $(top_srcdir)/arm/one.s \
$(top_srcdir)/generic/two.c
endif

if CPU_X86_64
libfoo_la_SOURCES += $(top_srcdir)/generic/one.c \
$(top_srcdir)/x86_64/two.s
endif

if CPU_UNDEFINED
libfoo_la_SOURCES += $(top_srcdir)/generic/one.c \
$(top_srcdir)/generic/two.c
endif
+3

AC_CANONICAL_HOST, . , configure.ac:

AC_CANONICAL_HOST
AC_SUBST([USE_DIR],[$host_cpu])
test -d $srcdir/$USE_DIR || USE_DIR=generic

Makefile.am:

SUBDIRS = $(USE_DIR) common

common/Makefile.am:

LDADD = ../$(USE_DIR)/libfoo.a

${host_cpu}/Makefile.am:

noinst_LIBRARIES = libfoo.a
libfoo_a_SOURCES = one.s ../common/two.c

This uses a slightly different directory structure than what you describe. C files that are used on all platforms will be located in commonand associated with the convenience library created in the platform’s specific directory. If some c files are used only on some platforms, you can use them in general terms and refer to them explicitly in Makefile.am for those platforms that need them.

+2
source

All Articles