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

CFLAGS="-mtune=generic -Os -pipe"
CXX="g++ -flto -fuse-linker-plugin -mtune=generic -Os -pipe -fno-exceptions -fno-rtti" 

P=j4-dmenu-desktop
V=2.17
SRC=$P-r$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc cmake git "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/enkore/$P/archive/r$V.tar.gz " $USER
tar xvf r$V*gz
cd $SRC
cmake .  
make -j5  # takes about 1 min
mkdir /tmp/$P
make install DESTDIR=/tmp/$P
cd /tmp

# no dev
#####

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

# main 
######
strip --strip-unneeded $P/usr/local/bin/*

# 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 'man-db.tcz' > $P-doc.tcz.dep

echo 'Title:          j4-dmenu-desktop.tcz 
Description:    X or Wayland launcher 
Version:        2.17
Author:         enkore
Original-site:  https://github.com/enkore/j4-dmenu-desktop
Copying-policy: GPL v3 
Size:           48K		
Extension_by:   aus9 at gmx dot com
Tags:           wayland bmenu
Comments:       j4-dmenu-desktop is an  X or xwayland or wayland native
                           app launcher
                                                      
                          Please read the example carefully as we have double hyphens
                          and no hyphen (-) depending on dmenu or bemenu

                          Optional dependencies
                          --Either load dmenu or bemenu or both to test please
                          --font packages.....and check what fonts are loaded by
                          $ fc-list

                          small font and assumes dmenu is loaded
                          $ j4-dmenu-desktop  
                          large font with dmenu loaded... Note -fn Sans-20
                          $ j4-dmenu-desktop --dmenu="dmenu -fn 'Luxi Sans-20' "
                          large font with bemenu loaded. Note --fn Sans 20
                          $ j4-dmenu-desktop --dmenu="bemenu --fn 'Luxi Sans 20' "
                 
                  Compiled for 10.x 
Change-log:     2019/06/22 first version 
Current:        2019/06/22  ' > $P.tcz.info

echo 'Title:          j4-dmenu-desktop-doc.tcz 
Description:    docs for j4-dmenu-desktop
Version:        2.17
Author:         enkore
Original-site:  https://github.com/enkore/j4-dmenu-desktop
Copying-policy: GPL v3 
Size:           20K		
Extension_by:   aus9 at gmx dot com
Tags:           wayland man
Comments:       man page

                Compiled for 10.1 
Change-log:     2019/06/22 first version 
Current:        2019/06/22  ' > $P-doc.tcz.info

submitqc --libs
