joachim99@2: #!/usr/bin/perl -w joachim99@2: joachim99@2: # Expands the specialised KDE tags in Makefile.in to (hopefully) valid joachim99@2: # make syntax. joachim99@2: # When called without file parameters, we work recursively on all Makefile.in joachim99@2: # in and below the current subdirectory. When called with file parameters, joachim99@2: # only those Makefile.in are changed. joachim99@2: # The currently supported tags are joachim99@2: # joachim99@2: # {program}_METASOURCES joachim99@2: # where you have a choice of two styles joachim99@2: # {program}_METASOURCES = name1.moc name2.moc ... [\] joachim99@2: # {program}_METASOURCES = AUTO joachim99@2: # The second style requires other tags as well. joachim99@2: # joachim99@2: # To install icons : joachim99@2: # KDE_ICON = iconname iconname2 ... joachim99@2: # KDE_ICON = AUTO joachim99@2: # joachim99@2: # For documentation : joachim99@14: # http://developer.kde.org/documentation/other/developer-faq.html joachim99@2: # joachim99@2: # and more new tags TBD! joachim99@2: # joachim99@2: # The concept (and base code) for this program came from automoc, joachim99@2: # supplied by the following joachim99@2: # joachim99@2: # Matthias Ettrich (The originator) joachim99@2: # Kalle Dalheimer (The original implementator) joachim99@2: # Harri Porten joachim99@2: # Alex Zepeda joachim99@2: # David Faure joachim99@2: # Stephan Kulow joachim99@14: # Dirk Mueller joachim99@2: joachim99@2: use Cwd; joachim99@2: use File::Find; joachim99@2: use File::Basename; joachim99@2: joachim99@2: # Prototype the functions joachim99@2: sub initialise (); joachim99@2: sub processMakefile ($); joachim99@2: sub updateMakefile (); joachim99@2: sub restoreMakefile (); joachim99@2: joachim99@2: sub removeLine ($$); joachim99@2: sub appendLines ($); joachim99@2: sub substituteLine ($$); joachim99@2: joachim99@2: sub findMocCandidates (); joachim99@2: sub pruneMocCandidates ($); joachim99@2: sub checkMocCandidates (); joachim99@2: sub addMocRules (); joachim99@2: joachim99@2: sub tag_AUTOMAKE (); joachim99@2: sub tag_META_INCLUDES (); joachim99@2: sub tag_METASOURCES (); joachim99@2: sub tag_POFILES (); joachim99@2: sub tag_DOCFILES (); joachim99@2: sub tag_LOCALINSTALL(); joachim99@2: sub tag_IDLFILES(); joachim99@2: sub tag_UIFILES(); joachim99@2: sub tag_SUBDIRS(); joachim99@2: sub tag_ICON(); joachim99@2: sub tag_CLOSURE(); joachim99@14: sub tag_NO_UNDEFINED(); joachim99@14: sub tag_NMCHECK(); joachim99@2: sub tag_DIST(); joachim99@14: sub tag_KDEINIT(); joachim99@2: joachim99@2: # Some global globals... joachim99@2: $verbose = 0; # a debug flag joachim99@2: $thisProg = "$0"; # This programs name joachim99@2: $topdir = cwd(); # The current directory joachim99@2: @makefiles = (); # Contains all the files we'll process joachim99@2: @foreignfiles = (); joachim99@2: $start = (times)[0]; # some stats for testing - comment out for release joachim99@2: $version = "v0.2"; joachim99@2: $errorflag = 0; joachim99@2: $cppExt = "(cpp|cc|cxx|C|c\\+\\+)"; joachim99@2: $hExt = "(h|H|hh|hxx|hpp|h\\+\\+)"; joachim99@2: $progId = "KDE tags expanded automatically by " . basename($thisProg); joachim99@2: $automkCall = "\n"; joachim99@2: $printname = ""; # used to display the directory the Makefile is in joachim99@2: $use_final = 1; # create code for --enable-final joachim99@2: $cleantarget = "clean"; joachim99@2: $dryrun = 0; joachim99@2: $pathoption = 0; joachim99@2: $foreign_libtool = 0; joachim99@2: joachim99@2: while (defined ($ARGV[0])) joachim99@2: { joachim99@2: $_ = shift; joachim99@2: if (/^--version$/) joachim99@2: { joachim99@2: print STDOUT "\n"; joachim99@2: print STDOUT basename($thisProg), " $version\n", joachim99@2: "This is really free software, unencumbered by the GPL.\n", joachim99@2: "You can do anything you like with it except sueing me.\n", joachim99@2: "Copyright 1998 Kalle Dalheimer \n", joachim99@2: "Concept, design and unnecessary questions about perl\n", joachim99@2: " by Matthias Ettrich \n\n", joachim99@2: "Making it useful by Stephan Kulow and\n", joachim99@2: "Harri Porten \n", joachim99@2: "Updated (Feb-1999), John Birch \n", joachim99@14: "Fixes and Improvements by Dirk Mueller \n", joachim99@2: "Current Maintainer Stephan Kulow\n\n"; joachim99@2: exit 0; joachim99@2: } joachim99@2: elsif (/^--verbose$|^-v$/) joachim99@2: { joachim99@2: $verbose = 1; # Oh is there a problem...? joachim99@2: } joachim99@2: elsif (/^-p(.+)$|^--path=(.+)$/) joachim99@2: { joachim99@2: $thisProg = "$1/".basename($thisProg) if($1); joachim99@2: $thisProg = "$2/".basename($thisProg) if($2); joachim99@2: warn ("$thisProg doesn't exist\n") if (!(-f $thisProg)); joachim99@2: $pathoption=1; joachim99@2: } joachim99@2: elsif (/^--help$|^-h$/) joachim99@2: { joachim99@2: print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n", joachim99@2: "\n", joachim99@14: "Patches dir/Makefile.in generated by automake\n", joachim99@14: "(where dir can be an absolute or relative directory name)\n", joachim99@2: "\n", joachim99@2: " -v, --verbose verbosely list files processed\n", joachim99@2: " -h, --help print this help, then exit\n", joachim99@2: " --version print version number, then exit\n", joachim99@2: " -p, --path= use the path to am_edit if the path\n", joachim99@14: " called from is not the one to be used\n", joachim99@14: " --no-final don't patch for --enable-final\n"; joachim99@2: joachim99@2: exit 0; joachim99@2: } joachim99@2: elsif (/^--no-final$/) joachim99@2: { joachim99@2: $use_final = 0; joachim99@2: $thisProg .= " --no-final"; joachim99@2: } joachim99@2: elsif (/^--foreign-libtool$/) joachim99@2: { joachim99@2: $foreign_libtool = 1; joachim99@2: $thisProg .= " --foreign-libtool"; joachim99@2: } joachim99@2: elsif (/^-n$/) joachim99@2: { joachim99@2: $dryrun = 1; joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: # user selects what input files to check joachim99@2: # add full path if relative path is given joachim99@2: $_ = cwd()."/".$_ if (! /^\//); joachim99@2: print "User wants $_\n" if ($verbose); joachim99@2: push (@makefiles, $_); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if ($thisProg =~ /^\// && !$pathoption ) joachim99@2: { joachim99@2: print STDERR "Illegal full pathname call performed...\n", joachim99@2: "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n", joachim99@2: "Please use option --path.\n"; joachim99@2: exit 1; joachim99@2: } joachim99@2: joachim99@2: # Only scan for files when the user hasn't entered data joachim99@2: if (!@makefiles) joachim99@2: { joachim99@2: print STDOUT "Scanning for Makefile.in\n" if ($verbose); joachim99@2: find (\&add_makefile, cwd()); joachim99@2: #chdir('$topdir'); joachim99@2: } else { joachim99@14: print STDOUT "Using input files specified by user\n" if ($verbose); joachim99@2: } joachim99@2: joachim99@2: foreach $makefile (sort(@makefiles)) joachim99@2: { joachim99@2: processMakefile ($makefile); joachim99@2: last if ($errorflag); joachim99@2: } joachim99@2: joachim99@2: # Just some debug statistics - comment out for release as it uses printf. joachim99@2: printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose); joachim99@2: joachim99@2: exit $errorflag; # causes make to fail if erroflag is set joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # In conjunction with the "find" call, this builds the list of input files joachim99@2: sub add_makefile () joachim99@2: { joachim99@2: push (@makefiles, $File::Find::name) if (/Makefile.in$/); joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Processes a single make file joachim99@2: # The parameter contains the full path name of the Makefile.in to use joachim99@2: sub processMakefile ($) joachim99@2: { joachim99@2: # some useful globals for the subroutines called here joachim99@2: local ($makefile) = @_; joachim99@2: local @headerdirs = ('.'); joachim99@2: local $haveAutomocTag = 0; joachim99@2: local $MakefileData = ""; joachim99@2: joachim99@2: local $cxxsuffix = "KKK"; joachim99@2: joachim99@2: local @programs = (); # lists the names of programs and libraries joachim99@2: local $program = ""; joachim99@2: joachim99@14: local @kdeinits = (); # lists the kdeinit targets joachim99@14: joachim99@2: local %realObjs = (); # lists the objects compiled into $program joachim99@2: local %sources = (); # lists the sources used for $program joachim99@2: local %finalObjs = (); # lists the objects compiled when final joachim99@2: local %realname = (); # the binary name of program variable joachim99@2: local %idlfiles = (); # lists the idl files used for $program joachim99@2: local %globalmocs = ();# list of all mocfiles (in %mocFiles format) joachim99@2: local %important = (); # list of files to be generated asap joachim99@2: local %uiFiles = (); joachim99@2: joachim99@2: local $allidls = ""; joachim99@2: local $idl_output = "";# lists all idl generated files for cleantarget joachim99@2: local $ui_output = "";# lists all uic generated files for cleantarget joachim99@2: joachim99@14: local %dependmocs = (); joachim99@2: joachim99@2: local $metasourceTags = 0; joachim99@2: local $dep_files = ""; joachim99@2: local $dep_finals = ""; joachim99@2: local %target_adds = (); # the targets to add joachim99@14: local %rule_adds = (); joachim99@2: local $kdelang = ""; joachim99@2: local @cleanfiles = (); joachim99@2: local $cleanMoc = ""; joachim99@2: local $closure_output = ""; joachim99@2: joachim99@14: local %varcontent = (); joachim99@14: joachim99@2: $makefileDir = dirname($makefile); joachim99@2: chdir ($makefileDir); joachim99@2: $printname = $makefile; joachim99@2: $printname =~ s/^\Q$topdir\E\///; joachim99@2: $makefile = basename($makefile); joachim99@2: joachim99@2: print STDOUT "Processing makefile $printname\n" if ($verbose); joachim99@14: joachim99@2: # Setup and see if we need to do this. joachim99@2: return if (!initialise()); joachim99@14: joachim99@2: tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in joachim99@2: tag_META_INCLUDES (); # Supplies directories for src locations joachim99@14: joachim99@2: foreach $program (@programs) { joachim99@2: $sources_changed{$program} = 0; joachim99@14: $dependmocs{$program} = ""; joachim99@2: $important{$program} = ""; joachim99@2: tag_IDLFILES(); # Sorts out idl rules joachim99@14: tag_NO_UNDEFINED(); joachim99@2: tag_CLOSURE(); joachim99@14: tag_NMCHECK(); joachim99@2: tag_UIFILES(); # Sorts out ui rules joachim99@2: tag_METASOURCES (); # Sorts out the moc rules joachim99@2: if ($sources_changed{$program}) { joachim99@14: my $lookup = $program . '_SOURCES\s*=[ \t]*(.*)'; joachim99@14: joachim99@14: if($program =~ /libkdeinit_(.*)/) { joachim99@14: my $prog = $1; joachim99@14: substituteLine($prog . '_SOURCES\s*=[ \t]*.*', joachim99@14: "${prog}_SOURCES = ${prog}_dummy.$cxxsuffix\n" . joachim99@14: "libkdeinit_${prog}_SOURCES = " . $sources{$program}); joachim99@14: $sources{$prog} = "${prog}_dummy.$cxxsuffix"; joachim99@14: } joachim99@14: else { joachim99@14: substituteLine($lookup, "$program\_SOURCES=" . $sources{$program}); joachim99@14: } joachim99@2: } joachim99@2: if ($important{$program}) { joachim99@2: local %source_dict = (); joachim99@2: for $source (split(/[\034\s]+/, $sources{$program})) { joachim99@2: $source_dict{$source} = 1; joachim99@2: } joachim99@2: for $source (@cleanfiles) { joachim99@2: $source_dict{$source} = 0; joachim99@2: } joachim99@2: for $source (keys %source_dict) { joachim99@2: next if (!$source); joachim99@2: if ($source_dict{$source}) { joachim99@2: # sanity check joachim99@2: if (! -f $source) { joachim99@2: print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n"; joachim99@2: } else { joachim99@2: $target_adds{"\$(srcdir)/$source"} .= $important{$program}; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: if ($cleanMoc) { joachim99@2: # Always add dist clean tag joachim99@2: # Add extra *.moc.cpp files created for USE_AUTOMOC because they joachim99@2: # aren't included in the normal *.moc clean rules. joachim99@2: appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n"); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources "; joachim99@2: } joachim99@14: joachim99@14: tag_DIST() unless ($kdeopts{"noautodist"}); joachim99@2: joachim99@2: if ($idl_output) { joachim99@2: appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n"); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-idl "; joachim99@2: } joachim99@2: joachim99@2: if ($ui_output) { joachim99@2: appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n"); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-ui "; joachim99@2: } joachim99@2: joachim99@2: if ($closure_output) { joachim99@2: appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n"); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-closures "; joachim99@2: } joachim99@2: joachim99@2: if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) { joachim99@2: $kdelang = '$(KDE_LANG)' joachim99@2: } else { joachim99@2: $kdelang = ''; joachim99@2: } joachim99@2: joachim99@2: tag_POFILES (); # language rules for po directory joachim99@2: tag_DOCFILES (); # language rules for doc directories joachim99@2: tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs joachim99@2: tag_ICON(); joachim99@2: tag_SUBDIRS(); joachim99@2: joachim99@2: my $tmp = "force-reedit:\n"; joachim99@2: $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n"; joachim99@2: appendLines($tmp); joachim99@2: joachim99@14: make_bcheck_target(); joachim99@2: make_meta_classes(); joachim99@2: tag_COMPILE_FIRST(); joachim99@2: tag_FINAL() if (!$kdeopts{"nofinal"}); joachim99@2: joachim99@2: my $final_lines = "final:\n\t\$(MAKE) "; joachim99@2: my $final_install_lines = "final-install:\n\t\$(MAKE) "; joachim99@2: my $nofinal_lines = "no-final:\n\t\$(MAKE) "; joachim99@2: my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) "; joachim99@2: joachim99@2: foreach $program (@programs) { joachim99@14: my $lookup = $program . '_OBJECTS\s*=[ \t]*.*'; joachim99@2: my $new = ""; joachim99@2: my @list = split(/[\034\s]+/, $realObjs{$program}); joachim99@2: if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) { joachim99@2: $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program}; joachim99@2: $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program}; joachim99@2: $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)"; joachim99@2: $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)"; joachim99@14: joachim99@2: $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; joachim99@2: $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; joachim99@2: $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" "; joachim99@2: $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" "; joachim99@2: } else { joachim99@2: $new = "$program\_OBJECTS = " . $realObjs{$program}; joachim99@2: } joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: substituteLine ($lookup, $new); joachim99@14: } joachim99@14: else { joachim99@14: appendLines("$new\n"); joachim99@14: } joachim99@2: } joachim99@14: appendLines($final_lines . "all-am\n"); joachim99@14: appendLines($final_install_lines . "install-am\n"); joachim99@14: appendLines($nofinal_lines . "all-am\n"); joachim99@14: appendLines($nofinal_install_lines . "install-am\n"); joachim99@14: joachim99@14: my $lookup = '(\@\S+\@)?DEP_FILES\s*=[ \t]*(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup/) { joachim99@14: my $condition = $1; joachim99@14: my $depfiles = $2; joachim99@14: my $workfiles; joachim99@14: joachim99@2: if ($dep_finals) { joachim99@14: # Add the conditions on every line, since joachim99@14: # there may be line continuations in the list. joachim99@14: $workfiles = "$dep_files $dep_finals $depfiles"; joachim99@14: $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g; joachim99@14: $lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n"; joachim99@14: $workfiles = "$dep_files $depfiles"; joachim99@14: $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_FALSE\@\t/g; joachim99@14: $lines .= "$condition\@KDE_USE_FINAL_FALSE\@DEP_FILES = $workfiles"; joachim99@2: } else { joachim99@14: $workfiles = "$dep_files $depfiles"; joachim99@14: $workfiles =~ s/\034/\034$condition\t/g; joachim99@14: $lines = $condition . "DEP_FILES = $workfiles"; joachim99@2: } joachim99@2: substituteLine($lookup, $lines); joachim99@2: } joachim99@14: joachim99@14: # new recursive targets joachim99@14: $target_adds{ "nmcheck" } .= ""; # always create nmcheck target joachim99@14: $target_adds{ "nmcheck-am" } .= "nmcheck"; joachim99@14: $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup/) { joachim99@14: substituteLine($lookup, "RECURSIVE_TARGETS = $1 nmcheck-recursive bcheck-recursive"); joachim99@14: } joachim99@14: joachim99@2: my $cvs_lines = "cvs-clean:\n"; joachim99@14: $cvs_lines .= "\t\$(MAKE) admindir=\$(top_srcdir)/admin -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n"; joachim99@2: appendLines($cvs_lines); joachim99@14: joachim99@2: $cvs_lines = "kde-rpo-clean:\n"; joachim99@2: $cvs_lines .= "\t-rm -f *.rpo\n"; joachim99@2: appendLines($cvs_lines); joachim99@2: $target_adds{"clean"} .= "kde-rpo-clean "; joachim99@2: joachim99@14: my %target_dels = ("install-data-am" => ""); joachim99@14: joachim99@2: # some strange people like to do a install-exec, and expect that also joachim99@2: # all modules are installed. automake doesn't know this, so we need to move joachim99@2: # this here from install-data to install-exec. joachim99@2: if ($MakefileData =~ m/\nkde_module_LTLIBRARIES\s*=/) { joachim99@14: # $target_adds{"install-exec-am"} .= "install-kde_moduleLTLIBRARIES "; joachim99@14: # don't use $target_adds here because we need to append the dependency, not joachim99@14: # prepend it. Fixes #44342 , when a module depends on a lib in the same dir joachim99@14: # and libtool needs it during relinking upon install (Simon) joachim99@14: my $lookup = "install-exec-am:([^\n]*)"; joachim99@14: if($MakefileData =~ /\n$lookup\n/) { joachim99@14: substituteLine("$lookup", "install-exec-am: $1 install-kde_moduleLTLIBRARIES"); joachim99@2: } joachim99@14: $target_dels{"install-data-am"} .= "install-kde_moduleLTLIBRARIES "; joachim99@14: $target_adds{"install-data-am"} .= " "; joachim99@2: } joachim99@14: joachim99@2: my $lines = ""; joachim99@2: joachim99@2: foreach $add (keys %target_adds) { joachim99@2: my $lookup = quotemeta($add) . ':([^\n]*)'; joachim99@2: if ($MakefileData =~ /\n$lookup\n/) { joachim99@14: my $newlines = $1; joachim99@14: my $oldlines = $lookup; joachim99@14: if (defined $target_dels{$add}) { joachim99@14: foreach $del (split(' ', $target_dels{$add})) { joachim99@14: $newlines =~ s/\s*$del\s*/ /g; joachim99@14: } joachim99@14: } joachim99@14: substituteLine($oldlines, "$add: " . $target_adds{$add} . $newlines); joachim99@2: } else { joachim99@14: $lines .= "$add: " . $target_adds{$add} . "\n"; joachim99@2: } joachim99@2: } joachim99@14: joachim99@14: appendLines($lines) if ($lines); joachim99@14: joachim99@14: $lines = join("\n", values %rule_adds); joachim99@14: appendLines($lines) if ($lines); joachim99@2: joachim99@2: my $found = 1; joachim99@14: joachim99@2: while ($found) { joachim99@2: if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) { joachim99@14: my $stuff_before = $1; joachim99@14: my $stuff_after = $2; joachim99@2: my $lookup = quotemeta("$1\$(CXXFLAGS)$2"); joachim99@2: my $replacement = "$1\$(KCXXFLAGS)$2"; joachim99@2: $MakefileData =~ s/$lookup/$replacement/; joachim99@2: $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/; joachim99@14: $replacement = "$stuff_before\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$stuff_after"; joachim99@2: substituteLine($lookup, $replacement); joachim99@2: } else { joachim99@2: $found = 0; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if($foreign_libtool == 0) { joachim99@2: $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=link) (\$\(CXXLD\).*\$\(KCXXFLAGS\))'; joachim99@14: joachim99@2: if ($MakefileData =~ m/$lookup/ ) { joachim99@2: $MakefileData =~ s/$lookup/$1 --tag=CXX $2/; joachim99@2: } joachim99@2: joachim99@14: $lookup = '(\n[^#].*\$\(LIBTOOL\) --mode=compile)\s+(\$\(CXX\)\s+)'; joachim99@2: if ($MakefileData =~ m/$lookup/ ) { joachim99@2: $MakefileData =~ s/$lookup/$1 --tag=CXX $2/; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g; joachim99@2: joachim99@2: $lookup = '(.*)cp -pr \$\$/\$\$file \$\(distdir\)/\$\$file(.*)'; joachim99@2: if ($MakefileData =~ m/\n$lookup\n/) { joachim99@2: substituteLine($lookup, "$1cp -pr \$\$d/\$\$file \$(distdir)/\$\$file$2"); joachim99@2: } joachim99@2: joachim99@2: # Always update the Makefile.in joachim99@2: updateMakefile (); joachim99@2: return; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@14: # Beware: This procedure is not complete. E.g. it also parses lines joachim99@14: # containing a '=' in rules (for instance setting shell vars). For our joachim99@14: # usage this us enough, though. joachim99@14: sub read_variables () joachim99@14: { joachim99@14: while ($MakefileData =~ /\n\s*(\S+)\s*=([^\n]*)/g) { joachim99@14: $varcontent{$1} = $2; joachim99@14: } joachim99@14: } joachim99@14: joachim99@2: # Check to see whether we should process this make file. joachim99@2: # This is where we look for tags that we need to process. joachim99@2: # A small amount of initialising on the tags is also done here. joachim99@2: # And of course we open and/or create the needed make files. joachim99@2: sub initialise () joachim99@2: { joachim99@2: if (! -r "Makefile.am") { joachim99@2: print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose); joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: # Checking for files to process... joachim99@2: open (FILEIN, $makefile) joachim99@2: || die "Could not open $makefileDir/$makefile: $!\n"; joachim99@2: # Read the file joachim99@2: # stat(FILEIN)[7] might look more elegant, but is slower as it joachim99@2: # requires stat'ing the file joachim99@2: seek(FILEIN, 0, 2); joachim99@2: my $fsize = tell(FILEIN); joachim99@2: seek(FILEIN, 0, 0); joachim99@2: read FILEIN, $MakefileData, $fsize; joachim99@2: close FILEIN; joachim99@2: print "DOS CRLF within $makefileDir/$makefile!\n" if($MakefileData =~ y/\r//d); joachim99@2: joachim99@2: # Remove the line continuations, but keep them marked joachim99@2: # Note: we lose the trailing spaces but that's ok. joachim99@14: # Don't mangle line-leading spaces (usually tabs) joachim99@14: # since they're important. joachim99@14: $MakefileData =~ s/\\\s*\n/\034/g; joachim99@2: joachim99@2: # If we've processed the file before... joachim99@2: restoreMakefile () if ($MakefileData =~ /$progId/); joachim99@2: joachim99@2: foreach $dir (@foreignfiles) { joachim99@2: if (substr($makefileDir,0,length($dir)) eq $dir) { joachim99@2: return 0; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: %kdeopts = (); joachim99@2: $kdeopts{"foreign"} = 0; joachim99@2: $kdeopts{"qtonly"} = 0; joachim99@14: $kdeopts{"noautodist"} = 0; joachim99@2: $kdeopts{"foreign-libtool"} = $foreign_libtool; joachim99@2: $kdeopts{"nofinal"} = !$use_final; # default joachim99@2: joachim99@14: read_variables(); joachim99@14: joachim99@14: if ($MakefileData =~ /\nKDE_OPTIONS\s*=[ \t]*([^\n]*)\n/) { joachim99@14: my $kde_options_str = $1; joachim99@14: local @kde_options = split(/[\034\s]+/, $kde_options_str); joachim99@2: if (grep(/^foreign$/, @kde_options)) { joachim99@2: push(@foreignfiles, $makefileDir . "/"); joachim99@2: return 0; # don't touch me joachim99@2: } joachim99@2: for $opt (@kde_options) { joachim99@2: if (!defined $kdeopts{$opt}) { joachim99@2: print STDERR "Warning: unknown option $opt in $printname\n"; joachim99@2: } else { joachim99@2: $kdeopts{$opt} = 1; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: # Look for the tags that mean we should process this file. joachim99@2: $metasourceTags = 0; joachim99@2: $metasourceTags++ while ($MakefileData =~ /\n[^=\#]*METASOURCES\s*=/g); joachim99@2: joachim99@2: my $pofileTag = 0; joachim99@2: $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g); joachim99@2: if ($pofileTag > 1) joachim99@2: { joachim99@2: print STDERR "Error: Only one POFILES tag allowed\n"; joachim99@2: $errorflag = 1; joachim99@2: } joachim99@2: joachim99@2: while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) { joachim99@14: my $suffixes_str = $1; joachim99@14: my @list=split(' ', $suffixes_str); joachim99@2: foreach $ext (@list) { joachim99@2: if ($ext =~ /^\.$cppExt$/) { joachim99@2: $cxxsuffix = $ext; joachim99@2: $cxxsuffix =~ s/\.//g; joachim99@2: print STDOUT "will use suffix $cxxsuffix\n" if ($verbose); joachim99@2: last; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@14: joachim99@14: tag_KDEINIT(); joachim99@14: joachim99@14: while ($MakefileData =~ /\n(\S*)_OBJECTS\s*=[\034 \t]*([^\n]*)\n/g) { joachim99@14: joachim99@2: my $program = $1; joachim99@2: my $objs = $2; # safe them joachim99@14: joachim99@2: my $ocv = 0; joachim99@14: joachim99@14: my @objlist = split(/[\034\s]+/, $objs); joachim99@2: foreach $obj (@objlist) { joachim99@14: if ($obj =~ /(\S*)\$\((\S+)\)/ ) { joachim99@14: my $pre = $1; joachim99@14: my $variable = $2; joachim99@14: if ($pre eq '' && exists($varcontent{$variable})) { joachim99@14: my @addlist = split(/[\034\s]+/, $varcontent{$variable}); joachim99@14: push(@objlist, @addlist); joachim99@14: } elsif ($variable !~ 'OBJEXT') { joachim99@2: $ocv = 1; joachim99@14: } joachim99@2: } joachim99@2: } joachim99@14: joachim99@2: next if ($ocv); joachim99@14: next if ($program =~ /^am_libkdeinit_/); joachim99@2: joachim99@2: $program =~ s/^am_// if ($program =~ /^am_/); joachim99@14: joachim99@2: my $sourceprogram = $program; joachim99@2: $sourceprogram =~ s/\@am_/\@/ if($sourceprogram =~ /^.*\@am_.+/); joachim99@14: joachim99@2: print STDOUT "found program $program\n" if ($verbose); joachim99@2: push(@programs, $program); joachim99@14: joachim99@2: $realObjs{$program} = $objs; joachim99@14: joachim99@14: if ($MakefileData =~ /\n$sourceprogram\_SOURCES\s*=[ \t]*(.*)\n/) { joachim99@2: $sources{$program} = $1; joachim99@2: } joachim99@2: else { joachim99@2: $sources{$program} = ""; joachim99@2: print STDERR "found program with no _SOURCES: $program\n"; joachim99@2: } joachim99@2: joachim99@2: my $realprogram = $program; joachim99@2: $realprogram =~ s/_/./g; # unmask to regexp joachim99@2: if ($MakefileData =~ /\n($realprogram)(\$\(EXEEXT\)?)?:.*\$\($program\_OBJECTS\)/) { joachim99@2: $realname{$program} = $1; joachim99@2: } else { joachim99@2: # not standard Makefile - nothing to worry about joachim99@2: $realname{$program} = ""; joachim99@2: } joachim99@2: } joachim99@14: joachim99@14: my $lookup = 'DEPDIR\s*=.*'; joachim99@14: if ($MakefileData !~ /\n$lookup/) { joachim99@14: $lookup = 'bindir\s*=[ \t]*.*'; joachim99@14: substituteLine($lookup, "DEPDIR = .deps\n$1") if ($MakefileData =~ /\n($lookup)/); joachim99@14: } joachim99@2: joachim99@2: my @marks = ('MAINTAINERCLEANFILES', 'CLEANFILES', 'DISTCLEANFILES'); joachim99@2: foreach $mark (@marks) { joachim99@14: while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) { joachim99@14: my $clean_str = $2; joachim99@14: foreach $file (split('[\034\s]+', $clean_str)) { joachim99@2: $file =~ s/\.\///; joachim99@2: push(@cleanfiles, $file); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: my $localTag = 0; joachim99@2: $localTag++ if ($MakefileData =~ /\ninstall-\S+-local:/); joachim99@2: joachim99@2: return (!$errorflag); joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Gets the list of user defined directories - relative to $srcdir - where joachim99@2: # header files could be located. joachim99@2: sub tag_META_INCLUDES () joachim99@2: { joachim99@14: my $lookup = '[^=\n]*META_INCLUDES\s*=[ \t]*(.*)'; joachim99@14: return 1 if ($MakefileData !~ /($lookup)\n/); joachim99@2: print STDOUT "META_INCLUDE processing <$1>\n" if ($verbose); joachim99@2: joachim99@2: my $headerStr = $2; joachim99@2: removeLine ($lookup, $1); joachim99@2: joachim99@14: my @headerlist = split(/[\034\s]+/, $headerStr); joachim99@2: joachim99@2: foreach $dir (@headerlist) joachim99@2: { joachim99@2: $dir =~ s#\$\(srcdir\)#.#; joachim99@2: if (! -d $dir) joachim99@2: { joachim99@2: print STDERR "Warning: $dir can't be found. ", joachim99@2: "Must be a relative path to \$(srcdir)\n"; joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: push (@headerdirs, $dir); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: sub tag_FINAL() joachim99@2: { joachim99@2: my @final_names = (); joachim99@2: joachim99@2: foreach $program (@programs) { joachim99@2: joachim99@2: if ($sources{$program} =~ /\(/) { joachim99@2: print STDOUT "found ( in $program\_SOURCES. skipping\n" if ($verbose); joachim99@2: next; joachim99@2: } joachim99@14: joachim99@14: my $mocs = ""; # Moc files (in this program) joachim99@14: my $moc_cpp_added = 0; # If we added some .moc.cpp files, due to joachim99@14: # no other .cpp file including the .moc one. joachim99@2: joachim99@14: my @progsources = split(/[\034\s]+/, $sources{$program}); joachim99@14: my %shash = (); joachim99@14: @shash{@progsources} = 1; # we are only interested in the existence joachim99@2: my %sourcelist = (); joachim99@2: joachim99@2: foreach $source (@progsources) { joachim99@2: my $suffix = $source; joachim99@2: $suffix =~ s/^.*\.([^\.]+)$/$1/; joachim99@2: joachim99@14: $sourcelist{$suffix} .= "$source "; joachim99@14: } joachim99@14: foreach my $mocFile (keys (%globalmocs)) joachim99@14: { joachim99@14: my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3); joachim99@14: if (defined ($cppFile)) { joachim99@14: $mocs .= " $mocFile.moc" if exists $shash{$cppFile}; joachim99@2: } else { joachim99@14: $sourcelist{$cxxsuffix} .= "$mocFile.moc.$cxxsuffix "; joachim99@14: $moc_cpp_added = 1; joachim99@14: } joachim99@2: } joachim99@2: foreach $suffix (keys %sourcelist) { joachim99@2: joachim99@14: # See if this file contains c++ code. (i.e., just check the file's suffix against c++ extensions) joachim99@2: my $suffix_is_cxx = 0; joachim99@2: if($suffix =~ /($cppExt)$/) { joachim99@2: $cxxsuffix = $1; joachim99@2: $suffix_is_cxx = 1; joachim99@2: } joachim99@2: joachim99@14: my $mocfiles_in = ($suffix eq $cxxsuffix) && $moc_cpp_added; joachim99@2: joachim99@14: my @sourcelist = split(/[\034\s]+/, $sourcelist{$suffix}); joachim99@2: joachim99@2: if ((@sourcelist == 1 && !$mocfiles_in) || $suffix_is_cxx != 1 ) { joachim99@2: joachim99@2: # we support IDL on our own joachim99@14: if ($suffix eq "skel" || $suffix =~ /^stub/ joachim99@14: || $suffix =~ /^signals/ # obsolete, remove in KDE-4 joachim99@14: || $suffix eq "h" || $suffix eq "ui" ) { joachim99@2: next; joachim99@2: } joachim99@2: joachim99@2: foreach $file (@sourcelist) { joachim99@2: $file =~ s/\Q$suffix\E$//; joachim99@2: joachim99@2: $finalObjs{$program} .= $file; joachim99@2: if ($program =~ /_la$/) { joachim99@2: $finalObjs{$program} .= "lo "; joachim99@2: } else { joachim99@2: $finalObjs{$program} .= "o "; joachim99@2: } joachim99@2: } joachim99@2: next; # suffix joachim99@2: } joachim99@2: joachim99@2: my $source_deps = ""; joachim99@2: foreach $source (@sourcelist) { joachim99@2: if (-f $source) { joachim99@14: $source_deps .= " \$(srcdir)/$source"; joachim99@2: } else { joachim99@14: $source_deps .= " $source"; joachim99@2: } joachim99@2: } joachim99@14: joachim99@14: $handling = "$program.all_$suffix.$suffix: \$(srcdir)/Makefile.in" . $source_deps . " " . join(' ', $mocs) . "\n"; joachim99@2: $handling .= "\t\@echo 'creating $program.all_$suffix.$suffix ...'; \\\n"; joachim99@2: $handling .= "\trm -f $program.all_$suffix.files $program.all_$suffix.final; \\\n"; joachim99@2: $handling .= "\techo \"#define KDE_USE_FINAL 1\" >> $program.all_$suffix.final; \\\n"; joachim99@14: $handling .= "\tfor file in " . $sourcelist{$suffix} . "; do \\\n"; joachim99@2: $handling .= "\t echo \"#include \\\"\$\$file\\\"\" >> $program.all_$suffix.files; \\\n"; joachim99@2: $handling .= "\t test ! -f \$\(srcdir\)/\$\$file || egrep '^#pragma +implementation' \$\(srcdir\)/\$\$file >> $program.all_$suffix.final; \\\n"; joachim99@2: $handling .= "\tdone; \\\n"; joachim99@14: $handling .= "\tcat $program.all_$suffix.final $program.all_$suffix.files > $program.all_$suffix.$suffix; \\\n"; joachim99@2: $handling .= "\trm -f $program.all_$suffix.final $program.all_$suffix.files\n"; joachim99@14: joachim99@2: appendLines($handling); joachim99@14: joachim99@2: push(@final_names, "$program.all_$suffix.$suffix"); joachim99@14: my $finalObj = "$program.all_$suffix."; joachim99@2: if ($program =~ /_la$/) { joachim99@14: $finalObj .= "lo"; joachim99@2: } else { joachim99@14: $finalObj .= "o"; joachim99@2: } joachim99@14: $finalObjs{$program} .= $finalObj . " "; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if (!$kdeopts{"nofinal"} && @final_names >= 1) { joachim99@2: # add clean-final target joachim99@2: my $lines = "$cleantarget-final:\n"; joachim99@2: $lines .= "\t-rm -f " . join(' ', @final_names) . "\n" if (@final_names); joachim99@2: appendLines($lines); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-final "; joachim99@2: joachim99@2: foreach $finalfile (@final_names) { joachim99@2: $finalfile =~ s/\.[^.]*$/.P/; joachim99@2: $dep_finals .= " \$(DEPDIR)/$finalfile"; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@14: sub tag_KDEINIT() joachim99@14: { joachim99@14: my @progs = (); joachim99@14: my $ltlibs = ""; joachim99@14: my $lookup = 'kdeinit_LTLIBRARIES\s*=[ \t]*(.*)'; joachim99@14: joachim99@14: if ($MakefileData =~ m/\n$lookup/) { joachim99@14: @kdeinits = split(/[\034\s]+/, $1); joachim99@14: my $lines = ""; joachim99@14: foreach my $kdeinit (@kdeinits) { joachim99@14: if ($kdeinit =~ m/\.la$/) { joachim99@14: $kdeinit =~ s/\.la$//; joachim99@14: push(@progs, $kdeinit); joachim99@14: joachim99@14: $lines .= "\n${kdeinit}.la.$cxxsuffix:\n"; joachim99@14: $lines .= "\techo 'extern \"C\" int kdemain(int argc, char* argv[]);' > ${kdeinit}.la.$cxxsuffix; \\\n"; joachim99@14: $lines .= "\techo 'int main(int argc, char* argv[]) { return kdemain(argc,argv); }' >> ${kdeinit}.la.$cxxsuffix\n"; joachim99@14: joachim99@14: $lines .= "\n${kdeinit}_dummy.$cxxsuffix:\n"; joachim99@14: $lines .= "\t echo > ${kdeinit}_dummy.$cxxsuffix\n"; joachim99@14: joachim99@14: push(@cleanfiles, "${kdeinit}.la.$cxxsuffix"); joachim99@14: push(@cleanfiles, "${kdeinit}_dummy.$cxxsuffix"); joachim99@14: joachim99@14: # add dependency joachim99@14: $dep_files .= " \$(DEPDIR)/${kdeinit}.la.Po" if($dep_files !~/${kdeinit}.la.Po/ ); joachim99@14: $dep_files .= " \$(DEPDIR)/${kdeinit}_dummy.Plo" if($dep_files !~/${kdeinit}_dummy.Plo/ ); joachim99@14: joachim99@14: # make library joachim99@14: $lookup = $kdeinit . '_la_LIBADD\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $libadd = $1; joachim99@14: substituteLine($lookup, "${kdeinit}_la_LIBADD = libkdeinit_${kdeinit}.la"); joachim99@14: appendLines("libkdeinit_${kdeinit}_la_LIBADD = $libadd\n"); joachim99@14: } joachim99@14: appendLines("libkdeinit_${kdeinit}_la_LDFLAGS = \$(all_libraries)\n"); joachim99@14: joachim99@14: # add library dependencies joachim99@14: $lookup = $kdeinit . '_la_DEPENDENCIES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $libdeps = $1; joachim99@14: substituteLine($lookup, "${kdeinit}_la_DEPENDENCIES = libkdeinit_${kdeinit}.la"); joachim99@14: appendLines("libkdeinit_${kdeinit}_la_DEPENDENCIES = $libdeps\n"); joachim99@14: } joachim99@14: joachim99@14: # make library objects joachim99@14: $lookup = "am_${kdeinit}_la_OBJECTS" . '\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $libobjects = $1; joachim99@14: substituteLine($lookup, "am_${kdeinit}_la_OBJECTS = ${kdeinit}_dummy.lo"); joachim99@14: appendLines("am_libkdeinit_${kdeinit}_la_OBJECTS = $libobjects\n"); joachim99@14: my $prog = "libkdeinit_${kdeinit}_la"; joachim99@14: push(@programs, $prog); joachim99@14: $realObjs{$prog} = $libobjects; joachim99@14: $realname{$prog} = "libkdeinit_${kdeinit}.la"; joachim99@14: } joachim99@14: $target_adds{"libkdeinit_${kdeinit}.la"} = "\$(libkdeinit_${kdeinit}_la_OBJECTS) \$(libkdeinit_${kdeinit}_la_DEPENDENCIES)\n" . joachim99@14: "\t\$(CXXLINK) -rpath \$(libdir) \$(libkdeinit_${kdeinit}_la_LDFLAGS) ". joachim99@14: "\$(libkdeinit_${kdeinit}_la_OBJECTS) " . joachim99@14: "\$(libkdeinit_${kdeinit}_la_LIBADD) " . joachim99@14: "\$(LIBS)\n"; joachim99@14: joachim99@14: # make libkdeinit sources joachim99@14: $lookup = $kdeinit . '_la_SOURCES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $srces = $1; joachim99@14: $sources_changed{"libkdeinit_${kdeinit}_la"} = 1; joachim99@14: $sources{"libkdeinit_${kdeinit}_la"} = $srces; joachim99@14: } joachim99@14: joachim99@14: # make libkdeinit metasources joachim99@14: $lookup = $kdeinit . '_la_METASOURCES\s*=[ \t]*(.*)'; joachim99@14: substituteLine($lookup, "libkdeinit_${kdeinit}_la_METASOURCES = $1") joachim99@14: if($MakefileData =~ m/\n$lookup/); joachim99@14: joachim99@14: =cut joachim99@14: # make binary sources joachim99@14: $lookup = $kdeinit. '_SOURCES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: substituteLine($lookup, "${kdeinit}_SOURCES = ${kdeinit}.la.$cxxsuffix"); joachim99@14: $lookup = 'SOURCES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $srces = $1; joachim99@14: $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/; joachim99@14: $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/; joachim99@14: substituteLine($lookup, "SOURCES = $srces"); joachim99@14: } joachim99@14: $lookup = 'DIST_SOURCES\s*=[ \t](.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: my $srces = $1; joachim99@14: $srces =~ s/\b$kdeinit\.c\b/\$(${kdeinit}_SOURCES)/; joachim99@14: $srces =~ s/\$\(${kdeinit}_la_SOURCES\)/\$(libkdeinit_${kdeinit}_la_SOURCES)/; joachim99@14: substituteLine($lookup, "DIST_SOURCES = $srces"); joachim99@14: } joachim99@14: } joachim99@14: joachim99@14: # make binary objects / libs joachim99@14: $lookup = $kdeinit . '_OBJECTS\s*=[ \t]*.*'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)"; joachim99@14: substituteLine("${kdeinit}_LDFLAGS\\s*=.*", "${kdeinit}_LDFLAGS = \$(all_libraries)"); joachim99@14: substituteLine("${kdeinit}_LDADD\\s*=.*", "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la"); joachim99@14: substituteLine("${kdeinit}_DEPENDENCIES\\s*=.*", "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la"); joachim99@14: } joachim99@14: =cut joachim99@14: # add binary joachim99@14: push(@programs, $kdeinit); joachim99@14: $realObjs{$kdeinit} = "${kdeinit}.la.\$(OBJEXT)"; joachim99@14: $realname{$kdeinit} = $kdeinit; joachim99@14: $sources{$kdeinit} = "${kdeinit}.la.$cxxsuffix"; joachim99@14: joachim99@14: $lines .= "${kdeinit}_LDFLAGS = \$(all_libraries)\n"; joachim99@14: $lines .= "${kdeinit}_LDADD = libkdeinit_${kdeinit}.la\n"; joachim99@14: $lines .= "${kdeinit}_DEPENDENCIES = libkdeinit_${kdeinit}.la\n"; joachim99@14: joachim99@14: $target_adds{"${kdeinit}\$(EXEEXT)"} = joachim99@14: "\$(${kdeinit}_OBJECTS) \$(${kdeinit}_DEPENDENCIES)\n" . joachim99@14: "\t\@rm -f ${kdeinit}\$(EXEEXT)\n" . joachim99@14: "\t\$(CXXLINK) \$(${kdeinit}_LDFLAGS) \$(${kdeinit}_OBJECTS) \$(${kdeinit}_LDADD) \$(LIBS)\n"; joachim99@14: joachim99@14: $ltlibs .= " libkdeinit_${kdeinit}.la"; joachim99@14: } joachim99@14: } joachim99@14: appendLines($lines); joachim99@14: joachim99@14: # add libkdeinit target joachim99@14: $lookup = 'lib_LTLIBRARIES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ m/\n$lookup/) { joachim99@14: substituteLine($lookup, "lib_LTLIBRARIES = $1 $ltlibs"); joachim99@14: } joachim99@14: else { joachim99@14: print STDERR joachim99@14: "Error: lib_LTLIBRARIES missing in $printname (required for kdeinit_LTLIBRARIES).\n"; joachim99@14: $errorflag = 1; joachim99@14: } joachim99@14: } joachim99@14: joachim99@14: if($#progs >= 0) { joachim99@14: if($MakefileData !~ m/\nbin_PROGRAMS\s*=/) { joachim99@14: print STDERR "Error: bin_PROGRAMS missing in $printname (required for bin_PROGRAMS).\n"; joachim99@14: $errorflag = 1; joachim99@14: } joachim99@14: else { joachim99@14: # add our new progs to SOURCES, DIST_SOURCES and bin_PROGRAMS joachim99@14: my $progsources = ""; joachim99@14: my $progexes = ""; joachim99@14: foreach my $p (@progs) { joachim99@14: $progsources .= "\$(${p}_SOURCES) "; joachim99@14: $progexes .= "${p}\$(EXEEXT) "; joachim99@14: } joachim99@14: $lookup = 'SOURCES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ /\n$lookup/) { joachim99@14: substituteLine($lookup, "SOURCES = $1 $progsources"); joachim99@14: } joachim99@14: $lookup = 'DIST_SOURCES\s*=[ \t]*(.*)'; joachim99@14: if($MakefileData =~ /\n$lookup/) { joachim99@14: substituteLine($lookup, "DIST_SOURCES = $1 $progsources"); joachim99@14: } joachim99@14: # bin_PROGRAMS is complicated, as it exists twice, so we do a little joachim99@14: # magic trick here joachim99@14: $lookup = 'PROGRAMS\s*=[ \t]*(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup/) { joachim99@14: substituteLine($lookup, "bin_PROGRAMS += $progexes\nPROGRAMS = $1"); joachim99@14: } joachim99@14: } joachim99@14: } joachim99@14: } joachim99@14: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: sub tag_COMPILE_FIRST() joachim99@2: { joachim99@2: foreach $program (@programs) { joachim99@14: my $lookup = "$program" . '_COMPILE_FIRST\s*=[ \t]*(.*)'; joachim99@2: if ($MakefileData =~ m/\n$lookup\n/) { joachim99@14: my $compilefirst_str = $1; joachim99@14: my @compilefirst = split(/[\034\s]+/, $compilefirst_str); joachim99@14: my @progsources = split(/[\034\s]+/, $sources{$program}); joachim99@2: my %donesources = (); joachim99@2: foreach $source (@progsources) { joachim99@2: my @deps = (); joachim99@2: my $sdeps = ""; joachim99@2: if (-f $source) { joachim99@2: $sdeps = "\$(srcdir)/$source"; joachim99@2: } else { joachim99@2: $sdeps = "$source"; joachim99@2: } joachim99@2: foreach $depend (@compilefirst) { joachim99@2: next if ($source eq $depend); joachim99@2: # avoid cyclic dependencies joachim99@2: next if defined($donesources{$depend}); joachim99@2: push @deps, $depend; joachim99@2: } joachim99@14: $target_adds{$sdeps} = join(' ', @deps) if (@deps); joachim99@2: $donesources{$source} = 1; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: joachim99@2: # Organises the list of headers that we'll use to produce moc files joachim99@2: # from. joachim99@2: sub tag_METASOURCES () joachim99@2: { joachim99@2: local @newObs = (); # here we add to create object files joachim99@14: local @depend = (); # here we add to create moc files joachim99@2: local $mocExt = ".moc"; joachim99@2: local %mocFiles = (); joachim99@2: joachim99@2: my $line = ""; joachim99@2: my $postEqual = ""; joachim99@2: joachim99@2: my $lookup; joachim99@2: my $found = ""; joachim99@2: if ($metasourceTags > 1) { joachim99@2: $lookup = $program . '_METASOURCES\s*=\s*(.*)'; joachim99@2: return 1 if ($MakefileData !~ /\n($lookup)\n/); joachim99@2: $found = $1; joachim99@2: } else { joachim99@2: $lookup = $program . '_METASOURCES\s*=\s*(.*)'; joachim99@2: if ($MakefileData !~ /\n($lookup)\n/) { joachim99@2: $lookup = 'METASOURCES\s*=\s*(.*)'; joachim99@14: return 1 if ($MakefileData !~ /\n($lookup)\n/); joachim99@2: $found = $1; joachim99@2: $metasourceTags = 0; # we can use the general target only once joachim99@2: } else { joachim99@2: $found = $1; joachim99@2: } joachim99@2: } joachim99@2: print STDOUT "METASOURCE processing <$found>)\n" if ($verbose); joachim99@2: joachim99@2: $postEqual = $found; joachim99@2: $postEqual =~ s/[^=]*=//; joachim99@2: joachim99@2: removeLine ($lookup, $found); joachim99@2: joachim99@2: # Always find the header files that could be used to "moc" joachim99@2: return 1 if (findMocCandidates ()); joachim99@2: joachim99@2: if ($postEqual =~ /AUTO\s*(\S*)|USE_AUTOMOC\s*(\S*)/) joachim99@2: { joachim99@2: print STDERR "$printname: the argument for AUTO|USE_AUTOMOC is obsolete" if ($+); joachim99@2: $mocExt = ".moc.$cxxsuffix"; joachim99@2: $haveAutomocTag = 1; joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: # Not automoc so read the list of files supplied which joachim99@2: # should be .moc files. joachim99@2: joachim99@2: $postEqual =~ tr/\034/ /; joachim99@2: joachim99@2: # prune out extra headers - This also checks to make sure that joachim99@2: # the list is valid. joachim99@2: pruneMocCandidates ($postEqual); joachim99@2: } joachim99@2: joachim99@2: checkMocCandidates (); joachim99@2: joachim99@2: if (@newObs) { joachim99@2: my $ext = ($program =~ /_la$/) ? ".moc.lo " : ".moc.o "; joachim99@2: $realObjs{$program} .= "\034" . join ($ext, @newObs) . $ext; joachim99@14: $dependmocs{$program} = join (".moc.$cxxsuffix " , @newObs) . ".moc.$cxxsuffix"; joachim99@2: foreach $file (@newObs) { joachim99@2: $dep_files .= " \$(DEPDIR)/$file.moc.P" if($dep_files !~/$file.moc.P/); joachim99@2: } joachim99@2: } joachim99@14: if (@depend) { joachim99@14: $dependmocs{$program} .= " "; joachim99@14: $dependmocs{$program} .= join('.moc ', @depend) . ".moc"; joachim99@14: $dependmocs{$program} .= " "; joachim99@2: } joachim99@2: addMocRules (); joachim99@2: @globalmocs{keys %mocFiles}=values %mocFiles; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Returns 0 if the line was processed - 1 otherwise. joachim99@2: # Errors are logged in the global $errorflags joachim99@2: sub tag_AUTOMAKE () joachim99@2: { joachim99@14: my $lookup = '.*cd \$\(top_srcdir\)\s+&&[\034\s]+\$\(AUTOMAKE\)(.*)'; joachim99@2: return 1 if ($MakefileData !~ /\n($lookup)\n/); joachim99@2: print STDOUT "AUTOMAKE processing <$1>\n" if ($verbose); joachim99@2: joachim99@2: my $newLine = $1."\n\tcd \$(top_srcdir) && perl $thisProg $printname"; joachim99@2: substituteLine ($lookup, $newLine); joachim99@2: $automkCall = $1; joachim99@14: joachim99@14: $lookup = '.*cd \$\(srcdir\)\s+&&[\034\s]+\$\(AUTOCONF\)(.*)'; joachim99@14: if ($MakefileData =~ /\n($lookup)\n/) { joachim99@14: $newLine = "\tcd \$(srcdir) && rm -f configure && \$(MAKE) -f admin/Makefile.common configure"; joachim99@14: substituteLine ($lookup, $newLine); joachim99@14: } joachim99@14: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: sub handle_TOPLEVEL() joachim99@2: { joachim99@2: my $pofiles = ""; joachim99@2: my @restfiles = (); joachim99@2: opendir (THISDIR, "."); joachim99@2: foreach $entry (readdir(THISDIR)) { joachim99@2: next if (-d $entry); joachim99@2: joachim99@2: next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry =~ /.gmo$/); joachim99@2: joachim99@2: if ($entry =~ /\.po$/) { joachim99@2: next; joachim99@2: } joachim99@2: push(@restfiles, $entry); joachim99@2: } joachim99@2: closedir (THISDIR); joachim99@2: joachim99@2: if (@restfiles) { joachim99@2: $target_adds{"install-data-am"} .= "install-nls-files "; joachim99@2: $lines = "install-nls-files:\n"; joachim99@2: $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$kdelang\n"; joachim99@2: for $file (@restfiles) { joachim99@2: $lines .= "\t\$(INSTALL_DATA) \$\(srcdir\)/$file \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n"; joachim99@2: } joachim99@2: $target_adds{"uninstall"} .= "uninstall-nls-files "; joachim99@2: $lines .= "uninstall-nls-files:\n"; joachim99@2: for $file (@restfiles) { joachim99@2: $lines .= "\t-rm -f \$(DESTDIR)\$(kde_locale)/$kdelang/$file\n"; joachim99@2: } joachim99@2: appendLines($lines); joachim99@2: } joachim99@2: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: sub tag_SUBDIRS () joachim99@2: { joachim99@2: if ($MakefileData !~ /\nSUBDIRS\s*=\s*\$\(AUTODIRS\)\s*\n/) { joachim99@2: return 1; joachim99@2: } joachim99@2: joachim99@2: my $subdirs = "."; joachim99@2: joachim99@2: opendir (THISDIR, "."); joachim99@2: foreach $entry (readdir(THISDIR)) { joachim99@2: next if ($entry eq "CVS" || $entry =~ /^\./); joachim99@2: if (-d $entry && -f $entry . "/Makefile.am") { joachim99@2: $subdirs .= " $entry"; joachim99@2: next; joachim99@2: } joachim99@2: } joachim99@2: closedir (THISDIR); joachim99@2: joachim99@14: substituteLine('SUBDIRS\s*=.*', "SUBDIRS =$subdirs"); joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: sub tag_IDLFILES () joachim99@2: { joachim99@2: my @psources = split(/[\034\s]+/, $sources{$program}); joachim99@2: my $dep_lines = ""; joachim99@2: my @cppFiles = (); joachim99@2: joachim99@2: foreach $source (@psources) { joachim99@2: my $skel = ($source =~ m/\.skel$/); joachim99@2: my $stub = ($source =~ m/\.stub$/); joachim99@14: my $signals = ($source =~ m/\.signals$/); # obsolete, remove in KDE-4 joachim99@2: joachim99@2: if ($stub || $skel || $signals) { joachim99@14: joachim99@2: my $qs = quotemeta($source); joachim99@2: $sources{$program} =~ s/$qs//; joachim99@2: $sources_changed{$program} = 1; joachim99@14: joachim99@2: $source =~ s/\.(stub|skel|signals)$//; joachim99@2: my $sourcename; joachim99@14: joachim99@2: if ($skel) { joachim99@2: $sourcename = "$source\_skel"; joachim99@2: } elsif ($stub) { joachim99@2: $sourcename = "$source\_stub"; joachim99@2: } else { joachim99@2: $sourcename = "$source\_signals"; joachim99@2: } joachim99@2: joachim99@2: my $sourcedir = ''; joachim99@2: if (-f "$makefileDir/$source.h") { joachim99@2: $sourcedir = '$(srcdir)/'; joachim99@2: } else { joachim99@2: if ($MakefileData =~ /\n$source\_DIR\s*=\s*(\S+)\n/) { joachim99@2: $sourcedir = $1; joachim99@2: $sourcedir .= "/" if ($sourcedir !~ /\/$/); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if ($allidls !~ /$source\_kidl/) { joachim99@2: joachim99@14: $dep_lines .= "$source.kidl: $sourcedir$source.h \$(DCOP_DEPENDENCIES)\n"; joachim99@14: $dep_lines .= "\t\$(DCOPIDL) $sourcedir$source.h > $source.kidl || ( rm -f $source.kidl ; false )\n"; joachim99@2: joachim99@2: $allidls .= $source . "_kidl "; joachim99@2: } joachim99@2: joachim99@2: if ($allidls !~ /$sourcename/) { joachim99@2: joachim99@2: $dep_lines_tmp = ""; joachim99@2: joachim99@2: if ($skel) { joachim99@2: $dep_lines .= "$sourcename.$cxxsuffix: $source.kidl\n"; joachim99@2: $dep_lines .= "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-stub $source.kidl\n"; joachim99@2: } elsif ($stub) { joachim99@2: $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-signals --no-skel $source.kidl\n"; joachim99@14: } else { # signals - obsolete, remove in KDE 4 joachim99@2: $dep_lines_tmp = "\t\$(DCOPIDL2CPP) --c++-suffix $cxxsuffix --no-stub --no-skel $source.kidl\n"; joachim99@2: } joachim99@2: joachim99@2: if ($stub || $signals) { joachim99@2: $target_adds{"$sourcename.$cxxsuffix"} .= "$sourcename.h "; joachim99@2: $dep_lines .= "$sourcename.h: $source.kidl\n"; joachim99@2: $dep_lines .= $dep_lines_tmp; joachim99@2: } joachim99@2: joachim99@2: $allidls .= $sourcename . " "; joachim99@2: } joachim99@2: joachim99@2: $idlfiles{$program} .= $sourcename . " "; joachim99@2: joachim99@2: if ($program =~ /_la$/) { joachim99@2: $realObjs{$program} .= " $sourcename.lo"; joachim99@2: } else { joachim99@2: $realObjs{$program} .= " $sourcename.\$(OBJEXT)"; joachim99@2: } joachim99@2: $sources{$program} .= " $sourcename.$cxxsuffix"; joachim99@2: $sources_changed{$program} = 1; joachim99@2: $important{$program} .= "$sourcename.h " if (!$skel); joachim99@2: $idl_output .= "\\\n\t$sourcename.$cxxsuffix $sourcename.h $source.kidl "; joachim99@2: push(@cleanfiles, "$sourcename.$cxxsuffix"); joachim99@2: push(@cleanfiles, "$sourcename.h"); joachim99@2: push(@cleanfiles, "$sourcename.kidl"); joachim99@2: $dep_files .= " \$(DEPDIR)/$sourcename.P" if ($dep_files !~/$sourcename.P/); joachim99@2: } joachim99@2: } joachim99@2: if ($dep_lines) { joachim99@2: appendLines($dep_lines); joachim99@2: } joachim99@2: joachim99@2: if (0) { joachim99@2: my $lookup = "($program)"; joachim99@2: $lookup .= '(|\$\(EXEEXT\))'; joachim99@2: $lookup =~ s/\_/./g; joachim99@2: $lookup .= ":(.*..$program\_OBJECTS..*)"; joachim99@2: # $lookup = quotemeta($lookup); joachim99@2: if ($MakefileData =~ /\n$lookup\n/) { joachim99@2: joachim99@2: my $line = "$1$2: "; joachim99@2: foreach $file (split(' ', $idlfiles{$program})) { joachim99@2: $line .= "$file.$cxxsuffix "; joachim99@2: } joachim99@2: $line .= $3; joachim99@2: substituteLine($lookup, $line); joachim99@2: } else { joachim99@2: print STDERR "no built dependency found $lookup\n"; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: sub tag_UIFILES () joachim99@2: { joachim99@2: my @psources = split(/[\034\s]+/, $sources{$program}); joachim99@2: my @depFiles = (); joachim99@2: joachim99@2: foreach $source (@psources) { joachim99@2: joachim99@2: if ($source =~ m/\.ui$/) { joachim99@2: joachim99@2: print STDERR "adding UI file $source\n" if ($verbose); joachim99@2: joachim99@2: my $qs = quotemeta($source); joachim99@2: $sources{$program} =~ s/$qs//; joachim99@2: $sources_changed{$program} = 1; joachim99@2: joachim99@2: $source =~ s/\.ui$//; joachim99@2: joachim99@2: my $sourcedir = ''; joachim99@2: if (-f "$makefileDir/$source.ui") { joachim99@2: $sourcedir = '$(srcdir)/'; joachim99@2: } joachim99@2: joachim99@2: if (!$uiFiles{$source}) { joachim99@2: joachim99@14: my $dep_lines = "$source.$cxxsuffix: $sourcedir$source.ui $source.h $source.moc\n"; joachim99@2: $dep_lines .= "\trm -f $source.$cxxsuffix\n"; joachim99@2: if (!$kdeopts{"qtonly"}) { joachim99@2: $dep_lines .= "\techo '#include ' > $source.$cxxsuffix\n"; joachim99@14: my ($mangled_source) = $source; joachim99@14: $mangled_source =~ s/[^A-Za-z0-9]/_/g; # get rid of garbage joachim99@14: $dep_lines .= "\t\$(UIC) -tr \${UIC_TR} -i $source.h $sourcedir$source.ui > $source.$cxxsuffix.temp ; ret=\$\$?; \\\n"; joachim99@14: $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"; joachim99@14: $dep_lines .= "\trm -f $source.$cxxsuffix.temp ;\\\n"; joachim99@2: } else { joachim99@14: $dep_lines .= "\t\$(UIC) -i $source.h $sourcedir$source.ui > $source.$cxxsuffix; ret=\$\$?; \\\n"; joachim99@2: } joachim99@14: $dep_lines .= "\tif test \"\$\$ret\" = 0; then echo '#include \"$source.moc\"' >> $source.$cxxsuffix; else rm -f $source.$cxxsuffix ; exit \$\$ret ; fi\n\n"; joachim99@2: $dep_lines .= "$source.h: $sourcedir$source.ui\n"; joachim99@2: $dep_lines .= "\t\$(UIC) -o $source.h $sourcedir$source.ui\n\n"; joachim99@2: $dep_lines .= "$source.moc: $source.h\n"; joachim99@2: $dep_lines .= "\t\$(MOC) $source.h -o $source.moc\n"; joachim99@2: joachim99@14: $rule_adds{"$source.$cxxsuffix"} = $dep_lines; joachim99@14: joachim99@2: $uiFiles{$source} = 1; joachim99@14: $dependmocs{$program} .= " $source.moc"; joachim99@2: $globalmocs{$source} = "\035$source.h\035$source.cpp"; joachim99@2: } joachim99@2: joachim99@2: if ($program =~ /_la$/) { joachim99@2: $realObjs{$program} .= " $source.lo"; joachim99@2: } else { joachim99@2: $realObjs{$program} .= " $source.\$(OBJEXT)"; joachim99@2: } joachim99@2: $sources{$program} .= " $source.$cxxsuffix"; joachim99@2: $sources_changed{$program} = 1; joachim99@2: $important{$program} .= "$source.h "; joachim99@2: $ui_output .= "\\\n\t$source.$cxxsuffix $source.h $source.moc "; joachim99@2: push(@cleanfiles, "$source.$cxxsuffix"); joachim99@2: push(@cleanfiles, "source.h"); joachim99@2: push(@cleanfiles, "$source.moc"); joachim99@2: $dep_files .= " \$(DEPDIR)/$source.P" if($dep_files !~/$source.P/ ); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: sub tag_ICON() joachim99@2: { joachim99@14: my $lookup = '([^\s]*)_ICON\s*=[ \t]*(.*)'; joachim99@2: my $install = ""; joachim99@2: my $uninstall = ""; joachim99@2: joachim99@14: while ($MakefileData =~ /\n$lookup/g) { joachim99@2: my $destdir; joachim99@2: if ($1 eq "KDE") { joachim99@2: $destdir = "kde_icondir"; joachim99@2: } else { joachim99@2: $destdir = $1 . "dir"; joachim99@2: } joachim99@2: my $iconauto = ($2 =~ /AUTO\s*$/); joachim99@2: my @appnames = (); joachim99@2: if ( ! $iconauto ) { joachim99@14: my $appicon_str = $2; joachim99@14: my @_appnames = split(" ", $appicon_str); joachim99@2: print STDOUT "KDE_ICON processing <@_appnames>\n" if ($verbose); joachim99@2: foreach $appname (@_appnames) { joachim99@2: push(@appnames, quotemeta($appname)); joachim99@2: } joachim99@2: } else { joachim99@2: print STDOUT "KDE_ICON processing \n" if ($verbose); joachim99@2: } joachim99@2: joachim99@2: my @files = (); joachim99@2: opendir (THISDIR, "."); joachim99@2: foreach $entry (readdir(THISDIR)) { joachim99@2: next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/); joachim99@2: next if (! -f $entry); joachim99@2: if ( $iconauto ) joachim99@2: { joachim99@2: push(@files, $entry) joachim99@14: if ($entry =~ /\.xpm/ || $entry =~ /\.png/ || $entry =~ /\.mng/ || $entry =~ /\.svg/); joachim99@2: } else { joachim99@2: foreach $appname (@appnames) { joachim99@2: push(@files, $entry) joachim99@14: if ($entry =~ /-$appname\.xpm/ || $entry =~ /-$appname\.png/ || $entry =~ /-$appname\.mng/ || $entry =~ /-$appname\.svg/); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: closedir (THISDIR); joachim99@2: joachim99@2: my %directories = (); joachim99@2: joachim99@2: foreach $file (@files) { joachim99@2: my $newfile = $file; joachim99@2: my $prefix = $file; joachim99@14: $prefix =~ s/\.(png|xpm|mng|svg|svgz)$//; joachim99@2: my $appname = $prefix; joachim99@2: $appname =~ s/^[^-]+-// if ($appname =~ /-/) ; joachim99@2: $appname =~ s/^[^-]+-// if ($appname =~ /-/) ; joachim99@2: $appname = quotemeta($appname); joachim99@2: $prefix =~ s/$appname$//; joachim99@2: $prefix =~ s/-$//; joachim99@2: joachim99@2: $prefix = 'lo16-app' if ($prefix eq 'mini'); joachim99@2: $prefix = 'lo32-app' if ($prefix eq 'lo'); joachim99@2: $prefix = 'hi48-app' if ($prefix eq 'large'); joachim99@2: $prefix .= '-app' if ($prefix =~ m/^...$/); joachim99@2: joachim99@2: my $type = $prefix; joachim99@2: $type =~ s/^.*-([^-]+)$/$1/; joachim99@2: $prefix =~ s/^(.*)-[^-]+$/$1/; joachim99@2: joachim99@2: my %type_hash = joachim99@2: ( joachim99@2: 'action' => 'actions', joachim99@2: 'app' => 'apps', joachim99@2: 'device' => 'devices', joachim99@2: 'filesys' => 'filesystems', joachim99@2: 'mime' => 'mimetypes' joachim99@2: ); joachim99@14: joachim99@2: if (! defined $type_hash{$type} ) { joachim99@2: print STDERR "unknown icon type $type in $printname ($file)\n"; joachim99@2: next; joachim99@2: } joachim99@14: joachim99@2: my %dir_hash = joachim99@2: ( joachim99@2: 'los' => 'locolor/16x16', joachim99@2: 'lom' => 'locolor/32x32', joachim99@2: 'him' => 'hicolor/32x32', joachim99@2: 'hil' => 'hicolor/48x48', joachim99@2: 'lo16' => 'locolor/16x16', joachim99@2: 'lo22' => 'locolor/22x22', joachim99@2: 'lo32' => 'locolor/32x32', joachim99@2: 'hi16' => 'hicolor/16x16', joachim99@2: 'hi22' => 'hicolor/22x22', joachim99@2: 'hi32' => 'hicolor/32x32', joachim99@2: 'hi48' => 'hicolor/48x48', joachim99@2: 'hi64' => 'hicolor/64x64', joachim99@14: 'hi128' => 'hicolor/128x128', joachim99@14: 'hisc' => 'hicolor/scalable', joachim99@14: 'cr16' => 'crystalsvg/16x16', joachim99@14: 'cr22' => 'crystalsvg/22x22', joachim99@14: 'cr32' => 'crystalsvg/32x32', joachim99@14: 'cr48' => 'crystalsvg/48x48', joachim99@14: 'cr64' => 'crystalsvg/64x64', joachim99@14: 'cr128' => 'crystalsvg/128x128', joachim99@14: 'crsc' => 'crystalsvg/scalable' joachim99@2: ); joachim99@2: joachim99@14: $newfile =~ s@.*-($appname\.(png|xpm|mng|svgz|svg?))@$1@; joachim99@2: joachim99@2: if (! defined $dir_hash{$prefix}) { joachim99@2: print STDERR "unknown icon prefix $prefix in $printname\n"; joachim99@2: next; joachim99@2: } joachim99@2: joachim99@2: my $dir = $dir_hash{$prefix} . "/" . $type_hash{$type}; joachim99@2: if ($newfile =~ /-[^\.]/) { joachim99@2: my $tmp = $newfile; joachim99@2: $tmp =~ s/^([^-]+)-.*$/$1/; joachim99@2: $dir = $dir . "/" . $tmp; joachim99@2: $newfile =~ s/^[^-]+-//; joachim99@2: } joachim99@2: joachim99@2: if (!defined $directories{$dir}) { joachim99@2: $install .= "\t\$(mkinstalldirs) \$(DESTDIR)\$($destdir)/$dir\n"; joachim99@2: $directories{$dir} = 1; joachim99@2: } joachim99@2: joachim99@2: $install .= "\t\$(INSTALL_DATA) \$(srcdir)/$file \$(DESTDIR)\$($destdir)/$dir/$newfile\n"; joachim99@2: $uninstall .= "\t-rm -f \$(DESTDIR)\$($destdir)/$dir/$newfile\n"; joachim99@2: joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if (length($install)) { joachim99@2: $target_adds{"install-data-am"} .= "install-kde-icons "; joachim99@2: $target_adds{"uninstall-am"} .= "uninstall-kde-icons "; joachim99@2: appendLines("install-kde-icons:\n" . $install . "\nuninstall-kde-icons:\n" . $uninstall); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: sub handle_POFILES($$) joachim99@2: { joachim99@2: my @pofiles = split(" ", $_[0]); joachim99@2: my $lang = $_[1]; joachim99@2: joachim99@2: # Build rules for creating the gmo files joachim99@2: my $tmp = ""; joachim99@2: my $allgmofiles = ""; joachim99@2: my $pofileLine = "POFILES ="; joachim99@2: foreach $pofile (@pofiles) joachim99@2: { joachim99@2: $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension joachim99@2: $tmp .= "$1.gmo: $pofile\n"; joachim99@2: $tmp .= "\trm -f $1.gmo; \$(GMSGFMT) -o $1.gmo \$(srcdir)/$pofile\n"; joachim99@2: $tmp .= "\ttest ! -f $1.gmo || touch $1.gmo\n"; joachim99@2: $allgmofiles .= " $1.gmo"; joachim99@2: $pofileLine .= " $1.po"; joachim99@2: } joachim99@2: appendLines ($tmp); joachim99@2: my $lookup = 'POFILES\s*=([^\n]*)'; joachim99@14: if ($MakefileData !~ /\n$lookup/) { joachim99@2: appendLines("$pofileLine\nGMOFILES =$allgmofiles"); joachim99@2: } else { joachim99@2: substituteLine ($lookup, "$pofileLine\nGMOFILES =$allgmofiles"); joachim99@2: } joachim99@2: joachim99@2: if ($allgmofiles) { joachim99@2: joachim99@2: # Add the "clean" rule so that the maintainer-clean does something joachim99@2: appendLines ("clean-nls:\n\t-rm -f $allgmofiles\n"); joachim99@2: joachim99@2: $target_adds{"maintainer-clean"} .= "clean-nls "; joachim99@2: joachim99@14: $lookup = 'DISTFILES\s*=[ \t]*(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup/) { joachim99@2: $tmp = "DISTFILES = \$(GMOFILES) \$(POFILES) $1"; joachim99@2: substituteLine ($lookup, $tmp); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: $target_adds{"install-data-am"} .= "install-nls "; joachim99@2: joachim99@2: $tmp = "install-nls:\n"; joachim99@2: if ($lang) { joachim99@2: $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES\n"; joachim99@2: } joachim99@2: $tmp .= "\t\@for base in "; joachim99@2: foreach $pofile (@pofiles) joachim99@2: { joachim99@2: $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension joachim99@2: $tmp .= "$1 "; joachim99@2: } joachim99@2: joachim99@2: $tmp .= "; do \\\n"; joachim99@2: if ($lang) { joachim99@2: $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; joachim99@14: $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; joachim99@14: $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/\$\$base.mo ;\\\n"; joachim99@14: $tmp .= "\t fi ;\\\n"; joachim99@2: } else { joachim99@2: $tmp .= "\t echo \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; joachim99@2: $tmp .= "\t \$(mkinstalldirs) \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES ; \\\n"; joachim99@14: $tmp .= "\t if test -f \$\$base.gmo; then \$(INSTALL_DATA) \$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; joachim99@14: $tmp .= "\t elif test -f \$(srcdir)/\$\$base.gmo; then \$(INSTALL_DATA) \$(srcdir)/\$\$base.gmo \$(DESTDIR)\$(kde_locale)/\$\$base/LC_MESSAGES/\$(PACKAGE).mo ;\\\n"; joachim99@14: $tmp .= "\t fi ;\\\n"; joachim99@2: } joachim99@2: $tmp .= "\tdone\n\n"; joachim99@2: appendLines ($tmp); joachim99@2: joachim99@2: $target_adds{"uninstall"} .= "uninstall-nls "; joachim99@2: joachim99@2: $tmp = "uninstall-nls:\n"; joachim99@2: foreach $pofile (@pofiles) joachim99@2: { joachim99@2: $pofile =~ /(.*)\.[^\.]*$/; # Find name minus extension joachim99@2: if ($lang) { joachim99@2: $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$lang/LC_MESSAGES/$1.mo\n"; joachim99@2: } else { joachim99@2: $tmp .= "\trm -f \$(DESTDIR)\$(kde_locale)/$1/LC_MESSAGES/\$(PACKAGE).mo\n"; joachim99@2: } joachim99@2: } joachim99@2: appendLines($tmp); joachim99@2: joachim99@2: $target_adds{"all"} .= "all-nls "; joachim99@2: joachim99@2: $tmp = "all-nls: \$(GMOFILES)\n"; joachim99@2: joachim99@2: appendLines($tmp); joachim99@2: joachim99@2: $target_adds{"distdir"} .= "distdir-nls "; joachim99@2: joachim99@2: $tmp = "distdir-nls:\$(GMOFILES)\n"; joachim99@2: $tmp .= "\tfor file in \$(POFILES); do \\\n"; joachim99@2: $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; joachim99@2: $tmp .= "\tdone\n"; joachim99@2: $tmp .= "\tfor file in \$(GMOFILES); do \\\n"; joachim99@2: $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; joachim99@2: $tmp .= "\tdone\n"; joachim99@2: joachim99@2: appendLines ($tmp); joachim99@2: joachim99@2: if (!$lang) { joachim99@2: appendLines("merge:\n\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common package-merge POFILES=\"\${POFILES}\" PACKAGE=\${PACKAGE}\n\n"); joachim99@2: } joachim99@2: joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Returns 0 if the line was processed - 1 otherwise. joachim99@2: # Errors are logged in the global $errorflags joachim99@2: sub tag_POFILES () joachim99@2: { joachim99@2: my $lookup = 'POFILES\s*=([^\n]*)'; joachim99@14: return 1 if ($MakefileData !~ /\n$lookup/); joachim99@2: print STDOUT "POFILES processing <$1>\n" if ($verbose); joachim99@2: joachim99@2: my $tmp = $1; joachim99@2: joachim99@2: # make sure these are all gone. joachim99@2: if ($MakefileData =~ /\n\.po\.gmo:\n/) joachim99@2: { joachim99@2: print STDERR "Warning: Found old .po.gmo rules in $printname. New po rules not added\n"; joachim99@2: return 1; joachim99@2: } joachim99@2: joachim99@2: # Either find the pofiles in the directory (AUTO) or use joachim99@2: # only the specified po files. joachim99@2: my $pofiles = ""; joachim99@2: if ($tmp =~ /^\s*AUTO\s*$/) joachim99@2: { joachim99@2: opendir (THISDIR, "."); joachim99@2: $pofiles = join(" ", grep(/\.po$/, readdir(THISDIR))); joachim99@2: closedir (THISDIR); joachim99@2: print STDOUT "pofiles found = $pofiles\n" if ($verbose); joachim99@2: if (-f "charset" && -f "kdelibs.po") { joachim99@2: handle_TOPLEVEL(); joachim99@2: } joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: $tmp =~ s/\034/ /g; joachim99@2: $pofiles = $tmp; joachim99@2: } joachim99@2: return 1 if (!$pofiles); # Nothing to do joachim99@2: joachim99@2: handle_POFILES($pofiles, $kdelang); joachim99@2: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: sub helper_LOCALINSTALL($) joachim99@2: { joachim99@14: my $lookup = "\035" . $_[0] . " *:[^\035]*\035\t"; joachim99@14: my $copy = $MakefileData; joachim99@14: $copy =~ s/\n/\035/g; joachim99@14: if ($copy =~ /($lookup.*)$/) { joachim99@2: joachim99@14: $install = $1; joachim99@14: $install =~ s/\035$_[0] *:[^\035]*\035//; joachim99@2: my $emptyline = 0; joachim99@14: while (! $emptyline ) { joachim99@2: if ($install =~ /([^\035]*)\035(.*)/) { joachim99@2: local $line = $1; joachim99@2: $install = $2; joachim99@2: if ($line !~ /^\s*$/ && $line !~ /^(\@.*\@)*\t/) { joachim99@2: $emptyline = 1; joachim99@2: } else { joachim99@2: replaceDestDir($line); joachim99@2: } joachim99@2: } else { joachim99@2: $emptyline = 1; joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: } joachim99@2: joachim99@2: sub tag_LOCALINSTALL () joachim99@2: { joachim99@2: helper_LOCALINSTALL('install-exec-local'); joachim99@2: helper_LOCALINSTALL('install-data-local'); joachim99@2: helper_LOCALINSTALL('uninstall-local'); joachim99@2: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: sub replaceDestDir($) { joachim99@2: local $line = $_[0]; joachim99@2: joachim99@2: if ( $line =~ /^\s*(\@.*\@)*\s*\$\(mkinstalldirs\)/ joachim99@2: || $line =~ /^\s*(\@.*\@)*\s*\$\(INSTALL\S*\)/ joachim99@2: || $line =~ /^\s*(\@.*\@)*\s*(-?rm.*) \S*$/) joachim99@2: { joachim99@2: $line =~ s/^(.*) ([^\s]+)\s*$/$1 \$(DESTDIR)$2/ if ($line !~ /\$\(DESTDIR\)/); joachim99@2: } joachim99@2: joachim99@2: if ($line ne $_[0]) { joachim99@2: $_[0] = quotemeta $_[0]; joachim99@2: substituteLine($_[0], $line); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #--------------------------------------------------------------------------- joachim99@14: # libtool is very hard to persuade it could use -Wl,--no-undefined for making joachim99@14: # -no-undefined actually work joachim99@14: # append $(KDE_NO_UNFINED) after every -no-undefined in LDFLAGS joachim99@14: # this may go away if libtool ever does this on its own joachim99@14: sub tag_NO_UNDEFINED () { joachim99@14: return if ($program !~ /_la$/); joachim99@14: joachim99@14: my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n"; joachim99@14: $MakefileData =~ m/$lookup/; joachim99@14: return if (!defined($1)); joachim99@14: return if ($1 !~ /CXXLINK/); joachim99@14: joachim99@14: if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ ) { joachim99@14: return; joachim99@14: } joachim99@14: joachim99@14: $lookup = $program . '\_LDFLAGS(\s*)=(.*)-no-undefined(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup\n/) { joachim99@14: my $replace = $program . "\_LDFLAGS$1=$2-no-undefined \$(KDE_NO_UNDEFINED)$3"; joachim99@14: substituteLine($lookup, $replace); joachim99@14: } joachim99@14: } joachim99@14: joachim99@2: sub tag_CLOSURE () { joachim99@2: return if ($program !~ /_la$/); joachim99@14: joachim99@2: my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n"; joachim99@2: $MakefileData =~ m/$lookup/; joachim99@14: return if (!defined($1)); joachim99@2: return if ($1 !~ /CXXLINK/); joachim99@2: joachim99@2: if ($MakefileData !~ /\n$program\_LDFLAGS\s*=.*-no-undefined/ && joachim99@2: $MakefileData !~ /\n$program\_LDFLAGS\s*=.*KDE_PLUGIN/ ) { joachim99@2: print STDERR "Report: $program contains undefined in $printname\n" if ($program =~ /^lib/ && $dryrun); joachim99@2: return; joachim99@2: } joachim99@14: joachim99@2: my $closure = $realname{$program} . ".closure"; joachim99@2: my $lines = "$closure: \$($program\_OBJECTS) \$($program\_DEPENDENCIES)\n"; joachim99@2: $lines .= "\t\@echo \"int main() {return 0;}\" > $program\_closure.$cxxsuffix\n"; joachim99@2: $lines .= "\t\@\$\(LTCXXCOMPILE\) -c $program\_closure.$cxxsuffix\n"; joachim99@2: $lines .= "\t\$\(CXXLINK\) $program\_closure.lo \$($program\_LDFLAGS) \$($program\_OBJECTS) \$($program\_LIBADD) \$(LIBS)\n"; joachim99@2: $lines .= "\t\@rm -f $program\_closure.* $closure\n"; joachim99@2: $lines .= "\t\@echo \"timestamp\" > $closure\n"; joachim99@2: $lines .= "\n"; joachim99@2: appendLines($lines); joachim99@2: $lookup = $realname{$program} . ": (.*)"; joachim99@2: if ($MakefileData =~ /\n$lookup\n/) { joachim99@2: $lines = "\@KDE_USE_CLOSURE_TRUE@". $realname{$program} . ": $closure $1"; joachim99@2: $lines .= "\n\@KDE_USE_CLOSURE_FALSE@" . $realname{$program} . ": $1"; joachim99@2: substituteLine($lookup, $lines); joachim99@2: } joachim99@2: $closure_output .= " $closure"; joachim99@2: } joachim99@2: joachim99@14: sub tag_NMCHECK () { joachim99@14: return if ($program !~ /_la$/); joachim99@14: my $lookup = quotemeta($realname{$program}) . ":.*?\n\t.*?\\((.*?)\\) .*\n"; joachim99@14: $MakefileData =~ m/$lookup/; joachim99@14: my $linkcmd = $1; joachim99@14: return if (!defined($1)); joachim99@14: return if ($linkcmd !~ /CXXLINK/ && $linkcmd !~ /LINK/); joachim99@14: joachim99@14: $lookup = $program . '_NMCHECK\s*=([^\n]*)'; joachim99@14: if( $MakefileData !~ m/\n$lookup\n/ ) { joachim99@14: return; joachim99@14: } joachim99@14: my $allowed = $1; joachim99@14: $allowed =~ s/^ *//; joachim99@14: $lookup = $program . '_NMCHECKWEAK\s*=([^\n]*)'; joachim99@14: my $weak = ""; joachim99@14: my $is_weak = 0; joachim99@14: if( $MakefileData =~ m/\n$lookup\n/ ) { joachim99@14: $weak = $1; joachim99@14: $is_weak = 1; joachim99@14: } joachim99@14: $weak =~ s/^ *//; joachim99@14: joachim99@14: if( $is_weak ) joachim99@14: { joachim99@14: $weak = '--allowweak=\'' . $weak . '\' '; joachim99@14: } joachim99@14: my $nmline = "\@KDE_USE_NMCHECK_TRUE@\t\@\$(MAKE) \$(AM_MAKEFLAGS) nmcheck_$realname{$program} || ( rm -f $realname{$program}; exit 1 )"; joachim99@14: $lookup = '(\t\$\(CXXLINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)'; joachim99@14: if( $MakefileData =~ /\n$lookup\n/ ) { joachim99@14: my $oldstuff = $1; joachim99@14: substituteLine( $lookup, $oldstuff . "\n" . $nmline ); joachim99@14: } joachim99@14: $lookup = '(\t\$\(LINK\)[^\n]*' . $program . '_OBJECTS[^\n]*)'; joachim99@14: if( $MakefileData =~ /\n$lookup\n/ ) { joachim99@14: my $oldstuff = $1; joachim99@14: substituteLine( $lookup, $oldstuff . "\n" . $nmline ); joachim99@14: } joachim99@14: $nmline = "\@\$(top_srcdir)/admin/nmcheck $realname{$program} \'$allowed\' $weak"; joachim99@14: appendLines( "\nnmcheck_$realname{$program}: $realname{$program} \n\t$nmline\n" ); joachim99@14: $target_adds{ "nmcheck" } .= "nmcheck_$realname{$program} "; joachim99@14: } joachim99@14: joachim99@2: sub tag_DIST () { joachim99@2: my %foundfiles = (); joachim99@2: opendir (THISDIR, "."); joachim99@2: foreach $entry (readdir(THISDIR)) { joachim99@14: next if ($entry eq "CVS" || $entry =~ /^\./ || $entry eq "Makefile" || $entry =~ /~$/ || $entry =~ /^\#.*\#$/); joachim99@2: next if (! -f $entry); joachim99@14: next if ($entry =~ /\.moc/ || $entry =~ /\.moc.$cppExt$/ || $entry =~ /\.lo$/ || $entry =~ /\.la$/ || $entry =~ /\.o/); joachim99@14: next if ($entry =~ /\.all_$cppExt\.$cppExt$/); joachim99@2: $foundfiles{$entry} = 1; joachim99@2: } joachim99@2: closedir (THISDIR); joachim99@2: joachim99@2: # doing this for MAINTAINERCLEANFILES would be wrong joachim99@2: my @marks = ("EXTRA_DIST", "DIST_COMMON", '\S*_SOURCES', '\S*_HEADERS', 'CLEANFILES', 'DISTCLEANFILES', '\S*_OBJECTS'); joachim99@2: foreach $mark (@marks) { joachim99@14: while ($MakefileData =~ /\n($mark)\s*=[ \t]*([^\n]*)/g) { joachim99@14: my $cleanfiles_str = $2; joachim99@14: foreach $file (split('[\034\s]+', $cleanfiles_str)) { joachim99@2: $file =~ s/\.\///; joachim99@2: $foundfiles{$file} = 0 if (defined $foundfiles{$file}); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: my @files = ("Makefile", "config.cache", "config.log", "stamp-h", joachim99@14: "stamp-h1", "stamp-h1", "config.h", "Makefile", joachim99@14: "config.status", "config.h", "libtool", "core" ); joachim99@2: foreach $file (@files) { joachim99@2: $foundfiles{$file} = 0 if (defined $foundfiles{$file}); joachim99@2: } joachim99@2: joachim99@2: my $KDE_DIST = ""; joachim99@2: foreach $file (keys %foundfiles) { joachim99@2: if ($foundfiles{$file} == 1) { joachim99@2: $KDE_DIST .= "$file "; joachim99@2: } joachim99@2: } joachim99@2: if ($KDE_DIST) { joachim99@2: print "KDE_DIST $printname $KDE_DIST\n" if ($verbose); joachim99@14: joachim99@14: my $lookup = 'DISTFILES\s*=[ \t]*(.*)'; joachim99@14: if ($MakefileData =~ /\n$lookup/) { joachim99@14: substituteLine($lookup, "DISTFILES = $1 \$(KDE_DIST)"); joachim99@14: appendLines("KDE_DIST=$KDE_DIST\n"); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: # Returns 0 if the line was processed - 1 otherwise. joachim99@2: # Errors are logged in the global $errorflags joachim99@2: sub tag_DOCFILES () joachim99@2: { joachim99@2: $target_adds{"all"} .= "docs-am "; joachim99@2: joachim99@14: my $lookup = 'KDE_DOCS\s*=[ \t]*([^\n]*)'; joachim99@14: goto nodocs if ($MakefileData !~ /\n$lookup/); joachim99@2: print STDOUT "KDE_DOCS processing <$1>\n" if ($verbose); joachim99@2: joachim99@2: my $tmp = $1; joachim99@2: joachim99@2: # Either find the files in the directory (AUTO) or use joachim99@2: # only the specified po files. joachim99@2: my $files = ""; joachim99@2: my $appname = $tmp; joachim99@2: $appname =~ s/^(\S*)\s*.*$/$1/; joachim99@2: if ($appname =~ /AUTO/) { joachim99@2: $appname = basename($makefileDir); joachim99@2: if ("$appname" eq "en") { joachim99@2: 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"; joachim99@2: exit(1); joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: if ($tmp !~ / - /) joachim99@2: { joachim99@2: opendir (THISDIR, "."); joachim99@2: foreach $entry (readdir(THISDIR)) { joachim99@14: next if ($entry eq "CVS" || $entry =~ /^\./ || $entry =~ /^Makefile/ || $entry =~ /~$/ || $entry =~ /^\#.*\#$/ || $entry eq "core" || $entry eq "index.cache.bz2"); joachim99@2: next if (! -f $entry); joachim99@2: $files .= "$entry "; joachim99@2: } joachim99@2: closedir (THISDIR); joachim99@2: print STDOUT "docfiles found = $files\n" if ($verbose); joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: $tmp =~ s/\034/ /g; joachim99@2: $tmp =~ s/^\S*\s*-\s*//; joachim99@2: $files = $tmp; joachim99@2: } joachim99@2: goto nodocs if (!$files); # Nothing to do joachim99@2: joachim99@2: if ($files =~ /(^| )index\.docbook($| )/) { joachim99@14: joachim99@2: my $lines = ""; joachim99@2: my $lookup = 'MEINPROC\s*='; joachim99@2: if ($MakefileData !~ /\n($lookup)/) { joachim99@2: $lines = "MEINPROC=/\$(kde_bindir)/meinproc\n"; joachim99@2: } joachim99@2: $lookup = 'KDE_XSL_STYLESHEET\s*='; joachim99@2: if ($MakefileData !~ /\n($lookup)/) { joachim99@2: $lines .= "KDE_XSL_STYLESHEET=/\$(kde_datadir)/ksgmltools2/customization/kde-chunk.xsl\n"; joachim99@2: } joachim99@2: $lookup = '\nindex.cache.bz2:'; joachim99@2: if ($MakefileData !~ /\n($lookup)/) { joachim99@2: $lines .= "index.cache.bz2: \$(srcdir)/index.docbook \$(KDE_XSL_STYLESHEET) $files\n"; joachim99@14: $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; fi\n"; joachim99@2: $lines .= "\n"; joachim99@2: } joachim99@14: joachim99@14: $lines .= "docs-am: index.cache.bz2\n"; joachim99@2: $lines .= "\n"; joachim99@2: $lines .= "install-docs: docs-am install-nls\n"; joachim99@2: $lines .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n"; joachim99@2: $lines .= "\t\@if test -f index.cache.bz2; then \\\n"; joachim99@2: $lines .= "\techo \$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; joachim99@2: $lines .= "\t\$(INSTALL_DATA) index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; joachim99@14: $lines .= "\telif test -f \$(srcdir)/index.cache.bz2; then \\\n"; joachim99@14: $lines .= "\techo \$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; joachim99@14: $lines .= "\t\$(INSTALL_DATA) \$(srcdir)/index.cache.bz2 \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/; \\\n"; joachim99@2: $lines .= "\tfi\n"; joachim99@2: $lines .= "\t-rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n"; joachim99@2: $lines .= "\t\$(LN_S) \$(kde_libs_htmldir)/$kdelang/common \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/common\n"; joachim99@2: joachim99@2: $lines .= "\n"; joachim99@2: $lines .= "uninstall-docs:\n"; joachim99@2: $lines .= "\t-rm -rf \$(kde_htmldir)/$kdelang/$appname\n"; joachim99@2: $lines .= "\n"; joachim99@2: $lines .= "clean-docs:\n"; joachim99@2: $lines .= "\t-rm -f index.cache.bz2\n"; joachim99@2: $lines .= "\n"; joachim99@2: $target_adds{"install-data-am"} .= "install-docs "; joachim99@2: $target_adds{"uninstall"} .= "uninstall-docs "; joachim99@2: $target_adds{"clean-am"} .= "clean-docs "; joachim99@2: appendLines ($lines); joachim99@2: } else { joachim99@2: appendLines("docs-am: $files\n"); joachim99@2: } joachim99@2: joachim99@14: $target_adds{"install-data-am"} .= "install-nls "; joachim99@2: $target_adds{"uninstall"} .= "uninstall-nls "; joachim99@2: joachim99@2: $tmp = "install-nls:\n"; joachim99@2: $tmp .= "\t\$(mkinstalldirs) \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname\n"; joachim99@2: $tmp .= "\t\@for base in $files; do \\\n"; joachim99@2: $tmp .= "\t echo \$(INSTALL_DATA) \$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; joachim99@2: $tmp .= "\t \$(INSTALL_DATA) \$(srcdir)/\$\$base \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; joachim99@2: $tmp .= "\tdone\n"; joachim99@2: if ($appname eq 'common') { joachim99@2: $tmp .= "\t\@echo \"merging common and language specific dir\" ;\\\n"; joachim99@14: $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"; joachim99@2: $tmp .= "\t\@com_files=`cd \$(kde_htmldir)/en/common && echo *` ;\\\n"; joachim99@2: $tmp .= "\tcd \$(DESTDIR)\$(kde_htmldir)/$kdelang/common ;\\\n"; joachim99@2: $tmp .= "\tif test -n \"\$\$com_files\"; then for p in \$\$com_files ; do \\\n"; joachim99@2: $tmp .= "\t case \" $files \" in \\\n"; joachim99@2: $tmp .= "\t *\" \$\$p \"*) ;; \\\n"; joachim99@14: $tmp .= "\t *) test ! -f \$\$p && echo \$(LN_S) ../../en/common/\$\$p \$(DESTDIR)\$(kde_htmldir)/$kdelang/common/\$\$p && \$(LN_S) ../../en/common/\$\$p \$\$p ;; \\\n"; joachim99@2: $tmp .= "\t esac ; \\\n"; joachim99@2: $tmp .= "\tdone ; fi ; true\n"; joachim99@2: } joachim99@2: $tmp .= "\n"; joachim99@2: $tmp .= "uninstall-nls:\n"; joachim99@2: $tmp .= "\tfor base in $files; do \\\n"; joachim99@2: $tmp .= "\t rm -f \$(DESTDIR)\$(kde_htmldir)/$kdelang/$appname/\$\$base ;\\\n"; joachim99@2: $tmp .= "\tdone\n\n"; joachim99@2: appendLines ($tmp); joachim99@2: joachim99@2: $target_adds{"distdir"} .= "distdir-nls "; joachim99@2: joachim99@2: $tmp = "distdir-nls:\n"; joachim99@2: $tmp .= "\tfor file in $files; do \\\n"; joachim99@2: $tmp .= "\t cp \$(srcdir)/\$\$file \$(distdir); \\\n"; joachim99@2: $tmp .= "\tdone\n"; joachim99@2: joachim99@2: appendLines ($tmp); joachim99@2: joachim99@2: return 0; joachim99@2: joachim99@2: nodocs: joachim99@2: appendLines("docs-am:\n"); joachim99@2: return 1; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: # Find headers in any of the source directories specified previously, that joachim99@2: # are candidates for "moc-ing". joachim99@2: sub findMocCandidates () joachim99@2: { joachim99@2: foreach $dir (@headerdirs) joachim99@2: { joachim99@2: my @list = (); joachim99@2: opendir (SRCDIR, "$dir"); joachim99@2: @hFiles = grep { /.+\.$hExt$/o && !/^\./ } readdir(SRCDIR); joachim99@2: closedir SRCDIR; joachim99@2: foreach $hf (@hFiles) joachim99@2: { joachim99@2: next if ($hf =~ /^\.\#/); joachim99@2: $hf =~ /(.*)\.[^\.]*$/; # Find name minus extension joachim99@2: next if ($uiFiles{$1}); joachim99@2: open (HFIN, "$dir/$hf") || die "Could not open $dir/$hf: $!\n"; joachim99@2: my $hfsize = 0; joachim99@2: seek(HFIN, 0, 2); joachim99@2: $hfsize = tell(HFIN); joachim99@2: seek(HFIN, 0, 0); joachim99@2: read HFIN, $hfData, $hfsize; joachim99@2: close HFIN; joachim99@2: # push (@list, $hf) if(index($hfData, "Q_OBJECT") >= 0); ### fast but doesn't handle //Q_OBJECT joachim99@14: # handle " { friend class blah; Q_OBJECT ", but don't match antlarr_Q_OBJECT (\b). joachim99@14: if ( $hfData =~ /{([^}]*)\bQ_OBJECT/s ) { joachim99@14: push (@list, $hf) unless $1 =~ m://[^\n]*Q_OBJECT[^\n]*$:s; ## reject "// Q_OBJECT" joachim99@2: } joachim99@2: } joachim99@2: # The assoc array of root of headerfile and header filename joachim99@2: foreach $hFile (@list) joachim99@2: { joachim99@2: $hFile =~ /(.*)\.[^\.]*$/; # Find name minus extension joachim99@2: if ($mocFiles{$1}) joachim99@2: { joachim99@2: print STDERR "Warning: Multiple header files found for $1\n"; joachim99@2: next; # Use the first one joachim99@2: } joachim99@2: $mocFiles{$1} = "$dir\035$hFile"; # Add relative dir joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: return 0; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # The programmer has specified a moc list. Prune out the moc candidates joachim99@2: # list that we found based on looking at the header files. This generates joachim99@2: # a warning if the programmer gets the list wrong, but this doesn't have joachim99@2: # to be fatal here. joachim99@2: sub pruneMocCandidates ($) joachim99@2: { joachim99@2: my %prunedMoc = (); joachim99@2: local @mocList = split(' ', $_[0]); joachim99@2: joachim99@2: foreach $mocname (@mocList) joachim99@2: { joachim99@2: $mocname =~ s/\.moc$//; joachim99@2: if ($mocFiles{$mocname}) joachim99@2: { joachim99@2: $prunedMoc{$mocname} = $mocFiles{$mocname}; joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: my $print = $makefileDir; joachim99@2: $print =~ s/^\Q$topdir\E\\//; joachim99@2: # They specified a moc file but we can't find a header that joachim99@2: # will generate this moc file. That's possible fatal! joachim99@2: print STDERR "Warning: No moc-able header file for $print/$mocname\n"; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: undef %mocFiles; joachim99@2: %mocFiles = %prunedMoc; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Finds the cpp files (If they exist). joachim99@2: # The cpp files get appended to the header file separated by \035 joachim99@2: sub checkMocCandidates () joachim99@2: { joachim99@2: my @cppFiles; joachim99@2: my $cpp2moc; # which c++ file includes which .moc files joachim99@2: my $moc2cpp; # which moc file is included by which c++ files joachim99@2: joachim99@2: return unless (keys %mocFiles); joachim99@2: opendir(THISDIR, ".") || return; joachim99@2: @cppFiles = grep { /.+\.$cppExt$/o && !/.+\.moc\.$cppExt$/o joachim99@2: && !/.+\.all_$cppExt\.$cppExt$/o joachim99@2: && !/^\./ } readdir(THISDIR); joachim99@2: closedir THISDIR; joachim99@2: return unless (@cppFiles); joachim99@2: my $files = join (" ", @cppFiles); joachim99@2: $cpp2moc = {}; joachim99@2: $moc2cpp = {}; joachim99@2: foreach $cxxf (@cppFiles) joachim99@2: { joachim99@2: open (CXXFIN, $cxxf) || die "Could not open $cxxf: $!\n"; joachim99@2: seek(CXXFIN, 0, 2); joachim99@2: my $cxxfsize = tell(CXXFIN); joachim99@2: seek(CXXFIN, 0, 0); joachim99@2: read CXXFIN, $cxxfData, $cxxfsize; joachim99@2: close CXXFIN; joachim99@2: while(($cxxfData =~ m/^[ \t]*\#include\s*[<\"](.*\.moc)[>\"]/gm)) { joachim99@2: $cpp2moc->{$cxxf}->{$1} = 1; joachim99@2: $moc2cpp->{$1}->{$cxxf} = 1; joachim99@2: } joachim99@2: } joachim99@2: foreach my $mocFile (keys (%mocFiles)) joachim99@2: { joachim99@2: @cppFiles = keys %{$moc2cpp->{"$mocFile.moc"}}; joachim99@2: if (@cppFiles == 1) { joachim99@2: $mocFiles{$mocFile} .= "\035" . $cppFiles[0]; joachim99@14: push(@depend, $mocFile); joachim99@2: } elsif (@cppFiles == 0) { joachim99@2: push (@newObs, $mocFile); # Produce new object file joachim99@2: next if ($haveAutomocTag); # This is expected... joachim99@2: # But this is an error we can deal with - let them know joachim99@2: print STDERR joachim99@2: "Warning: No c++ file that includes $mocFile.moc\n"; joachim99@2: } else { joachim99@2: # We can't decide which file to use, so it's fatal. Although as a joachim99@2: # guess we could use the mocFile.cpp file if it's in the list??? joachim99@2: print STDERR joachim99@2: "Error: Multiple c++ files that include $mocFile.moc\n"; joachim99@2: print STDERR "\t",join ("\t", @cppFiles),"\n"; joachim99@2: $errorflag = 1; joachim99@2: delete $mocFiles{$mocFile}; joachim99@2: # Let's continue and see what happens - They have been told! joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Add the rules for generating moc source from header files joachim99@2: # For Automoc output *.moc.cpp but normally we'll output *.moc joachim99@2: # (We must compile *.moc.cpp separately. *.moc files are included joachim99@2: # in the appropriate *.cpp file by the programmer) joachim99@2: sub addMocRules () joachim99@2: { joachim99@2: my $cppFile; joachim99@2: my $hFile; joachim99@2: joachim99@2: foreach $mocFile (keys (%mocFiles)) joachim99@2: { joachim99@2: undef $cppFile; joachim99@2: ($dir, $hFile, $cppFile) = split ("\035", $mocFiles{$mocFile}, 3); joachim99@2: $dir =~ s#^\.#\$(srcdir)#; joachim99@2: if (defined ($cppFile)) joachim99@2: { joachim99@14: $cppFile =~ s,\.[^.]*$,,; joachim99@14: $target_adds{"$cppFile.o"} .= "$mocFile.moc "; joachim99@14: $target_adds{"$cppFile.lo"} .= "$mocFile.moc "; joachim99@14: appendLines ("$mocFile.moc: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile.moc\n"); joachim99@14: $cleanMoc .= " $mocFile.moc"; joachim99@14: appendLines ("mocs: $mocFile.moc\n"); joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: appendLines ("$mocFile$mocExt: $dir/$hFile\n\t\$(MOC) $dir/$hFile -o $mocFile$mocExt\n"); joachim99@2: $cleanMoc .= " $mocFile$mocExt"; joachim99@14: appendLines ("mocs: $mocFile$mocExt\n"); joachim99@2: } joachim99@2: } joachim99@2: } joachim99@2: joachim99@14: sub make_bcheck_target() joachim99@14: { joachim99@14: my $lookup = 'RECURSIVE_TARGETS\s*=[ \t]*(.*)'; joachim99@14: my $bcheckdep = "bcheck-am"; joachim99@14: $bcheckdep = "bcheck-recursive" if ($MakefileData =~ /\n$lookup/); joachim99@14: joachim99@14: my $headers= ""; joachim99@14: $headers = $1 if($MakefileData =~ /\nHEADERS\s*=[ \t]*(.+)/); joachim99@14: $headers =~ s/\$\((?:noinst|EXTRA)_HEADERS\)//g; joachim99@14: joachim99@14: $target_adds{"clean-am"} .= "clean-bcheck "; joachim99@14: joachim99@14: my $t = "clean-bcheck: \n" . joachim99@14: "\trm -f *.bchecktest.cc *.bchecktest.cc.class a.out\n\n" . joachim99@14: "bcheck: $bcheckdep\n\n" . joachim99@14: "bcheck-am:\n" . joachim99@14: "\t\@for i in $headers; do \\\n" . joachim99@14: "\t if test \$(srcdir)/\$\$i -nt \$\$i.bchecktest.cc; then \\\n" . joachim99@14: "\t echo \"int main() {return 0;}\" > \$\$i.bchecktest.cc ; \\\n" . joachim99@14: "\t echo \"#include \\\"\$\$i\\\"\" >> \$\$i.bchecktest.cc ; \\\n" . joachim99@14: "\t echo \"\$\$i\"; \\\n" . joachim99@14: "\t if ! "; joachim99@14: $t .= $cxxsuffix eq "KKK" ? joachim99@14: "\$(CXX) \$(DEFS) -I. -I\$(srcdir) -I\$(top_builddir) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS) \$(KDE_CXXFLAGS) " : joachim99@14: "\$(CXXCOMPILE) "; joachim99@14: $t .= " --dump-class-hierarchy \$\$i.bchecktest.cc; then \\\n" . joachim99@14: "\t rm -f \$\$i.bchecktest.cc; exit 1; \\\n" . joachim99@14: "\t fi ; \\\n" . joachim99@14: "\t echo \"\" >> \$\$i.bchecktest.cc.class; \\\n" . joachim99@14: "\t perl \$(top_srcdir)/admin/bcheck.pl \$\$i.bchecktest.cc.class || { rm -f \$\$i.bchecktest.cc; exit 1; }; \\\n" . joachim99@14: "\t rm -f a.out; \\\n" . joachim99@14: "\t fi ; \\\n" . joachim99@14: "\tdone\n"; joachim99@14: appendLines("$t\n"); joachim99@14: } joachim99@14: joachim99@2: sub make_meta_classes () joachim99@2: { joachim99@2: return if ($kdeopts{"qtonly"}); joachim99@2: joachim99@2: my $cppFile; joachim99@2: my $hFile; joachim99@2: my $moc_class_headers = ""; joachim99@2: foreach $program (@programs) { joachim99@2: my $mocs = ""; joachim99@14: my @progsources = split(/[\034\s]+/, $sources{$program}); joachim99@14: my @depmocs = split(' ', $dependmocs{$program}); joachim99@2: my %shash = (), %mhash = (); joachim99@2: @shash{@progsources} = 1; # we are only interested in the existence joachim99@2: @mhash{@depmocs} = 1; joachim99@2: joachim99@2: print STDOUT "program=$program\n" if ($verbose); joachim99@2: print STDOUT "psources=[".join(' ', keys %shash)."]\n" if ($verbose); joachim99@2: print STDOUT "depmocs=[".join(' ', keys %mhash)."]\n" if ($verbose); joachim99@2: print STDOUT "globalmocs=[".join(' ', keys(%globalmocs))."]\n" if ($verbose); joachim99@2: foreach my $mocFile (keys (%globalmocs)) joachim99@2: { joachim99@14: my ($dir, $hFile, $cppFile) = split ("\035", $globalmocs{$mocFile}, 3); joachim99@2: if (defined ($cppFile)) joachim99@2: { joachim99@2: $mocs .= " $mocFile.moc" if exists $shash{$cppFile}; joachim99@2: } joachim99@2: else joachim99@2: { joachim99@2: # Bah. This is the case, if no C++ file includes the .moc joachim99@2: # file. We make a .moc.cpp file for that. Unfortunately this joachim99@2: # is not included in the %sources hash, but rather is mentioned joachim99@14: # in %dependmocs. If the user wants to use AUTO he can't just joachim99@2: # use an unspecific METAINCLUDES. Instead he must use joachim99@2: # program_METAINCLUDES. Anyway, it's not working real nicely. joachim99@2: # E.g. Its not clear what happens if user specifies two joachim99@2: # METAINCLUDES=AUTO in the same Makefile.am. joachim99@2: $mocs .= " $mocFile.moc.$cxxsuffix" joachim99@2: if exists $mhash{$mocFile.".moc.$cxxsuffix"}; joachim99@2: } joachim99@2: } joachim99@2: if ($mocs) { joachim99@2: print STDOUT "==> mocs=[".$mocs."]\n" if ($verbose); joachim99@2: } joachim99@2: print STDOUT "\n" if $verbose; joachim99@2: } joachim99@2: if ($moc_class_headers) { joachim99@2: appendLines ("$cleantarget-moc-classes:\n\t-rm -f $moc_class_headers\n"); joachim99@2: $target_adds{"$cleantarget-am"} .= "$cleantarget-moc-classes "; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: sub updateMakefile () joachim99@2: { joachim99@2: return if ($dryrun); joachim99@2: joachim99@2: open (FILEOUT, "> $makefile") joachim99@2: || die "Could not create $makefile: $!\n"; joachim99@2: joachim99@14: $MakefileData =~ s/\034/\\\n/g; # Restore continuation lines joachim99@14: # Append our $progId line, _below_ the "generated by automake" line joachim99@14: # because automake-1.6 relies on the first line to be his own. joachim99@14: my $progIdLine = "\# $progId - " . '$Revision$ '."\n"; joachim99@14: if ( !( $MakefileData =~ s/^(.*generated .*by automake.*\n)/$1$progIdLine/ ) ) { joachim99@14: warn "automake line not found in $makefile\n"; joachim99@14: # Fallback: first line joachim99@14: print FILEOUT $progIdLine; joachim99@14: }; joachim99@2: print FILEOUT $MakefileData; joachim99@2: close FILEOUT; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # The given line needs to be removed from the makefile joachim99@2: # Do this by adding the special "removed line" comment at the line start. joachim99@2: sub removeLine ($$) joachim99@2: { joachim99@2: my ($lookup, $old) = @_; joachim99@2: joachim99@2: $old =~ s/\034/\\\n#>- /g; # Fix continuation lines joachim99@2: $MakefileData =~ s/\n$lookup/\n#>\- $old/; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Replaces the old line with the new line joachim99@2: # old line(s) are retained but tagged as removed. The new line(s) have the joachim99@2: # "added" tag placed before it. joachim99@2: sub substituteLine ($$) joachim99@2: { joachim99@2: my ($lookup, $new) = @_; joachim99@2: joachim99@2: if ($MakefileData =~ /\n($lookup)/) { joachim99@2: $old = $1; joachim99@2: $old =~ s/\034/\\\n#>\- /g; # Fix continuation lines joachim99@14: my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1; joachim99@14: $new =~ s/\\\n/\034/g; joachim99@2: $MakefileData =~ s/\n$lookup/\n#>- $old\n#>\+ $newCount\n$new/; joachim99@2: } else { joachim99@14: warn "Warning: substitution of \"$lookup\" in $printname failed\n"; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Slap new lines on the back of the file. joachim99@2: sub appendLines ($) joachim99@2: { joachim99@2: my ($new) = @_; joachim99@14: my $copynew = $new; joachim99@14: my $newCount = ($new =~ tr/\034//) + ($new =~ tr/\n//) + 1; joachim99@14: $new =~ s/\\\n/\034/g; # Fix continuation lines joachim99@2: $MakefileData .= "\n#>\+ $newCount\n$new"; joachim99@2: } joachim99@2: joachim99@2: #----------------------------------------------------------------------------- joachim99@2: joachim99@2: # Restore the Makefile.in to the state it was before we fiddled with it joachim99@2: sub restoreMakefile () joachim99@2: { joachim99@2: $MakefileData =~ s/# $progId[^\n\034]*[\n\034]*//g; joachim99@2: # Restore removed lines joachim99@2: $MakefileData =~ s/([\n\034])#>\- /$1/g; joachim99@2: # Remove added lines joachim99@2: while ($MakefileData =~ /[\n\034]#>\+ ([^\n\034]*)/) joachim99@2: { joachim99@2: my $newCount = $1; joachim99@2: my $removeLines = ""; joachim99@2: while ($newCount--) { joachim99@2: $removeLines .= "[^\n\034]*([\n\034]|)"; joachim99@2: } joachim99@2: $MakefileData =~ s/[\n\034]#>\+.*[\n\034]$removeLines/\n/; joachim99@2: } joachim99@2: } joachim99@2: joachim99@2: #-----------------------------------------------------------------------------