#!/bin/bash

# This should bascically be the same as a static build, but the 
# "make install" is followed by the appimage creation. After the
# install does its work, the bin directory and subdirectories 
# contain the whole application.

# Install linuxdeploy (CLI version). Download from
# https://github.com/linuxdeploy/linuxdeploy/releases/continuous . It is an
# AppImage, set it executable, and put it in a directory in your path.
# For instance, depending on distribution, directory ~/bin and/or ~/.local/bin
# might be automatically included in your path at log-in time it they exists.
# Or use a globally accessable directory if different logins need to us it.

# To include the context-sensitive help, specify the directory
# where the manual source is. This script will then call the "translate"
# script there to build the manual, and copy it to the proper place 
# before the AppImage is built.

MANUALDIRECTORY=../../cin-manual-latex

( ./autogen.sh
  ./configure --with-single-user --enable-static-build
  make && make install ) 2>&1 | tee log
mv Makefile Makefile.cfg
cp Makefile.devel Makefile

mkdir AppDir                # create lowest level
mkdir AppDir/usr

cp -r bin AppDir/usr/    # copy whole of bin directory

# Build and copy the manual if the directory is specified and exists
if [ -d "$MANUALDIRECTORY" ]; then
  pushd $MANUALDIRECTORY
  # run the build in a subshell so if some error causes an exit
  # the popd will still work.
  (./translate_manual)
  popd
  cp -r $MANUALDIRECTORY/CinelerraGG_Manual bin/doc/
fi   

# We need to specify all executables, so linuxdeploy can pick up dependencies.
# Any executable code in other places like plugins in not picked up (yet).
~/bin/linuxdeploy-x86_64.AppImage --appdir=AppDir -o appimage -d image/cin.desktop -i image/cin.svg -e bin/cin -e bin/mpeg2enc -e bin/mplex -e bin/hveg2enc -e bin/lv2ui -e bin/bdwrite -e bin/zmpeg3toc -e bin/zmpeg3show -e bin/zmpeg3cat -e bin/zmpeg3ifochk -e bin/zmpeg3cc2txt -e bin/mplexlo -l /usr/lib/x86_64-linux-gnu/libjbig.so.0 -l /usr/lib/x86_64-linux-gnu/libbz2.so 02>&1 | tee appimage.log

# There is now an appimage in the cinelerra-5.1 directory. 


