Improve robustness and performance of building Unix static libraries

This is a fixup of 385deae79f26dd685339d3141a06d04d6bd753cd, which solved #12116

Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12821)
