Autoconf uses wrong AR on OS X
Asked Answered
P

1

6

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
Perfect answered 2/11, 2017 at 11:58 Comment(4)
Are you using AM_PROG_AR in configure.ac?Bruni
I think you will need to specify your preferred options on the configure command line: ./configure AR=/usr/bin/libtool ARFLAGS="-static -o". There's then a chance that you'll override what the script would determine for itself.Stanford
Thanks Jonathan. Running AR=/usr/bin/libtool ARFLAGS='-static -o' ./configure dies early. The message is checking the archiver (/usr/bin/libtool) interface... unknown and then configure: error: could not determine /usr/bin/libtool interface. That's kind of why we've been trying to fix it in the script.Perfect
Still occurs in February 2019 when installing OpenFST on MacOS Mojave. Any solution?Spermicide
T
5

Autotools is selecting the wrong AR and ARFLAGS for the platform. It happens with (and without) AM_PROG_AR in Makefile.am: [...] Autoconf should be using Apple's libtool

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 Mac libtool that mimics the traditional command-line interface of POSIX ar. When configuring for Mac, designate the wrapper script to configure as the value of variable AR.

    ./configure AR=my-mac-libtool-wrapper
    
  • If the build system does not use AM_PROG_AR then by default the AR and ARFLAGS variables will mean nothing to configure, but you can specify them directly to make:

    make AR=/usr/bin/libtool ARFLAGS="-static -o"
    
  • Alternatively, if the build system does not use AM_PROG_AR then you can add your own code to make configure handle the AR and ARFLAGS variables. The minimum to get configure to 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])
    
Thalamencephalon answered 7/11, 2017 at 17:33 Comment(1)
Thanks John. "I understand that you would like configure to select and use OS X libtool..." - I believe its a bit stronger than that. Apple advises it, and the ar(1) utility does not handle fat files. I'll try some of your suggestions. Thanks again.Perfect

© 2022 - 2024 — McMap. All rights reserved.