#!/bin/sh

. config/options

export MAKEFLAGS=-j1

case $TARGET_ARCH in
  i386)
    TARGET=linux-elf
    ;;
  x86_64)
    TARGET=linux-x86_64
    ;;
  powerpc)
    TARGET=linux-ppc
    ;;
  powerpc64)
    TARGET=linux-ppc64
    ;;
  arm)
    TARGET=linux-armv4
    ;;
  mips)
    TARGET=linux-generic32
    ;;
esac

FEATURES="zlib-dynamic threads shared no-idea no-mdc2 no-rc5 no-krb5 -DHAVE_CRYPTODEV"

cd $BUILD/$1*

./Configure $FEATURES --prefix=/usr --openssldir=/etc/ssl $TARGET
make CC=$CC LD=$LD RANLIB=$RANLIB all build-shared
make CC=$CC LD=$LD RANLIB=$RANLIB do_linux-shared

install_dir="`pwd`/.install"
install_dir_debug="`pwd`/.install-debuginfo"
mkdir -p $install_dir
make CC=$CC LD=$LD RANLIB=$RANLIB INSTALL_PREFIX="$install_dir" install_sw

# fix library dir for 64bit archs
if [ "$TARGET_ARCH" = x86_64 -o "$TARGET_ARCH" = powerpc64 ]; then
  mv $install_dir/usr/lib64 $install_dir/usr/lib
  sed -i 's/lib64/lib/g' $install_dir/usr/lib/pkgconfig/*.pc
fi

# remove static libs, we don't want them
rm -f $install_dir/usr/lib/*.a

# fix libraries permissions
find $install_dir -type f -name "*.so*" | xargs chmod u+w

fix_libs $install_dir
strip_libs $install_dir $install_dir_debug
