From 49654daa6b1ecf2126154466a9fccef4fc7ec2f5 Mon Sep 17 00:00:00 2001
From: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Date: Mon, 3 Dec 2018 18:37:36 +0000
Subject: Checking Mac OS host for configuring OpenSSL

OpenSSL can't automatically detect the architecture of Mac OS systems, so
as it suggests on its Wiki, it needs some help for doing that. With this
commit, we are checking the build on Mac OS with the presence of `otool'
(Mac OS's linker). If it's there, we'll add the OpenSSL configuration
options suggested by OpenSSL's Wiki.
---
 configure                                      | 19 ++++++++++++++++++-
 reproduce/src/make/dependencies-basic.mk       | 12 ++++++++++++
 reproduce/src/make/dependencies-build-rules.mk |  4 ++--
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index 2dfd3d3..31d5eb7 100755
--- a/configure
+++ b/configure
@@ -630,6 +630,22 @@ fi
 
 
 
+# If we are on a Mac OS system
+# ----------------------------
+#
+# For the time being, we'll use the existance of `otool' to see if we are
+# on a Mac OS system or not. Some tools (for example OpenSSL) need to know
+# this.
+if type otool > /dev/null 2>/dev/null; then
+    on_mac_os=yes
+else
+    on_mac_os=no
+fi
+
+
+
+
+
 # Build Basic dependencies
 # ------------------------
 #
@@ -642,9 +658,10 @@ if which nproc > /dev/null 2>/dev/null; then numthreads=$(nproc --all);
 else                                         numthreads=2;
 fi
 make -f reproduce/src/make/dependencies-basic.mk \
-     static_build=$static_build                  \
      rpath_command=$rpath_command                \
+     static_build=$static_build                  \
      needs_ldl=$needs_ldl                        \
+     on_mac_os=$on_mac_os                        \
      #-j$numthreads
 
 
diff --git a/reproduce/src/make/dependencies-basic.mk b/reproduce/src/make/dependencies-basic.mk
index ceaa0f3..ea59566 100644
--- a/reproduce/src/make/dependencies-basic.mk
+++ b/reproduce/src/make/dependencies-basic.mk
@@ -333,8 +333,20 @@ $(ilidir)/zlib: $(tdir)/zlib-$(zlib-version).tar.gz \
 $(ilidir)/openssl: $(tdir)/openssl-$(openssl-version).tar.gz         \
                    $(tdir)/cert.pem                                  \
                    $(ilidir)/zlib | $(idir)/etc
+        # According to OpenSSL's Wiki (link bellow), it can't automatically
+        # detect Mac OS's structure. It will need some help. So we'll use
+        # the `on_mac_os' Make variable that we defined in the configure
+        # script and help it with some extra configuration options and an
+        # environment variable.
+        #
+        # https://wiki.openssl.org/index.php/Compilation_and_Installation
+	if [ x$(on_mac_os) = xyes ]; then                            \
+	  export KERNEL_BITS=64;                                     \
+	  copt="shared no-ssl2 no-ssl3 enable-ec_nistp_64_gcc_128";  \
+	fi;                                                          \
 	$(call gbuild, $<, openssl-$(openssl-version), ,             \
                        zlib                                          \
+	               $$copt                                        \
                        $(rpath_command)                              \
                        --openssldir=$(idir)/etc/ssl                  \
 	               --with-zlib-lib=$(ildir)                      \
diff --git a/reproduce/src/make/dependencies-build-rules.mk b/reproduce/src/make/dependencies-build-rules.mk
index af2be95..4de9a4e 100644
--- a/reproduce/src/make/dependencies-build-rules.mk
+++ b/reproduce/src/make/dependencies-build-rules.mk
@@ -72,8 +72,8 @@ gbuild = if [ x$(static_build) = xyes ] && [ $(3)x = staticx ]; then          \
 	   mv tmp-$$confscript $$confscript;                                  \
 	   chmod +x $$confscript;                                             \
 	   shellop="SHELL=$(ibdir)/bash";                                     \
-	 elif [ -f /bin/bash     ]; then shellop="SHELL=/bin/bash";           \
-	 else                            shellop="SHELL=/bin/sh";             \
+	 elif [ -f /bin/bash ]; then shellop="SHELL=/bin/bash";               \
+	 else shellop="SHELL=/bin/sh";                                        \
 	 fi;                                                                  \
                                                                               \
 	 if [ x"$(2)" = x"zlib-$(zlib-version)" ]; then                       \
-- 
cgit v1.2.1