Repository: spack/spack

Issue:
Installation issue: hdf-eos2 build error with intel@2021.10.0 on AWS EC2 instance hpc6a running Ubuntu 22.04
### Steps to reproduce the issue

This issue is a duplicate of https://github.com/JCSDA/spack-stack/issues/1091.

On an AWS EC2 hpc6a instance running Ubuntu 22.04 and using Intel 2021.10.0 (part of oneAPI 2023.2.3), the error shown below occurs, regardless of the build variants being selected (`~static +shared`, `+static ~shared`, `+static +shared`) and despite this being in the package recipe for hdf-eos2:
```
        # Package really wants h4cc to be used
        extra_args.append("CC={0}/bin/h4cc -Df2cFortran".format(self.spec["hdf"].prefix))

        # We always build PIC code
        extra_args.append("--with-pic")
        extra_args.append("--enable-install_include")

        # Set shared/static appropriately
        extra_args.extend(self.enable_or_disable("shared"))
        extra_args.extend(self.enable_or_disable("static"))
```
My assumption is that something is not working as intended when using `h4cc`. The easiest solution I found was this:
```
diff --git a/var/spack/repos/builtin/packages/hdf-eos2/package.py b/var/spack/repos/builtin/packages/hdf-eos2/package.py
index 886e2ade..99e01779 100644
--- a/var/spack/repos/builtin/packages/hdf-eos2/package.py
+++ b/var/spack/repos/builtin/packages/hdf-eos2/package.py
@@ -115,6 +115,8 @@ def configure_args(self):

         # https://forum.hdfgroup.org/t/help-building-hdf4-with-clang-error-implicit-declaration-of-function-test-mgr-szip-is-invalid-in-c99/7680
         if self.spec.satisfies("%apple-clang"):
-            extra_args.append("CFLAGS=-Wno-error=implicit-function-declaration")
+            extra_args.append("CFLAGS=-Wno-error=implicit-function-declaration -fPIC")
+        else:
+            extra_args.append("CFLAGS=-fPIC")

         return extra_args
```
I will create a PR for this shortly.

### Error message

