summaryrefslogtreecommitdiff
path: root/win32/makedist/makedist.midori
blob: 1447ba2b9dd62febb6924a8f620a18315875f44c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#! /bin/sh

# Copyright (C) 2010-2011 Peter de Ridder <peter@xfce.org>
# Copyright (C) 2012 Paweł Forysiuk <tuxator@o2.pl>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# See the file COPYING for the full license text.

# script: makedist.midori [version tag]
#
# This script creates an archive containing all required files for
# midori on windows.  The midori version is inserted in the name of
# the archive and appended to the name of the root directory in the
# archive.
# The name of the archive is contructed as follows:
# midori<version tag>-<timestamp>.extension
# The archive contains a root directory named:
# midori<version tag>

# a bit of configuration
root_dir=$MINGW_PREFIX
where_am_i=$PWD

if [ "$GSTREAMER_API_VERSION" == "" ]; then
    GSTREAMER_API_VERSION=0.10
fi

if [ "$MINGW_PREFIX" == "" ]; then
   echo "Error: MINGW_PREFIX variable is empty!"
   exit
fi

# create temporary working directory
temp_dir=`mktemp -d`

# check if we can use 7zip
have_7zip=`which 7za`

GTK3_BUILD=1
# Default to gtk3 but check just in case
GTK3=$(grep GTK3 CMakeCache.txt | awk -F \= '{print $2}')
if [ "$GTK3" != "ON" ] && [ "$GTK3" != "1" ];then
    GTK3_BUILD=0
fi

version=$(grep PACKAGE_VERSION ./midori/CMakeFiles/midori.dir/DependInfo.cmake|sed -e 's/^.*PACKAGE_VERSION=\\"\([^"]*\)\\".*$/\1/')

#strip sha from version if release
if [ "$RELEASE" != "" ];then
    version=$(echo $version| awk -F \~ '{print $1}')
fi

if [ "$1" != "" ]; then
   version_tag="$1"
fi

if [ "$version_tag" != "" ]; then
    version_tag=$version-$version_tag
else
    version_tag=$version
fi

if [ "$RELEASE" == "" ]; then
    ARCHIVE_FILENAME=midori-$version_tag-`date +%Y%m%d%H%M`
else
    ARCHIVE_FILENAME=midori-$version_tag
fi

# generate archive filename
if [ "$have_7zip" != ""  ]; then
    ARCHIVE=$ARCHIVE_FILENAME.7z
else
    ARCHIVE=$ARCHIVE_FILENAME.zip
fi

if [ "NSIS" != "" ];then
    cp -a $where_am_i/../win32/makedist/midori.nsi $temp_dir
    cp -a $where_am_i/../win32/makedist/midori.ico $temp_dir
fi

# function: dll-recursive <list of exe and dll files ...>
#
# recursively search all dll dependencies of the input files.
# The resulting list of dll files including the input files is
# printed to stdout.
dll_recursive ()
{
  temp_file_new=`mktemp`
  temp_file_old=`mktemp`

  while [ "$1" ]
  do
    echo $1 >> $temp_file_new
    shift
  done

  while [ "x`sha1sum - < $temp_file_new`" != "x`sha1sum - < $temp_file_old`" ]
  do
    files=`cat $temp_file_new $temp_file_old | sort | uniq -u`
    cp -L $temp_file_new $temp_file_old
    strings $files 2> /dev/null | grep \\.dll | cat - $temp_file_old | sort | uniq > $temp_file_new
  done

  cat $temp_file_new

  rm $temp_file_new $temp_file_old
}

grab_files ()
{
   local dir="$1"
   pushd $root_dir > /dev/null
   shift
   while [ "$1" ]; do
       find $dir "(" -name "$1" ")" -prune -exec mkdir -p $workdir/{} ";" -exec rmdir --ignore-fail-on-non-empty $workdir/{} ";" -exec cp -Lr {} $workdir/{} ";"
       if [ "$?" -ne "0" ]; then
           exit
       fi
       shift
   done
   popd > /dev/null
}

grab_icons()
{
  local theme="$1"
  local list="$2"
  
  sizes=$(grep CreateDirectory $list |awk -F '"' '{print $2}' |awk -F '\' '{print $6}')
  categories=$(grep InstallIconTheme $list | awk -F '"' '{print $2}'|sort|uniq)

	
  for category in $categories
  do
     category_icons=$(grep InstallIconTheme $list |grep $category|awk -F '"' '{print $4}')
     for size in $sizes
     do
	mkdir -p $workdir/share/icons/$theme/$category/$size
	for icon in $category_icons
        do
	  cp -L /usr/share/icons/$theme/$category/$size/$icon.* $workdir/share/icons/$theme/$category/$size/
        done
     done
  done

  cp -L /usr/share/icons/$theme/index.theme $workdir/share/icons/$theme 

}

echo "Creating $ARCHIVE"

# create destination folder
workdir=$temp_dir/midori-$version
mkdir $workdir

echo "<*> Generating dll list..."

# auto generate dll list, only of existing files
pushd $root_dir/bin > /dev/null
dll_recursive midori*.exe gspawn-*-helper*.exe libhunspell*.dll > $temp_dir/midori.exe.lst
dll_recursive ../lib/gio/modules/*.dll >> $temp_dir/midori.exe.lst
dll_recursive iconv.dll >> $temp_dir/midori.exe.lst
# we ship gdb now for -g and diagnostic button
dll_recursive gdb.exe >> $temp_dir/midori.exe.lst

for i in $(cat $temp_dir/midori.exe.lst | grep -v midori | sort | uniq)
do
  if [ -f $root_dir/bin/$i ]; then
  rpm -qf $root_dir/bin/$i >> $temp_dir/packages_used.lst
  fi
done

dll_recursive ../lib/gstreamer-$GSTREAMER_API_VERSION/*.dll >> $temp_dir/midori.exe.lst
rpm -qf $root_dir/lib/gstreamer-$GSTREAMER_API_VERSION/*.dll >> $temp_dir/packages_used.lst

if [ "$DEBUG_BUILD" != "" ]; then
    dll_recursive GtkLauncher.exe >> $temp_dir/midori.exe.lst
fi

files=`ls | cat - $temp_dir/midori.exe.lst | sort | uniq -d`
rm $temp_dir/midori.exe.lst
popd > /dev/null

echo "<*> Copying dlls..."

# copy auto generate dll list
pushd $root_dir/bin > /dev/null
mkdir $workdir/bin
cp -L $files $workdir/bin 2>/dev/null
popd > /dev/null

mkdir -p $workdir/bin/Plugins
cat > $workdir/bin/portable.bat << _EOF
@ECHO OFF
echo Starting Midori in portable mode!
start midori.exe --portable
pause
_EOF

echo "<*> Copying configuration files..."

# copy etc
grab_files etc midori
grab_files etc gtkrc

# If modules are not compiled we need a list of them
grab_files etc pango
# Freetype is preferred font backend
# copy configuration, otherwise webkit will crash
grab_files etc fonts


echo "<*> Copying modules and libraries..."

# copy lib
if [ "$GTK3_BUILD" == "1" ]; then
    grab_files lib gtk-3.0
else
    grab_files lib gtk-2.0
fi

grab_files lib midori
grab_files lib gdk-pixbuf-2.0

grab_files lib enchant
grab_files lib gio

# Fedora ships on-demand pango modules, check just in case
grab_files lib pango

grab_files lib gstreamer-$GSTREAMER_API_VERSION

echo "<*> Copying resources and translations..."

# copy share
grab_files share midori
grab_files share mime
grab_files share midori.mo

grab_icons Faenza $where_am_i/../win32/makedist/midori.nsi

# We need to ship our CA bundle for now
cp -a /etc/pki/tls/certs/ca-bundle.crt $workdir/share/midori/res/

if [ "$GTK3_BUILD" == "1" ]; then
    grab_files share webkitgtk-3.0
    grab_files share schemas
    mkdir -p $workdir/share/themes/Greybird
    cp -Lr /usr/share/themes/Greybird/gtk-3.0 $workdir/share/themes/Greybird
    MO_VER=30
else
    grab_files share MS-Windows
    grab_files share webkitgtk-1.0
    MO_VER=20
fi

if [ "$DEBUG_BUILD" == "" ];then
    pushd $workdir > /dev/null
    find -iname *.debug -exec rm {} \;
    popd > /dev/null
fi

rpm -qf /etc/pki/tls/certs/ca-bundle.crt >> $temp_dir/packages_used.lst
rpm -qf /usr/share/icons/Faenza/ >> $temp_dir/packages_used.lst
rpm -qf /usr/share/themes/Greybird/gtk-3.0 >> $temp_dir/packages_used.lst

# copy locales for gtk
# so we have translated stock items, file dialogs

pushd $root_dir > /dev/null
find share "(" -name "midori.mo" ")" >  $temp_dir/locale.list
mkdir -p $workdir/share/locale/
for LOCALE in $(cat $temp_dir/locale.list); do
	 LOCALE=$(echo $LOCALE|awk -F/ '{print $3}')
	 cp /usr/share/locale/$LOCALE/LC_MESSAGES/gtk$MO_VER.mo $workdir/share/locale/$LOCALE/LC_MESSAGES/
done
rm $temp_dir/locale.list

echo "<*> Setting up default gtk settings..."
# we want to override default gtk settings
if [ "$GTK3_BUILD" == "1" ]; then
    gtk_etc_dir="$workdir/etc/gtk-3.0/"
    gtk_rc_file="$gtk_etc_dir/settings.ini"
else
    gtk_etc_dir="$workdir/etc/gtk-2.0/"
    gtk_rc_file="$gtk_etc_dir/gtkrc"
fi

mkdir -p $gtk_etc_dir

# Use small icons by default and Faenza icon theme
if [ "$GTK3_BUILD" == "1" ]; then

    cat > $gtk_rc_file << _EOF
[Settings]
gtk-icon-theme-name = Faenza
_EOF

else
    cat > $gtk_rc_file << _EOF
gtk-theme-name = "MS-Windows"
gtk-icon-theme-name = "Faenza"
_EOF

fi

cat >> $gtk_rc_file << _EOF
gtk-toolbar-style = GTK_TOOLBAR_ICONS
gtk-toolbar-icon-size = GTK_ICON_SIZE_MENU
_EOF

mkdir -p $workdir/etc/xdg/midori

cat >> $workdir/etc/xdg/midori/config << _EOF
[settings]
default-font-family=Times New Roman
monospace-font-family=Courier New
default-font-size=14
default-monospace-font-size=14
_EOF

# Don't hardcode mingw path, otherwise fontconfig uses fallback settings
# which tend to look very bad on Windows
sed -r 's@>.+(conf\.d)<@>\1@g' -i $workdir/etc/fonts/fonts.conf

popd > /dev/null

echo "<*> Copying docs..."

# copy doc files to root
cp -L $workdir/share/doc/midori/{COPYING,AUTHORS} $workdir

cat $temp_dir/packages_used.lst | sort | uniq > $workdir/share/doc/midori/README.packages
rm $temp_dir/packages_used.lst

#drop a/la files, we don't do static builds anyway
find $workdir -iname *.*a -exec rm {} \;

echo "<*> Compressing archive (slow)..."
ARCHIVE=`pwd`/$ARCHIVE

# store as zip/7z file
pushd $temp_dir > /dev/null
if [ "$have_7zip" != "" ]; then
    7za a -m0=lzma $ARCHIVE midori-$version_tag > /dev/null
else
    zip -rq $ARCHIVE midori-$version_tag
fi

if [ "$NSIS" != "" ];then
    nsis_file=Midori-${version}_setup.exe
    echo "Creating $nsis_file"
    makensis -NOCD -V2 ./midori.nsi
    mv $nsis_file $where_am_i
fi
popd > /dev/null

echo "<*> Cleaning up..."

# remove working directory
rm -r $temp_dir


echo "<*> Computing checksums..."

sum_file=midori-$version.sha1
sha1sum $ARCHIVE >> $sum_file

if [ "$NSIS" != "" ]; then
    sha1sum $nsis_file >> $sum_file
fi

cat $sum_file