From f5ca504a390b8db3432dc7d67f934cd29daf3086 Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Wed, 29 Apr 2015 00:50:34 +0200
Subject: [PATCH 1/7] add openssl recipe

---
 recipes/openssl/__init__.py | 49 +++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 recipes/openssl/__init__.py

diff --git a/recipes/openssl/__init__.py b/recipes/openssl/__init__.py
new file mode 100644
index 0000000..a0d5140
--- /dev/null
+++ b/recipes/openssl/__init__.py
@@ -0,0 +1,49 @@
+from toolchain import Recipe, shprint
+from os.path import join, exists
+import sh
+import os
+
+
+arch_mapper = {'i386': 'darwin-i386-cc',
+               'x86_64': 'darwin64-x86_64-cc',
+               'armv7': 'iphoneos-cross',
+               'arm64': 'iphoneos-cross'}
+
+
+class OpensslRecipe(Recipe):
+    version = "1.0.2a"
+    url = "http://www.openssl.org/source/openssl-{version}.tar.gz"
+    libraries = ["libssl.a", "libcrypto.a"]
+    include_dir = "include"
+    include_per_arch = True
+
+    def build_arch(self, arch):
+        options_iphoneos = (
+            "-isysroot {}".format(arch.sysroot),
+            "-DOPENSSL_THREADS",
+            "-D_REENTRANT",
+            "-DDSO_DLFCN",
+            "-DHAVE_DLFCN_H",
+            "-fomit-frame-pointer",
+            "-fno-common",
+            "-O3"
+        )
+        build_env = arch.get_env()
+        target = arch_mapper[arch.arch]
+        shprint(sh.env, _env=build_env)
+        sh.perl(join(self.build_dir, "Configure"),
+                target,
+                _env=build_env)
+        if target == 'iphoneos-cross':
+            sh.sed("-ie", "s!^CFLAG=.*!CFLAG={} {}!".format(build_env['CFLAGS'],
+                   " ".join(options_iphoneos)),
+                   "Makefile")
+            sh.sed("-ie", "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;! ",
+                   "crypto/ui/ui_openssl.c")
+        else:
+            sh.sed("-ie", "s!^CFLAG=!CFLAG={} !".format(build_env['CFLAGS']),
+                   "Makefile")
+        shprint(sh.make, "clean")
+        shprint(sh.make, "-j4", "build_libs")
+
+recipe = OpensslRecipe()

From 4c14123e531935dc528bb56ff1ce14c9be7bffbe Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Wed, 29 Apr 2015 02:44:29 +0200
Subject: [PATCH 2/7] add openssl dependency to python

maybe this should be optional?
---
 recipes/python/ModulesSetup | 2 ++
 recipes/python/__init__.py  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/recipes/python/ModulesSetup b/recipes/python/ModulesSetup
index 567de4b..02db3c5 100644
--- a/recipes/python/ModulesSetup
+++ b/recipes/python/ModulesSetup
@@ -50,3 +50,5 @@ pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Mo
 
 # Future (used by numpy)
 future_builtins future_builtins.c
+
+_ssl _ssl.c -DUSE_SSL -lssl -lcrypto
diff --git a/recipes/python/__init__.py b/recipes/python/__init__.py
index 0c40576..2e0b3a3 100644
--- a/recipes/python/__init__.py
+++ b/recipes/python/__init__.py
@@ -7,7 +7,7 @@ import os
 class PythonRecipe(Recipe):
     version = "2.7.1"
     url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
-    depends = ["hostpython", "libffi", ]
+    depends = ["hostpython", "libffi", "openssl"]
     library = "libpython2.7.a"
     pbx_libraries = ["libz", "libbz2", "libsqlite3"]
 

From a241a524b14b410273792b86859e47051ca3f205 Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Fri, 12 Jun 2015 14:13:08 +0200
Subject: [PATCH 3/7] update openssl version

---
 recipes/openssl/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/recipes/openssl/__init__.py b/recipes/openssl/__init__.py
