#!/bin/bash
THISUSER=`cat /etc/sysconfig/tcuser`
#

export CFLAGS="-march=i486 -mtune=i686 -O2 -pipe"
export CXXFLAGS="-march=i486 -mtune=i686 -O2 -pipe"

#BASE PLUGIN
#----------------
#CLASS BUILDER
#EXPORT
#FILE BROWSER
#HTML CHARACTER
#SAVE ACTIONS
#SPLIT WINDOWS

#EXTRAPLUGIN
#plugins in the package are all there but not all are compiled
#no not compiled
#?? not know
#----------------
		#   Addons
		#   Codenav
		#   Commander
		#   Debugger (vte ?posixapi?)
#no Devhelp (devhelp 2.x :i can't compile)
		#   Geanydoc
		#   Geanyextrasel
#no Geanygendoc (CTPL, Docutils :ok)
		#   Geanyinsertnum
		#   Geanylatex
		#   Geanylipsum
		#   Geanylua (lua-dev.tcz)
		#   Geanymacro
		#   Geanyminiscript
		#   Geanynumberedbookmarks
		#   Geanypg (gpgme)
		#   Geanyprj
		#   Geanysendmail
		#   Geanyvc	(gtkspell)
		#   Geniuspaste (libsoup)
		#   Gproject
	#   Markdown (like Webhelper)
#no Multiterm (valac)
		#   Scope (vte, gdb?)
		#   Shiftcolumn
		#   Spellcheck (enchant)
		#   Tableconvert
		#   Treebrowser
		#   Updatechecker (libsoup)
	#   Webhelper	(gtk2 glib2(gio) gdk-pixbuf2 webkitgtk xorg?)
		#   Xmlsnippets
		#?? pretty-printer


NAME=geany-plugins
SRCNAME="$NAME"
VER=1.23
CONFIGOPTS="--prefix=/usr/local" 
HERE=`pwd`
PKG=/tmp/"$NAME"/pkg


BUILDDEPS="compiletc.tcz geany.tcz geany-dev.tcz enchant.tcz enchant-dev.tcz vte.tcz vte-dev.tcz \
perl_xml_parser.tcz gtkspell-dev.tcz \
gpgme-dev.tcz intltool.tcz squashfs-tools-4.x.tcz gettext.tcz Xorg-7.6-dev.tcz Xorg-7.6-lib.tcz \
gtk2-dev.tcz webkitgtk-1.0-0-dev.tcz lua-dev.tcz libsoup.tcz"
DEPS="geany.tcz enchant.tcz vte.tcz gtkspell.tcz gpgme.tcz"

#Install deps
for I in `echo "$BUILDDEPS"`; do 
name=`basename "$I" .tcz`
if [ ! -f /usr/local/tce.installed/$name ]; then
su "$THISUSER" -c "tce-load -i "$I"" || exit 1
fi
done



#download package
if [ ! -f "$SRCNAME"-"$VER".tar.gz ]; then
	wget -c http://plugins.geany.org/geany-plugins/"$SRCNAME"-"$VER".tar.gz
	#echo ""$SRCNAME"-"$VER".tar.gz not found, exiting.."
	#exit 1
fi
[ -d "$PKG" ] && rm -r "$PKG"
mkdir -p "$PKG"
[ -d "$SRCNAME"-"$VER" ] && rm -r "$SRCNAME"-"$VER"
tar xvf "$SRCNAME"-"$VER".tar.gz



#compile
cd "$SRCNAME"-"$VER"
./configure "$CONFIGOPTS" 
make
make install DESTDIR="$PKG"


##??
cd "$PKG"
find . | xargs file | grep "executable" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | grep "not stripped" | cut -f 1 -d : | xargs strip -g 2> /dev/null

#make package
cd "$HERE"
mksquashfs "$PKG" ./"$NAME".tcz
	#DO NOT WORK
	#> "$NAME".tcz.dep
	#for I in `cat "$DEPS"`; do 
	#echo "$I" >> "$NAME".tcz.dep
	#done

#divide package
#dev
./tcz-externalizer ./"$NAME".tcz -dev *.la || exit
sleep 1 &&
#doc
./tcz-externalizer ./"$NAME".tcz -doc /doc || exit
sleep 1 &&
#locales
./tcz-externalizer ./"$NAME".tcz -locale *.mo || exit
sleep 1 &&
#move pack in a new dir
mkdir ./"$NAME"-PACKAGE &&
mkdir ./"$NAME"-PACKAGE/sw &&
mkdir ./"$NAME"-PACKAGE/dev &&
mkdir ./"$NAME"-PACKAGE/doc &&
mkdir ./"$NAME"-PACKAGE/locale &&
mv ./"$NAME".tcz ./"$NAME"-PACKAGE/sw &&
mv ./"$NAME"-dev.tcz ./"$NAME"-PACKAGE/dev &&
mv ./"$NAME"-doc.tcz ./"$NAME"-PACKAGE/doc &&
mv ./"$NAME"-locale.tcz ./"$NAME"-PACKAGE/locale &&


#submitqc and other package file
cd ./"$NAME"-PACKAGE/sw/ &&
sudo submitqc4 ./"$NAME".tcz &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME".tcz.dep &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME".tcz.info &&
cd ../../

cd ./"$NAME"-PACKAGE/dev/ &&
sudo submitqc4 ./"$NAME"-dev.tcz &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME"-dev.tcz.info &&
cd ../../

cd ./"$NAME"-PACKAGE/doc/ &&
sudo submitqc4 ./"$NAME"-doc.tcz &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME"-doc.tcz.info &&
cd ../../

cd ./"$NAME"-PACKAGE/locale/ &&
sudo submitqc4 ./"$NAME"-locale.tcz &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME"-locale.tcz.dep &&
wget -c http://distro.ibiblio.org/tinycorelinux/4.x/x86/tcz/"$NAME"-locale.tcz.info &&
cd ../../

cp ./"$0" ./"$NAME"-PACKAGE
cp ./tcz-externalizer ./"$NAME"-PACKAGE
cp ./"$SRCNAME"-"$VER".tar.gz ./"$NAME"-PACKAGE

echo -e "\n\e[31mRemember to update info and dep file\e[0m\n"



