rev |
line source |
al@865
|
1 #!/bin/sh
|
al@865
|
2 #
|
al@865
|
3 # compressor - module of the SliTaz Cook
|
al@865
|
4 # Copyright (C) SliTaz GNU/Linux - GNU GPL v3
|
al@865
|
5 #
|
al@865
|
6
|
al@865
|
7 . /usr/lib/slitaz/libcook.sh
|
al@865
|
8
|
al@865
|
9
|
al@865
|
10 #
|
al@865
|
11 # Functions
|
al@865
|
12 #
|
al@865
|
13
|
al@865
|
14
|
al@865
|
15 # Display time.
|
al@865
|
16
|
al@865
|
17 disp_time() {
|
al@865
|
18 div=$(( ($1 + 30) / 60))
|
al@865
|
19 case $div in
|
al@865
|
20 0) min='';;
|
al@865
|
21 # L10n: 'm' is for minutes (approximate time)
|
al@865
|
22 *) min=$(_n ' ~ %dm' "$div");;
|
al@865
|
23 esac
|
al@865
|
24
|
al@865
|
25 # L10n: 's' is for seconds (cooking time)
|
al@865
|
26 _ '%ds%s' "$1" "$min"
|
al@865
|
27 }
|
al@865
|
28
|
al@865
|
29
|
al@865
|
30 # Compressor mini summary
|
al@865
|
31
|
al@865
|
32 comp_summary() {
|
al@865
|
33 # "$time0" "$size0" "$size1"
|
al@865
|
34 time1=$(date +%s)
|
al@865
|
35 status
|
al@865
|
36 [ "$2" -eq 0 ] && return
|
al@865
|
37 time=$(($time1 - $1))
|
al@865
|
38 saving=$(( ($2 - $3) / 1024 ))
|
al@865
|
39 _ ' Time: %s. Size: %s B -> %s B. Save: %s KB' "$(disp_time $time)" "$2" "$3" "$saving"
|
al@865
|
40 }
|
al@865
|
41
|
al@865
|
42
|
al@865
|
43 # Calculating different sizes
|
al@865
|
44
|
al@865
|
45 sizes() {
|
al@865
|
46 case $1 in
|
al@865
|
47 man) find $install/usr/share/man -type f -exec ls -l \{\} \; ;;
|
al@865
|
48 png) find $install -type f -name '*.png' -exec ls -l \{\} \; ;;
|
al@865
|
49 svg) find $install -type f -name '*.svg' -exec ls -l \{\} \; ;;
|
al@865
|
50 xml) find $install -type f \( -name '*.ui' -o -name '*.glade' \) -exec ls -l \{\} \; ;;
|
al@865
|
51 des) find $install -type f -name '*.desktop' -exec ls -l \{\} \; ;;
|
al@865
|
52 mo1) find $install -type f -name '*.mo' -exec ls -l \{\} \; ;;
|
al@865
|
53 loc) find $install/usr/share/i18n/locales -type f -exec ls -l \{\} \; ;;
|
al@865
|
54 mo2) find $fs/usr/share/locale -type f -name '*.mo' -exec ls -l \{\} \; ;;
|
al@865
|
55 esac | awk '{s+=$5}END{print s}'
|
al@865
|
56 }
|
al@865
|
57
|
al@865
|
58
|
al@865
|
59 # Function to compress all man pages
|
al@865
|
60 # Compressing can be disabled with COOKOPTS="!manz"
|
al@865
|
61
|
al@865
|
62 compress_manpages() {
|
al@865
|
63 time0=$(date +%s)
|
al@865
|
64 [ "${COOKOPTS/!manz/}" != "$COOKOPTS" ] && return
|
al@865
|
65 manpath="$install/usr/share/man"
|
al@865
|
66 [ -d "$manpath" ] || return
|
al@865
|
67 size0=$(sizes man); [ -z "$size0" ] && return
|
al@865
|
68
|
al@867
|
69 tazpkg -gi advancecomp --quiet --cookmode
|
al@867
|
70
|
al@865
|
71 action 'Compressing man pages...'
|
al@865
|
72
|
al@865
|
73 # We'll use only Gzip compression, so decompress other formats first
|
al@865
|
74 find $manpath -type f -name '*.bz2' -exec bunzip2 \{\} \;
|
al@865
|
75 find $manpath -type f -name '*.xz' -exec unxz \{\} \;
|
al@865
|
76
|
al@865
|
77 # Fast compress with gzip
|
al@865
|
78 find $manpath -type f -name '*.[1-9]*' -exec gzip \{\} \;
|
al@865
|
79
|
al@865
|
80 # Fix symlinks
|
al@865
|
81 for i in $(find $install/usr/share/man -type l); do
|
al@865
|
82 dest=$(readlink $i | sed 's|\.[gbx]z2*$||')
|
al@865
|
83 link=$(echo $i | sed 's|\.[gbx]z2*$||')
|
al@865
|
84 rm $i; ln -s $dest.gz $link.gz
|
al@865
|
85 done
|
al@865
|
86
|
al@865
|
87 # Recompress with advdef (it can't compress, only recompress)
|
al@865
|
88 for i in $(find $install/usr/share/man -type f); do
|
al@865
|
89 advdef -z4q $i
|
al@865
|
90 done
|
al@865
|
91
|
al@865
|
92 comp_summary "$time0" "$size0" "$(sizes man)"
|
al@865
|
93 }
|
al@865
|
94
|
al@865
|
95
|
al@865
|
96 # Function used after compile_rules() to compress all png images
|
al@865
|
97 # Compressing can be disabled with COOKOPTS="!pngz"
|
al@865
|
98
|
al@865
|
99 compress_png() {
|
al@865
|
100 time0=$(date +%s)
|
al@865
|
101 [ "${COOKOPTS/!pngz/}" != "$COOKOPTS" ] && return
|
al@865
|
102 size0=$(sizes png); [ -z "$size0" ] && return
|
al@865
|
103
|
al@865
|
104 use_pq=true
|
al@865
|
105 use_op=true
|
al@865
|
106 [ "${COOKOPTS/!pngquant/}" != "$COOKOPTS" ] && use_pq=false
|
al@865
|
107 [ "${COOKOPTS/!optipng/}" != "$COOKOPTS" ] && use_op=false
|
al@867
|
108 $use_pq && tazpkg -gi pngquant --quiet --cookmode
|
al@867
|
109 $use_op && tazpkg -gi optipng --quiet --cookmode
|
al@865
|
110
|
al@867
|
111 action 'Compressing png images...'
|
al@865
|
112
|
al@865
|
113 oplevel=$(echo $COOKOPTS | grep 'op[0-8]' | sed 's|.*op\([0-8]\).*|\1|')
|
al@865
|
114 [ -z "$oplevel" ] && oplevel='2'
|
al@865
|
115 [ "$oplevel" == '8' ] && oplevel='7 -zm1-9'
|
al@865
|
116
|
al@865
|
117 for i in $(find $install -type f -name '*.png'); do
|
al@865
|
118 $use_pq && pngquant -f --skip-if-larger --ext .png --speed 1 "$i"
|
al@865
|
119 $use_op && optipng -quiet -strip all -o$oplevel "$i"
|
al@865
|
120 done
|
al@865
|
121
|
al@865
|
122 comp_summary "$time0" "$size0" "$(sizes png)"
|
al@865
|
123 }
|
al@865
|
124
|
al@865
|
125
|
al@865
|
126 # Function used after compile_rules() to compress all svg images
|
al@865
|
127 # Compressing can be disabled with COOKOPTS="!svgz"
|
al@865
|
128
|
al@865
|
129 compress_svg() {
|
al@865
|
130 time0=$(date +%s)
|
al@865
|
131 [ "${COOKOPTS/!svgz/}" != "$COOKOPTS" ] && return
|
al@865
|
132 size0=$(sizes svg); [ -z "$size0" ] && return
|
al@865
|
133
|
al@867
|
134 tazpkg -gi svgcleaner --quiet --cookmode
|
al@867
|
135
|
al@865
|
136 action 'Compressing svg images...'
|
al@865
|
137
|
al@865
|
138 cleaner_log="$(mktemp)"
|
al@865
|
139 for i in $(find $install -type f -name '*.svg'); do
|
al@865
|
140 echo -n "$i: " >> "$cleaner_log"
|
al@865
|
141 svgcleaner "$i" "$i" --remove-unresolved-classes false --quiet true >> "$cleaner_log"
|
al@865
|
142 done
|
al@865
|
143
|
al@865
|
144 comp_summary "$time0" "$size0" "$(sizes svg)"
|
al@865
|
145
|
al@865
|
146 sed -i '/: $/d' "$cleaner_log"
|
al@865
|
147 if [ -s "$cleaner_log" ]; then
|
al@865
|
148 _ 'Cleaner warnings and errors:'
|
al@865
|
149 awk '{printf " %s\n", $0;}' "$cleaner_log"
|
al@865
|
150 echo
|
al@865
|
151 fi
|
al@865
|
152 rm "$cleaner_log"
|
al@865
|
153 }
|
al@865
|
154
|
al@865
|
155
|
al@865
|
156 # Function used after compile_rules() to shrink all *.ui and *.glade files:
|
al@865
|
157 # remove insignificant spaces and comments
|
al@865
|
158 # Compressing can be disabled with COOKOPTS="!uiz"
|
al@865
|
159
|
al@865
|
160 compress_ui() {
|
al@865
|
161 [ "${COOKOPTS/!uiz/}" != "$COOKOPTS" ] && return
|
al@865
|
162 [ -z "$(find $install -type f \( -name '*.ui' -o -name '*.glade' \) )" ] && return
|
al@865
|
163
|
al@867
|
164 tazpkg -gi xmlstarlet --quiet --cookmode
|
al@867
|
165
|
al@865
|
166 action 'Compressing ui files...'
|
al@867
|
167
|
al@865
|
168 size0=$(sizes xml)
|
al@865
|
169 time0=$(date +%s)
|
al@865
|
170 temp_ui="$(mktemp)"
|
al@865
|
171 for ui in $(find $install -type f \( -name '*.ui' -o -name '*.glade' \) ); do
|
al@865
|
172 xmlstarlet c14n --without-comments "$ui" | xmlstarlet sel -B -t -c '*' > "$temp_ui"
|
al@865
|
173 cat "$temp_ui" > "$ui"
|
al@865
|
174 done
|
al@865
|
175
|
al@865
|
176 comp_summary "$time0" "$size0" "$(sizes xml)"
|
al@865
|
177 rm "$temp_ui"
|
al@865
|
178 }
|
al@865
|
179
|
al@865
|
180
|
al@865
|
181 # Get list of supported locales...
|
al@865
|
182
|
al@865
|
183 get_supported_locales() {
|
al@865
|
184 lpc='/slitaz-i18n/stuff/locale-pack.conf'
|
al@865
|
185 if [ -e "$WOK$lpc" ]; then
|
al@865
|
186 # ... from package in the local wok
|
al@865
|
187 . "$WOK$lpc"
|
al@865
|
188 else
|
al@865
|
189 # ... from Hg
|
al@865
|
190 temp_conf=$(mktemp)
|
al@865
|
191 wget -q -O $temp_conf -T 10 "http://hg.slitaz.org/wok/raw-file/tip$lpc"
|
al@865
|
192 if [ -s $temp_conf ]; then
|
al@865
|
193 . $temp_conf
|
al@865
|
194 else
|
al@865
|
195 # Give up and use hardcoded list
|
al@865
|
196 LOCALE_PACK="ar ca cs da de el en es fi fr hr hu id is it ja nb nl nn pl pt \
|
al@865
|
197 pt_BR ro ru sl sv tr uk zh_CN zh_TW"
|
al@865
|
198 fi
|
al@865
|
199 rm $temp_conf
|
al@865
|
200 fi
|
al@865
|
201 echo $LOCALE_PACK
|
al@865
|
202 }
|
al@865
|
203
|
al@865
|
204
|
al@865
|
205 # Fix common errors and warnings in the .desktop files
|
al@865
|
206 # Fixing can be disabled with COOKOPTS="!fixdesktops"
|
al@865
|
207
|
al@865
|
208 fix_desktop_files() {
|
al@865
|
209 [ "${COOKOPTS/!fixdesktops/}" != "$COOKOPTS" ] && return
|
al@865
|
210 [ -z "$(find $install -type f -name '*.desktop')" ] && return
|
al@865
|
211
|
al@865
|
212 size0=$(sizes des)
|
al@865
|
213 time0=$(date +%s)
|
al@865
|
214
|
al@865
|
215 if [ -n "$QA" -a -z "$(which desktop-file-validate)" ]; then
|
al@867
|
216 tazpkg -gi desktop-file-utils-extra --quiet --cookmode
|
al@865
|
217 fi
|
al@865
|
218
|
al@865
|
219 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
|
al@865
|
220 # Default value is "" (empty). That means for us that we'll use the full
|
al@865
|
221 # list of supported locales here.
|
al@865
|
222 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
|
al@865
|
223
|
al@865
|
224 for desktop in $(find $install -type f -name '*.desktop'); do
|
al@865
|
225 cp "$desktop" "$desktop.orig"
|
al@865
|
226
|
al@865
|
227 # Sort out .desktop file (is prerequisite to correct working of `fix-desktop-file`)
|
al@865
|
228 sdft "$desktop" -i
|
al@865
|
229
|
al@865
|
230 # Fix common errors in .desktop file
|
al@865
|
231 fix-desktop-file "$desktop"
|
al@865
|
232
|
al@865
|
233 # Strip unsupported locales from .desktop file
|
al@865
|
234 [ "${COOKOPTS/!i18nz/}" == "$COOKOPTS" ] &&
|
al@865
|
235 sdft "$desktop" -i -k "$LOCALE"
|
al@865
|
236
|
al@865
|
237 # Extra-strip
|
al@865
|
238 [ "${COOKOPTS/!extradesktops/}" == "$COOKOPTS" ] &&
|
al@865
|
239 sdft "$desktop" -i -g -x -tf -r 'Keywords*' -o
|
al@865
|
240
|
al@865
|
241 if [ -n "$QA" ]; then
|
al@865
|
242 # Check the rest of errors, warnings and tips
|
al@865
|
243 _ 'QA: Checking %s...' "$(basename $desktop)"
|
al@865
|
244 diff "$desktop.orig" "$desktop"
|
al@865
|
245 desktop-file-validate "$desktop" | busybox fold -s
|
al@865
|
246 echo
|
al@865
|
247 fi
|
al@865
|
248
|
al@865
|
249 rm "$desktop.orig"
|
al@865
|
250 done
|
al@865
|
251
|
al@865
|
252 comp_summary "$time0" "$size0" "$(sizes des)"
|
al@865
|
253 }
|
al@865
|
254
|
al@865
|
255
|
al@865
|
256 # Normalize all *.mo files: unconditionally convert to UTF-8; remove strings that are not really added
|
al@865
|
257 # to the translation (msgid = msgstr)
|
al@865
|
258 # Normalization can be disabled with COOKOPTS="!monorm"
|
al@865
|
259
|
al@865
|
260 normalize_mo() {
|
al@865
|
261 [ "${COOKOPTS/!monorm/}" != "$COOKOPTS" ] && return
|
al@865
|
262 [ -z "$(find $install -type f -name '*.mo')" ] && return
|
al@865
|
263
|
al@867
|
264 # Gettext functions: msgunfmt, msguniq, msgconv, msgfmt
|
al@867
|
265 tazpkg -gi gettext --quiet --cookmode
|
al@867
|
266 # Gconv modules (convert to UTF-8)
|
al@867
|
267 tazpkg -gi glibc-locale --quiet --cookmode
|
al@867
|
268
|
al@865
|
269 action 'Normalizing mo files...'
|
al@867
|
270
|
al@865
|
271 size0=$(sizes mo1)
|
al@865
|
272 time0=$(date +%s)
|
al@865
|
273
|
al@865
|
274 # Process all existing *.mo files
|
al@865
|
275 for mo in $(find "$install" -type f -name '*.mo'); do
|
al@865
|
276 tmpfile="$(mktemp)"
|
al@865
|
277
|
al@865
|
278 msgunfmt "$mo" | msguniq | msgconv -o "$tmpfile" -t 'UTF-8'
|
al@865
|
279 # add newline
|
al@865
|
280 echo >> "$tmpfile"
|
al@865
|
281
|
al@865
|
282 # get Plural-Forms
|
al@865
|
283 awk '
|
al@865
|
284 BEGIN { skip = ""; }
|
al@865
|
285 {
|
al@865
|
286 if (! skip) {
|
al@865
|
287 s = $0;
|
al@865
|
288 gsub(/^[^\"]*\"/, "", s);
|
al@865
|
289 gsub(/\"$/, "", s);
|
al@865
|
290 printf("%s", s);
|
al@865
|
291 }
|
al@865
|
292 if (! $0) skip = "yes";
|
al@865
|
293 }
|
al@865
|
294 ' "$tmpfile" | sed 's|\\n|\n|g' | grep "^Plural-Forms:" > "$tmpfile.pf"
|
al@865
|
295
|
al@865
|
296 if ! grep -q 'msgid_plural' "$tmpfile"; then
|
al@865
|
297 echo > "$tmpfile.pf"
|
al@865
|
298 fi
|
al@865
|
299
|
al@865
|
300 # main
|
al@865
|
301 awk -v pf="$(cat "$tmpfile.pf")" '
|
al@865
|
302 function clean() {
|
al@865
|
303 mode = msgctxt = msgid = msgid_plural = msgstr = msgstr0 = msgstr1 = msgstr2 = msgstr3 = msgstr4 = msgstr5 = "";
|
al@865
|
304 }
|
al@865
|
305
|
al@865
|
306 function getstring() {
|
al@865
|
307 # Skip unquoted words at the beginning (msgid, msgstr...) and get string from inside quotes
|
al@865
|
308 s = $0;
|
al@865
|
309 gsub(/^[^\"]*\"/, "", s);
|
al@865
|
310 gsub(/\"$/, "", s);
|
al@865
|
311 return s;
|
al@865
|
312 }
|
al@865
|
313
|
al@865
|
314 BEGIN {
|
al@865
|
315 printf("msgid \"\"\nmsgstr \"\"\n\"Content-Type: text/plain; charset=UTF-8\\n\"\n");
|
al@865
|
316 if (pf)
|
al@865
|
317 printf("\"%s\\n\"\n", pf);
|
al@865
|
318 printf("\n");
|
al@865
|
319 skip = 1;
|
al@865
|
320 clean();
|
al@865
|
321 }
|
al@865
|
322
|
al@865
|
323 {
|
al@865
|
324 # Skip the entire header
|
al@865
|
325 if (!skip) {
|
al@865
|
326 if ($1 == "msgctxt" || $1 == "msgid" || $1 == "msgstr" || $1 == "msgid_plural")
|
al@865
|
327 mode = $1;
|
al@865
|
328 if ($1 == "msgstr[0]") mode = "msgstr0";
|
al@865
|
329 if ($1 == "msgstr[1]") mode = "msgstr1";
|
al@865
|
330 if ($1 == "msgstr[2]") mode = "msgstr2";
|
al@865
|
331 if ($1 == "msgstr[3]") mode = "msgstr3";
|
al@865
|
332 if ($1 == "msgstr[4]") mode = "msgstr4";
|
al@865
|
333 if ($1 == "msgstr[5]") mode = "msgstr5";
|
al@865
|
334
|
al@865
|
335 if (mode == "msgctxt") msgctxt = msgctxt getstring();
|
al@865
|
336 if (mode == "msgid") msgid = msgid getstring();
|
al@865
|
337 if (mode == "msgstr") msgstr = msgstr getstring();
|
al@865
|
338 if (mode == "msgid_plural") msgid_plural = msgid_plural getstring();
|
al@865
|
339 if (mode == "msgstr0") msgstr0 = msgstr0 getstring();
|
al@865
|
340 if (mode == "msgstr1") msgstr1 = msgstr1 getstring();
|
al@865
|
341 if (mode == "msgstr2") msgstr2 = msgstr2 getstring();
|
al@865
|
342 if (mode == "msgstr3") msgstr3 = msgstr3 getstring();
|
al@865
|
343 if (mode == "msgstr4") msgstr4 = msgstr4 getstring();
|
al@865
|
344 if (mode == "msgstr5") msgstr5 = msgstr5 getstring();
|
al@865
|
345
|
al@865
|
346 if (! $0) {
|
al@865
|
347 if (msgid != msgstr) {
|
al@865
|
348 if (msgctxt) printf("msgctxt \"%s\"\n", msgctxt);
|
al@865
|
349 printf("msgid \"%s\"\n", msgid);
|
al@865
|
350 if (msgid_plural) printf("msgid_plural \"%s\"\n", msgid_plural);
|
al@865
|
351 if (msgstr) printf("msgstr \"%s\"\n", msgstr);
|
al@865
|
352 if (msgstr0) printf("msgstr[0] \"%s\"\n", msgstr0);
|
al@865
|
353 if (msgstr1) printf("msgstr[1] \"%s\"\n", msgstr1);
|
al@865
|
354 if (msgstr2) printf("msgstr[2] \"%s\"\n", msgstr2);
|
al@865
|
355 if (msgstr3) printf("msgstr[3] \"%s\"\n", msgstr3);
|
al@865
|
356 if (msgstr4) printf("msgstr[4] \"%s\"\n", msgstr4);
|
al@865
|
357 if (msgstr5) printf("msgstr[5] \"%s\"\n", msgstr5);
|
al@865
|
358 printf("\n");
|
al@865
|
359 }
|
al@865
|
360 clean();
|
al@865
|
361 }
|
al@865
|
362 }
|
al@865
|
363 if ($0 == "") skip = "";
|
al@865
|
364 }
|
al@865
|
365 ' "$tmpfile" > "$tmpfile.awk"
|
al@865
|
366
|
al@865
|
367 msgfmt "$tmpfile.awk" -o "$tmpfile.mo"
|
al@865
|
368
|
al@865
|
369 if [ -s "$tmpfile.mo" ]; then
|
al@865
|
370 rm "$mo"; mv "$tmpfile.mo" "$mo"
|
al@865
|
371 else
|
al@865
|
372 _ 'Error processing %s' "$mo"
|
al@865
|
373 [ -e "$tmpfile.mo" ] && rm "$tmpfile.mo"
|
al@865
|
374 fi
|
al@865
|
375
|
al@865
|
376 # Clean
|
al@865
|
377 rm "$tmpfile" "$tmpfile.pf" "$tmpfile.awk"
|
al@865
|
378 done
|
al@865
|
379
|
al@865
|
380 comp_summary "$time0" "$size0" "$(sizes mo1)"
|
al@865
|
381 }
|
al@865
|
382
|
al@865
|
383
|
al@865
|
384 # Strip locale definitions: normalize whitespace and remove comments
|
al@865
|
385 # Stripping can be disabled with COOKOPTS="!locdef"
|
al@865
|
386
|
al@865
|
387 strip_locale_def() {
|
al@865
|
388 [ "${COOKOPTS/!locdef/}" != "$COOKOPTS" ] && return
|
al@865
|
389 [ ! -d "$install/usr/share/i18n/locales" ] && return
|
al@865
|
390 [ -z "$(find $install/usr/share/i18n/locales -type f)" ] && return
|
al@865
|
391
|
al@865
|
392 action 'Stripping locale definitions...'
|
al@865
|
393 size0=$(sizes loc)
|
al@865
|
394 time0=$(date +%s)
|
al@865
|
395
|
al@865
|
396 for i in $(find $install/usr/share/i18n/locales -type f); do
|
al@865
|
397 sed -i 's| | |g; s| *| |g; s|^ ||; /^%/d' $i
|
al@865
|
398 done
|
al@865
|
399
|
al@865
|
400 comp_summary "$time0" "$size0" "$(sizes loc)"
|
al@865
|
401 }
|
al@865
|
402
|
al@865
|
403
|
al@865
|
404 # Find and strip: --strip-all (-s) or --strip-debug on static libs as well
|
al@865
|
405 # as removing unneeded files like in Python packages. Cross compiled binaries
|
al@865
|
406 # must be stripped with cross-tools aka $ARCH-slitaz-*-strip
|
al@865
|
407 # Stripping can be disabled with COOKOPTS="!strip"
|
al@865
|
408
|
al@865
|
409 strip_package() {
|
al@865
|
410 [ "${COOKOPTS/!strip/}" != "$COOKOPTS" ] && return
|
al@865
|
411
|
al@865
|
412 case "$ARCH" in
|
al@865
|
413 arm*|x86_64) export STRIP="$HOST_SYSTEM-strip" ;;
|
al@865
|
414 *) export STRIP='strip' ;;
|
al@865
|
415 esac
|
al@865
|
416 action 'Executing strip on all files...'
|
al@865
|
417 size0=0
|
al@865
|
418 size1=0
|
al@865
|
419 time0=$(date +%s)
|
al@865
|
420
|
al@865
|
421 # Strip executable files
|
al@865
|
422 for dir in $fs/bin $fs/sbin $fs/usr/bin $fs/usr/sbin $fs/usr/games; do
|
al@865
|
423 if [ -d "$dir" ]; then
|
al@865
|
424 oldsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
425 find $dir -type f -exec $STRIP -s '{}' 2>/dev/null \;
|
al@865
|
426 newsize=$(find $dir -type f -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
427 size0=$((size0 + oldsize)); size1=$((size1 + newsize))
|
al@865
|
428 fi
|
al@865
|
429 done
|
al@865
|
430
|
al@865
|
431 # Strip shared and static libraries
|
al@865
|
432 # Remove Python *.pyc and *.pyo, Perl perllocal.pod and .packlist
|
al@865
|
433 oldsize=$(find $fs -type f \( \
|
al@865
|
434 -name '*.so*' -o -name '*.a' -o \
|
al@865
|
435 -name '*.pyc' -o -name '*.pyo' -o \
|
al@865
|
436 -name 'perllocal.pod' -o -name '.packlist' \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
437
|
al@865
|
438 find $fs -name '*.so*' -exec $STRIP -s '{}' 2>/dev/null \;
|
al@865
|
439 find $fs -name '*.a' -exec $STRIP --strip-debug '{}' 2>/dev/null \;
|
al@865
|
440 find $fs -type f \( -name '*.pyc' -o -name '*.pyo' \) -delete 2>/dev/null
|
al@865
|
441 find $fs -type f \( -name 'perllocal.pod' -o -name '.packlist' \) -delete 2>/dev/null
|
al@865
|
442
|
al@865
|
443 newsize=$(find $fs -type f \( \
|
al@865
|
444 -name '*.so*' -o -name '*.a' -o \) -exec ls -l '{}' \; | awk '{s+=$5}END{print s}')
|
al@865
|
445
|
al@865
|
446 comp_summary "$time0" "$((size0 + oldsize))" "$((size1 + newsize))"
|
al@865
|
447 }
|
al@865
|
448
|
al@865
|
449
|
al@865
|
450 # Strip unsupported locales (.mo files)
|
al@865
|
451
|
al@865
|
452 strip_mo_i18n() {
|
al@865
|
453 [ "${COOKOPTS/!i18nz/}" != "$COOKOPTS" ] && return
|
al@865
|
454
|
al@865
|
455 [ ! -d "$fs/usr/share/locale" ] && return
|
al@865
|
456 [ -z "$(find $fs/usr/share/locale -type f -name '*.mo')" ] && return
|
al@865
|
457
|
al@865
|
458 action 'Thin out translation files...'
|
al@865
|
459 size0=$(sizes mo2)
|
al@865
|
460 time0=$(date +%s)
|
al@865
|
461
|
al@865
|
462 # The variable $LOCALE is set in cook.conf and may be overridden in the receipt.
|
al@865
|
463 # Default value is "" (empty). That means for us that we'll use the full
|
al@865
|
464 # list of supported locales here.
|
al@865
|
465 [ -z "$LOCALE" ] && LOCALE=$(get_supported_locales)
|
al@865
|
466
|
al@865
|
467 # Existing locales
|
al@865
|
468 elocales=" $(ls -1 "$fs/usr/share/locale" | tr '\n' ' ') "
|
al@865
|
469
|
al@865
|
470 # Thin out the list of existing locales. At the end there will be only locales that need
|
al@865
|
471 # deleting (and the garbage like '_AU', _US', '_BR' leaving from 'en_AU', 'en_US', 'pt_BR'...)
|
al@865
|
472 for keep_locale in $LOCALE; do
|
al@865
|
473 elocales=${elocales//$keep_locale}
|
al@865
|
474 done
|
al@865
|
475
|
al@865
|
476 # Remove the unsupported locales
|
al@865
|
477 for rem_locale in $elocales; do
|
al@865
|
478 [ -d "$fs/usr/share/locale/$rem_locale" ] &&
|
al@865
|
479 rm -r "$fs/usr/share/locale/$rem_locale"
|
al@865
|
480 done
|
al@865
|
481
|
al@865
|
482 comp_summary "$time0" "$size0" "$(sizes mo2)"
|
al@865
|
483 }
|
al@865
|
484
|
al@865
|
485
|
al@865
|
486
|
al@865
|
487
|
al@865
|
488 case $1 in
|
al@865
|
489 install)
|
al@865
|
490 # Compressors working in the $install
|
al@865
|
491 case "$ARCH" in
|
al@865
|
492 arm*) ;;
|
al@865
|
493 *)
|
al@865
|
494 compress_manpages
|
al@865
|
495 compress_png
|
al@865
|
496 compress_svg
|
al@865
|
497 compress_ui
|
al@865
|
498 ;;
|
al@865
|
499 esac
|
al@865
|
500
|
al@865
|
501 fix_desktop_files
|
al@865
|
502 normalize_mo
|
al@865
|
503 strip_locale_def
|
al@865
|
504 ;;
|
al@865
|
505 fs)
|
al@865
|
506 # Compressors working in the $fs
|
al@865
|
507 strip_package
|
al@865
|
508 strip_mo_i18n
|
al@865
|
509 ;;
|
al@865
|
510 esac
|