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
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"
24 gtk3_dependency_pkgs
=""
25 gtk4_dependency_pkgs
=""
62 handle_command_line_options
() {
84 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-3 | -4] [CACHEDIR]"
85 echo " -c Use pacman cache. Otherwise pacman will download"
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)"
103 set -e # stop on errors
104 # enable extended globbing as we need it in _getpkg
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"
117 if [ "$cross" != "yes" ]; then
118 # if running natively, we do not need wine or any other wrappers
124 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
128 ${gtk_dependency_pkgs}
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
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})
152 package_urls
="${package_urls}\n${package_url}"
158 _remember_package_source
$pkg $i
159 if [ "$use_cache" = "yes" ]; then
160 if [ -e "$pkg" ]; then
161 echo "Extracting $pkg from cache"
164 echo "ERROR: File $pkg not found"
168 echo "Download $pkg using curl"
169 filename
=$
(basename "$pkg")
170 curl
--silent --location --output "$filename" "$pkg"
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
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
187 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
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
214 # cleanup development and other unnecessary files
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
228 rm -rf share
/applications
229 rm -rf share
/bash-completion
233 rm -rf share
/gettext-
*
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
241 rm -rf share
/icons
/Adwaita
/cursors
244 rm -rf share
/thumbnailers
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
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
303 handle_command_line_options $@
308 cleanup_unnecessary_files
309 download_and_extract_sort
310 create_bundle_dependency_info_file