# Description: Secure Sockets Layer and Transport Layer Security tools
# URL: https://www.openssl.org/
# Maintainer: Tim Biermann, tbier at posteo dot de

name=openssl11
version=1.1.1w
release=1
source=(https://www.openssl.org/source/${name:0:7}-$version.tar.gz \
  no-rpath.patch openssl-1.0-versioned-symbols.patch)

build() {
  cd ${name:0:7}-$version
  #export MAKEFLAGS="$MAKEFLAGS -j1"

  ./Configure --prefix=/usr \
    --openssldir=/etc/ssl \
    --libdir=lib/openssl-1.1 \
    shared \
    enable-ec_nistp_64_gcc_128 linux-x86_64

  sed -i "s|-O3|$CFLAGS|" Makefile

  make depend
  make
  make DESTDIR=$PKG LIBDIR=lib/openssl-1.1 MANDIR=/usr/share/man MANSUFFIX=ssl install_sw

  find $PKG -name "*fips*" -delete
  chmod -R +w $PKG

  install -m755 -d "$PKG/usr/include/openssl-1.1"
  #mv "$PKG/etc/ssl" "$PKG/etc/ssl-1.1"
  mv "$PKG/usr/include/openssl" "$PKG/usr/include/openssl-1.1/"
  mv "$PKG/usr/lib/openssl-1.1/libcrypto.so.1.1" "$PKG/usr/lib/"
  mv "$PKG/usr/lib/openssl-1.1/libssl.so.1.1" "$PKG/usr/lib/"
  ln -sf ../libssl.so.1.1 "$PKG/usr/lib/openssl-1.1/libssl.so"
  ln -sf ../libcrypto.so.1.1 "$PKG/usr/lib/openssl-1.1/libcrypto.so"
  mv "$PKG/usr/bin/openssl" "$PKG/usr/bin/openssl-1.1"
  mv "$PKG/usr/bin/c_rehash" "$PKG/usr/bin/c_rehash-1.1"

  # Update includedir in .pc files
  sed -e 's|/include$|/include/openssl-1.1|' -i $PKG/usr/lib/openssl-1.1/pkgconfig/*.pc

  #rm -rf $PKG/{etc,usr/bin/c_rehash}
}
