Repository: spack/spack

Issue:
Installation issue: texinfo
### Steps to reproduce the issue

```console
$ spack spec -I texinfo
Input spec
--------------------------------
 -   texinfo

Concretized
--------------------------------
 -   texinfo@7.0%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]      ^perl@5.36.0%apple-clang@13.1.6+cpanm+shared+threads build_system=generic arch=darwin-ventura-skylake
[+]          ^berkeley-db@18.1.40%apple-clang@13.1.6+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=darwin-ventura-skylake
[+]          ^bzip2@1.0.8%apple-clang@13.1.6~debug~pic+shared build_system=generic arch=darwin-ventura-skylake
[+]              ^diffutils@3.8%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]                  ^libiconv@1.16%apple-clang@13.1.6 build_system=autotools libs=shared,static arch=darwin-ventura-skylake
[+]          ^gdbm@1.23%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]              ^readline@8.1.2%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]                  ^ncurses@6.3%apple-clang@13.1.6~symlinks+termlib abi=none build_system=autotools arch=darwin-ventura-skylake
[+]                      ^pkgconf@1.8.0%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]          ^zlib@1.2.13%apple-clang@13.1.6+optimize+pic+shared build_system=makefile arch=darwin-ventura-skylake
```


### Error message

<details><summary>Error message</summary>

```
==> Installing texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh
==> No binary for texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh found: installing from source
==> Fetching https://ftpmirror.gnu.org/texinfo/texinfo-7.0.tar.gz
==> No patches needed for texinfo
==> texinfo: Executing phase: 'autoreconf'
==> texinfo: Executing phase: 'configure'
==> texinfo: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16' 'V=1'

7 errors found in build log:
     4475    /Users/pnanda/src/spack/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/perl-5.36.0-ovdihj66uusqhgyg
             yw2zabendk4upqqy/lib/5.36.0/darwin-thread-multi-2level/CORE/XSUB.h:330:7: note: expanded from macro 'XSR
             ETURN'
     4476        } STMT_END
     4477          ^~~~~~~~
     4478    ./ppport.h:4002:20: note: expanded from macro 'STMT_END'
     4479    #  define STMT_END      )
     4480                            ^
  >> 4481    parsetexi/api.c:33:10: fatal error: 'libintl.h' file not found
     4482    #include <libintl.h>
     4483             ^~~~~~~~~~~
     4484    parsetexi/Parsetexi.c:190:13: warning: '(' and '{' tokens introducing statement expression appear in dif
             ferent macro expansion contexts [-Wcompound-token-split-by-macro]
     4485            XSprePUSH; PUSHi((IV)RETVAL);
     4486                       ^~~~~~~~~~~~~~~~~
     4487    /Users/pnanda/src/spack/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/perl-5.36.0-ovdihj66uusqhgyg
             yw2zabendk4upqqy/lib/5.36.0/darwin-thread-multi-2level/CORE/pp.h:476:18: note: expanded from macro 'PUSH
             i'

     ...

     6436        XSRETURN(1);
     6437        ^~~~~~~~~~~
     6438    /Users/pnanda/src/spack/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/perl-5.36.0-ovdihj66uusqhgyg
             yw2zabendk4upqqy/lib/5.36.0/darwin-thread-multi-2level/CORE/XSUB.h:330:7: note: expanded from macro 'XSR
             ETURN'
     6439        } STMT_END
     6440          ^~~~~~~~
     6441    ./ppport.h:4002:20: note: expanded from macro 'STMT_END'
  >> 6442    make[5]: *** [parsetexi/Parsetexi_la-api.lo] Error 1
     6443    #  define STMT_END      )
     6444                            ^
     6445    make[5]: *** Waiting for unfinished jobs....
     6446    libtool: compile:  /usr/bin/clang -DHAVE_CONFIG_H -I. -I/var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T
             /pnanda/spack-stage/spack-stage-texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh/spack-src/tp/Texinfo/XS -I/
             var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-texinfo-7.0-z3gotxjpfmxmp
             xn3zpcvafamlapuu5sh/spack-src/tp/Texinfo/XS/parsetexi -I/var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T
             /pnanda/spack-stage/spack-stage-texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh/spack-src/tp/Texinfo/XS -I/
             var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-texinfo-7.0-z3gotxjpfmxmp
             xn3zpcvafamlapuu5sh/spack-src/tp/Texinfo/XS/gnulib/lib -I./gnulib/lib -DDATADIR=\"/Users/pnanda/src/spac
             k/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh/share
             \" -fno-common -DPERL_DARWIN -mmacosx-version-min=13.0 -DAPPLLIB_EXP=/Users/pnanda/src/spack/opt/spack/d
             arwin-ventura-skylake/apple-clang-13.1.6/perl-5.36.0-ovdihj66uusqhgygyw2zabendk4upqqy/lib/perl5 -fno-str
             ict-aliasing -pipe -fstack-protector-strong -I/Users/pnanda/src/spack/opt/spack/darwin-ventura-skylake/a
             pple-clang-13.1.6/gdbm-1.23-spv4uevvq4whjeybnyuxcqju2rjkpz6y/include -DPERL_USE_SAFE_PUTENV -O3 -DVERSIO
             N=\"0\" -DXS_VERSION=\"0\" -I/Users/pnanda/src/spack/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6
             /perl-5.36.0-ovdihj66uusqhgygyw2zabendk4upqqy/lib/5.36.0/darwin-thread-multi-2level/CORE -MT parsetexi/P
             arsetexi_la-macro.lo -MD -MP -MF parsetexi/.deps/Parsetexi_la-macro.Tpo -c parsetexi/macro.c  -fno-commo
             n -DPIC -o parsetexi/.libs/Parsetexi_la-macro.o
     6447    26 warnings generated.
     6448    mv -f parsetexi/.deps/Parsetexi_la-debug.Tpo parsetexi/.deps/Parsetexi_la-debug.Plo

     ...

     6458    mv -f parsetexi/.deps/Parsetexi_la-indices.Tpo parsetexi/.deps/Parsetexi_la-indices.Plo
     6459    mv -f parsetexi/.deps/Parsetexi_la-separator.Tpo parsetexi/.deps/Parsetexi_la-separator.Plo
     6460    mv -f parsetexi/.deps/Parsetexi_la-def.Tpo parsetexi/.deps/Parsetexi_la-def.Plo
     6461    mv -f parsetexi/.deps/Parsetexi_la-macro.Tpo parsetexi/.deps/Parsetexi_la-macro.Plo
     6462    mv -f parsetexi/.deps/Parsetexi_la-handle_commands.Tpo parsetexi/.deps/Parsetexi_la-handle_commands.Plo
     6463    mv -f parsetexi/.deps/Parsetexi_la-end_line.Tpo parsetexi/.deps/Parsetexi_la-end_line.Plo
  >> 6464    make[4]: *** [all-recursive] Error 1
  >> 6465    make[3]: *** [all] Error 2
  >> 6466    make[2]: *** [all-recursive] Error 1
  >> 6467    make[1]: *** [all-recursive] Error 1
  >> 6468    make: *** [all] Error 2

See build log for details:
  /var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-texinfo-7.0-z3gotxjpfmxmpxn3zpcvafamlapuu5sh/spack-build-out.txt
```
</details>


