Repository: spack/spack

Issue:
Installation issue: minizip
minizip does not link to static ./../../libz.a.
I do not fully understand the logic, so I cannot correct it.
```console
$ spack spec minizip
Input spec
--------------------------------
minizip

Concretized
--------------------------------
==> Warning: gcc@7.5.0 cannot build optimized binaries for "zen2". Using best target possible: "zen"
minizip@1.2.11%gcc@7.5.0 patches=7f8df109299dd8e9dc01d6ebe8e95c6ffb41cabc592a5746a0d05c7faade0450,be83617463cefc747d14858eb70f13f0ccccbbeee14191ea3c874c78bd570243 arch=linux-ubuntu18.04-zen
    ^autoconf@2.69%gcc@7.5.0 arch=linux-ubuntu18.04-zen
        ^m4@1.4.18%gcc@7.5.0+sigsegv patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 arch=linux-ubuntu18.04-zen
            ^libsigsegv@2.12%gcc@7.5.0 arch=linux-ubuntu18.04-zen
        ^perl@5.32.1%gcc@7.5.0+cpanm+shared+threads arch=linux-ubuntu18.04-zen
            ^berkeley-db@18.1.40%gcc@7.5.0 arch=linux-ubuntu18.04-zen
            ^gdbm@1.18.1%gcc@7.5.0 arch=linux-ubuntu18.04-zen
                ^readline@8.0%gcc@7.5.0 arch=linux-ubuntu18.04-zen
                    ^ncurses@6.2%gcc@7.5.0~symlinks+termlib arch=linux-ubuntu18.04-zen
                        ^pkgconf@1.7.3%gcc@7.5.0 arch=linux-ubuntu18.04-zen
    ^automake@1.16.3%gcc@7.5.0 arch=linux-ubuntu18.04-zen
    ^libtool@2.4.6%gcc@7.5.0 arch=linux-ubuntu18.04-zen
    ^zlib@1.2.11%gcc@7.5.0+optimize+pic+shared arch=linux-ubuntu18.04-zen

$ spack install minizip
==> Warning: gcc@7.5.0 cannot build optimized binaries for "zen2". Using best target possible: "zen"
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/libsigsegv-2.12-l4tbfmivrfs5zuul6ldtmtuu67nzs6sd
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/berkeley-db-18.1.40-sadpffsvdw4oet2g6akzvchxofsz3u52
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/pkgconf-1.7.3-gkazwxam46qsvgcimw3dg7q56ug725w3
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/zlib-1.2.11-egwcgg2m23u6kiqdrywuxn5tansov3pp
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/m4-1.4.18-i63xbkmc3xwkmz5efawvos4gtby3incc
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/ncurses-6.2-emhiiqvj3auacuw6pebxdpxckml47zed
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/libtool-2.4.6-lkpafhzoslainb6ivsjm64d4voctnrjz
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/readline-8.0-4vxgclcoev7s22lxj3rx5xx3m6w3iffh
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/gdbm-1.18.1-35ah4rucwu7rcliu7dsaovavha36sg2p
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/perl-5.32.1-hsbuwsoplwg5p75t3bayfvuhjachvt75
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/autoconf-2.69-2cb3n4p5gxpgnitmkfuanhr2kqz2sb55
[+] /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/automake-1.16.3-wapg7rl6vmirb2ym5oxnmsl2bvty5qof
==> Installing minizip-1.2.11-hivf2d5bgkl4dakzs7zn3iyrcwloddgg
==> No binary for minizip-1.2.11-hivf2d5bgkl4dakzs7zn3iyrcwloddgg found: installing from source
==> Using cached archive: /home/cessenat/Softs/spack/var/spack/cache/_source-cache/archive/c3/c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1.tar.gz
==> minizip: Executing phase: 'autoreconf'
==> minizip: Executing phase: 'configure'
==> minizip: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j2'

3 errors found in build log:
     205    /bin/bash ./libtool  --tag=CC   --mode=link /home/cessenat/Softs/spack/lib/spack/env/gcc/gcc  -g -O2 ./../../libz.a -version-info 1:0:0  -o l
            ibminizip.la -rpath /home/cessenat/Softs/spack/opt/spack/linux-ubuntu18.04-zen/gcc-7.5.0/minizip-1.2.11-hivf2d5bgkl4dakzs7zn3iyrcwloddgg/lib 
            ioapi.lo mztools.lo unzip.lo zip.lo
     206    
     207    *** Warning: Linking the shared library libminizip.la against the
     208    *** static library ./../../libz.a is not portable!
     209    libtool: link: /home/cessenat/Softs/spack/lib/spack/env/gcc/gcc -shared  -fPIC -DPIC  .libs/ioapi.o .libs/mztools.o .libs/unzip.o .libs/zip.o
               ./../../libz.a  -g -O2   -Wl,-soname -Wl,libminizip.so.1 -o .libs/libminizip.so.1.0.0
     210    /usr/bin/ld: ./../../libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recom
            pile with -fPIC
  >> 211    /usr/bin/ld: final link failed: Bad value
  >> 212    collect2: error: ld returned 1 exit status
     213    Makefile:525: recipe for target 'libminizip.la' failed
  >> 214    make: *** [libminizip.la] Error 1

See build log for details:
  /tmp/cessenat/spack-stage/spack-stage-minizip-1.2.11-hivf2d5bgkl4dakzs7zn3iyrcwloddgg/spack-build-out.txt
```
$ spack debug report
* **Spack:** 0.16.0-1079-af988fc32d
* **Python:** 3.8.7
* **Platform:** linux-ubuntu18.04-zen2
* **Concretizer:** original

* [spack-build-out.txt](https://github.com/spack/spack/files/6034601/spack-build-out.txt)
* [spack-build-env.txt](
[spack-build-env.txt](https://github.com/spack/spack/files/6034606/spack-build-env.txt)
)


<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [x] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [x] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [x] I have uploaded the build log and environment files
- [x] I have searched the issues of this repo and believe this is not a duplicate



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/minizip/package.py b/var/spack/repos/builtin/packages/minizip/package.py
--- a/var/spack/repos/builtin/packages/minizip/package.py
+++ b/var/spack/repos/builtin/packages/minizip/package.py
@@ -24,10 +24,11 @@ class Minizip(AutotoolsPackage):
 
     # error: implicit declaration of function 'mkdir' is invalid in C99
     patch('implicit.patch', when='%apple-clang@12:')
+    patch('implicit.patch', when='%gcc@7.3.0:')
 
     # statically link to libz.a
     # https://github.com/Homebrew/homebrew-core/blob/master/Formula/minizip.rb
-    patch('static.patch')
+    patch('static.patch', when='%apple-clang@12:')
 
     # build minizip and miniunz
     @run_before('autoreconf')


Test patch: