#!/bin/bash
# test we are root
if [ "$(id -u)" != "0" ]; then
   echo "run as root now exitting"
   exit 1
fi

export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe"
export LDFLAGS="-Wl,-O1" 

P=slurp
SRC=$P-src
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc meson wayland-dev cairo-dev \
scdoc-dev git libxkbcommon-dev"
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "git clone https://github.com/emersion/slurp.git" $USER
mv $P $SRC
cd $SRC
# meson defaults to usr/local
meson --strip build
ninja -C build
touch /tmp/mark
ninja -C build install
cd /tmp

# main
######
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/LICENSE  $P/usr/local/share/doc/$P/
mkdir -p $P/usr/local/bin
mv /usr/local/bin/$P* $P/usr/local/bin

# doc
#####
mkdir -p $P-doc/usr/local/share/man/man1
cp $SRC/build/*.1 $P-doc/usr/local/share/man/man1/
mkdir -p $P-doc/usr/local/share/doc/$P
cp $SRC/LICENSE  $P-doc/usr/local/share/doc/$P/

# TCZ them
#######
LIST="$P $P-doc "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find usr -not -type d > /tmp/$Z.tcz.list
        sed 's|usr|/usr|g' -i /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          slurp-doc.tcz 
Description:    docs for slurp
Version:        git 20200702
Author:         emersion
Original-site:  https://github.com/emersion/slurp
Copying-policy: Accompanied 
Size:           4.0K	
Extension_by:   aus9 
Tags:           sway man
Comments:       docs  

Change-log:     2019/06/16 Original v 1.2.0 on 10x 
Current:        2020/07/02 -> git 20200702 on 11x
' > $P-doc.tcz.info

echo 'Title:          slurp.tcz 
Description:    Select a region in a sway for screenshots 
Version:        git 20200702
Author:         emersion
Original-site:  https://github.com/emersion/slurp
Copying-policy: Accompanied 
Size:           12K		
Extension_by:   aus9 
Tags:           sway screen capture
Comments:       slurp is a command-line app to select a region 
                inside sway and used with grim to take a screenshot.
                grim can not escape its current window, but slurp can.

                $ slurp | grim 1.png
                (for a RH mouse user, Left click top left corner of 
                your desired selection, hold mouse button down
                move mouse to bottom RH corner of selection.
                Release button.....screenshot taken)

                man page offer more options

Change-log:     2019/06/16 Original v 1.2.0 on 10x 
Current:        2020/07/02 -> git 20200702 on 11x 
 ' > $P.tcz.info

echo 'libjpeg-turbo.tcz
cairo.tcz
grim.tcz' > $P.tcz.dep
echo 'man-db.tcz' > $P-doc.tcz.dep

submitqc --libs
