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

export CFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe" 
export CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a72 -Os -pipe \
-fno-exceptions -fno-rtti"

P=mtpaint
SRC=mtPaint 
USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc squashfs-tools zsync wget git gtk2-dev openjpeg-dev giflib-dev"   
    for Z in $LIST
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
su -c "git clone https://github.com/wjaguar/mtPaint.git"  $USER
mkdir $P
cd $SRC
# NOTE LARGER SPACE BETWEEN local and gtk is deliberate...gtk1 make fails gtk2 ok
./configure --prefix=/usr/local  gtk2 thread GIF jpeg jp2v2 tiff lcms2 nowebp noft
# Version             3.49.33
# System              GNU/Linux
# Toolkit             GTK+2
# Lists               GTK+2
# File Picker         mtpaint
# Colour Picker       mtpaint
# Animation Package   Gifsicle
# Use FreeType        YES
# Use CMS             LittleCMS2
# Icon set            icons1
# Internationalized   NO
# Multithreaded       YES
# Optimizations       RELEASE
# CFLAGS              -O2  -fcommon 
# LDFLAGS             -s 
# Static libraries    NONE
# Use GIF             GIF
# Use JPEG            YES
# Use JPEG 2000       OpenJPEG2
# Use TIFF            YES
# Use WebP            NO
# Binary install      /usr/local/bin
# Install man page    NO

make -j5 # takes 45 secs....... install-strip fails
make install DESTDIR=/tmp/$P
cd /tmp

# main
#######
APP=$P/usr/local/share/applications/
mkdir -p $APP

echo '[Desktop Entry]
Name=mtpaint
Exec=mtpaint
Terminal=false
Icon=mtpaint
X-FullPathIcon=/usr/local/share/pixmaps/mtpaint.png
MimeType=image/bmp;image/gif;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xbitmap;image/x-xwindowdump;image/x-xcf;image/x-compressed-xcf;image/tiff;image/jpeg;image/png;image/x-icon;
StartupNotify=false
Type=Application
Categories=Graphics;GTK; ' >> $APP/$P.desktop

mkdir -p $P/usr/local/share/pixmaps
cp $SRC/doc/$P.png $P/usr/local/share/pixmaps

strip --strip-unneeded $P/usr/local/bin/$P

# TCZ them
###########
LIST="$P "
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
        zsyncmake $Z.tcz
done

ls -hal

echo 'Title:          mtpaint.tcz  
Description:    gtk2 GUI paint tool
Version:        3.49.33
Author:         Dmitry Groshev, Mark Tyler & Xiaolin Wu
Original-site:  https://github.com/wjaguar/mtPaint.git
Copying-policy: GPL v3
Size:           428K		
Extension_by:   aus9
Tags:           gtk2 paint graphics
Comments:       can also convert some image formats      
 
Change-log:     2020/11/03 original v 3.49.33 on 12x 
Current:        2020/11/03  '> mtpaint.tcz.info

echo 'gtk2.tcz
giflib.tcz
openjpeg.tcz
liblcms2.tcz' > $P.tcz.dep

