Pass the event to gtk_menu_popup_at_pointer() when possible
[geany-mirror.git] / scripts / gtk-bundle-from-msys2.sh
blobe2e9747fd2375a1bb04dfb3f3325fa9433f9edaa
1 #!/bin/bash
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=x86_64 # do not change, i686 is not supported any longer
10 use_cache="no"
11 make_zip="no"
12 gtkv="3"
13 run_pi="y"
14 cross="no"
16 UNX_UTILS_URL="https://download.geany.org/contrib/UnxUpdates.zip"
18 # Wine commands for 32bit and 64bit binaries (we still need 32bit for UnxUtils sort.exe)
19 # Used only when "-x" is set
20 EXE_WRAPPER_32="mingw-w64-i686-wine"
21 EXE_WRAPPER_64="mingw-w64-x86_64-wine"
23 package_urls=""
24 gtk3_dependency_pkgs=""
25 gtk4_dependency_pkgs=""
27 packages="
28 adwaita-icon-theme
29 atk
30 brotli
31 bzip2
32 cairo
33 expat
34 fontconfig
35 freetype
36 fribidi
37 gcc-libs
38 gdk-pixbuf2
39 gettext
40 glib2
41 graphite2
42 grep
43 gtk-update-icon-cache
44 harfbuzz
45 hicolor-icon-theme
46 libdatrie
47 libepoxy
48 libffi
49 libiconv
50 libpng
51 librsvg
52 libthai
53 libwinpthread-git
54 libxml2
55 pango
56 pcre2
57 pixman
59 zlib
62 handle_command_line_options() {
63 for opt in "$@"; do
64 case "$opt" in
65 "-c"|"--cache")
66 use_cache="yes"
68 "-z"|"--zip")
69 make_zip="yes"
71 "-3")
72 gtkv="3"
74 "-4")
75 gtkv="4"
77 "-n")
78 run_pi=""
80 "-x")
81 cross="yes"
83 "-h"|"--help")
84 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-3 | -4] [CACHEDIR]"
85 echo " -c Use pacman cache. Otherwise pacman will download"
86 echo " archive files"
87 echo " -h Show this help screen"
88 echo " -n Do not run post install scripts of the packages"
89 echo " -z Create a zip afterwards"
90 echo " -3 Prefer gtk3"
91 echo " -4 Prefer gtk4"
92 echo " -x Set when the script is executed in a cross-compilation context (e.g. to use wine)"
93 echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
94 exit 1
97 cachedir="$opt"
99 esac
100 done
103 set -e # stop on errors
104 # enable extended globbing as we need it in _getpkg
105 shopt -s extglob
107 initialize() {
108 if [ -z "$cachedir" ]; then
109 cachedir="/var/cache/pacman/pkg"
112 if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
113 echo "Cache dir \"$cachedir\" not a directory"
114 exit 1
117 if [ "$cross" != "yes" ]; then
118 # if running natively, we do not need wine or any other wrappers
119 EXE_WRAPPER_32=""
120 EXE_WRAPPER_64=""
123 gtk="gtk$gtkv"
124 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
126 pkgs="
127 ${packages}
128 ${gtk_dependency_pkgs}
129 ${gtk}
133 _getpkg() {
134 if [ "$use_cache" = "yes" ]; then
135 package_info=$(pacman -Qi mingw-w64-$ABI-$1)
136 package_version=$(echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]')
137 # use @(gz|xz|zst) to filter out signature files (e.g. mingw-w64-x86_64-...-any.pkg.tar.zst.sig)
138 ls $cachedir/mingw-w64-${ABI}-${1}-${package_version}-*.tar.@(gz|xz|zst) | sort -V | tail -n 1
139 else
140 # -dd to ignore dependencies as we listed them already above in $packages and
141 # make pacman ignore its possibly existing cache (otherwise we would get an URL to the cache)
142 pacman -Sddp --cachedir /nonexistent mingw-w64-${ABI}-${1}
146 _remember_package_source() {
147 if [ "$use_cache" = "yes" ]; then
148 package_url=$(pacman -Sddp mingw-w64-${ABI}-${2})
149 else
150 package_url="${1}"
152 package_urls="${package_urls}\n${package_url}"
155 extract_packages() {
156 for i in $pkgs; do
157 pkg=$(_getpkg $i)
158 _remember_package_source $pkg $i
159 if [ "$use_cache" = "yes" ]; then
160 if [ -e "$pkg" ]; then
161 echo "Extracting $pkg from cache"
162 tar xaf $pkg
163 else
164 echo "ERROR: File $pkg not found"
165 exit 1
167 else
168 echo "Download $pkg using curl"
169 filename=$(basename "$pkg")
170 curl --silent --location --output "$filename" "$pkg"
171 tar xf "$filename"
172 rm "$filename"
174 if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
175 VERSION=$(grep ^pkgver .PKGINFO | sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
177 rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
178 done
181 move_extracted_files() {
182 echo "Move extracted data to destination directory"
183 if [ -d mingw64 ]; then
184 for d in bin etc home include lib locale share var; do
185 if [ -d "mingw64/$d" ]; then
186 rm -rf $d
187 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
188 sleep 0.5
189 mv mingw64/$d .
191 done
192 rmdir mingw64
196 delayed_post_install() {
197 if [ "$run_pi" ]; then
198 echo "Execute delayed post install tasks"
199 # Commands have been collected manually from the various .INSTALL scripts
200 ${EXE_WRAPPER_64} bin/fc-cache.exe -f
201 ${EXE_WRAPPER_64} bin/gdk-pixbuf-query-loaders.exe --update-cache
202 ${EXE_WRAPPER_64} bin/gtk-update-icon-cache-3.0.exe -q -t -f share/icons/hicolor
203 ${EXE_WRAPPER_64} bin/gtk-update-icon-cache-3.0.exe -q -t -f share/icons/Adwaita
204 ${EXE_WRAPPER_64} bin/glib-compile-schemas share/glib-2.0/schemas/
208 cleanup_unnecessary_files() {
209 echo "Cleanup unnecessary files"
210 # cleanup temporary files
211 rm -rf var/cache/fontconfig
212 rmdir var/cache
213 rmdir var
214 # cleanup development and other unnecessary files
215 rm -rf include
216 rm -rf lib/cmake
217 rm -rf lib/gettext
218 rm -rf lib/libffi-*
219 rm -rf lib/pkgconfig
220 rm -rf lib/python3.9
221 find lib -name '*.a' -delete
222 find lib -name '*.typelib' -delete
223 find lib -name '*.def' -delete
224 find lib -name '*.h' -delete
225 find lib -name '*.sh' -delete
226 # cleanup other unnecessary files
227 rm -rf share/aclocal
228 rm -rf share/applications
229 rm -rf share/bash-completion
230 rm -rf share/doc
231 rm -rf share/gdb
232 rm -rf share/gettext
233 rm -rf share/gettext-*
234 rm -rf share/gir-1.0
235 rm -rf share/glib-2.0/codegen
236 rm -rf share/glib-2.0/gdb
237 rm -rf share/glib-2.0/gettext
238 rm -rf share/graphite2
239 rm -rf share/gtk-3.0
240 rm -rf share/gtk-doc
241 rm -rf share/icons/Adwaita/cursors
242 rm -rf share/info
243 rm -rf share/man
244 rm -rf share/thumbnailers
245 rm -rf share/vala
246 rm -rf share/xml
247 rm -rf usr/share/libalpm
248 # cleanup binaries and libs (delete anything except *.dll and GSpawn helper binaries)
249 find bin ! -name '*.dll' ! -name 'grep.exe' ! -name 'gspawn-win32-helper*.exe' -type f -delete
250 # cleanup empty directories
251 find . -type d -empty -delete
254 download_and_extract_sort() {
255 echo "Download and unpack 'sort'"
256 # add sort to the bin directory
257 unxutils_archive="unxutilsupdates.zip"
258 wget --no-verbose -O ${unxutils_archive} ${UNX_UTILS_URL}
259 unzip ${unxutils_archive} sort.exe -d bin/
260 rm ${unxutils_archive}
263 create_bundle_dependency_info_file() {
264 # sort.exe from UnxUtils is a 32bit binary, so use $EXE_WRAPPER_32
265 sort_version="$(${EXE_WRAPPER_32} bin/sort.exe --version | sed -n 1p)"
266 # use "sed -n 1p" instead of "head -n1" as grep will otherwise prints a weird error,
267 # probably because the output pipe is closed prematurely
268 grep_version="$(${EXE_WRAPPER_64} bin/grep.exe --version | sed -n 1p)"
269 filename="ReadMe.Dependencies.Geany.txt"
270 cat << EOF > "${filename}"
271 This installation contains dependencies for Geany which are distributed
272 as binaries (usually .dll files) as well as additional files
273 necessary for these dependencies.
274 Following is a list of all included binary packages with their
275 full download URL as used to create this installation.
277 sort.exe is extracted from the ZIP archive at
278 ${UNX_UTILS_URL}.
279 Sort version: ${sort_version}
281 grep.exe is taken from a 64bit MSYS2 installation and
282 is bundled together with its dependencies.
283 Grep version: ${grep_version}
285 Other dependencies are provided by the MSYS2 project
286 (https://msys2.github.io) and were downloaded from:
288 echo -e "${package_urls}" >> "${filename}"
291 create_zip_archive() {
292 if [ "$make_zip" = "yes" ]; then
293 if [ -z "$VERSION" ]; then
294 VERSION="unknown-version"
296 echo "Packing the bundle"
297 zip -r gtk-$VERSION.zip bin etc include lib locale share var
302 # main()
303 handle_command_line_options $@
304 initialize
305 extract_packages
306 move_extracted_files
307 delayed_post_install
308 cleanup_unnecessary_files
309 download_and_extract_sort
310 create_bundle_dependency_info_file
311 create_zip_archive