Skip to content

Commit

Permalink
Add shell script to add plugin dependencies into GTK bundle on MSYS2
Browse files Browse the repository at this point in the history
This is a helper script to easily fetch and extract plugin dependencies
on Windows using the MSYS2 environment.
  • Loading branch information
eht16 committed Feb 28, 2016
1 parent 32c2f52 commit f88c0fe
Showing 1 changed file with 184 additions and 0 deletions.
184 changes: 184 additions & 0 deletions build/gtk-bundle-from-msys2.sh
@@ -0,0 +1,184 @@
#!/bin/sh
#
# Fetch and extract Geany-Plugins dependencies for Windows/MSYS2
# This script will download (or use Pacman's cache) to extract
# plugin dependencies as defined below. To be run within a MSYS2
# shell. The extracted files will be placed into the current
# directory.

ABI=i686
use_cache="no"
make_zip="no"
gtkv="3"

# ctags - binary for GeanyCTags plugin
# enchant - for SpellCheck plugin
# glib-networking and webkitgtk2/3 for WebHelper and Markdown plugins
# lua51 - for GeanyLua plugin
# gnupg and gpgme - for GeanyPG plugin
# libsoup - for UpdateChecker plugin
# libgit2 - for GitChangeBar plugin
# gtkspell - for GeanyVC plugin
packages="
ctags
enchant
lua51
glib-networking
gnupg
gpgme
libsoup
libgit2
gtkspell
"
gtk2_dependency_pkgs="
webkitgtk2
"
gtk3_dependency_pkgs="
webkitgtk3
"


handle_command_line_options() {
for opt in "$@"; do
case "$opt" in
"-c"|"--cache")
use_cache="yes"
;;
"-z"|"--zip")
make_zip="yes"
;;
"-2")
gtkv="2"
;;
"-3")
gtkv="3"
;;
"-h"|"--help")
echo "gtk-bundle-from-msys2.sh [-c] [-z] [-2 | -3]"
echo " -c Use pacman cache. Otherwise pacman will download"
echo " archive files"
echo " -z Create a zip afterwards"
echo " -2 Prefer gtk2"
echo " -3 Prefer gtk3"
exit 1
;;
*)
cachedir="$opt"
;;
esac
done
}

initialize() {
if [ -z "$cachedir" ]; then
cachedir="/var/cache/pacman/pkg"
fi

if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
echo "Cache dir \"$cachedir\" not a directory"
exit 1
fi

gtk="gtk$gtkv"
eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"

pkgs="
${packages}
${gtk_dependency_pkgs}
"
}

_getpkg() {
if [ "$use_cache" = "yes" ]; then
ls $cachedir/mingw-w64-$ABI-$1-* | sort -V | tail -n 1
else
pacman -Sp mingw-w64-$ABI-$1
fi
}

extract_packages() {
for i in $pkgs; do
pkg=$(_getpkg $i)
if [ "$use_cache" = "yes" ]; then
if [ -e "$pkg" ]; then
echo "Extracting $pkg from cache"
tar xaf $pkg
else
echo "ERROR: File $pkg not found"
exit 1
fi
else
echo "Download $pkg using curl"
curl -L "$pkg" | tar -x --xz
fi
if [ -f .INSTALL ]; then
echo "Running post_install script"
/bin/bash -c ". .INSTALL; post_install"
fi
rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
done
}

move_extracted_files() {
if [ -d mingw32 ]; then
for d in bin etc home include lib locale share var; do
if [ -d "mingw32/$d" ]; then
rm -rf $d
# prevent sporadic 'permission denied' errors on my system, not sure why they happen
sleep 0.5
mv mingw32/$d .
fi
done
rmdir mingw32
fi
}

cleanup_unnecessary_files() {
echo "Cleanup unnecessary files"
# include: cleanup development files
rm -rf include
# lib: cleanup development files
rm -rf lib/pkgconfig
rm -rf lib/girepository-1.0
rm -rf lib/lua
find lib -name '*.a' -delete
find lib -name '*.typelib' -delete
find lib -name '*.def' -delete
# share: cleanup other unnecessary files
rm -rf share/aclocal
rm -rf share/common-lisp
rm -rf share/doc
rm -rf share/gir-1.0
rm -rf share/gtk-doc
rm -rf share/info
rm -rf share/lua
rm -rf share/man
# bin: cleanup binaries and libs (delete anything except *.dll and binaries we need)
find bin \
! -name '*.dll' \
! -name ctags.exe \
! -name gpg2.exe \
! -name gpgme-w32spawn.exe \
! -name gpgme-tool.exe \
! -name gpgconf.exe \
-type f \
-delete
# cleanup empty directories
find . -type d -empty -delete
}

create_zip_archive() {
if [ "$make_zip" = "yes" ]; then
echo "Packing the bundle"
zip -r plugins-$gtk.zip bin etc include lib locale share var
fi
}


# main()
handle_command_line_options $@
initialize
extract_packages
move_extracted_files
cleanup_unnecessary_files
create_zip_archive

0 comments on commit f88c0fe

Please sign in to comment.