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

# due to meson recreate missing la file
########################################
cat >> /usr/local/lib/libatk-1.0.la  <<'EOF'
# libatk-1.0.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-0.1
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libatk-1.0.so.0'

# Names of this library.
library_names='libatk-1.0.so.0.22810.1 libatk-1.0.so.0 libatk-1.0.so'

# The name of the static archive.
old_library=''

# Linker flags that cannot go in dependency_libs.
inherited_linker_flags=''

# Libraries that this one depends upon.
dependency_libs=' -L/usr/local/lib /usr/local/lib/libgobject-2.0.la /usr/local/lib/libffi.la /usr/local/lib/libglib-2.0.la /usr/local/lib/libpcre.la -lpthread'

# Names of additional weak libraries provided by this library
weak_library_names=''

# Version information for libatk-1.0.
current=22810
age=22810
revision=1

# Is this an already installed library?
installed=yes

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
EOF

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

P=xfce4-xkb-plugin
V=0.8.1
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc intltool libX11-dev gtk3-dev  \
xfce4-panel-dev libxklavier-dev librsvg-dev "
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 \
http://archive.xfce.org/src/panel-plugins/$P/0.8/$P-$V.tar.bz2  " $USER

mkdir $P
tar jxvf $P*bz2
cd $SRC
./configure --enable-debug=no 
##############################
# Build Configuration:
# Debug Support:    n
###################### 
make check
make install-strip DESTDIR=/tmp/$P
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib/xfce4/panel/plugins
mv $P/usr/local/lib/xfce4/panel/plugins/*a $P-dev/usr/local/lib/xfce4/panel/plugins/
chmod 644 $P-dev/usr/local/lib/xfce4/panel/plugins/*a
# license must accompany source code
mkdir -p $P-dev/usr/local/share/doc/$P-dev
cp $SRC/COPYING $P-dev/usr/local/share/doc/$P-dev

# locale
#########
mkdir -p $P-locale/usr/local/share/doc/$P-locale
mv $P/usr/local/share/locale $P-locale/usr/local/share
# add accompainied license
cp $SRC/COPYING $P-locale/usr/local/share/doc/$P-locale/

# main only one file that could split to doc so leave it in main
#####
mkdir -p $P/usr/local/share/doc/$P
cp $SRC/AUTHORS $P/usr/local/share/doc/$P/
cp $S/COPYING $P/usr/local/share/doc/$P/

# TCZ them
#######
LIST="$P $P-dev $P-locale"
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

echo 'xfce4-xkb-plugin.tcz ' > $P-locale.tcz.dep

echo 'xfce4-xkb-plugin.tcz 
intltool.tcz 
libX11-dev.tcz 
gtk3-dev.tcz 
xfce4-panel-dev.tcz
libxklavier-dev.tcz 
librsvg-dev.tcz ' > $P-dev.tcz.dep

echo 'gtk3.tcz
libxklavier.tcz
xfce4-panel.tcz
librsvg.tcz' > $P.tcz.dep

echo 'Title:          xfce4-xkb-plugin.tcz  
Description:    Extra Key Board support for XFCE
Version:        0.8.1
Author:         see AUTHORS  
Original-site:  xfce.org
Copying-policy: accompanied
Size:           		
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       Allows selection of various kb make/models and layouts.
                Go into the XFCE settings to make changes please. If you 
                press your "change" layout key and if layout does not change,  
                run (and result should be XFCE) 
                $ echo $XDG_CURRENT_DESKTOP

                How to add panel applet. I assume you are a RH mouse user
                RH empty space of panel -> panel -> Add New Items   
                Select Keyboard Layouts and click Add
                Click close to close that GUI. A flag will appear
                for first kb layout. You can have up to 4 layouts

                Why have 2 layouts? Go to Settings  and select keyboard 
                -> TAB layout. You MUST untick the box for system defaults
                to make changes please. To see the add layouts button, 
                please maximise the active window. Some 
                countries may offer different layouts.

                I prefer to change layout option key to "Left Win"
                (left windows key) which means no matter how many
                layouts I have..... pressing this key will cycle 
                to the next layout and eventually back to original etc.

                I prefer to change the Compose Key to "Right Win"
                This offers slightly diff kb combos as example
                staying on US kb  press your Compose key
                then c then = (results in the Euro sign) or
                swap to compose then  = then c
                --no need to hold down compose key
                Press the compose key then other keys as per
                https://en.wikipedia.org/wiki/Compose_key
                
                You know your compose key is working correctly if
                when you press compose and next keyboard letter
                no display is seen.  

                Compiled for 64 9.x
Change-log:     2018/04/22  First version 
Current:        2018/05/22 redo for gtk3 issue' > $P.tcz.info

echo 'Title:          xfce4-xkb-plugin-dev.tcz
Description:    one dev file
Version:        0.8.1
Author:         see AUTHORS 
Original-site:  xfce.org
Copying-policy: accompanied
Size:           	
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       development file
                no headers use the source please.

                Compiled for 64 9.x
Change-log:     2018/04/22  First version 
Current:        2018/05/22 redo for gtk3 issue ' > $P-dev.tcz.info

echo 'Title:          xfce4-xkb-plugin-locale.tcz
Description:    locales
Version:        0.8.1
Author:         see AUTHORS 
Original-site:  xfce.org
Copying-policy: accompanied
Size:           	
Extension_by:   aus9 at gmx dot com
Tags:           xfce 
Comments:       for non-english users untested

                Compiled for 64 9.x
Change-log:     2018/04/22  First version 
Current:        2018/05/22 redo for gtk3 issue ' > $P-locale.tcz.info

submitqc  --libs
