macos - How to determine where 'ar' is being called in Makefile?


Keywords:macos 


Question: 

I'm trying to build Git on OS X. Git depends on libidn2. libidn2 2.0.0 fails:

make  all-am
make[3]: Entering directory '/Users/jwalton/Build-Scripts/libidn2-2.0.0/lib'
  CC       idna.lo
  CC       lookup.lo
  CC       decode.lo
  CC       register.lo
  CC       bidi.lo
  CC       version.lo
  CC       error.lo
  CC       punycode.lo
  CC       free.lo
  CC       data.lo
  CC       tr46map.lo
  CC       tables.lo
  CC       context.lo
  CCLD     libidn2.la
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
copying selected object files to avoid basename conflicts...
ar: temporary file: No such file or directory
Makefile:1027: recipe for target 'libidn2.la' failed
make[3]: *** [libidn2.la] Error 1
make[3]: Leaving directory '/Users/jwalton/Build-Scripts/libidn2-2.0.0/lib'
Makefile:955: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/Users/jwalton/Build-Scripts/libidn2-2.0.0/lib'
Makefile:1065: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/Users/jwalton/Build-Scripts/libidn2-2.0.0'
Makefile:974: recipe for target 'all' failed
make: *** [all] Error 2

My recipe to build libidn2 finds all Makefiles and it fixes AR and ARFLAGS:

if [[ "$IS_DARWIN" -ne "0" ]]; then
    for mfile in $(find "$PWD" -name 'Makefile'); do
        echo "Fixing Makefile $mfile"
        sed -i "" 's|AR = ar|AR = /usr/bin/libtool|g' "$mfile"
        sed -i "" 's|ARFLAGS = cr|ARFLAGS = -static -o|g' "$mfile"
    done
fi

I've confirmed it fixes all the Makefiles:

$ find $PWD -name Makefile -exec grep 'AR =' {} \; | egrep -iv 'amtar|char'
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool
AR = /usr/bin/libtool
ac_ct_AR = /usr/bin/libtool

I also tried AR="/usr/bin/libtool" ARFLAGS="-static -o" ./configure and make AR="/usr/bin/libtool" ARFLAGS="-static -o", but the choices are not honored. It produces additional failed builds.

Makefile debugging support is fairly crappy, so I'm not sure how to proceed. make -d fails even the simplest tasks, like providing a filename and line number. remake -d produces the same unhelpful results. The large project written by someone else aggravates the situation.

$ make -d
...
Putting child 0x7f9bf0c45cf0 (libidn2.la) PID 75531 on the chain.
Live child 0x7f9bf0c45cf0 (libidn2.la) PID 75531
  CCLD     libidn2.la
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
copying selected object files to avoid basename conflicts...
ar: temporary file: No such file or directory
Reaping losing child 0x7f9bf0c45cf0 PID 75531
Makefile:1027: recipe for target 'libidn2.la' failed

Here's line 1027, which is not the call to ar:

libidn2.la: $(libidn2_la_OBJECTS) $(libidn2_la_DEPENDENCIES) $(EXTRA_libidn2_la\
_DEPENDENCIES)
        $(AM_V_CCLD)$(libidn2_la_LINK) -rpath $(libdir) $(libidn2_la_OBJECTS) $\
(libidn2_la_LIBADD) $(LIBS)

How can I locate where ar is being called in the collection of Makefiles?


1 Answer: 

To a simple understanding of a failing recipe you can:

  1. echo the rule (i.e. echo $(AM_V_CCLD)$(libidn2_la_LINK) ...)
  2. add a second command which fails to stop the make

If you need additional help please reports here the make output after these changes.

In your case the use of makefile option --debug=m can help