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.
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"
21 gtk2_dependency_pkgs
=""
22 gtk3_dependency_pkgs
="
52 handle_command_line_options
() {
71 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-2 | -3] [CACHEDIR]"
72 echo " -c Use pacman cache. Otherwise pacman will download"
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)"
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"
100 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
104 ${gtk_dependency_pkgs}
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
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}`
125 package_urls
="${package_urls}\n${package_url}"
131 _remember_package_source
$pkg $i
132 if [ "$use_cache" = "yes" ]; then
133 if [ -e "$pkg" ]; then
134 echo "Extracting $pkg from cache"
137 echo "ERROR: File $pkg not found"
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
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
161 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
170 cleanup_unnecessary_files
() {
171 echo "Cleanup unnecessary files"
172 # cleanup temporary files
173 rm -rf var
/cache
/fontconfig
176 # cleanup development and other unnecessary files
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
188 rm -rf share
/applications
189 rm -rf share
/bash-completion
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
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
() {
212 if [ "${own_arch}" == "${ABI}" -o -z "${MSYS2_ABI_PATH}" ]; then
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
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
275 handle_command_line_options $@
279 cleanup_unnecessary_files
280 copy_grep_and_dependencies
281 download_and_extract_sort
282 create_bundle_dependency_info_file