#!/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"

G=gphoto
P=libgphoto2
V=2.5.26
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc squashfs-tools wget zsync libtool-dev libexif-dev libusb-dev libxml2-dev \
curl-dev liblzma-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 \
https://sourceforge.net/projects/$G/files/lib$G/$V/$SRC.tar.bz2"  $USER
mkdir $P
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --disable-static --localstatedir=/var --disable-nls
###################################################################################
# Configuration (libgphoto2_port 0.12.0):
# Compiler:                      gcc
# libltdl includes:              
# libltdl library:               -lltdl
# Use translations:              no
# libexif:                       yes
# Serial ports
# Serial support:                yes
# ttylock locking:               no
# lockdev locking:               no
# USB ports
# libusb-1.0:                    yes
# libusb:                        no
# virtual USB support:           disabled, no virtual PTP test camera
# IOLIBs:                        disk ptpip serial usb1 usbdiskdirect usbscsi
# build API docs with gtk-doc:   no (not requested)
# GP2DDB support:                no  (EXPERIMENTAL)
# Compiler:                      gcc
# libltdl includes:              
# libltdl library:               -lltdl
# Use translations:              no
# JPEG mangling support:         no
# libxml-2.0:                    yes
# XML support for Olympus E s..: yes
# libcurl:                       yes
# CURL support for Lumix Wifi:   yes
# gdlib:                         no
# libGD conversion support:      no
# Camlibs:                       standard set (ax203 canon digigr8 dimagev directory 
#                                jl2005a jl2005c kodak_dc240 lumix mars pentax ptp2 
#                                ricoh_g3 sierra sonix sq905 st2205 topfield tp6801 SKIPPING docupen)
# build API docs with gtk-doc:   no (not requested)
# libexif:                       yes
# Subprojects:                   libgphoto2_port
make -j5 # takes 1M 5s
make install-strip DESTDIR=/tmp/$P
cd /tmp

# dev
#####
mkdir -p $P-dev/usr/local/lib/
mv $P/usr/local/include $P-dev/usr/local/
mv $P/usr/local/lib/pkgconfig $P-dev/usr/local/lib/
mv $P/usr/local/lib/*a $P-dev/usr/local/lib/
chmod 644 $P-dev/usr/local/lib/*a 

mkdir -p $P-dev/usr/local/lib/$P/$V
mv $P/usr/local/lib/$P/$V/*la $P-dev/usr/local/lib/$P/$V
chmod 644 $P-dev/usr/local/lib/$P/$V/*la

mkdir -p $P-dev/usr/local/lib/libgphoto2_port/0.12.0
mv $P/usr/local/lib/libgphoto2_port/0.12.0/*la $P-dev/usr/local/lib/libgphoto2_port/0.12.0/
chmod 644 $P-dev/usr/local/lib/libgphoto2_port/0.12.0/*la

# TC64 has exe moved to dev
mv $P/usr/local/bin $P-dev/usr/local/

# TCZ them
###########
LIST="$P $P-dev "
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:          libgphoto2-dev.tcz
Description:    dev files
Version:        2.5.26
Author:         https://github.com/gphoto/libgphoto2/blob/master/AUTHORS
Original-site:  http://gphoto.org
Copying-policy: https://github.com/gphoto/libgphoto2/blob/master/COPYING
Size:           44K
Extension_by:   aus9
Tags:           camera
Comments:       dev files

Change-log:     2020/11/04 Original v 2.5.26 on 12x
Current:        2020/11/04 ' > $P-dev.tcz.info
     
echo 'Title:          libgphoto2.tcz
Description:    camera library 
Version:        2.5.26
Author:         https://github.com/gphoto/libgphoto2/blob/master/AUTHORS
Original-site:  http://gphoto.org
Copying-policy: https://github.com/gphoto/libgphoto2/blob/master/COPYING
Size:           1M
Extension_by:   aus9
Tags:           camera
Comments:       library that can be used by applications to 
                access various digital cameras
             
Change-log:     2020/11/04 Original v 2.5.26 on 12x
Current:        2020/11/04 ' > $P.tcz.info 

echo 'libgphoto2.tcz
libtool-dev.tcz 
libexif-dev.tcz  
libusb-dev.tcz  
libxml2-dev.tcz 
curl-dev.tcz  
liblzma-dev.tcz  ' > $P-dev.tcz.dep