Repository: spack/spack

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

```console
$> spack install namd@2.14 interface=python ^python@3.8.12
[...]
Adding file obj/Parser.o...
OpenMP support enabled
charmc> ----------- Module dependency search ------------
charmc> ----------- Module dependency search complete ------------
charmc> All libraries are: -L/cvmfs/hpcsw.umd.edu/spack-software/2021.11.29/linux-rhel8-zen2/gcc-9.4.0/charmpp-6.10.2-h2v6pcv7wm2kdh6c4qojowtb7n7kn5bz/bin/../lib -lmoduleCkLoop -lmoduleCkMulticast -lpthread -lckmain -lck -lmemory-default -lthreads-default -lconv-machine -lconv-core -ltmgr -lconv-util -lconv-partition -lhwloc_embedded -lm -lcudart -lmemory-default -lthreads-default -lldb-rand -lconv-ldb -lpthread -lckqt -lckqt -ldl -ltcl8.6 -ldl -lpthread -lcrypt -lintl -lpthread -ldl -lutil -lm -lm -lfftw3f -lm -lmoduleCkMulticast -lmoduleCkLoop -lmoduleNDMeshStreamer -lmodulecompletion -lmpi -lz -lm /cvmfs/hpcsw.umd.edu/spack-software/2021.11.29/linux-rhel8-zen2/gcc-9.4.0/charmpp-6.10.2-h2v6pcv7wm2kdh6c4qojowtb7n7kn5bz/bin/../lib/conv-static.o
Adding registration for module CkMulticast
Adding registration for module CkLoop
charmc: Executing g++ -DCMK_GFORTRAN -DCMK_GFORTRAN  [...] -o moduleinit4141582.o
charmc: Executing g++ -rdynamic -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX [...]  -o namd2
bj/ScriptTcl.o: In function `PyInit_namd()':
ScriptTcl.C:(.text+0xaf): undefined reference to `PyModule_Create2'
obj/ScriptTcl.o: In function `PyInit_tcl()':
ScriptTcl.C:(.text+0xef): undefined reference to `PyModule_Create2'
[...]
```
Basically a large number of Python functions are not being found, which is due to the -lpython flag being missing in the compilation (sorry --- such is elided in the long compilation lines above, but visible in attached files).

Delving further, it appears to be a problem with the namd build system and a change in python-config command with python@3.8.  Namd uses python-config to configure the compilation flags when building with python.  Basically, starting with python@3.8 the
python-config --libs (and --ldflags) commands no longer include -lpython or equivalent unless the additional flag --embed is given.

I have notified the namd developers, but plan to add a small patch to the namd config file to add the --embed flag when building namd@2.14 with python@3.8.



### Information on your system

``console
$ spack debug report
* **Spack:** 0.17.0-319-5dce4d79bd
* **Python:** 3.6.8
* **Platform:** linux-rhel8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/7803061/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/7803062/spack-build-env.txt)

No maintainers for namd found

### 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
Installation issue: namd
### Steps to reproduce the issue

```console
$> spack install namd@2.14 interface=python ^python@3.8.12
[...]
Adding file obj/Parser.o...
OpenMP support enabled
charmc> ----------- Module dependency search ------------
charmc> ----------- Module dependency search complete ------------
charmc> All libraries are: -L/cvmfs/hpcsw.umd.edu/spack-software/2021.11.29/linux-rhel8-zen2/gcc-9.4.0/charmpp-6.10.2-h2v6pcv7wm2kdh6c4qojowtb7n7kn5bz/bin/../lib -lmoduleCkLoop -lmoduleCkMulticast -lpthread -lckmain -lck -lmemory-default -lthreads-default -lconv-machine -lconv-core -ltmgr -lconv-util -lconv-partition -lhwloc_embedded -lm -lcudart -lmemory-default -lthreads-default -lldb-rand -lconv-ldb -lpthread -lckqt -lckqt -ldl -ltcl8.6 -ldl -lpthread -lcrypt -lintl -lpthread -ldl -lutil -lm -lm -lfftw3f -lm -lmoduleCkMulticast -lmoduleCkLoop -lmoduleNDMeshStreamer -lmodulecompletion -lmpi -lz -lm /cvmfs/hpcsw.umd.edu/spack-software/2021.11.29/linux-rhel8-zen2/gcc-9.4.0/charmpp-6.10.2-h2v6pcv7wm2kdh6c4qojowtb7n7kn5bz/bin/../lib/conv-static.o
Adding registration for module CkMulticast
Adding registration for module CkLoop
charmc: Executing g++ -DCMK_GFORTRAN -DCMK_GFORTRAN  [...] -o moduleinit4141582.o
charmc: Executing g++ -rdynamic -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX [...]  -o namd2
bj/ScriptTcl.o: In function `PyInit_namd()':
ScriptTcl.C:(.text+0xaf): undefined reference to `PyModule_Create2'
obj/ScriptTcl.o: In function `PyInit_tcl()':
ScriptTcl.C:(.text+0xef): undefined reference to `PyModule_Create2'
[...]
```
Basically a large number of Python functions are not being found, which is due to the -lpython flag being missing in the compilation (sorry --- such is elided in the long compilation lines above, but visible in attached files).

Delving further, it appears to be a problem with the namd build system and a change in python-config command with python@3.8.  Namd uses python-config to configure the compilation flags when building with python.  Basically, starting with python@3.8 the
python-config --libs (and --ldflags) commands no longer include -lpython or equivalent unless the additional flag --embed is given.

I have notified the namd developers, but plan to add a small patch to the namd config file to add the --embed flag when building namd@2.14 with python@3.8.



### Information on your system

``console
$ spack debug report
* **Spack:** 0.17.0-319-5dce4d79bd
* **Python:** 3.6.8
* **Platform:** linux-rhel8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/7803061/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/7803062/spack-build-env.txt)

No maintainers for namd found

### 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/namd/package.py b/var/spack/repos/builtin/packages/namd/package.py
--- a/var/spack/repos/builtin/packages/namd/package.py
+++ b/var/spack/repos/builtin/packages/namd/package.py
@@ -39,6 +39,8 @@ class Namd(MakefilePackage, CudaPackage):
     # allowed
     patch('inherited-member-2.13.patch', when='@2.13')
     patch('inherited-member-2.14.patch', when='@2.14')
+    # Handle change in python-config for python@3.8:
+    patch('namd-python38.patch', when='interface=python ^python@3.8:')
 
     depends_on('charmpp@6.10.1:', when="@2.14:")
     depends_on('charmpp@6.8.2', when="@2.13")


Test patch: