Upstream tarball 20080304
[amule.git] / src / utils / scripts / denoiser.rules
blob052f59125160d7612f2bef942ac6046048e5406e
1 # This file is part of the aMule project.
3 # Copyright (c) 2003-2008 aMule Project ( admin@amule.org / http://www.amule.org )
4 # Copyright (c) 2006-2008 Dévai Tamás aka GonoszTopi
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either
9 # version 2 of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
21 # The sed script is tested with GNU sed versions 3.02, 4.1.2
22 # The generated Makefiles are tested with GNU make versions 3.79.1, 3.80
25 # Denoising levels:
27 #       0 - do nothing, handled outside the scope of this script.
29 #       1 - only strip Makefiles from comments and empty lines, this should
30 #       theoretically speed up 'make', although not as much that you could
31 #       notice it.
33 #       2 - leave directory change messages from make, but silence normal
34 #       command printing. No echo denoising at this level.
36 #       3 - silence all messages from make, and partial echo denoising.
38 #       4 - full denoising:
39 #               * silence all messages from make
40 #               * full echo denoising
41 #               * compiler warning suppression
44 # Syntax of this file:
46 #       This file gets preprocessed, all comments and empty lines removed. The
47 #       preprocessor understands '#if ', '#else' and '#endif' commands, as long
48 #       as they start on the first character on the line. No whitespace is
49 #       allowed before the commands. Note that the space character after #if is
50 #       part of the command, if it is replaced by a tab then it won't make a
51 #       command anymore!
53 # #if truth testing:
55 #       #if currently understands only one keyword: 'level', followed by a number
56 #       - the current denoising level. There may be any arbitrary characters
57 #       between the keyword and the value - i.e. 'levels 2,3' will also match
58 #       when 'level 3' matches.
60 # #if preprocessor commands may be nested for at least 4000 levels deep :-)
62 # The preprocessor script can be found at the end of this file.
65 # ----- now the code -----
67 # suppress messages from make
69 #if levels 3,4
70 1 i\
71 MAKEFLAGS=-s --no-print-directory
72 #endif
74 #if level 2
75 1 i\
76 MAKEFLAGS=-w -s
77 #endif
80 #if levels 2,3,4
82 #endif
85 # delete comments
86 /^#/ {
87         d
90 # delete empty lines
91 /^[     ]*$/ {
92         d
96 # rewrite compiler flags
97 #if level 4
98 /=/ {
99         /^[^=]*CFLAGS/ b 8
100         /^[^=]*CPPFLAGS/ b 8
101         /^[^=]*CXXFLAGS/ b 8
102         b 9
103         :8
104         # save -Wl, -Wa, and -Wp, flags, they're for linker, assember and preprocessor respectively
105         s/ -Wl,/ -%l,/g
106         s/ -Wa,/ -%a,/g
107         s/ -Wp,/ -%p,/g
109         # delete all -W flags
110         / -W/ s/ -W[^ ]*//g
112         # insert -w flag, if it isn't already in the flags
113         / -w/! s/=/= -w/
115         # restore -Wl, -Wa, and -Wp, flags
116         s/ -%l,/ -Wl,/g
117         s/ -%a,/ -Wa,/g
118         s/ -%p,/ -Wp,/g
119         :9
121 #endif
124 # rewrite rules
125 #if levels 2,3,4
126 # all rules contain ':' and start at the very beginning of the line
127 /^[^    ].*:/ {
128         # no rules contain '=', so just skip these lines
129         /=/ b
131         # save rule target in secondary buffer
132         h
133         s/\([^:][^:]*\):.*/\1/
134         x
136         # skip continuation lines
137         :1
138         /\\$/ {
139                 n
140                 b 1
141         }
143         # process rule commands
144         :2
145         n
146         :3
148         # delete comments inside rules
149         /^#/ {
150                 s/.*//
151                 N
152                 s/\n//g
153                 b 3
154         }
156         # if the current line is empty or not anymore a command, parse as usual
157         /^$/ b 0
158         /^[^    ]/ b 0
160         x
161         /^\n/ b 5
163         # skipping install-strip target, since it will trigger the echo-denoiser,
164         # and would silence the whole installation, which is abolutely not wanted
165         /^install-strip$/ {
166                 s/.*//
167                 x
168                 b 0
169         }
171         # do some output based on rule target
172         /\.o$/ {
173                 i\
174         echo "Compiling $(<F)"
175                 b 4
176         }
177         /\.obj$/ {
178                 i\
179         echo "Compiling $(<F)"
180                 b 4
181         }
182         /\.a$/ {
183                 i\
184         echo "Building $(@F)"
185                 b 4
186         }
187         /$(EXEEXT)$/ {
188                 i\
189         echo "Linking $(@F)"
190                 b 4
191         }
192         /^\.po\.g\?mo$/ {
193                 i\
194         echo "Generating translations for $(<F:.po=)"
195                 b 4
196         }
197         /\.cpp$/ {
198                 i\
199         echo "Generating $(@F)"
200                 b 4
201         }
202         /\.$(OBJEXT)$/ {
203                 i\
204         echo "Compiling $(<F)"
205                 b 4
206         }
207         /^$(DOMAIN)\.pot-update$/ {
208                 i\
209         echo "Updating translation catalog template"
210                 b 4
211         }
212         /^$(POFILES)$/ {
213                 i\
214         echo "Updating translation catalog for $(@F:.po=)"
215                 b 4
216         }
217         /^\.nop\.po-update$/ {
218                 i\
219         echo "Updating translation catalog for $(<F:.nop=)"
220                 b 4
221         }
222         :4
223         # indicate that we already did the echo thingie
224         #
225         # s/^/\n/ works with newer sed versions like 4.1.2,
226         # but unfortunately msys uses sed 3.02, which does not
227         # translate \n to a newline in the replacement string.
228         #s/^/\n/
229         #
230         # Compatible method: include a newline literally
231         s/^/\
233         :5
235         # If --enable-maintainer-mode, Makefiles may be automatically regenerated.
236         # Denoise new Makefile aswell.
237         /Makefile$/ {
238                 x
239                 /echo/! {
240                         /config\.status[         ][     ]*[^    ][^     ]*/ s/\(config\.status[          ][     ]*[^    ][^     ]*[^;\&\|]*\)\(.*\)/\1 denoiser\2/
241                 }
242                 x
243         }
245         x
247 #if levels 3,4
248         # Denoise echo commands (assuming that no echo command contains the ';' character)
249         #
250         # Denoising works by redirecting output to /dev/null, which is slower, though safer
251         # than removing the command.
252         /^[     ]*@*echo/ {
253                 x
254                 /maintainer-clean-generic/ b 6a
255 #if level 3
256                 /maintainer/ b 6a
257                 /$(RECURSIVE_TARGETS)/ b 6a
258                 /recursive/ b 6a
259 #endif
260                 b 6b
261                 :6a
262                 x
263                 b 6
264                 :6b
265                 x
266                 G
267                 h
268                 s/\(echo[^;][^;]*\).*/\1/
269                 # do not redirect if it's already redirected
270                 />/ {
271                         g
272                         s/[^\n]*//
273                         x
274                         s/\n.*//
275                         b 6
276                 }
277                 g
278                 s/[^\n]*//
279                 x
280                 s/\n.*//
281                 s/\(.*echo[^;][^;]*\)\(.*\)/\1>\/dev\/null\2/
282                 :6
283         }
284 #endif (levels 3,4)
285         
286         # mkinstalldirs will also echo its job, sink its output too
287         /$(mkinstalldirs)/ {
288                 G
289                 h
290                 s/\($(mkinstalldirs)[^;][^;]*\).*/\1/
291                 # do not redirect if it's already redirected
292                 />/ {
293                         g
294                         s/[^\n]*//
295                         x
296                         s/\n.*//
297                         b 7
298                 }
299                 g
300                 s/[^\n]*//
301                 x
302                 s/\n.*//
303                 s/\(.*$(mkinstalldirs)[^;][^;]*\)\(.*\)/\1>\/dev\/null\2/
304                 :7
305         }
307 #if level 4
308         # the above applies to msgfmt, but here it's enough to remove the '--statistics' flag
309         /$(GMSGFMT)/ s/--statistics//
311         # msgmerge needs a --silent flag
312         s/$(MSGMERGE)/\0 --silent/
313         s/$(MSGMERGE_UPDATE)/\0 --silent/
314 #endif
316         # the following two ruleset must be the last two in this block and in this order!
318 #if levels 3,4
319         # uninstallation
320         /^[     ]*rm -f[^;]*$(DESTDIR)/ {
321                 x
322                 /uninstall/ {
323                         H
324                         g
325                         s/.*rm -f[^;]*$(DESTDIR)\([^;" ][^;" ]*\).*/    echo "Uninstalling \1"; \\/
326                         P
327                         g
328                         s/[^\n]*//
329                         x
330                         s/\n.*//
331                         # skip checking for install: 1) trivially false 2) uninstall would match /install/
332                         b 2
333                 }
334                 x
335         }
337         # installation
338         /^[     ]*$([^)]*INSTALL/ {
339                 x
340                 /install/ {
341                         H
342                         g
343                         s/.*$(DESTDIR)\([^;" ][^;" ]*\).*/      echo "Installing \1"; \\/
344                         P
345                         g
346                         s/[^\n]*//
347                         x
348                         s/\n.*//
349                         b 2
350                 }
351                 x
352         }
353 #endif (levels 3,4)
355         b 2
357 #endif (levels 2,3,4)
360 # ---- the preprocessor ----
362 ## default processing mode is 'true'
363 #1 {
364 #       x
365 #       s/.*/1/
366 #       x
369 ## delete empty lines
370 #/^[    ]*$/ d;
372 ## look for "#if "
373 #/^#if / {
374 #       /level.*$level/ {
375 #               x
376 #               s/^/1/
377 #               x
378 #               b0
379 #       }
380 #       x
381 #       s/^/0/
382 #       x
383 #       :0
384 #       d
387 ## process "#else"
388 #/^#else/ {
389 #       x
390 #       /^1/ {
391 #               s/1/0/
392 #               b1
393 #       }
394 #       s/0/1/
395 #       :1
396 #       x
397 #       d
400 ## check for "#endif"
401 #/^#endif/ {
402 #       x
403 #       s/.//
404 #       x
405 #       d
408 ## delete comments
409 #/^[    ]*#/ d
411 ## process code lines according to #if/#else/#endif
413 #/^1/ {
414 #       x
415 #       b