#!/bin/sh
# test we are root
if [ "$(id -u)" != "0" ]; then
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe "

P=x265-41
SRC=x265_4.1
USER=`cat /etc/sysconfig/tcuser`
LIST="submitqc compiletc cmake nasm "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
/usr/local/bin/wget -nc --no-check-certificate \
https://bitbucket.org/multicoreware/x265_git/downloads/x265_4.1.tar.gz
tar xvf x265*
cd $SRC/build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=TRUE ../source
make -j6 # 1m 40s
make install DESTDIR=/tmp/$P
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib
mv $P/usr/local/lib/*a $P-dev/usr/local/lib

# main
#######
strip --strip-unneeded $P/usr/local/bin/*
strip --strip-unneeded $P/usr/local/lib/*
mkdir -p $P/usr/local/share/doc/$P/
echo 'GPL v 2 ' > $P/usr/local/share/doc/$P/COPYING

# TCZ them
###########
LIST2="$P $P-dev "
for Z in $LIST2
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          x265-41-dev.tcz
Description:    dev files
Version:        4.1
Author:         MulticoreWare
Original-site:  https://bitbucket.org/multicoreware/x265_git/downloads/
Copying-policy: GPL v2
Size:           2.2M
Extension_by:   aus9 
Tags:           video encoder h265
Comments:       Development
                May conflict with x265-dev

Change-log:     2026/01/15 v 4.1 on 17x
Current:        2026/01/15 ' > $P-dev.tcz.info
echo 'x265-41.tcz' > $P-dev.tcz.dep 

echo 'Title:          x265-41.tcz
Description:    h265 encoder
Version:        4.1
Author:         MulticoreWare
Original-site:  https://bitbucket.org/multicoreware/x265_git/downloads/
Copying-policy: GPL v2 
Size:           1.9M 
Extension_by:   aus9 
Tags:           video encoder h265
Comments:       May conflict with x265
                for encoding video streams into the H265/HEVC format
                The executable is x265

Change-log:     2026/01/15 v 4.1 on 17x
Current:        2026/01/15 ' > $P.tcz.info 
readelf -d $P/usr/local/bin/* | grep 'NEEDED'
# libx265.so.215 this TCE
# libmvec.so.1   glibc_add_lib.tcz
echo 'glibc_add_lib.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync
  
