Use libtool instead of ar to create static libraries on Darwin.
PATCH 1/1 Use libtool instead of ar to create static libraries on Darwin.
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.html
In any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)
rules.mak +4 -0
@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^)) %.a: +ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@") +else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Signature · 1 line
2.6.4 (Apple Git-63)
rules.mak modules: · line 112
Quoted 7 lines · Christopher Friedt
%.a:
rules.mak +4
-0+ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@") +else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif
Does it work to use libtool -static everywhere?
r~
Quoted 13 lines · Richard Henderson
Quoted 10 lines · Christopher Friedt
%.a:
(quoted diff) +2
-0+ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"libtool $(TARGET_DIR)$@")
+else$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR$(TARGET_DIR)$@")
+endifDoes it work to use libtool -static everywhere?
That *would* be nice... yeah, it would be nice if Apple's tools could work the same as *all* of the other unices out there. Unfortunately, that's not the case, since at least GNU libtool does *not* accept the "-static" argument.
To be honest, if it weren't for the man page for libtool on Mac OS X
[1] dating all the way back to Snow Leopard saying that libtool is the preferred tool on Mac for creating static archives, I'm left wondering if this is just a massive oversight / bug in Apple's ld64.
Quoted 4 lines · Christopher Friedt
To be honest, if it weren't for the man page for libtool on Mac OS X
[1] dating all the way back to Snow Leopard saying that libtool is the preferred tool on Mac for creating static archives, I'm left wondering if this is just a massive oversight / bug in Apple's ld64.
I think it's definitely a bug -- if "ar" and "ld" don't work together Apple should remove "ar", not just unhelpfully break it. We probably need to work around the bug anyway though.
thanks
-- PMM
Quoted 4 lines · Christopher Friedt
Quoted 2 lines · Richard Henderson
Quoted 1 line · Christopher Friedt
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
%.a:
(quoted diff) +2
-0+ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"libtool $(TARGET_DIR)$@")
+else$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR$(TARGET_DIR)$@")
+endifDoes it work to use libtool -static everywhere?
One possibility for future-proofing the link stage that applies to most (all?) platforms that Qemu runs on would be to switch to libtool for all arch's and just adjust the "libtool flags" as necessary.
Would require checking for libtool.
Fallback to ar?
©
Sent from my Android
Quoted 18 lines · Christopher Friedt
Quoted 4 lines · Christopher Friedt
Quoted 2 lines · Richard Henderson
Quoted 1 line · Christopher Friedt
Quoted 11 lines
Quoted 11 lines
Quoted 9 lines
%.a:
(quoted diff) +2
-0+ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^,"libtool $(TARGET_DIR)$@")
+else$(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR$(TARGET_DIR)$@")
+endifDoes it work to use libtool -static everywhere?
Quoted 5 lines
One possibility for future-proofing the link stage that applies to most (all?) platforms that Qemu runs on would be to switch to libtool for all arch's and just adjust the "libtool flags" as necessary.
Would require checking for libtool.
This is more complicated than we need. OSX "libtool" and GNU "libtool" are really completely different things. We don't (these days) do anything that we need GNU libtool for, so there's no need to depend on it or use it optionally -- we should just use "ar". If we need to special case the "program for creating static libraries" for OSX that's annoying but we can do that.
thanks
-- PMM
Quoted 21 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.htmlIn any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
Signed-off-by Christopher Friedt <[email protected]>--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)rules.mak +0
-0
rules.mak modules: · line 114
Quoted 10 lines
rules.mak +4
-0@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^)) %.a: +ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@") +else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Hmm. Is this patch still relevant? Apparently I missed it back then.
Thanks,
/mjt
Quoted 38 lines · Michael Tokarev
Quoted 37 lines · Christopher Friedt
Currently, at least on Mac OS X 10.11.4 (El Capitan), Qemu fails to build for a few reasons.
One of those reasons is that Apple's ld (at least ld64) does not properly process archive files created with ar (even Apple's ar).
After some RTFM'ing, I came upon this tidbit, which is unfortunate. Luckily, autotools packages are not broken.
"Libtool with -static is intended to replace ar(5) and ranlib."
http://www.manpages.info/macosx/libtool.1.htmlIn any case, this change takes Apple's recommendations into account and allows Qemu to build on Mac OS X El Capitan.
Signed-off-by Christopher Friedt <[email protected]>--- rules.mak | 4 ++++ 1 file changed, 4 insertions(+)rules.mak +4
-0@@ -105,7 +105,11 @@ modules: $(call LINK,$(filter %.o %.a %.mo, $^)) %.a: +ifdef CONFIG_DARWIN + $(call quiet-command,rm -f $@ && libtool -static -o $@ $^," libtool $(TARGET_DIR)$@") +else $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR $(TARGET_DIR)$@") +endif
Quoted 4 lines
Quoted 1 line
quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))
Hmm. Is this patch still relevant? Apparently I missed it back then.
I don't have El Capitan, but I can confirm that it doesn't break the build on Yosemite, so I guess we should have it.
I'd like to know the error message the linker produces first, though (and we should put that in the commit message).
The progress string argument to quiet-command is slightly wrong:
we capitalize the shortname of the command being run, so it ought to look like " LIBTOOL $(TARGET_DIR)$@" so it lines up and looks nice with the other output.
thanks
-- PMM