# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import *


class Nettle(AutotoolsPackage, GNUMirrorPackage):
    """The Nettle package contains the low-level cryptographic library
    that is designed to fit easily in many contexts."""

    homepage = "https://www.lysator.liu.se/~nisse/nettle/"
    gnu_mirror_path = "nettle/nettle-3.3.tar.gz"

    license("GPL-2.0-or-later OR LGPL-3.0-or-later")

    version("3.9.1", sha256="ccfeff981b0ca71bbd6fbcb054f407c60ffb644389a5be80d6716d5b550c6ce3")
    version("3.8.1", sha256="364f3e2b77cd7dcde83fd7c45219c834e54b0c75e428b6f894a23d12dd41cbfe")
    version("3.4.1", sha256="f941cf1535cd5d1819be5ccae5babef01f6db611f9b5a777bae9c7604b8a92ad")
    version("3.4", sha256="ae7a42df026550b85daca8389b6a60ba6313b0567f374392e54918588a411e94")
    version("3.3", sha256="46942627d5d0ca11720fec18d81fc38f7ef837ea4197c1f630e71ce0d470b11e")
    version("3.2", sha256="ea4283def236413edab5a4cf9cf32adf540c8df1b9b67641cfc2302fca849d97")
    version("2.7.1", sha256="bc71ebd43435537d767799e414fce88e521b7278d48c860651216e1fc6555b40")
    version("2.7", sha256="c294ea133c05382cc2effb1734d49f4abeb1ad8515543a333de49a11422cd4d6")

    depends_on("gmp")
    depends_on("m4", type="build")
    depends_on("openssl")

    def configure_args(self):
        return ["CFLAGS={0}".format(self.compiler.c99_flag)]

var/spack/repos/builtin/packages/nettle/package.py
# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import *


class Nettle(AutotoolsPackage, GNUMirrorPackage):
    """The Nettle package contains the low-level cryptographic library
    that is designed to fit easily in many contexts."""

    homepage = "https://www.lysator.liu.se/~nisse/nettle/"
    gnu_mirror_path = "nettle/nettle-3.3.tar.gz"

    license("GPL-2.0-or-later OR LGPL-3.0-or-later")

    version("3.9.1", sha256="ccfeff981b0ca71bbd6fbcb054f407c60ffb644389a5be80d6716d5b550c6ce3")
    version("3.8.1", sha256="364f3e2b77cd7dcde83fd7c45219c834e54b0c75e428b6f894a23d12dd41cbfe")
    version("3.4.1", sha256="f941cf1535cd5d1819be5ccae5babef01f6db611f9b5a777bae9c7604b8a92ad")
    version("3.4", sha256="ae7a42df026550b85daca8389b6a60ba6313b0567f374392e54918588a411e94")
    version("3.3", sha256="46942627d5d0ca11720fec18d81fc38f7ef837ea4197c1f630e71ce0d470b11e")
    version("3.2", sha256="ea4283def236413edab5a4cf9cf32adf540c8df1b9b67641cfc2302fca849d97")
    version("2.7.1", sha256="bc71ebd43435537d767799e414fce88e521b7278d48c860651216e1fc6555b40")
    version("2.7", sha256="c294ea133c05382cc2effb1734d49f4abeb1ad8515543a333de49a11422cd4d6")

    depends_on("gmp")
    depends_on("m4", type="build")

    def flag_handler(self, name, flags):
        if name == "cflags":
            flags.append(self.compiler.c99_flag)
        return (flags, None, None)

    def configure_args(self):
        return ["--disable-openssl"]

var/spack/repos/builtin/packages/nettle/package.py
diff --git a/var/spack/repos/builtin/packages/nettle/package.py b/var/spack/repos/builtin/packages/nettle/package.py
index 1ebcd3fc0d8d14..a0262fab2870ab 100644
--- a/var/spack/repos/builtin/packages/nettle/package.py
+++ b/var/spack/repos/builtin/packages/nettle/package.py
@@ -26,7 +26,11 @@ class Nettle(AutotoolsPackage, GNUMirrorPackage):
 
     depends_on("gmp")
     depends_on("m4", type="build")
