-
Notifications
You must be signed in to change notification settings - Fork 3
/
prep.sh
177 lines (154 loc) · 6.07 KB
/
prep.sh
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
#!/bin/sh
PSI_DIR="$(cd "$1"; pwd)"
INST_DIR="$(cd "$(dirname "$0")"; pwd)" # readlink can the same easier but it's not always available
BUILD_DIR="$(cd "${INST_DIR}/.."; pwd)/build"
TS_DIR="$(cd "${INST_DIR}/.."; pwd)/psi-l10n"
QM_DIR="${BUILD_DIR}/psi_lang"
QT_QM_DIR="$(qmake -query QT_INSTALL_TRANSLATIONS)"
LANG_REPO_URL=https://github.com/psi-im/psi-l10n.git
SPELL_DIR="$PSI_DIR/myspell/dicts"
die() { echo "Error: $@"; exit 1; }
[ -d "$1" ] || die "Pass a directory with files for installation as a first argument"
cd "${INST_DIR}"
mkdir -p "${QM_DIR}"
if [ "$NOGIT" != 1 ]; then
if [ -d "${TS_DIR}" ]; then
(cd "${TS_DIR}"; git pull) || die "failed to get translation sources"
else
git clone "${LANG_REPO_URL}" "${TS_DIR}" || die "failed to get translation sources"
fi
fi
for f in "${TS_DIR}"/translations/*.ts; do
base="$(basename "$f" .ts)"
code="$(echo "$base" | cut -d '_' -f 2-)" # strip psi_
qm="${QM_DIR}"/${base}.qm
qt_qm="${QT_QM_DIR}/qt_${code}.qm"
if [ "$f" -nt "$qm" ]; then
lrelease "$f" -qm "${qm}" || die "failed to update to generate qm"
fi
if [ "$qt_qm" -nt "${QM_DIR}/qt_${code}.qm" ]; then
cp "${QT_QM_DIR}/qt_${code}.qm" "${QM_DIR}"
fi
done
# QM files are ready by this moment in ../build/psi_lang
# Not let's generate some NSIS magic
flanginst="${BUILD_DIR}/psi_lang_install.nsh"
flangsetup="${BUILD_DIR}/psi_lang_setup.nsh"
rm -f "$flanginst" "$flangsetup"
cat tools/psi_lang.map | grep -E 'Lang.* LANG' | sort | while read -r ldesc; do
#<key>,<SectionName>,<LanguageID>,<LanguageName>
lang_key="$(echo "$ldesc" | cut -f 1)"
lang_section="$(echo "$ldesc" | cut -f 2)"
lang_id="$(echo "$ldesc" | cut -f 3)"
lang_name="$(echo "$ldesc" | cut -f 4-)"
lang_file="psi_${lang_key}.qm"
if [ -f "$QM_DIR/$lang_file" ]; then
echo "Found translation file for ${lang_name}"
else
echo "Translation file for ${lang_name} is not found"
continue
fi
# psi_lang_install.nsh
(echo "
; ${lang_name}
Section /o \"${lang_name}\" $lang_section
SetOverwrite on
!insertmacro UNINSTLOG_OPENINSTALL
\${SetOutPath} \"\$INSTDIR\\translations\\\"
\${File} \"\${APP_BUILD}psi_lang\${FILE_SEPARATOR}\" \"${lang_file}\""
if [ -f "$QM_DIR/qt_${lang_key}.qm" ]; then
echo " \${File} \"\${APP_BUILD}psi_lang\${FILE_SEPARATOR}\" \"qt_${lang_key}.qm\""
fi
echo " !insertmacro UNINSTLOG_CLOSEINSTALL
SectionEnd"
) >> "${flanginst}"
# psi_lang_setup.nsh
if [ -n "$lang_id" ]; then
echo "
StrCmp \$LANGUAGE \${${lang_id}} 0 +2
SectionSetFlags \${${lang_section}} \${SF_SELECTED}" >> "${flangsetup}"
else
echo "
; No ${lang_name} AutoSelection" >> "${flangsetup}"
fi
done
# ========================================================
# nsh files to Psi translations are generated.
# Now lets generate everything else
out_inst="${BUILD_DIR}/psi_files_install.nsh"
echo ";
; List of files to be INSTALLED (Base section)
;
" > $out_inst
directories=$(cd "$PSI_DIR"; find -path './myspell/dicts' -prune -o -path './translations' -prune -o -type d -printf '%P\n')
echo "\${SetOutPath} \$INSTDIR" >> $out_inst
( cd "$PSI_DIR"; find -maxdepth 1 -type f -printf '%P\n' | sed 's|.*|${File} "${APP_SOURCE}${FILE_SEPARATOR}" "\0"|' ) >> $out_inst
for dir in $directories; do
files="$(cd "$PSI_DIR"; find $dir -maxdepth 1 -type f | while read -r f; do d="$(dirname "$f")"; n="$(basename "$f")"; echo "\${File} \"\${APP_SOURCE}\${FILE_SEPARATOR}${d//\//\${FILE_SEPARATOR\}}\${FILE_SEPARATOR}\" \"$n\""; done)"
if [ -n "$files" ]; then
echo "\${SetOutPath} \"\$INSTDIR\${FILE_SEPARATOR}${dir//\//\${FILE_SEPARATOR\}}\"" >> $out_inst
echo "$files" >> $out_inst
else
echo "\${AddItem} \"\$INSTDIR\${FILE_SEPARATOR}${dir//\//\${FILE_SEPARATOR\}}\"" >> $out_inst
fi
done
# ========================================================
# Now the last thing. Install sections for spelling dicts
spell_inst="${BUILD_DIR}/psi_spell_install.nsh"
spell_setup="${BUILD_DIR}/psi_spell_setup.nsh"
rm "$spell_inst" "$spell_setup"
cat tools/spell_lang.map | grep -E 'Lang.* LANG' | sort | while read -r ldesc; do
#<key>,<SectionName>,<LanguageID>,<LanguageName>
lang_key="$(echo "$ldesc" | cut -f 1)"
lang_section="$(echo "$ldesc" | cut -f 2)"
lang_id="$(echo "$ldesc" | cut -f 3)"
lang_name="$(echo "$ldesc" | cut -f 4-)"
if [ -f "$SPELL_DIR/${lang_key}.dic" -a -f "$SPELL_DIR/${lang_key}.aff" ]; then
echo "Found spell dictionary for ${lang_name}"
else
echo "Spell dictionary for ${lang_name} is not found"
continue
fi
# psi_lang_install.nsh
(echo "
; ${lang_name}
Section /o \"${lang_name}\" $lang_section
!insertmacro UNINSTLOG_OPENINSTALL
SetOverwrite on
\${SetOutPath} \"\$INSTDIR\${FILE_SEPARATOR}myspell\${FILE_SEPARATOR}dicts\${FILE_SEPARATOR}\"
\${File} \"\${APP_SOURCE}\${FILE_SEPARATOR}myspell\${FILE_SEPARATOR}dicts\${FILE_SEPARATOR}\" \"${lang_key}.dic\"
\${File} \"\${APP_SOURCE}\${FILE_SEPARATOR}myspell\${FILE_SEPARATOR}dicts\${FILE_SEPARATOR}\" \"${lang_key}.aff\""
echo " !insertmacro UNINSTLOG_CLOSEINSTALL
SectionEnd"
) >> "${spell_inst}"
# psi_lang_setup.nsh
if [ -n "$lang_id" ]; then
echo "
StrCmp \$LANGUAGE \${${lang_id}} 0 +2
SectionSetFlags \${${lang_section}} \${SF_SELECTED}" >> "${spell_setup}"
else
echo "
; No ${lang_name} AutoSelection" >> "${spell_setup}"
fi
done
# ========================================================
# Generate configuration file
echo "
!define APPVERSION \"1.2\"
!define APPEXTRAVERSION \"\"
!define BUILD_WITH_LANGPACKS
; ^ comment if you want to build the installer without language packs
!define BUILD_WITH_SPELL
; ^ comment if you want to build the installer without spell dictionaries
;!define BUILD_32
; ^ uncomment to package a 32-bit psi. otherwise 64-bit psi is assumed
!define FILE_SEPARATOR \"\\\"
!define INSTALLER_HOME \"$(cygpath -pw "$INST_DIR")\"
!define APP_SOURCE \"$(cygpath -pw "$PSI_DIR")\${FILE_SEPARATOR}\"
!define APP_BUILD \"$(cygpath -pw "$BUILD_DIR")\${FILE_SEPARATOR}\"
; Notice these \\ in the end of APP_SOURCE and APP_BUILD. They are meaningful.
!define INSTALLER_BUILD \"0\"
; ^ update whenever you add something to the installer and rebuild it
; without changing APPVERSION
; ^ reset to 0 when you change APPVERSION
" > "${INST_DIR}/config.nsh"