From 90d985dd123974027ec2b4e7da30f744b803b6bd Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 2 Jan 2015 21:32:25 +0000 Subject: latexmk (2jan15) git-svn-id: svn://tug.org/texlive/trunk@35947 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/latexmk/latexmk.pl | 1857 +++++++++++++++----------- 1 file changed, 1041 insertions(+), 816 deletions(-) (limited to 'Master/texmf-dist/scripts/latexmk') diff --git a/Master/texmf-dist/scripts/latexmk/latexmk.pl b/Master/texmf-dist/scripts/latexmk/latexmk.pl index 95f302d82a1..1dbe4e7c00e 100755 --- a/Master/texmf-dist/scripts/latexmk/latexmk.pl +++ b/Master/texmf-dist/scripts/latexmk/latexmk.pl @@ -1,7 +1,14 @@ #!/usr/bin/env perl +# !!!!!!!!!! Don't forget to document $silence_logfile_warnings.!!! + # N.B. !!!!!!!!!!! See 17 July 2012 comments !!!!!!!!!!!!!!!!!! +# Re -cd issue !!!!!!!!!!!!! SEE "??!!" COMMENTS. +# If relative path is given for $out_dir or $aux_dir, and -cd is +# used, should it be interpreted w.r.t. initial cwd (i.e., cwd when +# latexmk is started), or w.r.t. to document directory??????? +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # On a UNIX-like system, the above enables latexmk to run independently # of the location of the perl executable. This line relies on the @@ -111,12 +118,13 @@ use warnings; $my_name = 'latexmk'; $My_name = 'Latexmk'; -$version_num = '4.39'; -$version_details = "$My_name, John Collins, 10 Nov 2013"; +$version_num = '4.41'; +$version_details = "$My_name, John Collins, 1 January 2015"; use Config; use File::Basename; use File::Copy; +use Cwd 'abs_path'; use File::Glob ':glob'; # Better glob. Does not use space as item separator. use File::Path 2.08 qw( make_path ); use FileHandle; @@ -147,8 +155,8 @@ else { warn "Something wrong with the perl configuration: No signals?\n"; } -## Copyright John Collins 1998-2013 -## (username collins at node phys.psu.edu) +## Copyright John Collins 1998-2015 +## (username jcc8 at node psu.edu) ## (and thanks to David Coppit (username david at node coppit.org) ## for suggestions) ## Copyright Evan McLean @@ -184,6 +192,50 @@ else { ## Modification log from 9 Dec 2011 onwards in detail ## ## 12 Jan 2012 STILL NEED TO DOCUMENT some items below +## +## 1 Jan 2015 John Collins V. 4.41 +## 18 Dec 2014 John Collins -c also deletes $deps_file if it is used. +## 16 Dec 2014 John Collins Finish change of e-mail +## 5 Dec 2014 John Collins Quote jobname when needed. +## 5 Sep 2014 John Collins Change my e-mail +## 30 Aug 2014 John Collins Change my e-mail +## 13 Aug 2014 John Collins Try to correct error handling to avoid +## repeated runs of latex after an error. +## Revert to some code from v. 4-32. +## Do I need $retry_msg? +## 8 Aug 2014 John Collins Fix up for the making of -eps-converted-to.pdf +## 4 Aug 2014 John Collins Sort and remove redundant xxx-undefined +## warning lines from log file. +## 23 Jul 2014 John Collins Fix failure when using both -cd and -output-directory +## 22 Jul 2014 John Collins If $HOME not set, then don't read ~/.latexmkrc +## Introduce $silence_logfile_warnings +## 21 Jul 2014 John Collins In setting $pscmd, allow for non-existent +### $ENV{USER} +## 29 May 2014 John Collins Correct sub Run for internal cmd w/o arguments +## 21 Mar 2014 John Collins Experimental: Add analysis hook for aux file. +## But I need to change rdb_create_rule in someway to +## allow correct handling of: (a) rule creation if +## rule doesn't exist, (b) either no change, or rule +## update, if the rule exists. No change is a bad +## idea, because conditions may change. Such a +## change, to effectively rdb_ensure_rule, would also +## help other dependencies, e.g., if a custom +## dependency has been created on one run of latexmk, +## and then on another run the definition is changed. +## With the old method, the old cus-dep is used unless +## the dependency cache fdb_latexmk is cleared; but +## with the new method the custom dependency will be +## changed correctly. +## 5 Mar 2014 John Collins System initialization files: allow them +## to be named latexmkrc as well as LatexMk, +## for more consistency with user directory +## names. Keep both cases, to preserve +## backward compatibility. +## 30 Jan 2014 John Collins Change sign-on message. Bug report info with help. V. 4.40a +## 15 Jan 2014 John Collins Fix failure to clean up correctly when +## root filename contains [, which is +## a glob metacharacter. +## V. 4.40 ## 10 Nov 2013 John Collins Change split / /, ... to split /\s*/, ... ## so as to be immune from extra white space. ## Clean up $clean_ext and $clean_full_ext by removing @@ -361,6 +413,17 @@ $log_wrap = 79; # (Documentation obviously needs to be improved!) %extra_rule_spec = (); + +# Hooks for customized extra processing on aux files. The following +# variable is an array of references to function. Each function is +# invoked in turn when a line of an aux file is processed (if none +# of the built-in actions have been done). On entry to the function, +# the following variables are set: +# $_ = current line of aux file +# $rule = name of rule during the invocation of which, the aux file +# was supposed to have been generated. +@aux_hooks = (); + ######################################################################### ## Default document processing programs, and related settings, ## These are mostly the same on all systems. @@ -620,6 +683,8 @@ $quote_filenames = 1; # Quote filenames in external commands $del_dir = ''; # Directory into which cleaned up files are to be put. # If $del_dir is '', just delete the files +@rc_system_files = (); + ######################################################################### ################################################################ @@ -665,6 +730,14 @@ $MSWin_fudge_break = 1; # Give special treatment to ctrl/C and ctrl/break # System-dependent overrides: +# Currently, the cases I have tests for are: MSWin32, cygwin, linux and +# darwin, with the main complications being for MSWin32 and cygwin. +# Special treatment may also be useful for MSYS (for which $^O reports +# "msys"). This is another *nix-emulation/system for MSWindows. At +# present it is treated as unix-like, but the environment variables +# are those of Windows. (The test for USERNAME as well as USER was +# to make latexmk work under MSYS's perl.) +# if ( $^O eq "MSWin32" ) { # Pure MSWindows configuration ## Configuration parameters: @@ -676,7 +749,7 @@ if ( $^O eq "MSWin32" ) { ## List of possibilities for the system-wide initialization file. ## The first one found (if any) is used. - @rc_system_files = ( 'C:/latexmk/LatexMk' ); + @rc_system_files = ( "C:/latexmk/LatexMk", "C:/latexmk/latexmkrc" ); $search_path_separator = ';'; # Separator of elements in search_path @@ -776,15 +849,19 @@ elsif ( $^O eq "cygwin" ) { ## List of possibilities for the system-wide initialization file. ## The first one found (if any) is used. ## We could stay with MSWin files here, since cygwin perl understands them - ## @rc_system_files = ( 'C:/latexmk/LatexMk' ); + ## @rc_system_files = ( 'C:/latexmk/LatexMk', 'C:/latexmk/latexmkrc' ); ## But they are deprecated in v. 1.7. So use the UNIX version, prefixed ## with a cygwin equivalent of the MSWin location - @rc_system_files = - ( '/cygdrive/c/latexmk/LatexMk', - '/opt/local/share/latexmk/LatexMk', - '/usr/local/share/latexmk/LatexMk', - '/usr/local/lib/latexmk/LatexMk' ); - + ## In addition, we need to add the same set of possible locations as with + ## unix, so that the user use a unix-style setup. + @rc_system_files = (); + foreach ( 'LatexMk', 'latexmkrc' ) { + push @rc_system_files, + ( "/cygdrive/c/latexmk/$_", + "/opt/local/share/latexmk/$_", + "/usr/local/share/latexmk/$_", + "/usr/local/lib/latexmk/$_" ); + } $search_path_separator = ';'; # Separator of elements in search_path # This is tricky. The search_path_separator depends on the kind # of executable: native NT v. cygwin. @@ -852,13 +929,15 @@ else { ## The first one found (if any) is used. ## Normally on a UNIX it will be in a subdirectory of /opt/local/share or ## /usr/local/share, depending on the local conventions. - ## /usr/local/lib/latexmk/LatexMk is put in the list for + ## But /usr/local/lib/latexmk is put in the list for ## compatibility with older versions of latexmk. - @rc_system_files = - ( '/opt/local/share/latexmk/LatexMk', - '/usr/local/share/latexmk/LatexMk', - '/usr/local/lib/latexmk/LatexMk' ); - + @rc_system_files = (); + foreach ( 'LatexMk', 'latexmkrc' ) { + push @rc_system_files, + ( "/opt/local/share/latexmk/$_", + "/usr/local/share/latexmk/$_", + "/usr/local/lib/latexmk/$_" ); + } $search_path_separator = ':'; # Separator of elements in search_path $dvi_update_signal = $signo{USR1} @@ -919,10 +998,21 @@ else { # # The following works on Solaris, LINUX, HP-UX, IRIX # Use -f to get full listing, including command line arguments. - # Use -u $ENV{CMD} to get all processes started by current user (not just + # Use -u $ENV{USER} to get all processes started by current user (not just # those associated with current terminal), but none of other users' # processes. - $pscmd = "ps -f -u $ENV{USER}"; + # However, the USER environment variable may not exist. Windows uses + # USERNAME instead. (And this propagates to a situation of + # unix-emulation software running under Windows.) + if ( exists $ENV{USER} ) { + $pscmd = "ps -f -u $ENV{USER}"; + } + elsif ( exists $ENV{USERNAME} ) { + $pscmd = "ps -f -u $ENV{USERNAME}"; + } + else { + $pscmd = "ps -f"; + } $pid_position = 1; # offset of PID in output of pscmd; first item is 0. if ( $^O eq "linux" ) { # Ps on Redhat (at least v. 7.2) appears to truncate its output @@ -974,12 +1064,12 @@ $max_repeat = 5; # Maximum times I repeat latex. Normally # occur, which mess up page numbers in the toc and lof, # Hence a 4th run is conceivably necessary. # At least one document class (JHEP.cls) works - # in such a way that a 4th run is needed. + # in such a way that a 4th run is needed. # We allow an extra run for safety for a - # maximum of 5. Needing further runs is - # usually an indication of a problem; further - # runs may not resolve the problem, and - # instead could cause an infinite loop. + # maximum of 5. Needing further runs is + # usually an indication of a problem; further + # runs may not resolve the problem, and + # instead could cause an infinite loop. $clean_ext = ""; # space separated extensions of files that are # to be deleted when doing cleanup, beyond # standard set @@ -1007,7 +1097,7 @@ $texfile_search = ""; # Specification for extra files to search for # backward compatibility. $fdb_ext = 'fdb_latexmk'; # Extension for the file for latexmk's - # file-database + # file-database # Make it long to avoid possible collisions. $fdb_ver = 3; # Version number for kind of fdb_file. @@ -1025,8 +1115,9 @@ $aux_dir = ''; # Directory for aux files (log, aux, etc). ## default flag settings. $recorder = 1; # Whether to use recorder option on latex/pdflatex -$silent = 0; # silence latex's messages? -$landscape_mode = 0; # default to portrait mode +$silent = 0; # Silence latex's messages? +$silence_logfile_warnings = 0; # Do list warnings in log file +$landscape_mode = 0; # default to portrait mode # The following two arrays contain lists of extensions (without # period) for files that are read in during a (pdf)LaTeX run but that @@ -1062,7 +1153,7 @@ $pdf_mode = 0; # No pdf file requested to be made by pdflatex # 2 to create pdf file by ps2pdf # 3 to create pdf file by dvipdf $view = 'default'; # Default preview is of highest of dvi, ps, pdf -$sleep_time = 2; # time to sleep b/w checks for file changes in -pvc mode +$sleep_time = 2; # time to sleep b/w checks for file changes in -pvc mode $banner = 0; # Non-zero if we have a banner to insert $banner_scale = 220; # Original default scale $banner_intensity = 0.95; # Darkness of the banner message @@ -1075,9 +1166,9 @@ $dependents_phony = 0; # Whether list(s) of dependencies includes phony targets $deps_file = '-'; # File for dependency list output. Default stdout. $rules_list = 0; # Whether to display list(s) of dependencies @dir_stack = (); # Stack of pushed directories, each of form of - # pointer to array [ cwd, good_cwd ], where - # good_cwd differs from cwd by being converted - # to native MSWin path when cygwin is used. + # pointer to array [ cwd, good_cwd ], where + # good_cwd differs from cwd by being converted + # to native MSWin path when cygwin is used. $cleanup_mode = 0; # No cleanup of nonessential LaTex-related files. # $cleanup_mode = 0: no cleanup # $cleanup_mode = 1: full cleanup @@ -1092,8 +1183,8 @@ $cleanup_includes_cusdep_generated = 0; # Determines whether cleanup deletes files generated by # (pdf)latex (found from \openout lines in log file). $diagnostics = 0; -$dvi_filter = ''; # DVI filter command -$ps_filter = ''; # Postscript filter command +$dvi_filter = ''; # DVI filter command +$ps_filter = ''; # Postscript filter command $force_mode = 0; # =1 to force processing past errors $go_mode = 0; # =1 to force processing regardless of time-stamps @@ -1124,6 +1215,7 @@ $waiting = 0; # Flags whether we are in loop waiting for an event # Used for some results of parsing log file: $reference_changed = 0; +$mult_defined = 0; $bad_reference = 0; $bad_citation = 0; @@ -1280,7 +1372,7 @@ if (!$BIBINPUTS) { $BIBINPUTS = '.'; } # Rule data: # 0: [ cmd_type, ext_cmd, int_cmd, test_kind, # source, dest, base, - # out_of_date, out_of_date_user, + # out_of_date, out_of_date_user, # time_of_last_run, time_of_last_file_check, # changed # last_result, last_message, @@ -1290,57 +1382,57 @@ if (!$BIBINPUTS) { $BIBINPUTS = '.'; } # cmd_type is 'primary', 'external', or 'cusdep' # ext_cmd is string for associated external command # with substitutions (%D for destination, %S - # for source, %B for base of current rule, - # %R for base of primary tex file, %T for - # texfile name, %O for options, + # for source, %B for base of current rule, + # %R for base of primary tex file, %T for + # texfile name, %O for options, # %Y for $aux_dir1, and %Z for $out_dir1 # int_cmd specifies any internal command to be - # used to implement the application of the - # rule. If this is present, it overrides - # the external command, and it is the - # responsibility of the perl subroutine - # specified in intcmd to execute the - # external command if this is appropriate. - # This variable intcmd is a reference to an array, + # used to implement the application of the + # rule. If this is present, it overrides + # the external command, and it is the + # responsibility of the perl subroutine + # specified in intcmd to execute the + # external command if this is appropriate. + # This variable intcmd is a reference to an array, # $$intcmd[0] = internal routine # $$intcmd[1...] = its arguments (if any) # test_kind specifies method of determining # whether a file is out-of-date: # 0 for never # 1 for usual: whether there is a source - # file change + # file change # 2 for dest earlier than source # 3 for method 2 at first run, 1 thereafter # (used when don't have file data from - # previous run). + # previous run). # source = name of primary source file, if any # dest = name of primary destination file, - # if any + # if any # base = base name, if any, of files for - # this rule + # this rule # out_of_date = 1 if it has been detected that - # this rule needs to be run - # (typically because a source - # file has changed). + # this rule needs to be run + # (typically because a source + # file has changed). # 0 otherwise # out_of_date_user is like out_of_date, except # that the detection of out-of-dateness # has been made from a change of a - # putative user file, i.e., one that is - # not a generated file (e.g., aux). This - # kind of out-of-dateness should provoke a - # rerun whether or not there was an error - # during a run of (pdf)LaTeX. Normally, - # if there is an error, one should wait - # for the user to correct the error. But - # it is possible the error condition is - # already corrected during the run, e.g., - # by the user changing a source file in - # response to an error message. + # putative user file, i.e., one that is + # not a generated file (e.g., aux). This + # kind of out-of-dateness should provoke a + # rerun whether or not there was an error + # during a run of (pdf)LaTeX. Normally, + # if there is an error, one should wait + # for the user to correct the error. But + # it is possible the error condition is + # already corrected during the run, e.g., + # by the user changing a source file in + # response to an error message. # time_of_last_run = time that this rule was - # last applied. (In standard units - # from perl, to be directly compared - # with file modification times.) + # last applied. (In standard units + # from perl, to be directly compared + # with file modification times.) # time_of_last_file_check = last time that a check # was made for changes in source files. # changed flags whether special changes have been made @@ -1445,8 +1537,10 @@ if ( $auto_rc_use ) { # System rc file: read_first_rc_file_in_list( @rc_system_files ); } -if ( $auto_rc_use ) { +if ( $auto_rc_use && ($HOME ne "" ) ) { # User rc file: + # N.B. $HOME equals "" if latexmk couldn't determine a home directory. + # In that case, we shouldn't look for an rc file there. read_first_rc_file_in_list( "$HOME/.latexmkrc" ); } if ( $auto_rc_use ) { @@ -1508,10 +1602,14 @@ while ($_ = $ARGV[0]) push @extra_latex_options, $1; push @extra_pdflatex_options, $1; } + elsif ( /^-logfilewarninglist$/ || /^-logfilewarnings$/ ) + { $silence_logfile_warnings = 0; } + elsif ( /^-logfilewarninglist-$/ || /^-logfilewarnings-$/ ) + { $silence_logfile_warnings = 1; } # See above for -M elsif (/^-MF$/) { if ( $ARGV[0] eq '' ) { - &exit_help( "No file name specified after -MF switch"); + &exit_help( "No file name specified after -MF switch"); } $deps_file = $ARGV[0]; shift; @@ -1629,37 +1727,37 @@ while ($_ = $ARGV[0]) &exit_help( "No RC file specified after -r switch"); } if ( -e $ARGV[0] ) { - process_rc_file( $ARGV[0] ); + process_rc_file( $ARGV[0] ); } else { - die "$My_name: RC file [$ARGV[0]] does not exist\n"; + die "$My_name: RC file [$ARGV[0]] does not exist\n"; } shift; } elsif (/^-bm$/) { if ( $ARGV[0] eq '' ) { - &exit_help( "No message specified after -bm switch"); + &exit_help( "No message specified after -bm switch"); } $banner = 1; $banner_message = $ARGV[0]; shift; } elsif (/^-bi$/) { if ( $ARGV[0] eq '' ) { - &exit_help( "No intensity specified after -bi switch"); + &exit_help( "No intensity specified after -bi switch"); } $banner_intensity = $ARGV[0]; shift; } elsif (/^-bs$/) { if ( $ARGV[0] eq '' ) { - &exit_help( "No scale specified after -bs switch"); + &exit_help( "No scale specified after -bs switch"); } $banner_scale = $ARGV[0]; shift; } elsif (/^-dF$/) { if ( $ARGV[0] eq '' ) { - &exit_help( "No dvi filter specified after -dF switch"); + &exit_help( "No dvi filter specified after -dF switch"); } $dvi_filter = $ARGV[0]; shift; @@ -1692,17 +1790,30 @@ if ( $bad_options > 0 ) { } warn "$My_name: This is $version_details, version: $version_num.\n", - "**** Report bugs etc to John Collins . ****\n" unless $silent; if ( ($out_dir ne '') && ($aux_dir eq '') ){ $aux_dir = $out_dir; } +# Initially $aux_dir and $out_dir are either absolute or relative to CURRENT +# directory. +# If we'll cd to directory of TeX file to do our work, we'll need to convert +# any relative directories to absolute, to preserve the user-requested +# directories after a cd. +# Otherwise, we need to normalize them in our standard way (to ensure +# standardization in the places we use them. + + foreach ($out_dir, $aux_dir) { - # Remove aliases to cwd: - $_ = normalize_filename( $_ ); - if ($_ eq '.' ) { $_ = ''; } + if ($do_cd) { + $_ = abs_path( $_ ); + } + else { + # Remove aliases to cwd: + $_ = normalize_filename( $_ ); + if ($_ eq '.' ) { $_ = ''; } + } } # Versions terminating in directory/path separator $out_dir1 = $out_dir; @@ -1725,7 +1836,7 @@ foreach ( 'BIBINPUTS' ) { $ENV{$_} = $aux_dir.$search_path_separator.$ENV{$_}; } else { - $ENV{$_} = $aux_dir.$search_path_separator; + $ENV{$_} = $aux_dir.$search_path_separator; } } @@ -1792,13 +1903,13 @@ else { # Make hash of excluded files, for easy checking: my %excl = (); foreach my $file (@excluded_file_list) { - $excl{$file} = ''; + $excl{$file} = ''; } foreach my $file (@file_list1) { - push( @file_list, $file) unless ( exists $excl{$file} ); + push( @file_list, $file) unless ( exists $excl{$file} ); } if ( !@file_list ) { - &exit_help( "No file name specified, and I couldn't find any"); + &exit_help( "No file name specified, and I couldn't find any"); } } @@ -1881,11 +1992,16 @@ if ( $recorder ) { add_option( "-recorder", \$latex, \$pdflatex ); } +# If the output and/or aux directories are specified: Fix the (pdf)latex +# commands to use them, and ensure that the directories exist. +# N.B. We are immune against cd'ing to directory of TeX file, because in +# that case we have forced the directories to be absolute. + if ( $out_dir ) { add_option( "-output-directory=\"$out_dir\"", \$latex, \$pdflatex ); if ( ! -e $out_dir ) { warn "$My_name: making output directory '$out_dir'\n" - if ! $silent; + if ! $silent; make_path $out_dir; } elsif ( ! -d $out_dir ) { @@ -1902,7 +2018,7 @@ if ( $aux_dir && ($aux_dir ne $out_dir) ) { add_option( "-aux-directory=\"$aux_dir\"", \$latex, \$pdflatex ); if ( ! -e $aux_dir ) { warn "$My_name: making auxiliary directory '$aux_dir'\n" - if ! $silent; + if ! $silent; make_path $aux_dir; } elsif ( ! -d $aux_dir ) { @@ -1913,7 +2029,7 @@ if ( $aux_dir && ($aux_dir ne $out_dir) ) { } if ( $jobname ne '' ) { - $jobstring = "--jobname=$jobname"; + $jobstring = "--jobname=\"$jobname\""; add_option( "$jobstring", \$latex, \$pdflatex ); } @@ -1965,7 +2081,7 @@ if ($print_type eq 'auto') { if ( $printout_mode ) { $one_time{'print'} = 1; if ($print_type eq 'none'){ - warn "$My_name: You have requested printout, but \$print_type is set to 'none'\n"; + warn "$My_name: You have requested printout, but \$print_type is set to 'none'\n"; } } if ( $preview_continuous_mode || $preview_mode ) { $one_time{'view'} = 1; } @@ -2010,15 +2126,15 @@ if ($aux_dir) { # Ensure $aux_dir is in TEXINPUTS search path. # This is used by dvips for files generated by mpost. if ( ! exists $ENV{TEXINPUTS} ) { - # Note the trailing ":" which ensures that the last item - # in the list of paths is the empty path, which actually - # means the default path, i.e., the following means that - # the TEXINPUTS search path is $aux_dir and the standard - # value. - $ENV{TEXINPUTS} = $aux_dir.$search_path_separator; + # Note the trailing ":" which ensures that the last item + # in the list of paths is the empty path, which actually + # means the default path, i.e., the following means that + # the TEXINPUTS search path is $aux_dir and the standard + # value. + $ENV{TEXINPUTS} = $aux_dir.$search_path_separator; } elsif ( $ENV{TEXINPUTS} !~ /$aux_dir$search_path_separator/ ) { - $ENV{TEXINPUTS} = $aux_dir.$search_path_separator.$ENV{TEXINPUTS}; + $ENV{TEXINPUTS} = $aux_dir.$search_path_separator.$ENV{TEXINPUTS}; } } @@ -2067,21 +2183,21 @@ foreach $filename ( @file_list ) pushd( $path ); } else { - $path = ''; + $path = ''; } ## remove extension from filename if was given. if ( &find_basename($filename, $root_filename, $texfile_name) ) { - if ( $force_mode ) { - warn "$My_name: Could not find file [$texfile_name]\n"; - } - else { + if ( $force_mode ) { + warn "$My_name: Could not find file [$texfile_name]\n"; + } + else { &ifcd_popd; - &exit_msg1( "Could not find file [$texfile_name]", - 11); - } + &exit_msg1( "Could not find file [$texfile_name]", + 11); + } } if ($jobname ne '' ) { $root_filename = $jobname; @@ -2120,11 +2236,11 @@ foreach $filename ( @file_list ) $base = $path.$base; if ( $rule =~ /^makeindex/ ) { push @index_bibtex_generated, $$Psource, $$Pdest, "$base.ilg"; - } + } elsif ( $rule =~ /^(bibtex|biber)/ ) { push @index_bibtex_generated, $$Pdest, "$base.blg"; push @aux_files, $$Psource; - } + } elsif ( exists $other_generated{$$Psource} ) { $other_generated{$$Pdest}; } @@ -2140,24 +2256,24 @@ foreach $filename ( @file_list ) if $diagnostics; # Variables set by parse_log. Can I remove them? local %generated_log = (); - local %dependents = (); # Maps files to status. Not used here. - local @bbl_files = (); # Not used here. - local %idx_files = (); # Maps idx_file to (ind_file, base). Not used here. - local %conversions = (); # (pdf)latex-performed conversions. Not used here. - # Maps output file created and read by (pdf)latex - # to source file of conversion. - local $primary_out = ''; # Actual output file (dvi or pdf). Not used here. + local %dependents = (); # Maps files to status. Not used here. + local @bbl_files = (); # Not used here. + local %idx_files = (); # Maps idx_file to (ind_file, base). Not used here. + local %conversions = (); # (pdf)latex-performed conversions. Not used here. + # Maps output file created and read by (pdf)latex + # to source file of conversion. + local $primary_out = ''; # Actual output file (dvi or pdf). Not used here. &parse_log; %other_generated = %generated_log; - } + } else { print "$My_name: No fdb or log file, so clean up default set of files ...\n" if $diagnostics; - } + } if ( ($go_mode == 2) && !$silent ) { warn "$My_name: Removing all generated files\n" unless $silent; - } + } if ($bibtex_use < 2) { delete $generated_exts_all{'bbl'}; } @@ -2165,14 +2281,14 @@ foreach $filename ( @file_list ) my %index_bibtex_generated = (); my %aux_files = (); foreach (@index_bibtex_generated) { - $index_bibtex_generated{$_} = 1 + $index_bibtex_generated{$_} = 1 unless ( /\.bbl$/ && ($bibtex_use < 2) ); delete( $other_generated{$_} ); - } + } foreach (@aux_files) { $aux_files{$_} = 1; delete( $other_generated{$_} ); - } + } if ($diagnostics) { show_array( "For deletion, the following were determined from fdb file or log file:\n" ." Generated (from makeindex and bibtex):", @@ -2181,7 +2297,9 @@ foreach $filename ( @file_list ) show_array( " Other generated files:\n" ." (only deleted if \$cleanup_includes_generated is set): ", keys %other_generated ); - } + show_array( " Yet other generated files:\n", + keys %generated_exts_all ); + } &cleanup1( $aux_dir1, $fdb_ext, 'blg', 'ilg', 'log', 'aux.bak', 'idx.bak', split('\s+',$clean_ext), keys %generated_exts_all @@ -2189,12 +2307,15 @@ foreach $filename ( @file_list ) unlink_or_move( 'texput.log', "texput.aux", keys %index_bibtex_generated, keys %aux_files ); + if ( $dependents_list && ( $deps_file ne '-' ) ) { + unlink_or_move( $deps_file ); + } if ($cleanup_includes_generated) { - unlink_or_move( keys %other_generated ); - } + unlink_or_move( keys %other_generated ); + } if ( $cleanup_includes_cusdep_generated) { - &cleanup_cusdep_generated; - } + &cleanup_cusdep_generated; + } if ( $cleanup_mode == 1 ) { &cleanup1( $out_dir1, 'dvi', 'dviF', 'ps', 'psF', 'pdf', split('\s+', $clean_full_ext) @@ -2254,12 +2375,12 @@ foreach $filename ( @file_list ) # previous run. So use filetime criterion for make # instead of change from previous run, until we have # done our own make. - rdb_recurse( [keys %possible_primaries], - sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} } + rdb_recurse( [keys %possible_primaries], + sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} } ); if ( -e $log_name ) { - rdb_for_some( [keys %possible_primaries], \&rdb_set_latex_deps ); - } + rdb_for_some( [keys %possible_primaries], \&rdb_set_latex_deps ); + } } foreach $rule ( rdb_accessible( uniq1( keys %requested_filerules ) ) ){ # For all source files of all accessible rules, @@ -2267,12 +2388,12 @@ foreach $filename ( @file_list ) # file, set them from disk. rdb_one_rule ($rule, undef, sub{ if ( $$Ptime == 0) { &rdb_update1; } } - ); + ); } if ($go_mode) { # Force everything to be remade. - rdb_recurse( [keys %requested_filerules], sub{$$Pout_of_date=1;} ); + rdb_recurse( [keys %requested_filerules], sub{$$Pout_of_date=1;} ); } @@ -2443,16 +2564,16 @@ sub rdb_make_rule_list { my $print_file = ''; my $print_cmd = 'NONE'; if ( $print_type eq 'dvi' ) { - $print_file = $dvi_final; - $print_cmd = $lpr_dvi; + $print_file = $dvi_final; + $print_cmd = $lpr_dvi; } elsif ( $print_type eq 'pdf' ) { - $print_file = $pdf_final; - $print_cmd = $lpr_pdf; + $print_file = $pdf_final; + $print_cmd = $lpr_pdf; } elsif ( $print_type eq 'ps' ) { - $print_file = $ps_final; - $print_cmd = $lpr; + $print_file = $ps_final; + $print_cmd = $lpr; } elsif ( $print_type eq 'none' ) { $print_cmd = 'NONE echo NO PRINTING CONFIGURED'; @@ -2510,30 +2631,30 @@ sub rdb_set_rules { %rule_db = (); foreach my $Prule_list (@_) { - foreach my $rule ( keys %$Prule_list) { - my ( $cmd_type, $ext_cmd, $int_cmd, $source, $dest, $base, $test_kind, $PA_extra_gen ) = @{$$Prule_list{$rule}}; + foreach my $rule ( keys %$Prule_list) { + my ( $cmd_type, $ext_cmd, $int_cmd, $source, $dest, $base, $test_kind, $PA_extra_gen ) = @{$$Prule_list{$rule}}; if ( ! $PA_extra_gen ) { $PA_extra_gen = []; } - my $needs_making = 0; - # Substitute in the filename variables, since we will use - # those for determining filenames. But delay expanding $cmd - # until run time, in case of changes. - foreach ($base, $source, $dest, @$PA_extra_gen ) { - s/%R/$root_filename/; - s/%Y/$aux_dir1/; - s/%Z/$out_dir1/; - } - foreach ($source, $dest ) { - s/%B/$base/; - s/%T/$texfile_name/; - } + my $needs_making = 0; + # Substitute in the filename variables, since we will use + # those for determining filenames. But delay expanding $cmd + # until run time, in case of changes. + foreach ($base, $source, $dest, @$PA_extra_gen ) { + s/%R/$root_filename/; + s/%Y/$aux_dir1/; + s/%Z/$out_dir1/; + } + foreach ($source, $dest ) { + s/%B/$base/; + s/%T/$texfile_name/; + } # print "$rule: $cmd_type, EC='$ext_cmd', IC='$int_cmd', $test_kind,\n", # " S='$source', D='$dest', B='$base' $needs_making\n"; - rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, $test_kind, - $source, $dest, $base, - $needs_making, undef, undef, 1, $PA_extra_gen ); + rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, $test_kind, + $source, $dest, $base, + $needs_making, undef, undef, 1, $PA_extra_gen ); # !! ?? Last line was -# $needs_making, undef, ($test_kind==1) ); - } +# $needs_making, undef, ($test_kind==1) ); + } } # End arguments of subroutine &rdb_make_links; } # END rdb_set_rules @@ -2558,7 +2679,7 @@ sub rdb_make_links { ) { $$Pfrom_rule = $from_rules{$file}; } - } + } ); rdb_for_all( 0, @@ -2568,9 +2689,9 @@ sub rdb_make_links { } if ( $$Pfrom_rule && (! rdb_rule_exists( $$Pfrom_rule ) ) ) { $$Pfrom_rule = ''; - } + } #?? print "$rule: $file, $$Pfrom_rule\n"; - } + } ); } # END rdb_make_links @@ -2615,12 +2736,12 @@ sub do_cusdep { if ( !-e $$Psource ) { # Source does not exist. Users of this rule will need to turn # it off when custom dependencies are reset - if ( !$silent ) { + if ( !$silent ) { ## ??? Was commented out. 1 Sep. 2008 restored, for cusdep no-file-exists issue warn "$My_name: In trying to apply custom-dependency rule\n", " to make '$$Pdest' from '$$Psource'\n", " the source file has disappeared since the last run\n"; - } + } # Treat as successful } elsif ( !$func_name ) { @@ -2636,21 +2757,21 @@ sub do_cusdep { " function name '$func_name' does not exists.\n"; } else { - my $cusdep_ret = &$func_name( $$Pbase ); + my $cusdep_ret = &$func_name( $$Pbase ); if ( defined $cusdep_ret && ($cusdep_ret != 0) ) { - $return = $cusdep_ret; - if ($return) { + $return = $cusdep_ret; + if ($return) { warn "Rule '$rule', function '$func_name'\n", " failed with return code = $return\n"; - } - } + } + } elsif ( !-e $$Pdest ) { # Destination non-existent, but routine failed to give an error warn "$My_name: In running custom-dependency rule\n", " to make '$$Pdest' from '$$Psource'\n", " function '$func_name' did not make the destination.\n"; - $return = -1; - } + $return = -1; + } } return $return; } # END do_cusdep @@ -2673,9 +2794,9 @@ sub do_viewfile { else { warn "$My_name is configured to make '$$Pdest' via a temporary file\n", " but the command template '$$Pext_cmd' does not have a slot\n", - " to set the destination file, so I won't use a temporary file\n"; + " to set the destination file, so I won't use a temporary file\n"; $return = &Run_subst(); - } + } } else { $return = &Run_subst(); @@ -2701,12 +2822,12 @@ sub do_update_view { my $Pneed_to_get_viewer_process = \${$PAint_cmd}[4]; if ($viewer_update_method == 2) { - if ($$Pneed_to_get_viewer_process) { + if ($$Pneed_to_get_viewer_process) { $$Pviewer_process = &find_process_id( $$Psource ); if ($$Pviewer_process != 0) { $$Pneed_to_get_viewer_process = 0; - } - } + } + } if ($$Pviewer_process == 0) { print "$My_name: need to signal viewer for file '$$Psource', but didn't get \n", " process ID for some reason, e.g., no viewer, bad configuration, bug\n" @@ -2715,8 +2836,8 @@ sub do_update_view { elsif ( defined $viewer_update_signal) { print "$My_name: signalling viewer, process ID $$Pviewer_process\n" if $diagnostics ; - kill $viewer_update_signal, $$Pviewer_process; - } + kill $viewer_update_signal, $$Pviewer_process; + } else { warn "$My_name: viewer is supposed to be sent a signal\n", " but no signal is defined. Misconfiguration or bug?\n"; @@ -2726,7 +2847,7 @@ sub do_update_view { elsif ($viewer_update_method == 4) { if (defined $$Pext_cmd) { $return = &Run_subst(); - } + } else { warn "$My_name: viewer is supposed to be updated by running a command,\n", " but no command is defined. Misconfiguration or bug?\n"; @@ -2745,7 +2866,7 @@ sub if_source { } else { warn "Needed source file '$$Psource' does not exist.\n"; - return -1; + return -1; } } #END if_source @@ -2908,7 +3029,7 @@ CHANGE: $SIG{BREAK} = $SIG{INT} = 'IGNORE'; } if ($compiling_cmd) { - Run_subst( $compiling_cmd ); + Run_subst( $compiling_cmd ); } $failure = rdb_make( @targets ); @@ -2920,25 +3041,25 @@ CHANGE: # Start viewer if needed. if ( ($failure > 0) && (! $force_mode) ) { # No viewer yet - } + } elsif ( ($view_file ne '') && (-e $view_file) && $updated && $viewer_running ) { # A viewer is running. Explicitly get it to update screen if we have to do it: rdb_one_rule( 'update_view', \&rdb_run1 ); } elsif ( ($view_file ne '') && (-e $view_file) && !$viewer_running ) { # Start the viewer - if ( !$silent ) { + if ( !$silent ) { if ($new_viewer_always) { warn "$My_name: starting previewer for '$view_file'\n", "------------\n"; - } + } else { warn "$My_name: I have not found a previewer that ", "is already running. \n", " So I will start it for '$view_file'\n", "------------\n"; - } - } + } + } local $retcode = 0; rdb_one_rule( 'view', sub { $retcode = &rdb_run1;} ); if ( $retcode != 0 ) { @@ -2952,11 +3073,11 @@ CHANGE: else { $viewer_running = 1; $$Pneed_to_get_viewer_process = 1; - } # end analyze result of trying to run viewer + } # end analyze result of trying to run viewer } # end start viewer if ( $failure > 0 ) { if ( !$failure_msg ) { - $failure_msg = 'Failure to make the files correctly'; + $failure_msg = 'Failure to make the files correctly'; } @pre_primary = (); # Array of rules @post_primary = (); # Array of rules @@ -2978,12 +3099,12 @@ CHANGE: warn "$My_name: $failure_msg\n", " ==> You will need to change a source file before I do another run <==\n"; if ($failure_cmd) { - Run_subst( $failure_cmd ); + Run_subst( $failure_cmd ); } - } + } else { if ($success_cmd) { - Run_subst( $success_cmd ); + Run_subst( $success_cmd ); } } rdb_show_rule_errors(); @@ -2997,8 +3118,8 @@ CHANGE: } else { warn "Cannot open '$deps_file' for output of dependency information\n"; - } - } + } + } if ( $first_time || $updated || $failure ) { print "\n=== Watching for updated files. Use ctrl/C to stop ...\n"; } @@ -3011,24 +3132,24 @@ CHANGE: $have_break = 0; WAIT: while (1) { sleep( $sleep_time ); - if ($have_break) { last WAIT; } + if ($have_break) { last WAIT; } if ( rdb_new_changes(keys %rules_to_watch) ) { - if (!$silent) { + if (!$silent) { warn "$My_name: Need to remake files.\n"; - &rdb_diagnose_changes( ' ' ); - } + &rdb_diagnose_changes( ' ' ); + } last WAIT; - } + } # Don't count waiting time in processing: $processing_time1 = processing_time(); # Does this do this job???? local $new_files = 0; rdb_for_some( [keys %current_primaries], sub{ $new_files += &rdb_find_new_files } ); if ($new_files > 0) { - warn "$My_name: New file(s) found.\n"; + warn "$My_name: New file(s) found.\n"; last WAIT; - } - if ($have_break) { last WAIT; } + } + if ($have_break) { last WAIT; } } # end WAIT: &default_break; if ($have_break) { @@ -3078,7 +3199,7 @@ sub process_rc_file { # PREVIOUS VERSION # if ( ! -r $rc_file ) { # warn "$My_name: I cannot read the rc-file '$rc_file'\n", -# " or at least that's what Perl (for $^O) reports\n"; +# " or at least that's what Perl (for $^O) reports\n"; # return 1; # } # do( $rc_file ); @@ -3128,11 +3249,12 @@ sub execute_code_string { sub cleanup1 { # Usage: cleanup1( directory, exts_without_period, ... ) # - # The directory is a fixed name, so I must escape any glob metacharacters - # in it: + # The directory and the root file name are fixed names, so I must escape + # any glob metacharacters in them: my $dir = fix_pattern( shift ); + my $root_fixed = fix_pattern( $root_filename ); foreach (@_) { - (my $name = /%R/ ? $_ : "%R.$_") =~ s/%R/$dir$root_filename/; + (my $name = /%R/ ? $_ : "%R.$_") =~ s/%R/$dir$root_fixed/; unlink_or_move( glob( "$name" ) ); } } #END cleanup1 @@ -3295,6 +3417,10 @@ sub print_help " -latex= - set program used for latex.\n", " (replace '' by the program name)\n", " -latexoption=