index a0d5140..d724bbc 100644
--- a/recipes/openssl/__init__.py
+++ b/recipes/openssl/__init__.py
@@ -11,7 +11,7 @@ arch_mapper = {'i386': 'darwin-i386-cc',
 
 
 class OpensslRecipe(Recipe):
-    version = "1.0.2a"
+    version = "1.0.2b"
     url = "http://www.openssl.org/source/openssl-{version}.tar.gz"
     libraries = ["libssl.a", "libcrypto.a"]
     include_dir = "include"

From 87d2c8b9fc90e44faad6969c1cb1926efde8b037 Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Fri, 12 Jun 2015 14:14:38 +0200
Subject: [PATCH 4/7] don't enforce python to compile SSL

---
 recipes/python/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/recipes/python/__init__.py b/recipes/python/__init__.py
index 2e0b3a3..0c40576 100644
--- a/recipes/python/__init__.py
+++ b/recipes/python/__init__.py
@@ -7,7 +7,7 @@ import os
 class PythonRecipe(Recipe):
     version = "2.7.1"
     url = "https://www.python.org/ftp/python/{version}/Python-{version}.tar.bz2"
-    depends = ["hostpython", "libffi", "openssl"]
+    depends = ["hostpython", "libffi", ]
     library = "libpython2.7.a"
     pbx_libraries = ["libz", "libbz2", "libsqlite3"]
 

From 07d9c4fa2b1cfc3d312f009e4709babba2a64be3 Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Sun, 14 Jun 2015 19:50:28 +0200
Subject: [PATCH 5/7] update openssl version to 1.0.2c

---
 recipes/openssl/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/recipes/openssl/__init__.py b/recipes/openssl/__init__.py
index d724bbc..752ef13 100644
--- a/recipes/openssl/__init__.py
+++ b/recipes/openssl/__init__.py
@@ -11,7 +11,7 @@ arch_mapper = {'i386': 'darwin-i386-cc',
 
 
 class OpensslRecipe(Recipe):
-    version = "1.0.2b"
+    version = "1.0.2c"
     url = "http://www.openssl.org/source/openssl-{version}.tar.gz"
     libraries = ["libssl.a", "libcrypto.a"]
     include_dir = "include"

From 8b1c94153de83ff121077bab9567932b9a4d387d Mon Sep 17 00:00:00 2001
From: Ben Hagen <c.ben.hagen@gmail.com>
Date: Wed, 15 Jul 2015 17:54:40 +0200
Subject: [PATCH 6/7] update openssl version to 1.0.2d

---
 recipes/openssl/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/recipes/openssl/__init__.py b/recipes/openssl/__init__.py
index 752ef13..38a27f2 100644
--- a/recipes/openssl/__init__.py
+++ b/recipes/openssl/__init__.py
@@ -11,7 +11,7 @@ arch_mapper = {'i386': 'darwin-i386-cc',
 
 
 class OpensslRecipe(Recipe):
-    version = "1.0.2c"
+    version = "1.0.2d"
     url = "http://www.openssl.org/source/openssl-{version}.tar.gz"
     libraries = ["libssl.a", "libcrypto.a"]
     include_dir = "include"

From 296d331935a9208ff4292acef697db3c25134017 Mon Sep 17 00:00:00 2001
From: akshayaurora <akshayaurora@gmail.com>
Date: Fri, 7 Aug 2015 22:44:44 +0530
Subject: [PATCH 7/7] Python recipe: Make openssl module optional

---
 recipes/python/ModulesSetup         | 1 -
 recipes/python/ModulesSetup.openssl | 1 +
 recipes/python/__init__.py          | 2 ++
 3 files changed, 3 insertions(+), 1 deletion(-)
 create mode 100644 recipes/python/ModulesSetup.openssl

diff --git a/recipes/python/ModulesSetup b/recipes/python/ModulesSetup
index 2504628..d4f936d 100644
--- a/recipes/python/ModulesSetup
+++ b/recipes/python/ModulesSetup
@@ -52,4 +52,3 @@ pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Mo
 # Future (used by numpy)
 future_builtins future_builtins.c
 
-_ssl _ssl.c -DUSE_SSL -lssl -lcrypto
diff --git a/recipes/python/ModulesSetup.openssl b/recipes/python/ModulesSetup.openssl
new file mode 100644
index 0000000..331ec43
--- /dev/null
+++ b/recipes/python/ModulesSetup.openssl
@@ -0,0 +1 @@
+_ssl _ssl.c -DUSE_SSL -lssl -lcrypto
diff --git a/recipes/python/__init__.py b/recipes/python/__init__.py
index b200a28..7cf875d 100644
--- a/recipes/python/__init__.py
+++ b/recipes/python/__init__.py
@@ -30,6 +30,8 @@ class PythonRecipe(Recipe):
         self.apply_patch("xcompile.patch")
         self.apply_patch("setuppath.patch")
         self.append_file("ModulesSetup.mobile", "Modules/Setup.local")
+        if "openssl.build_all" in self.ctx.state:
+             self.append_file("ModulesSetup.openssl", 'Modules/Setup.local')
 
         self.set_marker("patched")