OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / bin / qmake
1 #!/usr/bin/perl -w
2 #
3 # Quiet make.
4 #
5 # Reduces the amount of output from make.
6 # Recognises commands from glibc and linux kernel builds.
7 #
8 # Copyright 2002 Philip Craig (philipc@snapgear.com)
9 # Based on Rob Landley's blueberry.py
10
11
12 ### Start of configurable options...
13
14 # Print the full file paths instead of the "Entering $dir" messages
15 $fullpath = 1;
16
17 # Print errors highlighted
18 $highlighterror = 1;
19 # Using ^H to make errors bold (less understands this)
20 $errorbold = 0;
21 # Use a color ("1;38" is light grey) (less needs the -R option for this)
22 $errorcolour = "1;38";
23
24 # Display "Installing ... " messages
25 $showinstall = 0;
26 # Display "Archiving to ... " messages
27 $showarchive = 0;
28
29 # Exec make instead of reading stdin
30 $runmake = 0;
31 # Run make based on whether stdin is a tty
32 # This lets you use qmake as a replacement for make if stdin is a tty,
33 # or otherwise pipe the output of make into qmake.
34 $autorunmake = 1;
35
36 ### ...end of options
37
38
39 $nexttarget = '(unknown)';
40 @target = ('(default)');
41 chomp($topdir = `pwd`);
42 @dir = ("$topdir");
43 $firstline = 1;
44 $neednewline = 0;
45
46
47 sub nice_file {
48         my($file) = @_;
49
50         if ($fullpath) {
51                 if ($file !~ /^\//) {
52                         $file = "$dir[$#dir]/$file";
53                 }
54                 if ($file =~ /^\Q$topdir\E\/(.*)$/) {
55                         $file = $1;
56                 }
57         }
58         else {
59                 if ($file =~ /^\Q$topdir\E\/(.*)$/) {
60                         if ($1 =~ /^\Q$dir[$#dir]\E\/(.*)$/) {
61                                 $file = $1;
62                         }
63                 }
64         }
65
66         return $file;
67 }
68
69 {
70         my $splitline;
71         my $fromsplit;
72         my $raw;
73
74         undef($splitline);
75         $fromsplit = 0;
76
77         sub get_line {
78                 my($fh) = @_;
79                 local $_;
80
81                 if (defined($splitline)) {
82                         $_ = $splitline;
83                         undef($splitline);
84                         $fromsplit = 1;
85                 }
86                 else {
87                         $_ = <$fh>;
88                         defined($_) || return $_;
89                         chomp($_);
90
91                         # Join lines at \
92                         while (/\\$/) {
93                                 $nextline = <$fh>;
94                                 defined($nextline) || last;
95                                 chop;
96                                 $_ = join(' ', split(/\s+/, $_.' '.$nextline));
97                         }
98                         $fromsplit = 0;
99                 }
100                 # Split lines at ;
101                 # We're not smart enough to split loop constructs yet though
102                 if (!(/^\s*for\s+/ || /^\s*do\s+/ || /^\s*if\s+/)
103                         && /^([^\[\]\(\)\{\}\`\;]+);\s+(.+)$/) {
104                         $_ = $1;
105                         $splitline = $2;
106                 }
107                 $raw = $_;
108                 return $_;
109         }
110
111         my $lasthidden;
112         undef($lasthidden);
113
114         sub hide_line {
115                 $lasthidden = $raw;
116         }
117
118         sub put_message {
119                 my($message) = @_;
120
121                 if ($neednewline) {
122                         print "\n";
123                         $neednewline = 0;
124                 }
125                 print "$message\n";
126                 $firstline = 0;
127         }
128
129         sub put_line {
130                 my($line) = @_;
131
132                 if (!$fullpath && (!defined($lastdir) || $lastdir ne $dir[$#dir])) {
133                         $lastdir = $dir[$#dir];
134                         if ($target[$#target] !~ /dep/) {
135                                 if (!$firstline) {
136                                         put_message('');
137                                 }
138                                 put_message("Entering $lastdir\n");
139                         }
140                 }
141
142                 if ($neednewline) {
143                         print "\n";
144                 }
145
146                 if (defined($line)) {
147                         print "$line";
148                         $lasthidden = $raw;
149                 }
150                 else {
151                         print "$raw";
152                         #print "Unknown: $raw";
153                         undef($lasthidden);
154                 }
155                 $neednewline = 1;
156                 $firstline = 0;
157         }
158
159         sub put_raw {
160                 my $line;
161
162                 undef($line);
163                 put_line($line);
164         }
165
166         sub put_action_file {
167                 my($action, $file) = @_;
168                 my $line;
169
170                 if (defined($action) && defined($file)) {
171                         $line = "$action " . nice_file($file);
172                 }
173                 put_line($line);
174         }
175
176         sub show_lasthidden {
177                 if (defined($lasthidden)) {
178                         put_message($lasthidden);
179                         undef($lasthidden);
180                 }
181         }
182
183         sub put_error {
184                 my($error1, $error2) = @_;
185                 my $line;
186
187                 show_lasthidden();
188                 if ($highlighterror) {
189                         if ($errorbold) {
190                                 $raw = '';
191                                 foreach $i (split(//, $error1)) {
192                                         $raw .= "$i\b$i";
193                                 }
194                                 $raw .= $error2;
195                         }
196                         else {
197                                 $raw = "\033[" . $errorcolour . "m"
198                                         . $error1 . "\033[0m" . $error2;
199                         }
200                 }
201                 else {
202                         $raw = $error1 . $error2;
203                 }
204                 put_raw();
205         }
206 }
207
208 if ($autorunmake) {
209         if (-t STDIN) {
210                 $runmake = 1;
211         }
212         else {
213                 $runmake = 0;
214         }
215 }
216 if ($runmake) {
217         open(MAKE, '-|', "make " . join(' ', @ARGV) . " 2>&1")
218                 || die 'Could not execute make';
219         $fh = *MAKE;
220 }
221 else {
222         $fh = *STDIN;
223 }
224
225 $genromfs = 0;
226 $ar = 0;
227 $mkcramfs = 0;
228 $makewait = "";
229
230
231 LINE: while (defined($_ = get_line($fh))) {
232         if ($genromfs) {
233                 next LINE if /^\d+\s+/;
234                 $genromfs = 0;
235         }
236         if ($ar) {
237                 next LINE if /^[ar]\s+-\s+/;
238                 $ar = 0;
239         }
240         if ($mkcramfs) {
241                 next LINE if /^  /;
242                 next LINE if /^'/;
243                 next LINE if /^\s*-?\d+\.\d+%/;
244                 next LINE if /^Directory/;
245                 $mkcramfs = 0;
246         }
247         if ($makewait ne "") {
248                 @word = split;
249                 next LINE if ($#word <= 0 || $word[0] ne $makewait);
250                 $makewait = "";
251         }
252
253         # Remove '[ ... ] || ' from start
254         if (/^\[[^\[\]]*\]\s*\|\|\s*(.*)$/) {
255                 $_ = $1;
256                 redo;
257         }
258
259         # Remove ENVVAR="..." from start
260         if (/^\w+=\"[^\"]*\"\s+(.*)$/) {
261                 $_ = $1;
262                 redo;
263         }
264
265         # Remove 'cd dir && " from start
266         if (/^cd\s+\S+\s+\&\&\s+(.*)$/) {
267                 # TODO: should remember dir for displaying filenames
268                 $_ = $1;
269                 redo;
270         }
271
272         # Remove '(echo ...) | ' from start (glibc stuff)
273         if (/^\(echo.*\)\s+\|\s+(gcc.*)$/) {
274                 $_ = $1;
275                 redo;
276         };
277
278         # Remove 'ld-linux.so.2' from start (glibc stuff)
279         if (/^\S*\/ld-linux.so.2\s+(--library-path\s+\S+)?\s+(.*)$/) {
280                 $_ = $2;
281                 redo;
282         }
283
284         # Remove + from the start (from bash set +x)
285         if (/^\+\s+(.*)$/) {
286                 $_ = $1;
287         }
288
289         # Handle 'In file included from xxx.c:dd:' errors
290         if (/^In file included from /) {
291                 show_lasthidden();
292                 put_raw();
293                 next LINE;
294         }
295
296         #libssl noise
297         if (/^[mM]aking all in /
298                         || /^You may get an error following this line./) {
299                 hide_line();
300                 next LINE;
301         }
302
303         #uClinux-dist noise
304         if (/ --> /) {
305                 hide_line();
306                 next LINE;
307         }
308
309         #busybox noise
310         if (/ -> .*busybox/) {
311                 hide_line();
312                 next LINE;
313         }
314
315         #parallel job output during configure check
316         if (/^checking .*\.\.\. (make.*[^.])$/) {
317                 print("Found checking continuation\n");
318                 $_ = $1;
319         }
320
321         $allwords = $_;
322         @word = split;
323         ($#word >= 0) || next LINE;
324
325         for ($word[0]) {
326                 /^(.*[-\/])?ar$/ && do {
327                         if ($#word == 2) {
328                                 if ($showarchive) {
329                                         put_action_file('Creating empty', $word[2]);
330                                         next LINE;
331                                 }
332                         }
333                         elsif ($#word > 2) {
334                                 $ar = 1;
335                                 if ($showarchive) {
336                                         put_action_file('Archiving to', $word[2]);
337                                         next LINE;
338                                 }
339                         }
340                         hide_line();
341                         next LINE;
342                 };
343
344                 (/^(.*[-\/])?as$/ || /^(.*\/)?as86$/) && do {
345                         if ($#word >= 1) {
346                                 put_action_file('Assembling', $word[$#word]);
347                                 next LINE;
348                         }
349                         last;
350                 };
351
352                 (/^(.*[-\/])?(k?g)?cc$/ || /^(.*[-\/])?g\+\+$/) && do {
353                         $action = 'Linking';
354                         undef($file);
355                         for $i (@word[1 .. $#word]) {
356                                 if ($i eq '-E') {
357                                         $action = 'Preprocessing';
358                                 }
359                                 elsif ($i eq '-c' || $i eq '-S') {
360                                         $action = 'Compiling';
361                                 }
362                                 elsif ($i eq '-M') {
363                                         $action = 'Generating dependencies for';
364                                 }
365                         }
366                         if ($action eq 'Linking') {
367                                 for ($i=1; $i<$#word; $i++) {
368                                         if ($word[$i] eq '-o') {
369                                                 $file = $word[$i+1];
370                                                 last;
371                                         }
372                                 }
373                         }
374                         else {
375                                 WORD: for $i (@word[1 .. $#word]) {
376                                         if ($i =~ /\.[sS]$/) {
377                                                 if ($action eq 'Compiling') {
378                                                         $action = 'Assembling';
379                                                 }
380                                                 $file = $i;
381                                                 last WORD;
382                                         }
383                                         elsif ($i =~ /\.c(pp)?$/ || $i =~ /\.ld$/) {
384                                                 $file = $i;
385                                                 last WORD;
386                                         }
387                                         elsif ($i eq '-') {
388                                                 for ($i=1; $i<$#word; $i++) {
389                                                         if ($word[$i] eq '-o') {
390                                                                 $action .= ' from stdin to';
391                                                                 $file = $word[$i+1];
392                                                                 last WORD;
393                                                         }
394                                                 }
395                                         }
396                                 }
397                         }
398                         if (defined($file)) {
399                                 put_action_file($action, $file);
400                                 next LINE;
401                         }
402                         last;
403                 };
404
405                 /^checking$/ && do {
406                         # configure
407                         hide_line();
408                         next LINE;
409                 };
410
411                 /^echo$/ && do {
412                         # glibc stamp files
413                         if ($#word >=3 && $word[$#word-1] eq '>'
414                                         && $word[$#word] =~ /\/stamp\.o[sS]?T$/) {
415                                 hide_line();
416                                 next LINE;
417                         }
418                         # mysql stamp files
419                         if ($#word >=3 && $word[$#word-1] eq '>'
420                                         && $word[$#word] =~ /\.lo$/) {
421                                 hide_line();
422                                 next LINE;
423                         }
424                         last;
425                 };
426
427                 /^genromfs$/ && do {
428                         undef($from);
429                         undef($to);
430                         for ($i=1; $i<$#word; $i++) {
431                                 if ($word[$i] eq '-f') {
432                                         $to = $word[$i+1];
433                                 }
434                                 if ($word[$i] eq '-d') {
435                                         $from = $word[$i+1];
436                                 }
437                         }
438                         if (defined($from) && defined($to)) {
439                                 put_line("Generating romfs $to from $from");
440                         }
441                         else {
442                                 put_raw();
443                         }
444                         $genromfs = 1;
445                         next LINE;
446                 };
447
448                 (/^(.*\/)?install$/ || /^romfs-inst.sh$/) && do {
449                         if (!$showinstall) {
450                                 hide_line();
451                                 next LINE;
452                         }
453                         if ($#word >= 1) {
454                                 if ($word[$#word] =~ /(.*)\.new$/) {
455                                         put_action_file('Installing', $1);
456                                 }
457                                 else {
458                                         put_action_file('Installing', $word[$#word]);
459                                 }
460                                 next LINE;
461                         }
462                         last;
463                 };
464
465                 (/^(.*[-\/])?ld$/ || /^(.*\/)?ld86$/) && do {
466                         for ($i=1; $i<$#word; $i++) {
467                                 if ($word[$i] eq '-o') {
468                                         put_action_file('Linking', $word[$i+1]);
469                                         next LINE;
470                                 }
471                         }
472                         last;
473                 };
474
475                 /^(.*\/)?ln$/ && do {
476                         if ($#word >= 2 && $word[1] =~ /^-.*s/) {
477                                 hide_line();
478                                 next LINE;
479                         }
480                         last;
481                 };
482
483                 /^(.*\/)m4$/ && do {
484                         if ($#word >= 1) {
485                                 put_action_file('Preprocessing', $word[$#word]);
486                                 next LINE;
487                         }
488                         last;
489                 };
490
491                 /^make$/ && do {
492                         if ($#word >= 3 && $word[1] eq '-C') {
493                                 $nexttarget = join(' ', @word[3 .. $#word]);
494                         }
495                         elsif ($#word >= 1) {
496                                 $nexttarget = join(' ', @word[1 .. $#word]);
497                         }
498                         else {
499                                 $nexttarget = '(default)';
500                         }
501                         # TODO: nexttarget needs more cleaning to be printable,
502                         # but it's good enough to determine 'make dep' targets...
503                         hide_line();
504                         next LINE;
505                 };
506
507                 /^make(\[[0-9]+\])?:$/ && do {
508                         if ($#word >= 3) {
509                                 if ($word[2] eq 'directory') {
510                                         if ($word[1] eq 'Entering') {
511                                                 $dir = $word[3];
512                                                 if ($dir =~ /^\`(.*)\'$/) {
513                                                         $dir = $1;
514                                                 }
515                                                 if ($dir =~ /^\Q$topdir\E\/(.*)$/) {
516                                                         $dir = $1;
517                                                 }
518                                                 push @dir, $dir;
519                                                 push @target, $nexttarget;
520                                                 $nexttarget = '(unknown)';
521                                         }
522                                         elsif ($word[1] eq 'Leaving') {
523                                                 pop @dir;
524                                                 pop @target;
525                                         }
526                                         hide_line();
527                                         next LINE;
528                                 }
529                                 elsif ($word[1] eq 'Nothing') {
530                                         hide_line();
531                                         next LINE;
532                                 }
533                                 elsif ($word[$#word] eq 'date.') {
534                                         hide_line();
535                                         next LINE;
536                                 }
537                                 elsif ($word[2] eq 'jobserver'|| $word[$#word-1] eq 'jobserver') {
538                                         hide_line();
539                                         next LINE;
540                                 }
541                                 elsif ($word[2] eq 'Waiting') {
542                                         $makewait = $word[0];
543                                         hide_line();
544                                         next LINE;
545                                 }
546                         }
547                         put_error($word[0], substr($allwords, length($word[0])));
548                         next LINE;
549                 };
550
551                 /^\.\/mkbuiltins$/ && do {
552                         # bash
553                         hide_line();
554                         next LINE;
555                 };
556
557                 /^(.*\/)?mkcramfs$/ && do {
558                         $mkcramfs = 1;
559                         last;
560                 };
561
562                 /mkdep$/ && do {
563                         put_line("Finding dependencies in $dir[$#dir]");
564                         next LINE;
565                 };
566
567                 (/\/mkinstalldirs$/ || /^mkdir$/) && do {
568                         hide_line();
569                         next LINE;
570                 };
571
572                 /^mv$/ && do {
573                         if ($#word >= 2) {
574                                 # glibc stamp files
575                                 if ($word[$#word-1] eq $word[$#word].'T') {
576                                         hide_line();
577                                         next LINE;
578                                 }
579                                 # glibc installs
580                                 if ($word[$#word-1] eq $word[$#word].'.new') {
581                                         hide_line();
582                                         next LINE;
583                                 }
584                         }
585                         last;
586                 };
587
588                 /^(.*[-\/])?nm$/ && do {
589                         if ($#word >= 1) {
590                                 put_action_file('Extracting symbols to', $word[$#word]);
591                                 next LINE;
592                         }
593                         last;
594                 };
595
596                 /^(.*[-\/])?objcopy$/ && do {
597                         if ($#word >= 1) {
598                                 put_action_file('Objcopy to', $word[$#word]);
599                                 next LINE;
600                         }
601                         last;
602                 };
603
604                 /^(.*[-\/])?ranlib$/ && do {
605                         hide_line();
606                         next LINE;
607                 };
608
609                 /^(.*\/)?rm$/ && do {
610                         hide_line();
611                         next LINE;
612                 };
613
614                 /^source=/ && do {
615                         # mysql dependency checking
616                         hide_line();
617                         next LINE;
618                 };
619
620                 /^(.*[-\/])?strip$/ && do {
621                         hide_line();
622                         next LINE;
623                 };
624
625                 /^touch$/ && do {
626                         #glibc stamp files
627                         if ($#word >=1 && $word[$#word] =~ /\/stamp.o[sS]?$/) {
628                                 hide_line();
629                                 next LINE;
630                         }
631                         last;
632                 };
633
634                 /^unset$/ && do {
635                         if ($#word == 1) {
636                                 if ($word[1] eq 'GCC_EXEC_PREFIX') {
637                                         hide_line();
638                                         next LINE;
639                                 }
640                         }
641                 };
642
643                 /\/zic$/ && do {
644                         if ($#word >= 1) {
645                                 put_action_file('Compiling timezone', $word[$#word]);
646                                 next LINE;
647                         }
648                         last;
649                 };
650
651                 /^\:$/ && do {
652                         hide_line();
653                         next LINE;
654                 };
655
656                 /^\#/ && do {
657                         hide_line();
658                         next LINE;
659                 };
660
661                 /^\**$/ && do {
662                         put_error($allwords, '');
663                         next LINE;
664                 };
665
666                 /.+:$/ && do {
667                         put_error($word[0], substr($allwords, length($word[0])));
668                         next LINE;
669                 };
670         }
671
672         put_raw();
673 }
674
675 if ($neednewline) {
676         print "\n";
677 }