Add plugin API functions to get/set document data
[geany-mirror.git] / scripts / gtk-bundle-from-msys2.sh
blob6ef90708f85e0f01bcd9640d33f7ff333cc0ffed
1 #!/bin/sh
3 # Fetch and extract Geany dependencies for Windows/MSYS2
4 # This script will download (or use Pacman's cache) to extract
5 # dependencies as defined below needed to run Geany.
6 # To be run within a MSYS2 shell. The extracted files will be
7 # placed into the current directory.
9 ABI=i686
10 use_cache="no"
11 make_zip="no"
12 gtkv="3"
13 run_pi="y"
15 UNX_UTILS_URL="http://unxutils.sourceforge.net/UnxUpdates.zip"
16 GREP_URL="https://download.geany.org/contrib/grep-2.23.tar.xz"
18 package_urls=""
19 gtk2_dependency_pkgs=""
20 gtk3_dependency_pkgs="
21 libepoxy
22 hicolor-icon-theme
23 adwaita-icon-theme
26 packages="
27 gcc-libs
28 pcre
29 zlib
30 expat
31 libffi
32 libiconv
33 bzip2
34 libffi
35 libpng
36 gettext
37 glib2
38 graphite2
39 libwinpthread-git
40 harfbuzz
41 fontconfig
42 freetype
43 atk
44 pango
45 cairo
46 pixman
47 gdk-pixbuf2
50 handle_command_line_options() {
51 for opt in "$@"; do
52 case "$opt" in
53 "-c"|"--cache")
54 use_cache="yes"
56 "-z"|"--zip")
57 make_zip="yes"
59 "-2")
60 gtkv="2"
62 "-3")
63 gtkv="3"
65 "-n")
66 run_pi=""
68 "-h"|"--help")
69 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-2 | -3] [CACHEDIR]"
70 echo " -c Use pacman cache. Otherwise pacman will download"
71 echo " archive files"
72 echo " -h Show this help screen"
73 echo " -n Do not run post install scripts of the packages"
74 echo " -z Create a zip afterwards"
75 echo " -2 Prefer gtk2"
76 echo " -3 Prefer gtk3"
77 echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
78 exit 1
81 cachedir="$opt"
83 esac
84 done
87 initialize() {
88 if [ -z "$cachedir" ]; then
89 cachedir="/var/cache/pacman/pkg"
92 if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
93 echo "Cache dir \"$cachedir\" not a directory"
94 exit 1
97 gtk="gtk$gtkv"
98 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
100 pkgs="
101 ${packages}
102 ${gtk_dependency_pkgs}
103 ${gtk}
107 _getpkg() {
108 if [ "$use_cache" = "yes" ]; then
109 package_info=`pacman -Qi mingw-w64-$ABI-$1`
110 package_version=`echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]'`
111 ls $cachedir/mingw-w64-${ABI}-${1}-${package_version}-* | sort -V | tail -n 1
112 else
113 pacman -Sp mingw-w64-${ABI}-${1}
117 _remember_package_source() {
118 if [ "$use_cache" = "yes" ]; then
119 package_url=`pacman -Sp mingw-w64-${ABI}-${2}`
120 else
121 package_url="${1}"
123 package_urls="${package_urls}\n${package_url}"
126 extract_packages() {
127 for i in $pkgs; do
128 pkg=$(_getpkg $i)
129 _remember_package_source $pkg $i
130 if [ "$use_cache" = "yes" ]; then
131 if [ -e "$pkg" ]; then
132 echo "Extracting $pkg from cache"
133 tar xaf $pkg
134 else
135 echo "ERROR: File $pkg not found"
136 exit 1
138 else
139 echo "Download $pkg using curl"
140 curl -L "$pkg" | tar -x --xz
142 if [ -n "$run_pi" ] && [ -f .INSTALL ]; then
143 echo "Running post_install script for \"$i\""
144 /bin/bash -c ". .INSTALL; post_install"
146 if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
147 VERSION=$(grep ^pkgver .PKGINFO | sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
149 rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
150 done
153 move_extracted_files() {
154 echo "Move extracted data to destination directory"
155 if [ -d mingw32 ]; then
156 for d in bin etc home include lib locale share var; do
157 if [ -d "mingw32/$d" ]; then
158 rm -rf $d
159 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
160 sleep 0.5
161 mv mingw32/$d .
163 done
164 rmdir mingw32
168 cleanup_unnecessary_files() {
169 echo "Cleanup unnecessary files"
170 # cleanup temporary files
171 rm -rf var/cache/fontconfig
172 rmdir var/cache
173 rmdir var
174 # cleanup development and other unnecessary files
175 rm -rf include
176 rm -rf lib/gettext
177 rm -rf lib/libffi-*
178 rm -rf lib/pkgconfig
179 find lib -name '*.a' -delete
180 find lib -name '*.typelib' -delete
181 find lib -name '*.def' -delete
182 find lib -name '*.h' -delete
183 find lib -name '*.sh' -delete
184 # cleanup other unnecessary files
185 rm -rf share/aclocal
186 rm -rf share/applications
187 rm -rf share/bash-completion
188 rm -rf share/doc
189 rm -rf share/gdb
190 rm -rf share/gettext
191 rm -rf share/gir-1.0
192 rm -rf share/glib-2.0/codegen
193 rm -rf share/glib-2.0/gdb
194 rm -rf share/glib-2.0/gettext
195 rm -rf share/graphite2
196 rm -rf share/gtk-2.0
197 rm -rf share/gtk-3.0
198 rm -rf share/gtk-doc
199 rm -rf share/info
200 rm -rf share/man
201 rm -rf share/xml
202 # cleanup binaries and libs (delete anything except *.dll)
203 find bin ! -name '*.dll' -type f -delete
204 # cleanup empty directories
205 find . -type d -empty -delete
208 download_and_compile_grep() {
209 grep_archive="grep_source.tar.xz"
210 grep_build_dir="grep_build"
211 grep_build_log="grep_build.log"
212 echo "Download and compile 'grep' (see ${grep_build_dir}/${grep_build_log} for details)"
213 mkdir ${grep_build_dir}
214 cd ${grep_build_dir}
215 wget --no-verbose -O ${grep_archive} ${GREP_URL}
216 tar xf ${grep_archive}
217 grep-2*/configure > ${grep_build_log} 2>&1 || exit 1
218 make >> ${grep_build_log} 2>&1 || exit 1
219 strip src/grep.exe
220 cp src/grep.exe ../bin/
221 cd ..
222 rm -rf ${grep_build_dir}
225 download_and_extract_sort() {
226 echo "Download and unpack 'sort'"
227 # add sort to the bin directory
228 unxutils_archive="unxutilsupdates.zip"
229 wget --no-verbose -O ${unxutils_archive} ${UNX_UTILS_URL}
230 unzip ${unxutils_archive} sort.exe -d bin/
231 rm ${unxutils_archive}
234 create_bundle_dependency_info_file() {
235 filename="ReadMe.Dependencies.Geany.txt"
236 cat << EOF > "${filename}"
237 This installation contains dependencies for Geany which are distributed
238 as binaries (usually .dll files) as well as additional files
239 necessary for these dependencies.
240 Following is a list of all included binary packages with their
241 full download URL as used to create this installation.
243 sort.exe is extracted from the ZIP archive at
244 ${UNX_UTILS_URL}.
246 grep.exe is self-compiled from the sources available at
247 ${GREP_URL}.
248 Used command to compile: ./configure && make
250 Other dependencies are provided by the MSYS2 project
251 (https://msys2.github.io) and were downloaded from:
253 echo -e "${package_urls}" >> "${filename}"
254 unix2dos "${filename}"
257 create_zip_archive() {
258 if [ "$make_zip" = "yes" ]; then
259 if [ -z "$VERSION" ]; then
260 VERSION="unknown-version"
262 echo "Packing the bundle"
263 zip -r gtk-$VERSION.zip bin etc include lib locale share var
268 # main()
269 handle_command_line_options $@
270 initialize
271 extract_packages
272 move_extracted_files
273 cleanup_unnecessary_files
274 download_and_compile_grep
275 download_and_extract_sort
276 create_bundle_dependency_info_file
277 create_zip_archive