#!/bin/bash

U=$(readlink -n -f ./usr/)

pushd ./upx-src/
 export LD=mold
 export CCLD=mold
 export CC="mold -run gcc"
 export CFLAGS="-flto -ffast-math -O4 -fPIE -pie -fomit-frame-pointer -funroll-loops -fforce-addr -falign-functions=4 -msse4a"
 export CXXFLAGS="-flto -ffast-math -O4 -fPIE -pie -fomit-frame-pointer -funroll-loops -fforce-addr -falign-functions=4 -msse4a"

 cp ./doc/upx.1 ../upxfromgit.1

 rm -r -f b
 mkdir b
 pushd b
  cmake -DCMAKE_INSTALL_PREFIX=/usr ..
  make
  mv ./upx $U/bin/upxfromgit
  make clean
 popd

popd