From fe04272d88809e433f8d08435e0f4ea7b89b5fd3 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 16 Apr 2021 20:15:34 +0000 Subject: latexmk (16apr21) git-svn-id: svn://tug.org/texlive/trunk@58886 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/latexmk/latexmk.pl | 742 ++++++++++++++------------- 1 file changed, 382 insertions(+), 360 deletions(-) (limited to 'Master/texmf-dist/scripts') diff --git a/Master/texmf-dist/scripts/latexmk/latexmk.pl b/Master/texmf-dist/scripts/latexmk/latexmk.pl index a05e938f912..1ef32d985ef 100755 --- a/Master/texmf-dist/scripts/latexmk/latexmk.pl +++ b/Master/texmf-dist/scripts/latexmk/latexmk.pl @@ -1,130 +1,7 @@ #!/usr/bin/env perl -#!!!!!!!!!!!!!!!!!!!????????? CLEAN UP INITIALIZATION -#!!! See all FIX items. -# Perhaps add subroutine rdb_change_active( (rules to deactivate), (rules to activate)) - -# ?? Still need to fix bcf error issue. -# Don't keep looping after error -# pvc: Only re-run on USER FILE CHANGE. -# See # ??????? BCF - - -#!!!!!!!!??? Check @pwd_log - - -# !!!!!!!!!! Don't forget to document $silence_logfile_warnings.!!! - -# N.B. !!!!!!!!!!! See 17 July 2012 comments !!!!!!!!!!!!!!!!!! - -# On a UNIX-like system, the above enables latexmk to run independently -# of the location of the perl executable. This line relies on the -# existence of the program /usr/bin/env -# If there is a problem for any reason, you can replace the first line of -# this file by: - -#!/usr/bin/perl -w - -# with the path of the perl executable adjusted for your system. - -use warnings; - -# Delete #??!! when working - -# See ?? <=============================== - -## ?? Issues with clean-up -## List of aux files deleted is those read, not those generated. -## Other files are generated by *latex; should they be deleted? -## (I have hooks for this). - - - -#======================================= - -#?? Force mode doesn't appear to do force (if error in latex file) -#??? Get banner back in. -#?? CORRECT DIAGNOSTICS ON CHANGED FILES IF THEY DIDN'T EXIST BEFORE -#?? Further corrections to deal with disappeared source files for custom dependencies. -# Message repeatedly appears about remake when source file of cusdep doesn't exist. -#?? logfile w/o fdb file: don't set changed file, perhaps for generated exts. -# Reconsider -#?? Do proper run-stuff for bibtex, makeindex, cus-deps. OK I think -# Parse and correctly find ist files - - -# ATTEMPT TO ALLOW FILENAMES WITH SPACES: -# (as of 1 Apr 2006, and then 14 Sep. 2007) - -# Problems: -# A. Quoting filenames will not always work. -# a. Under UNIX, quotes are legal in filenames, so when PERL -# directly runs a binary, a quoted filename will be treated as -# as a filename containing a quote character. But when it calls -# a shell, the quotes are handled by the shell as quotes. -# b. Under MSWin32, quotes are illegal filename characters, and tend -# to be handled correctly. -# c. But under cygwin, results are not so clear (there are many -# combinations: native v. cygwin perl, native v cygwin programs -# NT v. unix scripts, which shell is called. -# B. TeX doesn't always handle filenames with spaces gracefully. -# a. UNIX/LINUX: The version on gluon2 Mar 31, 2006 to Sep. 2007) -# doesn't handle them at all. (TeX treats space as separator.) -# b. At least some later versions actually do (Brad Miller e-mail, -# Sep. 2007). -# c. fptex [[e-TeXk, Version 3.141592-2.1 (Web2c 7.5.2)] does, on -# my MSWin at home. In \input the filename must be in quotes. -# d. Bibtex [BibTeX (Web2c 7.5.2) 0.99c on my MSWin system at home, -# Sep. 2007] does not allow names of bibfiles to have spaces. -# C. =====> Using the shell for command lines is not safe, since special -# characters can cause lots of mayhem. -# It will therefore be a good idea to sanitize filenames. -# -# I've sanitized all calls out: -# a. system and exec use a single argument, which forces -# use of shell, under all circumstances -# Thus I can safely use quotes on filenames: They will be handled by -# the shell under UNIX, and simply passed on to the program under MSWin32. -# b. I reorganized Run, Run_Detached to use single command line -# c. All calls to Run and Run_Detached have quoted filenames. -# d. So if a space-free filename with wildcards is given on latexmk's -# command line, and it globs to space-containing filename(s), that -# works (fptex on home computer, native NT tex) -# e. ====> But globbing fails: the glob function takes space as filename -# separator. ==================== - -#================= TO DO ================ -# -# 1. See ?? ESPECIALLY $MSWin_fudge_break -# 2. Check fudged conditions in looping and make_files -# 3. Should not completely abort after a run that ends in failure from latex -# Missing input files (including via custom dependency) should be checked for -# a change in status -# If sources for missing files from custom dependency -# are available, then do a rerun -# If sources of any kind become available rerun (esp. for pvc) -# rerun -# Must parse log_file after unsuccessful run of latex: it may give -# information about missing files. -# 4. Check file of bug reports and requests -# 5. Rationalize bibtex warnings and errors. Two almost identical routines. -# Should 1. Use single routine -# 2. Convert errors to failure only in calling routine -# 3. Save first warning/error. - -# ?? Use of generated_exts arrays and hashes needs rationalization - -# To do: -# Rationalize again handling of include files. -# Now I use kpsewhich to do searches, if file not found -# (How do I avoid getting slowed down too much?) -# Document the assumptions at each stage of processing algorithm. -# Option to restart previewer automatically, if it dies under -pvc -# Test for already running previewer gets wrong answer if another -# process has the viewed file in its command line - -## Copyright John Collins 1998-2020 +## Copyright John Collins 1998-2021 ## (username jcc8 at node psu.edu) ## (and thanks to David Coppit (username david at node coppit.org) ## for suggestions) @@ -149,25 +26,86 @@ use warnings; ## ## ## -## NEW FEATURES, since v. 2.0: -## 1. Correct algorithm for deciding how many times to run latex: -## based on whether source file(s) change between runs -## 2. Continuous preview works, and can be of ps file or dvi file -## 3. pdf creation by pdflatex possible -## 4. Defaults for commands are OS dependent. -## 5. Parsing of log file instead of source file is used to -## obtain dependencies, by default. -## -## Modification log from 9 Dec 2011 onwards in detail -## -## 12 Jan 2012 STILL NEED TO DOCUMENT some items below +## Modification log from 1 Jan 2020 onwards in detail ## +## 14-15 Apr 2021 John Collins In normalize_filename, try both good_cwd() and +## cwd() for removing directory component. +## That improves clean up. +## V. 4.72b +## 14 Apr 2021 John Collins Allow index instead of makeindex in indexfudge options +## 12 Apr 2021 John Collins Start to fix bug on not-found files with out_dir = . +## 11 Apr 2021 John Collins V. 4.72a. +## Modify contents of minimal aux file. +## 9 Apr 2021 John Collins Correct bug that if on one run of latexmk a +## missing file was detected and the file was +## later created, then a subsequent run of latexmk +## didn't cause a recompilation. The cause was an +## error in latexmk's initialization of its file +## database. +## V. 4.72. +## 12 Jan 2021 John Collins Correct parse_log +## 28 Dec 2020 John Collins Process -output-format=fmt option rather than passing it to *latex +## 26-27 Dec 2020 John Collins Deal with bug exposed by chapterbib. (It involved +## incorrect attempt to deal with filenames specified +## relative to aux_dir. +## 14 Dec 2020 John Collins Try to solve problems of normalization of source +## name and general normalization of file names. +## 10 Dec 2020 John Collins Set up run_makeindex and $makeindex_fudge, just as +## for bibtex, and corresponding CL options. +## Revert changes to normalize_filename, they aren't +## needed any more. +## Normalize filenames in rdb_ensure_file. +## 25 Nov 2020 John Collins Revert to default $bibtex_fudge to 1 +## Rationale: +## There are enough annoying security-related +## complications in many cases concerning +## filenames with a path component given to +## bibtex, that it is better to do the cd trick +## by default. In addition there are some +## interesting incompatibilities between TeXLive +## and MiKTeX. In the rare (I suspect) cases +## where the fudge fails, the user can always +## turn it off, of course. +## I should do same fudge for makeindex. +## Comment out warning when bibtex fudge is used. +## 18 Nov 2020 John Collins Add options -bibtexfudge, -bibtexfudge-, -nobibtexfudge, +## so that the options are in agreement with documentation +## including historical versions. +## Set environmnent variable TEXMFOUTPUT to the +## aux_dir. This solves problem that bibtex and +## makeindex sometimes cannot write to the +## aux_dir (for their log and output files). This +## problem occurs notably when the aux_dir is +## specified by an absolute path to a directory that +## is not a subdirectory of the cwd. +## 12 Nov 2020 John Collins Correct some aliasing of filenames. +## 11 Nov 2020 John Collins Remove some messages. +## Don't allow log file as a source. +## 2 Nov 2020 John Collins Refuse to allow main pdf file or main output file to +## be source of a primary rule, and give warning +## about it. (Concerns at least hyperxmp (2020/10/05 v. 5.6; +## this accesses file system metadata, specifically file size, +## and the fls file therefore lists the pdf file as a source. +## This generally leads to an infinite loop, without a special +## a configuration.) Hyperxmp v. 5.7 2010/11/01 doesn't give +## this problem. But the test is still good to have. +## 23 Oct 2020 John Collins Fix incorrect $/ in reading rc files +## 10-15 Oct 2020 John Collins Correct bug in normalizing filename +## Give .latexmkrc priority over latexmkrc in cwd +## 8 Oct 2020 John Collins Restore use Cwd "chdir";. There's no longer +## a problem with cd +## 7 Oct 2020 John Collins Extra diagnostics for reporting normalized aux/out dirs +## 6 Oct 2020 John Collins Better normalize etc. +## 1 Oct 2020 John Collins Improve some messages. +## 30 Sep 2020 John Collins V. 4.70c. +## Clean up some comments. ## 29 Sep 2020 John Collins V. 4.70b. ## Correct switch_output. ## Try to ensure bibtex isn't given absolute pathname, when aux_dir ## is under current directory. (Otherwise bibtex isn't allowed ## to write a bbl file under default TeXLive settings.) ## Add options -bibfudge, -bibfudge-, -nobibfudge. +## Current version (4.70b, 29 Sep 2020) to CTAN ## 13 Sep 2020 John Collins V. 4.70a. Updates in comments about bibtex. ## 28 Aug 2020 John Collins Correct $biber and $bibtex to use %S not %B ## 24 Aug 2020 John Collins Make sure bibtex/biber rules when created for @@ -221,81 +159,9 @@ use warnings; ## xetex source). This forces xdvipdfmx to always ## try to embed fonts, ignoring licensing flags, etc. ## -## Current version (4.67, 26 Dec 2019) to CTAN -## 26 Dec 2019 John Collins Change place of setting of $view_file -## Make fully consistent set of options for engines: -## -latex, -latex=..., -## preserving backward compatibility, and avoiding suprises. -## 11 Dec 2019 John Collins Change rules for wrapping in log file: This deals -## with xelatex wrapping at > standard number of -## bytes in presence of non-ASCII Unicode characters. -## 4 Dec 2019 John Collins If there were missing subdirectories in output/aux -## directories, and these were successfully created, -## then ignore error from *latex, since rerun may -## succeed. -## 14 Nov 2019 John Collins Add comment. -## 12 Nov 2019 John Collins Use $compiling_cmd, $warning_cmd, $success_cmd -# on normal make, rather than just in -pvc mode. -## 5 Aug 2019 John Collins The changing of '\' to '/' in filenames is now -## done for msys as well as MSWin32. -## 8 Jul 2019 John Collins Allow addition of hook for processing lists of -## missing source files, used after run of *latex. -## 2 Jul 2019 John Collins Silence message about disallowing change of output -## file type. -## V. 4.66 -## 28 Jun 2019 John Collins Try to deal with log file parsing problems -## V. 4.65 -## 21 May 2019 John Collins Fix incorrect listings by -rules and by -deps -## 21 May 2019 John Collins V. 4.64a. -## 20,21 May 2019 John Collins Fix problem with not always running dvipdf, -## dvips, xdvpdf because of missing information -## on source files. Do this by adding a -## source_rule hash to each rule and adding a -## pass-based criterion for out-of-dateness -## 20 May 2019 John Collins V. 4.64. -## 17 Mar 2019 John Collins V. 4.63c. -## 18 Mar 2019 John Collins Update copyright date -## 17 Mar 2019 John Collins Further test for problems when linking rules -## 17 Mar 2019 John Collins V. 4.63b. -## 17 Mar 2019 John Collins Fix problem revealed by bibtopic package -## 15 Mar 2019 John Collins Corrections -## 14 Mar 2019 John Collins Version to 4.63a -## 12-14 Mar 2019 John Collins Jobname has placeholder -## 8-11 Mar 2019 John Collins Correct aux-dir bugs -## 8 Mar 2019 John Collins Version to 4.63 -## 1 Jan 2019 John Collins Correct bug in output switching code -## 31 Dec 2018 John Collins Correct bug that with $cleanup_includes_generated -## -c mode deletes final output files (e.g., .dvi, .pdf). -## 13 Dec 2018 John Collins Fixes, cleanup -## 12 Dec 2018 John Collins Fix rdb_read -## 11 Dec 2018 John Collins For output-switch: Reorganize initialization -## Remove possibility of more than one primary. -## 1 Dec 2018 John Collins Clean up some code. -## 30 Nov 2018 John Collins Allow any characters in directory part of tex -## filename when cd mode on. (Still standard -## set of disallowed characters applies basename.) -## 21 Nov 2018 John Collins Infrastructure finished, I think, for active flag -## Start on output switch -## 16 Nov 2018 John Collins Remove in non-diagnostics mode a warning about -## rule not in use in this session that is given -## when reading an fdb_latexmk file. -## 2 Nov 2018 John Collins Start implementing active flag for rules. -## 1 Nov 2018 John Collins Fix finding of missing files that are relative to aux_dir -## 29-31 Oct 2018 John Collins Some cleanup. -## 27,28 Oct 2018 John Collins Fix bug that in -pvc mode, after an error in -## certain rules, new rounds of compilation -## are triggered because of changes in generated -## files, instead of only by later user-generated -## changes. -## Improve linking of rules. -## 25 Oct 2018 John Collins V. 4.62 -## Clean up can remove (empty) directories -## 25 Oct 2018 John Collins Fix definition of clean up substitution for %R -## so that something with intermediate %R works, -## as in 'pythontex-files-%R/*'. ## -## 1998-2018, John Collins. Many improvements and fixes. -## See CHANGE-log.txt for full list, and CHANGES for summary +## 1998-2019, John Collins: Many improvements and fixes. +## See CHANGE-log.txt for full list, and CHANGES for summaries ## ## Modified by Evan McLean (no longer available for support) ## Original script (RCS version 2.3) called "go" written by David J. Musliner @@ -313,8 +179,8 @@ use warnings; $my_name = 'latexmk'; $My_name = 'Latexmk'; -$version_num = '4.70b'; -$version_details = "$My_name, John Collins, 29 September 2020"; +$version_num = '4.72b'; +$version_details = "$My_name, John Collins, 15 April 2021"; use Config; use File::Basename; @@ -351,8 +217,9 @@ use File::Path 2.08 qw( make_path ); use FileHandle; use File::Find; use List::Util qw( max ); -use Cwd; # To be able to change cwd -#use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd. NO NEED, and it messes up -cd -outdir= +use Cwd; +use Cwd "abs_path"; +use Cwd "chdir"; # Ensure $ENV{PWD} tracks cwd. use Digest::MD5; #use strict; @@ -414,6 +281,8 @@ $log_wrap = 79; # See subroutine test_fix_texnames and its call for their use. $illegal_in_texname = "\x00\t\f\n\r\$%\\~\x7F"; +# Whether to normalize filenames where possible: +$normalize_names = 2; # Strongest kind. ## Hash mapping file extension (w/o period, e.g., 'eps') to a single regexp, # whose matching by a line in a file with that extension indicates that the @@ -539,7 +408,6 @@ foreach ( "-mltex enable MLTeX extensions such as \charsubdef", "-output-comment=STRING use STRING for DVI file comment instead of date\n". " (no effect for PDF)", - "-output-format=FORMAT use FORMAT for job output; FORMAT is `dvi\" or `pdf\"", "-parse-first-line enable parsing of first line of input file", "-no-parse-first-line disable parsing of first line of input file", "-progname=STRING set program (and fmt) name to STRING", @@ -621,6 +489,7 @@ foreach ( #-jobname=STRING set the job name to STRING #-aux-directory=dir Set the directory dir to which auxiliary files are written #-output-directory=DIR use existing DIR as the directory to write files in + # "-output-format=FORMAT use FORMAT for job output; FORMAT is `dvi\" or `pdf\"", #-quiet #-recorder enable filename recorder # @@ -659,12 +528,6 @@ foreach ( $biber = 'biber %O %S'; $bibtex = 'bibtex %O %S'; # Switch(es) to make biber & bibtex silent: -$bibtex_fudge = 0; # Don't use hack to get bibtex working in old versions that - # don't handle output-directory. When this version of - # latexmk is part of a distribution of TeX, the - # accompanying bibtex should also be recent enough - # (e.g., TeXLive 2019 or later, current MiKTeX) not to - # need the hack/fudge. $biber_silent_switch = '--onlylog'; $bibtex_silent_switch = '-terse'; $bibtex_use = 1; # Whether to actually run bibtex to update bbl files. @@ -685,11 +548,23 @@ $bibtex_use = 1; # Whether to actually run bibtex to update bbl files. # # In any event bibtex is only run if the log file # indicates that the document uses bbl files. +$bibtex_fudge = 1; # Whether or not to cd to aux dir when running bibtex. + # If the cd is not done, and bibtex is passed a + # filename with a path component, then it can easily + # happen that (a) bibtex refuses to write bbl and blg + # files to the aux directory, for security reasons, + # and/or (b) bibtex in pre-2019 versions fails to find + # some input file(s). But in some other cases, the cd + # method fails. ## Command to invoke makeindex $makeindex = 'makeindex %O -o %D %S'; # Switch(es) to make makeinex silent: $makeindex_silent_switch = '-q'; +$makeindex_fudge = 1; # Whether or not to cd to aux dir when running makeindex. + # Set to 1 to avoid security-related prohibition on + # makeindex writing to aux_dir when it is not specified + # as a subdirectory of cwd. ## Command to convert dvi file to pdf file directly: $dvipdf = 'dvipdf %O %S %D'; @@ -1548,13 +1423,14 @@ $allow_switch = 1; # Allow switch of rule structure to accommodate # for source, %B for base of current rule, # %R for base of primary tex file, %T for # texfile name, %O for options, + # %V=$aux_dir, %W=$out_dir, # %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 + # **direct** execution of the external command, and + # it is the responsibility of the perl subroutine + # specified in intcmd to execute the specified # external command if this is appropriate. # This variable intcmd is a reference to an array, # $$intcmd[0] = internal routine @@ -1776,7 +1652,7 @@ if ( $auto_rc_use && ($HOME ne "" ) ) { } if ( $auto_rc_use ) { # Rc file in current directory: - read_first_rc_file_in_list( "./latexmkrc", "./.latexmkrc" ); + read_first_rc_file_in_list( ".latexmkrc", "latexmkrc" ); } ## Process command line args. @@ -1793,8 +1669,8 @@ while ($_ = $ARGV[0]) if ( /^-aux-directory=(.*)$/ || /^-auxdir=(.*)$/ ) { $aux_dir = $1; } - elsif (/^-bibfudge$/) { $bibtex_fudge = 1; } - elsif (/^-bibfudge-$/) { $bibtex_fudge = 0; } + elsif (/^-bib(tex|)fudge$/) { $bibtex_fudge = 1; } + elsif (/^-bib(tex|)fudge-$/) { $bibtex_fudge = 0; } elsif (/^-bibtex$/) { $bibtex_use = 2; } elsif (/^-bibtex-$/) { $bibtex_use = 0; } elsif (/^-nobibtex$/) { $bibtex_use = 0; } @@ -1861,6 +1737,8 @@ while ($_ = $ARGV[0]) shift; } elsif ( /^-MP$/ ) { $dependents_phony = 1; } + elsif (/^-(make|)indexfudge$/) { $makeindex_fudge = 1; } + elsif (/^-(make|)indexfudge-$/) { $makeindex_fudge = 0; } elsif ( /-MSWinBackSlash$/ ) { $MSWin_back_slash = 1; } elsif ( /-MSWinBackSlash-$/ ) { $MSWin_back_slash = 0; } elsif (/^-new-viewer$/) { @@ -1873,10 +1751,26 @@ while ($_ = $ARGV[0]) $auto_rc_use = 0; # N.B. This has already been obeyed. } - elsif (/^-nobibfudge$/) { $bibtex_fudge = 0; } + elsif (/^-nobib(tex|)fudge$/) { $bibtex_fudge = 0; } + elsif (/^-no(make|)indexfudge$/) { $makeindex_fudge = 0; } elsif ( /^-output-directory=(.*)$/ ||/^-outdir=(.*)$/ ) { $out_dir = $1; } + elsif ( /^-output-format=(.*)$/ ) { + my $format = $1; + if ($format eq 'dvi' ) { + $dvi_mode = 1; + $pdf_mode = $postscript_mode = 0; + } + elsif ($format eq 'pdf' ) { + $pdf_mode = 1; + $dvi_mode = $postscript_mode = 0; + } + else { + warn "$My_name: unknown format in option '$_'\n"; + $bad_options++; + } + } elsif (/^-p$/) { $printout_mode = 1; $preview_continuous_mode = 0; # to avoid conflicts $preview_mode = 0; @@ -2045,7 +1939,7 @@ while ($_ = $ARGV[0]) push @extra_xelatex_options, $original; } elsif (/^-/) { - warn "$My_name: $_ bad option\n"; + warn "$My_name: $_ unknown option\n"; $bad_options++; } else { @@ -2083,8 +1977,6 @@ $out_dir_requested = $out_dir; # 3 log file **not** in aux_dir or out_dir, but in cwd. $where_log = -1; -&set_dirs_etc; - if ($bibtex_use > 1) { push @generated_exts, 'bbl'; } @@ -2253,19 +2145,6 @@ if ( $recorder ) { # possible cd to the document directory, since the directories can be # relative to the document. -$q = $quote_filenames ? '"' : ''; -if ( $out_dir ) { - add_option( "-output-directory=$q$out_dir$q", - \$latex, \$pdflatex, \$lualatex, \$xelatex ); -} -if ( $aux_dir && ($aux_dir ne $out_dir) ) { - # N.B. If $aux_dir and $out_dir are the same, then the -output-directory - # option is sufficient, especially because the -aux-directory exists - # only in MiKTeX, not in TeXLive. - add_option( "-aux-directory=$q$aux_dir$q", - \$latex, \$pdflatex, \$lualatex, \$xelatex ); -} - if ( $jobname ne '' ) { # Since $jobname may include placeholder(s), put %R placeholder # in option, and let %R be substituted by actual jobname at runtime. @@ -2467,6 +2346,8 @@ foreach ($clean_ext, $clean_full_ext) { s/^\s+//; s/\s+$//; s/\s+/ /g; } # Deal with illegal and problematic characters in filename: test_fix_texnames( @file_list ); +$quote = $quote_filenames ? '"' : ''; + FILE: foreach $filename ( @file_list ) { @@ -2479,12 +2360,18 @@ foreach $filename ( @file_list ) if ( $do_cd ) { ($filename, $path) = fileparse( $filename ); warn "$My_name: Changing directory to '$path'\n" - if !$silent; + if !$silent; pushd( dirname_no_tail( $path ) ); } else { $path = ''; } + local $aux_dir = $aux_dir; + local $out_dir = $out_dir; + local $latex = $latex; + local $lualatex = $lualatex; + local $pdflatex = $pdflatex; + local $xelatex = $xelatex; # Ensure the output/auxiliary directories exist, if need be if ( $out_dir ) { @@ -2516,7 +2403,31 @@ foreach $filename ( @file_list ) } } + if ($normalize_names) { + $aux_dir = normalize_filename($aux_dir); + $out_dir = normalize_filename($out_dir); + } + set_dirs_etc(); + if ($diagnostics) { + warn "$My_name: Cwd: '", good_cwd(), "'\n"; + warn "$My_name: Normalized aux dir and out dir: '$aux_dir', '$out_dir'\n"; + warn "$My_name: and combining forms: '$aux_dir1', '$out_dir1'\n"; + } + if ( $out_dir && ($out_dir ne '.') ) { + add_option( "-output-directory=$quote$out_dir$quote", + \$latex, \$pdflatex, \$lualatex, \$xelatex ); + } + if ( $aux_dir && ($aux_dir ne '.') && ($aux_dir ne $out_dir) ) { + # N.B. If $aux_dir and $out_dir are the same, then the -output-directory + # option is sufficient, especially because the -aux-directory exists + # only in MiKTeX, not in TeXLive. + add_option( "-aux-directory=$quote%V$quote", + \$latex, \$pdflatex, \$lualatex, \$xelatex ); + } + + &set_names; + # For use under error conditions: @default_includes = ($texfile_name, $aux_main); # N.B. Do **not** apply local %rule_db here. It might appear appropriate, @@ -2710,15 +2621,13 @@ foreach $filename ( @file_list ) rdb_for_some( [keys %current_primaries], \&rdb_set_latex_deps ); } } - foreach $rule ( &rdb_accessible ) { - # For all source files of all accessible rules, - # if the file data are not already set (e.g., from fdb_latexmk - # file, set them from disk. - rdb_one_rule ($rule, undef, - sub{ if ( $$Ptime == 0) { &rdb_update1; } } - ); - } - + # At this point, we assume that the file database was correctly + # initialized from fdb_latexmk database (corresponding to the state at + # the end of the previous run of latexmk, if the fdb_latexmk file exists. + # PERHAPS if fdb_latexmk doesn't exist we ought to assume there was + # a previous run that completed, if the appropriate output files exist, + # so a new run of *latex etc isn't needed; then we should set the file + # data from the on-disk state. if ($go_mode) { # Force everything to be remade. rdb_recurse( [ &rdb_target_array], sub{$$Pout_of_date=1;} ); @@ -2937,7 +2846,7 @@ sub ensure_path { else { $ENV{$var} = $_ . $search_path_separator; } - if (!$silent) { + if ($diagnostics) { print "Set environment variable $var='$ENV{$var}'\n"; } } @@ -2946,18 +2855,27 @@ sub ensure_path { ############################################################# sub set_dirs_etc { - # Normalize versions terminating in directory/path separator - # and versions referring to current directory - # These actions in a subroutine so they can be used elsewhere. + # Normalize $out_dir and $aux_dir, so that if they have a non-trivial last + # component, any trailing '/' is removed. + # Then set $out_dir1 and $aux_dir1 to have a directory separator character + # '/' added if needed to give forms suitable for direct concatenation with + # a filename. These are needed for substitutions like %Y%R. + # Nasty cases of dir_name: "/" on all systems, "A:", "A:/" etc on MS-Win + # Then set some TeX-related environment variables. $out_dir = dirname_no_tail( $out_dir ); $aux_dir = dirname_no_tail( $aux_dir ); $out_dir1 = $out_dir; $aux_dir1 = $aux_dir; - foreach ( $aux_dir1, $out_dir1 ) { + $out_dir_abs = abs_path($out_dir); + $out_dir1_abs = $out_dir_abs; + $aux_dir_abs = abs_path($aux_dir); + $aux_dir1_abs = $aux_dir_abs; + foreach ( $aux_dir1, $out_dir1, $aux_dir1_abs, $out_dir1_abs ) { if ( ($_ ne '') && ! m([\\/\:]$) ) { + # Add a trailing '/' if necessary to give a string that can be + # correctly concatenated with a filename: $_ .= '/'; } - while ( s[^\.\/][] ) {} } if ($aux_dir) { # Ensure $aux_dir is in BIBINPUTS and TEXINPUTS search paths. @@ -2970,9 +2888,31 @@ sub set_dirs_etc { # there is an error. So cope with this situation (and any analogous # cases by adding the aux_dir to the relevant path search environment # variables. BIBINPUTS seems to be the only one currently affected. + # Convert $aux_dir to absolute path to make the search path invariant + # under change of directory. foreach ( 'BIBINPUTS', 'TEXINPUTS' ) { - ensure_path( $_, $aux_dir ); - } + ensure_path( $_, $aux_dir_abs ); + } + # Set TEXMFOUTPUT so that when the aux_dir is not a subdirectory + # of the cwd (or below), bibtex and makeindex can write to it. + # Otherwise, security precautions in these programs will prevent + # them from writing there. + # The security issues concern **document-controlled** writing of + # files, when bibtex or makeindex is invoked directly by a + # document. In contrast, here $aux_dir is set by latexmk, not by + # the document. (See the main texmf.cnf file in a TeXLive + # distribution for some information.) The security issues here + # appear to be identical to those when giving an + # -output-directory=... option to *latex. + # CONSTRAINTS: + # 1. This works in the aux dir is an an absolute path pointing to a + # higher-level directory, but NOT when it is a relative path, e.g., + # "../build". + # 2. The directories for files on the command line given to bibtex + # and makeindex must be exactly the same as the value in $aux_dir. + # This is ensured by the way in which the command strings are + # constructed. + $ENV{TEXMFOUTPUT} = $aux_dir_abs; } } @@ -3179,6 +3119,7 @@ sub rdb_make_links { # over non-main generated files from other rules. local %from_rules_old = %from_rules; &rdb_cache_generated; + rdb_for_actives( 0, sub{ @@ -3194,7 +3135,7 @@ sub rdb_make_links { } ); rdb_for_actives( \&rdb_set_source_rules ); -# &rdb_show; +# print "=========In rdb_make_links: rules\n"; &rdb_show; } # END rdb_make_links #************************************************************ @@ -3296,8 +3237,13 @@ sub one_from_rule_cache { #************************************************************ sub set_trivial_aux_fdb { - # 1. Write aux file EXACTLY as would be written if the tex file - # had no cross references, etc. I.e., a minimal .aux file. + # 1. Write aux file as would be written if the tex file had no cross + # cross references, etc. i.e., a minimal .aux file, as would be + # written by latex with a simple document. + # That saves a run of latex on such simple documents. + # Before about 2020, latex only wrote one line, containing '\relax ' + # in the aux file. After that a reference to the last page was + # added. So now I write what is written for a one page document. # 2. Write a corresponding fdb file # 3. Provoke a run of *latex (actually of all primaries). @@ -3305,6 +3251,9 @@ sub set_trivial_aux_fdb { open( aux_file, '>', $aux_main ) or die "Cannot write file '$aux_main'\n"; print aux_file "\\relax \n"; + # The following is added by recent versions of latex for a + # one page document + print aux_file "\\gdef \\\@abspage\@last{1}\n"; close(aux_file); foreach my $rule (keys %possible_primaries ) { @@ -3807,8 +3756,10 @@ sub process_rc_file { return 1; } elsif ( open $RCH, "<$rc_file" ) { - { local $/; eval <$RCH>; } + my $code = ''; + { local $/; $code = <$RCH>;} close $RCH; + eval $code; } else { warn "$My_name: I cannot read the rc-file '$rc_file'\n"; @@ -3998,8 +3949,8 @@ sub print_help " -bibtex-cond - use bibtex when needed, but only if the bib file exists\n", " -bibtex-cond1 - use bibtex when needed, but only if the bib file exists;\n", " on cleanup delete bbl file only if bib file exists\n", - " -bibfudge - use change-directory fudge needed for old bibtexs\n", - " -bibfudge- - don't use change-directory fudge needed for old bibtexs\n", + " -bibfudge or -bibtexfudge - change directory to output directory when running bibtex\n", + " -bibfudge- or -bibtexfudge- - don't change directory when running bibtex\n", " -bm - Print message across the page when converting to postscript\n", " -bi - Set contrast or intensity of banner\n", " -bs - Set scale for banner\n", @@ -4033,6 +3984,8 @@ sub print_help " -g- - Turn off -g\n", " -h - print help\n", " -help - print help\n", + " -indexfudge or -makeindexfudge - change directory to output directory when running makeindex\n", + " -indexfudge- or -makeindexfudge- - don't change directory when running makeindex\n", " -jobname=STRING - set basename of output file(s) to STRING.\n", " (Like --jobname=STRING on command line for many current\n", " implementations of latex/pdflatex.)\n", @@ -4050,6 +4003,8 @@ sub print_help " -M - Show list of dependent files after processing\n", " -MF file - Specifies name of file to receives list dependent files\n", " -MP - List of dependent files includes phony target for each source file.\n", + " -makeindexfudge - change directory to output directory when running makeindex\n", + " -makeindexfudge-- don't change directory to output directory when running makeindex\n", " -MSWinBackSlash under MSWin use backslash (\\) for directory separators\n", " for filenames given to called programs\n", " -MSWinBackSlash- under MSWin use forward slash (/) for directory separators\n", @@ -4057,11 +4012,16 @@ sub print_help " -new-viewer - in -pvc mode, always start a new viewer\n", " -new-viewer- - in -pvc mode, start a new viewer only if needed\n", " -nobibtex - never use bibtex\n", - " -nobibfudge - don't use change-directory fudge needed for old bibtexs\n", + " -nobibfudge or -nobibtexfudge - don't change directory when running bibtex\n", " -nodependents - Do not show list of dependent files after processing\n", + " -noindexfudge or -nomakeindexfudge - don't change directory when running makeindex\n", " -norc - omit automatic reading of system, user and project rc files\n", " -output-directory=dir or -outdir=dir\n", " - set name of directory for output files\n", + " -output-format=FORMAT\n", + " - if FORMAT is dvi, turn on dvi output, turn off others\n", + " - if FORMAT is pdf, turn on pdf output, turn off others\n", + " - otherwise error\n", " -pdf - generate pdf by pdflatex\n", " -pdfdvi - generate pdf by dvipdf\n", " -pdflatex= - set program used for pdflatex.\n", @@ -4337,7 +4297,11 @@ sub run_bibtex { my $return = 999; # Prevent changes we make to environment becoming global: local %ENV = %ENV; + my ( $base, $path, $ext ) = fileparseA( $$Psource ); + # Define source and dest base to include extension, no path. + my $source_base = $base.$ext; + my $dest_base = basename( $$Pdest ); if ( $path && $bibtex_fudge ) { # Up to TeXLive 2018, the following was true; situation has changed since. # When an output directory is specified and with a bibtex from 2018 or @@ -4346,6 +4310,9 @@ sub run_bibtex { # directory to the directory of the top-level .aux file to run bibtex. # But we have to fix search paths for .bib and .bst, since they may be # specified relative to the document directory. + # There is also another problem: Depending on the exact + # specification of the aux dir, bibtex may refuse to write to the + # aux dir, for security reasons. my $cwd = good_cwd(); foreach ( 'BIBINPUTS', 'BSTINPUTS' ) { if ( exists $ENV{$_} ) { @@ -4357,31 +4324,56 @@ sub run_bibtex { } pushd( $path ); if (!$silent) { - print "$My_name: ==========WARNING:=================\n", - "I am taking action to evade a bug/feature in older versions of bibtex\n", - "This may give problems under some situations, symptomized by bibtex not\n", - "finding a .bib file or an aux file.\n", - "Provided you have a recent version of bibtex (about 2019 or later) you\n", - "can avoid the problems by putting '\$bibtex_fudge = 0;' in an\n", - "initialization file (a latexmrc file for $my_name.\n", - "\n", - "Here my bug-evading action:\n", - "I temporarily changed directory to '$path'\n", - "Set BIBINPUTS='$ENV{BIBINPUTS}'\n", - "Set BSTINPUTS='$ENV{BSTINPUTS}'\n"; - } - $return = &Run_subst( undef, undef, '', $base.$ext, '', $base ); + print "$My_name: Change directory to '$path'.\n", + "To assist finding of files in document\n", + "directory, I set\n", + " BIBINPUTS='$ENV{BIBINPUTS}'\n", + " BSTINPUTS='$ENV{BSTINPUTS}'.\n"; + } + # Override standard substitutions for source, dest, and base names in + # default external command: + $return = &Run_subst( undef, undef, '', $source_base, $dest_base, $base ); popd(); if (!$silent) { - print "$My_name: changed directory back to '", cwd(), "'\n"; + print "$My_name: Change directory back to '", cwd(), "'\n"; } } else { + # Use default substitutions etc for rule: $return = Run_subst(); } return $return; -} +} #END run_bibtex + +#************************************************** +sub run_makeindex { + my $return = 999; + my ( $base, $path, $ext ) = fileparseA( $$Psource ); + + # Define source and dest base to include extension, no path. + my $source_base = $base.$ext; + my $dest_base = basename( $$Pdest ); + if ( $path && $makeindex_fudge ) { + my $cwd = good_cwd(); + pushd( $path ); + if (!$silent) { + print "$My_name: Change directory to '$path'.\n"; + } + # Override standard substitutions for source, dest, and base names in + # default external command: + $return = &Run_subst( undef, undef, '', $source_base, $dest_base, $base ); + popd(); + if (!$silent) { + print "$My_name: Change directory back to '", cwd(), "'\n"; + } + } + else { + # Use default substitutions etc for rule: + $return = Run_subst(); + } + return $return; +} #END run_makeindex #************************************************** @@ -4423,7 +4415,6 @@ sub check_bibtex_log { } close $blg_file; my $missing = $missing_citations + $#missing_aux + 1; - if ( $#missing_aux > -1 ) { # Need to make the missing files. warn "$My_name: One or more aux files is missing for bibtex. I'll try\n", @@ -4453,17 +4444,15 @@ sub check_bibtex_log { sub normalize_force_directory { # Usage, normalize_force_directory( dir, filename ) + # Filename is assumed to be relative to dir (terminated with directory separator). # Perform the following operations: # Clean filename - # If filename contains no path component, insert dir in front + # Prefix filename with dir # Normalize filename # Return result - my $default_dir = $_[0]; + my $dir = $_[0]; my $filename = clean_filename( $_[1] ); - my ($base_name, $path ) = fileparse( $filename ); - if ( $base_name eq $filename ) { - $filename = "$default_dir$filename"; - } + $filename = "$dir$filename"; return normalize_filename( $filename ); } #END normalize force_directory @@ -4595,22 +4584,6 @@ sub parse_log { # print "==== Cusdep to-exts:"; foreach (keys %cusdep_to) {print " '$_'";} print "\n"; - # Filenames given in log file may be preceded by a pathname - # denoting current directory. In MiKTeX, this is an absolute - # pathname; in TeXLive, it is './'. Either way, we'll want to - # remove this pathname string --- see the comments in sub - # rdb_set_latex_deps. In order of reliability for use in - # normalizing filenames from the log file, the following forms - # of the cwd are used: - # (a) internally deduced pwd from log file from sequence of lines - # **file - # (dir/file - # if possible. NO THAT'S WRONG if kpsearch is done. - # (b) from PWD line in fls file (if available), passed as $pwd_latex - # (c) system-given cwd as interpreted by sub good_cwd. - # We'll put the first two in @pwd_log - my @pwd_log = (); - if ($pwd_latex) { push @pwd_log, $pwd_latex; } # $primary_out is actual output file (dvi or pdf) # It is initialized before the call to this routine, to ensure @@ -4851,6 +4824,8 @@ LINE: # \openout followed by filename followed by line end. # pdflatex and xelatex quote it and wrap, # lualatex leaves filename as is, and doesn't wrap. + # Filename is always relative to aux_dir, given standard security + # settings in TeXLive. my $cand = $1; if ( $cand =~ /\`\"([^\'\"]+)\"\'\.$/ ) { # One form of quoting by pdflatex, xelatex: `"..."'. @@ -4864,7 +4839,7 @@ LINE: # Bad quotes: e.g., incomplete wrapped line next LINE; } - $generated_log{normalize_force_directory( $aux_dir1, $cand )} = 1; + $generated_log{ normalize_force_directory($aux_dir1, $cand) } = 1; next LINE; } # Test for conversion produced by package: @@ -4903,7 +4878,7 @@ LINE: $idx_file =~ s/\s*$//; # When *latex is run with an -output-directory # or an -aux_directory, the file name does not contain - # the output path; fix this, after removing quotes: + # the path. Fix this: $idx_file = normalize_force_directory( $aux_dir1, $idx_file ); my ($idx_base, $idx_path, $idx_ext) = fileparseA( $idx_file ); $idx_base = $idx_path.$idx_base; @@ -4928,10 +4903,10 @@ LINE: next LINE; } elsif ( /^No file (.*?\.bbl)./ ) { - my $bbl_file = normalize_force_directory( $aux_dir1, $1); - my $aux_file = $bbl_file; - $aux_file =~ s/\.bbl$/\.aux/; - warn "$My_name: Non-existent bbl file '$bbl_file in line'\n $_\n"; + # Filename is always relative to aux_dir, given standard security + # settings in TeXLive. + my $bbl_file = normalize_force_directory( $aux_dir1, $1 ); + warn "$My_name: Missing bbl file '$bbl_file' in following:\n $_\n"; $dependents{$bbl_file} = 0; push @bbl_files, $bbl_file; next LINE; @@ -4939,11 +4914,11 @@ LINE: foreach my $pattern (@file_not_found) { if ( /$pattern/ ) { my $file = clean_filename($1); - warn "$My_name: Missing input file: '$file' from line\n '$_'\n" + warn "$My_name: Missing input file: '$file' from following:\n '$_'\n" unless $silent; $dependents{normalize_filename($file, @pwd_log)} = 0; my $file1 = $file; - if ( $aux_dir ) { + if ( $aux_dir && ($aux_dir ne '.') ) { # Allow for the possibility that latex generated # a file in $aux_dir, from which the missing file can # be created by a cusdep (or other) rule that puts @@ -4955,8 +4930,6 @@ LINE: # relative to the aux_dir, so allow for that as well my $file1 = normalize_force_directory( $aux_dir1, $file ); $dependents{$file1} = 0; - $dependents{$aux_dir1.$file} = 0; - } next LINE; } @@ -5147,6 +5120,7 @@ LINE: next INCLUDE_NAME; } $include_name = normalize_filename( $include_name, @pwd_log ); + if ( ! defined $include_name ) { next INCLUDE_NAME; } my ($base, $path, $ext) = fileparseB( $include_name ); if ( ($path eq './') || ($path eq '.\\') ) { $include_name = $base.$ext; @@ -5434,6 +5408,11 @@ sub parse_fls { if ( ! open ($fls_file, "<$fls_name") ) { return 1; } + + my $pdf_base = basename($pdf_name); + my $log_base = basename($log_name); + my $out_base = basename($$Pdest); + foreach $_ ( <$fls_file> ) { # Remove trailing CR and LF. Thus we get correct behavior when an fls file # is produced by MS-Windows program (e.g., in MiKTeX) with CRLF line ends, @@ -5441,12 +5420,15 @@ sub parse_fls { # in read-in lines): $_ =~ s/[\n\r]*$//; if (/^\s*PWD\s+(.*)$/) { - $cwd = $1; - $$Ppwd_latex = $cwd; - if ( $cwd =~ /\"/ ) { + my $cwd_fls = $1; + $$Ppwd_latex = $cwd_fls; + if ( $cwd_fls =~ /\"/ ) { warn "$My_name: The working directory has a '\"' character in its name:\n", " '$cwd'\n This can cause me trouble. Beware!\n"; } + if ( normalize_filename($cwd_fls) ne normalize_filename($cwd) ) { + print "$My_name: ============== Inequiv cwd_fls cwd '$cwd_fls' '$cwd'\n"; + } } elsif (/^\s*INPUT\s+(.*)$/) { # Take precautions against aliasing of foo, ./foo and other possibilities for cwd. @@ -5463,7 +5445,34 @@ sub parse_fls { if ( (exists $$Poutputs{$file}) && (! exists $$Pinputs{$file}) ) { $$Pfirst_read_after_write{$file} = 1; } - $$Pinputs{$file} = 1; + # Take precautions against main destination file being listed as INPUT file + # This results, e.g., from hyperxmp (2020/10/05 v. 5.6) reading the pdf file + # size, and triggers an infinite loop, unless we omit the pdf file from the + # list of input files. (Hyperxmp v. 5.7 2010/11/01 doesn't give this problem.) + # There's a related issue with the log file, when acmart.cls is used with + # xelatex. (I don't work out what causes this, e.g., what package.) + # Test on basenames rather than full name to evade in a simple-minded way + # alias issues with the directory part. + if ( basename($file) eq $pdf_base ) { + warn "$My_name: !!!!!!!!!!! Fls file lists main pdf **output** file as an input\n", + " file for rule '$rule'. I won't treat as a source file, since that leads\n", + " to an infinite loop.\n", + " This can be caused by the hyperxmp package in an old version.\n", + " You should update to hyperxmp in ver. 5.7 or higher\n"; + } elsif ( basename($file) eq $out_base ) { + warn "$My_name: !!!!!!!!!!! Fls file lists main **output** file as an input\n", + " file for rule '$rule'. I won't treat as a source file, since that leads\n", + " to an infinite loop.\n", + " This can be caused by the hyperxmp package in an old version.\n", + " You should update to hyperxmp in ver. 5.7 or higher\n"; + } elsif ( basename($file) eq $log_base ) { + warn "$My_name: !!!!!!!!!!! Fls file lists log file as an input\n", + " file for rule '$rule'. I won't treat it as a source file, since\n", + " there appear to be no good uses for it.\n", + " This behavior happens at least under acmart.cls with xelatex\n"; + } else { + $$Pinputs{$file} = 1; + } } elsif (/^\s*OUTPUT\s+(.*)$/) { # Take precautions against aliasing of foo, ./foo and other possibilities for cwd. @@ -5481,7 +5490,6 @@ sub parse_fls { sub dirname_no_tail { my $dirname = $_[0]; -# print "DNT1 = '$dirname'\n"; foreach ($dirname) { # Normalize name to use / to separate directory components: # (Note both / and \ are allowed under MSWin.) @@ -5497,7 +5505,6 @@ sub dirname_no_tail { } } } -# print "DNT2 = '$dirname'\n"; return $dirname; } @@ -5525,28 +5532,44 @@ sub clean_filename { sub normalize_filename { # Usage: normalize_filename( filename [, extra forms of name of cwd] ) # Returns filename with removal of various forms for cwd, and - # with conversion of directory separator to '/' only + # with conversion of directory separator to '/' only. + # Works also when filename is name of a directory. # my ( $file, @dirs ) = @_; my $file1 = $file; # Saved original value my $cwd = good_cwd(); + my $cwd1 = cwd(); # Normalize files to use / to separate directory components: # (Note both / and \ are allowed under MSWin.) - foreach ($cwd, $file, @dirs) { + foreach ($cwd, $cwd1, $file, @dirs) { s(\\)(/)g; $_ = dirname_no_tail( $_ ); } + if ($filename eq '.') { $filename = ''; } # Remove initial component equal to current working directory. # Use \Q and \E round directory name in regex to avoid interpretation # of metacharacters in directory name: - foreach my $dir ( @dirs, '.', $cwd ) { + foreach my $dir ( @dirs, '.', $cwd, $cwd1 ) { if ( $dir =~ /^\s*$/ ) { + # All spaces, nothing to do. next; } + if ($file eq $dir) { + # Filename equals cwd, so it is . relative to cwd: + $file = '.'; + last; + } if ( $file =~ s(^\Q$dir\E/)() ) { last; } } + if ($file eq '.' ) { + # This only occurs for a directory that is the cwd. + # Our convention is always to replace this by a blank. + # Watch out for tests of existence that will go wrong, + # and for a form for concatenating this with a filename. + $file = ''; + } return $file; } @@ -5556,7 +5579,7 @@ sub normalize_clean_filename { # Usage: normalize_clean_filename( filename [, extra forms of name of cwd] ) # Same as normalize_filename, but first remove any double quotes, as # done by clean_filename, which is appropriate for filenames from log file. - my ($file, @dirs) = @_; + my ($file, @dirs) = shift; return normalize_filename( clean_filename( $file ) , @dirs ); } @@ -5934,6 +5957,7 @@ LINE: if ($rule =~ /^makeindex/) { $PA_extra_gen = [ "$base.ilg" ]; } if ($rule =~ /^(bibtex|biber)/) { $PA_extra_gen = [ "$base.blg" ]; } if ($rule =~ /^bibtex/) { $int_cmd = "run_bibtex"; } + if ($rule =~ /^makeindex/) { $int_cmd = "run_makeindex"; } warn "$My_name: File-database '$in_name': setting rule '$rule'\n" if $diagnostics; my $cmd_type = 'external'; @@ -5972,7 +5996,6 @@ LINE: my $size = $3; my $md5 = $4; my $from_rule = $5; -#?? print " --- File '$file'\n"; if ($state != 1) { warn "$My_name: In file-database '$in_name' ", "line $. is outside a section:\n '$_'\n"; @@ -6425,7 +6448,7 @@ sub rdb_set_latex_deps { if ( ! rdb_rule_exists( $from_rule ) ){ print "!!!===Creating rule '$from_rule': '$ind_file' from '$idx_file'\n" if ($diagnostics); - rdb_create_rule( $from_rule, 'external', $makeindex, '', 1, + rdb_create_rule( $from_rule, 'external', $makeindex, 'run_makeindex', 1, $idx_file, $ind_file, $ind_base, 1, 0, 0, 1, [ "$ind_base.ilg" ] ); print " ===Source file '$ind_file' for '$rule'\n" if ($diagnostics); @@ -6959,10 +6982,9 @@ DEP: if ( (! -e $file) && $use_make_for_missing_files ) { # Try to make the missing file #Set character to surround filenames in commands: - my $q = $quote_filenames ? '"' : ''; if ( $toext ne '' ) { print "$My_name: '$rule': source file '$file' doesn't exist. I'll try making it...\n"; - &Run_subst( "$make $q$file$q" ); + &Run_subst( "$make $quote$file$quote" ); if ( -e $file ) { return; } @@ -6972,7 +6994,7 @@ DEP: " I'll try making it with allowed extensions \n"; foreach my $try_ext ( keys %$Pinput_extensions ) { my $new_dest = "$file.$try_ext"; - &Run_subst( "$make $q$new_dest$q" ); + &Run_subst( "$make $quote$new_dest$quote" ); if ( -e $new_dest ) { print "SUCCESS in making '$new_dest'\n"; # Put file in rule, without a from_rule, but @@ -7763,7 +7785,7 @@ sub rdb_classify2 { sub rdb_run1 { - # Assumes contexts for: rule. + # Assumes context for: rule. # Unconditionally apply the rule # Returns return code from applying the rule. # Otherwise: 0 on other kind of success, @@ -7790,7 +7812,8 @@ sub rdb_run1 { if ( ! defined $_ ) { $_ = 'undef'; } } if ($int_cmd) { - print "For rule '$rule', running '\&$int_cmd( @int_args_for_printing )' ...\n"; + print "For rule '$rule', use internal command '\&$int_cmd( @int_args_for_printing )' ...\n" + if $diagnostics; $return = &$int_cmd( @int_args ); } elsif ($$Pext_cmd) { @@ -7976,7 +7999,8 @@ sub Run_subst { # options, source, dest, base: correspond to placeholders. # Substitutions: # %S=source, %D=dest, %B=base, %R=root=base for latex, %O=options, - # %T=texfile, %Y=$aux_dir1, %Z=$out_dir1 + # %T=texfile, + # %V=$aux_dir, %W=$out_dir, %Y=$aux_dir1, %Z=$out_dir1 # This is a globally usable subroutine, and works in a rule context, # and outside. # Defaults: @@ -8001,24 +8025,24 @@ sub Run_subst { } #Set character to surround filenames: - my $q = $quote_filenames ? '"' : ''; - my %subst = ( - '%A' => $q.$tex_basename.$q, - '%B' => $q.$base.$q, - '%D' => $q.$dest.$q, + '%A' => $quote.$tex_basename.$quote, + '%B' => $quote.$base.$quote, + '%D' => $quote.$dest.$quote, '%O' => $options, - '%S' => $q.$source.$q, - '%R' => $q.$root_filename.$q, - '%S' => $q.$source.$q, - '%T' => $q.$texfile_name.$q, - '%Y' => $q.$aux_dir1.$q, - '%Z' => $q.$out_dir1.$q, + '%S' => $quote.$source.$quote, + '%R' => $quote.$root_filename.$quote, + '%S' => $quote.$source.$quote, + '%T' => $quote.$texfile_name.$quote, + '%V' => $quote.$aux_dir.$quote, + '%W' => $quote.$out_dir.$quote, + '%Y' => $quote.$aux_dir1.$quote, + '%Z' => $quote.$out_dir1.$quote, '%%' => '%' # To allow literal %B, %R, etc, by %%B. ); if ($pre_tex_code) { - $subst{'%U'} = $q.$pre_tex_code.$q; - $subst{'%P'} = "$q$pre_tex_code\\input{$source}$q"; + $subst{'%U'} = $quote.$pre_tex_code.$quote; + $subst{'%P'} = "$quote$pre_tex_code\\input{$source}$quote"; } else { $subst{'%U'} = ''; @@ -8594,7 +8618,6 @@ sub rdb_one_rule { #===== Accesses rule part of database structure ======= local ( $rule, $rule_act1, $file_act, $rule_act2 ) = @_; -#?? &R1; if ( (! $rule) || ! rdb_rule_exists($rule) ) { return; } local ( $PArule_data, $PHsource, $PHdest, $PHsource_rules ) = @{$rule_db{$rule}}; @@ -8608,7 +8631,6 @@ sub rdb_one_rule { &$rule_act1 if $rule_act1; &rdb_do_files( $file_act ) if $file_act; &$rule_act2 if $rule_act2; -#?? &R2; } #END rdb_one_rule #************************************************************ @@ -8671,7 +8693,6 @@ sub rdb_one_file { # Assumes $rule context set. #===== Accesses file part of database structure ======= local ($file, $file_act) = @_; -#?? &F1; if ( (!$file) ||(!exists ${$PHsource}{$file}) ) { return; } local $PAfile_data = ${$PHsource}{$file}; local ($Ptime, $Psize, $Pmd5, $Pfrom_rule, $Pcorrect_after_primary ) @@ -8680,7 +8701,6 @@ sub rdb_one_file { if ( ! rdb_rule_exists( $$Pfrom_rule ) ) { $$Pfrom_rule = ''; } -#?? &F2; } #END rdb_one_file #************************************************************ @@ -9354,7 +9374,6 @@ sub find_file1 { else { return( $name, 1 );} } foreach my $dir ( @path ) { - #??print "-------------dir='$dir', "; # Make $dir concatenatable, and empty for current dir: if ( $dir eq '.' ) { $dir = ''; @@ -9366,7 +9385,6 @@ sub find_file1 { #Append directory separator only to non-empty dir $dir = "$dir/"; } - #?? print " newdir='$dir'\n"; if (-e "$dir$name") { return("$dir$name", 0); } @@ -9417,8 +9435,6 @@ sub find_file_list1 { } } @$ref_output = @return_list; -#?? show_array( " Output", @$ref_output ); -#?? foreach (@$ref_output) { if ( /\/\// ) { print " ====== double slash in '$_'\n"; } } return @not_found; } #END find_file_list1 @@ -10021,10 +10037,12 @@ sub Run_Detached { sub find_process_id { # find_process_id(string) finds id of process containing string and -# being run by the present user. Typically the string will be the -# name of the process or part of its command line. +# being run by the present user. In all the uses in latexmk, the string is +# the name of a file that is expected to be on the command line. +# # On success, this subroutine returns the process ID. # On failure, it returns 0. +# # This subroutine only works on UNIX systems at the moment. if ( $pid_position < 0 ) { @@ -10079,7 +10097,7 @@ sub cache_good_cwd { # that the result can be used for input to MSWin programs as well # as cygwin programs. # Similarly for msys. - my $cwd = cwd(); + my $cwd = getcwd(); if ( $^O eq "cygwin" ) { my $cmd = "cygpath -w \"$cwd\""; my $Win_cwd = `$cmd`; @@ -10099,6 +10117,10 @@ sub cache_good_cwd { elsif ( $^O eq "msys" ) { $cwd =~ s[^/([a-z])/][\u$1:/]; } + # Normalized + if ($normalize_names) { + $cwd = abs_path($cwd); + } $cache{cwd} = $cwd; } # END cache_good_cwd -- cgit v1.2.3