```
     ...

     637    mv -f wviiinv.o .libs/wviiinv.o
     638    /bin/bash ../../libtool --mode=link --tag=CC /home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_p/intel
            /2021.10.0/hdf-4.2.15-mup3q46/bin/h4cc -Df2cFortran  -g -O2 -I/home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__s
            pack_path_p/intel/2021.10.0/hdf-4.2.15-mup3q46/include  -L/home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack
            _path_p/intel/2021.10.0/libjpeg-turbo-2.1.0-zi7qc2t/lib -L/home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack
            _path_p/intel/2021.10.0/hdf-4.2.15-mup3q46/lib -o libGctp.la -rpath /home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder
            __/__spack_path_p/intel/2021.10.0/hdf-eos2-2.20v1.00-f34rguv/lib  gctp.lo alberfor.lo alberinv.lo alconfor.lo alconinv.lo azimfor.lo aziminv.lo bceafor.lo bceainv.lo br_gctp.lo ceafor.lo ceainv.lo cproj.lo eqconfor.lo eqconinv.lo equifor.lo equiinv.lo
             for_init.lo gnomfor.lo gnominv.lo goodfor.lo goodinv.lo gvnspfor.lo gvnspinv.lo hamfor.lo haminv.lo imolwfor.lo imolwinv.lo inv_init.lo isinusfor.lo isinusinv.lo lamazfor.lo lamazinv.lo lamccfor.lo lamccinv.lo merfor.lo merinv.lo millfor.lo millinv.l
            o molwfor.lo molwinv.lo obleqfor.lo obleqinv.lo omerfor.lo omerinv.lo orthfor.lo orthinv.lo paksz.lo polyfor.lo polyinv.lo psfor.lo psinv.lo report.lo robfor.lo robinv.lo sinfor.lo sininv.lo sphdz.lo somfor.lo sominv.lo sterfor.lo sterinv.lo stplnfor.
            lo stplninv.lo tmfor.lo tminv.lo untfz.lo utmfor.lo utminv.lo vandgfor.lo vandginv.lo wivfor.lo wivinv.lo wviifor.lo wviiinv.lo  -lmfhdf -ldf -lz -ljpeg -lm
     639    /home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_p/intel/2021.10.0/hdf-4.2.15-mup3q46/bin/h4cc -Df2cF
            ortran -shared  .libs/gctp.o .libs/alberfor.o .libs/alberinv.o .libs/alconfor.o .libs/alconinv.o .libs/azimfor.o .libs/aziminv.o .libs/bceafor.o .libs/bceainv.o .libs/br_gctp.o .libs/ceafor.o .libs/ceainv.o .libs/cproj.o .libs/eqconfor.o .libs/eqconin
            v.o .libs/equifor.o .libs/equiinv.o .libs/for_init.o .libs/gnomfor.o .libs/gnominv.o .libs/goodfor.o .libs/goodinv.o .libs/gvnspfor.o .libs/gvnspinv.o .libs/hamfor.o .libs/haminv.o .libs/imolwfor.o .libs/imolwinv.o .libs/inv_init.o .libs/isinusfor.o .
            libs/isinusinv.o .libs/lamazfor.o .libs/lamazinv.o .libs/lamccfor.o .libs/lamccinv.o .libs/merfor.o .libs/merinv.o .libs/millfor.o .libs/millinv.o .libs/molwfor.o .libs/molwinv.o .libs/obleqfor.o .libs/obleqinv.o .libs/omerfor.o .libs/omerinv.o .libs/
            orthfor.o .libs/orthinv.o .libs/paksz.o .libs/polyfor.o .libs/polyinv.o .libs/psfor.o .libs/psinv.o .libs/report.o .libs/robfor.o .libs/robinv.o .libs/sinfor.o .libs/sininv.o .libs/sphdz.o .libs/somfor.o .libs/sominv.o .libs/sterfor.o .libs/sterinv.o
            .libs/stplnfor.o .libs/stplninv.o .libs/tmfor.o .libs/tminv.o .libs/untfz.o .libs/utmfor.o .libs/utminv.o .libs/vandgfor.o .libs/vandginv.o .libs/wivfor.o .libs/wivinv.o .libs/wviifor.o .libs/wviiinv.o  -L/home/ubuntu/spack-stack/CI/actions-runner/_wo
            rk/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_p/intel/2021.10.0/libjpeg-turbo-2.1.0-zi7qc2t/lib -L/home/ubuntu/spack-stack/CI/actions-runner/_wo
            rk/spack-stack/spack-stack/envs/ue-intel-2021.10.0/install/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_placeholder__/__spack_path_p/intel/2021.10.0/hdf-4.2.15-mup3q46/lib -lmfhdf -ldf -lz -ljpeg -lm  -Wl,-soname -Wl,libGctp.so.0
             -o .libs/libGctp.so.0.0.0
     640    icc: remark #10441: The Intel(R) C++ Compiler Classic (ICC) is deprecated and will be removed from product release in the second half of 2023. The Intel(R) oneAPI DPC++/C++ Compiler (ICX) is the recommended compiler moving forward. Please transition t
            o use this compiler. Use '-diag-disable=10441' to disable this message.
     641    ld: .libs/gctp.o: relocation R_X86_64_32S against `inpj' can not be used when making a shared object; recompile with -fPIC
     642    ld: failed to set dynamic section sizes: bad value
  >> 643    make[2]: *** [Makefile:303: libGctp.la] Error 1
     644    make[2]: Leaving directory '/home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/cache/build_stage/spack-stage-hdf-eos2-2.20v1.00-f34rguvwfr673j2qmb46b7l7m3ou7iba/spack-src/gctp/src'
  >> 645    make[1]: *** [Makefile:241: all-recursive] Error 1
     646    make[1]: Leaving directory '/home/ubuntu/spack-stack/CI/actions-runner/_work/spack-stack/spack-stack/cache/build_stage/spack-stage-hdf-eos2-2.20v1.00-f34rguvwfr673j2qmb46b7l7m3ou7iba/spack-src/gctp'
  >> 647    make: *** [Makefile:264: all-recursive] Error 1
```

### Information on your system

```
* **Spack:** 0.22.0.dev0 (0a68124ed00751975d4194404906c45cd5ada2d1)
* **Python:** 3.10.12
* **Platform:** linux-ubuntu22.04-zen2
* **Concretizer:** clingo
```

### Additional information

Not needed: will supply PR that fixes this shortly.

### General information

- [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/hdf-eos2/package.py b/var/spack/repos/builtin/packages/hdf-eos2/package.py
--- a/var/spack/repos/builtin/packages/hdf-eos2/package.py
+++ b/var/spack/repos/builtin/packages/hdf-eos2/package.py
@@ -160,4 +160,15 @@ def configure_args(self):
         if "zlib" in self.spec:
             extra_args.append("--with-zlib={0}".format(self.spec["zlib-api"].prefix))
 
+        # https://forum.hdfgroup.org/t/help-building-hdf4-with-clang-error-implicit-declaration-of-function-test-mgr-szip-is-invalid-in-c99/7680
+        # -fPIC: https://github.com/spack/spack/issues/43792
+        if self.spec.satisfies("%apple-clang"):
+            extra_args.append(
+                "CFLAGS=-Wno-error=implicit-function-declaration {0}".format(
+                    self.compiler.cc_pic_flag
+                )
+            )
+        else:
+            extra_args.append("CFLAGS={0}".format(self.compiler.cc_pic_flag))
+
         return extra_args


Test patch: