#!/bin/bash

package=openssl
#version=-1.0.0b
version=-1.1.1k

progname=$0

source ../cascade-make/lib/cascade-lib.bash GEXTSVN ../.. $*

prefix=$GEXTSVN_INSTALLED

opt_run_untar $force_untar $auto_untar $package $version

# To compile subversion for 32 bit, we need to run the internal configure
# and tell it that it's for 32 bit, as follows (command from Gemini that worked):
#     ./Configure linux-generic32 -m32
# For 64 bit, the default wrapper ./config is run which runs the underlying
# ./Configure with the determined bitness settings (but it gets it wrong for our
# 32 bit LSB emulation and manylinux 32 bit where the kernel is still 64 bit).
# To detect whether we're 32 or 64 bit is a bit tricky, as uname -m doesn't suffice here:
# The manylinux 32 bit docker container also returns x86_64 despite being 32 bit
# And the docker's "hostname" is randomised, so to detect bitness, Gemini suggested 2 ways:
# 1.    file -L /bin/bash
# For manylinux and LSB environments set up for 32 bit (even if the kernel is still 64 bit
# that is, even if uname -m still returns x86_64 indicating 64 bit), we'd see;
#    /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=b61e56abf197f842f01f7c7316bdf320b872f99b, stripped
# OR:
# 2.    getconf LONG_BIT
# For a 32 bit LSB/manylinux setup we'd see it return:
#    32
# We're going with the 2nd test as the answer is more straightforward
# And I've confirmed we see 64 on 64 bit LSB and manylinux vs it returning
# 32 on 32 bit LSB environment and manylinux docker container.
true_bitness_info=`getconf LONG_BIT`

#opt_run_configure $force_config $auto_config $package $version $prefix
if [ $force_config = 1 ] ; then
    if [ "$true_bitness_info" = "32" ]; then
	echo "@@@@ Configuring OpenSSL specially for 32 bit with: /Configure linux-generic32 -m32 --prefix=$prefix --openssldir=$prefix shared"
	(cd $package$version ; ./Configure linux-generic32 -m32 --prefix=$prefix --openssldir=$prefix shared)
    else
	(cd $package$version ; ./config --prefix=$prefix shared)
    fi
fi

opt_run_make $compile   $package $version
opt_run_make $install   $package $version "install_sw"
opt_run_make $clean     $package $version "clean"
opt_run_make $distclean $package $version "distclean"

opt_run_tarclean $tarclean $package $version