### Information on your system

* **Spack:** 0.20.0.dev0 (69dd742dc93f19e365b70652be9cc0553add6fb7)
* **Python:** 3.10.8
* **Platform:** darwin-ventura-skylake
* **Concretizer:** clingo

### Additional information

* [spack-build-out.txt](https://github.com/spack/spack/files/10142886/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/10142889/spack-build-env.txt)


### 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/texinfo/package.py b/var/spack/repos/builtin/packages/texinfo/package.py
--- a/var/spack/repos/builtin/packages/texinfo/package.py
+++ b/var/spack/repos/builtin/packages/texinfo/package.py
@@ -34,6 +34,7 @@ class Texinfo(AutotoolsPackage, GNUMirrorPackage):
     version("5.0", sha256="2c579345a39a2a0bb4b8c28533f0b61356504a202da6a25d17d4d866af7f5803")
 
     depends_on("perl")
+    depends_on("gettext")
 
     # sanity check
     sanity_check_is_file = [
@@ -61,6 +62,12 @@ def build_targets(self):
             targets.append("CFLAGS={}".format(self.compiler.c11_flag))
         return targets
 
+    def setup_build_environment(self, env):
+        # texinfo builds Perl XS modules internally, and by default it overrides the
+        # CC that the top-level configure reports. This loses the Spack wrappers unless
+        # we set PERL_EXT_CC
+        env.set("PERL_EXT_CC", spack_cc)
+
     @classmethod
     def determine_version(cls, exe):
         output = Executable(exe)("--version", output=str, error=str)


Test patch: