Ruby: delete rspec related kinds
[geany-mirror.git] / scripts / gtk-bundle-from-msys2.sh
blob1b99258aff8a891cb13e943c9300efef0e0d1914
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 libwinpthread-git
39 harfbuzz
40 fontconfig
41 freetype
42 atk
43 pango
44 cairo
45 pixman
46 gdk-pixbuf2
49 handle_command_line_options() {
50 for opt in "$@"; do
51 case "$opt" in
52 "-c"|"--cache")
53 use_cache="yes"
55 "-z"|"--zip")
56 make_zip="yes"
58 "-2")
59 gtkv="2"
61 "-3")
62 gtkv="3"
64 "-n")
65 run_pi=""
67 "-h"|"--help")
68 echo "gtk-bundle-from-msys2.sh [-c] [-h] [-n] [-z] [-2 | -3] [CACHEDIR]"
69 echo " -c Use pacman cache. Otherwise pacman will download"
70 echo " archive files"
71 echo " -h Show this help screen"
72 echo " -n Do not run post install scripts of the packages"
73 echo " -z Create a zip afterwards"
74 echo " -2 Prefer gtk2"
75 echo " -3 Prefer gtk3"
76 echo "CACHEDIR Directory where to look for cached packages (default: /var/cache/pacman/pkg)"
77 exit 1
80 cachedir="$opt"
82 esac
83 done
86 initialize() {
87 if [ -z "$cachedir" ]; then
88 cachedir="/var/cache/pacman/pkg"
91 if [ "$use_cache" = "yes" ] && ! [ -d "$cachedir" ]; then
92 echo "Cache dir \"$cachedir\" not a directory"
93 exit 1
96 gtk="gtk$gtkv"
97 eval "gtk_dependency_pkgs=\${${gtk}_dependency_pkgs}"
99 pkgs="
100 ${packages}
101 ${gtk_dependency_pkgs}
102 ${gtk}
106 _getpkg() {
107 if [ "$use_cache" = "yes" ]; then
108 package_info=`pacman -Qi mingw-w64-$ABI-$1`
109 package_version=`echo "$package_info" | grep "^Version " | cut -d':' -f 2 | tr -d '[[:space:]]'`
110 ls $cachedir/mingw-w64-${ABI}-${1}-${package_version}-* | sort -V | tail -n 1
111 else
112 pacman -Sp mingw-w64-${ABI}-${1}
116 _remember_package_source() {
117 if [ "$use_cache" = "yes" ]; then
118 package_url=`pacman -Sp mingw-w64-${ABI}-${2}`
119 else
120 package_url="${1}"
122 package_urls="${package_urls}\n${package_url}"
125 extract_packages() {
126 for i in $pkgs; do
127 pkg=$(_getpkg $i)
128 _remember_package_source $pkg $i
129 if [ "$use_cache" = "yes" ]; then
130 if [ -e "$pkg" ]; then
131 echo "Extracting $pkg from cache"
132 tar xaf $pkg
133 else
134 echo "ERROR: File $pkg not found"
135 exit 1
137 else
138 echo "Download $pkg using curl"
139 curl -L "$pkg" | tar -x --xz
141 if [ -n "$run_pi" ] && [ -f .INSTALL ]; then
142 echo "Running post_install script for \"$i\""
143 /bin/bash -c ". .INSTALL; post_install"
145 if [ "$make_zip" = "yes" -a "$i" = "$gtk" ]; then
146 VERSION=$(grep ^pkgver .PKGINFO | sed -e 's,^pkgver = ,,' -e 's,-.*$,,')
148 rm -f .INSTALL .MTREE .PKGINFO .BUILDINFO
149 done
152 move_extracted_files() {
153 echo "Move extracted data to destination directory"
154 if [ -d mingw32 ]; then
155 for d in bin etc home include lib locale share var; do
156 if [ -d "mingw32/$d" ]; then
157 rm -rf $d
158 # prevent sporadic 'permission denied' errors on my system, not sure why they happen
159 sleep 0.5
160 mv mingw32/$d .
162 done
163 rmdir mingw32
167 cleanup_unnecessary_files() {
168 echo "Cleanup unnecessary files"
169 # cleanup temporary files
170 rm -rf var/cache/fontconfig
171 rmdir var/cache
172 rmdir var
173 # cleanup development and other unnecessary files
174 rm -rf include
175 rm -rf lib/gettext
176 rm -rf lib/libffi-*
177 rm -rf lib/pkgconfig
178 find lib -name '*.a' -delete
179 find lib -name '*.typelib' -delete
180 find lib -name '*.def' -delete
181 find lib -name '*.h' -delete
182 find lib -name '*.sh' -delete
183 # cleanup other unnecessary files
184 rm -rf share/aclocal
185 rm -rf share/applications
186 rm -rf share/bash-completion
187 rm -rf share/doc
188 rm -rf share/gdb
189 rm -rf share/gettext
190 rm -rf share/gir-1.0
191 rm -rf share/glib-2.0
192 rm -rf share/gtk-2.0
193 rm -rf share/gtk-3.0
194 rm -rf share/gtk-doc
195 rm -rf share/info
196 rm -rf share/man
197 rm -rf share/xml
198 # cleanup binaries and libs (delete anything except *.dll)
199 find bin ! -name '*.dll' -type f -delete
200 # cleanup empty directories
201 find . -type d -empty -delete
204 download_and_compile_grep() {
205 grep_archive="grep_source.tar.xz"
206 grep_build_dir="grep_build"
207 grep_build_log="grep_build.log"
208 echo "Download and compile 'grep' (see ${grep_build_dir}/${grep_build_log} for details)"
209 mkdir ${grep_build_dir}
210 cd ${grep_build_dir}
211 wget --no-verbose -O ${grep_archive} ${GREP_URL}
212 tar xf ${grep_archive}
213 grep-2*/configure > ${grep_build_log} 2>&1 || exit 1
214 make >> ${grep_build_log} 2>&1 || exit 1
215 strip src/grep.exe
216 cp src/grep.exe ../bin/
217 cd ..
218 rm -rf ${grep_build_dir}
221 download_and_extract_sort() {
222 echo "Download and unpack 'sort'"
223 # add sort to the bin directory
224 unxutils_archive="unxutilsupdates.zip"
225 wget --no-verbose -O ${unxutils_archive} ${UNX_UTILS_URL}
226 unzip ${unxutils_archive} sort.exe -d bin/
227 rm ${unxutils_archive}
230 create_bundle_dependency_info_file() {
231 filename="ReadMe.Dependencies.Geany.txt"
232 cat << EOF > "${filename}"
233 This installation contains dependencies for Geany which are distributed
234 as binaries (usually .dll files) as well as additional files
235 necessary for these dependencies.
236 Following is a list of all included binary packages with their
237 full download URL as used to create this installation.
239 sort.exe is extracted from the ZIP archive at
240 ${UNX_UTILS_URL}.
242 grep.exe is self-compiled from the sources available at
243 ${GREP_URL}.
244 Used command to compile: ./configure && make
246 Other dependencies are provided by the MSYS2 project
247 (https://msys2.github.io) and were downloaded from:
249 echo -e "${package_urls}" >> "${filename}"
250 unix2dos "${filename}"
253 create_zip_archive() {
254 if [ "$make_zip" = "yes" ]; then
255 if [ -z "$VERSION" ]; then
256 VERSION="unknown-version"
258 echo "Packing the bundle"
259 zip -r gtk-$VERSION.zip bin etc include lib locale share var
264 # main()
265 handle_command_line_options $@
266 initialize
267 extract_packages
268 move_extracted_files
269 cleanup_unnecessary_files
270 download_and_compile_grep
271 download_and_extract_sort
272 create_bundle_dependency_info_file
273 create_zip_archive