Repository: spack/spack

Issue:
Installation issue: ffmpeg with Apple Clang 15
### Steps to reproduce the issue

```console
> spack spec -I ffmpeg
Input spec
--------------------------------
 -   ffmpeg

Concretized
--------------------------------
 -   ffmpeg@6.0%apple-clang@15.0.0~X+bzlib~drawtext+gpl~libaom~libmp3lame~libopenjpeg~libopus~libsnappy~libspeex~libssh~libvorbis~libvpx~libwebp~libx264~libxml2~libzmq~lzma~nonfree~openssl~sdl2+shared+version3 build_system=autotools patches=d1ea47c arch=darwin-ventura-m2
[+]      ^bzip2@1.0.8%apple-clang@15.0.0~debug~pic+shared build_system=generic arch=darwin-ventura-m2
[+]          ^diffutils@3.9%apple-clang@15.0.0 build_system=autotools arch=darwin-ventura-m2
[+]      ^gnuconfig@2022-09-17%apple-clang@15.0.0 build_system=generic arch=darwin-ventura-m2
[+]      ^libiconv@1.17%apple-clang@15.0.0 build_system=autotools libs=shared,static arch=darwin-ventura-m2
[+]      ^yasm@1.3.0%apple-clang@15.0.0 build_system=autotools arch=darwin-ventura-m2
[+]      ^zlib-ng@2.1.3%apple-clang@15.0.0+compat+opt build_system=autotools patches=299b958,86c3f5b,ae9077a,b692621 arch=darwin-ventura-m2
```
I actually need ffmpeg 5 but the issue also occurs with 6. Ffmpeg built fine with Apple Clang 14.

### Error message

<details><summary>Error message</summary>

<pre>
/Users/Adam/spack/lib/spack/env/clang/clang -dynamiclib -Wl,-single_module -Wl,-install_name,/Users/Adam/spack/opt/spack/darwin-ventura-m2/apple-clang-15.0.0/ffmpeg-6.0-perdwctgla3obp6ca6m4tdcj7rnvebwy/lib/libavdevice.60.dylib,-current_version,60.1.100,-compatibility_version,60 -Wl,-exported_symbols_list,libavdevice/libavdevice.ver -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -Wl,-dynamic,-search_paths_first -Qunused-arguments  -o libavdevice/libavdevice.60.dylib libavdevice/alldevices.o libavdevice/audiotoolbox.o libavdevice/avdevice.o libavdevice/avfoundation.o libavdevice/lavfi.o libavdevice/utils.o libavdevice/version.o -lavfilter -lswscale -lpostproc -lavformat -lavcodec -lswresample -lavutil -framework Foundation -framework AudioToolbox -framework CoreAudio -lm -latomic -framework AVFoundation -framework CoreVideo -framework CoreMedia -framework CoreGraphics -framework AudioToolbox -pthread -framework OpenGL -framework OpenGL -pthread -lm -latomic -framework Metal -framework VideoToolbox -framework CoreImage -framework AppKit -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices -lm -latomic -lm -latomic -lm -latomic -lbz2 -lz -Wl,-framework,CoreFoundation -Wl,-framework,Security -liconv -lm -latomic -framework AudioToolbox -pthread -lz -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices -lm -latomic -pthread -lm -framework VideoToolbox -latomic -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices 
ld: warning: -single_module is obsolete
ld: warning: ignoring duplicate libraries: '-latomic', '-lm', '-lz'
ld: building exports trie: duplicate symbol '_av_ac3_parse_header'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libavdevice/libavdevice.60.dylib] Error 1
make: *** Waiting for unfinished jobs....
rm libavfilter/metal/vf_yadif_videotoolbox.metal.air libavfilter/metal/vf_yadif_videotoolbox.metallib libavfilter/metal/vf_yadif_videotoolbox.metallib.c
</pre></details>


### Information on your system

* **Spack:** 0.21.0.dev0 (f42402129ace15b6495c663320f2eca518d5f9d4)
* **Python:** 3.11.4
* **Platform:** darwin-ventura-m2
* **Concretizer:** clingo


### Additional information

* [spack-build-out.txt](https://github.com/spack/spack/files/12701014/spack-build-out.txt)
* [spack-build-env-mods.txt](https://github.com/spack/spack/files/12701016/spack-build-env-mods.txt)

@xjrc

### 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/ffmpeg/package.py b/var/spack/repos/builtin/packages/ffmpeg/package.py
--- a/var/spack/repos/builtin/packages/ffmpeg/package.py
+++ b/var/spack/repos/builtin/packages/ffmpeg/package.py
@@ -128,6 +128,10 @@ def headers(self):
         headers.directories = [self.prefix.include]
         return headers
 
+    @when("@:6.0 %apple-clang@15:")
+    def setup_build_environment(self, env):
+        env.append_flags("LDFLAGS", "-Wl,-ld_classic")
+
     def enable_or_disable_meta(self, variant, options):
         switch = "enable" if "+{0}".format(variant) in self.spec else "disable"
         return ["--{0}-{1}".format(switch, option) for option in options]


Test patch: