Search code examples
c++autotoolsautomake

Instruct Automake to use C++ compiler for *.S files?


We have a C++ project. We need to assemble a *.S file through the compiler. In our GNUmakefile we use:

# ARM asm implementation.
aes-armv4.o : aes-armv4.S
    $(CXX) $(CXXFLAGS) $(AES_FLAGS) -mfloat-abi=$(FP_ABI) -c $<

We have the following in our Makefile.am, which depends on AC_SUBST([AES_FLAGS], [-march=armv7-a -Wa,--noexecstack]) in configure.ac:

libaes_armv4_la_SOURCES = aes-armv4.S
libaes_armv4_la_CXXFLAGS = $(AM_CXXFLAGS) $(AES_FLAGS)

However, the resulting Makefile uses the C compiler and fails to use the flags we setup for the source file:

make[1]: Entering directory '/home/build/cryptopp'
/bin/bash ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -g -O2 -MT aes-armv4.lo -MD -MP -MF .deps/aes-armv4.Tpo -c -o aes-armv4.lo aes-armv4.S
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O2 -MT aes-armv4.lo -MD -MP -MF .deps/aes-armv4.Tpo -c aes-armv4.S -fPIC -DPIC -o .libs/aes-armv4.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -g -O2 -MT aes-armv4.lo -MD -MP -MF .deps/aes-armv4.Tpo -c aes-armv4.S -o aes-armv4.o >/dev/null 2>&1
mv -f .deps/aes-armv4.Tpo .deps/aes-armv4.Plo

AES_FLAGS provides -march=armv7-a -Wa,--noexecstack. -march=armv7-a increases performance due to unaligned loads and -Wa,--noexecstack is a security requirement.

The manual does not state how to tell Autotools to use the C++ compiler in this instance. Also see 8.9 C++ Support.

How do I tell Automake to use the C++ compiler and flags for the source file?


Our configure.ac has the following. It lacks a reference to the C compiler and never touches AC_PROG_CC, CFLAGS or AM_CFLAGS because we are a C++ project:

AC_PROG_CXX
AC_LANG([C++])

...
AC_SUBST([AES_FLAGS], [-march=armv7-a -Wa,--noexecstack])

Solution

  • automake uses the CCAS macro to specify which compiler to run, using CCASFLAGS and AM_CCASFLAGS to specify any custom compilation options.

    More information