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

# build after popt

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=gphoto2
V=2.5.26
SRC=$P-$V
USER=`cat /etc/sysconfig/tcuser`

LIST="compiletc squashfs-tools wget zsync libgphoto2-dev \
libjpeg-turbo-dev readline-dev popt-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/gphoto/files/gphoto/$V/$SRC.tar.bz2"  $USER
mkdir $P
tar jxvf $SRC*bz2
cd $SRC
./configure --prefix=/usr/local --disable-static --localstatedir=/var \
--disable-nls --with-aalib 
###################################################################################
# supplies
# Compiler:                      gcc
# Use translations:              no
# libgphoto2:                    yes
# pthread support:               yes (-lpthread)
# Interactive config support:    no (http://dickey.his.com/cdk/cdk.html)
# JPEG support:                  yes
# libexif:                       yes
# Text preview support:          no (http://www.sourceforge.net/projects/aa-project)
# use popt library:              yes
# popt libs:                     -L/usr/ -lpopt
# popt cppflags:                 -I/usr/include
# Readline support:              yes (requires explicit -lncurses)
# fix popt pathways
sed 's|POPT_CFLAGS = -I/usr|POPT_CFLAGS = -I/usr/local|' -i Makefile
sed 's|POPT_LIBS = -L/usr|POPT_LIBS = -L/usr/local|' -i Makefile

make -j5 # takes seconds
make install-strip DESTDIR=/tmp/$P
cd /tmp
rm -rf $P/usr/local/share

# 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:          gphoto2.tcz
Description:    command line frontend to libgphoto2 
Version:        2.5.26
Author:         Lutz Mueller, Hans Ulrich Niedermann, Christophe Barbe 
                Hubert Figuiere, Colin Marquardt, Marcus Meissner & Theodore Kilgore
Original-site:  http://gphoto.org
Copying-policy: GPL v2
Size:           52K
Extension_by:   aus9
Tags:           camera
Comments:       Mainly to copy images or movies from camera to PC
                TC mount tool/usb-utils not needed and online help =
                http://gphoto.org/doc/manual/
                Supported cameras list
                http://www.gphoto.org/proj/libgphoto2/support.php
                Mine=Fuji T500 is unlisted but image copy works OK
                
                $ gphoto2 --auto-detect # must show a camera or phone
                (My phone did not need usb debug enabled)
                eg USB PTP Class Camera usb:001,005
                If not, power cycle your camera until you see one.
                
                $ gphoto2 --get-all-files
                -> Saving file as DSCF1462.JPG                                                    
                -> Saving file as DSCF1464.AVI  

                $ gphoto2 -a  # shows with example
                Abilities for camera: USB PTP Class Camera                        
                Serial port support:              no
                USB support:                      yes 
                Capture choices: :                Image
                                                  Preview
                Configuration support:            yes
                Delete selected files on camera:  yes
                Delete all files on camera:       no
                File preview (thumbnail) support: yes
                File upload support:              yes 
                (I have not found an use for ~/.gphoto/settings)
                $ gphoto2 --capture-image
                -> Sorry, your camera does not support generic capture
                             
Change-log:     2020/11/04 Original v 2.5.26 on 12x
Current:        2020/11/04 ' > $P.tcz.info 

echo 'libgphoto2.tcz
readline.tcz
popt.tcz ' > $P.tcz.dep

