Diff

Differences From Artifact [82518c6710]:

To Artifact [5e536572e7]:


     1      1   #! /usr/bin/env bash
     2      2   
     3         -if [ ! -f 'build.sh' ]; then
     4         -	echo 'ERROR: This script must be run from the directory it is in' >&2
            3  +# BuildCompatible: KitCreator
     5      4   
     6         -	exit 1
     7         -fi
     8         -if [ -z "${TCLVERS}" ]; then
     9         -	echo 'ERROR: The TCLVERS environment variable is not set' >&2
    10         -
    11         -	exit 1
    12         -fi
    13         -
    14         -TLSVERS="1.6.7"
    15         -SRC="src/tls-${TLSVERS}.tar.gz"
    16         -SRCURL="http://sourceforge.net/projects/tls/files/tls/${TLSVERS}/tls${TLSVERS}-src.tar.gz"
    17         -SRCHASH='5119de3e5470359b97a8a00d861c9c48433571ee0167af0a952de66c99d3a3b8'
    18         -BUILDDIR="$(pwd)/build/tls${TLSVERS}"
    19         -OUTDIR="$(pwd)/out"
    20         -INSTDIR="$(pwd)/inst"
    21         -PATCHDIR="$(pwd)/patches"
    22         -export TLSVERS SRC SRCURL BUILDDIR OUTDIR INSTDIR PATCHDIR
    23         -
    24         -# Set configure options for this sub-project
    25         -LDFLAGS="${LDFLAGS} ${KC_TLS_LDFLAGS}"
    26         -CFLAGS="${CFLAGS} ${KC_TLS_CFLAGS}"
    27         -CPPFLAGS="${CPPFLAGS} ${KC_TLS_CPPFLAGS}"
    28         -LIBS="${LIBS} ${KC_TLS_LIBS}"
    29         -export LDFLAGS CFLAGS CPPFLAGS LIBS
    30         -
    31         -rm -rf 'build' 'out' 'inst'
    32         -mkdir 'build' 'out' 'inst' || exit 1
    33         -
    34         -TCL_VERSION="unknown"
    35         -if [ -f "${TCLCONFIGDIR}/tclConfig.sh" ]; then
    36         -        source "${TCLCONFIGDIR}/tclConfig.sh"
    37         -fi
    38         -export TCL_VERSION
    39         -
    40         -if [ ! -f "${SRC}" ]; then
    41         -	mkdir 'src' >/dev/null 2>/dev/null
    42         -
    43         -	if [ ! -d 'buildsrc' ]; then
    44         -		download "${SRCURL}" "${SRC}" "${SRCHASH}" || exit 1
    45         -	fi
    46         -fi
            5  +version="1.6.7"
            6  +url="http://sourceforge.net/projects/tls/files/tls/${TLSVERS}/tls${TLSVERS}-src.tar.gz"
            7  +sha256='5119de3e5470359b97a8a00d861c9c48433571ee0167af0a952de66c99d3a3b8'
    47      8   
    48      9   function buildSSLLibrary() {
    49     10   	local version url hash
    50     11   	local archive
    51     12   
    52     13   	version='2.4.1'
    53     14   	url="http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${version}.tar.gz"
................................................................................
    54     15   	hash='121922b13169cd47a85e3e77f0bc129f8d04247193b42491cb1fab9074e80477'
    55     16   
    56     17   	archive="src/libressl-${version}.tar.gz"
    57     18   
    58     19   	echo " *** Building LibreSSL v${version}" >&2
    59     20   
    60     21   	if [ ! -e "../${archive}" ]; then
    61         -		download "${url}" "../${archive}" "${hash}" || return 1
           22  +		"${_download}" "${url}" "../${archive}" "${hash}" || return 1
    62     23   	fi
    63     24   
    64     25   	(
    65     26   		rm -rf libressl-*
    66     27   
    67     28   		gzip -dc "../${archive}" | tar -xf - || exit 1
    68     29   
................................................................................
    75     36   		${MAKE:-make} V=1 || exit 1
    76     37   
    77     38   		echo "Running: ${MAKE:-make} V=1 install" 
    78     39   		${MAKE:-make} V=1 install || exit 1
    79     40   	) || return 1
    80     41   
    81     42   	SSLDIR="$(pwd)/libressl-${version}/INST"
    82         -	addlibs="$(PKG_CONFIG_PATH="$(pwd)/libressl-${version}/INST/lib/pkgconfig" "${PKG_CONFIG:-pkg-config}" libssl libcrypto --libs --static)"
           43  +	addlibs_LOCALSSL="$(PKG_CONFIG_PATH="${SSLDIR}/lib/pkgconfig" "${PKG_CONFIG:-pkg-config}" libssl libcrypto --libs --static)"
    83     44   }
    84     45   
    85         -(
    86         -	cd 'build' || exit 1
    87         -
    88         -	if [ ! -d '../buildsrc' ]; then
    89         -		gzip -dc "../${SRC}" | tar -xf -
    90         -	else    
    91         -		cp -rp ../buildsrc/* './'
    92         -	fi
    93         -
           46  +function preconfigure() {
    94     47   	# Determine SSL directory
    95     48   	if [ -z "${CPP}" ]; then
    96     49   		CPP="${CC:-cc} -E"
    97     50   	fi
    98     51   
    99     52   	if [ -n "${KC_TLS_SSLDIR}" ]; then
   100     53   		SSLDIR="${KC_TLS_SSLDIR}"
................................................................................
   108     61   		if [ -z "${SSLDIR}" ]; then
   109     62   			buildSSLLibrary || SSLDIR=''
   110     63   		fi
   111     64   
   112     65   		if [ -z "${SSLDIR}" ]; then
   113     66   			echo "Unable to find OpenSSL, aborting." >&2
   114     67   
   115         -			exit 1
           68  +			return 1
   116     69   		fi
   117     70   	fi
   118     71   
   119         -	# Apply required patches
   120         -	cd "${BUILDDIR}" || exit 1
   121         -	for patch in "${PATCHDIR}/all"/tls-${TLSVERS}-*.diff "${PATCHDIR}/${TCL_VERSION}"/tls-${TLSVERS}-*.diff; do
   122         -		if [ ! -f "${patch}" ]; then
   123         -			continue
   124         -		fi
   125         -
   126         -		echo "Applying: ${patch}"
   127         -		${PATCH:-patch} -p1 < "${patch}"
   128         -	done
   129         -
   130         -	cd "${BUILDDIR}" || exit 1
   131         -
   132         -	# Try to build as a shared object if requested
   133         -	if [ "${STATICTLS}" = "0" ]; then
   134         -		tryopts="--enable-shared --disable-shared"
   135         -	elif [ "${STATICTLS}" = "-1" ]; then
   136         -		tryopts="--enable-shared"
   137         -	else
   138         -		tryopts="--disable-shared"
   139         -	fi
   140         -
   141     72   	# Disable SSLv2, newer SSL libraries drop support for it entirely
   142     73   	CFLAGS="${CFLAGS} -DNO_SSL2=1"
   143     74   
   144     75   	# Disable SSLv3, newer SSL libraries drop support for it entirely
   145     76   	CFLAGS="${CFLAGS} -DNO_SSL3=1"
   146     77   
   147         -	SAVE_CFLAGS="${CFLAGS}"
   148         -	SAVE_LIBS="${LIBS}"
   149         -	for tryopt in $tryopts __fail__; do
   150         -		CFLAGS="${SAVE_CFLAGS}"
   151         -		LIBS="${SAVE_LIBS}"
   152         -		export CFLAGS LIBS
           78  +}
           79  +
           80  +function postconfigure() {
           81  +	local linkaddfile
           82  +	local addlibs
           83  +
           84  +	# Determine SSL library directory
           85  +	SSL_LIB_DIR="$(${MAKE:-make} --print-data-base | awk '/^SSL_LIB_DIR = /{ print }' | sed 's@^SSL_LIB_DIR = *@@')"
   153     86   
   154         -		# Clean up, if needed
   155         -		make distclean >/dev/null 2>/dev/null
   156         -		rm -rf "${INSTDIR}"
   157         -		mkdir "${INSTDIR}"
           87  +	echo "SSL_LIB_DIR = ${SSL_LIB_DIR}"
           88  +}
   158     89   
   159         -		if [ "${tryopt}" = "__fail__" ]; then
   160         -			exit 1
   161         -		fi
   162         -
   163         -		if [ "${tryopt}" == "--enable-shared" ]; then
   164         -			isshared="1"
   165         -		else
   166         -			isshared="0"
   167         -		fi
   168         -
   169         -		# If building a shared TLS, add the LINKADD libraries here
   170         -		if [ "${isshared}" = '1' ]; then
   171         -			LIBS="${LIBS} ${KC_TLS_LINKADD}"
   172         -		fi
   173         -
   174         -		# If build a static TLS for KitDLL, ensure that we use PIC
   175         -		# so that it can be linked into the shared object
   176         -		if [ "${isshared}" = "0" -a "${KITTARGET}" = "kitdll" ]; then
   177         -			CFLAGS="${CFLAGS} -fPIC"
   178         -		fi
   179         -
   180         -		if [ "${isshared}" = '0' ]; then
   181         -			sed 's@USE_TCL_STUBS@XXX_TCL_STUBS@g' configure > configure.new
   182         -		else
   183         -			sed 's@XXX_TCL_STUBS@USE_TCL_STUBS@g' configure > configure.new
   184         -		fi
   185         -		cat configure.new > configure
   186         -		rm -f configure.new
   187         -
   188         -		(
   189         -			echo "Running: ./configure $tryopt --prefix=\"${INSTDIR}\" --exec-prefix=\"${INSTDIR}\" --libdir=\"${INSTDIR}/lib\" --with-tcl=\"${TCLCONFIGDIR}\" --with-ssl-dir=\"${SSLDIR}\" ${CONFIGUREEXTRA}"
   190         -			./configure $tryopt --prefix="${INSTDIR}" --exec-prefix="${INSTDIR}" --libdir="${INSTDIR}/lib" --with-tcl="${TCLCONFIGDIR}" --with-ssl-dir="${SSLDIR}" ${CONFIGUREEXTRA}
   191         -
   192         -			echo "Running: ${MAKE:-make} tcllibdir=\"${INSTDIR}/lib\" AR=\"${AR:-ar}\" RANLIB=\"${RANLIB:-ranlib}\""
   193         -			${MAKE:-make} tcllibdir="${INSTDIR}/lib" AR="${AR:-ar}" RANLIB="${RANLIB:-ranlib}" || exit 1
   194         -
   195         -			echo "Running: ${MAKE:-make} tcllibdir=\"${INSTDIR}/lib\" AR=\"${AR:-ar}\" RANLIB=\"${RANLIB:-ranlib}\" install"
   196         -			${MAKE:-make} tcllibdir="${INSTDIR}/lib" AR="${AR:-ar}" RANLIB="${RANLIB:-ranlib}" install || exit 1
   197         -		) || continue
   198         -
   199         -		# Determine SSL library directory
   200         -		SSL_LIB_DIR="$(${MAKE:-make} --print-data-base | awk '/^SSL_LIB_DIR = /{ print }' | sed 's@^SSL_LIB_DIR = *@@')"
   201         -
   202         -		echo "SSL_LIB_DIR = ${SSL_LIB_DIR}"
   203         -
   204         -		break
   205         -	done
   206         -
           90  +function postinstall() {
   207     91   	# Create pkgIndex if needed
   208         -	if [ ! -e "${INSTDIR}/lib/tls${TLSVERS}/pkgIndex.tcl" ]; then
   209         -		cat << _EOF_ > "${INSTDIR}/lib/tls${TLSVERS}/pkgIndex.tcl"
   210         -package ifneeded tls ${TLSVERS} \
           92  +	if [ ! -e "${installdir}/lib/tls${version}/pkgIndex.tcl" ]; then
           93  +		cat << _EOF_ > "${installdir}/lib/tls${version}/pkgIndex.tcl"
           94  +package ifneeded tls ${version} \
   211     95       "[list source [file join \$dir tls.tcl]] ; \
   212     96        [list load {} tls]"
   213     97   _EOF_
   214     98   	fi
   215     99   
   216    100   	# Determine name of static object
   217         -	LINKADDFILE="$(find "${INSTDIR}" -name '*.a' | head -n 1)"
   218         -	if [ -n "${LINKADDFILE}" ]; then
   219         -		LINKADDFILE="${LINKADDFILE}.linkadd"
          101  +	linkaddfile="$(find "${installdir}" -name '*.a' | head -n 1)"
          102  +	if [ -n "${linkaddfile}" ]; then
          103  +		linkaddfile="${linkaddfile}.linkadd"
   220    104   
   221         -		## XXX: TODO: Determine what we actually need to link against
          105  +		if [ -n "${addlibs_LOCALSSL}" ]; then
          106  +			addlibs="${addlibs_LOCALSSL}"
          107  +		fi
          108  +
   222    109   		if [ -z "${addlibs}" ]; then
   223    110   			if [ "${KC_TLS_LINKSSLSTATIC}" = '1' ]; then
   224    111   				addlibs="$("${PKG_CONFIG:-pkg-config}" libssl libcrypto --libs --static)"
   225    112   			else
   226    113   				addlibs="$("${PKG_CONFIG:-pkg-config}" libssl libcrypto --libs)"
   227    114   			fi
   228    115   		fi
................................................................................
   234    121   
   235    122   		addlibs="${addlibs} ${KC_TLS_LINKADD}"
   236    123   
   237    124   		if [ "${KC_TLS_LINKSSLSTATIC}" = '1' ]; then
   238    125   			echo "-Wl,-Bstatic ${addlibs} ${addlibs_staticOnly} -Wl,-Bdynamic"
   239    126   		else
   240    127   			echo "${addlibs}"
   241         -		fi > "${LINKADDFILE}"
          128  +		fi > "${linkaddfile}"
   242    129   	fi
   243         -
   244         -	# Install files needed by installation
   245         -	cp -r "${INSTDIR}/lib" "${OUTDIR}" || exit 1
   246         -	find "${OUTDIR}" -name '*.a' -type f | xargs -n 1 rm -f --
   247         -
   248         -	exit 0
   249         -) || exit 1
   250         -
   251         -exit 0
          130  +}