I'm testing on OS X. We have a configure.ac and Makefile.am. Autotools is selecting the wrong AR and ARFLAGS for the platform. It happens with (and without) AM_PROG_AR in Makefile.am:
$ egrep 'AR =|ARFLAGS =' Makefile
AMTAR = $${TAR-tar}
AR = ar
ac_ct_AR = ar
Autoconf should be using Apple's libtool (not to be confused Autotools' libtool) and libtool's flags. Apple's libtool properly handles fat libraries and cross-compiles. It should be something like:
AR = /usr/bin/libtool
ARFLAGS = -static -o
Apple's Porting UNIX/Linux Applications to OS X does not discuss the topic, and I can't find it searching the Autoconf documentation. The Autoconf docs also lacks a AC_PROG_AR (or similar). See 5.2.1 Particular Program Checks in the Autoconf manual.
How do we tell Autoconf to use Apple's platform build tools, and not the Linux build tools?
$ autoconf --version
autoconf (GNU Autoconf) 2.69
$ automake --version
automake (GNU automake) 1.15.1
Autotools is selecting the wrong
ARandARFLAGSfor the platform. It happens with (and without)AM_PROG_ARinMakefile.am: [...] Autoconf should be using Apple'slibtool
I understand that you would like configure to select and use OS X libtool for creating archives, and that doing so would afford you some advantages. POSIX ar may even be an unsuitable tool for your particular job, but I reject the assertion that /usr/bin/ar is the wrong tool for the platform. Apple provides that tool in OS X, and it works as advertised, even if the advertised behavior is more circumscribed than you want or need.
It should be something like:
AR = /usr/bin/libtool ARFLAGS = -static -o
Maybe. Although Mac libtool can perform the same function as ar, it is not a drop-in replacement. That's what configure complains about when you specify those variables on its command line (but only when you also have AM_PROG_AR). In particular, if you examine the configure script you will probably find that it tests the behavior of the tool designated by AR with use of a command such as this:
$AR cru libconftest.a conftest.$ac_objext >&5
It will also have a fallback for the interface provided by Microsoft's lib utility. Both of these are associated with the AM_PROG_AR macro.
Note that the test uses hardcoded flags for the main options, not any $ARFLAGS that may have been specified. It is specifically testing the program's command-line interface, and Mac libtool does not provide one that is recognized.
You have several options:
Let the build system continue to use
AM_PROG_AR, and provide a wrapper script for Maclibtoolthat mimics the traditional command-line interface of POSIXar. When configuring for Mac, designate the wrapper script toconfigureas the value of variableAR../configure AR=my-mac-libtool-wrapperIf the build system does not use
AM_PROG_ARthen by default theARandARFLAGSvariables will mean nothing toconfigure, but you can specify them directly tomake:make AR=/usr/bin/libtool ARFLAGS="-static -o"Alternatively, if the build system does not use
AM_PROG_ARthen you can add your own code to makeconfigurehandle theARandARFLAGSvariables. The minimum to getconfigureto recognize them and pass them on to the Makefile without performing any actual tests would probably be:AC_ARG_VAR([AR], [Specifies the archiver to use]) AC_ARG_VAR([ARFLAGS], [Specifies the archiver flags to use])
来源:https://stackoverflow.com/questions/47074736/autoconf-uses-wrong-ar-on-os-x