Repository: spack/spack

Issue:
Failed to build `zlib %pgi@16` due to `pgcc-Error-Unknown switch: -include`
I tried to build `zlib %pgi@16` in Spack, but failed with the message `pgcc-Error-Unknown switch: -include` . I find nowhere in zlib's package that `-include` flag is introduced.  It works if I build zlib against PGI without spack.

```
$ spack purge; spack clean zlib; spack install zlib %pgi@16
==> Installing zlib
==> Using cached archive: /tmp/rpm/spack_source_cache/zlib/zlib-1.2.11.tar.gz
==> Staging archive: /home/rpm/spack/var/spack/stage/zlib-1.2.11-47ulrkqewycl2ai7ms4phqjunqcalk7w/zlib-1.2.11.tar.gz
==> Created stage in /home/rpm/spack/var/spack/stage/zlib-1.2.11-47ulrkqewycl2ai7ms4phqjunqcalk7w
==> Ran patch() for zlib
==> Building zlib [AutotoolsPackage]
==> Executing phase : 'autoreconf'
==> Executing phase : 'configure'
==> Executing phase : 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j32'
/home/rpm/spack/lib/spack/spack/build_systems/autotools.py:275, in build:
     270      def build(self, spec, prefix):
     271          """Makes the build targets specified by
     272          :py:attr:``~.AutotoolsPackage.build_targets``
     273          """
     274          with working_dir(self.build_directory):
  >> 275              inspect.getmodule(self).make(*self.build_targets)

See build log for details:
  /tmp/rpm/pytest-of-rpm/pytest-4/test_fetch0/tmp/spack-stage/spack-stage-8aqJBR/zlib-1.2.11/spack-build.out

$ less /tmp/rpm/pytest-of-rpm/pytest-4/test_fetch0/tmp/spack-stage/spack-stage-8aqJBR/zlib-1.2.11/spack-build.out
...
/home/rpm/spack/lib/spack/env/pgi/pgcc -fpic -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -include zconf.h -DPIC -c -o objs/gzlib.o /home/rpm/spack/var/spack/stage/zlib-1.2.11
-47ulrkqewycl2ai7ms4phqjunqcalk7w/zlib-1.2.11/gzlib.c
pgcc-Error-Unknown switch: -include
pgcc-Error-Unknown switch: -include
make: *** [crc32.o] Error 1
make: *** Waiting for unfinished jobs....
...
```

However, zlib works well with PGI and no `-include zconf.h` flag is introduce during manual installation.

```
$ cd /tmp
$ tar -xf /home/rpm/spack/var/spack/stage/zlib-1.2.11-47ulrkqewycl2ai7ms4phqjunqcalk7w/zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ module purge; module load pgi
$ ./configure && make
Checking for shared library support...
Building shared library libz.so.1.2.11 with pgcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
pgcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -I. -c -o example.o test/example.c
...
pgcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o minigzip64 minigzip64.o -L. libz.a
```


Discussion:
I am able to reproduce this. It looks like `zlib@1.2.8` works fine with PGI but `zlib@1.2.9:1.2.11` does not. I'll submit a bug report.
Hmm, you're right that it builds fine outside of Spack. If I convert it from `AutotoolsPackage` to `Package` it magically works again. But I can't think of what the difference could be...
Figured it out. `Package` calls `./configure` while `AutotoolsPackage` calls `/absolute/path/to/configure`. If I call `/absolute/path/to/configure` outside of Spack, it crashes with the same error message. Although `zlib` comes with a `configure` script, it doesn't actually use `AutotoolsPackage`. I'll have a PR shortly to fix this.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/zlib/package.py b/var/spack/repos/builtin/packages/zlib/package.py
--- a/var/spack/repos/builtin/packages/zlib/package.py
+++ b/var/spack/repos/builtin/packages/zlib/package.py
@@ -25,13 +25,15 @@
 from spack import *
 
 
-class Zlib(AutotoolsPackage):
+# Although zlib comes with a configure script, it does not use Autotools
+# The AutotoolsPackage causes zlib to fail to build with PGI
+class Zlib(Package):
     """A free, general-purpose, legally unencumbered lossless
        data-compression library."""
 
     homepage = "http://zlib.net"
     # URL must remain http:// so Spack can bootstrap curl
-    url = "http://zlib.net/fossils/zlib-1.2.10.tar.gz"
+    url = "http://zlib.net/fossils/zlib-1.2.11.tar.gz"
 
     version('1.2.11', '1c9f62f0778697a09d36121ead88e08e')
     # Due to the bug fixes, any installations of 1.2.9 or 1.2.10 should be
@@ -47,8 +49,13 @@ def setup_environment(self, spack_env, run_env):
         if '+pic' in self.spec:
             spack_env.set('CFLAGS', self.compiler.pic_flag)
 
-    def configure_args(self):
+    def install(self, spec, prefix):
         config_args = []
-        if '+shared' not in self.spec:
+        if '~shared' in spec:
             config_args.append('--static')
-        return config_args
+        configure('--prefix={0}'.format(prefix), *config_args)
+
+        make()
+        if self.run_tests:
+            make('check')
+        make('install')


Test patch: