1*946379e7Schristos#!/usr/bin/perl -w 2*946379e7Schristos 3*946379e7Schristos# Expands the specialised KDE tags in Makefile.in to (hopefully) valid 4*946379e7Schristos# make syntax. 5*946379e7Schristos# When called without file parameters, we work recursively on all Makefile.in 6*946379e7Schristos# in and below the current subdirectory. When called with file parameters, 7*946379e7Schristos# only those Makefile.in are changed. 8*946379e7Schristos# The currently supported tags are 9*946379e7Schristos# 10*946379e7Schristos# {program}_METASOURCES 11*946379e7Schristos# where you have a choice of two styles 12*946379e7Schristos# {program}_METASOURCES = name1.moc name2.moc ... [\] 13*946379e7Schristos# {program}_METASOURCES = AUTO 14*946379e7Schristos# The second style requires other tags as well. 15*946379e7Schristos# 16*946379e7Schristos# To install icons : 17*946379e7Schristos# KDE_ICON = iconname iconname2 ... 18*946379e7Schristos# KDE_ICON = AUTO 19*946379e7Schristos# 20*946379e7Schristos# For documentation : 21*946379e7Schristos# http://developer.kde.org/documentation/other/developer-faq.html 22*946379e7Schristos# 23*946379e7Schristos# and more new tags TBD! 24*946379e7Schristos# 25*946379e7Schristos# The concept (and base code) for this program came from automoc, 26*946379e7Schristos# supplied by the following 27*946379e7Schristos# 28*946379e7Schristos# Matthias Ettrich <ettrich@kde.org> (The originator) 29*946379e7Schristos# Kalle Dalheimer <kalle@kde.org> (The original implementator) 30*946379e7Schristos# Harri Porten <porten@tu-harburg.de> 31*946379e7Schristos# Alex Zepeda <jazepeda@pacbell.net> 32*946379e7Schristos# David Faure <faure@kde.org> 33*946379e7Schristos# Stephan Kulow <coolo@kde.org> 34*946379e7Schristos 35*946379e7Schristosuse Cwd; 36*946379e7Schristosuse File::Find; 37*946379e7Schristosuse File::Basename; 38*946379e7Schristos 39*946379e7Schristos# Prototype the functions 40*946379e7Schristossub initialise (); 41*946379e7Schristossub processMakefile ($); 42*946379e7Schristossub updateMakefile (); 43*946379e7Schristossub restoreMakefile (); 44*946379e7Schristos 45*946379e7Schristossub removeLine ($$); 46*946379e7Schristossub appendLines ($); 47*946379e7Schristossub substituteLine ($$); 48*946379e7Schristos 49*946379e7Schristossub findMocCandidates (); 50*946379e7Schristossub pruneMocCandidates ($); 51*946379e7Schristossub checkMocCandidates (); 52*946379e7Schristossub addMocRules (); 53*946379e7Schristos 54*946379e7Schristossub tag_AUTOMAKE (); 55*946379e7Schristossub tag_META_INCLUDES (); 56*946379e7Schristossub tag_METASOURCES (); 57*946379e7Schristossub tag_POFILES (); 58*946379e7Schristossub tag_DOCFILES (); 59*946379e7Schristossub tag_LOCALINSTALL(); 60*946379e7Schristossub tag_IDLFILES(); 61*946379e7Schristossub tag_UIFILES(); 62*946379e7Schristossub tag_SUBDIRS(); 63*946379e7Schristossub tag_ICON(); 64*946379e7Schristossub tag_CLOSURE(); 65*946379e7Schristossub tag_DIST(); 66*946379e7Schristos 67*946379e7Schristos# Some global globals... 68*946379e7Schristos$verbose = 0; # a debug flag 69*946379e7Schristos$thisProg = "$0"; # This programs name 70*946379e7Schristos$topdir = cwd(); # The current directory 71*946379e7Schristos@makefiles = (); # Contains all the files we'll process 72*946379e7Schristos@foreignfiles = (); 73*946379e7Schristos$start = (times)[0]; # some stats for testing - comment out for release 74*946379e7Schristos$version = "v0.2"; 75*946379e7Schristos$errorflag = 0; 76*946379e7Schristos$cppExt = "(cpp|cc|cxx|C|c\\+\\+)"; 77*946379e7Schristos$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)"; 78*946379e7Schristos$progId = "KDE tags expanded automatically by " . basename($thisProg); 79*946379e7Schristos$automkCall = "\n"; 80*946379e7Schristos$printname = ""; # used to display the directory the Makefile is in 81*946379e7Schristos$use_final = 1; # create code for --enable-final 82*946379e7Schristos$cleantarget = "clean"; 83*946379e7Schristos$dryrun = 0; 84*946379e7Schristos$pathoption = 0; 85*946379e7Schristos$foreign_libtool = 0; 86*946379e7Schristos 87*946379e7Schristoswhile (defined ($ARGV[0])) 88*946379e7Schristos{ 89*946379e7Schristos $_ = shift; 90*946379e7Schristos if (/^--version$/) 91*946379e7Schristos { 92*946379e7Schristos print STDOUT "\n"; 93*946379e7Schristos print STDOUT basename($thisProg), " $version\n", 94*946379e7Schristos "This is really free software, unencumbered by the GPL.\n", 95*946379e7Schristos "You can do anything you like with it except sueing me.\n", 96*946379e7Schristos "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n", 97*946379e7Schristos "Concept, design and unnecessary questions about perl\n", 98*946379e7Schristos " by Matthias Ettrich <ettrich\@kde.org>\n\n", 99*946379e7Schristos "Making it useful by Stephan Kulow <coolo\@kde.org> and\n", 100*946379e7Schristos "Harri Porten <porten\@kde.org>\n", 101*946379e7Schristos "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n", 102*946379e7Schristos "Current Maintainer Stephan Kulow\n\n"; 103*946379e7Schristos exit 0; 104*946379e7Schristos } 105*946379e7Schristos elsif (/^--verbose$|^-v$/) 106*946379e7Schristos { 107*946379e7Schristos $verbose = 1; # Oh is there a problem...? 108*946379e7Schristos } 109*946379e7Schristos elsif (/^-p(.+)$|^--path=(.+)$/) 110*946379e7Schristos { 111*946379e7Schristos $thisProg = "$1/".basename($thisProg) if($1); 112*946379e7Schristos $thisProg = "$2/".basename($thisProg) if($2); 113*946379e7Schristos warn ("$thisProg doesn't exist\n") if (!(-f $thisProg)); 114*946379e7Schristos $pathoption=1; 115*946379e7Schristos } 116*946379e7Schristos elsif (/^--help$|^-h$/) 117*946379e7Schristos { 118*946379e7Schristos print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n", 119*946379e7Schristos "\n", 120*946379e7Schristos "Patches dir/Makefile.in generated by automake\n", 121*946379e7Schristos "(where dir can be an absolute or relative directory name)\n", 122*946379e7Schristos "\n", 123*946379e7Schristos " -v, --verbose verbosely list files processed\n", 124*946379e7Schristos " -h, --help print this help, then exit\n", 125*946379e7Schristos " --version print version number, then exit\n", 126*946379e7Schristos " -p, --path= use the path to am_edit if the path\n", 127*946379e7Schristos " called from is not the one to be used\n", 128*946379e7Schristos " --no-final don't patch for --enable-final\n"; 129*946379e7Schristos 130*946379e7Schristos exit 0; 131*946379e7Schristos } 132*946379e7Schristos elsif (/^--no-final$/) 133*946379e7Schristos { 134*946379e7Schristos $use_final = 0; 135*946379e7Schristos $thisProg .= " --no-final"; 136*946379e7Schristos } 137*946379e7Schristos elsif (/^--foreign-libtool$/) 138*946379e7Schristos { 139*946379e7Schristos $foreign_libtool = 1; 140*946379e7Schristos $thisProg .= " --foreign-libtool"; 141*946379e7Schristos } 142*946379e7Schristos elsif (/^-n$/) 143*946379e7Schristos { 144*946379e7Schristos $dryrun = 1; 145*946379e7Schristos } 146*946379e7Schristos else 147*946379e7Schristos { 148*946379e7Schristos # user selects what input files to check 149*946379e7Schristos # add full path if relative path is given 150*946379e7Schristos $_ = cwd()."/".$_ if (! /^\//); 151*946379e7Schristos print "User wants $_\n" if ($verbose); 152*946379e7Schristos push (@makefiles, $_); 153*946379e7Schristos } 154*946379e7Schristos} 155*946379e7Schristos 156*946379e7Schristosif ($thisProg =~ /^\// && !$pathoption ) 157*946379e7Schristos{ 158*946379e7Schristos print STDERR "Illegal full pathname call performed...\n", 159*946379e7Schristos "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n", 160*946379e7Schristos "Please use option --path.\n"; 161*946379e7Schristos exit 1; 162*946379e7Schristos} 163*946379e7Schristos 164*946379e7Schristos# Only scan for files when the user hasn't entered data 165*946379e7Schristosif (!@makefiles) 166*946379e7Schristos{ 167*946379e7Schristos print STDOUT "Scanning for Makefile.in\n" if ($verbose); 168*946379e7Schristos find (\&add_makefile, cwd()); 169*946379e7Schristos #chdir('$topdir'); 170*946379e7Schristos} else { 171*946379e7Schristos print STDOUT "Using input files specified by user\n" if ($verbose); 172*946379e7Schristos} 173*946379e7Schristos 174*946379e7Schristosforeach $makefile (sort(@makefiles)) 175*946379e7Schristos{ 176*946379e7Schristos processMakefile ($makefile); 177*946379e7Schristos last if ($errorflag); 178*946379e7Schristos} 179*946379e7Schristos 180*946379e7Schristos# Just some debug statistics - comment out for release as it uses printf. 181*946379e7Schristosprintf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose); 182*946379e7Schristos 183*946379e7Schristosexit $errorflag; # causes make to fail if erroflag is set 184*946379e7Schristos 185*946379e7Schristos#----------------------------------------------------------------------------- 186*946379e7Schristos 187*946379e7Schristos# In conjunction with the "find" call, this builds the list of input files 188*946379e7Schristossub add_makefile () 189*946379e7Schristos{ 190*946379e7Schristos push (@makefiles, $File::Find::name) if (/Makefile.in$/); 191*946379e7Schristos} 192*946379e7Schristos 193*946379e7Schristos#----------------------------------------------------------------------------- 194*946379e7Schristos 195*946379e7Schristos# Processes a single make file 196*946379e7Schristos# The parameter contains the full path name of the Makefile.in to use 197*946379e7Schristossub processMakefile ($) 198*946379e7Schristos{ 199*946379e7Schristos # some useful globals for the subroutines called here 200*946379e7Schristos local ($makefile) = @_; 201*946379e7Schristos local @headerdirs = ('.'); 202*946379e7Schristos local $haveAutomocTag = 0; 203*946379e7Schristos local $MakefileData = ""; 204*946379e7Schristos 205*946379e7Schristos local $cxxsuffix = "KKK"; 206*946379e7Schristos 207*946379e7Schristos local @programs = (); # lists the names of programs and libraries 208*946379e7Schristos local $program = ""; 209*946379e7Schristos 210*946379e7Schristos local %realObjs = (); # lists the objects compiled into $program 211*946379e7Schristos local %sources = (); # lists the sources used for $program 212*946379e7Schristos local %finalObjs = (); # lists the objects compiled when final 213*946379e7Schristos local %realname = (); # the binary name of program variable 214*946379e7Schristos local %idlfiles = (); # lists the idl files used for $program 215*946379e7Schristos local %globalmocs = ();# list of all mocfiles (in %mocFiles format) 216*946379e7Schristos local %important = (); # list of files to be generated asap 217*946379e7Schristos local %uiFiles = (); 218*946379e7Schristos 219*946379e7Schristos local $allidls = ""; 220*946379e7Schristos local $idl_output = "";# lists all idl generated files for cleantarget 221*946379e7Schristos local $ui_output = "";# lists all uic generated files for cleantarget 222*946379e7Schristos 223*946379e7Schristos local %depedmocs = (); 224*946379e7Schristos 225*946379e7Schristos local $metasourceTags = 0; 226*946379e7Schristos local $dep_files = ""; 227*946379e7Schristos local $dep_finals = ""; 228*946379e7Schristos local %target_adds = (); # the targets to add 229*946379e7Schristos local $kdelang = ""; 230*946379e7Schristos local @cleanfiles = (); 231*946379e7Schristos local $cleanMoc = ""; 232*946379e7Schristos local $closure_output = ""; 233*946379e7Schristos 234*946379e7Schristos local %varcontent = (); 235*946379e7Schristos 236*946379e7Schristos $makefileDir = dirname($makefile); 237*946379e7Schristos chdir ($makefileDir); 238*946379e7Schristos $printname = $makefile; 239*946379e7Schristos $printname =~ s/^\Q$topdir\E\///; 240*946379e7Schristos $makefile = basename($makefile); 241*946379e7Schristos 242*946379e7Schristos print STDOUT "Processing makefile $printname\n" if ($verbose); 243*946379e7Schristos 244*946379e7Schristos # Setup and see if we need to do this. 245*946379e7Schristos return if (!initialise()); 246*946379e7Schristos 247*946379e7Schristos tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in 248*946379e7Schristos tag_META_INCLUDES (); # Supplies directories for src locations 249*946379e7Schristos 250*946379e7Schristos foreach $program (@programs) { 251*946379e7Schristos $sources_changed{$program} = 0; 252*946379e7Schristos $depedmocs{$program} = ""; 253*946379e7Schristos $important{$program} = ""; 254*946379e7Schristos tag_IDLFILES(); # Sorts out idl rules 255*946379e7Schristos tag_CLOSURE(); 256*946379e7Schristos tag_UIFILES(); # Sorts out ui rules 257*946379e7Schristos tag_METASOURCES (); # Sorts out the moc rules 258*946379e7Schristos if ($sources_changed{$program}) { 259*946379e7Schristos my $lookup = "$program" . '_SOURCES\s*=\s*(.*)'; 260*946379e7Schristos substituteLine($lookup, "$program\_SOURCES=" . $sources{$program}); 261*946379e7Schristos } 262*946379e7Schristos if ($important{$program}) { 263*946379e7Schristos local %source_dict = (); 264*946379e7Schristos for $source (split(/[\034\s]+/, $sources{$program})) { 265*946379e7Schristos $source_dict{$source} = 1; 266*946379e7Schristos } 267*946379e7Schristos for $source (@cleanfiles) { 268*946379e7Schristos $source_dict{$source} = 0; 269*946379e7Schristos } 270*946379e7Schristos for $source (keys %source_dict) { 271*946379e7Schristos next if (!$source); 272*946379e7Schristos if ($source_dict{$source}) { 273*946379e7Schristos # sanity check 274*946379e7Schristos if (! -f $source) { 275*946379e7Schristos print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n"; 276*946379e7Schristos } else { 277*946379e7Schristos $target_adds{"\$(srcdir)/$source"} .= $important{$program}; 278*946379e7Schristos } 279*946379e7Schristos } 280*946379e7Schristos } 281*946379e7Schristos } 282*946379e7Schristos } 283*946379e7Schristos if ($cleanMoc) { 284*946379e7Schristos # Always add dist clean tag 285*946379e7Schristos # Add extra *.moc.cpp files created for USE_AUTOMOC because they 286*946379e7Schristos # aren't included in the normal *.moc clean rules. 287*946379e7Schristos appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n"); 288*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources "; 289*946379e7Schristos } 290*946379e7Schristos 291*946379e7Schristos tag_DIST() unless ($kdeopts{"noautodist"}); 292*946379e7Schristos 293*946379e7Schristos if ($idl_output) { 294*946379e7Schristos appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n"); 295*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-idl "; 296*946379e7Schristos } 297*946379e7Schristos 298*946379e7Schristos if ($ui_output) { 299*946379e7Schristos appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n"); 300*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-ui "; 301*946379e7Schristos } 302*946379e7Schristos 303*946379e7Schristos if ($closure_output) { 304*946379e7Schristos appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n"); 305*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-closures "; 306*946379e7Schristos } 307*946379e7Schristos 308*946379e7Schristos if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) { 309*946379e7Schristos $kdelang = '$(KDE_LANG)' 310*946379e7Schristos } else { 311*946379e7Schristos $kdelang = ''; 312*946379e7Schristos } 313*946379e7Schristos 314*946379e7Schristos tag_POFILES (); # language rules for po directory 315*946379e7Schristos tag_DOCFILES (); # language rules for doc directories 316*946379e7Schristos tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs 317*946379e7Schristos tag_ICON(); 318*946379e7Schristos tag_SUBDIRS(); 319*946379e7Schristos 320*946379e7Schristos my $tmp = "force-reedit:\n"; 321*946379e7Schristos $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n"; 322*946379e7Schristos appendLines($tmp); 323*946379e7Schristos 324*946379e7Schristos make_meta_classes(); 325*946379e7Schristos tag_COMPILE_FIRST(); 326*946379e7Schristos tag_FINAL() if (!$kdeopts{"nofinal"}); 327*946379e7Schristos 328*946379e7Schristos my $final_lines = "final:\n\t\$(MAKE) "; 329*946379e7Schristos my $final_install_lines = "final-install:\n\t\$(MAKE) "; 330*946379e7Schristos my $nofinal_lines = "no-final:\n\t\$(MAKE) "; 331*946379e7Schristos my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) "; 332*946379e7Schristos 333*946379e7Schristos foreach $program (@programs) { 334*946379e7Schristos 335*946379e7Schristos my $lookup = "$program\_OBJECTS.*=[^\n]*"; 336*946379e7Schristos 337*946379e7Schristos my $new = ""; 338*946379e7Schristos 339*946379e7Schristos my @list = split(/[\034\s]+/, $realObjs{$program}); 340*946379e7Schristos 341*946379e7Schristos if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) { 342*946379e7Schristos 343*946379e7Schristos $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program}; 344*946379e7Schristos $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program}; 345*946379e7Schristos $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)"; 346*946379e7Schristos $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)"; 347*946379e7Schristos 348*946379e7Schristos $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; 349*946379e7Schristos $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; 350*946379e7Schristos $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" "; 351*946379e7Schristos $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" "; 352*946379e7Schristos } else { 353*946379e7Schristos $new = "$program\_OBJECTS = " . $realObjs{$program}; 354*946379e7Schristos } 355*946379e7Schristos substituteLine ($lookup, $new); 356*946379e7Schristos } 357*946379e7Schristos appendLines($final_lines . "all-am"); 358*946379e7Schristos appendLines($final_install_lines . "install-am"); 359*946379e7Schristos appendLines($nofinal_lines . "all-am"); 360*946379e7Schristos appendLines($nofinal_install_lines . "install-am"); 361*946379e7Schristos 362*946379e7Schristos my $lookup = '(\@\S+\@)?DEP_FILES\s*=([^\n]*)'; 363*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/o) { 364*946379e7Schristos my $condition = $1; 365*946379e7Schristos my $depfiles = $2; 366*946379e7Schristos my $workfiles; 367*946379e7Schristos 368*946379e7Schristos if ($dep_finals) { 369*946379e7Schristos # Add the conditions on every line, since 370*946379e7Schristos # there may be line continuations in the list. 371*946379e7Schristos $workfiles = "$dep_files $dep_finals $depfiles"; 372*946379e7Schristos $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g; 373*946379e7Schristos $lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n"; 374*946379e7Schristos $workfiles = "$dep_files $depfiles"; 375*946379e7Schristos $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g; 376*946379e7Schristos $lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles\n"; 377*946379e7Schristos } else { 378*946379e7Schristos $workfiles = "$dep_files $depfiles"; 379*946379e7Schristos $workfiles =~ s/\034/\034$condition\t/g; 380*946379e7Schristos $lines = $condition . "DEP_FILES = $workfiles\n"; 381*946379e7Schristos } 382*946379e7Schristos substituteLine($lookup, $lines); 383*946379e7Schristos } 384*946379e7Schristos 385*946379e7Schristos my $cvs_lines = "cvs-clean:\n"; 386*946379e7Schristos $cvs_lines .= "\t\$(MAKE) admindir=\$(top_srcdir)/admin -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n"; 387*946379e7Schristos appendLines($cvs_lines); 388*946379e7Schristos 389*946379e7Schristos $cvs_lines = "kde-rpo-clean:\n"; 390*946379e7Schristos $cvs_lines .= "\t-rm -f *.rpo\n"; 391*946379e7Schristos appendLines($cvs_lines); 392*946379e7Schristos $target_adds{"clean"} .= "kde-rpo-clean "; 393*946379e7Schristos 394*946379e7Schristos my %target_dels = ("install-data-am" => ""); 395*946379e7Schristos 396*946379e7Schristos # some strange people like to do a install-exec, and expect that also 397*946379e7Schristos # all modules are installed. automake doesn't know this, so we need to move 398*946379e7Schristos # this here from install-data to install-exec. 399*946379e7Schristos if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) { 400*946379e7Schristos# $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES "; 401*946379e7Schristos# don't use $target_adds here because we need to append the dependency, not 402*946379e7Schristos# prepend it. Fixes #44342 , when a module depends on a lib in the same dir 403*946379e7Schristos# and libtool needs it during relinking upon install (Simon) 404*946379e7Schristos my $lookup = "install-exec-am:([^\n]*)"; 405*946379e7Schristos if($MakefileData =~ /\n$lookup\n/) { 406*946379e7Schristos substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES"); 407*946379e7Schristos } 408*946379e7Schristos $target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES "; 409*946379e7Schristos $target_adds{"install-data-am"} .= " "; 410*946379e7Schristos } 411*946379e7Schristos 412*946379e7Schristos my $lines = ""; 413*946379e7Schristos 414*946379e7Schristos foreach $add (keys %target_adds) { 415*946379e7Schristos my $lookup = quotemeta($add) . ':([^\n]*)'; 416*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/) { 417*946379e7Schristos my $newlines = $1; 418*946379e7Schristos my $oldlines = $lookup; 419*946379e7Schristos if (defined $target_dels{$add}) { 420*946379e7Schristos foreach $del (split(' ', $target_dels{$add})) { 421*946379e7Schristos $newlines =~ s/\s*$del\s*/ /g; 422*946379e7Schristos } 423*946379e7Schristos } 424*946379e7Schristos substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines); 425*946379e7Schristos } else { 426*946379e7Schristos $lines .= "$add: " . $target_adds{$add} . "\n"; 427*946379e7Schristos } 428*946379e7Schristos } 429*946379e7Schristos if ($lines) { 430*946379e7Schristos appendLines($lines); 431*946379e7Schristos } 432*946379e7Schristos 433*946379e7Schristos my $found = 1; 434*946379e7Schristos 435*946379e7Schristos while ($found) { 436*946379e7Schristos if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) { 437*946379e7Schristos my $vor = $1; # "vor" means before in German 438*946379e7Schristos my $nach = $2; # "nach" means after in German 439*946379e7Schristos my $lookup = quotemeta("$1\$(CXXFLAGS)$2"); 440*946379e7Schristos my $replacement = "$1\$(KCXXFLAGS)$2"; 441*946379e7Schristos $MakefileData =~ s/$lookup/$replacement/; 442*946379e7Schristos $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/; 443*946379e7Schristos $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach"; 444*946379e7Schristos substituteLine($lookup, $replacement); 445*946379e7Schristos } else { 446*946379e7Schristos $found = 0; 447*946379e7Schristos } 448*946379e7Schristos } 449*946379e7Schristos 450*946379e7Schristos if($foreign_libtool == 0) { 451*946379e7Schristos $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))'; 452*946379e7Schristos 453*946379e7Schristos if ($MakefileData =~ m/$lookup/ ) { 454*946379e7Schristos $MakefileData =~ s/$lookup/$1 --tag=CXX $2/; 455*946379e7Schristos } 456*946379e7Schristos 457*946379e7Schristos $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)'; 458*946379e7Schristos if ($MakefileData =~ m/$lookup/ ) { 459*946379e7Schristos $MakefileData =~ s/$lookup/$1 --tag=CXX $2/; 460*946379e7Schristos } 461*946379e7Schristos } 462*946379e7Schristos 463*946379e7Schristos $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g; 464*946379e7Schristos 465*946379e7Schristos $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)'; 466*946379e7Schristos if ($MakefileData =~ m/\n$lookup\n/) { 467*946379e7Schristos substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2"); 468*946379e7Schristos } 469*946379e7Schristos 470*946379e7Schristos # Always update the Makefile.in 471*946379e7Schristos updateMakefile (); 472*946379e7Schristos return; 473*946379e7Schristos} 474*946379e7Schristos 475*946379e7Schristos#----------------------------------------------------------------------------- 476*946379e7Schristos 477*946379e7Schristos# Beware: This procedure is not complete. E.g. it also parses lines 478*946379e7Schristos# containing a '=' in rules (for instance setting shell vars). For our 479*946379e7Schristos# usage this us enough, though. 480*946379e7Schristossub read_variables () 481*946379e7Schristos{ 482*946379e7Schristos while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) { 483*946379e7Schristos $varcontent{$1} = $2; 484*946379e7Schristos } 485*946379e7Schristos} 486*946379e7Schristos 487*946379e7Schristos# Check to see whether we should process this make file. 488*946379e7Schristos# This is where we look for tags that we need to process. 489*946379e7Schristos# A small amount of initialising on the tags is also done here. 490*946379e7Schristos# And of course we open and/or create the needed make files. 491*946379e7Schristossub initialise () 492*946379e7Schristos{ 493*946379e7Schristos if (! -r "Makefile.am") { 494*946379e7Schristos print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose); 495*946379e7Schristos return 0; 496*946379e7Schristos } 497*946379e7Schristos 498*946379e7Schristos # Checking for files to process... 499*946379e7Schristos open (FILEIN, $makefile) 500*946379e7Schristos || die "Could not open $makefileDir/$makefile: $!\n"; 501*946379e7Schristos # Read the file 502*946379e7Schristos # stat(FILEIN)[7] might look more elegant, but is slower as it 503*946379e7Schristos # requires stat'ing the file 504*946379e7Schristos seek(FILEIN, 0, 2); 505*946379e7Schristos my $fsize = tell(FILEIN); 506*946379e7Schristos seek(FILEIN, 0, 0); 507*946379e7Schristos read FILEIN, $MakefileData, $fsize; 508*946379e7Schristos close FILEIN; 509*946379e7Schristos print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d); 510*946379e7Schristos 511*946379e7Schristos # Remove the line continuations, but keep them marked 512*946379e7Schristos # Note: we lose the trailing spaces but that's ok. 513*946379e7Schristos # Don't mangle line-leading spaces (usually tabs) 514*946379e7Schristos # since they're important. 515*946379e7Schristos $MakefileData =~ s/\\\s*\n/\034/g; 516*946379e7Schristos 517*946379e7Schristos # If we've processed the file before... 518*946379e7Schristos restoreMakefile () if ($MakefileData =~ /$progId/); 519*946379e7Schristos 520*946379e7Schristos foreach $dir (@foreignfiles) { 521*946379e7Schristos if (substr($makefileDir,0,length($dir)) eq $dir) { 522*946379e7Schristos return 0; 523*946379e7Schristos } 524*946379e7Schristos } 525*946379e7Schristos 526*946379e7Schristos %kdeopts = (); 527*946379e7Schristos $kdeopts{"foreign"} = 0; 528*946379e7Schristos $kdeopts{"qtonly"} = 0; 529*946379e7Schristos $kdeopts{"noautodist"} = 0; 530*946379e7Schristos $kdeopts{"foreign-libtool"} = $foreign_libtool; 531*946379e7Schristos $kdeopts{"nofinal"} = !$use_final; # default 532*946379e7Schristos 533*946379e7Schristos read_variables(); 534*946379e7Schristos 535*946379e7Schristos if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) { 536*946379e7Schristos my $kde_options_str = $1; 537*946379e7Schristos local @kde_options = split(/[\034\s]+/, $kde_options_str); 538*946379e7Schristos if (grep(/^foreign$/, @kde_options)) { 539*946379e7Schristos push(@foreignfiles, $makefileDir . "/"); 540*946379e7Schristos return 0; # don't touch me 541*946379e7Schristos } 542*946379e7Schristos for $opt (@kde_options) { 543*946379e7Schristos if (!defined $kdeopts{$opt}) { 544*946379e7Schristos print STDERR "Warning: unknown option $opt in $printname\n"; 545*946379e7Schristos } else { 546*946379e7Schristos $kdeopts{$opt} = 1; 547*946379e7Schristos } 548*946379e7Schristos } 549*946379e7Schristos } 550*946379e7Schristos 551*946379e7Schristos # Look for the tags that mean we should process this file. 552*946379e7Schristos $metasourceTags = 0; 553*946379e7Schristos $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g); 554*946379e7Schristos 555*946379e7Schristos my $pofileTag = 0; 556*946379e7Schristos $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g); 557*946379e7Schristos if ($pofileTag > 1) 558*946379e7Schristos { 559*946379e7Schristos print STDERR "Error: Only one POFILES tag allowed\n"; 560*946379e7Schristos $errorflag = 1; 561*946379e7Schristos } 562*946379e7Schristos 563*946379e7Schristos while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) { 564*946379e7Schristos my $suffixes_str = $1; 565*946379e7Schristos my @list=split(' ', $suffixes_str); 566*946379e7Schristos foreach $ext (@list) { 567*946379e7Schristos if ($ext =~ /^\.$cppExt$/) { 568*946379e7Schristos $cxxsuffix = $ext; 569*946379e7Schristos $cxxsuffix =~ s/\.//g; 570*946379e7Schristos print STDOUT "will use suffix $cxxsuffix\n" if ($verbose); 571*946379e7Schristos last; 572*946379e7Schristos } 573*946379e7Schristos } 574*946379e7Schristos } 575*946379e7Schristos 576*946379e7Schristos while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[\034\s]*([^\n]*)\n/g) { 577*946379e7Schristos 578*946379e7Schristos my $program = $1; 579*946379e7Schristos my $objs = $2; # safe them 580*946379e7Schristos 581*946379e7Schristos my $ocv = 0; 582*946379e7Schristos 583*946379e7Schristos my @objlist = split(/[\034\s]+/, $objs); 584*946379e7Schristos foreach $obj (@objlist) { 585*946379e7Schristos if ($obj =~ /(\S*)\$\((\S+)\)/ ) { 586*946379e7Schristos my $pre = $1; 587*946379e7Schristos my $variable = $2; 588*946379e7Schristos if ($pre eq '' && exists($varcontent{$variable})) { 589*946379e7Schristos my @addlist = split(/[\034\s]+/, $varcontent{$variable}); 590*946379e7Schristos push(@objlist, @addlist); 591*946379e7Schristos } elsif ($variable !~ 'OBJEXT') { 592*946379e7Schristos $ocv = 1; 593*946379e7Schristos } 594*946379e7Schristos } 595*946379e7Schristos } 596*946379e7Schristos 597*946379e7Schristos next if ($ocv); 598*946379e7Schristos 599*946379e7Schristos $program =~ s/^am_// if ($program =~ /^am_/); 600*946379e7Schristos 601*946379e7Schristos my $sourceprogram = $program; 602*946379e7Schristos $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/); 603*946379e7Schristos 604*946379e7Schristos print STDOUT "found program $program\n" if ($verbose); 605*946379e7Schristos push(@programs, $program); 606*946379e7Schristos 607*946379e7Schristos $realObjs{$program} = $objs; 608*946379e7Schristos 609*946379e7Schristos if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=\s*(.*)\n/) { 610*946379e7Schristos $sources{$program} = $1; 611*946379e7Schristos } 612*946379e7Schristos else { 613*946379e7Schristos $sources{$program} = ""; 614*946379e7Schristos print STDERR "found program with no _SOURCES: $program\n"; 615*946379e7Schristos } 616*946379e7Schristos 617*946379e7Schristos my $realprogram = $program; 618*946379e7Schristos $realprogram =~ s/_/./g; # unmask to regexp 619*946379e7Schristos if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) { 620*946379e7Schristos $realname{$program} = $1; 621*946379e7Schristos } else { 622*946379e7Schristos # not standard Makefile - nothing to worry about 623*946379e7Schristos $realname{$program} = ""; 624*946379e7Schristos } 625*946379e7Schristos } 626*946379e7Schristos 627*946379e7Schristos my $lookup = 'DEPDIR\s*=.*'; 628*946379e7Schristos if ($MakefileData !~ /\n($lookup)\n/o) { 629*946379e7Schristos $lookup = 'bindir\s*=.*'; 630*946379e7Schristos if ($MakefileData =~ /\n($lookup)\n/) { 631*946379e7Schristos substituteLine ($lookup, "DEPDIR = .deps\n$1"); 632*946379e7Schristos } 633*946379e7Schristos } 634*946379e7Schristos 635*946379e7Schristos my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES'); 636*946379e7Schristos foreach $mark (@marks) { 637*946379e7Schristos while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) { 638*946379e7Schristos my $clean_str = $2; 639*946379e7Schristos foreach $file (split('[\034\s]+', $clean_str)) { 640*946379e7Schristos $file =~ s/\.\///; 641*946379e7Schristos push(@cleanfiles, $file); 642*946379e7Schristos } 643*946379e7Schristos } 644*946379e7Schristos } 645*946379e7Schristos 646*946379e7Schristos my $localTag = 0; 647*946379e7Schristos $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/); 648*946379e7Schristos 649*946379e7Schristos return (!$errorflag); 650*946379e7Schristos} 651*946379e7Schristos 652*946379e7Schristos#----------------------------------------------------------------------------- 653*946379e7Schristos 654*946379e7Schristos# Gets the list of user defined directories - relative to $srcdir - where 655*946379e7Schristos# header files could be located. 656*946379e7Schristossub tag_META_INCLUDES () 657*946379e7Schristos{ 658*946379e7Schristos my $lookup = '[^=\n]*META_INCLUDES\s*=\s*(.*)'; 659*946379e7Schristos return 1 if ($MakefileData !~ /($lookup)\n/o); 660*946379e7Schristos print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose); 661*946379e7Schristos 662*946379e7Schristos my $headerStr = $2; 663*946379e7Schristos removeLine ($lookup, $1); 664*946379e7Schristos 665*946379e7Schristos my @headerlist = split(/[\034\s]+/, $headerStr); 666*946379e7Schristos 667*946379e7Schristos foreach $dir (@headerlist) 668*946379e7Schristos { 669*946379e7Schristos $dir =~ s#\$\(srcdir\)#.#; 670*946379e7Schristos if (! -d $dir) 671*946379e7Schristos { 672*946379e7Schristos print STDERR "Warning: $dir can't be found. ", 673*946379e7Schristos "Must be a relative path to \$(srcdir)\n"; 674*946379e7Schristos } 675*946379e7Schristos else 676*946379e7Schristos { 677*946379e7Schristos push (@headerdirs, $dir); 678*946379e7Schristos } 679*946379e7Schristos } 680*946379e7Schristos 681*946379e7Schristos return 0; 682*946379e7Schristos} 683*946379e7Schristos 684*946379e7Schristos#----------------------------------------------------------------------------- 685*946379e7Schristos 686*946379e7Schristossub tag_FINAL() 687*946379e7Schristos{ 688*946379e7Schristos my @final_names = (); 689*946379e7Schristos 690*946379e7Schristos foreach $program (@programs) { 691*946379e7Schristos 692*946379e7Schristos if ($sources{$program} =~ /\(/) { 693*946379e7Schristos print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose); 694*946379e7Schristos next; 695*946379e7Schristos } 696*946379e7Schristos 697*946379e7Schristos my $mocs = ""; # Moc files (in this program) 698*946379e7Schristos my $moc_cpp_added = 0; # If we added some .moc.cpp files, due to 699*946379e7Schristos # no other .cpp file including the .moc one. 700*946379e7Schristos 701*946379e7Schristos my @progsources = split(/[\034\s]+/, $sources{$program}); 702*946379e7Schristos my %shash = (); 703*946379e7Schristos @shash{@progsources} = 1; # we are only interested in the existence 704*946379e7Schristos my %sourcelist = (); 705*946379e7Schristos 706*946379e7Schristos foreach $source (@progsources) { 707*946379e7Schristos my $suffix = $source; 708*946379e7Schristos $suffix =~ s/^.*\.([^\.]+)$/$1/; 709*946379e7Schristos 710*946379e7Schristos $sourcelist{$suffix} .= "$source "; 711*946379e7Schristos } 712*946379e7Schristos foreach my $mocFile (keys (%globalmocs)) 713*946379e7Schristos { 714*946379e7Schristos my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3); 715*946379e7Schristos if (defined ($cppFile)) { 716*946379e7Schristos $mocs .= " $mocFile.moc" if exists $shash{$cppFile}; 717*946379e7Schristos } else { 718*946379e7Schristos $sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix "; 719*946379e7Schristos $moc_cpp_added = 1; 720*946379e7Schristos } 721*946379e7Schristos } 722*946379e7Schristos foreach $suffix (keys %sourcelist) { 723*946379e7Schristos 724*946379e7Schristos # See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions) 725*946379e7Schristos my $suffix_is_cxx = 0; 726*946379e7Schristos if($suffix =~ /($cppExt)$/) { 727*946379e7Schristos $cxxsuffix = $1; 728*946379e7Schristos $suffix_is_cxx = 1; 729*946379e7Schristos } 730*946379e7Schristos 731*946379e7Schristos my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added; 732*946379e7Schristos 733*946379e7Schristos my @sourcelist = split(/[\034\s]+/, $sourcelist{$suffix}); 734*946379e7Schristos 735*946379e7Schristos if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) { 736*946379e7Schristos 737*946379e7Schristos # we support IDL on our own 738*946379e7Schristos if ($suffix eq "skel" || $suffix =~ /^stub/ 739*946379e7Schristos || $suffix =~ /^signals/ # obsolete, remove in KDE-4 740*946379e7Schristos || $suffix eq "h" || $suffix eq "ui" ) { 741*946379e7Schristos next; 742*946379e7Schristos } 743*946379e7Schristos 744*946379e7Schristos foreach $file (@sourcelist) { 745*946379e7Schristos $file =~ s/\Q$suffix\E$//; 746*946379e7Schristos 747*946379e7Schristos $finalObjs{$program} .= $file; 748*946379e7Schristos if ($program =~ /_la$/) { 749*946379e7Schristos $finalObjs{$program} .= "lo "; 750*946379e7Schristos } else { 751*946379e7Schristos $finalObjs{$program} .= "o "; 752*946379e7Schristos } 753*946379e7Schristos } 754*946379e7Schristos next; # suffix 755*946379e7Schristos } 756*946379e7Schristos 757*946379e7Schristos my $source_deps = ""; 758*946379e7Schristos foreach $source (@sourcelist) { 759*946379e7Schristos if (-f $source) { 760*946379e7Schristos $source_deps .= " \$(srcdir)/$source"; 761*946379e7Schristos } else { 762*946379e7Schristos $source_deps .= " $source"; 763*946379e7Schristos } 764*946379e7Schristos } 765*946379e7Schristos 766*946379e7Schristos $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs) . "\n"; 767*946379e7Schristos $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n"; 768*946379e7Schristos $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n"; 769*946379e7Schristos $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n"; 770*946379e7Schristos $handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n"; 771*946379e7Schristos $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n"; 772*946379e7Schristos $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n"; 773*946379e7Schristos $handling .= "\tdone; \\\n"; 774*946379e7Schristos $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n"; 775*946379e7Schristos $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n"; 776*946379e7Schristos 777*946379e7Schristos appendLines($handling); 778*946379e7Schristos 779*946379e7Schristos push(@final_names, "$program.all_$suffix.$suffix"); 780*946379e7Schristos my $finalObj = "$program.all_$suffix."; 781*946379e7Schristos if ($program =~ /_la$/) { 782*946379e7Schristos $finalObj .= "lo"; 783*946379e7Schristos } else { 784*946379e7Schristos $finalObj .= "o"; 785*946379e7Schristos } 786*946379e7Schristos $finalObjs{$program} .= $finalObj . " "; 787*946379e7Schristos } 788*946379e7Schristos } 789*946379e7Schristos 790*946379e7Schristos if (!$kdeopts{"nofinal"} && @final_names >= 1) { 791*946379e7Schristos # add clean-final target 792*946379e7Schristos my $lines = "$cleantarget-final:\n"; 793*946379e7Schristos $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names); 794*946379e7Schristos appendLines($lines); 795*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-final "; 796*946379e7Schristos 797*946379e7Schristos foreach $finalfile (@final_names) { 798*946379e7Schristos $finalfile =~ s/\.[^.]*$/.P/; 799*946379e7Schristos $dep_finals .= " \$(DEPDIR)/$finalfile"; 800*946379e7Schristos } 801*946379e7Schristos } 802*946379e7Schristos} 803*946379e7Schristos 804*946379e7Schristos#----------------------------------------------------------------------------- 805*946379e7Schristos 806*946379e7Schristossub tag_COMPILE_FIRST() 807*946379e7Schristos{ 808*946379e7Schristos foreach $program (@programs) { 809*946379e7Schristos my $lookup = "$program" . '_COMPILE_FIRST\s*=\s*(.*)'; 810*946379e7Schristos if ($MakefileData =~ m/\n$lookup\n/) { 811*946379e7Schristos my $compilefirst_str = $1; 812*946379e7Schristos my @compilefirst = split(/[\034\s]+/, $compilefirst_str); 813*946379e7Schristos my @progsources = split(/[\034\s]+/, $sources{$program}); 814*946379e7Schristos my %donesources = (); 815*946379e7Schristos $handling = ""; 816*946379e7Schristos foreach $source (@progsources) { 817*946379e7Schristos my @deps = (); 818*946379e7Schristos my $sdeps = ""; 819*946379e7Schristos if (-f $source) { 820*946379e7Schristos $sdeps = "\$(srcdir)/$source"; 821*946379e7Schristos } else { 822*946379e7Schristos $sdeps = "$source"; 823*946379e7Schristos } 824*946379e7Schristos foreach $depend (@compilefirst) { 825*946379e7Schristos next if ($source eq $depend); 826*946379e7Schristos # avoid cyclic dependencies 827*946379e7Schristos next if defined($donesources{$depend}); 828*946379e7Schristos push @deps, $depend; 829*946379e7Schristos } 830*946379e7Schristos $handling .= "$sdeps: " . join(' ', @deps) . "\n" if (@deps); 831*946379e7Schristos $donesources{$source} = 1; 832*946379e7Schristos } 833*946379e7Schristos appendLines($handling) if (length($handling)); 834*946379e7Schristos } 835*946379e7Schristos } 836*946379e7Schristos} 837*946379e7Schristos 838*946379e7Schristos#----------------------------------------------------------------------------- 839*946379e7Schristos 840*946379e7Schristos 841*946379e7Schristos# Organises the list of headers that we'll use to produce moc files 842*946379e7Schristos# from. 843*946379e7Schristossub tag_METASOURCES () 844*946379e7Schristos{ 845*946379e7Schristos local @newObs = (); # here we add to create object files 846*946379e7Schristos local @deped = (); # here we add to create moc files 847*946379e7Schristos local $mocExt = ".moc"; 848*946379e7Schristos local %mocFiles = (); 849*946379e7Schristos 850*946379e7Schristos my $line = ""; 851*946379e7Schristos my $postEqual = ""; 852*946379e7Schristos 853*946379e7Schristos my $lookup; 854*946379e7Schristos my $found = ""; 855*946379e7Schristos#print "$program: tag_METASOURCES\n"; 856*946379e7Schristos if ($metasourceTags > 1) { 857*946379e7Schristos $lookup = $program . '_METASOURCES\s*=\s*(.*)'; 858*946379e7Schristos return 1 if ($MakefileData !~ /\n($lookup)\n/); 859*946379e7Schristos $found = $1; 860*946379e7Schristos } else { 861*946379e7Schristos $lookup = $program . '_METASOURCES\s*=\s*(.*)'; 862*946379e7Schristos if ($MakefileData !~ /\n($lookup)\n/) { 863*946379e7Schristos $lookup = 'METASOURCES\s*=\s*(.*)'; 864*946379e7Schristos return 1 if ($MakefileData !~ /\n($lookup)\n/o); 865*946379e7Schristos $found = $1; 866*946379e7Schristos $metasourceTags = 0; # we can use the general target only once 867*946379e7Schristos } else { 868*946379e7Schristos $found = $1; 869*946379e7Schristos } 870*946379e7Schristos } 871*946379e7Schristos print STDOUT "METASOURCE processing <$found>)\n" if ($verbose); 872*946379e7Schristos 873*946379e7Schristos $postEqual = $found; 874*946379e7Schristos $postEqual =~ s/[^=]*=//; 875*946379e7Schristos 876*946379e7Schristos removeLine ($lookup, $found); 877*946379e7Schristos 878*946379e7Schristos # Always find the header files that could be used to "moc" 879*946379e7Schristos return 1 if (findMocCandidates ()); 880*946379e7Schristos 881*946379e7Schristos if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/) 882*946379e7Schristos { 883*946379e7Schristos print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+); 884*946379e7Schristos $mocExt = ".moc.$cxxsuffix"; 885*946379e7Schristos $haveAutomocTag = 1; 886*946379e7Schristos } 887*946379e7Schristos else 888*946379e7Schristos { 889*946379e7Schristos # Not automoc so read the list of files supplied which 890*946379e7Schristos # should be .moc files. 891*946379e7Schristos 892*946379e7Schristos $postEqual =~ tr/\034/ /; 893*946379e7Schristos 894*946379e7Schristos # prune out extra headers - This also checks to make sure that 895*946379e7Schristos # the list is valid. 896*946379e7Schristos pruneMocCandidates ($postEqual); 897*946379e7Schristos } 898*946379e7Schristos 899*946379e7Schristos checkMocCandidates (); 900*946379e7Schristos 901*946379e7Schristos if (@newObs) { 902*946379e7Schristos my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o "; 903*946379e7Schristos $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext; 904*946379e7Schristos $depedmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix"; 905*946379e7Schristos foreach $file (@newObs) { 906*946379e7Schristos $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/); 907*946379e7Schristos } 908*946379e7Schristos } 909*946379e7Schristos if (@deped) { 910*946379e7Schristos $depedmocs{$program} .= " "; 911*946379e7Schristos $depedmocs{$program} .= join('.moc ', @deped) . ".moc"; 912*946379e7Schristos $depedmocs{$program} .= " "; 913*946379e7Schristos } 914*946379e7Schristos addMocRules (); 915*946379e7Schristos @globalmocs{keys %mocFiles}=values %mocFiles; 916*946379e7Schristos} 917*946379e7Schristos 918*946379e7Schristos#----------------------------------------------------------------------------- 919*946379e7Schristos 920*946379e7Schristos# Returns 0 if the line was processed - 1 otherwise. 921*946379e7Schristos# Errors are logged in the global $errorflags 922*946379e7Schristossub tag_AUTOMAKE () 923*946379e7Schristos{ 924*946379e7Schristos my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\034\s]+\$\(AUTOMAKE\)(.*)'; 925*946379e7Schristos return 1 if ($MakefileData !~ /\n($lookup)\n/); 926*946379e7Schristos print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose); 927*946379e7Schristos 928*946379e7Schristos my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname"; 929*946379e7Schristos substituteLine ($lookup, $newLine); 930*946379e7Schristos $automkCall = $1; 931*946379e7Schristos return 0; 932*946379e7Schristos} 933*946379e7Schristos 934*946379e7Schristos#----------------------------------------------------------------------------- 935*946379e7Schristos 936*946379e7Schristossub handle_TOPLEVEL() 937*946379e7Schristos{ 938*946379e7Schristos my $pofiles = ""; 939*946379e7Schristos my @restfiles = (); 940*946379e7Schristos opendir (THISDIR, "."); 941*946379e7Schristos foreach $entry (readdir(THISDIR)) { 942*946379e7Schristos next if (-d $entry); 943*946379e7Schristos 944*946379e7Schristos next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/); 945*946379e7Schristos 946*946379e7Schristos if ($entry =~ /\.po$/) { 947*946379e7Schristos next; 948*946379e7Schristos } 949*946379e7Schristos push(@restfiles, $entry); 950*946379e7Schristos } 951*946379e7Schristos closedir (THISDIR); 952*946379e7Schristos 953*946379e7Schristos if (@restfiles) { 954*946379e7Schristos $target_adds{"install-data-am"} .= "install-nls-files "; 955*946379e7Schristos $lines = "install-nls-files:\n"; 956*946379e7Schristos $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n"; 957*946379e7Schristos for $file (@restfiles) { 958*946379e7Schristos $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n"; 959*946379e7Schristos } 960*946379e7Schristos $target_adds{"uninstall"} .= "uninstall-nls-files "; 961*946379e7Schristos $lines .= "uninstall-nls-files:\n"; 962*946379e7Schristos for $file (@restfiles) { 963*946379e7Schristos $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n"; 964*946379e7Schristos } 965*946379e7Schristos appendLines($lines); 966*946379e7Schristos } 967*946379e7Schristos 968*946379e7Schristos return 0; 969*946379e7Schristos} 970*946379e7Schristos 971*946379e7Schristos#----------------------------------------------------------------------------- 972*946379e7Schristos 973*946379e7Schristossub tag_SUBDIRS () 974*946379e7Schristos{ 975*946379e7Schristos if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) { 976*946379e7Schristos return 1; 977*946379e7Schristos } 978*946379e7Schristos 979*946379e7Schristos my $subdirs = "."; 980*946379e7Schristos 981*946379e7Schristos opendir (THISDIR, "."); 982*946379e7Schristos foreach $entry (readdir(THISDIR)) { 983*946379e7Schristos next if ($entry eq "CVS" || $entry =~ /^\./); 984*946379e7Schristos if (-d $entry && -f $entry . "/Makefile.am") { 985*946379e7Schristos $subdirs .= " $entry"; 986*946379e7Schristos next; 987*946379e7Schristos } 988*946379e7Schristos } 989*946379e7Schristos closedir (THISDIR); 990*946379e7Schristos 991*946379e7Schristos my $lines = "SUBDIRS =$subdirs\n"; 992*946379e7Schristos substituteLine('SUBDIRS\s*=.*', $lines); 993*946379e7Schristos return 0; 994*946379e7Schristos} 995*946379e7Schristos 996*946379e7Schristossub tag_IDLFILES () 997*946379e7Schristos{ 998*946379e7Schristos my @psources = split(/[\034\s]+/, $sources{$program}); 999*946379e7Schristos my $dep_lines = ""; 1000*946379e7Schristos my @cppFiles = (); 1001*946379e7Schristos 1002*946379e7Schristos foreach $source (@psources) { 1003*946379e7Schristos 1004*946379e7Schristos my $skel = ($source =~ m/\.skel$/); 1005*946379e7Schristos my $stub = ($source =~ m/\.stub$/); 1006*946379e7Schristos my $signals = ($source =~ m/\.signals$/); # obsolete, remove in KDE-4 1007*946379e7Schristos 1008*946379e7Schristos if ($stub || $skel || $signals) { 1009*946379e7Schristos 1010*946379e7Schristos my $qs = quotemeta($source); 1011*946379e7Schristos $sources{$program} =~ s/$qs//; 1012*946379e7Schristos $sources_changed{$program} = 1; 1013*946379e7Schristos 1014*946379e7Schristos print STDOUT "adding IDL file $source\n" if ($verbose); 1015*946379e7Schristos 1016*946379e7Schristos $source =~ s/\.(stub|skel|signals)$//; 1017*946379e7Schristos 1018*946379e7Schristos my $sourcename; 1019*946379e7Schristos 1020*946379e7Schristos if ($skel) { 1021*946379e7Schristos $sourcename = "$source\_skel"; 1022*946379e7Schristos } elsif ($stub) { 1023*946379e7Schristos $sourcename = "$source\_stub"; 1024*946379e7Schristos } else { 1025*946379e7Schristos $sourcename = "$source\_signals"; 1026*946379e7Schristos } 1027*946379e7Schristos 1028*946379e7Schristos my $sourcedir = ''; 1029*946379e7Schristos if (-f "$makefileDir/$source.h") { 1030*946379e7Schristos $sourcedir = '$(srcdir)/'; 1031*946379e7Schristos } else { 1032*946379e7Schristos if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) { 1033*946379e7Schristos $sourcedir = $1; 1034*946379e7Schristos $sourcedir .= "/" if ($sourcedir !~ /\/$/); 1035*946379e7Schristos } 1036*946379e7Schristos } 1037*946379e7Schristos 1038*946379e7Schristos if ($allidls !~ /$source\_kidl/) { 1039*946379e7Schristos 1040*946379e7Schristos $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOP_DEPENDENCIES)\n"; 1041*946379e7Schristos $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; false )\n"; 1042*946379e7Schristos 1043*946379e7Schristos $allidls .= $source . "_kidl "; 1044*946379e7Schristos } 1045*946379e7Schristos 1046*946379e7Schristos if ($allidls !~ /$sourcename/) { 1047*946379e7Schristos 1048*946379e7Schristos $dep_lines_tmp = ""; 1049*946379e7Schristos 1050*946379e7Schristos if ($skel) { 1051*946379e7Schristos $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n"; 1052*946379e7Schristos $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n"; 1053*946379e7Schristos } elsif ($stub) { 1054*946379e7Schristos $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n"; 1055*946379e7Schristos } else { # signals - obsolete, remove in KDE 4 1056*946379e7Schristos $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n"; 1057*946379e7Schristos } 1058*946379e7Schristos 1059*946379e7Schristos if ($stub || $signals) { 1060*946379e7Schristos $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h "; 1061*946379e7Schristos $dep_lines .= "$sourcename.h: $source.kidl\n"; 1062*946379e7Schristos $dep_lines .= $dep_lines_tmp; 1063*946379e7Schristos } 1064*946379e7Schristos 1065*946379e7Schristos $allidls .= $sourcename . " "; 1066*946379e7Schristos } 1067*946379e7Schristos 1068*946379e7Schristos $idlfiles{$program} .= $sourcename . " "; 1069*946379e7Schristos 1070*946379e7Schristos if ($program =~ /_la$/) { 1071*946379e7Schristos $realObjs{$program} .= " $sourcename.lo"; 1072*946379e7Schristos } else { 1073*946379e7Schristos $realObjs{$program} .= " $sourcename.\$(OBJEXT)"; 1074*946379e7Schristos } 1075*946379e7Schristos $sources{$program} .= " $sourcename.$cxxsuffix"; 1076*946379e7Schristos $sources_changed{$program} = 1; 1077*946379e7Schristos $important{$program} .= "$sourcename.h " if (!$skel); 1078*946379e7Schristos $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl "; 1079*946379e7Schristos push(@cleanfiles, "$sourcename.$cxxsuffix"); 1080*946379e7Schristos push(@cleanfiles, "$sourcename.h"); 1081*946379e7Schristos push(@cleanfiles, "$sourcename.kidl"); 1082*946379e7Schristos $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/); 1083*946379e7Schristos } 1084*946379e7Schristos } 1085*946379e7Schristos if ($dep_lines) { 1086*946379e7Schristos appendLines($dep_lines); 1087*946379e7Schristos } 1088*946379e7Schristos 1089*946379e7Schristos if (0) { 1090*946379e7Schristos my $lookup = "($program)"; 1091*946379e7Schristos $lookup .= '(|\$\(EXEEXT\))'; 1092*946379e7Schristos $lookup =~ s/\_/./g; 1093*946379e7Schristos $lookup .= ":(.*..$program\_OBJECTS..*)"; 1094*946379e7Schristos # $lookup = quotemeta($lookup); 1095*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/) { 1096*946379e7Schristos 1097*946379e7Schristos my $line = "$1$2: "; 1098*946379e7Schristos foreach $file (split(' ', $idlfiles{$program})) { 1099*946379e7Schristos $line .= "$file.$cxxsuffix "; 1100*946379e7Schristos } 1101*946379e7Schristos $line .= $3; 1102*946379e7Schristos substituteLine($lookup, $line); 1103*946379e7Schristos } else { 1104*946379e7Schristos print STDERR "no built dependency found $lookup\n"; 1105*946379e7Schristos } 1106*946379e7Schristos } 1107*946379e7Schristos} 1108*946379e7Schristos 1109*946379e7Schristossub tag_UIFILES () 1110*946379e7Schristos{ 1111*946379e7Schristos my @psources = split(/[\034\s]+/, $sources{$program}); 1112*946379e7Schristos my $dep_lines = ""; 1113*946379e7Schristos my @depFiles = (); 1114*946379e7Schristos 1115*946379e7Schristos foreach $source (@psources) { 1116*946379e7Schristos 1117*946379e7Schristos if ($source =~ m/\.ui$/) { 1118*946379e7Schristos 1119*946379e7Schristos print STDERR "adding UI file $source\n" if ($verbose); 1120*946379e7Schristos 1121*946379e7Schristos my $qs = quotemeta($source); 1122*946379e7Schristos $sources{$program} =~ s/$qs//; 1123*946379e7Schristos $sources_changed{$program} = 1; 1124*946379e7Schristos 1125*946379e7Schristos $source =~ s/\.ui$//; 1126*946379e7Schristos 1127*946379e7Schristos my $sourcedir = ''; 1128*946379e7Schristos if (-f "$makefileDir/$source.ui") { 1129*946379e7Schristos $sourcedir = '$(srcdir)/'; 1130*946379e7Schristos } 1131*946379e7Schristos 1132*946379e7Schristos if (!$uiFiles{$source}) { 1133*946379e7Schristos 1134*946379e7Schristos $dep_lines .= "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n"; 1135*946379e7Schristos $dep_lines .= "\trm -f $source.$cxxsuffix\n"; 1136*946379e7Schristos if (!$kdeopts{"qtonly"}) { 1137*946379e7Schristos $dep_lines .= "\techo '#include <klocale.h>' > $source.$cxxsuffix\n"; 1138*946379e7Schristos my ($mangled_source) = $source; 1139*946379e7Schristos $mangled_source =~ s/[^A-Za-z0-9]/_/g; # get rid of garbage 1140*946379e7Schristos $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui > $source.$cxxsuffix.temp ; ret=\$\$?; \\\n"; 1141*946379e7Schristos $dep_lines .= "\tsed -e \"s,\${UIC_TR}( \\\"\\\" ),QString::null,g\" $source.$cxxsuffix.temp | sed -e \"s,\${UIC_TR}( \\\"\\\"\\, \\\"\\\" ),QString::null,g\" | sed -e \"s,image\\([0-9][0-9]*\\)_data,img\\1_" . $mangled_source . ",g\" >> $source.$cxxsuffix ;\\\n"; 1142*946379e7Schristos $dep_lines .= "\trm -f $source.$cxxsuffix.temp ;\\\n"; 1143*946379e7Schristos } else { 1144*946379e7Schristos $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix; ret=\$\$?; \\\n"; 1145*946379e7Schristos } 1146*946379e7Schristos $dep_lines .= "\tif test \"\$\$ret\" = 0; then echo '#include \"$source.moc\"' >> $source.$cxxsuffix; else rm -f $source.$cxxsuffix ; exit \$\$ret ; fi\n\n"; 1147*946379e7Schristos $dep_lines .= "$source.h: $sourcedir$source.ui\n"; 1148*946379e7Schristos $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n"; 1149*946379e7Schristos $dep_lines .= "$source.moc: $source.h\n"; 1150*946379e7Schristos $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n"; 1151*946379e7Schristos 1152*946379e7Schristos $uiFiles{$source} = 1; 1153*946379e7Schristos $depedmocs{$program} .= " $source.moc"; 1154*946379e7Schristos $globalmocs{$source} = "\035$source.h\035$source.cpp"; 1155*946379e7Schristos } 1156*946379e7Schristos 1157*946379e7Schristos if ($program =~ /_la$/) { 1158*946379e7Schristos $realObjs{$program} .= " $source.lo"; 1159*946379e7Schristos } else { 1160*946379e7Schristos $realObjs{$program} .= " $source.\$(OBJEXT)"; 1161*946379e7Schristos } 1162*946379e7Schristos $sources{$program} .= " $source.$cxxsuffix"; 1163*946379e7Schristos $sources_changed{$program} = 1; 1164*946379e7Schristos $important{$program} .= "$source.h "; 1165*946379e7Schristos $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc "; 1166*946379e7Schristos push(@cleanfiles, "$source.$cxxsuffix"); 1167*946379e7Schristos push(@cleanfiles, "source.h"); 1168*946379e7Schristos push(@cleanfiles, "$source.moc"); 1169*946379e7Schristos $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ ); 1170*946379e7Schristos } 1171*946379e7Schristos } 1172*946379e7Schristos if ($dep_lines) { 1173*946379e7Schristos appendLines($dep_lines); 1174*946379e7Schristos } 1175*946379e7Schristos} 1176*946379e7Schristos 1177*946379e7Schristossub tag_ICON() 1178*946379e7Schristos{ 1179*946379e7Schristos my $lookup = '([^\s]*)_ICON\s*=\s*([^\n]*)'; 1180*946379e7Schristos my $install = ""; 1181*946379e7Schristos my $uninstall = ""; 1182*946379e7Schristos 1183*946379e7Schristos while ($MakefileData =~ /\n$lookup/og) { 1184*946379e7Schristos my $destdir; 1185*946379e7Schristos if ($1 eq "KDE") { 1186*946379e7Schristos $destdir = "kde_icondir"; 1187*946379e7Schristos } else { 1188*946379e7Schristos $destdir = $1 . "dir"; 1189*946379e7Schristos } 1190*946379e7Schristos my $iconauto = ($2 =~ /AUTO\s*$/); 1191*946379e7Schristos my @appnames = (); 1192*946379e7Schristos if ( ! $iconauto ) { 1193*946379e7Schristos my $appicon_str = $2; 1194*946379e7Schristos my @_appnames = split(" ", $appicon_str); 1195*946379e7Schristos print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose); 1196*946379e7Schristos foreach $appname (@_appnames) { 1197*946379e7Schristos push(@appnames, quotemeta($appname)); 1198*946379e7Schristos } 1199*946379e7Schristos } else { 1200*946379e7Schristos print STDOUT "KDE_ICON processing <AUTO>\n" if ($verbose); 1201*946379e7Schristos } 1202*946379e7Schristos 1203*946379e7Schristos my @files = (); 1204*946379e7Schristos opendir (THISDIR, "."); 1205*946379e7Schristos foreach $entry (readdir(THISDIR)) { 1206*946379e7Schristos next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/); 1207*946379e7Schristos next if (! -f $entry); 1208*946379e7Schristos if ( $iconauto ) 1209*946379e7Schristos { 1210*946379e7Schristos push(@files, $entry) 1211*946379e7Schristos if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/ || $entry =~ /\.svg/); 1212*946379e7Schristos } else { 1213*946379e7Schristos foreach $appname (@appnames) { 1214*946379e7Schristos push(@files, $entry) 1215*946379e7Schristos if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/ || $entry =~ /-$appname\.svg/); 1216*946379e7Schristos } 1217*946379e7Schristos } 1218*946379e7Schristos } 1219*946379e7Schristos closedir (THISDIR); 1220*946379e7Schristos 1221*946379e7Schristos my %directories = (); 1222*946379e7Schristos 1223*946379e7Schristos foreach $file (@files) { 1224*946379e7Schristos my $newfile = $file; 1225*946379e7Schristos my $prefix = $file; 1226*946379e7Schristos $prefix =~ s/\.(png|xpm|mng|svg|svgz)$//; 1227*946379e7Schristos my $appname = $prefix; 1228*946379e7Schristos $appname =~ s/^[^-]+-// if ($appname =~ /-/) ; 1229*946379e7Schristos $appname =~ s/^[^-]+-// if ($appname =~ /-/) ; 1230*946379e7Schristos $appname = quotemeta($appname); 1231*946379e7Schristos $prefix =~ s/$appname$//; 1232*946379e7Schristos $prefix =~ s/-$//; 1233*946379e7Schristos 1234*946379e7Schristos $prefix = 'lo16-app' if ($prefix eq 'mini'); 1235*946379e7Schristos $prefix = 'lo32-app' if ($prefix eq 'lo'); 1236*946379e7Schristos $prefix = 'hi48-app' if ($prefix eq 'large'); 1237*946379e7Schristos $prefix .= '-app' if ($prefix =~ m/^...$/); 1238*946379e7Schristos 1239*946379e7Schristos my $type = $prefix; 1240*946379e7Schristos $type =~ s/^.*-([^-]+)$/$1/; 1241*946379e7Schristos $prefix =~ s/^(.*)-[^-]+$/$1/; 1242*946379e7Schristos 1243*946379e7Schristos my %type_hash = 1244*946379e7Schristos ( 1245*946379e7Schristos 'action' => 'actions', 1246*946379e7Schristos 'app' => 'apps', 1247*946379e7Schristos 'device' => 'devices', 1248*946379e7Schristos 'filesys' => 'filesystems', 1249*946379e7Schristos 'mime' => 'mimetypes' 1250*946379e7Schristos ); 1251*946379e7Schristos 1252*946379e7Schristos if (! defined $type_hash{$type} ) { 1253*946379e7Schristos print STDERR "unknown icon type $type in $printname ($file)\n"; 1254*946379e7Schristos next; 1255*946379e7Schristos } 1256*946379e7Schristos 1257*946379e7Schristos my %dir_hash = 1258*946379e7Schristos ( 1259*946379e7Schristos 'los' => 'locolor/16x16', 1260*946379e7Schristos 'lom' => 'locolor/32x32', 1261*946379e7Schristos 'him' => 'hicolor/32x32', 1262*946379e7Schristos 'hil' => 'hicolor/48x48', 1263*946379e7Schristos 'lo16' => 'locolor/16x16', 1264*946379e7Schristos 'lo22' => 'locolor/22x22', 1265*946379e7Schristos 'lo32' => 'locolor/32x32', 1266*946379e7Schristos 'hi16' => 'hicolor/16x16', 1267*946379e7Schristos 'hi22' => 'hicolor/22x22', 1268*946379e7Schristos 'hi32' => 'hicolor/32x32', 1269*946379e7Schristos 'hi48' => 'hicolor/48x48', 1270*946379e7Schristos 'hi64' => 'hicolor/64x64', 1271*946379e7Schristos 'hi128' => 'hicolor/128x128', 1272*946379e7Schristos 'hisc' => 'hicolor/scalable', 1273*946379e7Schristos 'cr16' => 'crystalsvg/16x16', 1274*946379e7Schristos 'cr22' => 'crystalsvg/22x22', 1275*946379e7Schristos 'cr32' => 'crystalsvg/32x32', 1276*946379e7Schristos 'cr48' => 'crystalsvg/48x48', 1277*946379e7Schristos 'cr64' => 'crystalsvg/64x64', 1278*946379e7Schristos 'cr128' => 'crystalsvg/128x128', 1279*946379e7Schristos 'crsc' => 'crystalsvg/scalable' 1280*946379e7Schristos ); 1281*946379e7Schristos 1282*946379e7Schristos $newfile =~ s@.*-($appname\.(png|xpm|mng|svgz|svg?))@$1@; 1283*946379e7Schristos 1284*946379e7Schristos if (! defined $dir_hash{$prefix}) { 1285*946379e7Schristos print STDERR "unknown icon prefix $prefix in $printname\n"; 1286*946379e7Schristos next; 1287*946379e7Schristos } 1288*946379e7Schristos 1289*946379e7Schristos my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type}; 1290*946379e7Schristos if ($newfile =~ /-[^\.]/) { 1291*946379e7Schristos my $tmp = $newfile; 1292*946379e7Schristos $tmp =~ s/^([^-]+)-.*$/$1/; 1293*946379e7Schristos $dir = $dir . "/" . $tmp; 1294*946379e7Schristos $newfile =~ s/^[^-]+-//; 1295*946379e7Schristos } 1296*946379e7Schristos 1297*946379e7Schristos if (!defined $directories{$dir}) { 1298*946379e7Schristos $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n"; 1299*946379e7Schristos $directories{$dir} = 1; 1300*946379e7Schristos } 1301*946379e7Schristos 1302*946379e7Schristos $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n"; 1303*946379e7Schristos $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n"; 1304*946379e7Schristos 1305*946379e7Schristos } 1306*946379e7Schristos } 1307*946379e7Schristos 1308*946379e7Schristos if (length($install)) { 1309*946379e7Schristos $target_adds{"install-data-am"} .= "install-kde-icons "; 1310*946379e7Schristos $target_adds{"uninstall-am"} .= "uninstall-kde-icons "; 1311*946379e7Schristos appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall); 1312*946379e7Schristos } 1313*946379e7Schristos} 1314*946379e7Schristos 1315*946379e7Schristossub handle_POFILES($$) 1316*946379e7Schristos{ 1317*946379e7Schristos my @pofiles = split(" ", $_[0]); 1318*946379e7Schristos my $lang = $_[1]; 1319*946379e7Schristos 1320*946379e7Schristos # Build rules for creating the gmo files 1321*946379e7Schristos my $tmp = ""; 1322*946379e7Schristos my $allgmofiles = ""; 1323*946379e7Schristos my $pofileLine = "POFILES ="; 1324*946379e7Schristos foreach $pofile (@pofiles) 1325*946379e7Schristos { 1326*946379e7Schristos $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension 1327*946379e7Schristos $tmp .= "$1.gmo: $pofile\n"; 1328*946379e7Schristos $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n"; 1329*946379e7Schristos $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n"; 1330*946379e7Schristos $allgmofiles .= " $1.gmo"; 1331*946379e7Schristos $pofileLine .= " $1.po"; 1332*946379e7Schristos } 1333*946379e7Schristos appendLines ($tmp); 1334*946379e7Schristos my $lookup = 'POFILES\s*=([^\n]*)'; 1335*946379e7Schristos if ($MakefileData !~ /\n$lookup/o) { 1336*946379e7Schristos appendLines("$pofileLine\nGMOFILES =$allgmofiles"); 1337*946379e7Schristos } else { 1338*946379e7Schristos substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles"); 1339*946379e7Schristos } 1340*946379e7Schristos 1341*946379e7Schristos if ($allgmofiles) { 1342*946379e7Schristos 1343*946379e7Schristos # Add the "clean" rule so that the maintainer-clean does something 1344*946379e7Schristos appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n"); 1345*946379e7Schristos 1346*946379e7Schristos $target_adds{"maintainer-clean"} .= "clean-nls "; 1347*946379e7Schristos 1348*946379e7Schristos $lookup = 'DISTFILES\s*=\s*(.*)'; 1349*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/o) { 1350*946379e7Schristos $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1"; 1351*946379e7Schristos substituteLine ($lookup, $tmp); 1352*946379e7Schristos } 1353*946379e7Schristos } 1354*946379e7Schristos 1355*946379e7Schristos $target_adds{"install-data-am"} .= "install-nls "; 1356*946379e7Schristos 1357*946379e7Schristos $tmp = "install-nls:\n"; 1358*946379e7Schristos if ($lang) { 1359*946379e7Schristos $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n"; 1360*946379e7Schristos } 1361*946379e7Schristos $tmp .= "\t\@for base in "; 1362*946379e7Schristos foreach $pofile (@pofiles) 1363*946379e7Schristos { 1364*946379e7Schristos $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension 1365*946379e7Schristos $tmp .= "$1 "; 1366*946379e7Schristos } 1367*946379e7Schristos 1368*946379e7Schristos $tmp .= "; do \\\n"; 1369*946379e7Schristos if ($lang) { 1370*946379e7Schristos $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; 1371*946379e7Schristos $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; 1372*946379e7Schristos $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; 1373*946379e7Schristos $tmp .= "\t fi ;\\\n"; 1374*946379e7Schristos } else { 1375*946379e7Schristos $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; 1376*946379e7Schristos $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n"; 1377*946379e7Schristos $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; 1378*946379e7Schristos $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; 1379*946379e7Schristos $tmp .= "\t fi ;\\\n"; 1380*946379e7Schristos } 1381*946379e7Schristos $tmp .= "\tdone\n\n"; 1382*946379e7Schristos appendLines ($tmp); 1383*946379e7Schristos 1384*946379e7Schristos $target_adds{"uninstall"} .= "uninstall-nls "; 1385*946379e7Schristos 1386*946379e7Schristos $tmp = "uninstall-nls:\n"; 1387*946379e7Schristos foreach $pofile (@pofiles) 1388*946379e7Schristos { 1389*946379e7Schristos $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension 1390*946379e7Schristos if ($lang) { 1391*946379e7Schristos $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n"; 1392*946379e7Schristos } else { 1393*946379e7Schristos $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n"; 1394*946379e7Schristos } 1395*946379e7Schristos } 1396*946379e7Schristos appendLines($tmp); 1397*946379e7Schristos 1398*946379e7Schristos $target_adds{"all"} .= "all-nls "; 1399*946379e7Schristos 1400*946379e7Schristos $tmp = "all-nls: \$(GMOFILES)\n"; 1401*946379e7Schristos 1402*946379e7Schristos appendLines($tmp); 1403*946379e7Schristos 1404*946379e7Schristos $target_adds{"distdir"} .= "distdir-nls "; 1405*946379e7Schristos 1406*946379e7Schristos $tmp = "distdir-nls:\$(GMOFILES)\n"; 1407*946379e7Schristos $tmp .= "\tfor file in \$(POFILES); do \\\n"; 1408*946379e7Schristos $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; 1409*946379e7Schristos $tmp .= "\tdone\n"; 1410*946379e7Schristos $tmp .= "\tfor file in \$(GMOFILES); do \\\n"; 1411*946379e7Schristos $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; 1412*946379e7Schristos $tmp .= "\tdone\n"; 1413*946379e7Schristos 1414*946379e7Schristos appendLines ($tmp); 1415*946379e7Schristos 1416*946379e7Schristos if (!$lang) { 1417*946379e7Schristos appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n"); 1418*946379e7Schristos } 1419*946379e7Schristos 1420*946379e7Schristos} 1421*946379e7Schristos 1422*946379e7Schristos#----------------------------------------------------------------------------- 1423*946379e7Schristos 1424*946379e7Schristos# Returns 0 if the line was processed - 1 otherwise. 1425*946379e7Schristos# Errors are logged in the global $errorflags 1426*946379e7Schristossub tag_POFILES () 1427*946379e7Schristos{ 1428*946379e7Schristos my $lookup = 'POFILES\s*=([^\n]*)'; 1429*946379e7Schristos return 1 if ($MakefileData !~ /\n$lookup/o); 1430*946379e7Schristos print STDOUT "POFILES processing <$1>\n" if ($verbose); 1431*946379e7Schristos 1432*946379e7Schristos my $tmp = $1; 1433*946379e7Schristos 1434*946379e7Schristos # make sure these are all gone. 1435*946379e7Schristos if ($MakefileData =~ /\n\.po\.gmo:\n/) 1436*946379e7Schristos { 1437*946379e7Schristos print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n"; 1438*946379e7Schristos return 1; 1439*946379e7Schristos } 1440*946379e7Schristos 1441*946379e7Schristos # Either find the pofiles in the directory (AUTO) or use 1442*946379e7Schristos # only the specified po files. 1443*946379e7Schristos my $pofiles = ""; 1444*946379e7Schristos if ($tmp =~ /^\s*AUTO\s*$/) 1445*946379e7Schristos { 1446*946379e7Schristos opendir (THISDIR, "."); 1447*946379e7Schristos $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR))); 1448*946379e7Schristos closedir (THISDIR); 1449*946379e7Schristos print STDOUT "pofiles found = $pofiles\n" if ($verbose); 1450*946379e7Schristos if (-f "charset" && -f "kdelibs.po") { 1451*946379e7Schristos handle_TOPLEVEL(); 1452*946379e7Schristos } 1453*946379e7Schristos } 1454*946379e7Schristos else 1455*946379e7Schristos { 1456*946379e7Schristos $tmp =~ s/\034/ /g; 1457*946379e7Schristos $pofiles = $tmp; 1458*946379e7Schristos } 1459*946379e7Schristos return 1 if (!$pofiles); # Nothing to do 1460*946379e7Schristos 1461*946379e7Schristos handle_POFILES($pofiles, $kdelang); 1462*946379e7Schristos 1463*946379e7Schristos return 0; 1464*946379e7Schristos} 1465*946379e7Schristos 1466*946379e7Schristossub helper_LOCALINSTALL($) 1467*946379e7Schristos{ 1468*946379e7Schristos my $lookup = "\035" . $_[0] . " *:[^\035]*\035\t"; 1469*946379e7Schristos my $copy = $MakefileData; 1470*946379e7Schristos $copy =~ s/\n/\035/g; 1471*946379e7Schristos if ($copy =~ /($lookup.*)$/) { 1472*946379e7Schristos 1473*946379e7Schristos $install = $1; 1474*946379e7Schristos $install =~ s/\035$_[0] *:[^\035]*\035//; 1475*946379e7Schristos my $emptyline = 0; 1476*946379e7Schristos while (! $emptyline ) { 1477*946379e7Schristos if ($install =~ /([^\035]*)\035(.*)/) { 1478*946379e7Schristos local $line = $1; 1479*946379e7Schristos $install = $2; 1480*946379e7Schristos if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) { 1481*946379e7Schristos $emptyline = 1; 1482*946379e7Schristos } else { 1483*946379e7Schristos replaceDestDir($line); 1484*946379e7Schristos } 1485*946379e7Schristos } else { 1486*946379e7Schristos $emptyline = 1; 1487*946379e7Schristos } 1488*946379e7Schristos } 1489*946379e7Schristos } 1490*946379e7Schristos 1491*946379e7Schristos} 1492*946379e7Schristos 1493*946379e7Schristossub tag_LOCALINSTALL () 1494*946379e7Schristos{ 1495*946379e7Schristos helper_LOCALINSTALL('install-exec-local'); 1496*946379e7Schristos helper_LOCALINSTALL('install-data-local'); 1497*946379e7Schristos helper_LOCALINSTALL('uninstall-local'); 1498*946379e7Schristos 1499*946379e7Schristos return 0; 1500*946379e7Schristos} 1501*946379e7Schristos 1502*946379e7Schristossub replaceDestDir($) { 1503*946379e7Schristos local $line = $_[0]; 1504*946379e7Schristos 1505*946379e7Schristos if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/ 1506*946379e7Schristos || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/ 1507*946379e7Schristos || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/) 1508*946379e7Schristos { 1509*946379e7Schristos $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/); 1510*946379e7Schristos } 1511*946379e7Schristos 1512*946379e7Schristos if ($line ne $_[0]) { 1513*946379e7Schristos $_[0] = quotemeta $_[0]; 1514*946379e7Schristos substituteLine($_[0], $line); 1515*946379e7Schristos } 1516*946379e7Schristos} 1517*946379e7Schristos 1518*946379e7Schristos#--------------------------------------------------------------------------- 1519*946379e7Schristossub tag_CLOSURE () { 1520*946379e7Schristos return if ($program !~ /_la$/); 1521*946379e7Schristos 1522*946379e7Schristos my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n"; 1523*946379e7Schristos $MakefileData =~ m/$lookup/; 1524*946379e7Schristos return if ($1 !~ /CXXLINK/); 1525*946379e7Schristos 1526*946379e7Schristos if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ && 1527*946379e7Schristos $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) { 1528*946379e7Schristos print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun); 1529*946379e7Schristos return; 1530*946379e7Schristos } 1531*946379e7Schristos 1532*946379e7Schristos my $closure = $realname{$program} . ".closure"; 1533*946379e7Schristos my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n"; 1534*946379e7Schristos $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n"; 1535*946379e7Schristos $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n"; 1536*946379e7Schristos $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n"; 1537*946379e7Schristos $lines .= "\t\@rm -f $program\_closure.* $closure\n"; 1538*946379e7Schristos $lines .= "\t\@echo \"timestamp\" > $closure\n"; 1539*946379e7Schristos $lines .= "\n"; 1540*946379e7Schristos appendLines($lines); 1541*946379e7Schristos $lookup = $realname{$program} . ": (.*)"; 1542*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/) { 1543*946379e7Schristos $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1"; 1544*946379e7Schristos $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1"; 1545*946379e7Schristos substituteLine($lookup, $lines); 1546*946379e7Schristos } 1547*946379e7Schristos $closure_output .= " $closure"; 1548*946379e7Schristos} 1549*946379e7Schristos 1550*946379e7Schristossub tag_DIST () { 1551*946379e7Schristos my %foundfiles = (); 1552*946379e7Schristos opendir (THISDIR, "."); 1553*946379e7Schristos foreach $entry (readdir(THISDIR)) { 1554*946379e7Schristos next if ($entry eq "CVS" || $entry =~ /^\./ || $entry eq "Makefile" || $entry =~ /~$/ || $entry =~ /^\#.*\#$/); 1555*946379e7Schristos next if (! -f $entry); 1556*946379e7Schristos next if ($entry =~ /\.moc/ || $entry =~ /\.moc.$cppExt$/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/); 1557*946379e7Schristos next if ($entry =~ /\.all_$cppExt\.$cppExt$/); 1558*946379e7Schristos $foundfiles{$entry} = 1; 1559*946379e7Schristos } 1560*946379e7Schristos closedir (THISDIR); 1561*946379e7Schristos 1562*946379e7Schristos # doing this for MAINTAINERCLEANFILES would be wrong 1563*946379e7Schristos my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS'); 1564*946379e7Schristos foreach $mark (@marks) { 1565*946379e7Schristos while ($MakefileData =~ /\n($mark)\s*=\s*([^\n]*)/g) { 1566*946379e7Schristos my $cleanfiles_str = $2; 1567*946379e7Schristos foreach $file (split('[\034\s]+', $cleanfiles_str)) { 1568*946379e7Schristos $file =~ s/\.\///; 1569*946379e7Schristos $foundfiles{$file} = 0 if (defined $foundfiles{$file}); 1570*946379e7Schristos } 1571*946379e7Schristos } 1572*946379e7Schristos } 1573*946379e7Schristos my @files = ("Makefile", "config.cache", "config.log", "stamp-h", 1574*946379e7Schristos "stamp-h1", "stamp-h1", "config.h", "Makefile", 1575*946379e7Schristos "config.status", "config.h", "libtool", "core" ); 1576*946379e7Schristos foreach $file (@files) { 1577*946379e7Schristos $foundfiles{$file} = 0 if (defined $foundfiles{$file}); 1578*946379e7Schristos } 1579*946379e7Schristos 1580*946379e7Schristos my $KDE_DIST = ""; 1581*946379e7Schristos foreach $file (keys %foundfiles) { 1582*946379e7Schristos if ($foundfiles{$file} == 1) { 1583*946379e7Schristos $KDE_DIST .= "$file "; 1584*946379e7Schristos } 1585*946379e7Schristos } 1586*946379e7Schristos if ($KDE_DIST) { 1587*946379e7Schristos print "KDE_DIST $printname $KDE_DIST\n" if ($verbose); 1588*946379e7Schristos 1589*946379e7Schristos my $lookup = "DISTFILES *=(.*)"; 1590*946379e7Schristos if ($MakefileData =~ /\n$lookup\n/o) { 1591*946379e7Schristos substituteLine($lookup, "KDE_DIST=$KDE_DIST\n\nDISTFILES=$1 \$(KDE_DIST)\n"); 1592*946379e7Schristos } 1593*946379e7Schristos } 1594*946379e7Schristos} 1595*946379e7Schristos 1596*946379e7Schristos#----------------------------------------------------------------------------- 1597*946379e7Schristos# Returns 0 if the line was processed - 1 otherwise. 1598*946379e7Schristos# Errors are logged in the global $errorflags 1599*946379e7Schristossub tag_DOCFILES () 1600*946379e7Schristos{ 1601*946379e7Schristos $target_adds{"all"} .= "docs-am "; 1602*946379e7Schristos 1603*946379e7Schristos my $lookup = 'KDE_DOCS\s*=\s*([^\n]*)'; 1604*946379e7Schristos goto nodocs if ($MakefileData !~ /\n$lookup/o); 1605*946379e7Schristos print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose); 1606*946379e7Schristos 1607*946379e7Schristos my $tmp = $1; 1608*946379e7Schristos 1609*946379e7Schristos # Either find the files in the directory (AUTO) or use 1610*946379e7Schristos # only the specified po files. 1611*946379e7Schristos my $files = ""; 1612*946379e7Schristos my $appname = $tmp; 1613*946379e7Schristos $appname =~ s/^(\S*)\s*.*$/$1/; 1614*946379e7Schristos if ($appname =~ /AUTO/) { 1615*946379e7Schristos $appname = basename($makefileDir); 1616*946379e7Schristos if ("$appname" eq "en") { 1617*946379e7Schristos print STDERR "Error: KDE_DOCS = AUTO relies on the directory name. Yours is 'en' - you most likely want something else, e.g. KDE_DOCS = myapp\n"; 1618*946379e7Schristos exit(1); 1619*946379e7Schristos } 1620*946379e7Schristos } 1621*946379e7Schristos 1622*946379e7Schristos if ($tmp !~ / - /) 1623*946379e7Schristos { 1624*946379e7Schristos opendir (THISDIR, "."); 1625*946379e7Schristos foreach $entry (readdir(THISDIR)) { 1626*946379e7Schristos next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry eq "core" || $entry eq "index.cache.bz2"); 1627*946379e7Schristos next if (! -f $entry); 1628*946379e7Schristos $files .= "$entry "; 1629*946379e7Schristos } 1630*946379e7Schristos closedir (THISDIR); 1631*946379e7Schristos print STDOUT "docfiles found = $files\n" if ($verbose); 1632*946379e7Schristos } 1633*946379e7Schristos else 1634*946379e7Schristos { 1635*946379e7Schristos $tmp =~ s/\034/ /g; 1636*946379e7Schristos $tmp =~ s/^\S*\s*-\s*//; 1637*946379e7Schristos $files = $tmp; 1638*946379e7Schristos } 1639*946379e7Schristos goto nodocs if (!$files); # Nothing to do 1640*946379e7Schristos 1641*946379e7Schristos if ($files =~ /(^| )index\.docbook($| )/) { 1642*946379e7Schristos 1643*946379e7Schristos my $lines = ""; 1644*946379e7Schristos my $lookup = 'MEINPROC\s*='; 1645*946379e7Schristos if ($MakefileData !~ /\n($lookup)/) { 1646*946379e7Schristos $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n"; 1647*946379e7Schristos } 1648*946379e7Schristos $lookup = 'KDE_XSL_STYLESHEET\s*='; 1649*946379e7Schristos if ($MakefileData !~ /\n($lookup)/) { 1650*946379e7Schristos $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n"; 1651*946379e7Schristos } 1652*946379e7Schristos $lookup = '\nindex.cache.bz2:'; 1653*946379e7Schristos if ($MakefileData !~ /\n($lookup)/) { 1654*946379e7Schristos $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n"; 1655*946379e7Schristos $lines .= "\t\@if test -n \"\$(MEINPROC)\"; then echo \$(MEINPROC) --check --cache index.cache.bz2 \$(srcdir)/index.docbook; \$(MEINPROC) --check --cache index.cache.bz2 \$(srcdir)/index.docbook || true; fi\n"; 1656*946379e7Schristos $lines .= "\n"; 1657*946379e7Schristos } 1658*946379e7Schristos 1659*946379e7Schristos $lines .= "docs-am: index.cache.bz2\n"; 1660*946379e7Schristos $lines .= "\n"; 1661*946379e7Schristos $lines .= "install-docs: docs-am install-nls\n"; 1662*946379e7Schristos $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n"; 1663*946379e7Schristos $lines .= "\t\@if test -f index.cache.bz2; then \\\n"; 1664*946379e7Schristos $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; 1665*946379e7Schristos $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; 1666*946379e7Schristos $lines .= "\telif test -f \$(srcdir)/index.cache.bz2; then \\\n"; 1667*946379e7Schristos $lines .= "\techo \$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; 1668*946379e7Schristos $lines .= "\t\$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; 1669*946379e7Schristos $lines .= "\tfi\n"; 1670*946379e7Schristos $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n"; 1671*946379e7Schristos $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n"; 1672*946379e7Schristos 1673*946379e7Schristos $lines .= "\n"; 1674*946379e7Schristos $lines .= "uninstall-docs:\n"; 1675*946379e7Schristos $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n"; 1676*946379e7Schristos $lines .= "\n"; 1677*946379e7Schristos $lines .= "clean-docs:\n"; 1678*946379e7Schristos $lines .= "\t-rm -f index.cache.bz2\n"; 1679*946379e7Schristos $lines .= "\n"; 1680*946379e7Schristos $target_adds{"install-data-am"} .= "install-docs "; 1681*946379e7Schristos $target_adds{"uninstall"} .= "uninstall-docs "; 1682*946379e7Schristos $target_adds{"clean-am"} .= "clean-docs "; 1683*946379e7Schristos appendLines ($lines); 1684*946379e7Schristos } else { 1685*946379e7Schristos appendLines("docs-am: $files\n"); 1686*946379e7Schristos } 1687*946379e7Schristos 1688*946379e7Schristos $target_adds{"install-data-am"} .= "install-nls "; 1689*946379e7Schristos $target_adds{"uninstall"} .= "uninstall-nls "; 1690*946379e7Schristos 1691*946379e7Schristos $tmp = "install-nls:\n"; 1692*946379e7Schristos $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n"; 1693*946379e7Schristos $tmp .= "\t\@for base in $files; do \\\n"; 1694*946379e7Schristos $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; 1695*946379e7Schristos $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; 1696*946379e7Schristos $tmp .= "\tdone\n"; 1697*946379e7Schristos if ($appname eq 'common') { 1698*946379e7Schristos $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n"; 1699*946379e7Schristos $tmp .= "\tif test ! -f \$(kde_htmldir)/en/common/kde-common.css; then echo 'no english docs found in \$(kde_htmldir)/en/common/'; exit 1; fi \n"; 1700*946379e7Schristos $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n"; 1701*946379e7Schristos $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n"; 1702*946379e7Schristos $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n"; 1703*946379e7Schristos $tmp .= "\t case \" $files \" in \\\n"; 1704*946379e7Schristos $tmp .= "\t *\" \$\$p \"*) ;; \\\n"; 1705*946379e7Schristos $tmp .= "\t *) test ! -f \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n"; 1706*946379e7Schristos $tmp .= "\t esac ; \\\n"; 1707*946379e7Schristos $tmp .= "\tdone ; fi ; true\n"; 1708*946379e7Schristos } 1709*946379e7Schristos $tmp .= "\n"; 1710*946379e7Schristos $tmp .= "uninstall-nls:\n"; 1711*946379e7Schristos $tmp .= "\tfor base in $files; do \\\n"; 1712*946379e7Schristos $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; 1713*946379e7Schristos $tmp .= "\tdone\n\n"; 1714*946379e7Schristos appendLines ($tmp); 1715*946379e7Schristos 1716*946379e7Schristos $target_adds{"distdir"} .= "distdir-nls "; 1717*946379e7Schristos 1718*946379e7Schristos $tmp = "distdir-nls:\n"; 1719*946379e7Schristos $tmp .= "\tfor file in $files; do \\\n"; 1720*946379e7Schristos $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; 1721*946379e7Schristos $tmp .= "\tdone\n"; 1722*946379e7Schristos 1723*946379e7Schristos appendLines ($tmp); 1724*946379e7Schristos 1725*946379e7Schristos return 0; 1726*946379e7Schristos 1727*946379e7Schristos nodocs: 1728*946379e7Schristos appendLines("docs-am:\n"); 1729*946379e7Schristos return 1; 1730*946379e7Schristos} 1731*946379e7Schristos 1732*946379e7Schristos#----------------------------------------------------------------------------- 1733*946379e7Schristos# Find headers in any of the source directories specified previously, that 1734*946379e7Schristos# are candidates for "moc-ing". 1735*946379e7Schristossub findMocCandidates () 1736*946379e7Schristos{ 1737*946379e7Schristos foreach $dir (@headerdirs) 1738*946379e7Schristos { 1739*946379e7Schristos my @list = (); 1740*946379e7Schristos opendir (SRCDIR, "$dir"); 1741*946379e7Schristos @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR); 1742*946379e7Schristos closedir SRCDIR; 1743*946379e7Schristos foreach $hf (@hFiles) 1744*946379e7Schristos { 1745*946379e7Schristos next if ($hf =~ /^\.\#/); 1746*946379e7Schristos $hf =~ /(.*)\.[^\.]*$/; # Find name minus extension 1747*946379e7Schristos next if ($uiFiles{$1}); 1748*946379e7Schristos open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n"; 1749*946379e7Schristos my $hfsize = 0; 1750*946379e7Schristos seek(HFIN, 0, 2); 1751*946379e7Schristos $hfsize = tell(HFIN); 1752*946379e7Schristos seek(HFIN, 0, 0); 1753*946379e7Schristos read HFIN, $hfData, $hfsize; 1754*946379e7Schristos close HFIN; 1755*946379e7Schristos # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT 1756*946379e7Schristos # handle " { friend class blah; Q_OBJECT ", but don't match antlarr_Q_OBJECT (\b). 1757*946379e7Schristos if ( $hfData =~ /{([^}]*)\bQ_OBJECT/s ) { 1758*946379e7Schristos push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## reject "// Q_OBJECT" 1759*946379e7Schristos } 1760*946379e7Schristos } 1761*946379e7Schristos # The assoc array of root of headerfile and header filename 1762*946379e7Schristos foreach $hFile (@list) 1763*946379e7Schristos { 1764*946379e7Schristos $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension 1765*946379e7Schristos if ($mocFiles{$1}) 1766*946379e7Schristos { 1767*946379e7Schristos print STDERR "Warning: Multiple header files found for $1\n"; 1768*946379e7Schristos next; # Use the first one 1769*946379e7Schristos } 1770*946379e7Schristos $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir 1771*946379e7Schristos } 1772*946379e7Schristos } 1773*946379e7Schristos 1774*946379e7Schristos return 0; 1775*946379e7Schristos} 1776*946379e7Schristos 1777*946379e7Schristos#----------------------------------------------------------------------------- 1778*946379e7Schristos 1779*946379e7Schristos# The programmer has specified a moc list. Prune out the moc candidates 1780*946379e7Schristos# list that we found based on looking at the header files. This generates 1781*946379e7Schristos# a warning if the programmer gets the list wrong, but this doesn't have 1782*946379e7Schristos# to be fatal here. 1783*946379e7Schristossub pruneMocCandidates ($) 1784*946379e7Schristos{ 1785*946379e7Schristos my %prunedMoc = (); 1786*946379e7Schristos local @mocList = split(' ', $_[0]); 1787*946379e7Schristos 1788*946379e7Schristos foreach $mocname (@mocList) 1789*946379e7Schristos { 1790*946379e7Schristos $mocname =~ s/\.moc$//; 1791*946379e7Schristos if ($mocFiles{$mocname}) 1792*946379e7Schristos { 1793*946379e7Schristos $prunedMoc{$mocname} = $mocFiles{$mocname}; 1794*946379e7Schristos } 1795*946379e7Schristos else 1796*946379e7Schristos { 1797*946379e7Schristos my $print = $makefileDir; 1798*946379e7Schristos $print =~ s/^\Q$topdir\E\\//; 1799*946379e7Schristos # They specified a moc file but we can't find a header that 1800*946379e7Schristos # will generate this moc file. That's possible fatal! 1801*946379e7Schristos print STDERR "Warning: No moc-able header file for $print/$mocname\n"; 1802*946379e7Schristos } 1803*946379e7Schristos } 1804*946379e7Schristos 1805*946379e7Schristos undef %mocFiles; 1806*946379e7Schristos %mocFiles = %prunedMoc; 1807*946379e7Schristos} 1808*946379e7Schristos 1809*946379e7Schristos#----------------------------------------------------------------------------- 1810*946379e7Schristos 1811*946379e7Schristos# Finds the cpp files (If they exist). 1812*946379e7Schristos# The cpp files get appended to the header file separated by \035 1813*946379e7Schristossub checkMocCandidates () 1814*946379e7Schristos{ 1815*946379e7Schristos my @cppFiles; 1816*946379e7Schristos my $cpp2moc; # which c++ file includes which .moc files 1817*946379e7Schristos my $moc2cpp; # which moc file is included by which c++ files 1818*946379e7Schristos 1819*946379e7Schristos return unless (keys %mocFiles); 1820*946379e7Schristos opendir(THISDIR, ".") || return; 1821*946379e7Schristos @cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o 1822*946379e7Schristos && !/.+\.all_$cppExt\.$cppExt$/o 1823*946379e7Schristos && !/^\./ } readdir(THISDIR); 1824*946379e7Schristos closedir THISDIR; 1825*946379e7Schristos return unless (@cppFiles); 1826*946379e7Schristos my $files = join (" ", @cppFiles); 1827*946379e7Schristos $cpp2moc = {}; 1828*946379e7Schristos $moc2cpp = {}; 1829*946379e7Schristos foreach $cxxf (@cppFiles) 1830*946379e7Schristos { 1831*946379e7Schristos open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n"; 1832*946379e7Schristos seek(CXXFIN, 0, 2); 1833*946379e7Schristos my $cxxfsize = tell(CXXFIN); 1834*946379e7Schristos seek(CXXFIN, 0, 0); 1835*946379e7Schristos read CXXFIN, $cxxfData, $cxxfsize; 1836*946379e7Schristos close CXXFIN; 1837*946379e7Schristos while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) { 1838*946379e7Schristos $cpp2moc->{$cxxf}->{$1} = 1; 1839*946379e7Schristos $moc2cpp->{$1}->{$cxxf} = 1; 1840*946379e7Schristos } 1841*946379e7Schristos } 1842*946379e7Schristos foreach my $mocFile (keys (%mocFiles)) 1843*946379e7Schristos { 1844*946379e7Schristos @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}}; 1845*946379e7Schristos if (@cppFiles == 1) { 1846*946379e7Schristos $mocFiles{$mocFile} .= "\035" . $cppFiles[0]; 1847*946379e7Schristos push(@deped, $mocFile); 1848*946379e7Schristos } elsif (@cppFiles == 0) { 1849*946379e7Schristos push (@newObs, $mocFile); # Produce new object file 1850*946379e7Schristos next if ($haveAutomocTag); # This is expected... 1851*946379e7Schristos # But this is an error we can deal with - let them know 1852*946379e7Schristos print STDERR 1853*946379e7Schristos "Warning: No c++ file that includes $mocFile.moc\n"; 1854*946379e7Schristos } else { 1855*946379e7Schristos # We can't decide which file to use, so it's fatal. Although as a 1856*946379e7Schristos # guess we could use the mocFile.cpp file if it's in the list??? 1857*946379e7Schristos print STDERR 1858*946379e7Schristos "Error: Multiple c++ files that include $mocFile.moc\n"; 1859*946379e7Schristos print STDERR "\t",join ("\t", @cppFiles),"\n"; 1860*946379e7Schristos $errorflag = 1; 1861*946379e7Schristos delete $mocFiles{$mocFile}; 1862*946379e7Schristos # Let's continue and see what happens - They have been told! 1863*946379e7Schristos } 1864*946379e7Schristos } 1865*946379e7Schristos} 1866*946379e7Schristos 1867*946379e7Schristos#----------------------------------------------------------------------------- 1868*946379e7Schristos 1869*946379e7Schristos# Add the rules for generating moc source from header files 1870*946379e7Schristos# For Automoc output *.moc.cpp but normally we'll output *.moc 1871*946379e7Schristos# (We must compile *.moc.cpp separately. *.moc files are included 1872*946379e7Schristos# in the appropriate *.cpp file by the programmer) 1873*946379e7Schristossub addMocRules () 1874*946379e7Schristos{ 1875*946379e7Schristos my $cppFile; 1876*946379e7Schristos my $hFile; 1877*946379e7Schristos 1878*946379e7Schristos foreach $mocFile (keys (%mocFiles)) 1879*946379e7Schristos { 1880*946379e7Schristos undef $cppFile; 1881*946379e7Schristos ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3); 1882*946379e7Schristos $dir =~ s#^\.#\$(srcdir)#; 1883*946379e7Schristos if (defined ($cppFile)) 1884*946379e7Schristos { 1885*946379e7Schristos $cppFile =~ s,\.[^.]*$,,; 1886*946379e7Schristos $target_adds{"$cppFile.o"} .= "$mocFile.moc "; 1887*946379e7Schristos $target_adds{"$cppFile.lo"} .= "$mocFile.moc "; 1888*946379e7Schristos appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n"); 1889*946379e7Schristos $cleanMoc .= " $mocFile.moc"; 1890*946379e7Schristos appendLines ("mocs: $mocFile.moc"); 1891*946379e7Schristos } 1892*946379e7Schristos else 1893*946379e7Schristos { 1894*946379e7Schristos appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n"); 1895*946379e7Schristos $cleanMoc .= " $mocFile$mocExt"; 1896*946379e7Schristos appendLines ("mocs: $mocFile$mocExt"); 1897*946379e7Schristos } 1898*946379e7Schristos } 1899*946379e7Schristos} 1900*946379e7Schristos 1901*946379e7Schristossub make_meta_classes () 1902*946379e7Schristos{ 1903*946379e7Schristos return if ($kdeopts{"qtonly"}); 1904*946379e7Schristos 1905*946379e7Schristos my $cppFile; 1906*946379e7Schristos my $hFile; 1907*946379e7Schristos my $moc_class_headers = ""; 1908*946379e7Schristos foreach $program (@programs) { 1909*946379e7Schristos my $mocs = ""; 1910*946379e7Schristos my @progsources = split(/[\034\s]+/, $sources{$program}); 1911*946379e7Schristos my @depmocs = split(' ', $depedmocs{$program}); 1912*946379e7Schristos my %shash = (), %mhash = (); 1913*946379e7Schristos @shash{@progsources} = 1; # we are only interested in the existence 1914*946379e7Schristos @mhash{@depmocs} = 1; 1915*946379e7Schristos 1916*946379e7Schristos print STDOUT "program=$program\n" if ($verbose); 1917*946379e7Schristos print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose); 1918*946379e7Schristos print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose); 1919*946379e7Schristos print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose); 1920*946379e7Schristos foreach my $mocFile (keys (%globalmocs)) 1921*946379e7Schristos { 1922*946379e7Schristos my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3); 1923*946379e7Schristos if (defined ($cppFile)) 1924*946379e7Schristos { 1925*946379e7Schristos $mocs .= " $mocFile.moc" if exists $shash{$cppFile}; 1926*946379e7Schristos } 1927*946379e7Schristos else 1928*946379e7Schristos { 1929*946379e7Schristos # Bah. This is the case, if no C++ file includes the .moc 1930*946379e7Schristos # file. We make a .moc.cpp file for that. Unfortunately this 1931*946379e7Schristos # is not included in the %sources hash, but rather is mentioned 1932*946379e7Schristos # in %depedmocs. If the user wants to use AUTO he can't just 1933*946379e7Schristos # use an unspecific METAINCLUDES. Instead he must use 1934*946379e7Schristos # program_METAINCLUDES. Anyway, it's not working real nicely. 1935*946379e7Schristos # E.g. Its not clear what happens if user specifies two 1936*946379e7Schristos # METAINCLUDES=AUTO in the same Makefile.am. 1937*946379e7Schristos $mocs .= " $mocFile.moc.$cxxsuffix" 1938*946379e7Schristos if exists $mhash{$mocFile.".moc.$cxxsuffix"}; 1939*946379e7Schristos } 1940*946379e7Schristos } 1941*946379e7Schristos if ($mocs) { 1942*946379e7Schristos print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose); 1943*946379e7Schristos } 1944*946379e7Schristos print STDOUT "\n" if $verbose; 1945*946379e7Schristos } 1946*946379e7Schristos if ($moc_class_headers) { 1947*946379e7Schristos appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n"); 1948*946379e7Schristos $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes "; 1949*946379e7Schristos } 1950*946379e7Schristos} 1951*946379e7Schristos 1952*946379e7Schristos#----------------------------------------------------------------------------- 1953*946379e7Schristos 1954*946379e7Schristossub updateMakefile () 1955*946379e7Schristos{ 1956*946379e7Schristos return if ($dryrun); 1957*946379e7Schristos 1958*946379e7Schristos open (FILEOUT, "> $makefile") 1959*946379e7Schristos || die "Could not create $makefile: $!\n"; 1960*946379e7Schristos 1961*946379e7Schristos $MakefileData =~ s/\034/\\\n/g; # Restore continuation lines 1962*946379e7Schristos # Append our $progId line, _below_ the "generated by automake" line 1963*946379e7Schristos # because automake-1.6 relies on the first line to be his own. 1964*946379e7Schristos my $progIdLine = "\# $progId - " . 'Revision: 1.349.2.6 '."\n"; 1965*946379e7Schristos if ( !( $MakefileData =~ s/^(.*generated .*by automake.*\n)/$1$progIdLine/ ) ) { 1966*946379e7Schristos warn "automake line not found in $makefile\n"; 1967*946379e7Schristos # Fallback: first line 1968*946379e7Schristos print FILEOUT $progIdLine; 1969*946379e7Schristos }; 1970*946379e7Schristos print FILEOUT $MakefileData; 1971*946379e7Schristos close FILEOUT; 1972*946379e7Schristos} 1973*946379e7Schristos 1974*946379e7Schristos#----------------------------------------------------------------------------- 1975*946379e7Schristos 1976*946379e7Schristos# The given line needs to be removed from the makefile 1977*946379e7Schristos# Do this by adding the special "removed line" comment at the line start. 1978*946379e7Schristossub removeLine ($$) 1979*946379e7Schristos{ 1980*946379e7Schristos my ($lookup, $old) = @_; 1981*946379e7Schristos 1982*946379e7Schristos $old =~ s/\034/\\\n#>- /g; # Fix continuation lines 1983*946379e7Schristos $MakefileData =~ s/\n$lookup/\n#>\- $old/; 1984*946379e7Schristos} 1985*946379e7Schristos 1986*946379e7Schristos#----------------------------------------------------------------------------- 1987*946379e7Schristos 1988*946379e7Schristos# Replaces the old line with the new line 1989*946379e7Schristos# old line(s) are retained but tagged as removed. The new line(s) have the 1990*946379e7Schristos# "added" tag placed before it. 1991*946379e7Schristossub substituteLine ($$) 1992*946379e7Schristos{ 1993*946379e7Schristos my ($lookup, $new) = @_; 1994*946379e7Schristos 1995*946379e7Schristos if ($MakefileData =~ /\n($lookup)/) { 1996*946379e7Schristos $old = $1; 1997*946379e7Schristos $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines 1998*946379e7Schristos my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1; 1999*946379e7Schristos $new =~ s/\\\n/\034/g; 2000*946379e7Schristos $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/; 2001*946379e7Schristos } else { 2002*946379e7Schristos print STDERR "Warning: substitution of \"$lookup\" in $printname failed\n"; 2003*946379e7Schristos } 2004*946379e7Schristos} 2005*946379e7Schristos 2006*946379e7Schristos#----------------------------------------------------------------------------- 2007*946379e7Schristos 2008*946379e7Schristos# Slap new lines on the back of the file. 2009*946379e7Schristossub appendLines ($) 2010*946379e7Schristos{ 2011*946379e7Schristos my ($new) = @_; 2012*946379e7Schristos my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1; 2013*946379e7Schristos $new =~ s/\\\n/\034/g; # Fix continuation lines 2014*946379e7Schristos $MakefileData .= "\n#>\+ $newCount\n$new"; 2015*946379e7Schristos} 2016*946379e7Schristos 2017*946379e7Schristos#----------------------------------------------------------------------------- 2018*946379e7Schristos 2019*946379e7Schristos# Restore the Makefile.in to the state it was before we fiddled with it 2020*946379e7Schristossub restoreMakefile () 2021*946379e7Schristos{ 2022*946379e7Schristos $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g; 2023*946379e7Schristos # Restore removed lines 2024*946379e7Schristos $MakefileData =~ s/([\n\034])#>\- /$1/g; 2025*946379e7Schristos # Remove added lines 2026*946379e7Schristos while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/) 2027*946379e7Schristos { 2028*946379e7Schristos my $newCount = $1; 2029*946379e7Schristos my $removeLines = ""; 2030*946379e7Schristos while ($newCount--) { 2031*946379e7Schristos $removeLines .= "[^\n\034]*([\n\034]|)"; 2032*946379e7Schristos } 2033*946379e7Schristos $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/; 2034*946379e7Schristos } 2035*946379e7Schristos} 2036*946379e7Schristos 2037*946379e7Schristos#----------------------------------------------------------------------------- 2038