-    depends_on("openssl")
+
+    def flag_handler(self, name, flags):
+        if name == "cflags":
+            flags.append(self.compiler.c99_flag)
+        return (flags, None, None)
 
     def configure_args(self):
-        return ["CFLAGS={0}".format(self.compiler.c99_flag)]
+        return ["--disable-openssl"]

Installation issue: nettle fails to build due to undocumented openssl dependency?
### Steps to reproduce the issue

```console
$ spack spec -I <spec>
Input spec
--------------------------------
 -   nettle

Concretized
--------------------------------
 -   nettle@3.9.1%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]      ^gmake@4.4.1%gcc@9.2.0~guile build_system=generic arch=linux-centos7-x86_64
[+]      ^gmp@6.2.1%gcc@9.2.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=linux-centos7-x86_64
[+]          ^autoconf@2.69%gcc@9.2.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-centos7-x86_64
[+]              ^perl@5.38.0%gcc@9.2.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=linux-centos7-x86_64
[+]                  ^berkeley-db@18.1.40%gcc@9.2.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-centos7-x86_64
[+]                  ^bzip2@1.0.8%gcc@9.2.0~debug~pic+shared build_system=generic arch=linux-centos7-x86_64
[+]                  ^gdbm@1.23%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]                      ^readline@8.2%gcc@9.2.0 build_system=autotools patches=bbf97f1 arch=linux-centos7-x86_64
[+]                          ^ncurses@6.4%gcc@9.2.0~symlinks+termlib abi=none build_system=autotools arch=linux-centos7-x86_64
[+]                              ^pkgconf@1.9.5%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]                  ^zlib-ng@2.1.4%gcc@9.2.0+compat+opt build_system=autotools arch=linux-centos7-x86_64
[+]          ^automake@1.16.5%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]          ^libtool@2.4.7%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]      ^m4@1.4.19%gcc@9.2.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-centos7-x86_64
[+]          ^diffutils@3.9%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]              ^libiconv@1.17%gcc@9.2.0 build_system=autotools libs=shared,static arch=linux-centos7-x86_64
[+]          ^libsigsegv@2.14%gcc@9.2.0 build_system=autotools arch=linux-centos7-x86_64
```


### Error message

<details><summary>Error message</summary>

<pre>
==> nettle: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j16' 'V=1'
...
     1151    nettle-openssl.o: In function `openssl_md5_init':
  >> 1152    /localData/000scratch/rowanw/spack-stage/spack-stage-nettle-3.9.1-bv6yy4efn7x73ybk5at6bly7tplvvul
             5/spack-src/examples/nettle-openssl.c:408: undefined reference to `EVP_MD_CTX_new'
     1153    nettle-openssl.o: In function `openssl_sha1_init':
  >> 1154    /localData/000scratch/rowanw/spack-stage/spack-stage-nettle-3.9.1-bv6yy4efn7x73ybk5at6bly7tplvvul
             5/spack-src/examples/nettle-openssl.c:409: undefined reference to `EVP_MD_CTX_new'
  >> 1155    collect2: error: ld returned 1 exit status
  >> 1156    make[1]: *** [Makefile:100: nettle-benchmark] Error 1
</pre></details>


### Information on your system

* **Spack:** 0.21.0 (c35700db51bfc673798643697df3ef0e8a5177f1)
* **Python:** 3.8.18
* **Platform:** linux-centos7-ivybridge
* **Concretizer:** clingo

### Additional information

A [quick google](https://stackoverflow.com/questions/46768071/openssl-linking-undefined-reference-evp-md-ctx-new-and-fre) of the error message suggests this is due to linking against an old openssl version, which checks out as I'm running on centos 7 and the default system libcrypto does not include the missing symbol while a newer version does:

```
$ ls -al /lib64/libcrypto.so
lrwxrwxrwx 1 root root 19 Apr 11  2023 /lib64/libcrypto.so -> libcrypto.so.1.0.2k

$ nm --dynamic /lib64/libcrypto.so.1.0.2k |grep EVP_MD_CTX_new

$ nm --dynamic /lib64/libcrypto.so.1.1.1k |grep EVP_MD_CTX_new
000000000015be20 T EVP_MD_CTX_new
```

Obviously spack shouldn't be relying on the system library; the nettle package doesn't specify any kind of dependency on openssl so that seems like a bug.

### 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
