📄 am_edit
字号:
#!/usr/bin/perl# Expands the specilised 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 :# ...## 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 <garbanzo@hooked.net># David Faure <faure@kde.org># Stephan Kulow <coolo@kde.org>## I've puddled around with automoc and produced something different# 1999-02-01 John Birch <jb.nz@writeme.com># * Rewritten automoc to cater for more than just moc file expansion# Version 0.01 does the same as automoc at this stage.# 1999-02-18 jb# * We must always write a Makefile.in file out even if we fail# because we need the "perl autokmake" in the AUTOMAKE so that a# "make" will regenerate the Makefile.in correctly.# Reworked moc file checking so that missing includes in cpp# will work and includes in cpp when using use_automoc will also# work.# 1999-02-23 jb# * Added POFILE processing and changed the USE_AUTOMOC tag to# AUTO instead.# ... See ChangeLog for more logsuse 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_TOPLEVEL();sub tag_SUBDIRS();sub tag_ICON();sub tag_CLOSURE();# 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++"; # used by grep$hExt = "*.h *.H *.hh *.hxx *.h++"; # used by grep$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;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 from automake\n", "(where dir can be a full or relative directory name)", "\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", " --no-final don't patch for --enable-final\n", " called from is not the one to be used\n"; exit 0; } elsif (/^--no-final$/) { $use_final = 0; $thisProg .= " --no-final"; } 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 user enter input files\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 $allidls = ""; local $idl_output = "";# lists all idl generated files for cleantarget local %depedmocs = (); local $metasourceTags = 0; local $dep_files = ""; local $dep_finals = ""; local %target_adds = (); # the targets to add local $kdelang = ""; $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) { tag_METASOURCES (); # Sorts out the moc rules tag_IDLFILES(); # Sorts out idl rules tag_CLOSURE(); } if ($idl_output) { appendLines ("$cleantarget-idl:\n\t-rm -f $idl_output\n"); $target_adds{"$cleantarget-am"} .= "$cleantarget-idl "; } if ($MakefileData =~ /\nKDE_LANG\s*=\s*(\S*)\n/) { $kdelang = '$(KDE_LANG)' } else { $kdelang = ''; } tag_POFILES (); # language rules for po directory tag_DOCFILES (); # language rules for doc directories tag_TOPLEVEL (); # language rules for po toplevel tag_LOCALINSTALL(); # add $(DESTDIR) before all kde_ dirs tag_ICON(); my $tmp = "force-reedit:\n"; $tmp .= "\t$automkCall\n\tcd \$(top_srcdir) && perl $thisProg $printname\n\n"; appendLines($tmp); make_meta_classes(); tag_FINAL() if ($use_final); my $final_lines = "final:\n\t\$(MAKE) "; foreach $program (@programs) { my $lookup = "$program\_OBJECTS.*=[^\n]*"; my $new = ""; my @list = split(/[\034\s]+/, $realObjs{$program}); if ($use_final && @list > 1 && $finalObjs{$program}) { $new = "\@KDE_USE_FINAL_FALSE\@$program\_OBJECTS = " . $realObjs{$program}; $new .= "\n\@KDE_USE_FINAL_TRUE\@$program\_OBJECTS = " . $finalObjs{$program}; $new .= "\n$program\_final\_OBJECTS = " . $finalObjs{$program}; $final_lines .= "$program\_OBJECTS=\"\$($program\_final_OBJECTS)\" "; } else { $new = "$program\_OBJECTS = " . $realObjs{$program}; } substituteLine ($lookup, $new); } appendLines($final_lines . "all-am"); my $lookup = 'DEP_FILES\s*=([^\n]*)'; if ($MakefileData =~ /\n$lookup\n/) { $depfiles = $1; if ($dep_finals) { $lines = "\@KDE_USE_FINAL_TRUE\@DEP_FILES = $dep_files $dep_finals \034\t$depfiles\n"; $lines .= "\@KDE_USE_FINAL_FALSE\@DEP_FILES = $dep_files $depfiles\n"; } else { $lines = "DEP_FILES = $dep_files $depfiles\n"; } substituteLine($lookup, $lines); } my $cvs_lines = "cvs-clean:\n"; $cvs_lines .= "\t\$(MAKE) -f \$(top_srcdir)/admin/Makefile.common cvs-clean\n"; appendLines($cvs_lines); $cvs_lines = "kde-rpo-clean:\n"; $cvs_lines .= "\t-rm -f *.rpo\n"; appendLines($cvs_lines); $target_adds{"clean"} .= "kde-rpo-clean "; foreach $add (keys %target_adds) { my $lookup = "$add:\s*(.*)"; if ($MakefileData =~ /\n$lookup\n/) { substituteLine($lookup, "$add: " . $target_adds{$add} . $1); } } my $found = 1; while ($found) { if ($MakefileData =~ m/\n(.*)\$\(CXXFLAGS\)(.*)\n/) { my $vor = $1; my $nach = $2; my $lookup = quotemeta("$1\$(CXXFLAGS)$2"); my $replacement = "$1\$(KCXXFLAGS)$2"; $MakefileData =~ s/$lookup/$replacement/; $lookup =~ s/\\\$\\\(CXXFLAGS\\\)/\\\$\\\(KCXXFLAGS\\\)/; $replacement = "$vor\$(KCXXFLAGS) \$(KDE_CXXFLAGS)$nach"; substituteLine($lookup, $replacement); } else { $found = 0; } } $MakefileData =~ s/\$\(KCXXFLAGS\)/\$\(CXXFLAGS\)/g; # Always update the Makefile.in updateMakefile (); return;}#-----------------------------------------------------------------------------# Check to see whether we should process this make file.# This is where we look for tags that we need to process.# A small amount of initialising on the tags is also done here.# And of course we open and/or create the needed make files.sub initialise (){ if (! -r "Makefile.am") { print STDOUT "found Makefile.in without Makefile.am\n" if ($verbose); return 0; } # Checking for files to process... open (FILEIN, $makefile) || die "Could not open $makefileDir/$makefile: $!\n"; # Read the file while ( <FILEIN> ) { $MakefileData .= $_; } close FILEIN; # Remove the line continuations, but keep them marked # Note: we lose the trailing spaces but that's ok. $MakefileData =~ s/\\\s*\n/\034/g; # If we've processed the file before... restoreMakefile () if ($MakefileData =~ /$progId/); foreach $dir (@foreignfiles) { if (substr($makefileDir,0,length($dir)) eq $dir) { return 0; } } if ($MakefileData =~ /\nKDE_OPTIONS\s*=\s*([^\n]*)\n/) { my @kde_options = split(/[\s\034]/, $1); push(@foreignfiles, $makefileDir . "/"); return 0 if (grep(/^foreign$/, @kde_options)); # don't touch me } # Look for the tags that mean we should process this file. $metasourceTags = 0; $metasourceTags++ while ($MakefileData =~ /\n[^=#]*METASOURCES\s*=/g); my $pofileTag = 0; $pofileTag++ while ($MakefileData =~ /\nPOFILES\s*=/g); if ($pofileTag > 1) { print STDERR "Error: Only one POFILES tag allowed\n"; $errorflag = 1; } while ($MakefileData =~ /\n\.SUFFIXES:([^\n]+)\n/g) { my @list=split(' ', $1); my $extions = " " . $cppExt . " "; foreach $ext (@list) { if ($extions =~ / \*\Q$ext\E /) { $cxxsuffix = $ext; $cxxsuffix =~ s/\.//g; print STDOUT "will use suffix $cxxsuffix\n" if ($verbose); last;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -