Repository: spack/spack

Issue:
Installation issue: gcc in OpenSuse: spack install `lib64` folders but includes `lib`
```console
spack install gcc@4.9.4
...
==> Error: ProcessError: Command exited with status 2:
    'make' '-j4'
....
  >> 7730    /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmpc
  >> 7731    /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmpfr
  >> 7732    collect2: error: ld returned 1 exit status
     7733    /home/alexis/spack/var/spack/stage/gcc-4.9.4-owyxvylenevrjvs2uue7pmqrfvi5rohl/gcc-4.9.4/gcc/lto/Make-lang.in:71: recipe for target 'lto1' failed
  >> 7734    make[3]: *** [lto1] Error 1
     7735    make[3]: *** Waiting for unfinished jobs....
  >> 7736    /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmpc
  >> 7737    /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: cannot find -lmpfr
...
```

### Platform and user environment

Please report your OS here:
```commandline
$  uname -a 
Linux greenline 4.4.90-18.32-default #1 SMP Fri Oct 6 13:30:08 UTC 2017 (465b410) x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -d
Description:    openSUSE Leap 42.2
``` 
### Additional information

```console
$ spack compilers
==> Available compilers
-- gcc opensuse42-x86_64 ----------------------------------------
gcc@4.8



hooks: Add lib64 hook
This hook creates a `lib` symlink if only a `lib64` directory is available.

Fixes #17556
Fixes #10842


Discussion:
I manually installed gcc 7.3.0. Then I successfully used it to build gcc@8.3.0 with spack. Might the core compiler (gcc 4.8) unable to build other gcc versions? Might be gcc 4.8 is too old to compile other versios? Well I tried with gcc 5.x and it didn't work... Could be a particular issue from the way opensuse installed gcc 4.8?
It seems mpc, mpfr, isl are all included in the compiling line using $prefix/lib while in the installed folder there is only the lib64 folder.

For instance, from one of the errors the compiling line is:

```
     9083    /home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/./prev-gcc/xg++ -B/home/alexis/spack/var/spack/stage/gcc-7.4
             .0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/./prev-gcc/ -B/home/alexis/spack/opt/spack/linux-opensuse42-x86_64/gcc-4.8/gcc-7.4.0-zftzyde3fqk4acxgw
             yl4w6c5cfzp2jmi/x86_64-pc-linux-gnu/bin/ -nostdinc++ -B/home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-
             x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -B/home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-x86_64-pc-
             linux-gnu/libstdc++-v3/libsupc++/.libs  -I/home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-x86_64-pc-lin
             ux-gnu/libstdc++-v3/include/x86_64-pc-linux-gnu  -I/home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-x86_
             64-pc-linux-gnu/libstdc++-v3/include  -I/home/alexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/libstdc++-v3/libsupc++ -L/home/a
             lexis/spack/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-x86_64-pc-linux-gnu/libstdc++-v3/src/.libs -L/home/alexis/spac
             k/var/spack/stage/gcc-7.4.0-zftzyde3fqk4acxgwyl4w6c5cfzp2jmi/gcc-7.4.0/spack-build/prev-x86_64-pc-linux-gnu/libstdc++-v3/libsupc++/.libs -no-pie   -g -O2 -gtogg
             le -DIN_GCC     -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverload
             ed-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -static-libstdc++ -static-libgcc  -o cc1plus \
     9084          cp/cp-lang.o c-family/stub-objc.o cp/call.o cp/decl.o cp/expr.o cp/pt.o cp/typeck2.o cp/class.o cp/decl2.o cp/error.o cp/lex.o cp/parser.o cp/ptree.o cp/r
             tti.o cp/typeck.o cp/cvt.o cp/except.o cp/friend.o cp/init.o cp/method.o cp/search.o cp/semantics.o cp/tree.o cp/repo.o cp/dump.o cp/optimize.o cp/mangle.o cp/c
             p-objcp-common.o cp/name-lookup.o cp/cxx-pretty-print.o cp/cp-cilkplus.o cp/cp-gimplify.o cp/cp-array-notation.o cp/lambda.o cp/vtable-class-hierarchy.o cp/cons
             texpr.o cp/cp-ubsan.o cp/constraint.o cp/logic.o attribs.o incpath.o c-family/c-common.o c-family/c-cppbuiltin.o c-family/c-dump.o c-family/c-format.o c-family/
             c-gimplify.o c-family/c-indentation.o c-family/c-lex.o c-family/c-omp.o c-family/c-opts.o c-family/c-pch.o c-family/c-ppoutput.o c-family/c-pragma.o c-family/c-
             pretty-print.o c-family/c-semantics.o c-family/c-ada-spec.o c-family/c-cilkplus.o c-family/array-notation-common.o c-family/cilk.o c-family/c-ubsan.o c-family/c
             -attribs.o c-family/c-warn.o i386-c.o glibc-c.o cc1plus-checksum.o libbackend.a main.o libcommon-target.a libcommon.a ../libcpp/libcpp.a ../libdecnumber/libdecn
             umber.a libcommon.a ../libcpp/libcpp.a   ../libbacktrace/.libs/libbacktrace.a ../libiberty/libiberty.a ../libdecnumber/libdecnumber.a  -L/home/alexis/spack/opt/
             spack/linux-opensuse42-x86_64/gcc-4.8/isl-0.18-ns44lmggxkyfwtlkc3vhivd4bhm2dpt3/lib -lisl -L/home/alexis/spack/opt/spack/linux-opensuse42-x86_64/gcc-4.8/gmp-6.1
             .2-4alukv63ns5ib42foqlnololyybj7lnu/lib -L/home/alexis/spack/opt/spack/linux-opensuse42-x86_64/gcc-4.8/mpfr-3.1.6-ij5ue4qzqp2do7kqxvwrc55oc5fy36p3/lib -L/home/a
             lexis/spack/opt/spack/linux-opensuse42-x86_64/gcc-4.8/mpc-1.1.0-herf7eitqs65bp3feq2nmec2at4oxl2y/lib -lmpc -lmpfr -lgmp -rdynamic -ldl  -L/home/alexis/spack/opt
             /spack/linux-opensuse42-x86_64/gcc-4.8/zlib-1.2.11-dgfddrhiv32zivt7rtu7wd4mif3c2mb7/lib -lz
     9085    graphite-isl-ast-to-gimple.o: In function `set_separate_option(isl_schedule_node*, void*)':
  >> 9086    graphite-isl-ast-to-gimple.c:(.text+0x471): undefined reference to `isl_schedule_node_get_type'
