/[pkg-kde]/scripts/autofixtll
ViewVC logotype

Diff of /scripts/autofixtll

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10310 by modax-guest, Sat Apr 26 22:44:41 2008 UTC revision 10311 by modax-guest, Mon Apr 28 01:00:13 2008 UTC
# Line 105  use IPC::Open2; Line 105  use IPC::Open2;
105    
106  #### Please add predefined libraries to load dynamic symbol from here.  #### Please add predefined libraries to load dynamic symbol from here.
107  # new Library(name, cmake_target, [path]). If path is not specified,  # new Library(name, cmake_target, [path]). If path is not specified,
108  # it's path=/usr/lib/$name.so. Use '' quotes.  # it's /usr/lib/$name.so. Use '' quotes to avoid escaping $.
109  my @LIBS = (  my @LIBS = (
110      new Library('QtDBus', '${QT_QTDBUS_LIBRARY}'),      new Library('QtDBus', '${QT_QTDBUS_LIBRARY}'),
111      new Library('QtNetwork', '${QT_QTNETWORK_LIBRARY}'),      new Library('QtNetwork', '${QT_QTNETWORK_LIBRARY}'),
# Line 195  sub Library::to_string() { Line 195  sub Library::to_string() {
195      return $self->{name} . " ( " . $self->{path} . " )";      return $self->{name} . " ( " . $self->{path} . " )";
196  }  }
197    
198    sub IgnoreStack::new {
199        return bless( { stack => [] }, shift() );
200    }
201    
202    sub IgnoreStack::process_line {
203        my ($self, $line) = @_;
204        my $stack = $self->{stack};
205    
206        if ($line =~ m/^\s*((end)?(foreach|function|if|macro|while))\s*[(]/i) {
207            my $isend = defined $2;
208            my $cmd = uc($3);
209    
210            if ($isend) {
211                if (@$stack) {
212                    my $s = pop @$stack;
213                    print STDERR "$MSG_PREFIX There is something wrong with IgnoreStack:\n",
214                                 "$MSG_PREFIX   stack top ($s) does not match end command ($cmd)\n" if $s ne $cmd;
215                } else {
216                    print STDERR "$MSG_PREFIX IgnoreStack is empty but got 'end$cmd'. A bug probably.\n";
217                }
218            } else {
219                push @$stack, $cmd;
220            }
221            return 1; # Processed
222        } else {
223            return 0;
224        }
225    }
226    
227    sub IgnoreStack::is_empty {
228        return scalar(@{shift()->{stack}}) == 0;
229    }
230    
231    sub IgnoreStack::dump_stack {
232        my $self = shift;
233        print "Ignore stack dump:\n";
234        for my $e (@{$self->{stack}}) {
235            print "  $e\n";
236        }
237    }
238    
239  sub determine_needed_libs {  sub determine_needed_libs {
240      my ($alllibs, $undefrefs) = @_;      my ($alllibs, $undefrefs) = @_;
# Line 230  sub write_target_link_libs { Line 270  sub write_target_link_libs {
270    
271      if (-r $cmakelists) {      if (-r $cmakelists) {
272          my @contents;          my @contents;
273            my @ignored;
274          my $found = 0;          my $found = 0;
275            # Ignore directive inside if/endif, while/endwhile etc. blocks
276            my $ignstack = new IgnoreStack;
277    
278          # Read and change          # Read and change
279          open(CMAKELISTS, "<$cmakelists");          open(CMAKELISTS, "<$cmakelists");
280          while (<CMAKELISTS>) {          while (<CMAKELISTS>) {
281              if (!$found && m/(target_link_libraries\s*\(\s*$target\s+)(.*?)(\s*\).*)?$/i) {              if (!$found && !$ignstack->process_line($_) &&
282                    m/^\s*(target_link_libraries\s*\(\s*$target\s+)(.*?)(\s*\).*)?$/i) {
283    
284                  # Fix it                  # Fix it
285                  my $newline = $1;                  my $newline = $1;
286                  my $end = $3;                  my $end = $3;
# Line 244  sub write_target_link_libs { Line 289  sub write_target_link_libs {
289                  $newline .= $strlibs;                  $newline .= $strlibs;
290                  $newline .= $end if ($end);                  $newline .= $end if ($end);
291                  $newline .= "\n";                  $newline .= "\n";
292                  push @contents, $newline;  
293                  $found = $.;                  if ($ignstack->is_empty()) {
294                        push @contents, $newline;
295                        $found = $.;
296                    } else {
297                        # Save for later use
298                        push @ignored, { found => $., newline => $newline };
299                        push @contents, $_;
300                    }
301              } else {              } else {
302                  push @contents, $_;                  push @contents, $_;
303              }              }
304          }          }
305          close(CMAKELISTS);          close(CMAKELISTS);
306    
307            if (!$ignstack->is_empty()) {
308                $ignstack->dump_stack();
309                print STDERR "$cmakelists has been processed but ignore stack is not empty. Probably a bug!\n";
310            }
311    
312            if (!$found && @ignored == 1) {
313                # That's probably it as there were no other candidates. Replace
314                $found = ${ignored[0]}->{found};
315                my $newline = ${ignored[0]}->{newline};
316                $contents[$found-1] = $newline;
317            } else {
318                print "$MSG_PREFIX More (", scalar(@ignored), ") than 1 target_link_libraries() found in the IF/WHILE etc. blocks\n";
319            }
320    
321          if (!$found) {          if (!$found) {
322              die "$MSG_PREFIX $cmakelists could not be corrected (needed '$strlibs' for target '$target'). Respective target_link_libraries() was not found $MSG_PREFIX";              die "$MSG_PREFIX $cmakelists could not be corrected (needed '$strlibs' for target '$target'). Respective target_link_libraries() was not found $MSG_PREFIX";
323          } else {          } else {
# Line 313  sub build_and_fix { Line 379  sub build_and_fix {
379                  die "Could not extract target from $bdir";                  die "Could not extract target from $bdir";
380              }              }
381              $bdir =~ s#/CMakeFiles/.*##;              $bdir =~ s#/CMakeFiles/.*##;
382          } elsif (m/^Linking (.*) (shared module|executable) /) {          } elsif (m/^Linking (.*) (shared (module|library)|executable) /) {
383              $link_cmd = 1;              $link_cmd = 1;
384          } elsif (m/undefined reference to `(.*)'$/) {          } elsif (m/undefined reference to `(.*)'$/) {
385              # undefined reference to `QDBusMessage::createSignal(QString const&, QString const&, QString const&)'              # undefined reference to `QDBusMessage::createSignal(QString const&, QString const&, QString const&)'
# Line 328  sub build_and_fix { Line 394  sub build_and_fix {
394      chdir $sourcedir;      chdir $sourcedir;
395    
396      # Try to correct the error      # Try to correct the error
397    #    print $MSG_PREFIX, $islderror, $bdir, $btarget, @undefrefs;
398      if ($islderror && $bdir && $btarget && @undefrefs) {      if ($islderror && $bdir && $btarget && @undefrefs) {
399          my $libs = determine_needed_libs(\@LIBS, \@undefrefs);          my $libs = determine_needed_libs(\@LIBS, \@undefrefs);
400          if (@$libs) {          if (@$libs) {
# Line 386  sub check_environment { Line 453  sub check_environment {
453            "$MSG_PREFIX    \$ $QUILT push $patchname\n" .            "$MSG_PREFIX    \$ $QUILT push $patchname\n" .
454            "$MSG_PREFIX    \$ $QUILT new $patchname\n";            "$MSG_PREFIX    \$ $QUILT new $patchname\n";
455      }      }
   
     if (! -d $builddir) {  
         die "Build directory '$builddir' does not exist";  
     }  
456  }  }
457    
458  sub get_gnu_build_type {  sub get_gnu_build_type {
# Line 400  sub get_gnu_build_type { Line 463  sub get_gnu_build_type {
463    
464  ############## Main loop ##############################  ############## Main loop ##############################
465    
466  $main::VERSION = "0.2";  $main::VERSION = "0.3";
467    
468  my $sourcedir = Cwd::getcwd();  my $sourcedir = Cwd::getcwd();
469  my $builddir = "obj-" . get_gnu_build_type();  my $builddir = "obj-" . get_gnu_build_type();

Legend:
Removed from v.10310  
changed lines
  Added in v.10311

  ViewVC Help
Powered by ViewVC 1.1.5