#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   echo "Run as root please, exiting." 
   exit 1                                                      
fi

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

P=numlockx
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc5 libX11-dev libXtst-dev  libXt-dev xorg-proto \
automake autoconf "
for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "wget -nc \
http://mirrors.bloomu.edu/debian/pool/main/n/numlockx/numlockx_1.2.orig.tar.gz \                                  
" $USER 
 
tar zxvf numlockx_1.2.orig.tar.gz 
cd $P-1.2
# configure default=/usr/local
./configure  
make -j3
mkdir -p /tmp/$P
make install DESTDIR=/tmp/$P

# Strip executables
cd /tmp/$P
find . | xargs file | grep "executable"    | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
cd /tmp
mkdir -p $P/usr/local/share/doc/$P
cp $P-1.2/LICENSE $P/usr/local/share/doc/$P
cp $P-1.2/AUTHORS $P/usr/local/share/doc/$P

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

# no dep file its for X
# create info files let submitqc5 add size

echo "Title:          numlockx.tcz  TESTING
Description:    numlock control in X
Version:        1.2
Author:      Lubos Lunak,  Oswald Buddenhagen
Original-site:  Lost see below
Copying-policy: MIT
Size:		
Extension_by:   gordons64
Tags:           numlockx 
Comments:       An app to turn on or off the numlock
                    http://mirrors.bloomu.edu/
                   debian/pool/main/n/numlockx/
                   numlockx_1.2.orig.tar.gz

              Create a text file with contents without quotes
              /usr/local/bin/numlockx on  
              save file as .X.d/numlockx
              reboot to test
          
 
		Compiled for Corepure64 6.x
Change-log:     2015/08/01 First version 
Current:        2015/08/01
" > numlockx.tcz.info

submitqc5