```

note for instance ` -L/home/alexis/spack/opt/spack/linux-opensuse42-x86_64/gcc-4.8/mpc-1.1.0-herf7eitqs65bp3feq2nmec2at4oxl2y/lib` this folder does not exist since lib64 should be there, then libmpc is not found. The same happens with the other libraries.
I wondering if this is related with issue [#7353](https://github.com/spack/spack/issues/7353). The author mention 

> Other lib64-using distributions, including SuSe, probably have the same issue.

And actually the issue seems to be the same. Spack install packages with `lib64` folders but includes `lib` in the path for further compilations. 

I will update the question to focus on this issue which I think is the main issue here.
Using the develop branch from today I'm also getting this same error using OpenSuse and it makes Spack impossible to use.  Has this been fixed within one of the Branches?

The command:
> spack install gcc@9.2.0

Successfully builds:
- mpc
- gmp
- mpfr
- etc...

Then:
It compiles gcc source but when it links the -L path contains .../lib/ directories but the libraries Spack previously built (mpc, gmp, mpfr, etc.) have all been built/installed into .../lib64/ directories.   

  >> 9356    /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -
             lmpc                                                                                   
  >> 9357    /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -
             lmpfr                                                                                  
  >> 9358    /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -
             lgmp   



Alternatively, we could make the different build systems specify the library path explicitly like the Meson one currently does. Autotools also seems to support `--libdir`.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -448,9 +448,7 @@ def configure_args(self):
             '--enable-languages={0}'.format(
                 ','.join(spec.variants['languages'].value)),
             # Drop gettext dependency
-            '--disable-nls',
-            '--with-mpfr={0}'.format(spec['mpfr'].prefix),
-            '--with-gmp={0}'.format(spec['gmp'].prefix),
+            '--disable-nls'
         ]
 
         # Use installed libz
@@ -476,13 +474,23 @@ def configure_args(self):
                 '--enable-bootstrap',
             ])
 
-        # MPC
-        if 'mpc' in spec:
-            options.append('--with-mpc={0}'.format(spec['mpc'].prefix))
+        # Configure include and lib directories explicitly for these
+        # dependencies since the short GCC option assumes that libraries
+        # are installed in "/lib" which might not be true on all OS
+        # (see #10842)
+        #
+        # More info at: https://gcc.gnu.org/install/configure.html
+        for dep_str in ('mpfr', 'gmp', 'mpc', 'isl'):
+            if dep_str not in spec:
+                continue
 
-        # ISL
-        if 'isl' in spec:
-            options.append('--with-isl={0}'.format(spec['isl'].prefix))
+            dep_spec = spec[dep_str]
+            include_dir = dep_spec.headers.directories[0]
+            lib_dir = dep_spec.libs.directories[0]
+            options.extend([
+                '--with-{0}-include={1}'.format(dep_str, include_dir),
+                '--with-{0}-lib={1}'.format(dep_str, lib_dir)
+            ])
 
         # nvptx-none offloading for host compiler
         if spec.satisfies('+nvptx'):


Test patch: