Repository: spack/spack

Issue:
Build error: GCC 9.2.0 on Catalina
### Steps to reproduce the issue

```console
$ spack install gcc
... 
  >> 586650    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/resource.h:443:34: error: expected declaration speci
               fiers before '__OSX_AVAILABLE_STARTING'
     586651      443 | int     getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
     586652          |   
[and similar stuff]
```

### Platform and user environment

Please report your OS here:
```commandline
healther@MacBook-Air spack % uname -a
Darwin MacBook-Air.local 19.0.0 Darwin Kernel Version 19.0.0: Wed Sep 25 20:18:50 PDT 2019; root:xnu-6153.11.26~2/RELEASE_X86_64 x86_64
``` 

This seems to be a partially known issue for example [gnu bugzilla](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90835#c12), and [stackexchange](https://apple.stackexchange.com/questions/372305/compiling-gcc-on-catalina) with a proposed solution essentially ending up patching system headers like [here](https://solarianprogrammer.com/2019/10/12/compiling-gcc-macos/). We should probably follow [homebrew](https://github.com/Homebrew/homebrew-core/blob/master/Formula/gcc.rb)s approach, where they apply this [patch](https://raw.githubusercontent.com/Homebrew/formula-patches/b8b8e65e/gcc/9.2.0-catalina.patch). However I'm not sure whether the bugzilla report should be taken as an indication that upstream gcc will fix things...


Discussion:

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
@@ -100,6 +100,7 @@ class Gcc(AutotoolsPackage):
     depends_on('isl@0.15:0.18', when='@6:8.9')
     depends_on('isl@0.15:0.20', when='@9:')
     depends_on('zlib', when='@6:')
+    depends_on('libiconv')
     depends_on('gnat', when='languages=ada')
     depends_on('binutils~libiberty', when='+binutils')
     depends_on('zip', type='build', when='languages=java')
@@ -195,6 +196,14 @@ class Gcc(AutotoolsPackage):
             # https://trac.macports.org/ticket/56502#no1
             # see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83531
             patch('darwin/headers-10.13-fix.patch', when='@5.5.0')
+        if macos_version() >= Version('10.15'):
+            # Fix system headers for Catalina SDK
+            # (otherwise __OSX_AVAILABLE_STARTING ends up undefined)
+            patch('https://raw.githubusercontent.com/Homebrew/formula-patches/b8b8e65e/gcc/9.2.0-catalina.patch',
+                  sha256='0b8d14a7f3c6a2f0d2498526e86e088926671b5da50a554ffa6b7f73ac4f132b', when='@9.2.0:')
+        # Use -headerpad_max_install_names in the build,
+        # otherwise updated load commands won't fit in the Mach-O header.
+        # This is needed because `gcc` avoids the superenv shim.
         patch('darwin/gcc-7.1.0-headerpad.patch', when='@5:')
         patch('darwin/gcc-6.1.0-jit.patch', when='@5:7')
         patch('darwin/gcc-4.9.patch1', when='@4.9.0:4.9.3')
@@ -255,18 +264,24 @@ def patch(self):
                         '-I{0}'.format(spec['zlib'].prefix.include),
                         'gcc/Makefile.in')
 
+    # https://gcc.gnu.org/install/configure.html
     def configure_args(self):
         spec = self.spec
 
         # Generic options to compile GCC
         options = [
+            # Distributor options
+            '--with-pkgversion=Spack GCC',
+            '--with-bugurl=https://github.com/spack/spack/issues',
+            # Xcode 10 dropped 32-bit support
             '--disable-multilib',
             '--enable-languages={0}'.format(
                 ','.join(spec.variants['languages'].value)),
+            # Drop gettext dependency
+            '--disable-nls',
+            '--with-libiconv-prefix={0}'.format(spec['libiconv'].prefix),
             '--with-mpfr={0}'.format(spec['mpfr'].prefix),
             '--with-gmp={0}'.format(spec['gmp'].prefix),
-            '--enable-lto',
-            '--with-quad'
         ]
 
         # Use installed libz
@@ -280,7 +295,7 @@ def configure_args(self):
         # Binutils
         if spec.satisfies('+binutils'):
             static_bootstrap_flags = '-static-libstdc++ -static-libgcc'
-            binutils_options = [
+            options.extend([
                 '--with-sysroot=/',
                 '--with-stage1-ldflags={0} {1}'.format(
                     self.rpath_args, static_bootstrap_flags),
@@ -290,8 +305,7 @@ def configure_args(self):
                 '--with-ld={0}/ld'.format(spec['binutils'].prefix.bin),
                 '--with-gnu-as',
                 '--with-as={0}/as'.format(spec['binutils'].prefix.bin),
-            ]
-            options.extend(binutils_options)
+            ])
 
         # MPC
         if 'mpc' in spec:
@@ -301,10 +315,6 @@ def configure_args(self):
         if 'isl' in spec:
             options.append('--with-isl={0}'.format(spec['isl'].prefix))
 
-        # macOS
-        if sys.platform == 'darwin':
-            options.append('--with-build-config=bootstrap-debug')
-
         # nvptx-none offloading for host compiler
         if spec.satisfies('+nvptx'):
             options.extend(['--enable-offload-targets=nvptx-none',
@@ -382,12 +392,6 @@ def nvptx_install(self):
             make()
             make('install')
 
-    @property
-    def build_targets(self):
-        if sys.platform == 'darwin':
-            return ['bootstrap']
-        return []
-
     @property
     def install_targets(self):
         if '+strip' in self.spec:


Test patch: