Repository: spack/spack

Issue:
gdbm build fails on Centos-5
Summary
gdbm build fails
### Expected Result
package builds
### Actual Result
```console
spack install gdbm
==> pkgconf is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/pkgconf-1.4.0-prcnvashlbumdqefezhzvct2jtwfcu2t
==> ncurses is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/ncurses-6.0-sjah6z6zvp5xbfoqfxuattnlryguskyl
==> readline is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/readline-7.0-yy33lokgwcdqxjqouywgogfsnysm55iw
==> Installing gdbm
==> Warning: Suspicious requests to set or unset 'CC' found
==> Warning: 	    	env.set('CC', join_path(link_dir, compiler.link_paths['cc'])) at /g/software/spack/lib/spack/spack/build_environment.py:146
==> Warning: 	--->	spack_env.set('CC', spack_cc) at /g/software/spack/var/spack/repos/builtin/packages/gdbm/package.py:49
==> Using cached archive: /g/software/spack/var/spack/cache/gdbm/gdbm-1.14.1.tar.gz
==> Staging archive: /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf/gdbm-1.14.1.tar.gz
==> Created stage in /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf
==> No patches needed for gdbm
==> Building gdbm [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j24'

9 errors found in build log:
     200      CC       gdbmstore.lo
     201      CC       gdbmsync.lo
     202      CC       base64.lo
     203      CC       bucket.lo
     204      CC       falloc.lo
     205      CC       findkey.lo
  >> 206    gdbmopen.c:35: error: expected declaration specifiers or '...' before 'blksize_t'
     207    gdbmopen.c: In function 'compute_directory_size':
  >> 208    gdbmopen.c:42: error: 'block_size' undeclared (first use in this function)
  >> 209    gdbmopen.c:42: error: (Each undeclared identifier is reported only once
  >> 210    gdbmopen.c:42: error: for each function it appears in.)
     211    gdbmopen.c: In function 'gdbm_fd_open':
     212    gdbmopen.c:197: warning: passing argument 2 of 'compute_directory_size' makes pointer from integer without a cast
     213    gdbmopen.c:35: note: expected 'int *' but argument is of type 'int'
  >> 214    gdbmopen.c:197: error: too many arguments to function 'compute_directory_size'
  >> 215    make[3]: *** [gdbmopen.lo] Error 1
     216    make[3]: *** Waiting for unfinished jobs....
     217    make[3]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1/src'
  >> 218    make[2]: *** [all] Error 2
     219    make[2]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1/src'
  >> 220    make[1]: *** [all-recursive] Error 1
     221    make[1]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1'
  >> 222    make: *** [all] Error 2

See build log for details:
  /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf/gdbm-1.14.1/spack-build.out
```
### Steps to reproduce the issue

```console
$ spack install -j1 gdbm
```

### Information on your system
- Centos-5
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

[spack-build.out.gdbm.txt](https://github.com/spack/spack/files/1886788/spack-build.out.gdbm.txt)

gdbm build fails on Centos-5
Summary
gdbm build fails
### Expected Result
package builds
### Actual Result
```console
spack install gdbm
==> pkgconf is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/pkgconf-1.4.0-prcnvashlbumdqefezhzvct2jtwfcu2t
==> ncurses is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/ncurses-6.0-sjah6z6zvp5xbfoqfxuattnlryguskyl
==> readline is already installed in /g/software/spack/opt/spack/linux-centos5-x86_64/gcc-4.4.4/readline-7.0-yy33lokgwcdqxjqouywgogfsnysm55iw
==> Installing gdbm
==> Warning: Suspicious requests to set or unset 'CC' found
==> Warning: 	    	env.set('CC', join_path(link_dir, compiler.link_paths['cc'])) at /g/software/spack/lib/spack/spack/build_environment.py:146
==> Warning: 	--->	spack_env.set('CC', spack_cc) at /g/software/spack/var/spack/repos/builtin/packages/gdbm/package.py:49
==> Using cached archive: /g/software/spack/var/spack/cache/gdbm/gdbm-1.14.1.tar.gz
==> Staging archive: /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf/gdbm-1.14.1.tar.gz
==> Created stage in /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf
==> No patches needed for gdbm
==> Building gdbm [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j24'

9 errors found in build log:
     200      CC       gdbmstore.lo
     201      CC       gdbmsync.lo
     202      CC       base64.lo
     203      CC       bucket.lo
     204      CC       falloc.lo
     205      CC       findkey.lo
  >> 206    gdbmopen.c:35: error: expected declaration specifiers or '...' before 'blksize_t'
     207    gdbmopen.c: In function 'compute_directory_size':
  >> 208    gdbmopen.c:42: error: 'block_size' undeclared (first use in this function)
  >> 209    gdbmopen.c:42: error: (Each undeclared identifier is reported only once
  >> 210    gdbmopen.c:42: error: for each function it appears in.)
     211    gdbmopen.c: In function 'gdbm_fd_open':
     212    gdbmopen.c:197: warning: passing argument 2 of 'compute_directory_size' makes pointer from integer without a cast
     213    gdbmopen.c:35: note: expected 'int *' but argument is of type 'int'
  >> 214    gdbmopen.c:197: error: too many arguments to function 'compute_directory_size'
  >> 215    make[3]: *** [gdbmopen.lo] Error 1
     216    make[3]: *** Waiting for unfinished jobs....
     217    make[3]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1/src'
  >> 218    make[2]: *** [all] Error 2
     219    make[2]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1/src'
  >> 220    make[1]: *** [all-recursive] Error 1
     221    make[1]: Leaving directory `/tmp/userx/spack-stage/spack-stage-gNQPxF/gdbm-1.14.1'
  >> 222    make: *** [all] Error 2

See build log for details:
  /g/software/spack/var/spack/stage/gdbm-1.14.1-xqgw3zjzq4zwgd7ewylemm23edukrbaf/gdbm-1.14.1/spack-build.out
```
### Steps to reproduce the issue

```console
$ spack install -j1 gdbm
```

### Information on your system
- Centos-5
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

[spack-build.out.gdbm.txt](https://github.com/spack/spack/files/1886788/spack-build.out.gdbm.txt)



Discussion:
It is a shame gdbm is not compiling as so many core packages depend on it! :(
Using gcc-5.1.0 yields similar errors:
```console
==> Installing gdbm
==> Warning: Suspicious requests to set or unset 'CC' found
==> Warning: 	    	env.set('CC', join_path(link_dir, compiler.link_paths['cc'])) at /g/software/spack/lib/spack/spack/build_environment.py:146
==> Warning: 	--->	spack_env.set('CC', spack_cc) at /g/software/spack/var/spack/repos/builtin/packages/gdbm/package.py:49
==> Using cached archive: /g/software/spack/var/spack/cache/gdbm/gdbm-1.14.1.tar.gz
==> Staging archive: /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk/gdbm-1.14.1.tar.gz
==> Created stage in /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk
==> No patches needed for gdbm
==> Building gdbm [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j20'

1 error found in build log:
     197      CC       gdbmseq.lo
     198      CC       gdbmreorg.lo
     199      CC       gdbmsetopt.lo
     200      CC       gdbmstore.lo
     201      CC       gdbmsync.lo
     202      CC       base64.lo
  >> 203    gdbmopen.c:35:40: error: unknown type name 'blksize_t'
     204     compute_directory_size (GDBM_FILE dbf, blksize_t block_size,
     205                                            ^
     206    gdbmopen.c: In function 'gdbm_fd_open':
     207    gdbmopen.c:197:7: warning: implicit declaration of function 'compute_directory_size' [-Wimplicit-function-declaration]
     208           compute_directory_size (dbf, block_size, &dir_size, &dir_bits);
     209           ^

See build log for details:
  /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk/gdbm-1.14.1/spack-build.out
```
just in case installed & loaded newer gmake via spack, but errors persist
with gcc-5.4.1, **the build of following versions work**: 1.9 to 1.12 inclusive!
I'm not surprised you ran into problems on CentOS 5, I've generally struggled to get new software to build on old platforms. One thing you can try is to install `binutils` with Spack and add it to the front of your `PATH`. This helped me get around a lot of issues I faced.
Good to know. I will give it a try very soon. I am wondering if there is a simple way to make Spack as minimally reliant on the system as possible.
You might be interested in #5545.
It is a shame gdbm is not compiling as so many core packages depend on it! :(
Using gcc-5.1.0 yields similar errors:
```console
==> Installing gdbm
==> Warning: Suspicious requests to set or unset 'CC' found
==> Warning: 	    	env.set('CC', join_path(link_dir, compiler.link_paths['cc'])) at /g/software/spack/lib/spack/spack/build_environment.py:146
==> Warning: 	--->	spack_env.set('CC', spack_cc) at /g/software/spack/var/spack/repos/builtin/packages/gdbm/package.py:49
==> Using cached archive: /g/software/spack/var/spack/cache/gdbm/gdbm-1.14.1.tar.gz
==> Staging archive: /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk/gdbm-1.14.1.tar.gz
==> Created stage in /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk
==> No patches needed for gdbm
==> Building gdbm [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j20'

1 error found in build log:
     197      CC       gdbmseq.lo
     198      CC       gdbmreorg.lo
     199      CC       gdbmsetopt.lo
     200      CC       gdbmstore.lo
     201      CC       gdbmsync.lo
     202      CC       base64.lo
  >> 203    gdbmopen.c:35:40: error: unknown type name 'blksize_t'
     204     compute_directory_size (GDBM_FILE dbf, blksize_t block_size,
     205                                            ^
     206    gdbmopen.c: In function 'gdbm_fd_open':
     207    gdbmopen.c:197:7: warning: implicit declaration of function 'compute_directory_size' [-Wimplicit-function-declaration]
     208           compute_directory_size (dbf, block_size, &dir_size, &dir_bits);
     209           ^

See build log for details:
  /g/software/spack/var/spack/stage/gdbm-1.14.1-du4is57tqgminzfgxob4h22yalhf6gyk/gdbm-1.14.1/spack-build.out
```
just in case installed & loaded newer gmake via spack, but errors persist
with gcc-5.4.1, **the build of following versions work**: 1.9 to 1.12 inclusive!
I'm not surprised you ran into problems on CentOS 5, I've generally struggled to get new software to build on old platforms. One thing you can try is to install `binutils` with Spack and add it to the front of your `PATH`. This helped me get around a lot of issues I faced.
Good to know. I will give it a try very soon. I am wondering if there is a simple way to make Spack as minimally reliant on the system as possible.
You might be interested in #5545.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gdbm/package.py b/var/spack/repos/builtin/packages/gdbm/package.py
--- a/var/spack/repos/builtin/packages/gdbm/package.py
+++ b/var/spack/repos/builtin/packages/gdbm/package.py
@@ -46,4 +46,12 @@ class Gdbm(AutotoolsPackage):
     depends_on("readline")
 
     def configure_args(self):
-        return ['--enable-libgdbm-compat']
+
+        # GDBM uses some non-standard GNU extensions,
+        # enabled with -D_GNU_SOURCE.  See:
+        #   https://patchwork.ozlabs.org/patch/771300/
+        #   https://stackoverflow.com/questions/5582211
+        #   https://www.gnu.org/software/automake/manual/html_node/Flag-Variables-Ordering.html
+        return [
+            '--enable-libgdbm-compat',
+            'CPPFLAGS=-D_GNU_SOURCE']


Test patch: