GTK: Fix accessible object lifetime on GTK < 3.8
[geany-mirror.git] / scripts / gtk-bundle-from-msys2.sh
blob18733600db782386443d44b9f733c9795b8e0fbf
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 # path to an installation of a MSYS2 installation in the native architecture matching $ABI
17 # leave empty if the script is called already from the same MSYS2 architecture as $ABI
18 MSYS2_ABI_PATH="/c/msys32"
20 package_urls=""
21 gtk2_dependency_pkgs=""
22 gtk3_dependency_pkgs="
23 libepoxy
24 hicolor-icon-theme
25 adwaita-icon-theme
28 packages="
29 gcc-libs
30 pcre
31 zlib
32 expat
33 libffi
34 libiconv
35 bzip2
36 libffi
37 libpng
38 gettext
39 glib2
40 graphite2
41 libwinpthread-git
42 harfbuzz
43 fontconfig
44 freetype
45 atk
46 pango
47 cairo
48 pixman
49 gdk-pixbuf2
52 handle_command_line_options() {
53 for opt in "$@"; do
54 case "$opt" in
55 "-c"|"--cache")
56 use_cache="yes"
58 "-z"|"--zip")
59 make_zip="yes"
61 "-2")
62 gtkv="2"
64 "-3")
65 gtkv="3"
67 "-n")
68 run_pi=""
70 "-h"|"--help")
71 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-2 | -3] [CACHEDIR]"
72 echo " -c Use pacman cache. Otherwise pacman will download"
73 echo " archive files"
74 echo " -h Show this help screen"
75 echo " -n Do not run post install scripts of the packages"
76 echo " -z Create a zip afterwards"
77 echo " -2 Prefer gtk2"
78 echo " -3 Prefer gtk3"
79 echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
80 exit 1
83 cachedir="$opt"
85 esac
86 done
89 initialize() {
90 if [ -z "$cachedir" ]; then
91 cachedir="/var/cache/pacman/pkg"
94 if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
95 echo "Cache dir \"$cachedir\" not a directory"
96 exit 1
99 gtk="gtk$gtkv"
100 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
102 pkgs="
103 ${packages}
104 ${gtk_dependency_pkgs}
105 ${gtk}
109 _getpkg() {
110 if [ "$use_cache" = "yes" ]; then
111 package_info=`pacman -Qi mingw-w64-$ABI-$1`
112 package_version=`echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]'`
113 ls $cachedir/mingw-w64-${ABI}-${1}-${package_version}-* | sort -V | tail -n 1
114 else
115 pacman -Sp mingw-w64-${ABI}-${1}
119 _remember_package_source() {
120 if [ "$use_cache" = "yes" ]; then
121 package_url=`pacman -Sp mingw-w64-${ABI}-${2}`
122 else
123 package_url="${1}"
125 package_urls="${package_urls}\n${package_url}"
128 extract_packages() {
129 for i in $pkgs; do
130 pkg=$(_getpkg $i)
131 _remember_package_source $pkg $i
132 if [ "$use_cache" = "yes" ]; then
133 if [ -e "$pkg" ]; then
134 echo "Extracting $pkg from cache"
135 tar xaf $pkg
136 else
137 echo "ERROR: File $pkg not found"
138 exit 1
140 else
141 echo "Download $pkg using curl"
142 curl -L "$pkg" | tar -x --xz
144 if [ -n "$run_pi" ] && [ -f .INSTALL ]; then
145 echo "Running post_install script for \"$i\""
146 /bin/bash -c ". .INSTALL; post_install"
148 if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
149 VERSION=$(grep ^pkgver .PKGINFO | sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
151 rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
152 done
155 move_extracted_files() {
156 echo "Move extracted data to destination directory"
157 if [ -d mingw32 ]; then
158 for d in bin etc home include lib locale share var; do
159 if [ -d "mingw32/$d" ]; then
160 rm -rf $d
161 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
162 sleep 0.5
163 mv mingw32/$d .
165 done
166 rmdir mingw32
170 cleanup_unnecessary_files() {
171 echo "Cleanup unnecessary files"
172 # cleanup temporary files
173 rm -rf var/cache/fontconfig
174 rmdir var/cache
175 rmdir var
176 # cleanup development and other unnecessary files
177 rm -rf include
178 rm -rf lib/gettext
179 rm -rf lib/libffi-*
180 rm -rf lib/pkgconfig
181 find lib -name '*.a' -delete
182 find lib -name '*.typelib' -delete
183 find lib -name '*.def' -delete
184 find lib -name '*.h' -delete
185 find lib -name '*.sh' -delete
186 # cleanup other unnecessary files
187 rm -rf share/aclocal
188 rm -rf share/applications
189 rm -rf share/bash-completion
190 rm -rf share/doc
191 rm -rf share/gdb
192 rm -rf share/gettext
193 rm -rf share/gir-1.0
194 rm -rf share/glib-2.0/codegen
195 rm -rf share/glib-2.0/gdb
196 rm -rf share/glib-2.0/gettext
197 rm -rf share/graphite2
198 rm -rf share/gtk-2.0
199 rm -rf share/gtk-3.0
200 rm -rf share/gtk-doc
201 rm -rf share/info
202 rm -rf share/man
203 rm -rf share/xml
204 # cleanup binaries and libs (delete anything except *.dll)
205 find bin ! -name '*.dll' -type f -delete
206 # cleanup empty directories
207 find . -type d -empty -delete
210 copy_grep_and_dependencies() {
211 own_arch=$(arch)
212 if [ "${own_arch}" == "${ABI}" -o -z "${MSYS2_ABI_PATH}" ]; then
213 bin_dir="/usr/bin"
214 else
215 # TODO extract grep and dependencies from Pacman packages according to the target ABI
216 bin_dir="${MSYS2_ABI_PATH}/usr/bin"
218 echo "Copy 'grep' from ${bin_dir}"
219 cp "${bin_dir}/grep.exe" "bin/"
220 # dependencies for grep.exe
221 cp "${bin_dir}/msys-2.0.dll" "bin/"
222 cp "${bin_dir}/msys-gcc_s-1.dll" "bin/"
223 cp "${bin_dir}/msys-iconv-2.dll" "bin/"
224 cp "${bin_dir}/msys-intl-8.dll" "bin/"
225 cp "${bin_dir}/msys-pcre-1.dll" "bin/"
228 download_and_extract_sort() {
229 echo "Download and unpack 'sort'"
230 # add sort to the bin directory
231 unxutils_archive="unxutilsupdates.zip"
232 wget --no-verbose -O ${unxutils_archive} ${UNX_UTILS_URL}
233 unzip ${unxutils_archive} sort.exe -d bin/
234 rm ${unxutils_archive}
237 create_bundle_dependency_info_file() {
238 grep_version="$(bin/grep --version | head -n1)"
239 sort_version="$(bin/sort --version | head -n1)"
240 filename="ReadMe.Dependencies.Geany.txt"
241 cat << EOF > "${filename}"
242 This installation contains dependencies for Geany which are distributed
243 as binaries (usually .dll files) as well as additional files
244 necessary for these dependencies.
245 Following is a list of all included binary packages with their
246 full download URL as used to create this installation.
248 sort.exe is extracted from the ZIP archive at
249 ${UNX_UTILS_URL}.
250 Sort version: ${sort_version}
252 grep.exe is taken from a 32bit MSYS2 installation and
253 is bundled together with its dependencies.
254 Grep version: ${grep_version}
256 Other dependencies are provided by the MSYS2 project
257 (https://msys2.github.io) and were downloaded from:
259 echo -e "${package_urls}" >> "${filename}"
260 unix2dos "${filename}"
263 create_zip_archive() {
264 if [ "$make_zip" = "yes" ]; then
265 if [ -z "$VERSION" ]; then
266 VERSION="unknown-version"
268 echo "Packing the bundle"
269 zip -r gtk-$VERSION.zip bin etc include lib locale share var
274 # main()
275 handle_command_line_options $@
276 initialize
277 extract_packages
278 move_extracted_files
279 cleanup_unnecessary_files
280 copy_grep_and_dependencies
281 download_and_extract_sort
282 create_bundle_dependency_info_file
283 create_zip_archive