#
# upx/ucl bash compiler no git version and no zlib1g-dev deps
# by KAPITALSIN B23092021
#
# SCRIPT TESTED UNDER LINUX MINT 19.3 x85_64 GLIBC 2.27 AND ARCOLINUX GLIBC 2.33 x86_64  
#
# NO GIT VERSION
#
# B23092021
# Added -N to wget
# Modified the command "cp -r lib/* ../../ucl-1.03/src/.libs/"
# Minor changes strip and renaming the compiled upx
#
sudo apt-get install libtool g++
wget -N https://github.com/upx/upx/releases/download/v3.96/upx-3.96-src.tar.xz
tar xvfa upx-3.96-src.tar.xz
cd upx-3.96-src
wget -N https://github.com/upx/upx-lzma-sdk/archive/refs/heads/master.zip -O lzmasdk.zip
unzip lzmasdk.zip && rm lzmasdk.zip
mv upx-lzma-sdk-master lzma

wget -N http://www.oberhumer.com/opensource/ucl/download/ucl-1.03.tar.gz
tar xvfa ucl-1.03.tar.gz && rm  ucl-1.03.tar.gz
cd ucl-1.03
export CPPFLAGS="$CPPFLAGS -std=c90 -fPIC"
./configure  --enable-static  --disable-shared
unset CPPFLAGS
make -j$(nproc)
export UPX_UCLDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ../src

wget -N https://fossies.org/linux/misc/zlib-1.2.11.tar.xz
tar xvfa zlib-1.2.11.tar.xz && rm zlib-1.2.11.tar.xz
cd zlib-1.2.11
./configure --static --prefix=$PWD
make -j4 install
cp zconf.h zlib.h   ../../ucl-1.03/src/
cp zconf.h zlib.h   ../../ucl-1.03/include
cp -r lib/* ../../ucl-1.03/src/.libs/
cd ..


sed -i 's/$(CHECK_WHITESPACE)//g' Makefile
rm -rf lzma-sdk
cp -r ../lzma lzma-sdk
make -j$(nproc) LDFLAGS="--static"
strip upx.out
mv upx.out ../../upx.396.bin
unset UPX_UCLDIR
