@@ -0,0 +1,114 @@
1+{ stdenv, fetchurl, perl
2+, withCryptodev ? false, cryptodevHeaders }:
3+
4+let
5+ name = "openssl-1.0.2a";
6+
7+ opensslCrossSystem = stdenv.lib.attrByPath [ "openssl" "system" ]
8+ (throw "openssl needs its platform name cross building" null)
9+ stdenv.cross;
10+
11+ patchesCross = isCross: let
12+ isDarwin = stdenv.isDarwin || (isCross && stdenv.cross.libc == "libSystem");
13+ in
14+ [ # Allow the location of the X509 certificate file (the CA
15+ # bundle) to be set through the environment variable
16+ # ‘OPENSSL_X509_CERT_FILE’. This is necessary because the
17+ # default location ($out/ssl/cert.pem) doesn't exist, and
18+ # hardcoding something like /etc/ssl/cert.pem is impure and
19+ # cannot be overriden per-process. For security, the
20+ # environment variable is ignored for setuid binaries.
21+ # FIXME: drop this patch; it really isn't necessary, because
22+ # OpenSSL already supports a ‘SSL_CERT_FILE’ variable.
23+ ./cert-file.patch
24+ ]
25+
26+ ++ stdenv.lib.optionals (isCross && opensslCrossSystem == "hurd-x86")
27+ [ ./cert-file-path-max.patch # merge with `cert-file.patch' eventually
28+ ./gnu.patch # submitted upstream
29+ ]
30+
31+ ++ stdenv.lib.optionals (stdenv.system == "x86_64-kfreebsd-gnu")
32+ [ ./gnu.patch
33+ ./kfreebsd-gnu.patch
34+ ]
35+
36+ ++ stdenv.lib.optional isDarwin ./darwin-arch.patch;
37+
38+ extraPatches = stdenv.lib.optional stdenv.isCygwin ./1.0.1-cygwin64.patch;
39+in
40+
41+stdenv.mkDerivation {
42+ inherit name;
43+
44+ src = fetchurl {
45+ urls = [
46+ "http://www.openssl.org/source/${name}.tar.gz"
47+ "http://openssl.linux-mirror.org/source/${name}.tar.gz"
48+ ];
49+ sha256 = "0jijgzf72659pikms2bc5w31h78xrd1h5zp2r01an2h340y3kdhm";
50+ };
51+
52+ patches = (patchesCross false) ++ extraPatches;
53+
54+ buildInputs = stdenv.lib.optional withCryptodev cryptodevHeaders;
55+
56+ nativeBuildInputs = [ perl ];
57+
58+ # On x86_64-darwin, "./config" misdetects the system as
59+ # "darwin-i386-cc". So specify the system type explicitly.
60+ configureScript =
61+ if stdenv.system == "x86_64-darwin" then "./Configure darwin64-x86_64-cc"
62+ else if stdenv.system == "x86_64-solaris" then "./Configure solaris64-x86_64-gcc"
63+ else "./config";
64+
65+ configureFlags = "shared --libdir=lib --openssldir=etc/ssl" +
66+ stdenv.lib.optionalString withCryptodev " -DHAVE_CRYPTODEV -DUSE_CRYPTODEV_DIGESTS";
67+
68+ # CYGXXX: used to be set for cygwin with optionalString. Not needed
69+ # anymore but kept to prevent rebuild.
70+ preBuild = "";
71+
72+ makeFlags = "MANDIR=$(out)/share/man";
73+
74+ # Parallel building is broken in OpenSSL.
75+ enableParallelBuilding = false;
76+
77+ postInstall =
78+ ''
79+ # If we're building dynamic libraries, then don't install static
80+ # libraries.
81+ if [ -n "$(echo $out/lib/*.so $out/lib/*.dylib)" ]; then
82+ rm $out/lib/*.a
83+ fi
84+ ''; # */
85+
86+ crossAttrs = {
87+ patches = patchesCross true;
88+
89+ preConfigure=''
90+ # It's configure does not like --build or --host
91+ export configureFlags="--libdir=lib --cross-compile-prefix=${stdenv.cross.config}- shared ${opensslCrossSystem}"
92+ '';
93+
94+ postInstall = ''
95+ # Openssl installs readonly files, which otherwise we can't strip.
96+ # This could at some stdenv hash change be put out of crossAttrs, too
97+ chmod -R +w $out
98+
99+ # Remove references to perl, to avoid depending on it at runtime
100+ rm $out/bin/c_rehash $out/ssl/misc/CA.pl $out/ssl/misc/tsget
101+ '';
102+ configureScript = "./Configure";
103+ } // stdenv.lib.optionalAttrs (opensslCrossSystem == "darwin64-x86_64-cc") {
104+ CC = "gcc";
105+ };
106+
107+ meta = {
108+ homepage = http://www.openssl.org/;
109+ description = "A cryptographic library that implements the SSL and TLS protocols";
110+ platforms = stdenv.lib.platforms.all;
111+ maintainers = [ stdenv.lib.maintainers.simons ];
112+ priority = 10; # resolves collision with ‘man-pages’
113+ };
114+}