📄 am_edit
字号:
#!/usr/bin/perl -w# Expands the specialised KDE tags in Makefile.in to (hopefully) valid# make syntax.# When called without file parameters, we work recursively on all Makefile.in# in and below the current subdirectory. When called with file parameters,# only those Makefile.in are changed.# The currently supported tags are## {program}_METASOURCES# where you have a choice of two styles# {program}_METASOURCES = name1.moc name2.moc ... [\]# {program}_METASOURCES = AUTO# The second style requires other tags as well.## To install icons :# KDE_ICON = iconname iconname2 ...# KDE_ICON = AUTO## For documentation :# http://developer.kde.org/documentation/other/developer-faq.html## and more new tags TBD!## The concept (and base code) for this program came from automoc,# supplied by the following## Matthias Ettrich <ettrich@kde.org> (The originator)# Kalle Dalheimer <kalle@kde.org> (The original implementator)# Harri Porten <porten@tu-harburg.de># Alex Zepeda <jazepeda@pacbell.net># David Faure <faure@kde.org># Stephan Kulow <coolo@kde.org>use Cwd;use File::Find;use File::Basename;# Prototype the functionssub initialise ();sub processMakefile ($);sub updateMakefile ();sub restoreMakefile ();sub removeLine ($$);sub appendLines ($);sub substituteLine ($$);sub findMocCandidates ();sub pruneMocCandidates ($);sub checkMocCandidates ();sub addMocRules ();sub tag_AUTOMAKE ();sub tag_META_INCLUDES ();sub tag_METASOURCES ();sub tag_POFILES ();sub tag_DOCFILES ();sub tag_LOCALINSTALL();sub tag_IDLFILES();sub tag_UIFILES();sub tag_SUBDIRS();sub tag_ICON();sub tag_CLOSURE();sub tag_NO_UNDEFINED();sub tag_DIST();# Some global globals...$verbose = 0; # a debug flag$thisProg = "$0"; # This programs name$topdir = cwd(); # The current directory@makefiles = (); # Contains all the files we'll process@foreignfiles = ();$start = (times)[0]; # some stats for testing - comment out for release$version = "v0.2";$errorflag = 0;$cppExt = "(cpp|cc|cxx|C|c\\+\\+)";$hExt = "(h|H|hh|hxx|hpp|h\\+\\+)";$progId = "KDE tags expanded automatically by " . basename($thisProg);$automkCall = "\n";$printname = ""; # used to display the directory the Makefile is in$use_final = 1; # create code for --enable-final$cleantarget = "clean";$dryrun = 0;$pathoption = 0;$foreign_libtool = 0;while (defined ($ARGV[0])){ $_ = shift; if (/^--version$/) { print STDOUT "\n"; print STDOUT basename($thisProg), " $version\n", "This is really free software, unencumbered by the GPL.\n", "You can do anything you like with it except sueing me.\n", "Copyright 1998 Kalle Dalheimer <kalle\@kde.org>\n", "Concept, design and unnecessary questions about perl\n", " by Matthias Ettrich <ettrich\@kde.org>\n\n", "Making it useful by Stephan Kulow <coolo\@kde.org> and\n", "Harri Porten <porten\@kde.org>\n", "Updated (Feb-1999), John Birch <jb.nz\@writeme.com>\n", "Current Maintainer Stephan Kulow\n\n"; exit 0; } elsif (/^--verbose$|^-v$/) { $verbose = 1; # Oh is there a problem...? } elsif (/^-p(.+)$|^--path=(.+)$/) { $thisProg = "$1/".basename($thisProg) if($1); $thisProg = "$2/".basename($thisProg) if($2); warn ("$thisProg doesn't exist\n") if (!(-f $thisProg)); $pathoption=1; } elsif (/^--help$|^-h$/) { print STDOUT "Usage $thisProg [OPTION] ... [dir/Makefile.in]...\n", "\n", "Patches dir/Makefile.in generated by automake\n", "(where dir can be an absolute or relative directory name)\n", "\n", " -v, --verbose verbosely list files processed\n", " -h, --help print this help, then exit\n", " --version print version number, then exit\n", " -p, --path= use the path to am_edit if the path\n", " called from is not the one to be used\n", " --no-final don't patch for --enable-final\n"; exit 0; } elsif (/^--no-final$/) { $use_final = 0; $thisProg .= " --no-final"; } elsif (/^--foreign-libtool$/) { $foreign_libtool = 1; $thisProg .= " --foreign-libtool"; } elsif (/^-n$/) { $dryrun = 1; } else { # user selects what input files to check # add full path if relative path is given $_ = cwd()."/".$_ if (! /^\//); print "User wants $_\n" if ($verbose); push (@makefiles, $_); }}if ($thisProg =~ /^\// && !$pathoption ){ print STDERR "Illegal full pathname call performed...\n", "The call to \"$thisProg\"\nwould be inserted in some Makefile.in.\n", "Please use option --path.\n"; exit 1;}# Only scan for files when the user hasn't entered dataif (!@makefiles){ print STDOUT "Scanning for Makefile.in\n" if ($verbose); find (\&add_makefile, cwd()); #chdir('$topdir');} else { print STDOUT "Using input files specified by user\n" if ($verbose);}foreach $makefile (sort(@makefiles)){ processMakefile ($makefile); last if ($errorflag);}# Just some debug statistics - comment out for release as it uses printf.printf STDOUT "Time %.2f CPU sec\n", (times)[0] - $start if ($verbose);exit $errorflag; # causes make to fail if erroflag is set#-----------------------------------------------------------------------------# In conjunction with the "find" call, this builds the list of input filessub add_makefile (){ push (@makefiles, $File::Find::name) if (/Makefile.in$/);}#-----------------------------------------------------------------------------# Processes a single make file# The parameter contains the full path name of the Makefile.in to usesub processMakefile ($){ # some useful globals for the subroutines called here local ($makefile) = @_; local @headerdirs = ('.'); local $haveAutomocTag = 0; local $MakefileData = ""; local $cxxsuffix = "KKK"; local @programs = (); # lists the names of programs and libraries local $program = ""; local %realObjs = (); # lists the objects compiled into $program local %sources = (); # lists the sources used for $program local %finalObjs = (); # lists the objects compiled when final local %realname = (); # the binary name of program variable local %idlfiles = (); # lists the idl files used for $program local %globalmocs = ();# list of all mocfiles (in %mocFiles format) local %important = (); # list of files to be generated asap local %uiFiles = (); local $allidls = ""; local $idl_output = "";# lists all idl generated files for cleantarget local $ui_output = "";# lists all uic generated files for cleantarget local %depedmocs = (); local $metasourceTags = 0; local $dep_files = ""; local $dep_finals = ""; local %target_adds = (); # the targets to add local $kdelang = ""; local @cleanfiles = (); local $cleanMoc = ""; local $closure_output = ""; local %varcontent = (); $makefileDir = dirname($makefile); chdir ($makefileDir); $printname = $makefile; $printname =~ s/^\Q$topdir\E\///; $makefile = basename($makefile); print STDOUT "Processing makefile $printname\n" if ($verbose); # Setup and see if we need to do this. return if (!initialise()); tag_AUTOMAKE (); # Allows a "make" to redo the Makefile.in tag_META_INCLUDES (); # Supplies directories for src locations foreach $program (@programs) { $sources_changed{$program} = 0; $depedmocs{$program} = ""; $important{$program} = ""; tag_IDLFILES(); # Sorts out idl rules tag_NO_UNDEFINED(); tag_CLOSURE(); tag_UIFILES(); # Sorts out ui rules tag_METASOURCES (); # Sorts out the moc rules if ($sources_changed{$program}) { my $lookup = "$program" . '_SOURCES\s*=\s*(.*)'; substituteLine($lookup, "$program\_SOURCES=" . $sources{$program}); } if ($important{$program}) { local %source_dict = (); for $source (split(/[\034\s]+/, $sources{$program})) { $source_dict{$source} = 1; } for $source (@cleanfiles) { $source_dict{$source} = 0; } for $source (keys %source_dict) { next if (!$source); if ($source_dict{$source}) { # sanity check if (! -f $source) { print STDERR "Error: $source is listed in a _SOURCE line in $printname, but doesn't exist yet. Put it in DISTCLEANFILES!\n"; } else { $target_adds{"\$(srcdir)/$source"} .= $important{$program}; } } } } } if ($cleanMoc) { # Always add dist clean tag # Add extra *.moc.cpp files created for USE_AUTOMOC because they # aren't included in the normal *.moc clean rules. appendLines ("$cleantarget-metasources:\n\t-rm -f $cleanMoc\n"); $target_adds{"$cleantarget-am"} .= "$cleantarget-metasources "; } tag_DIST() unless ($kdeopts{"noautodist"}); if ($idl_output) { appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n"); $target_adds{"$cleantarget-am"} .= "$cleantarget-idl "; } if ($ui_output) { appendLines ("$cleantarget-ui:\n\t-rm -f $ui_output\n"); $target_adds{"$cleantarget-am"} .= "$cleantarget-ui "; } if ($closure_output) { appendLines ("$cleantarget-closures:\n\t-rm -f $closure_output\n"); $target_adds{"$cleantarget-am"} .= "$cleantarget-closures "; } if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\s*\n/) { $kdelang = '$(KDE_LANG)' } else { $kdelang = ''; } tag_POFILES (); # language rules for po directory tag_DOCFILES (); # language rules for doc directories tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs tag_ICON(); tag_SUBDIRS(); my $tmp = "force-reedit:\n"; $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n"; appendLines($tmp); make_bcheck_target(); make_meta_classes(); tag_COMPILE_FIRST(); tag_FINAL() if (!$kdeopts{"nofinal"}); my $final_lines = "final:\n\t\$(MAKE) "; my $final_install_lines = "final-install:\n\t\$(MAKE) "; my $nofinal_lines = "no-final:\n\t\$(MAKE) "; my $nofinal_install_lines = "no-final-install:\n\t\$(MAKE) "; foreach $program (@programs) { my $lookup = "$program\_OBJECTS.*=[^\n]*"; my $new = ""; my @list = split(/[\034\s]+/, $realObjs{$program}); if (!$kdeopts{"nofinal"} && @list > 1 && $finalObjs{$program}) { $new .= "$program\_final\_OBJECTS = " . $finalObjs{$program}; $new .= "\n$program\_nofinal\_OBJECTS = " . $realObjs{$program}; $new .= "\n\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = \$($program\_nofinal\_OBJECTS)"; $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = \$($program\_final\_OBJECTS)"; $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; $final_install_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; $nofinal_lines .= "$program\_OBJECTS=\"\$($program\_nofinal\_OBJECTS)\" "; $nofinal_install_lines .= "$program\_OBJECTS=\"\$($program\_nofinal_OBJECTS)\" "; } else { $new = "$program\_OBJECTS = " . $realObjs{$program}; } substituteLine ($lookup, $new); } appendLines($final_lines . "all-am"); appendLines($final_install_lines . "install-am"); appendLines($nofinal_lines . "all-am"); appendLines($nofinal_install_lines . "install-am"); my $lookup = '(\@\S+\@)?DEP_FILES\s*=([^\n]*)'; if ($MakefileData =~ /\n$lookup\n/o) { my $condition = $1; my $depfiles = $2; my $workfiles; if ($dep_finals) { # Add the conditions on every line, since # there may be line continuations in the list. $workfiles = "$dep_files $dep_finals $depfiles"; $workfiles =~ s/\034/\034$condition\@KDE_USE_FINAL_TRUE\@\t/g; $lines = "$condition\@KDE_USE_FINAL_TRUE\@DEP_FILES = $workfiles\n";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -