From 2f66319a3a973e7cc4d8f124746d41d2d8b37c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Thu, 19 Jun 2014 13:13:06 +0200 Subject: [PATCH] make: OSX: don't fail for empty .a archives Fixes issue #1333. --- .gitattributes | 1 + Makefile.include | 5 +++++ dist/ar-wrapper | 20 ++++++++++++++++++++ dist/empty.a | Bin 0 -> 8 bytes 4 files changed, 26 insertions(+) create mode 100644 .gitattributes create mode 100755 dist/ar-wrapper create mode 100644 dist/empty.a diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..c9839d64f4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.a binary diff --git a/Makefile.include b/Makefile.include index 4a60d6f502..78285a6ed8 100644 --- a/Makefile.include +++ b/Makefile.include @@ -54,6 +54,11 @@ include $(RIOTBOARD)/$(BOARD)/Makefile.include include $(RIOTCPU)/$(CPU)/Makefile.include include $(RIOTBASE)/Makefile.dep +# OSX fails to create empty archives. Provide a wrapper to catch that error. +ifneq (0, $(shell mkdir -p $(BINDIR); $(AR) -rc $(BINDIR)empty-archive.a 2> /dev/null; echo $$?)) + AR := $(RIOTBASE)/dist/ar-wrapper $(AR) +endif + # Test if there where dependencies against a module in DISABLE_MODULE. ifneq (, $(filter $(DISABLE_MODULE), $(USEMODULE))) $(error "Required modules were disabled using DISABLE_MODULE: $(sort $(filter $(DISABLE_MODULE), $(USEMODULE)))") diff --git a/dist/ar-wrapper b/dist/ar-wrapper new file mode 100755 index 0000000000..a3d17d74c4 --- /dev/null +++ b/dist/ar-wrapper @@ -0,0 +1,20 @@ +#!/bin/sh + +# This wrapper takes the arguments: +# can be any ar implementation. +# , and are the normal arguments to . +# +# OS X's ar implementation has the problem, that it refuses to create empty archives. +# This wrapper will copy a provided empty .a file to if it was told to. + +# If contains "r", and there are no given. +if [ "${2#*r}" != "$2" ] && [ "$#" -eq 3 ]; then + # If exists, do nothing, otherwise copy an empty archive. + [ -e "$3" ] || cp "${0%ar-wrapper}/empty.a" "$3" +else + # Otherwise act like this wrapper was not present. + "$@" +fi + +# Return the exit code of the last invocation ("[", "cp", or ). +exit $? diff --git a/dist/empty.a b/dist/empty.a new file mode 100644 index 0000000000000000000000000000000000000000..8b277f0dd5dcdcb9c4b6c0b7a32153664f111266 GIT binary patch literal 8 PcmY$iNi0gvu;T&%3Vs4a literal 0 HcmV?d00001