~ubuntu-branches/ubuntu/vivid/latexmk/vivid

« back to all changes in this revision

Viewing changes to latexmk.pl

  • Committer: Package Import Robot
  • Author(s): OHURA Makoto
  • Date: 2015-01-12 16:24:19 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20150112162419-difnytcz3xntdeco
Tags: 1:4.41-1
* New upstream release
* debian/patches/rc_system_files.patch: refresh.
* debian/control: Update Standards-Version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env perl
2
2
 
 
3
# !!!!!!!!!! Don't forget to document $silence_logfile_warnings.!!!
 
4
 
3
5
# N.B. !!!!!!!!!!!  See 17 July 2012 comments !!!!!!!!!!!!!!!!!!
4
6
 
 
7
# Re -cd issue !!!!!!!!!!!!! SEE "??!!" COMMENTS.
 
8
#     If relative path is given for $out_dir or $aux_dir, and -cd is
 
9
#     used, should it be interpreted w.r.t. initial cwd (i.e., cwd when
 
10
#     latexmk is started), or w.r.t. to document directory???????
 
11
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5
12
 
6
13
# On a UNIX-like system, the above enables latexmk to run independently
7
14
#   of the location of the perl executable.  This line relies on the 
111
118
 
112
119
$my_name = 'latexmk';
113
120
$My_name = 'Latexmk';
114
 
$version_num = '4.39';
115
 
$version_details = "$My_name, John Collins, 10 Nov 2013";
 
121
$version_num = '4.41';
 
122
$version_details = "$My_name, John Collins, 1 January 2015";
116
123
 
117
124
use Config;
118
125
use File::Basename;
119
126
use File::Copy;
 
127
use Cwd 'abs_path';
120
128
use File::Glob ':glob';    # Better glob.  Does not use space as item separator.
121
129
use File::Path 2.08 qw( make_path );
122
130
use FileHandle;
147
155
   warn "Something wrong with the perl configuration: No signals?\n";
148
156
}
149
157
 
150
 
## Copyright John Collins 1998-2013
151
 
##           (username collins at node phys.psu.edu)
 
158
## Copyright John Collins 1998-2015
 
159
##           (username jcc8 at node psu.edu)
152
160
##      (and thanks to David Coppit (username david at node coppit.org) 
153
161
##           for suggestions) 
154
162
## Copyright Evan McLean
184
192
##   Modification log from 9 Dec 2011 onwards in detail
185
193
##
186
194
##   12 Jan 2012 STILL NEED TO DOCUMENT some items below
 
195
##
 
196
##      1 Jan 2015  John Collins  V. 4.41
 
197
##     18 Dec 2014  John Collins  -c also deletes $deps_file if it is used.
 
198
##     16 Dec 2014  John Collins  Finish change of e-mail
 
199
##      5 Dec 2014  John Collins  Quote jobname when needed.
 
200
##      5 Sep 2014  John Collins  Change my e-mail
 
201
##     30 Aug 2014  John Collins  Change my e-mail
 
202
##     13 Aug 2014  John Collins  Try to correct error handling to avoid
 
203
##                                repeated runs of latex after an error.
 
204
##                                Revert to some code from v. 4-32.
 
205
##                                Do I need $retry_msg?
 
206
##      8 Aug 2014  John Collins  Fix up for the making of -eps-converted-to.pdf
 
207
##      4 Aug 2014  John Collins  Sort and remove redundant xxx-undefined
 
208
##                                   warning lines from log file.
 
209
##     23 Jul 2014  John Collins  Fix failure when using both -cd and -output-directory
 
210
##     22 Jul 2014  John Collins  If $HOME not set, then don't read ~/.latexmkrc
 
211
##                                Introduce $silence_logfile_warnings
 
212
##     21 Jul 2014  John Collins  In setting $pscmd, allow for non-existent
 
213
###                                 $ENV{USER}
 
214
##     29 May 2014  John Collins  Correct sub Run for internal cmd w/o arguments
 
215
##     21 Mar 2014  John Collins  Experimental: Add analysis hook for aux file.
 
216
##                                But I need to change rdb_create_rule in someway to 
 
217
##                                allow correct handling of: (a) rule creation if 
 
218
##                                rule doesn't exist, (b) either no change, or rule
 
219
##                                update, if the rule exists.  No change is a bad
 
220
##                                idea, because conditions may change.  Such a 
 
221
##                                change, to effectively rdb_ensure_rule, would also
 
222
##                                help other dependencies, e.g., if a custom
 
223
##                                dependency has been created on one run of latexmk,
 
224
##                                and then on another run the definition is changed.
 
225
##                                With the old method, the old cus-dep is used unless 
 
226
##                                the dependency cache fdb_latexmk is cleared; but
 
227
##                                with the new method the custom dependency will be
 
228
##                                changed correctly.
 
229
##      5 Mar 2014  John Collins  System initialization files: allow them
 
230
##                                  to be named latexmkrc as well as LatexMk,
 
231
##                                  for more consistency with user directory
 
232
##                                  names.  Keep both cases, to preserve
 
233
##                                  backward compatibility.
 
234
##     30 Jan 2014  John Collins  Change sign-on message.  Bug report info with help. V. 4.40a
 
235
##     15 Jan 2014  John Collins  Fix failure to clean up correctly when
 
236
##                                   root filename contains [, which is
 
237
##                                   a glob metacharacter.
 
238
##                                V. 4.40
187
239
##     10 Nov 2013  John Collins  Change split / /, ... to split /\s*/, ...
188
240
##                                   so as to be immune from extra white space.
189
241
##                                Clean up $clean_ext and $clean_full_ext by removing 
361
413
# (Documentation obviously needs to be improved!)
362
414
%extra_rule_spec = ();
363
415
 
 
416
 
 
417
# Hooks for customized extra processing on aux files.  The following
 
418
# variable is an array of references to function.  Each function is
 
419
# invoked in turn when a line of an aux file is processed (if none
 
420
# of the built-in actions have been done).  On entry to the function,
 
421
# the following variables are set:
 
422
#    $_ = current line of aux file
 
423
#    $rule = name of rule during the invocation of which, the aux file
 
424
#            was supposed to have been generated.
 
425
@aux_hooks = ();
 
426
 
364
427
#########################################################################
365
428
## Default document processing programs, and related settings,
366
429
## These are mostly the same on all systems.
620
683
$del_dir = '';        # Directory into which cleaned up files are to be put.
621
684
                      # If $del_dir is '', just delete the files
622
685
 
 
686
@rc_system_files = ();
 
687
 
623
688
#########################################################################
624
689
 
625
690
################################################################
665
730
 
666
731
 
667
732
# System-dependent overrides:
 
733
# Currently, the cases I have tests for are: MSWin32, cygwin, linux and 
 
734
#   darwin, with the main complications being for MSWin32 and cygwin.
 
735
# Special treatment may also be useful for MSYS (for which $^O reports 
 
736
#   "msys").  This is another *nix-emulation/system for MSWindows.  At
 
737
#   present it is treated as unix-like, but the environment variables
 
738
#   are those of Windows.  (The test for USERNAME as well as USER was
 
739
#   to make latexmk work under MSYS's perl.)
 
740
#
668
741
if ( $^O eq "MSWin32" ) {
669
742
# Pure MSWindows configuration
670
743
    ## Configuration parameters:
676
749
 
677
750
    ## List of possibilities for the system-wide initialization file.  
678
751
    ## The first one found (if any) is used.
679
 
    @rc_system_files = ( 'C:/latexmk/LatexMk' );
 
752
    @rc_system_files = ( "C:/latexmk/LatexMk", "C:/latexmk/latexmkrc" );
680
753
 
681
754
    $search_path_separator = ';';  # Separator of elements in search_path
682
755
 
776
849
    ## List of possibilities for the system-wide initialization file.  
777
850
    ## The first one found (if any) is used.
778
851
    ## We could stay with MSWin files here, since cygwin perl understands them
779
 
    ## @rc_system_files = ( 'C:/latexmk/LatexMk' );
 
852
    ## @rc_system_files = ( 'C:/latexmk/LatexMk', 'C:/latexmk/latexmkrc' );
780
853
    ## But they are deprecated in v. 1.7.  So use the UNIX version, prefixed
781
854
    ##   with a cygwin equivalent of the MSWin location
782
 
    @rc_system_files = 
783
 
     ( '/cygdrive/c/latexmk/LatexMk', 
784
 
       '/opt/local/share/latexmk/LatexMk', 
785
 
       '/usr/local/share/latexmk/LatexMk',
786
 
       '/usr/local/lib/latexmk/LatexMk' );
787
 
 
 
855
    ## In addition, we need to add the same set of possible locations as with
 
856
    ## unix, so that the user use a unix-style setup.
 
857
    @rc_system_files = ();
 
858
    foreach ( 'LatexMk', 'latexmkrc' ) {
 
859
       push @rc_system_files,
 
860
            ( "/cygdrive/c/latexmk/$_", 
 
861
              "/opt/local/share/latexmk/$_", 
 
862
              "/usr/local/share/latexmk/$_",
 
863
              "/usr/local/lib/latexmk/$_" );
 
864
    }
788
865
    $search_path_separator = ';';  # Separator of elements in search_path
789
866
    # This is tricky.  The search_path_separator depends on the kind
790
867
    # of executable: native NT v. cygwin.  
852
929
    ## The first one found (if any) is used.
853
930
    ## Normally on a UNIX it will be in a subdirectory of /opt/local/share or
854
931
    ## /usr/local/share, depending on the local conventions.
855
 
    ## /usr/local/lib/latexmk/LatexMk is put in the list for
 
932
    ## But /usr/local/lib/latexmk is put in the list for
856
933
    ## compatibility with older versions of latexmk.
857
 
    @rc_system_files = 
858
 
     ( '/etc/LatexMk',
859
 
       '/opt/local/share/latexmk/LatexMk', 
860
 
       '/usr/local/share/latexmk/LatexMk',
861
 
       '/usr/local/lib/latexmk/LatexMk' );
862
 
 
 
934
    @rc_system_files = ();
 
935
    foreach ( 'LatexMk', 'latexmkrc' ) {
 
936
       push @rc_system_files,
 
937
            ( "/etc/$_",
 
938
              "/opt/local/share/latexmk/$_", 
 
939
              "/usr/local/share/latexmk/$_",
 
940
              "/usr/local/lib/latexmk/$_" );
 
941
    }
863
942
    $search_path_separator = ':';  # Separator of elements in search_path
864
943
 
865
944
    $dvi_update_signal = $signo{USR1} 
920
999
    #
921
1000
    # The following works on Solaris, LINUX, HP-UX, IRIX
922
1001
    # Use -f to get full listing, including command line arguments.
923
 
    # Use -u $ENV{CMD} to get all processes started by current user (not just
 
1002
    # Use -u $ENV{USER} to get all processes started by current user (not just
924
1003
    #   those associated with current terminal), but none of other users' 
925
1004
    #   processes. 
926
 
    $pscmd = "ps -f -u $ENV{USER}"; 
 
1005
    # However, the USER environment variable may not exist.  Windows uses 
 
1006
    #   USERNAME instead.  (And this propagates to a situation of 
 
1007
    #   unix-emulation software running under Windows.) 
 
1008
    if ( exists $ENV{USER} ) {
 
1009
       $pscmd = "ps -f -u $ENV{USER}"; 
 
1010
    }
 
1011
    elsif ( exists $ENV{USERNAME} ) {
 
1012
       $pscmd = "ps -f -u $ENV{USERNAME}"; 
 
1013
    }
 
1014
    else {
 
1015
       $pscmd = "ps -f"; 
 
1016
    }
927
1017
    $pid_position = 1; # offset of PID in output of pscmd; first item is 0.  
928
1018
    if ( $^O eq "linux" ) {
929
1019
        # Ps on Redhat (at least v. 7.2) appears to truncate its output
975
1065
                        # occur, which mess up page numbers in the toc and lof,
976
1066
                        # Hence a 4th run is conceivably necessary. 
977
1067
                        # At least one document class (JHEP.cls) works
978
 
                        # in such a way that a 4th run is needed.  
 
1068
                        # in such a way that a 4th run is needed.  
979
1069
                        # We allow an extra run for safety for a
980
 
                        # maximum of 5. Needing further runs is
981
 
                        # usually an indication of a problem; further
982
 
                        # runs may not resolve the problem, and
983
 
                        # instead could cause an infinite loop.
 
1070
                        # maximum of 5. Needing further runs is
 
1071
                        # usually an indication of a problem; further
 
1072
                        # runs may not resolve the problem, and
 
1073
                        # instead could cause an infinite loop.
984
1074
$clean_ext = "";        # space separated extensions of files that are
985
1075
                        # to be deleted when doing cleanup, beyond
986
1076
                        # standard set
1008
1098
                        # backward compatibility.
1009
1099
 
1010
1100
$fdb_ext = 'fdb_latexmk'; # Extension for the file for latexmk's
1011
 
                          # file-database
 
1101
                          # file-database
1012
1102
                          # Make it long to avoid possible collisions.
1013
1103
$fdb_ver = 3;             # Version number for kind of fdb_file.
1014
1104
 
1026
1116
 
1027
1117
## default flag settings.
1028
1118
$recorder = 1;          # Whether to use recorder option on latex/pdflatex
1029
 
$silent = 0;            # silence latex's messages?
1030
 
$landscape_mode = 0;    # default to portrait mode
 
1119
$silent = 0;            # Silence latex's messages?
 
1120
$silence_logfile_warnings = 0; # Do list warnings in log file
 
1121
$landscape_mode = 0;    # default to portrait mode
1031
1122
 
1032
1123
# The following two arrays contain lists of extensions (without
1033
1124
# period) for files that are read in during a (pdf)LaTeX run but that
1063
1154
                        #     2 to create pdf file by ps2pdf
1064
1155
                        #     3 to create pdf file by dvipdf
1065
1156
$view = 'default';      # Default preview is of highest of dvi, ps, pdf
1066
 
$sleep_time = 2;        # time to sleep b/w checks for file changes in -pvc mode
 
1157
$sleep_time = 2;        # time to sleep b/w checks for file changes in -pvc mode
1067
1158
$banner = 0;            # Non-zero if we have a banner to insert
1068
1159
$banner_scale = 220;    # Original default scale
1069
1160
$banner_intensity = 0.95;  # Darkness of the banner message
1076
1167
$deps_file = '-';       # File for dependency list output.  Default stdout.
1077
1168
$rules_list = 0;        # Whether to display list(s) of dependencies
1078
1169
@dir_stack = ();        # Stack of pushed directories, each of form of 
1079
 
                        # pointer to array  [ cwd, good_cwd ], where
1080
 
                        # good_cwd differs from cwd by being converted
1081
 
                        # to native MSWin path when cygwin is used.
 
1170
                        # pointer to array  [ cwd, good_cwd ], where
 
1171
                        # good_cwd differs from cwd by being converted
 
1172
                        # to native MSWin path when cygwin is used.
1082
1173
$cleanup_mode = 0;      # No cleanup of nonessential LaTex-related files.
1083
1174
                        # $cleanup_mode = 0: no cleanup
1084
1175
                        # $cleanup_mode = 1: full cleanup 
1093
1184
                        # Determines whether cleanup deletes files generated by
1094
1185
                        #    (pdf)latex (found from \openout lines in log file).
1095
1186
$diagnostics = 0;
1096
 
$dvi_filter = '';       # DVI filter command
1097
 
$ps_filter = '';        # Postscript filter command
 
1187
$dvi_filter = '';       # DVI filter command
 
1188
$ps_filter = '';        # Postscript filter command
1098
1189
 
1099
1190
$force_mode = 0;        # =1 to force processing past errors
1100
1191
$go_mode = 0;           # =1 to force processing regardless of time-stamps
1125
1216
 
1126
1217
# Used for some results of parsing log file:
1127
1218
$reference_changed = 0;
 
1219
$mult_defined = 0;
1128
1220
$bad_reference = 0;
1129
1221
$bad_citation = 0;
1130
1222
 
1281
1373
                    # Rule data:
1282
1374
                    #   0: [ cmd_type, ext_cmd, int_cmd, test_kind, 
1283
1375
                    #       source, dest, base,
1284
 
                    #       out_of_date, out_of_date_user,
 
1376
                    #       out_of_date, out_of_date_user,
1285
1377
                    #       time_of_last_run, time_of_last_file_check,
1286
1378
                    #       changed
1287
1379
                    #       last_result, last_message,
1291
1383
                    #     cmd_type is 'primary', 'external', or 'cusdep'
1292
1384
                    #     ext_cmd is string for associated external command
1293
1385
                    #       with substitutions (%D for destination, %S
1294
 
                    #       for source, %B for base of current rule,
1295
 
                    #       %R for base of primary tex file, %T for
1296
 
                    #       texfile name, %O for options,
 
1386
                    #       for source, %B for base of current rule,
 
1387
                    #       %R for base of primary tex file, %T for
 
1388
                    #       texfile name, %O for options,
1297
1389
                    #       %Y for $aux_dir1, and %Z for $out_dir1
1298
1390
                    #     int_cmd specifies any internal command to be
1299
 
                    #       used to implement the application of the
1300
 
                    #       rule.  If this is present, it overrides
1301
 
                    #       the external command, and it is the
1302
 
                    #       responsibility of the perl subroutine
1303
 
                    #       specified in intcmd to execute the
1304
 
                    #       external command if this is appropriate.
1305
 
                    #       This variable intcmd is a reference to an array,  
 
1391
                    #       used to implement the application of the
 
1392
                    #       rule.  If this is present, it overrides
 
1393
                    #       the external command, and it is the
 
1394
                    #       responsibility of the perl subroutine
 
1395
                    #       specified in intcmd to execute the
 
1396
                    #       external command if this is appropriate.
 
1397
                    #       This variable intcmd is a reference to an array,  
1306
1398
                    #       $$intcmd[0] = internal routine
1307
1399
                    #       $$intcmd[1...] = its arguments (if any)
1308
1400
                    #     test_kind specifies method of determining
1309
1401
                    #       whether a file is out-of-date:
1310
1402
                    #         0 for never
1311
1403
                    #         1 for usual: whether there is a source
1312
 
                    #              file change 
 
1404
                    #              file change 
1313
1405
                    #         2 for dest earlier than source
1314
1406
                    #         3 for method 2 at first run, 1 thereafter
1315
1407
                    #              (used when don't have file data from
1316
 
                    #              previous run).
 
1408
                    #              previous run).
1317
1409
                    #     source = name of primary source file, if any
1318
1410
                    #     dest   = name of primary destination file,
1319
 
                    #              if any
 
1411
                    #              if any
1320
1412
                    #     base   = base name, if any, of files for
1321
 
                    #              this rule
 
1413
                    #              this rule
1322
1414
                    #     out_of_date = 1 if it has been detected that
1323
 
                    #                     this rule needs to be run
1324
 
                    #                     (typically because a source
1325
 
                    #                     file has changed).
 
1415
                    #                     this rule needs to be run
 
1416
                    #                     (typically because a source
 
1417
                    #                     file has changed).
1326
1418
                    #                   0 otherwise
1327
1419
                    #     out_of_date_user is like out_of_date, except
1328
1420
                    #         that the detection of out-of-dateness
1329
1421
                    #         has been made from a change of a
1330
 
                    #         putative user file, i.e., one that is
1331
 
                    #         not a generated file (e.g., aux). This
1332
 
                    #         kind of out-of-dateness should provoke a
1333
 
                    #         rerun whether or not there was an error
1334
 
                    #         during a run of (pdf)LaTeX.  Normally,
1335
 
                    #         if there is an error, one should wait
1336
 
                    #         for the user to correct the error.  But
1337
 
                    #         it is possible the error condition is
1338
 
                    #         already corrected during the run, e.g.,
1339
 
                    #         by the user changing a source file in
1340
 
                    #         response to an error message. 
 
1422
                    #         putative user file, i.e., one that is
 
1423
                    #         not a generated file (e.g., aux). This
 
1424
                    #         kind of out-of-dateness should provoke a
 
1425
                    #         rerun whether or not there was an error
 
1426
                    #         during a run of (pdf)LaTeX.  Normally,
 
1427
                    #         if there is an error, one should wait
 
1428
                    #         for the user to correct the error.  But
 
1429
                    #         it is possible the error condition is
 
1430
                    #         already corrected during the run, e.g.,
 
1431
                    #         by the user changing a source file in
 
1432
                    #         response to an error message. 
1341
1433
                    #     time_of_last_run = time that this rule was
1342
 
                    #              last applied.  (In standard units
1343
 
                    #              from perl, to be directly compared
1344
 
                    #              with file modification times.)
 
1434
                    #              last applied.  (In standard units
 
1435
                    #              from perl, to be directly compared
 
1436
                    #              with file modification times.)
1345
1437
                    #     time_of_last_file_check = last time that a check
1346
1438
                    #              was made for changes in source files.
1347
1439
                    #     changed flags whether special changes have been made
1446
1538
    # System rc file:
1447
1539
    read_first_rc_file_in_list( @rc_system_files );
1448
1540
}
1449
 
if ( $auto_rc_use ) {
 
1541
if ( $auto_rc_use && ($HOME ne "" ) ) {    
1450
1542
    # User rc file:
 
1543
    # N.B. $HOME equals "" if latexmk couldn't determine a home directory.
 
1544
    # In that case, we shouldn't look for an rc file there.
1451
1545
    read_first_rc_file_in_list( "$HOME/.latexmkrc" );
1452
1546
}
1453
1547
if ( $auto_rc_use ) { 
1509
1603
      push @extra_latex_options, $1;
1510
1604
      push @extra_pdflatex_options, $1;
1511
1605
  }
 
1606
  elsif ( /^-logfilewarninglist$/ || /^-logfilewarnings$/ )
 
1607
      { $silence_logfile_warnings = 0; }
 
1608
  elsif ( /^-logfilewarninglist-$/ || /^-logfilewarnings-$/ )
 
1609
      { $silence_logfile_warnings = 1; }
1512
1610
# See above for -M
1513
1611
  elsif (/^-MF$/) {
1514
1612
     if ( $ARGV[0] eq '' ) {
1515
 
        &exit_help( "No file name specified after -MF switch");
 
1613
        &exit_help( "No file name specified after -MF switch");
1516
1614
     }
1517
1615
     $deps_file = $ARGV[0];
1518
1616
     shift; 
1630
1728
        &exit_help( "No RC file specified after -r switch"); 
1631
1729
     }
1632
1730
     if ( -e $ARGV[0] ) {
1633
 
        process_rc_file( $ARGV[0] );
 
1731
        process_rc_file( $ARGV[0] );
1634
1732
     } 
1635
1733
     else {
1636
 
        die "$My_name: RC file [$ARGV[0]] does not exist\n"; 
 
1734
        die "$My_name: RC file [$ARGV[0]] does not exist\n"; 
1637
1735
     }
1638
1736
     shift; 
1639
1737
  }
1640
1738
  elsif (/^-bm$/) {
1641
1739
     if ( $ARGV[0] eq '' ) {
1642
 
        &exit_help( "No message specified after -bm switch");
 
1740
        &exit_help( "No message specified after -bm switch");
1643
1741
     }
1644
1742
     $banner = 1; $banner_message = $ARGV[0];
1645
1743
     shift; 
1646
1744
  }
1647
1745
  elsif (/^-bi$/) {
1648
1746
     if ( $ARGV[0] eq '' ) {
1649
 
        &exit_help( "No intensity specified after -bi switch");
 
1747
        &exit_help( "No intensity specified after -bi switch");
1650
1748
     }
1651
1749
     $banner_intensity = $ARGV[0];
1652
1750
     shift; 
1653
1751
  }
1654
1752
  elsif (/^-bs$/) {
1655
1753
     if ( $ARGV[0] eq '' ) {
1656
 
        &exit_help( "No scale specified after -bs switch");
 
1754
        &exit_help( "No scale specified after -bs switch");
1657
1755
     }
1658
1756
     $banner_scale = $ARGV[0];
1659
1757
     shift; 
1660
1758
  }
1661
1759
  elsif (/^-dF$/) {
1662
1760
     if ( $ARGV[0] eq '' ) {
1663
 
        &exit_help( "No dvi filter specified after -dF switch");
 
1761
        &exit_help( "No dvi filter specified after -dF switch");
1664
1762
     }
1665
1763
     $dvi_filter = $ARGV[0];
1666
1764
     shift; 
1693
1791
}
1694
1792
 
1695
1793
warn "$My_name: This is $version_details, version: $version_num.\n",
1696
 
     "**** Report bugs etc to John Collins <collins at phys.psu.edu>. ****\n"
1697
1794
   unless $silent;
1698
1795
 
1699
1796
if ( ($out_dir ne '') && ($aux_dir eq '') ){
1700
1797
    $aux_dir = $out_dir;
1701
1798
}
1702
1799
 
 
1800
# Initially $aux_dir and $out_dir are either absolute or relative to CURRENT
 
1801
#    directory.
 
1802
# If we'll cd to directory of TeX file to do our work, we'll need to convert
 
1803
#   any relative directories to absolute, to preserve the user-requested
 
1804
#   directories after a cd.
 
1805
# Otherwise, we need to normalize them in our standard way (to ensure
 
1806
#   standardization in the places we use them.
 
1807
 
 
1808
 
1703
1809
foreach ($out_dir, $aux_dir) {
1704
 
   # Remove aliases to cwd:
1705
 
   $_ = normalize_filename( $_ );
1706
 
   if ($_ eq '.' ) { $_ = ''; }
 
1810
    if ($do_cd) {
 
1811
        $_ = abs_path( $_ );
 
1812
    }
 
1813
    else {
 
1814
        # Remove aliases to cwd:
 
1815
        $_ = normalize_filename( $_ );
 
1816
        if ($_ eq '.' ) { $_ = ''; }
 
1817
    }
1707
1818
}
1708
1819
# Versions terminating in directory/path separator
1709
1820
$out_dir1 = $out_dir;
1726
1837
        $ENV{$_} = $aux_dir.$search_path_separator.$ENV{$_};
1727
1838
    }
1728
1839
    else {
1729
 
        $ENV{$_} = $aux_dir.$search_path_separator;
 
1840
        $ENV{$_} = $aux_dir.$search_path_separator;
1730
1841
    }
1731
1842
}
1732
1843
 
1793
1904
    # Make hash of excluded files, for easy checking:
1794
1905
    my %excl = ();
1795
1906
    foreach my $file (@excluded_file_list) {
1796
 
        $excl{$file} = '';
 
1907
        $excl{$file} = '';
1797
1908
    }
1798
1909
    foreach my $file (@file_list1) {
1799
 
        push( @file_list, $file)  unless ( exists $excl{$file} );
 
1910
        push( @file_list, $file)  unless ( exists $excl{$file} );
1800
1911
    }    
1801
1912
    if ( !@file_list ) {
1802
 
        &exit_help( "No file name specified, and I couldn't find any");
 
1913
        &exit_help( "No file name specified, and I couldn't find any");
1803
1914
    }
1804
1915
}
1805
1916
 
1882
1993
    add_option( "-recorder", \$latex, \$pdflatex );
1883
1994
}
1884
1995
 
 
1996
# If the output and/or aux directories are specified: Fix the (pdf)latex
 
1997
#   commands to use them, and ensure that the directories exist.
 
1998
# N.B. We are immune against cd'ing to directory of TeX file, because in
 
1999
#   that case we have forced the directories to be absolute.
 
2000
 
1885
2001
if ( $out_dir ) {
1886
2002
    add_option( "-output-directory=\"$out_dir\"", \$latex, \$pdflatex );
1887
2003
    if ( ! -e $out_dir ) {
1888
2004
        warn "$My_name: making output directory '$out_dir'\n"
1889
 
            if ! $silent;
 
2005
            if ! $silent;
1890
2006
        make_path $out_dir;
1891
2007
    }
1892
2008
    elsif ( ! -d $out_dir ) {
1903
2019
    add_option( "-aux-directory=\"$aux_dir\"", \$latex, \$pdflatex );
1904
2020
    if ( ! -e $aux_dir ) {
1905
2021
        warn "$My_name: making auxiliary directory '$aux_dir'\n"
1906
 
            if ! $silent;
 
2022
            if ! $silent;
1907
2023
        make_path $aux_dir;
1908
2024
    }
1909
2025
    elsif ( ! -d $aux_dir ) {
1914
2030
}
1915
2031
 
1916
2032
if ( $jobname ne '' ) { 
1917
 
    $jobstring = "--jobname=$jobname";
 
2033
    $jobstring = "--jobname=\"$jobname\"";
1918
2034
    add_option( "$jobstring", \$latex, \$pdflatex );
1919
2035
}
1920
2036
 
1966
2082
if ( $printout_mode ) {
1967
2083
    $one_time{'print'} = 1;
1968
2084
    if ($print_type eq 'none'){
1969
 
        warn "$My_name: You have requested printout, but \$print_type is set to 'none'\n";
 
2085
        warn "$My_name: You have requested printout, but \$print_type is set to 'none'\n";
1970
2086
    }
1971
2087
}
1972
2088
if ( $preview_continuous_mode || $preview_mode ) { $one_time{'view'} = 1; }
2011
2127
    # Ensure $aux_dir is in TEXINPUTS search path.
2012
2128
    # This is used by dvips for files generated by mpost.
2013
2129
    if ( ! exists $ENV{TEXINPUTS} ) {
2014
 
        # Note the trailing ":" which ensures that the last item
2015
 
        # in the list of paths is the empty path, which actually
2016
 
        # means the default path, i.e., the following means that
2017
 
        # the TEXINPUTS search path is $aux_dir and the standard
2018
 
        # value.
2019
 
        $ENV{TEXINPUTS} = $aux_dir.$search_path_separator;
 
2130
        # Note the trailing ":" which ensures that the last item
 
2131
        # in the list of paths is the empty path, which actually
 
2132
        # means the default path, i.e., the following means that
 
2133
        # the TEXINPUTS search path is $aux_dir and the standard
 
2134
        # value.
 
2135
        $ENV{TEXINPUTS} = $aux_dir.$search_path_separator;
2020
2136
    }
2021
2137
    elsif ( $ENV{TEXINPUTS} !~ /$aux_dir$search_path_separator/ ) {
2022
 
        $ENV{TEXINPUTS} = $aux_dir.$search_path_separator.$ENV{TEXINPUTS};
 
2138
        $ENV{TEXINPUTS} = $aux_dir.$search_path_separator.$ENV{TEXINPUTS};
2023
2139
    }
2024
2140
}
2025
2141
 
2068
2184
       pushd( $path );
2069
2185
    }
2070
2186
    else {
2071
 
        $path = '';
 
2187
        $path = '';
2072
2188
    }
2073
2189
 
2074
2190
 
2075
2191
    ## remove extension from filename if was given.
2076
2192
    if ( &find_basename($filename, $root_filename, $texfile_name) )
2077
2193
    {
2078
 
        if ( $force_mode ) {
2079
 
           warn "$My_name: Could not find file [$texfile_name]\n";
2080
 
        }
2081
 
        else {
 
2194
        if ( $force_mode ) {
 
2195
           warn "$My_name: Could not find file [$texfile_name]\n";
 
2196
        }
 
2197
        else {
2082
2198
            &ifcd_popd;
2083
 
            &exit_msg1( "Could not find file [$texfile_name]",
2084
 
                        11);
2085
 
        }
 
2199
            &exit_msg1( "Could not find file [$texfile_name]",
 
2200
                        11);
 
2201
        }
2086
2202
    }
2087
2203
    if ($jobname ne '' ) {
2088
2204
        $root_filename = $jobname;
2121
2237
                    $base = $path.$base;
2122
2238
                    if ( $rule =~ /^makeindex/ ) {
2123
2239
                        push @index_bibtex_generated, $$Psource, $$Pdest, "$base.ilg";
2124
 
                    }
 
2240
                    }
2125
2241
                    elsif ( $rule =~ /^(bibtex|biber)/ ) {
2126
2242
                        push @index_bibtex_generated, $$Pdest, "$base.blg";
2127
2243
                        push @aux_files, $$Psource;
2128
 
                    }
 
2244
                    }
2129
2245
                    elsif ( exists $other_generated{$$Psource} ) {
2130
2246
                        $other_generated{$$Pdest};
2131
2247
                    }
2141
2257
              if $diagnostics;
2142
2258
            # Variables set by parse_log. Can I remove them?
2143
2259
            local %generated_log = ();
2144
 
            local %dependents = ();    # Maps files to status.  Not used here.
2145
 
            local @bbl_files = ();     # Not used here.
2146
 
            local %idx_files = ();     # Maps idx_file to (ind_file, base). Not used here.
2147
 
            local %conversions = ();   # (pdf)latex-performed conversions.  Not used here.
2148
 
                         # Maps output file created and read by (pdf)latex
2149
 
                         #    to source file of conversion.
2150
 
            local $primary_out = '';   # Actual output file (dvi or pdf). Not used here.
 
2260
            local %dependents = ();    # Maps files to status.  Not used here.
 
2261
            local @bbl_files = ();     # Not used here.
 
2262
            local %idx_files = ();     # Maps idx_file to (ind_file, base). Not used here.
 
2263
            local %conversions = ();   # (pdf)latex-performed conversions.  Not used here.
 
2264
                         # Maps output file created and read by (pdf)latex
 
2265
                         #    to source file of conversion.
 
2266
            local $primary_out = '';   # Actual output file (dvi or pdf). Not used here.
2151
2267
            &parse_log;
2152
2268
            %other_generated = %generated_log;
2153
 
        }
 
2269
        }
2154
2270
        else {
2155
2271
            print "$My_name: No fdb or log file, so clean up default set of files ...\n"
2156
2272
              if $diagnostics;
2157
 
        }
 
2273
        }
2158
2274
 
2159
2275
        if ( ($go_mode == 2) && !$silent ) {
2160
2276
            warn "$My_name: Removing all generated files\n" unless $silent;
2161
 
        }
 
2277
        }
2162
2278
        if ($bibtex_use < 2) { 
2163
2279
           delete $generated_exts_all{'bbl'}; 
2164
2280
        }
2166
2282
        my %index_bibtex_generated = ();
2167
2283
        my %aux_files = ();
2168
2284
        foreach (@index_bibtex_generated) {
2169
 
            $index_bibtex_generated{$_} = 1
 
2285
            $index_bibtex_generated{$_} = 1
2170
2286
               unless ( /\.bbl$/ && ($bibtex_use < 2) );
2171
2287
            delete( $other_generated{$_} );
2172
 
        }
 
2288
        }
2173
2289
        foreach (@aux_files) {
2174
2290
            $aux_files{$_} = 1;
2175
2291
            delete( $other_generated{$_} );
2176
 
        }
 
2292
        }
2177
2293
        if ($diagnostics) {
2178
2294
            show_array( "For deletion, the following were determined from fdb file or log file:\n"
2179
2295
                       ." Generated (from makeindex and bibtex):", 
2182
2298
            show_array( " Other generated files:\n"
2183
2299
                       ." (only deleted if \$cleanup_includes_generated is set): ",
2184
2300
                        keys %other_generated );
2185
 
        }
 
2301
            show_array( " Yet other generated files:\n",
 
2302
                        keys %generated_exts_all );
 
2303
        }
2186
2304
        &cleanup1( $aux_dir1, $fdb_ext, 'blg', 'ilg', 'log', 'aux.bak', 'idx.bak',
2187
2305
                   split('\s+',$clean_ext),
2188
2306
                   keys %generated_exts_all 
2190
2308
        unlink_or_move( 'texput.log', "texput.aux", 
2191
2309
                keys %index_bibtex_generated, 
2192
2310
                keys %aux_files );
 
2311
        if ( $dependents_list && ( $deps_file ne '-' ) ) {
 
2312
            unlink_or_move( $deps_file );
 
2313
        }
2193
2314
        if ($cleanup_includes_generated) {
2194
 
            unlink_or_move( keys %other_generated );
2195
 
        }
 
2315
            unlink_or_move( keys %other_generated );
 
2316
        }
2196
2317
        if ( $cleanup_includes_cusdep_generated) {
2197
 
            &cleanup_cusdep_generated;
2198
 
        }
 
2318
            &cleanup_cusdep_generated;
 
2319
        }
2199
2320
        if ( $cleanup_mode == 1 ) { 
2200
2321
            &cleanup1( $out_dir1, 'dvi', 'dviF', 'ps', 'psF', 'pdf',
2201
2322
                       split('\s+', $clean_full_ext)
2255
2376
        # previous run.  So use filetime criterion for make
2256
2377
        # instead of change from previous run, until we have
2257
2378
        # done our own make.
2258
 
        rdb_recurse( [keys %possible_primaries],
2259
 
                      sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} }
 
2379
        rdb_recurse( [keys %possible_primaries],
 
2380
                      sub{ if ( $$Ptest_kind == 1 ) { $$Ptest_kind = 3;} }
2260
2381
        );
2261
2382
        if ( -e $log_name ) {
2262
 
            rdb_for_some( [keys %possible_primaries], \&rdb_set_latex_deps );
2263
 
        }
 
2383
            rdb_for_some( [keys %possible_primaries], \&rdb_set_latex_deps );
 
2384
        }
2264
2385
    }
2265
2386
    foreach $rule ( rdb_accessible( uniq1( keys %requested_filerules  )  ) ){
2266
2387
        # For all source files of all accessible rules, 
2268
2389
        #    file, set them from disk.
2269
2390
        rdb_one_rule ($rule, undef, 
2270
2391
                      sub{ if ( $$Ptime == 0) { &rdb_update1; } }
2271
 
        );
 
2392
        );
2272
2393
    }
2273
2394
 
2274
2395
    if ($go_mode) {
2275
2396
        # Force everything to be remade.
2276
 
        rdb_recurse( [keys %requested_filerules], sub{$$Pout_of_date=1;}  );
 
2397
        rdb_recurse( [keys %requested_filerules], sub{$$Pout_of_date=1;}  );
2277
2398
    }
2278
2399
 
2279
2400
 
2444
2565
    my $print_file = '';
2445
2566
    my $print_cmd = 'NONE';
2446
2567
    if ( $print_type eq 'dvi' ) {
2447
 
        $print_file = $dvi_final;
2448
 
        $print_cmd = $lpr_dvi;
 
2568
        $print_file = $dvi_final;
 
2569
        $print_cmd = $lpr_dvi;
2449
2570
    }
2450
2571
    elsif ( $print_type eq 'pdf' ) {
2451
 
        $print_file = $pdf_final;
2452
 
        $print_cmd = $lpr_pdf;
 
2572
        $print_file = $pdf_final;
 
2573
        $print_cmd = $lpr_pdf;
2453
2574
    }
2454
2575
    elsif ( $print_type eq 'ps' ) {
2455
 
        $print_file = $ps_final;
2456
 
        $print_cmd = $lpr;
 
2576
        $print_file = $ps_final;
 
2577
        $print_cmd = $lpr;
2457
2578
    }
2458
2579
    elsif ( $print_type eq 'none' ) {
2459
2580
        $print_cmd = 'NONE echo NO PRINTING CONFIGURED';
2511
2632
    %rule_db = ();
2512
2633
 
2513
2634
    foreach my $Prule_list (@_) {
2514
 
        foreach my $rule ( keys %$Prule_list) {
2515
 
            my ( $cmd_type, $ext_cmd, $int_cmd, $source, $dest, $base, $test_kind, $PA_extra_gen ) = @{$$Prule_list{$rule}};
 
2635
        foreach my $rule ( keys %$Prule_list) {
 
2636
            my ( $cmd_type, $ext_cmd, $int_cmd, $source, $dest, $base, $test_kind, $PA_extra_gen ) = @{$$Prule_list{$rule}};
2516
2637
            if ( ! $PA_extra_gen ) { $PA_extra_gen = []; }
2517
 
            my $needs_making = 0;
2518
 
            # Substitute in the filename variables, since we will use
2519
 
            # those for determining filenames.  But delay expanding $cmd 
2520
 
            # until run time, in case of changes.
2521
 
            foreach ($base, $source, $dest, @$PA_extra_gen ) {
2522
 
                s/%R/$root_filename/;
2523
 
                s/%Y/$aux_dir1/;
2524
 
                s/%Z/$out_dir1/;
2525
 
            }
2526
 
            foreach ($source, $dest ) { 
2527
 
                s/%B/$base/;
2528
 
                s/%T/$texfile_name/;
2529
 
            }
 
2638
            my $needs_making = 0;
 
2639
            # Substitute in the filename variables, since we will use
 
2640
            # those for determining filenames.  But delay expanding $cmd 
 
2641
            # until run time, in case of changes.
 
2642
            foreach ($base, $source, $dest, @$PA_extra_gen ) {
 
2643
                s/%R/$root_filename/;
 
2644
                s/%Y/$aux_dir1/;
 
2645
                s/%Z/$out_dir1/;
 
2646
            }
 
2647
            foreach ($source, $dest ) { 
 
2648
                s/%B/$base/;
 
2649
                s/%T/$texfile_name/;
 
2650
            }
2530
2651
    #        print "$rule: $cmd_type, EC='$ext_cmd', IC='$int_cmd', $test_kind,\n",
2531
2652
    #              "    S='$source', D='$dest', B='$base' $needs_making\n";
2532
 
            rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, $test_kind, 
2533
 
                             $source, $dest, $base,
2534
 
                             $needs_making, undef, undef, 1, $PA_extra_gen );
 
2653
            rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, $test_kind, 
 
2654
                             $source, $dest, $base,
 
2655
                             $needs_making, undef, undef, 1, $PA_extra_gen );
2535
2656
# !! ?? Last line was
2536
 
#                            $needs_making, undef, ($test_kind==1) );
2537
 
        }
 
2657
#                            $needs_making, undef, ($test_kind==1) );
 
2658
        }
2538
2659
    } # End arguments of subroutine
2539
2660
    &rdb_make_links;
2540
2661
} # END rdb_set_rules
2559
2680
               ) 
2560
2681
            { $$Pfrom_rule = $from_rules{$file}; 
2561
2682
            }
2562
 
        }
 
2683
        }
2563
2684
    );
2564
2685
    rdb_for_all( 
2565
2686
        0,
2569
2690
            }
2570
2691
            if ( $$Pfrom_rule && (! rdb_rule_exists( $$Pfrom_rule ) ) ) {
2571
2692
                $$Pfrom_rule = '';
2572
 
            }
 
2693
            }
2573
2694
#??            print "$rule: $file, $$Pfrom_rule\n";
2574
 
        }
 
2695
        }
2575
2696
    );
2576
2697
} # END rdb_make_links
2577
2698
 
2616
2737
    if ( !-e $$Psource ) {
2617
2738
        # Source does not exist.  Users of this rule will need to turn
2618
2739
        # it off when custom dependencies are reset
2619
 
        if ( !$silent ) {
 
2740
        if ( !$silent ) {
2620
2741
## ??? Was commented out.  1 Sep. 2008 restored, for cusdep no-file-exists issue
2621
2742
            warn "$My_name: In trying to apply custom-dependency rule\n",
2622
2743
            "  to make '$$Pdest' from '$$Psource'\n",
2623
2744
            "  the source file has disappeared since the last run\n";
2624
 
        }
 
2745
        }
2625
2746
        # Treat as successful
2626
2747
    }
2627
2748
    elsif ( !$func_name ) {
2637
2758
        "  function name '$func_name' does not exists.\n";
2638
2759
    }
2639
2760
    else {
2640
 
        my $cusdep_ret = &$func_name( $$Pbase );
 
2761
        my $cusdep_ret = &$func_name( $$Pbase );
2641
2762
        if ( defined $cusdep_ret && ($cusdep_ret != 0) ) {
2642
 
            $return = $cusdep_ret;
2643
 
            if ($return) {
 
2763
            $return = $cusdep_ret;
 
2764
            if ($return) {
2644
2765
                warn "Rule '$rule', function '$func_name'\n",
2645
2766
                     "   failed with return code = $return\n";
2646
 
            }
2647
 
        }
 
2767
            }
 
2768
        }
2648
2769
        elsif ( !-e $$Pdest ) {
2649
2770
            # Destination non-existent, but routine failed to give an error
2650
2771
            warn "$My_name: In running custom-dependency rule\n",
2651
2772
            "  to make '$$Pdest' from '$$Psource'\n",
2652
2773
            "  function '$func_name' did not make the destination.\n";
2653
 
            $return = -1;
2654
 
        }
 
2774
            $return = -1;
 
2775
        }
2655
2776
    }
2656
2777
    return $return;
2657
2778
}  # END do_cusdep
2674
2795
        else {
2675
2796
            warn "$My_name is configured to make '$$Pdest' via a temporary file\n",
2676
2797
                 "    but the command template '$$Pext_cmd' does not have a slot\n",
2677
 
            "    to set the destination file, so I won't use a temporary file\n";
 
2798
            "    to set the destination file, so I won't use a temporary file\n";
2678
2799
            $return = &Run_subst();
2679
 
        }
 
2800
        }
2680
2801
    }
2681
2802
    else {
2682
2803
        $return = &Run_subst();
2702
2823
    my $Pneed_to_get_viewer_process = \${$PAint_cmd}[4];
2703
2824
    
2704
2825
    if ($viewer_update_method == 2) {
2705
 
        if ($$Pneed_to_get_viewer_process) {
 
2826
        if ($$Pneed_to_get_viewer_process) {
2706
2827
            $$Pviewer_process = &find_process_id( $$Psource );
2707
2828
            if ($$Pviewer_process != 0) {
2708
2829
                $$Pneed_to_get_viewer_process = 0;
2709
 
            }
2710
 
        }
 
2830
            }
 
2831
        }
2711
2832
        if ($$Pviewer_process == 0) {
2712
2833
            print "$My_name: need to signal viewer for file '$$Psource', but didn't get \n",
2713
2834
                  "   process ID for some reason, e.g., no viewer, bad configuration, bug\n"
2716
2837
        elsif ( defined $viewer_update_signal) {
2717
2838
            print "$My_name: signalling viewer, process ID $$Pviewer_process\n"
2718
2839
                if $diagnostics ;
2719
 
            kill $viewer_update_signal, $$Pviewer_process;
2720
 
        }
 
2840
            kill $viewer_update_signal, $$Pviewer_process;
 
2841
        }
2721
2842
        else {
2722
2843
            warn "$My_name: viewer is supposed to be sent a signal\n",
2723
2844
                 "  but no signal is defined.  Misconfiguration or bug?\n";
2727
2848
    elsif ($viewer_update_method == 4) {
2728
2849
        if (defined $$Pext_cmd) {
2729
2850
            $return = &Run_subst();
2730
 
        }
 
2851
        }
2731
2852
        else {
2732
2853
            warn "$My_name: viewer is supposed to be updated by running a command,\n",
2733
2854
                 "  but no command is defined.  Misconfiguration or bug?\n";
2746
2867
    }
2747
2868
    else {
2748
2869
        warn "Needed source file '$$Psource' does not exist.\n";
2749
 
        return -1;
 
2870
        return -1;
2750
2871
    }
2751
2872
} #END if_source
2752
2873
 
2909
3030
            $SIG{BREAK} = $SIG{INT} = 'IGNORE';
2910
3031
        }
2911
3032
        if ($compiling_cmd) {
2912
 
            Run_subst( $compiling_cmd );
 
3033
            Run_subst( $compiling_cmd );
2913
3034
        }
2914
3035
        $failure = rdb_make( @targets );
2915
3036
 
2921
3042
        # Start viewer if needed.
2922
3043
        if ( ($failure > 0) && (! $force_mode) ) {
2923
3044
            # No viewer yet
2924
 
        }
 
3045
        }
2925
3046
        elsif ( ($view_file ne '') && (-e $view_file) && $updated && $viewer_running ) {
2926
3047
            # A viewer is running.  Explicitly get it to update screen if we have to do it:
2927
3048
            rdb_one_rule( 'update_view', \&rdb_run1 );
2928
3049
        }
2929
3050
        elsif ( ($view_file ne '') && (-e $view_file) && !$viewer_running ) {
2930
3051
            # Start the viewer
2931
 
            if ( !$silent ) {
 
3052
            if ( !$silent ) {
2932
3053
                if ($new_viewer_always) {
2933
3054
                    warn "$My_name: starting previewer for '$view_file'\n",
2934
3055
                         "------------\n";
2935
 
                }
 
3056
                }
2936
3057
                else {
2937
3058
                    warn "$My_name: I have not found a previewer that ",
2938
3059
                         "is already running. \n",
2939
3060
                         "   So I will start it for '$view_file'\n",
2940
3061
                         "------------\n";
2941
 
               }
2942
 
            }
 
3062
               }
 
3063
            }
2943
3064
            local $retcode = 0;
2944
3065
            rdb_one_rule( 'view', sub { $retcode = &rdb_run1;} );
2945
3066
            if ( $retcode != 0 ) {
2953
3074
            else {
2954
3075
                $viewer_running = 1;
2955
3076
                $$Pneed_to_get_viewer_process = 1;
2956
 
            } # end analyze result of trying to run viewer
 
3077
            } # end analyze result of trying to run viewer
2957
3078
        } # end start viewer
2958
3079
        if ( $failure > 0 ) {
2959
3080
            if ( !$failure_msg ) {
2960
 
                $failure_msg = 'Failure to make the files correctly';
 
3081
                $failure_msg = 'Failure to make the files correctly';
2961
3082
            }
2962
3083
            @pre_primary = ();   # Array of rules
2963
3084
            @post_primary = ();  # Array of rules
2979
3100
            warn "$My_name: $failure_msg\n",
2980
3101
    "    ==> You will need to change a source file before I do another run <==\n";
2981
3102
            if ($failure_cmd) {
2982
 
                Run_subst( $failure_cmd );
 
3103
                Run_subst( $failure_cmd );
2983
3104
            }
2984
 
        }
 
3105
        }
2985
3106
        else {
2986
3107
            if ($success_cmd) {
2987
 
                Run_subst( $success_cmd );
 
3108
                Run_subst( $success_cmd );
2988
3109
            }
2989
3110
        }
2990
3111
        rdb_show_rule_errors();
2998
3119
           }
2999
3120
           else {
3000
3121
               warn "Cannot open '$deps_file' for output of dependency information\n";
3001
 
           }
3002
 
         }
 
3122
           }
 
3123
         }
3003
3124
        if ( $first_time || $updated || $failure ) {
3004
3125
            print "\n=== Watching for updated files. Use ctrl/C to stop ...\n";
3005
3126
        }
3012
3133
        $have_break = 0;
3013
3134
  WAIT: while (1) {
3014
3135
           sleep( $sleep_time );
3015
 
           if ($have_break) { last WAIT; }
 
3136
           if ($have_break) { last WAIT; }
3016
3137
           if ( rdb_new_changes(keys %rules_to_watch) ) { 
3017
 
               if (!$silent) {
 
3138
               if (!$silent) {
3018
3139
                   warn "$My_name: Need to remake files.\n";
3019
 
                   &rdb_diagnose_changes( '  ' );
3020
 
               }
 
3140
                   &rdb_diagnose_changes( '  ' );
 
3141
               }
3021
3142
               last WAIT;
3022
 
           }
 
3143
           }
3023
3144
           #  Don't count waiting time in processing:
3024
3145
           $processing_time1 = processing_time();
3025
3146
        # Does this do this job????
3026
3147
           local $new_files = 0;
3027
3148
           rdb_for_some( [keys %current_primaries], sub{ $new_files += &rdb_find_new_files } );
3028
3149
           if ($new_files > 0) {
3029
 
               warn "$My_name: New file(s) found.\n";
 
3150
               warn "$My_name: New file(s) found.\n";
3030
3151
               last WAIT; 
3031
 
           }
3032
 
           if ($have_break) { last WAIT; }
 
3152
           }
 
3153
           if ($have_break) { last WAIT; }
3033
3154
     } # end WAIT:
3034
3155
     &default_break;
3035
3156
     if ($have_break) { 
3079
3200
    # PREVIOUS VERSION
3080
3201
#    if ( ! -r $rc_file ) {
3081
3202
#        warn "$My_name: I cannot read the rc-file '$rc_file'\n",
3082
 
#            "          or at least that's what Perl (for $^O) reports\n";
 
3203
#            "          or at least that's what Perl (for $^O) reports\n";
3083
3204
#        return 1;
3084
3205
#    }
3085
3206
#    do( $rc_file );
3129
3250
sub cleanup1 {
3130
3251
    # Usage: cleanup1( directory, exts_without_period, ... )
3131
3252
    #
3132
 
    # The directory is a fixed name, so I must escape any glob metacharacters
3133
 
    #   in it:
 
3253
    # The directory and the root file name are fixed names, so I must escape
 
3254
    #   any glob metacharacters in them:
3134
3255
    my $dir = fix_pattern( shift );
 
3256
    my $root_fixed = fix_pattern( $root_filename );
3135
3257
    foreach (@_) { 
3136
 
        (my $name = /%R/ ? $_ : "%R.$_") =~ s/%R/$dir$root_filename/;
 
3258
        (my $name = /%R/ ? $_ : "%R.$_") =~ s/%R/$dir$root_fixed/;
3137
3259
        unlink_or_move( glob( "$name" ) );
3138
3260
    }
3139
3261
} #END cleanup1
3296
3418
  "   -latex=<program> - set program used for latex.\n",
3297
3419
  "                      (replace '<program>' by the program name)\n",
3298
3420
  "   -latexoption=<option> - add the given option to the (pdf)latex command\n",
 
3421
  "   -logfilewarninglist or -logfilewarnings \n",
 
3422
  "               give list of warnings after run of (pdf)latex\n",
 
3423
  "   -logfilewarninglist- or -logfilewarnings- \n",
 
3424
  "               do not give list of warnings after run of (pdf)latex\n",
3299
3425
  "   -M     - Show list of dependent files after processing\n",
3300
3426
  "   -MF file - Specifies name of file to receives list dependent files\n",
3301
3427
  "   -MP    - List of dependent files includes phony target for each source file.\n",
3364
3490
  " \n",
3365
3491
  "In addition, latexmk recognizes many other options that are passed to\n",
3366
3492
  "latex and/or pdflatex without interpretation by latexmk.  Run latexmk\n",
3367
 
  "with the option -showextraoptions to see a list of these\n";
 
3493
  "with the option -showextraoptions to see a list of these\n",
 
3494
  "\n",
 
3495
  "Report bugs etc to John Collins <jcc8 at psu.edu>.\n";
3368
3496
 
3369
3497
} #END print_help
3370
3498
 
3466
3594
                $error_count ++;
3467
3595
                if ( /> (FATAL|ERROR) - The file '[^']+' does not contain any citations!/ ) { #'
3468
3596
                    $no_citations++;
3469
 
                }
 
3597
                }
3470
3598
            }
3471
3599
        }
3472
3600
        elsif ( /> INFO - Found .* '([^']+)'\s*$/
3475
3603
                || /> INFO - Reading (.*)$/
3476
3604
                || /> INFO - Processing .* file '([^']+)' .*$/
3477
3605
              ) {
3478
 
            if ( defined $Pbiber_source ) {
 
3606
            if ( defined $Pbiber_source ) {
3479
3607
                push @$Pbiber_source, $1;
3480
 
            }
 
3608
            }
3481
3609
        }
3482
3610
        elsif ( /> INFO - WARNINGS: ([\d]+)\s*$/ ) {
3483
3611
            $bibers_warning_count = $1;
3484
 
        }
 
3612
        }
3485
3613
        elsif ( /> INFO - ERRORS: ([\d]+)\s*$/ ) {
3486
3614
            $bibers_error_count = $1;
3487
 
        }
 
3615
        }
3488
3616
    }
3489
3617
    close $log_file;
3490
3618
 
3499
3627
        # Special treatment if sole missing file is bib file
3500
3628
        # I don't want to treat that as an error
3501
3629
        warn "$My_name: Biber did't find bib file [$not_found[0]]\n";
3502
 
        return 5;
 
3630
        return 5;
3503
3631
    }
3504
3632
    else {
3505
3633
        show_array( "$My_name: Failed to find one or more biber source files:",
3510
3638
        }
3511
3639
        if ($control_file_missing) {
3512
3640
            return 6;
3513
 
        }
 
3641
        }
3514
3642
        return 4;
3515
3643
    }
3516
3644
#    print "$My_name: #Biber errors = $error_count, warning messages = $warning_count,\n  ",
3539
3667
            my ( $base, $path, $ext ) = fileparseA( $$Psource );
3540
3668
            my $cwd = good_cwd();
3541
3669
            foreach ( 'BIBINPUTS', 'BSTINPUTS' ) {
3542
 
                if ( exists $ENV{$_} ) {
3543
 
                    $ENV{$_} = $cwd.$search_path_separator.$ENV{$_};
3544
 
                }
3545
 
                else {
3546
 
                    $ENV{$_} = $cwd.$search_path_separator;
3547
 
                }
3548
 
            }
 
3670
                if ( exists $ENV{$_} ) {
 
3671
                    $ENV{$_} = $cwd.$search_path_separator.$ENV{$_};
 
3672
                }
 
3673
                else {
 
3674
                    $ENV{$_} = $cwd.$search_path_separator;
 
3675
                }
 
3676
            }
3549
3677
            pushd( $path );
3550
3678
            $return = &Run_subst( undef, undef, '', $base.$ext, '', $base );
3551
3679
            popd();
3554
3682
            warn "$My_name: Directory in file name '$$Psource' for bibtex\n",
3555
3683
                 "   but it is not the output directory '$aux_dir'\n";
3556
3684
            $return = Run_subst();
3557
 
        }
 
3685
        }
3558
3686
    }
3559
3687
    else {
3560
3688
        $return = Run_subst();
3591
3719
        }
3592
3720
        elsif ( /^I couldn\'t open auxiliary file (.*\.aux)/ ) {
3593
3721
            push @missing_aux, $1;
3594
 
        }
 
3722
        }
3595
3723
        elsif ( /^I found no \\citation commands---while reading file/ ) {
3596
3724
            $missing_citations++;
3597
 
        }
 
3725
        }
3598
3726
        elsif (/There (were|was) (\d+) error message/) {
3599
3727
            $error_count = $2;
3600
3728
            #print "Bibtex error: count=$error_count $_"; 
3695
3823
    my %cusdep_to = ();
3696
3824
    foreach ( @cus_dep_list ) {
3697
3825
        my ($fromext, $toext) = split;
3698
 
        $cusdep_from{$fromext} = $cusdep_from{".$fromext"} = $_;
3699
 
        $cusdep_to{$toext} = $cusdep_to{".$toext"} = $_;
 
3826
        $cusdep_from{$fromext} = $cusdep_from{".$fromext"} = $_;
 
3827
        $cusdep_to{$toext} = $cusdep_to{".$toext"} = $_;
3700
3828
    }
3701
3829
#    print "==== Cusdep from-exts:"; foreach (keys %cusdep_from) {print " '$_'";} print "\n";
3702
3830
#    print "==== Cusdep to-exts:"; foreach (keys %cusdep_to) {print " '$_'";} print "\n";
3715
3843
    # a sensible default in case of misparsing
3716
3844
 
3717
3845
    $reference_changed = 0;
 
3846
    $mult_defined = 0;
3718
3847
    $bad_reference = 0;
3719
3848
    $bad_citation = 0;
3720
3849
 
3766
3895
                                 #    data structure until block is ended.)
3767
3896
    my %new_conversions = ();
3768
3897
    my @retries = ();
 
3898
    my $log_silent = ($silent ||  $silence_logfile_warnings);
 
3899
    my @warning_list = ();
3769
3900
LINE:
3770
3901
    while( ($line <= $#lines) || ($#retries > -1) ) { 
3771
3902
        if ($#retries > -1) {
3772
 
            $_ = pop @retries;
3773
 
        }
3774
 
        else {
 
3903
            $_ = pop @retries;
 
3904
        }
 
3905
        else {
3775
3906
            $_ = $lines[$line];
3776
3907
            $line ++;
3777
 
        }
 
3908
        }
3778
3909
        if ( /^! pdfTeX warning/ || /^pdfTeX warning/ ) {
3779
3910
            # This kind of warning is produced by some versions of pdftex
3780
3911
            # or produced by my reparse of warnings from other
3781
3912
            # versions.
3782
3913
            next;
3783
 
        }
 
3914
        }
3784
3915
        elsif ( /^(.+)(pdfTeX warning.*)$/ ) {
3785
3916
            # Line contains a pdfTeX warnings that may have been
3786
3917
            # inserted directly after other material without an
3787
3918
            # intervening new line.  I think pdfTeX always inserts a
3788
3919
            # newline after the warning.  (From examination of source
3789
3920
            # code.) 
3790
 
            push @retries, $1;
 
3921
            push @retries, $1;
3791
3922
            # But continue parsing the original line, in case it was a
3792
3923
            # misparse, e.g., of a filename ending in 'pdfTeX';
3793
 
        }
 
3924
        }
3794
3925
        if ( $line == 1 ){
3795
 
            if ( /^This is / ) {
3796
 
                # First line OK
 
3926
            if ( /^This is / ) {
 
3927
                # First line OK
3797
3928
                next LINE;
3798
3929
            } else {
3799
3930
                warn "$My_name: Error on first line of '$log_name'.\n".
3800
3931
                    "This is apparently not a TeX log file.  ",
3801
 
                    "The first line is:\n$_\n";
 
3932
                    "The first line is:\n$_\n";
3802
3933
                $failure = 1;
3803
3934
                $failure_msg = "Log file '$log_name' appears to have wrong format.";
3804
3935
                return 0;
3805
 
            }
3806
 
        }
 
3936
            }
 
3937
        }
3807
3938
        if ( $block_type ) {
3808
3939
            # In middle of parsing block
3809
3940
            if ( /^\($current_pkg\)/ ) {
3811
3942
                if ( ($block_type eq 'conversion') 
3812
3943
                     && /^\($current_pkg\)\s+Output file: <([^>]+)>/ ) 
3813
3944
                {
3814
 
                    $delegated_output = normalize_clean_filename($1);
 
3945
                    $delegated_output = normalize_clean_filename($1);
3815
3946
                }
3816
 
                next LINE;
3817
 
            }
 
3947
                next LINE;
 
3948
            }
3818
3949
            # Block has ended.
3819
3950
            if ($block_type eq 'conversion') {
 
3951
print "=== $delegated_source -> $delegated_output\n";
3820
3952
                 $new_conversions{$delegated_source} =  $delegated_output;
3821
 
            }
 
3953
            }
3822
3954
            $current_pkg = $block_type 
3823
3955
                 = $delegated_source = $delegated_output = "";
3824
3956
            # Then process current line
3825
 
        }
 
3957
        }
 
3958
 
3826
3959
        # Check for changed references, bad references and bad citations:
3827
3960
        if (/Rerun to get/) { 
3828
 
            warn "$My_name: References changed.\n" if ! $silent;
 
3961
            warn "$My_name: References changed.\n" if ! $log_silent;
3829
3962
            $reference_changed = 1;
3830
3963
        } 
3831
 
        if (/LaTeX Warning: (Reference[^\001]*undefined)./) { 
3832
 
            warn "$My_name: $1 \n" unless $silent;
3833
 
            $bad_reference++;
3834
 
        } 
3835
 
        if (/LaTeX Warning: (Citation[^\001]*undefined)./) {
3836
 
            warn "$My_name: $1 \n" unless $silent;
3837
 
            $bad_citation++;
3838
 
        }
3839
 
        if (/Package natbib Warning: (Citation[^\001]*undefined)./) {
3840
 
            warn "$My_name: $1 \n" unless $silent;
3841
 
            $bad_citation++;
3842
 
        }
3843
 
        if ( /^Document Class: / ) {
3844
 
            # Class sign-on line
3845
 
            next LINE;
3846
 
        }
3847
 
        if ( /^\(Font\)/ ) {
3848
 
            # Font info line
3849
 
            next LINE;
3850
 
        }
3851
 
        if (/^No pages of output\./) {
 
3964
        if (/^LaTeX Warning: (Reference[^\001]*undefined on input line .*)\./) {
 
3965
            push @warning_list, $1;
 
3966
            $bad_reference++;
 
3967
        } 
 
3968
        elsif (/^LaTeX Warning: (Label [^\001]* multiply defined.*)\./) {
 
3969
            push @warning_list, $1;
 
3970
            $mult_defined++;
 
3971
        }
 
3972
        elsif (/^LaTeX Warning: (Citation[^\001]*undefined on input line .*)\./) {
 
3973
            push @warning_list, $1;
 
3974
            $bad_citation++;
 
3975
        }
 
3976
        elsif (/^Package natbib Warning: (Citation[^\001]*undefined on input line .*)\./) {
 
3977
            push @warning_list, $1;
 
3978
            $bad_citation++;
 
3979
        }
 
3980
        elsif ( /^Document Class: / ) {
 
3981
            # Class sign-on line
 
3982
            next LINE;
 
3983
        }
 
3984
        elsif ( /^\(Font\)/ ) {
 
3985
            # Font info line
 
3986
            next LINE;
 
3987
        }
 
3988
        elsif (/^No pages of output\./) {
3852
3989
            $primary_out = ''; 
3853
 
            warn "$My_name: Log file says no output from latex\n";
3854
 
            next LINE;
3855
 
        }
3856
 
        if ( /^Output written on\s+(.*)\s+\(\d+\s+page/ ) {
 
3990
            warn "$My_name: Log file says no output from latex\n";
 
3991
            next LINE;
 
3992
        }
 
3993
        elsif ( /^Output written on\s+(.*)\s+\(\d+\s+page/ ) {
3857
3994
            $primary_out = normalize_clean_filename($1);
3858
 
            warn "$My_name: Log file says output to '$primary_out'\n"
3859
 
               unless $silent;
3860
 
            next LINE;
3861
 
        }
3862
 
        if ( /^Overfull / 
3863
 
             || /^Underfull / 
 
3995
            warn "$My_name: Log file says output to '$primary_out'\n"
 
3996
               unless $silent;
 
3997
            next LINE;
 
3998
        }
 
3999
        elsif ( /^Overfull / 
 
4000
             || /^Underfull / 
3864
4001
             || /^or enter new name\. \(Default extension: .*\)/ 
3865
4002
             || /^\*\*\* \(cannot \\read from terminal in nonstop modes\)/
3866
4003
           ) {
3867
 
            # Latex error/warning, etc.
3868
 
            next LINE;
3869
 
        }
3870
 
        if ( /^\\openout\d+\s*=\s*\`([^\']+)\'\.$/ ) {
 
4004
            # Latex error/warning, etc.
 
4005
            next LINE;
 
4006
        }
 
4007
        elsif ( /^\\openout\d+\s*=\s*\`([^\']+)\'\.$/ ) {
3871
4008
                #  When (pdf)latex is run with an -output-directory 
3872
4009
                #    or an -aux_directory, the file name does not contain
3873
4010
                #    the output path; fix this, after removing quotes:
3874
4011
            $generated_log{normalize_force_directory( $aux_dir1, $1 )} = 1;
3875
 
            next LINE;
3876
 
        }
 
4012
            next LINE;
 
4013
        }
3877
4014
        # Test for conversion produced by package:
3878
 
        if ( /^Package (\S+) Info: Source file: <([^>]+)>/ ) {
3879
 
            # Info. produced by epstopdf (and possibly others) 
 
4015
        elsif ( /^Package (\S+) Info: Source file: <([^>]+)>/ ) {
 
4016
            # Info. produced by epstopdf (and possibly others) 
3880
4017
            #    about file conversion
3881
4018
            $current_pkg = normalize_clean_filename($1);
3882
4019
            $delegated_source = normalize_clean_filename($2);
3883
4020
            $block_type = 'conversion';
3884
 
            next LINE;
3885
 
        }
 
4021
            next LINE;
 
4022
        }
3886
4023
#    Test for writing of index file.  The precise format of the message 
3887
4024
#    depends on which package (makeidx.sty , multind.sty or index.sty) and 
3888
4025
#    which version writes the message.
3889
 
        if ( /Writing index file (.*)$/ ) {
 
4026
        elsif ( /Writing index file (.*)$/ ) {
3890
4027
            my $idx_file = '';
3891
 
            if ( /^Writing index file (.*)$/ ) {
 
4028
            if ( /^Writing index file (.*)$/ ) {
3892
4029
                # From makeidx.sty or multind.sty
3893
4030
                $idx_file = $1;
3894
 
            }
 
4031
            }
3895
4032
            elsif ( /^index\.sty> Writing index file (.*)$/ ) {
3896
4033
                # From old versions of index.sty
3897
4034
                $idx_file = $1;
3898
 
            }
 
4035
            }
3899
4036
            elsif ( /^Package \S* Info: Writing index file (.*) on input line/ ) {
3900
4037
                # From new versions of index.sty
3901
4038
                $idx_file = $1;                
3902
 
            }
 
4039
            }
3903
4040
            else {
3904
 
                warn "$My_name: Message indicates index file was written\n",
3905
 
                     "  ==> but I do not know how to understand it: <==\n",
3906
 
                     "  '$_'\n";
 
4041
                warn "$My_name: Message indicates index file was written\n",
 
4042
                     "  ==> but I do not know how to understand it: <==\n",
 
4043
                     "  '$_'\n";
3907
4044
                next LINE;
3908
 
            }
3909
 
                # Typically, there is trailing space, not part of filename:
3910
 
            $idx_file =~ s/\s*$//;
 
4045
            }
 
4046
                # Typically, there is trailing space, not part of filename:
 
4047
            $idx_file =~ s/\s*$//;
3911
4048
                #  When (pdf)latex is run with an -output-directory 
3912
4049
                #    or an -aux_directory, the file name does not contain
3913
4050
                #    the output path; fix this, after removing quotes:
3914
 
            $idx_file = normalize_force_directory( $aux_dir1, $idx_file );
3915
 
            my ($idx_base, $idx_path, $idx_ext) = fileparseA( $idx_file );
3916
 
            $idx_base = $idx_path.$idx_base;
 
4051
            $idx_file = normalize_force_directory( $aux_dir1, $idx_file );
 
4052
            my ($idx_base, $idx_path, $idx_ext) = fileparseA( $idx_file );
 
4053
            $idx_base = $idx_path.$idx_base;
3917
4054
            $idx_file = $idx_base.$idx_ext;
3918
 
            if ( $idx_ext eq '.idx' ) {
3919
 
                warn "$My_name: Index file '$idx_file' was written\n"
3920
 
                  unless $silent;
3921
 
                $idx_files{$idx_file} = [ "$idx_base.ind", $idx_base ];
3922
 
            }
3923
 
            elsif ( exists $cusdep_from{$idx_ext} ) {
 
4055
            if ( $idx_ext eq '.idx' ) {
 
4056
                warn "$My_name: Index file '$idx_file' was written\n"
 
4057
                  unless $silent;
 
4058
                $idx_files{$idx_file} = [ "$idx_base.ind", $idx_base ];
 
4059
            }
 
4060
            elsif ( exists $cusdep_from{$idx_ext} ) {
3924
4061
                if ( !$silent ) {
3925
 
                    warn "$My_name: Index file '$idx_file' was written\n";
 
4062
                    warn "$My_name: Index file '$idx_file' was written\n";
3926
4063
                    warn "   Cusdep '$cusdep_from{$idx_ext}' should be used\n";
3927
4064
                }
3928
4065
                # No action needed here
3929
 
            }
3930
 
            else {
3931
 
                warn "$My_name: Index file '$idx_file' written\n",
3932
 
                     "  ==> but it has an extension I do not know how to handle <==\n";
3933
 
            }
 
4066
            }
 
4067
            else {
 
4068
                warn "$My_name: Index file '$idx_file' written\n",
 
4069
                     "  ==> but it has an extension I do not know how to handle <==\n";
 
4070
            }
3934
4071
 
3935
 
            next LINE;
3936
 
        }
3937
 
        if ( /^No file (.*?\.bbl)./ ) {
 
4072
            next LINE;
 
4073
        }
 
4074
        elsif ( /^No file (.*?\.bbl)./ ) {
3938
4075
                #  When (pdf)latex is run with an -output-directory 
3939
4076
                #    or an -aux_directory, the file name does not contain
3940
4077
                #    the output path; fix this, after removing quotes:
3941
 
            my $bbl_file = normalize_force_directory( $aux_dir1, $1 );
3942
 
            warn "$My_name: Non-existent bbl file '$bbl_file'\n $_\n";
3943
 
            $dependents{$bbl_file} = 0;
3944
 
            push @bbl_files, $bbl_file;
3945
 
            next LINE;
3946
 
        }
3947
 
        foreach my $pattern (@file_not_found) {
3948
 
            if ( /$pattern/ ) {
 
4078
            my $bbl_file = normalize_force_directory( $aux_dir1, $1 );
 
4079
            warn "$My_name: Non-existent bbl file '$bbl_file'\n $_\n";
 
4080
            $dependents{$bbl_file} = 0;
 
4081
            push @bbl_files, $bbl_file;
 
4082
            next LINE;
 
4083
        }
 
4084
        foreach my $pattern (@file_not_found) {
 
4085
            if ( /$pattern/ ) {
3949
4086
                my $file = clean_filename($1);
3950
 
                warn "$My_name: Missing input file: '$file' from line\n  '$_'\n"
3951
 
                    unless $silent;
3952
 
                $dependents{normalize_filename($file)} = 0;
3953
 
                my $file1 = $file;
 
4087
                warn "$My_name: Missing input file: '$file' from line\n  '$_'\n"
 
4088
                    unless $silent;
 
4089
                $dependents{normalize_filename($file)} = 0;
 
4090
                my $file1 = $file;
3954
4091
                if ( $aux_dir ) {
3955
4092
                      # Allow for the possibility that latex generated
3956
4093
                      # a file in $aux_dir, from which the missing file can
3960
4097
                      # file in $aux_dir, with a path.  So give this alternate
3961
4098
                      # location.
3962
4099
                      my $file1 = normalize_force_directory( $aux_dir1, $file );
3963
 
                      $dependents{$file1} = 0;
3964
 
                }
3965
 
                next LINE;
3966
 
            }
3967
 
        }
3968
 
        if ( /^File: (.+) Graphic file \(type / ) {
3969
 
            # First line of message from includegraphics/x
3970
 
            $dependents{normalize_clean_filename($1)} = 1;
3971
 
            next LINE;
3972
 
        }
3973
 
        # Now test for generic lines to ignore, only after special cases!
3974
 
        if ( /^File: / ) {
3975
 
           # Package sign-on line. Includegraphics/x also produces a line 
3976
 
           # with this signature, but I've already handled it.
3977
 
           next LINE;
3978
 
        }
3979
 
        if ( /^Package: / ) {
3980
 
            # Package sign-on line
3981
 
            next LINE;
3982
 
        }
3983
 
        if (/^\! LaTeX Error: / ) {
3984
 
            next LINE;
3985
 
        }
 
4100
                      $dependents{$file1} = 0;
 
4101
                }
 
4102
                next LINE;
 
4103
            }
 
4104
        }
 
4105
        if ( /^File: (.+) Graphic file \(type / ) {
 
4106
            # First line of message from includegraphics/x
 
4107
            $dependents{normalize_clean_filename($1)} = 1;
 
4108
            next LINE;
 
4109
        }
 
4110
        # Now test for generic lines to ignore, only after special cases!
 
4111
        if ( /^File: / ) {
 
4112
           # Package sign-on line. Includegraphics/x also produces a line 
 
4113
           # with this signature, but I've already handled it.
 
4114
           next LINE;
 
4115
        }
 
4116
        if ( /^Package: / ) {
 
4117
            # Package sign-on line
 
4118
            next LINE;
 
4119
        }
 
4120
        if (/^\! LaTeX Error: / ) {
 
4121
            next LINE;
 
4122
        }
3986
4123
        if ( m[^! I can't write on file `(.*)/([^/']*)'.\s*$] ) {
3987
 
            my $dir = $1;
 
4124
            my $dir = $1;
3988
4125
            my $file = $2;
3989
4126
            my $full_dir = $aux_dir1.$dir;
3990
4127
            if ( ($aux_dir ne '') && (! -e $full_dir) && ( $file =~ /\.aux$/) ) {
3992
4129
                     "    I'll try to make the subdirectory later.\n"
3993
4130
                  if $diagnostics;
3994
4131
                push @missing_subdirs, $full_dir;
3995
 
            }
 
4132
            }
3996
4133
            else {
3997
4134
                warn "$My_name: ====== There were problems writing to",
3998
4135
                     "----- '$file' in '$full_dir'.\n",
3999
4136
                     "----- But this is not the standard situation of\n",
4000
4137
                     "----- aux file to subdir of output directory, with\n",
4001
 
                     "----- non-existent subdir\n",
 
4138
                     "----- non-existent subdir\n",
4002
4139
            }
4003
4140
        }
4004
4141
   INCLUDE_CANDIDATE:
4027
4164
        #   anymore.
4028
4165
        #
4029
4166
        # Solution: use ' [', but not '[' as first try at delimiter.
4030
 
        # Then if candidate filename is of form 'name1[name2]', then
4031
 
        #   try splitting it.  If 'name1' and/or 'name2' exists, put
4032
 
        #   it/them in list, else just put 'name1[name2]' in list.
4033
 
        # So form of filename is now:
4034
 
        #  '(', 
4035
 
        # then any number of characters that are NOT ')', '(', or '{'
4036
 
        #   (these form the filename);
4037
 
        # then ' [', or ' (', or ')', or end-of-string.
4038
 
        # That fails for pdflatex
4039
 
        # In log file:
4040
 
        #   '(' => start of reading of file, followed by filename
4041
 
        #   ')' => end of reading of file
4042
 
        #   '[' => start of page (normally preceeded by space)
4043
 
        # Remember: 
4044
 
        #    filename (on VAX/VMS) may include '[' and ']' (directory
4045
 
        #             separators) 
4046
 
        #    filenames (on MS-Win) commonly include space.
 
4167
        # Then if candidate filename is of form 'name1[name2]', then
 
4168
        #   try splitting it.  If 'name1' and/or 'name2' exists, put
 
4169
        #   it/them in list, else just put 'name1[name2]' in list.
 
4170
        # So form of filename is now:
 
4171
        #  '(', 
 
4172
        # then any number of characters that are NOT ')', '(', or '{'
 
4173
        #   (these form the filename);
 
4174
        # then ' [', or ' (', or ')', or end-of-string.
 
4175
        # That fails for pdflatex
 
4176
        # In log file:
 
4177
        #   '(' => start of reading of file, followed by filename
 
4178
        #   ')' => end of reading of file
 
4179
        #   '[' => start of page (normally preceeded by space)
 
4180
        # Remember: 
 
4181
        #    filename (on VAX/VMS) may include '[' and ']' (directory
 
4182
        #             separators) 
 
4183
        #    filenames (on MS-Win) commonly include space.
4047
4184
        #    filenames on UNIX can included space.
4048
4185
        #    Miktex quotes filenames
4049
4186
        #    But web2c doesn't.  Then 
4053
4190
        #    are rare.  System filenames with spaces are common, but
4054
4191
        #    they are normally followed by a newline rather than messages. 
4055
4192
 
4056
 
        # First step: replace $_ by whole of line after the '('
4057
 
        #             Thus $_ is putative filename followed by other stuff.
 
4193
        # First step: replace $_ by whole of line after the '('
 
4194
        #             Thus $_ is putative filename followed by other stuff.
4058
4195
            $_ = $1; 
4059
4196
            # Array of new candidate include files; sometimes more than one.
4060
4197
            my @new_includes = ();
4061
4198
            my $quoted = 0;
4062
4199
            if ( /^\"([^\"]+)\"/ ) {
4063
4200
               # Quoted file name, as from MikTeX
4064
 
                $quoted = 1;
 
4201
                $quoted = 1;
4065
4202
            }
4066
4203
            elsif ( /^([^\(^\)]*?)\s+[\[\{\<]/ ) {
4067
4204
                # Terminator: space then '[' or '{' or '<'
4075
4212
            elsif  ( /^([^\(^\)]*)(\))/ ) {
4076
4213
                # Terminator is ')'
4077
4214
            }
4078
 
            else {
 
4215
            else {
4079
4216
                #Terminator is end-of-string
4080
4217
            }
4081
4218
            $_ = $';       # Put $_ equal to the unmatched tail of string '
4086
4223
                # followed by space followed by message
4087
4224
                # (Common)
4088
4225
                push @new_includes, $1;
4089
 
            }
 
4226
            }
4090
4227
            if ( $include_candidate eq "[]" ) {
4091
4228
                # Part of overfull hbox message
4092
4229
                next INCLUDE_CANDIDATE;
4106
4243
                    # If the first component exists, we probably have the
4107
4244
                    #   pdflatex form
4108
4245
                    push @new_includes, $1, $2;
4109
 
                }
 
4246
                }
4110
4247
                else {
4111
4248
                    # We have something else.
4112
4249
                    # So leave the original candidate in the list
4113
 
                }
4114
 
            }
4115
 
        INCLUDE_NAME:
 
4250
                }
 
4251
            }
 
4252
        INCLUDE_NAME:
4116
4253
            foreach my $include_name (@new_includes) {
4117
4254
                $include_name = normalize_filename( $include_name );
4118
 
                my ($base, $path, $ext) = fileparseB( $include_name );
 
4255
                my ($base, $path, $ext) = fileparseB( $include_name );
4119
4256
                if ( ($path eq './') || ($path eq '.\\') ) {
4120
4257
                    $include_name = $base.$ext;
4121
 
                }
 
4258
                }
4122
4259
                if ( $include_name !~ m'[/|\\]' ) {
4123
4260
                    # Filename does not include a path character
4124
4261
                    # High potential for misparsed line
4125
 
                    $dependents{$include_name} = 2;
4126
 
                } else {
4127
 
                    $dependents{$include_name} = 3;
4128
 
                }
4129
 
                if ( $ext eq '.bbl' ) {
4130
 
                    warn "$My_name: Found input bbl file '$include_name'\n"
4131
 
                       unless $silent;
4132
 
                    push @bbl_files, $include_name;
4133
 
                }
4134
 
            } # INCLUDE_NAME
 
4262
                    $dependents{$include_name} = 2;
 
4263
                } else {
 
4264
                    $dependents{$include_name} = 3;
 
4265
                }
 
4266
                if ( $ext eq '.bbl' ) {
 
4267
                    warn "$My_name: Found input bbl file '$include_name'\n"
 
4268
                       unless $silent;
 
4269
                    push @bbl_files, $include_name;
 
4270
                }
 
4271
            } # INCLUDE_NAME
4135
4272
        } # INCLUDE_CANDIDATE
4136
4273
    } # LINE
4137
4274
 
4156
4293
        }
4157
4294
        elsif ( -e $candidate ) {
4158
4295
            if ( exists $generated_log{$candidate} ){
4159
 
                $dependents{$candidate} = 6;
4160
 
            }
 
4296
                $dependents{$candidate} = 6;
 
4297
            }
4161
4298
            elsif ($code == 0) {
4162
 
                $dependents{$candidate} = 5;
4163
 
            }
4164
 
            else {
4165
 
                $dependents{$candidate} = 4;
4166
 
            }
4167
 
        }
4168
 
        elsif ($code == 1) {
 
4299
                $dependents{$candidate} = 5;
 
4300
            }
 
4301
            else {
 
4302
                $dependents{$candidate} = 4;
 
4303
            }
 
4304
        }
 
4305
        elsif ($code == 1) {
4169
4306
            # Graphics file that is supposed to have been read.
4170
4307
            # Candidate name is as given in source file, not as path
4171
4308
            #   to actual file.
4174
4311
            # If the file still is not found, assume non-existent;
4175
4312
            my @kpse_result = kpsewhich( $candidate );
4176
4313
            if ($#kpse_result > -1) {
4177
 
                delete $dependents{$candidate};
 
4314
                delete $dependents{$candidate};
4178
4315
                $dependents{$kpse_result[0]} = 4;
4179
 
                next CANDIDATE;
4180
 
            }
4181
 
            else {
4182
 
                push @not_found, $candidate;
4183
 
            }
4184
 
        }
 
4316
                next CANDIDATE;
 
4317
            }
 
4318
            else {
 
4319
                push @not_found, $candidate;
 
4320
            }
 
4321
        }
4185
4322
        elsif ($code == 2) {
4186
4323
            # Candidate is from '(...' construct in log file, for input file
4187
4324
            #    which should include pathname if valid input file.
4189
4326
            #    $code==2.
4190
4327
            # We get here if candidate file does not exist with given name
4191
4328
            # Almost surely result of a misparsed line in log file.
4192
 
            delete $dependents{$candidate};
 
4329
            delete $dependents{$candidate};
4193
4330
            push @misparse, $candidate;
4194
 
        }
 
4331
        }
4195
4332
        elsif ($code == 3) {
4196
4333
            # Candidate is from '(...' construct in log file, for input file
4197
4334
            #    which should include pathname if valid input file.
4201
4338
            # given name.  
4202
4339
            # Almost surely result of a misparsed line in log file.
4203
4340
            # But with lower probability than $code == 2
4204
 
            delete $dependents{$candidate};
 
4341
            delete $dependents{$candidate};
4205
4342
            push @misparse, $candidate;
4206
 
        }
4207
 
        elsif ($code == 0) {
 
4343
        }
 
4344
        elsif ($code == 0) {
4208
4345
            my ($base, $path, $ext) = fileparseA($candidate);
4209
4346
            $ext =~ s/^\.//;
4210
4347
            if ( ($ext eq '') && (-e "$path$base.tex") ) {
4215
4352
                #    to the missing file, unless the .tex file was
4216
4353
                #    created during the run.  
4217
4354
                # OLD $dependents{"$path$base.tex"} = 4;
4218
 
                # OLD delete $dependents{$candidate};
 
4355
                # OLD delete $dependents{$candidate};
4219
4356
                # NEW:
4220
 
                $dependents{"$path$base.tex"} = 4;
4221
 
            }
4222
 
            push @missing, $candidate;
4223
 
        }
 
4357
                $dependents{"$path$base.tex"} = 4;
 
4358
            }
 
4359
            push @missing, $candidate;
 
4360
        }
4224
4361
    }
4225
4362
CANDIDATE_PAIR:
4226
4363
    foreach my $delegated_source (keys %new_conversions) {
4227
 
        my $delegated_output = $new_conversions{$delegated_source};
 
4364
        my $delegated_output = $new_conversions{$delegated_source};
4228
4365
        my $rule = "Delegated $delegated_source, $delegated_output";
4229
4366
        # N.B. $delegated_source eq '' means the output file
4230
4367
        #      was created without a named input file.
4235
4372
                my @kpse_result = kpsewhich( $candidate,);
4236
4373
                if ($#kpse_result > -1) {
4237
4374
                    $candidate = $kpse_result[0];
4238
 
                }
4239
 
            }
4240
 
        }
 
4375
                }
 
4376
            }
 
4377
        }
4241
4378
        if ( ( (-e $delegated_source) || ($delegated_source eq '') )
4242
4379
              && (-e $delegated_output) )
4243
4380
        {
4244
 
            $conversions{$delegated_output} = $delegated_source;
4245
 
            $dependents{$delegated_output} = 7;
 
4381
            $conversions{$delegated_output} = $delegated_source;
 
4382
            $dependents{$delegated_output} = 7;
4246
4383
            if ($delegated_source) {
4247
4384
                $dependents{$delegated_source} = 4;
4248
 
            }
4249
 
        }
4250
 
        elsif (!$silent) {
 
4385
            }
 
4386
        }
 
4387
        elsif (!$silent) {
4251
4388
            print "Logfile claimed conversion from '$delegated_source' ",
4252
 
                  "to '$delegated_output'.  But:\n";
 
4389
                  "to '$delegated_output'.  But:\n";
4253
4390
            if (! -e $delegated_output) {
4254
 
                print  "   Output file does not exist\n";
4255
 
            }
 
4391
                print  "   Output file does not exist\n";
 
4392
            }
4256
4393
            if ( ($delegated_source ne '') && (! -e $delegated_source) ) {
4257
 
                print  "   Input file does not exist\n";
4258
 
            }
4259
 
        }
 
4394
                print  "   Input file does not exist\n";
 
4395
            }
 
4396
        }
4260
4397
    }
4261
4398
 
 
4399
    if ( ($#warning_list >= 0) && !$log_silent ) {
 
4400
        @warning_list = uniqs( @warning_list );
 
4401
        show_array( "$My_name: List of undefined refs and citations:",
 
4402
                    @warning_list );
 
4403
    }
4262
4404
    
4263
4405
    if ( $diagnostics ) {
4264
4406
        @misparse = uniqs( @misparse );
4275
4417
 
4276
4418
        print "$dependents dependent files detected, of which ",
4277
4419
              "$exist exist, $not_found were not found,\n",
4278
 
              "   and $missing appear not to exist.\n";
 
4420
              "   and $missing appear not to exist.\n";
4279
4421
        print "Dependents:\n";
4280
4422
        foreach (@dependents) { 
4281
4423
            print "   '$_' "; 
4282
4424
            if ( $dependents{$_} == 6 ) { print " written by (pdf)latex";}
4283
4425
            if ( $dependents{$_} == 7 ) { print " converted by (pdf)latex";}
4284
 
            print "\n";
 
4426
            print "\n";
4285
4427
        }
4286
4428
        if ($not_found > 0) {
4287
 
            print "Not found:\n";
4288
 
            foreach (@not_found) { print "   $_\n"; }
4289
 
        }
 
4429
            print "Not found:\n";
 
4430
            foreach (@not_found) { print "   $_\n"; }
 
4431
        }
4290
4432
        if ($missing > 0) {
4291
 
            print "Not existent:\n";
4292
 
            foreach (@missing) { print "   $_\n"; }
4293
 
        }
 
4433
            print "Not existent:\n";
 
4434
            foreach (@missing) { print "   $_\n"; }
 
4435
        }
4294
4436
        if ( $bbl > 0 ) {
4295
4437
            print "Input bbl files:\n";
4296
4438
            foreach (@bbl_files) { print "   $_\n"; }
4336
4478
            if ( (exists $$Poutputs{$file}) && (! exists $$Pinputs{$file}) ) {
4337
4479
                $$Pfirst_read_after_write{$file} = 1;
4338
4480
            }
4339
 
            $$Pinputs{$file} = 1;
4340
 
        }
 
4481
            $$Pinputs{$file} = 1;
 
4482
        }
4341
4483
        elsif (/^\s*OUTPUT\s+(.*)$/) {
4342
4484
            # Take precautions against aliasing of foo, ./foo and other possibilities for cwd.
4343
 
            $$Poutputs{ normalize_filename( $1 )} = 1;
4344
 
        }
 
4485
            $$Poutputs{ normalize_filename( $1 )} = 1;
 
4486
        }
4345
4487
    }
4346
4488
    close( $fls_file );
4347
4489
    return 0;
4516
4658
      }
4517
4659
      elsif ( /^\\\@input\{(.*)\}/ ) { 
4518
4660
          # \\@input{next_aux_file_name}
4519
 
          &parse_aux1( $aux_dir1.$1 );
 
4661
          &parse_aux1( $aux_dir1.$1 );
 
4662
      }
 
4663
      else {
 
4664
          foreach my $Psub (@aux_hooks) {
 
4665
              &$Psub;
 
4666
          }
4520
4667
      }
4521
4668
   }
4522
4669
   close($aux_fh);
4564
4711
    if ( ! defined $check_time ) { $check_time = 0;}
4565
4712
    my ($new_time, $new_size) = get_time_size($file);
4566
4713
    my @nofile =  (0,-1,0);     # What we use for initializing
4567
 
                                # a new entry in fdb or flagging
4568
 
                                # non-existent file
 
4714
                                # a new entry in fdb or flagging
 
4715
                                # non-existent file
4569
4716
    if ( $new_size < 0 ) {
4570
4717
        delete $fdb_current{$file};
4571
4718
        return @nofile;
4659
4806
        s/^\s*//;
4660
4807
        s/\s*$//;
4661
4808
        if ($state == -1) {
4662
 
            if ( ! /^# Fdb version ([\d]+)$/ ) {
4663
 
                warn "$My_name: File-database '$in_name' is not of correct format\n";
 
4809
            if ( ! /^# Fdb version ([\d]+)$/ ) {
 
4810
                warn "$My_name: File-database '$in_name' is not of correct format\n";
4664
4811
                return 1;
4665
 
            }
 
4812
            }
4666
4813
            if ( $1 > $fdb_ver) {
4667
 
                warn "$My_name: File-database '$in_name' is of too new version, $1 > $fdb_ver\n";
 
4814
                warn "$My_name: File-database '$in_name' is of too new version, $1 > $fdb_ver\n";
4668
4815
                return 1;
4669
 
            }
 
4816
            }
4670
4817
            $state = 0;
4671
4818
        }
4672
4819
        # Ignore blank lines and comments
4673
4820
        if ( /^$/ || /^#/ || /^%/ ) { next LINE;}
4674
4821
        if ( /^\[\"([^\"]+)\"\]/ ) {
4675
4822
            # Start of section
4676
 
            $rule = $1;
 
4823
            $rule = $1;
4677
4824
            my $tail = $'; #'  Single quote in comment tricks the parser in
4678
4825
                           # emacs from misparsing an isolated single quote
4679
4826
            $run_time = $check_time = 0;
4680
4827
            $source = $dest = $base = '';
4681
4828
            if ( $tail =~ /^\s*(\S+)\s*$/ ) {
4682
4829
                $run_time = $1;
4683
 
            }
 
4830
            }
4684
4831
            elsif ( $tail =~ /^\s*(\S+)\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s*$/ ) {
4685
4832
                $run_time = $1;
4686
4833
                $source = $2;
4687
4834
                $dest = $3;
4688
4835
                $base = $4;
4689
 
            }
 
4836
            }
4690
4837
            elsif ( $tail =~ /^\s*(\S+)\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s+\"([^\"]*)\"\s+(\S+)\s*$/ ) {
4691
4838
                $run_time = $1;
4692
4839
                $source = $2;
4693
4840
                $dest = $3;
4694
4841
                $base = $4;
4695
4842
                $check_time = $5;
4696
 
            }
 
4843
            }
4697
4844
            if ( rdb_rule_exists( $rule ) ) {
4698
4845
                rdb_one_rule( $rule, 
4699
4846
                              sub{ 
4702
4849
                                   $$Pcheck_time = $check_time;
4703
4850
                                 }                                      
4704
4851
                             );
4705
 
            }
 
4852
            }
4706
4853
            elsif ($rule =~ /^cusdep\s+(\S+)\s+(\S+)\s+(.+)$/ ) {
4707
4854
                # Create custom dependency
4708
4855
                my $fromext = $1;
4722
4869
                #    lines of the fdb file
4723
4870
                rdb_create_rule( $rule, 'cusdep', '', $PAnew_cmd, 1, 
4724
4871
                                 $source, $dest, $base, 0, $run_time, $check_time, 1 );
4725
 
            }
 
4872
            }
4726
4873
            elsif ( $rule =~ /^(makeindex|bibtex|biber)\s*(.*)$/ ) {
4727
4874
                my $PA_extra_gen = [];
4728
4875
                my $rule_generic = $1;
4736
4883
                    $base = $path.$base;
4737
4884
                    if ($rule_generic eq 'makeindex') {
4738
4885
                        $dest = "$base.ind";
4739
 
                    }
 
4886
                    }
4740
4887
                    elsif ($rule_generic eq 'bibtex') {
4741
4888
                        $dest = "$base.bbl";
4742
4889
                        $source = "$base.aux";
4743
 
                    }
 
4890
                    }
4744
4891
                    elsif ($rule_generic eq 'biber') {
4745
4892
                        $dest = "$base.bbl";
4746
4893
                        $source = "$base.bcf";
4747
 
                    }
4748
 
                }
 
4894
                    }
 
4895
                }
4749
4896
                if ($rule =~ /^makeindex/) { $PA_extra_gen = [ "$base.ilg" ]; }
4750
4897
                if ($rule =~ /^(bibtex|biber)/) { $PA_extra_gen = [ "$base.blg" ]; }
4751
4898
                if ($rule =~ /^bibtex/) { $int_cmd = "run_bibtex"; }
4752
 
                warn "$My_name: File-database '$in_name': setting rule '$rule'\n"
 
4899
                warn "$My_name: File-database '$in_name': setting rule '$rule'\n"
4753
4900
                   if $diagnostics;
4754
4901
                my $cmd_type = 'external';
4755
4902
                my $ext_cmd = ${$rule_generic};
4756
 
                warn "  Rule kind = '$rule_generic'; ext_cmd = '$ext_cmd';\n",
 
4903
                warn "  Rule kind = '$rule_generic'; ext_cmd = '$ext_cmd';\n",
4757
4904
                     "  int_cmd = '$int_cmd';\n",
4758
 
                     "  source = '$source'; dest = '$dest'; base = '$base';\n"
 
4905
                     "  source = '$source'; dest = '$dest'; base = '$base';\n"
4759
4906
                   if $diagnostics;
4760
4907
                # Set source file as non-existent.  
4761
4908
                # If it existed on last run, it will be in later 
4762
4909
                #    lines of the fdb file
4763
4910
                rdb_create_rule( $rule, $cmd_type, $ext_cmd, $int_cmd, 1, 
4764
4911
                                 $source, $dest, $base, 0, $run_time,  $check_time, 1, $PA_extra_gen );
4765
 
            }
 
4912
            }
4766
4913
            else {
4767
 
                warn "$My_name: In file-database '$in_name' rule '$rule'\n",
 
4914
                warn "$My_name: In file-database '$in_name' rule '$rule'\n",
4768
4915
                     "   is not in use in this session\n"
4769
4916
                if $diagnostics;
4770
 
                $new_source = undef;
4771
 
                $state = 10;
4772
 
                next LINE;
4773
 
            }
 
4917
                $new_source = undef;
 
4918
                $state = 10;
 
4919
                next LINE;
 
4920
            }
4774
4921
            $new_source = $new_sources{$rule} = {};
4775
 
            $state = 1;  #Reading a section, source part
4776
 
        }
 
4922
            $state = 1;  #Reading a section, source part
 
4923
        }
4777
4924
        elsif ( ($state <=0) || ($state >= 3) ) {
4778
4925
            next LINE;
4779
 
        }
 
4926
        }
4780
4927
        elsif ( /^\(source\)/ ) { $state = 1; next LINE; }
4781
4928
        elsif ( /^\(generated\)/ ) { $state = 2; next LINE; }
4782
 
        elsif ( ($state == 1) && /^\"([^\"]*)\"\s+(\S+)\s+(\S+)\s+(\S+)\s+\"([^\"]*)\"/ ) {
 
4929
        elsif ( ($state == 1) && /^\"([^\"]*)\"\s+(\S+)\s+(\S+)\s+(\S+)\s+\"([^\"]*)\"/ ) {
4783
4930
            # Source file line
4784
 
            my $file = $1;
4785
 
            my $time = $2;
4786
 
            my $size = $3;
4787
 
            my $md5 = $4;
 
4931
            my $file = $1;
 
4932
            my $time = $2;
 
4933
            my $size = $3;
 
4934
            my $md5 = $4;
4788
4935
            my $from_rule = $5;
4789
4936
#??            print "  --- File '$file'\n";
4790
4937
            if ($state != 1) {
4791
4938
                warn "$My_name: In file-database '$in_name' ",
4792
 
                     "line $. is outside a section:\n   '$_'\n";
4793
 
                $errors++;
4794
 
                next LINE;
4795
 
            }
 
4939
                     "line $. is outside a section:\n   '$_'\n";
 
4940
                $errors++;
 
4941
                next LINE;
 
4942
            }
4796
4943
            # Set file in database.  But ensure we don't do an unnecessary 
4797
4944
            #    fdb_get, which can trigger a new MD5 calculation, which is
4798
4945
            #    lengthy for a big file.  Ininitially flagging the file
4799
4946
            #    as non-existent solves the problem:
4800
 
            rdb_ensure_file( $rule, $file, undef, 1 ); 
 
4947
            rdb_ensure_file( $rule, $file, undef, 1 ); 
4801
4948
            rdb_set_file1( $rule, $file, $time, $size, $md5 );
4802
4949
            fdb_set( $file, $time, $size, $md5 );
4803
4950
            # Save the rest of the data, especially the from_fule until we know all 
4804
4951
            #   the rules, otherwise the from_rule may not exist.
4805
4952
            # Also we'll have a better chance of looping through files.
4806
 
            ${$new_source}{$file} = [ $time, $size, $md5, $from_rule ];
4807
 
        }
4808
 
        elsif ( ($state == 2) && /^\"([^\"]*)\"/ ) {
 
4953
            ${$new_source}{$file} = [ $time, $size, $md5, $from_rule ];
 
4954
        }
 
4955
        elsif ( ($state == 2) && /^\"([^\"]*)\"/ ) {
4809
4956
            my $file = $1;
4810
4957
            rdb_one_rule( $rule, sub{ rdb_add_generated($file); } );
4811
4958
        }
4812
 
        else {
4813
 
            warn "$My_name: In file-database '$in_name' ",
 
4959
        else {
 
4960
            warn "$My_name: In file-database '$in_name' ",
4814
4961
                 "line $. is of wrong format:\n   '$_'\n";
4815
 
            $errors++;
4816
 
            next LINE;
4817
 
        }
 
4962
            $errors++;
 
4963
            next LINE;
 
4964
        }
4818
4965
    }
4819
4966
    undef $in_handle;
4820
4967
    # Set cus dependencies.
4864
5011
       \@rules,
4865
5012
       sub { 
4866
5013
           # Omit data on a unused and never-run primary rule:
4867
 
           if ( ($$Prun_time == 0) 
 
5014
           if ( ($$Prun_time == 0) 
4868
5015
                && exists( $possible_primaries{$rule} )
4869
5016
                && ! exists( $current_primaries{$rule} )
4870
5017
              )
4874
5021
           print $out_handle "[\"$rule\"] $$Prun_time \"$$Psource\" \"$$Pdest\" \"$$Pbase\" $$Pcheck_time\n";
4875
5022
           rdb_do_files(
4876
5023
             sub { print $out_handle "  \"$file\" $$Ptime $$Psize $$Pmd5 \"$$Pfrom_rule\"\n"; }
4877
 
           );
 
5024
           );
4878
5025
           print $out_handle "  (generated)\n";
4879
5026
           foreach (keys %$PHdest) {
4880
5027
               print $out_handle "  \"$_\"\n";
4896
5043
 
4897
5044
    # Rules should only be primary
4898
5045
    if ( $$Pcmd_type ne 'primary' ) {
4899
 
        warn "\n$My_name: ==========$My_name: Probable BUG======= \n   ",
 
5046
        warn "\n$My_name: ==========$My_name: Probable BUG======= \n   ",
4900
5047
             "   rdb_set_latex_deps called to set files ",
4901
5048
             "for non-primary rule '$rule'\n\n";
4902
5049
        return;
4924
5071
    local @missing_subdirs = ();  # Missing subdirectories in aux_dir
4925
5072
 
4926
5073
    # The following are also returned, but are global, to be used by caller
4927
 
    # $reference_changed, $bad_reference $bad_citation
 
5074
    # $reference_changed, $bad_reference $bad_citation, $mult_defined
 
5075
 
 
5076
    # Do I have my own eps-to-pdf conversion?
 
5077
    my $epspdf_cusdep = 0;
 
5078
    foreach (@cus_dep_list) {
 
5079
        if ( /^eps pdf / ) { $epspdf_cusdep = 1; last; }
 
5080
    }
4928
5081
 
4929
5082
    &parse_log;
4930
5083
    $missing_dirs = 'none';      # Status of missing directories
4934
5087
            foreach my $dir ( uniqs( @missing_subdirs ) ) {
4935
5088
                if ( -d $dir ) {
4936
5089
                    $missing_dirs = 'failure';
4937
 
                    warn "$My_name: ==== Directory '$dir' is said to be missing\n",
4938
 
                         "     But it exists!\n";
 
5090
                    warn "$My_name: ==== Directory '$dir' is said to be missing\n",
 
5091
                         "     But it exists!\n";
4939
5092
                }
4940
5093
                elsif ( (-e $dir) && (!-d $dir) ) {
4941
5094
                    $missing_dirs = 'failure';
4942
 
                    warn "$My_name: ==== Directory '$dir' is said to be missing\n",
4943
 
                         "     But a non-directory file of this name exists!\n";
 
5095
                    warn "$My_name: ==== Directory '$dir' is said to be missing\n",
 
5096
                         "     But a non-directory file of this name exists!\n";
4944
5097
                }
4945
5098
                else {
4946
5099
                    if (mkdir $dir) {
4947
5100
                        warn "$My_name: Directory '$dir' created\n";
4948
 
                    }
 
5101
                    }
4949
5102
                    else {
4950
5103
                        $missing_dirs = 'failure';
4951
5104
                        warn "$My_name: Couldn't create directory '$dir'.\n",
4952
5105
                             "    System error: '$!'\n";
4953
 
                    }
 
5106
                    }
4954
5107
                }
4955
5108
            }
4956
 
        }
 
5109
        }
4957
5110
        else {
4958
5111
            $missing_dirs = 'not allowed';
4959
5112
            warn "$My_name: There are missing subdirectories, but their creation\n",
4960
 
                 "    is not allowed.  The subdirectories are:\n";
 
5113
                 "    is not allowed.  The subdirectories are:\n";
4961
5114
            foreach my $dir ( uniqs( @missing_subdirs ) ) {
4962
5115
                warn "   '$dir'\n";
4963
5116
            }
4969
5122
        parse_fls( $fls_file, \%source_fls, \%generated_fls, \%first_read_after_write );
4970
5123
        foreach (keys %source_fls) {
4971
5124
            $dependents{$_} = 4;
4972
 
        }
 
5125
        }
4973
5126
        foreach (keys %generated_fls) {
4974
5127
            rdb_add_generated( $_ );
4975
5128
            if ( exists($dependents{$_}) ) {
4976
5129
               $dependents{$_} = 6;
 
5130
            }
 
5131
        }
 
5132
    }
 
5133
 
 
5134
    for my $conv (sort keys %conversions) {
 
5135
        my $conv_source = $conversions{$conv};
 
5136
        if ( $conv =~ /^(.*)-eps-converted-to\.pdf$/ ) {
 
5137
            # Check all the conditions for pdflatex's conversion eps to pdf
 
5138
            # are valid; if they are, treat the converted file as not a
 
5139
            # source file.
 
5140
            my $base = $1;
 
5141
            if ( (-e $conv_source) && (-e $conv) && ( $conv_source eq "$base.eps" ) ) {
 
5142
                # $conv isn't a real source of (pdf)latex
 
5143
                rdb_remove_files( $rule, $conv );
 
5144
                delete $dependents{$conv};
 
5145
                if ($epspdf_cusdep) {
 
5146
                    $dependents{"$base.pdf"} = ((-e "$base.pdf") ? 4 : 0 );
 
5147
                }
4977
5148
            }
4978
 
        }
 
5149
        }
4979
5150
    }
 
5151
 
 
5152
 
 
5153
 
4980
5154
# ?? !! Should also deal with .run.xml file
4981
5155
 
4982
5156
    # Handle result on output file:
5004
5178
 
5005
5179
  IDX_FILE:
5006
5180
    foreach my $idx_file ( keys %idx_files ) {
5007
 
        my ($ind_file, $ind_base) = @{$idx_files{$idx_file}};
 
5181
        my ($ind_file, $ind_base) = @{$idx_files{$idx_file}};
5008
5182
        my $from_rule = "makeindex $idx_file";
5009
5183
        if ( ! rdb_rule_exists( $from_rule ) ){
5010
5184
            print "!!!===Creating rule '$from_rule': '$ind_file' from '$idx_file'\n"
5014
5188
            print "  ===Source file '$ind_file' for '$rule'\n"
5015
5189
                  if ($diagnostics);
5016
5190
            rdb_ensure_file( $rule, $ind_file, $from_rule );
5017
 
        }
 
5191
        }
5018
5192
        # Make sure the .ind file is treated as a detected source file;
5019
5193
        # otherwise if the log file has it under a different name (as
5020
5194
        # with MiKTeX which gives full directory information), there
5024
5198
        if ( ! -e $ind_file ) { 
5025
5199
            # Failure was non-existence of makable file
5026
5200
            # Leave failure issue to other rules.
5027
 
            $failure = 0;
5028
 
        }
 
5201
            $failure = 0;
 
5202
        }
5029
5203
    }
5030
5204
 
 
5205
    local %processed_aux_files = ();
5031
5206
  BBL_FILE:
5032
5207
    foreach my $bbl_file ( uniqs( @bbl_files ) ) {
5033
 
        my ($bbl_base, $bbl_path, $bbl_ext) = fileparseA( $bbl_file );
 
5208
        my ($bbl_base, $bbl_path, $bbl_ext) = fileparseA( $bbl_file );
5034
5209
        $bbl_base = $bbl_path.$bbl_base;
5035
5210
        my @new_bib_files = ();
5036
5211
        my @new_aux_files = ();
5039
5214
        my $bib_program = 'bibtex';
5040
5215
        if ( test_gen_file( "$bbl_base.bcf" ) ) {
5041
5216
             $bib_program = 'biber';
5042
 
        }
 
5217
        }
5043
5218
        my $from_rule = "$bib_program $bbl_base";
5044
5219
        print "=======  Dealing with '$from_rule'\n" if ($diagnostics);
5045
5220
        if ($bib_program eq 'biber') {
5057
5232
            if ( $bib_program eq 'biber' ) {
5058
5233
                rdb_create_rule( $from_rule, 'external', $biber, '', 1,
5059
5234
                                 "$bbl_base.bcf", $bbl_file, $bbl_base, 1, 0, 0 );
5060
 
             }
 
5235
             }
5061
5236
             else {
5062
5237
                 rdb_create_rule( $from_rule, 'external', $bibtex, 'run_bibtex', 1,
5063
5238
                                  "$bbl_base.aux", $bbl_file, $bbl_base, 1, 0, 0 );
5064
 
               }
5065
 
        }
 
5239
               }
 
5240
        }
5066
5241
        local %old_sources = ();
5067
5242
        rdb_one_rule( $from_rule, sub { %old_sources = %$PHsource; } );
5068
5243
        foreach my $source ( @new_bib_files, @new_aux_files, @new_bst_files, @biber_source ) {
5071
5246
            rdb_ensure_file( $from_rule, $source );
5072
5247
            delete $old_sources{$source};
5073
5248
        }
 
5249
        foreach my $source ( @new_aux_files ) {
 
5250
            $processed_aux_files{$source} = 1;
 
5251
        }
5074
5252
        if ($diagnostics) {
5075
5253
            foreach ( keys %old_sources ) {
5076
5254
                print "Removing no-longer-needed dependent '$_' from rule '$from_rule'\n";
5084
5262
            # Failure was non-existence of makable file
5085
5263
            # Leave failure issue to other rules.
5086
5264
            $failure = 0;
5087
 
        }
 
5265
        }
 
5266
    }
 
5267
 
 
5268
    if ( ($#aux_hooks > -1) && ! exists $processed_aux_files{$aux_main} ) {
 
5269
        my @new_bib_files = ();
 
5270
        my @new_aux_files = ();
 
5271
        my @new_bst_files = ();
 
5272
        parse_aux( $aux_main, \@new_bib_files, \@new_aux_files, \@new_bst_files );
 
5273
        foreach my $source ( @new_aux_files ) {
 
5274
            $processed_aux_files{$source} = 1;
 
5275
        }
5088
5276
    }
5089
5277
 
5090
5278
NEW_SOURCE:
5091
 
    foreach my $new_source (keys %dependents, keys %conversions) {
 
5279
    foreach my $new_source (keys %dependents) {
5092
5280
        print "  ===Source file for rule '$rule': '$new_source'\n"
5093
 
            if ($diagnostics);
5094
 
        if ( ($dependents{$new_source} == 5) 
 
5281
            if ($diagnostics);
 
5282
        if ( ($dependents{$new_source} == 5) 
5095
5283
             || ($dependents{$new_source} == 6) 
5096
5284
           ) {
5097
5285
            # (a) File was detected in "No file..." line in log file. 
5105
5293
            #    database, then the previous version of the file should be 
5106
5294
            #    treated as non-existent, to ensure another run is forced.
5107
5295
            rdb_ensure_file( $rule, $new_source, undef, 1 );
5108
 
        }
5109
 
        elsif ( $dependents{$new_source} == 7 )  {
 
5296
        }
 
5297
        elsif ( $dependents{$new_source} == 7 )  {
5110
5298
            # File was result of conversion by (pdf)latex.
5111
5299
            my $cnv_source = $conversions{$new_source};
5112
5300
            rdb_ensure_file( $rule, $new_source );
5113
 
            if ($cnv_source) {
 
5301
            if ($cnv_source) {
5114
5302
                # Conversion from $cnv_source to $new_source
5115
5303
                #   implies that effectively $cnv_source is a source
5116
5304
                #   of the (pdf)latex run.
5117
5305
                rdb_ensure_file( $rule, $cnv_source );
5118
 
            }
 
5306
            }
5119
5307
            # Flag that changes of the generated file during a run 
5120
5308
            #    do not require a rerun:
5121
5309
            rdb_one_file( $new_source, sub{ $$Pcorrect_after_primary = 1; } );
5122
 
        }
5123
 
        else {
 
5310
        }
 
5311
        else {
5124
5312
            # But we don't need special precautions for ordinary user files 
5125
5313
            #    (or for files that are generated outside of latex/pdflatex). 
5126
5314
            rdb_ensure_file( $rule, $new_source );
5127
 
        }
5128
 
        if ( ($dependents{$new_source} == 6) 
 
5315
        }
 
5316
        if ( ($dependents{$new_source} == 6) 
5129
5317
             || ($dependents{$new_source} == 7) 
5130
5318
           ) {
5131
 
            rdb_add_generated($new_source);
 
5319
            rdb_add_generated($new_source);
5132
5320
        }
5133
5321
    }
5134
5322
 
5135
5323
    my @more_sources = &rdb_set_dependents( $rule );
5136
5324
    my $num_new = $#more_sources + 1;
5137
5325
    foreach (@more_sources) { 
5138
 
        $dependents{$_} = 4;
 
5326
        $dependents{$_} = 4;
5139
5327
        if ( ! -e $_ ) { 
5140
5328
            # Failure was non-existence of makable file
5141
5329
            # Leave failure issue to other rules.
5147
5335
        delete $dependents{$_};
5148
5336
    }
5149
5337
    if ($diagnostics) {
5150
 
        if ($num_new > 0 ) {
5151
 
            print "$num_new new source files for rule '$rule':\n";
5152
 
            foreach (@more_sources) { print "   '$_'\n"; }
5153
 
        }
5154
 
        else {
5155
 
            print "No new source files for rule '$rule':\n";
5156
 
        }
 
5338
        if ($num_new > 0 ) {
 
5339
            print "$num_new new source files for rule '$rule':\n";
 
5340
            foreach (@more_sources) { print "   '$_'\n"; }
 
5341
        }
 
5342
        else {
 
5343
            print "No new source files for rule '$rule':\n";
 
5344
        }
5157
5345
        my @first_read_after_write = sort keys %first_read_after_write;
5158
5346
        if ($#first_read_after_write >= 0) {
5159
5347
            print "The following files were only read after being written:\n";
5160
5348
            foreach (@first_read_after_write) {
5161
5349
                print "   '$_'\n";
5162
 
            }
5163
 
          }
 
5350
            }
 
5351
          }
5164
5352
    }
5165
5353
    my @files_not_needed = ();
5166
5354
    foreach (keys %$PHsource) { 
5168
5356
            print "Removing no-longer-needed dependent '$_' from rule '$rule'\n"
5169
5357
              if $diagnostics;
5170
5358
            push @files_not_needed, $_;
5171
 
        }
 
5359
        }
5172
5360
    }
5173
5361
    rdb_remove_files( $rule, @files_not_needed );
5174
5362
 
5216
5404
            $new_includes{"$missing.tex"} = 1;
5217
5405
        }
5218
5406
        if ( -e $missing ) { 
5219
 
            $new_includes{$missing} = 1;
 
5407
            $new_includes{$missing} = 1;
5220
5408
        }
5221
5409
        if ( $ext ne "" ) {
5222
5410
            foreach my $dep (@cus_dep_list){
5223
5411
               my ($fromext,$toext) = split('\s+',$dep);
5224
5412
               if ( ( "$ext" eq "$toext" )
5225
5413
                    && ( -e "$path$base.$fromext" )
5226
 
                  )  {
 
5414
                  )  {
5227
5415
                  # Source file for the missing file exists
5228
5416
                  # So we have a real include file, and it will be made
5229
5417
                  # next time by rdb_set_dependents
5230
5418
                  $new_includes{$missing} = 1;
5231
5419
               }
5232
 
               else {
 
5420
               else {
5233
5421
                   # no point testing the $toext if the file doesn't exist.
5234
 
               }
 
5422
               }
5235
5423
               next MISSING_FILE;
5236
 
            }
 
5424
            }
5237
5425
       }
5238
5426
       else {
5239
5427
           # $_ doesn't exist, $_.tex doesn't exist,
5253
5441
                  $new_includes{"$path$base.$toext"} = 1;
5254
5442
#                  next MISSING_FILE;
5255
5443
              }
5256
 
           }
 
5444
           }
5257
5445
       }
5258
5446
    } # end MISSING_FILES
5259
5447
 
5272
5460
        my $stripped = $file;
5273
5461
        $stripped =~ s{^\./}{};
5274
5462
        if ( exists $PHsource{$file} ) {
5275
 
            delete $new_includes{$file};
5276
 
        }
 
5463
            delete $new_includes{$file};
 
5464
        }
5277
5465
        else {
5278
 
            $found ++;
5279
 
            rdb_ensure_file( $rule, $file );
5280
 
        }
 
5466
            $found ++;
 
5467
            rdb_ensure_file( $rule, $file );
 
5468
        }
5281
5469
    }
5282
5470
 
5283
5471
    if ( $diagnostics && ( $found > 0 ) ) {
5284
 
        warn "$My_name: Detected previously missing files:\n";
 
5472
        warn "$My_name: Detected previously missing files:\n";
5285
5473
        foreach ( sort keys %new_includes ) {
5286
5474
            warn "   '$_'\n";
5287
 
        }
 
5475
        }
5288
5476
    }
5289
5477
    return $found;
5290
5478
} # END rdb_find_new_files
5301
5489
    rdb_for_some( [@_],  0, \&rdb_one_dep );
5302
5490
# OLD    rdb_recurse( [@_],  0, \&rdb_one_dep );
5303
5491
    foreach (@deletions) {
5304
 
        my ($rule, $file) = @$_;
 
5492
        my ($rule, $file) = @$_;
5305
5493
        rdb_remove_files( $rule, $file );
5306
5494
    }
5307
5495
    &rdb_make_links;
5330
5518
        my ($fromext,$proptoext,$must,$func_name) = split('\s+',$dep);
5331
5519
        if ( $toext eq $proptoext ) {
5332
5520
            my $source = "$base_name.$fromext";
5333
 
            # Found match of rule
 
5521
            # Found match of rule
5334
5522
            if ($diagnostics) {
5335
5523
                print "Found cusdep:  $source to make $rule:$new_dest ====\n";
5336
5524
            }
5337
 
            if ( -e $source ) {
5338
 
                $$Pfrom_rule = "cusdep $fromext $toext $base_name";
5339
 
#??             print "?? Ensuring rule for '$$Pfrom_rule'\n";
 
5525
            if ( -e $source ) {
 
5526
                $$Pfrom_rule = "cusdep $fromext $toext $base_name";
 
5527
#??             print "?? Ensuring rule for '$$Pfrom_rule'\n";
5340
5528
                local @PAnew_cmd = ( 'do_cusdep', $func_name );
5341
5529
                if ( !-e $new_dest ) {
5342
 
                    push @new_sources, $new_dest;
5343
 
                }
 
5530
                    push @new_sources, $new_dest;
 
5531
                }
5344
5532
                if (! rdb_rule_exists( $$Pfrom_rule ) ) {
5345
5533
                    print "=== Creating rule for '$$Pfrom_rule'\n";
5346
5534
                    rdb_create_rule( $$Pfrom_rule, 'cusdep', '', \@PAnew_cmd, 3, 
5347
5535
                                     $source, $new_dest, $base_name, 0 );
5348
 
                }
 
5536
                }
5349
5537
                else {
5350
 
                    rdb_one_rule( 
 
5538
                    rdb_one_rule( 
5351
5539
                       $$Pfrom_rule, 
5352
5540
                       sub{ @$PAint_cmd = @PAnew_cmd; $$Pdest = $new_dest;}
5353
5541
                    );
5354
 
                }
5355
 
                return;
5356
 
            }
 
5542
                }
 
5543
                return;
 
5544
            }
5357
5545
            else {
5358
5546
                # Source file does not exist
5359
5547
                if ( !$force_mode && ( $must != 0 ) ) {
5362
5550
                    $failure_msg = "File '$base_name.$fromext' does not exist ".
5363
5551
                                   "to build '$base_name.$toext'";
5364
5552
                    return;
5365
 
                }
 
5553
                }
5366
5554
                elsif ( $$Pfrom_rule =~ /^cusdep $fromext $toext / )  {
5367
5555
                    # Source file does not exist, destination has the rule set.
5368
5556
                    # So turn the from_rule off
5369
 
                    $$Pfrom_rule = '';
5370
 
                }
5371
 
                else {
5372
 
                }
5373
 
            }
5374
 
        }
 
5557
                    $$Pfrom_rule = '';
 
5558
                }
 
5559
                else {
 
5560
                }
 
5561
            }
 
5562
        }
5375
5563
        elsif ( ($toext eq '') 
5376
5564
                && (! -e $file ) 
5377
5565
                && (! -e "$base_name.$proptoext" ) 
5384
5572
            my $source = "$base_name.$fromext";
5385
5573
            if ( -e $source ) {
5386
5574
                $new_dest = "$base_name.$proptoext";
5387
 
                my $from_rule = "cusdep $fromext $proptoext $base_name";
 
5575
                my $from_rule = "cusdep $fromext $proptoext $base_name";
5388
5576
                push @new_sources, $new_dest;
5389
 
                print "Ensuring rule for '$from_rule', to make '$new_dest'\n"
5390
 
                    if $diagnostics > -1;
 
5577
                print "Ensuring rule for '$from_rule', to make '$new_dest'\n"
 
5578
                    if $diagnostics > -1;
5391
5579
                local @PAnew_cmd = ( 'do_cusdep', $func_name );
5392
5580
                if (! rdb_rule_exists( $from_rule ) ) {
5393
5581
                    rdb_create_rule( $from_rule, 'cusdep', '', \@PAnew_cmd, 3, 
5394
5582
                                     $source, $new_dest, $base_name, 0 );
5395
 
                }
 
5583
                }
5396
5584
                else {
5397
 
                    rdb_one_rule( 
 
5585
                    rdb_one_rule( 
5398
5586
                       $$Pfrom_rule, 
5399
5587
                       sub{ @$PAint_cmd = @PAnew_cmd; $$Pdest = $new_dest;}
5400
5588
                    );
5401
 
                }
 
5589
                }
5402
5590
                rdb_ensure_file( $rule, $new_dest, $from_rule );
5403
5591
                # We've now got a spurious file in our rule.  But don't mess
5404
5592
                # with deleting an item we are in the middle of!
5405
5593
                push @deletions, [$rule, $file];
5406
 
                return;
5407
 
            }
 
5594
                return;
 
5595
            }
5408
5596
        } # End of Rule found
5409
5597
    } # End DEP
5410
5598
    if ( (! -e $file) && $use_make_for_missing_files ) {
5416
5604
             &Run_subst( "$make $q$file$q" );
5417
5605
             if ( -e $file ) {
5418
5606
                 return;
5419
 
             }
5420
 
        }
 
5607
             }
 
5608
        }
5421
5609
        else {
5422
5610
             print "$My_name: '$rule': source '$file' doesn't exist.\n",
5423
5611
                   "   I'll try making it with allowed extensions \n";
5437
5625
                     # the error due to a missing file.
5438
5626
                     $$Pout_of_date_user = 1;
5439
5627
                     return;
5440
 
                 }
5441
 
           }
5442
 
        }
 
5628
                 }
 
5629
           }
 
5630
        }
5443
5631
    }
5444
5632
} #END rdb_one_dep
5445
5633
 
5453
5641
    my @accessible_all = rdb_accessible( keys %requested_filerules ); 
5454
5642
    rdb_for_some( 
5455
5643
        \@accessible_all,
5456
 
        sub{ $count_rules++; 
 
5644
        sub{ $count_rules++; 
5457
5645
             print "Rule '$rule' depends on:\n"; 
5458
5646
           },
5459
 
        sub{ print "    '$file'\n"; },
5460
 
        sub{ print "  and generates:\n";
 
5647
        sub{ print "    '$file'\n"; },
 
5648
        sub{ print "  and generates:\n";
5461
5649
             foreach (keys %$PHdest) { print "    '$_'\n"; }
5462
5650
#             print "  default_extra_generated:\n";
5463
5651
#             foreach (@$PA_extra_generated) { print "    '$_'\n"; }
5464
5652
           },
5465
5653
    );
5466
5654
    if ($count_rules <= 0) {
5467
 
        print "   ---No rules defined\n";
 
5655
        print "   ---No rules defined\n";
5468
5656
    }
5469
5657
} #END rdb_list
5470
5658
 
5484
5672
    my @accessible_all = rdb_accessible( keys %requested_filerules );
5485
5673
    rdb_for_some(
5486
5674
        \@accessible_all,
5487
 
        sub{ 
 
5675
        sub{ 
5488
5676
#             foreach (keys %$PHdest) { print "-----   $_\n"; }
5489
5677
             push @generated, keys %$PHdest; 
5490
5678
           },
5491
 
        sub{ $source{$file} = 1; }
 
5679
        sub{ $source{$file} = 1; }
5492
5680
    );
5493
5681
    foreach (keys %generated_exts_all) {
5494
5682
        (my $name = /%R/ ? $_ : "%R.$_") =~ s/%R/$root_filename/;
5527
5715
    print "===Rules:\n";
5528
5716
    local $count_rules = 0;
5529
5717
    rdb_for_all( 
5530
 
        sub{ $count_rules++; 
 
5718
        sub{ $count_rules++; 
5531
5719
             my @int_cmd = @$PAint_cmd;
5532
 
             foreach (@int_cmd) {
5533
 
                 if ( !defined($_) ) { $_='undef';}
5534
 
             }
 
5720
             foreach (@int_cmd) {
 
5721
                 if ( !defined($_) ) { $_='undef';}
 
5722
             }
5535
5723
             print "  [$rule]: '$$Pcmd_type' '$$Pext_cmd' '@int_cmd' $$Ptest_kind ",
5536
5724
                   "'$$Psource' '$$Pdest' '$$Pbase' $$Pout_of_date $$Pout_of_date_user\n"; },
5537
 
        sub{ print "    '$file': $$Ptime $$Psize $$Pmd5 '$$Pfrom_rule'\n"; }
 
5725
        sub{ print "    '$file': $$Ptime $$Psize $$Pmd5 '$$Pfrom_rule'\n"; }
5538
5726
    );
5539
5727
    if ($count_rules <= 0) {
5540
 
        print "   ---No rules defined\n";
 
5728
        print "   ---No rules defined\n";
5541
5729
    }
5542
5730
} #END rdb_show
5543
5731
 
5735
5923
                           # making currently non-existent file, which
5736
5924
                           # could become a needed source file for a run
5737
5925
                           # and therefore undo an error condition
5738
 
            if ($diagnostics) {
 
5926
            if ($diagnostics) {
5739
5927
                print "Make: doing pre_primary and primary...\n";
5740
5928
            }
5741
5929
            # Do the primary run if it is needed. On return $runs == 0
5746
5934
            #       limit.  In the second case $too_many_runs is set.
5747
5935
            rdb_for_some( [@pre_primary, $primary], \&rdb_make1 );
5748
5936
            if ( ($runs > 0) && ! $too_many_passes ) {
5749
 
                next PASS;
 
5937
                $retry_msg = 0;
 
5938
                if ( $force_mode || (! $failure) ) {
 
5939
                    next PASS;
 
5940
                }
 
5941
                # Get here on failure, without being in force_mode
 
5942
                if ( $newrule_nofile ) { 
 
5943
                    $retry_msg = 1;
 
5944
                    print "$My_name: Error on run, but found possibility to ",
 
5945
                          "make new source files\n";
 
5946
                    next PASS;
 
5947
                }
 
5948
                else { last PASS; }
5750
5949
            }
5751
5950
            if ($runs == 0) {
5752
5951
                # $failure not set on this pass, so use value from previous pass:
5753
5952
                $failure = $previous_failure;
 
5953
                if ($retry_msg) {
 
5954
                    print "But in fact no new files made\n";
 
5955
                }
5754
5956
                if ($failure && !$force_mode ) { last PASS; }
5755
 
            }
 
5957
            }
5756
5958
            if ( $missing_dvi_pdf ) { 
5757
5959
               # No output from primary, after completing circular dependence
5758
5960
               warn "Failure to make '$missing_dvi_pdf'\n";
5759
5961
               $failure = 1; 
5760
5962
               last PASS;
5761
5963
            }    
5762
 
            if ($diagnostics) {
5763
 
                print "Make: doing post_primary...\n";
5764
 
            }
 
5964
            if ($diagnostics) {
 
5965
                print "Make: doing post_primary...\n";
 
5966
            }
5765
5967
            rdb_for_some( [@post_primary], \&rdb_make1 );
5766
5968
            if ( ($runs == 0) || $too_many_passes ) {
5767
5969
                # If $too_many_passes is set, it should also be that
5768
5970
                # $runs == 0; but for safety, I also checked
5769
5971
                # $too_many_passes.
5770
5972
                last PASS;
5771
 
            }
5772
 
        }
5773
 
        continue {
 
5973
            }
 
5974
        }
 
5975
        continue {
5774
5976
            # Re-evaluate rule classification and accessibility,
5775
5977
            # but do not change primaries.
5776
5978
            # Problem is that %current_primaries gets altered
5778
5980
            &rdb_classify_rules( \%possible_primaries, @requested_targets );
5779
5981
            %current_primaries = %old_curr_prim;
5780
5982
            &rdb_make_links;
5781
 
        }
 
5983
        }
5782
5984
    }
5783
5985
    rdb_for_some( [@unusual_one_time], \&rdb_make1 );
5784
5986
    rdb_write( $fdb_name );
5785
5987
 
5786
5988
    if (! $silent) {
5787
 
        if ($failure && $force_mode) {
 
5989
        if ($failure && $force_mode) {
5788
5990
            print "$My_name: Errors, in force_mode: so I tried finishing targets\n";
5789
 
        }
5790
 
        elsif ($failure) {
 
5991
        }
 
5992
        elsif ($failure) {
5791
5993
            print "$My_name: Errors, so I did not complete making targets\n";
5792
 
        }
5793
 
        else {
 
5994
        }
 
5995
        else {
5794
5996
            local @dests = ();
5795
5997
            rdb_for_some( [@_], sub{ push @dests, $$Pdest if ($$Pdest); } );
5796
5998
            print "$My_name: All targets (@dests) are up-to-date\n";
5797
 
        }
 
5999
        }
5798
6000
    }
5799
6001
    return $failure;
5800
6002
} #END rdb_make
5805
6007
    local @errors = ();
5806
6008
    local @warnings = ();
5807
6009
    rdb_for_all( 
5808
 
               sub{
5809
 
                   if ($$Plast_message ne '') {
 
6010
               sub{
 
6011
                   if ($$Plast_message ne '') {
5810
6012
                       if ($$Plast_result == 200) {
5811
 
                          push @warnings, "$rule: $$Plast_message";
5812
 
                       }
5813
 
                       else {
5814
 
                          push @errors, "$rule: $$Plast_message";
5815
 
                       }
5816
 
                   }
5817
 
                   elsif ($$Plast_result == 1) {
5818
 
                       push @errors, "$rule: failed to create output file";
5819
 
                   }
5820
 
                   elsif ($$Plast_result == 2) {
5821
 
                       push @errors, "$rule: gave an error";
5822
 
                   }
5823
 
                   elsif ($$Prun_time == 0) {
 
6013
                          push @warnings, "$rule: $$Plast_message";
 
6014
                       }
 
6015
                       else {
 
6016
                          push @errors, "$rule: $$Plast_message";
 
6017
                       }
 
6018
                   }
 
6019
                   elsif ($$Plast_result == 1) {
 
6020
                       push @errors, "$rule: failed to create output file";
 
6021
                   }
 
6022
                   elsif ($$Plast_result == 2) {
 
6023
                       push @errors, "$rule: gave an error";
 
6024
                   }
 
6025
                   elsif ($$Prun_time == 0) {
5824
6026
                       #  This can have innocuous causes.  So don't report
5825
 
                   }
5826
 
               }
5827
 
              );
 
6027
                   }
 
6028
               }
 
6029
              );
5828
6030
    if ($#warnings > -1) { 
5829
 
        warn "Collected warning summary (may duplicate other messages):\n";
5830
 
        foreach (@warnings){
5831
 
            warn "  $_\n";
5832
 
        }
 
6031
        warn "Collected warning summary (may duplicate other messages):\n";
 
6032
        foreach (@warnings){
 
6033
            warn "  $_\n";
 
6034
        }
5833
6035
    }
5834
6036
    if ($#errors > -1) { 
5835
 
        warn "Collected error summary (may duplicate other messages):\n";
5836
 
        foreach (@errors){
5837
 
            warn "  $_\n";
5838
 
        }
 
6037
        warn "Collected error summary (may duplicate other messages):\n";
 
6038
        foreach (@errors){
 
6039
            warn "  $_\n";
 
6040
        }
5839
6041
    }
5840
6042
    return $#errors+1;
5841
6043
}
5868
6070
        $bibtex_not_run = 0;
5869
6071
        if ($bibtex_use == 0) {
5870
6072
           $bibtex_not_run = 2;
5871
 
        }
 
6073
        }
5872
6074
        elsif ($bibtex_use == 1) {
5873
 
            foreach ( keys %$PHsource ) {
5874
 
                if ( ( /\.bib$/ ) && (! -e $_) ) {
 
6075
            foreach ( keys %$PHsource ) {
 
6076
                if ( ( /\.bib$/ ) && (! -e $_) ) {
5875
6077
                    push @missing_bib_files, $_;
5876
6078
                    $bibtex_not_run = 1;
5877
 
                }
5878
 
            }
5879
 
        }
 
6079
                }
 
6080
            }
 
6081
        }
5880
6082
    }
5881
6083
 
5882
6084
    if ( ($$Prun_time == 0) && exists($possible_primaries{$rule}) ) {
5886
6088
    }
5887
6089
    else {
5888
6090
        if ( $$Pdest && (! -e $$Pdest) ) {
5889
 
            # With a non-existent destination, if we haven't made any passes
 
6091
            # With a non-existent destination, if we haven't made any passes
5890
6092
            #   through a rule, rerunning the rule is good, because the file
5891
6093
            #   may fail to exist because of being deleted by the user (for ex.)
5892
6094
            #   rather than because of a failure on a previous run. 
5893
6095
            # (We could do better with a flag in fdb file.)
5894
 
            # But after the first pass, the situation is different.  
5895
 
            #   For a primary rule (pdf)latex, the lack of a destination file 
5896
 
            #      could result from there being zero content due to a missing
5897
 
            #      essential input file.  The input file could be generated 
5898
 
            #      by a program to be run later (e.g., a cusdep or bibtex), 
5899
 
            #      so we should wait until all passes are completed before 
 
6096
            # But after the first pass, the situation is different.  
 
6097
            #   For a primary rule (pdf)latex, the lack of a destination file 
 
6098
            #      could result from there being zero content due to a missing
 
6099
            #      essential input file.  The input file could be generated 
 
6100
            #      by a program to be run later (e.g., a cusdep or bibtex), 
 
6101
            #      so we should wait until all passes are completed before 
5900
6102
            #      deciding a non-existent destination file is an error.
5901
 
            #   For a custom dependency, the rule may be obsolete, and
5902
 
            #      if the source file does not exist also, we should simply
5903
 
            #      not run the rule, but not set an error condition.
5904
 
            #      Any error will arise at the (pdf)latex level due to a 
5905
 
            #      missing source file at that level.
5906
 
            if ( $$Psource && (! -e $$Psource)
 
6103
            #   For a custom dependency, the rule may be obsolete, and
 
6104
            #      if the source file does not exist also, we should simply
 
6105
            #      not run the rule, but not set an error condition.
 
6106
            #      Any error will arise at the (pdf)latex level due to a 
 
6107
            #      missing source file at that level.
 
6108
            if ( $$Psource && (! -e $$Psource)
5907
6109
# OLD                && ( ( $$Pcmd_type eq 'cusdep') )
5908
6110
# NEW
5909
6111
                 && ( ( $$Pcmd_type ne 'primary') )
5910
6112
               ) {
5911
6113
                # Main source file doesn't exist, and rule is NOT primary.
5912
 
                # No action, since a run is pointless.  Primary is different:
 
6114
                # No action, since a run is pointless.  Primary is different:
5913
6115
                # file might be found elsewhere (by kpsearch from (pdf)latex),
5914
6116
                # while non-existence of main source file is a clear error.
5915
 
            }
5916
 
            elsif ( $$Pcmd_type eq 'delegated' ) {
5917
 
                # Delegate to destination rule
5918
 
            }
5919
 
            elsif ( $pass{$rule}==0) {
5920
 
                push @no_dest, $$Pdest;
5921
 
                $$Pout_of_date = 1;
5922
 
            }
5923
 
            if ( $$Pcmd_type eq 'primary' ) {
5924
 
                $missing_dvi_pdf = $$Pdest;
5925
 
            }
5926
 
        }
 
6117
            }
 
6118
            elsif ( $$Pcmd_type eq 'delegated' ) {
 
6119
                # Delegate to destination rule
 
6120
            }
 
6121
            elsif ( $pass{$rule}==0) {
 
6122
                push @no_dest, $$Pdest;
 
6123
                $$Pout_of_date = 1;
 
6124
            }
 
6125
            if ( $$Pcmd_type eq 'primary' ) {
 
6126
                $missing_dvi_pdf = $$Pdest;
 
6127
            }
 
6128
        }
5927
6129
    }
5928
6130
 
5929
6131
    &rdb_flag_changes_here(0);
5930
6132
 
5931
6133
    if (!$$Pout_of_date) {
5932
 
#??     if ( ($$Pcmd_type eq 'primary') && (! $silent) ) {
 
6134
#??     if ( ($$Pcmd_type eq 'primary') && (! $silent) ) {
5933
6135
#            print "Rule '$rule' up to date\n";
5934
6136
#        }
5935
 
        return;
 
6137
        return;
5936
6138
    }
5937
6139
    if ($diagnostics) { print "     remake\n"; }
5938
6140
    if (!$silent) { 
5957
6159
        # Treat rule as completed, else in -pvc mode get infinite reruns:
5958
6160
        $$Pout_of_date = 0;
5959
6161
        $failure = 1;
5960
 
        $failure_msg = "'$rule' needed too many passes";
 
6162
        $failure_msg = "'$rule' needed too many passes";
5961
6163
        return;
5962
6164
    }
5963
6165
 
5972
6174
        }
5973
6175
        elsif ($bibtex_not_run == 2 ) {
5974
6176
            warn "$My_name: I AM CONFIGURED/INVOKED NOT TO RUN '$rule'\n"; 
5975
 
        }
 
6177
        }
5976
6178
        $return = &rdb_dummy_run1;
5977
6179
    }
5978
6180
    else {
6003
6205
 
6004
6206
            # So in this case, do NOT report an error          
6005
6207
            $$Pout_of_date = 0;
6006
 
        }
 
6208
        }
6007
6209
        elsif ($$Pcmd_type eq 'primary' ) { 
6008
6210
            # For a primary rule, i.e., (pdf)latex, not to produce the 
6009
6211
            #    expected output file may not be an error condition.  
6014
6216
        elsif ($return == -2) {
6015
6217
           # Missing output file was reported to be NOT an error
6016
6218
           $$Pout_of_date = 0;
6017
 
        }
 
6219
        }
6018
6220
        elsif ( ($bibtex_use <= 1) && ($bibtex_not_run > 0) ) {
6019
6221
           # Lack of destination file is not to be treated as an error
6020
6222
           # for a bibtex rule when latexmk is configured not to treat
6022
6224
           # only error.
6023
6225
           $$Pout_of_date = 0;
6024
6226
        }
6025
 
        else {
 
6227
        else {
6026
6228
            $failure = 1;
6027
 
        }
 
6229
        }
6028
6230
    }
6029
6231
    if ( ($return != 0) && ($return != -2) ) {
6030
6232
        $failure = 1; 
6031
 
        $$Plast_result = 2;
 
6233
        $$Plast_result = 2;
6032
6234
        if ( !$$Plast_message ) {
6033
6235
            $$Plast_message = "Run of rule '$rule' gave a non-zero error code";
6034
 
        }
 
6236
        }
6035
6237
# !!??        $failure_msg = $$Plast_message;
6036
6238
        
6037
6239
    }
6082
6284
    @post_primary = reverse @post_primary;
6083
6285
 
6084
6286
    if ($diagnostics) {
6085
 
        print "Rule classification: \n";
6086
 
        if ($#requested_targets < 0) {
6087
 
            print "  No requested rules\n";
6088
 
        }
6089
 
        else {
6090
 
            print "  Requested rules:\n";
6091
 
            foreach ( @requested_targets ) { print "    $_\n"; }
6092
 
        }
6093
 
        if ($#pre_primary < 0) {
6094
 
            print "  No pre-primaries\n";
6095
 
        }
6096
 
        else {
6097
 
            print "  Pre-primaries:\n";
6098
 
            foreach (@pre_primary) { print "    $_\n"; }
6099
 
        }
6100
 
        print "  Primaries:\n";
6101
 
        foreach (keys %current_primaries) { print "    $_\n"; }
6102
 
        if ($#post_primary < 0) {
6103
 
            print "  No post-primaries\n";
6104
 
        }
6105
 
        else {
6106
 
            print "  Post-primaries:\n";
6107
 
            foreach (@post_primary) { print "    $_\n"; }
6108
 
        }
6109
 
        if ($#unusual_one_time < 0) {
6110
 
            print "  No inner-level one_time rules, as expected\n";
6111
 
        }
6112
 
        else {
6113
 
            print "  Inner-level one_time rules:\n";
6114
 
            foreach ( @unusual_one_time ) { print "    $_\n"; }
6115
 
        }
 
6287
        print "Rule classification: \n";
 
6288
        if ($#requested_targets < 0) {
 
6289
            print "  No requested rules\n";
 
6290
        }
 
6291
        else {
 
6292
            print "  Requested rules:\n";
 
6293
            foreach ( @requested_targets ) { print "    $_\n"; }
 
6294
        }
 
6295
        if ($#pre_primary < 0) {
 
6296
            print "  No pre-primaries\n";
 
6297
        }
 
6298
        else {
 
6299
            print "  Pre-primaries:\n";
 
6300
            foreach (@pre_primary) { print "    $_\n"; }
 
6301
        }
 
6302
        print "  Primaries:\n";
 
6303
        foreach (keys %current_primaries) { print "    $_\n"; }
 
6304
        if ($#post_primary < 0) {
 
6305
            print "  No post-primaries\n";
 
6306
        }
 
6307
        else {
 
6308
            print "  Post-primaries:\n";
 
6309
            foreach (@post_primary) { print "    $_\n"; }
 
6310
        }
 
6311
        if ($#unusual_one_time < 0) {
 
6312
            print "  No inner-level one_time rules, as expected\n";
 
6313
        }
 
6314
        else {
 
6315
            print "  Inner-level one_time rules:\n";
 
6316
            foreach ( @unusual_one_time ) { print "    $_\n"; }
 
6317
        }
6116
6318
        my @normal_one_time = keys %one_time;
6117
 
        if ($#normal_one_time < 0) {
6118
 
            print "  No outer-level one_time rules\n";
6119
 
        }
6120
 
        else {
6121
 
            print "  Outer-level one_time rules:\n";
6122
 
            foreach ( @normal_one_time ) { print "    $_\n"; }
6123
 
        }
 
6319
        if ($#normal_one_time < 0) {
 
6320
            print "  No outer-level one_time rules\n";
 
6321
        }
 
6322
        else {
 
6323
            print "  Outer-level one_time rules:\n";
 
6324
            foreach ( @normal_one_time ) { print "    $_\n"; }
 
6325
        }
6124
6326
    } #end diagnostics
6125
6327
 
6126
6328
} #END rdb_classify_rules
6147
6349
           $current_primaries{ $rule } = 1;
6148
6350
       }
6149
6351
       else {
6150
 
           push @post_primary, $rule;
 
6352
           push @post_primary, $rule;
6151
6353
       }
6152
6354
    }
6153
6355
    else {
6154
6356
        $state = 2;     # in post-primary rule
6155
 
        push @pre_primary, $rule;
 
6357
        push @pre_primary, $rule;
6156
6358
    }
6157
6359
} #END rdb_classify1
6158
6360
 
6192
6394
    my $int_cmd = shift @int_args;
6193
6395
    my @int_args_for_printing = @int_args;
6194
6396
    foreach (@int_args_for_printing) {
6195
 
        if ( ! defined $_ ) { $_ = 'undef'; }
 
6397
        if ( ! defined $_ ) { $_ = 'undef'; }
6196
6398
    }
6197
6399
    if ($int_cmd) {
6198
 
        print "For rule '$rule', running '\&$int_cmd( @int_args_for_printing )' ...\n";
 
6400
        print "For rule '$rule', running '\&$int_cmd( @int_args_for_printing )' ...\n";
6199
6401
        $return = &$int_cmd( @int_args ); 
6200
6402
    }
6201
6403
    elsif ($$Pext_cmd) {
6202
 
        $return = &Run_subst();
 
6404
        $return = &Run_subst();
6203
6405
    }
6204
6406
    else {
6205
6407
        warn "$My_name: Either a bug OR a configuration error:\n",
6232
6434
                "   be recreated, I'll try to do so.\n";
6233
6435
           $return = -2;
6234
6436
           rdb_for_some( [keys %current_primaries], sub{ $$Pout_of_date = 1; } );
6235
 
        }
 
6437
        }
6236
6438
        elsif ($retcode == 4) {
6237
6439
            $$Plast_result = 2;
6238
6440
            $$Plast_message = "Could not find all biber source files for '$$Pbase'";
6261
6463
        if ( ! -e $$Psource ) {
6262
6464
            $retcode = 10;
6263
6465
            rdb_for_some( [keys %current_primaries], sub{ $$Pout_of_date = 1; } );
6264
 
        }
 
6466
        }
6265
6467
        if ($retcode == 3) {
6266
6468
            $$Plast_result = 2;
6267
6469
            $$Plast_message = "Could not open bibtex log file for '$$Pbase'";
6282
6484
                warn "$My_name: Bibtex did not produce '$$Pdest'.  But that\n",
6283
6485
                     "     was because of missing files, so I will continue.\n";
6284
6486
                $return = -2;
6285
 
            }
 
6487
            }
6286
6488
            else {
6287
6489
                $return = 0;
6288
 
            }
 
6490
            }
6289
6491
        }
6290
6492
    }
6291
6493
 
6292
6494
    $updated = 1;
6293
6495
    if ($$Ptest_kind == 3) { 
6294
6496
        # We are time-criterion first time only.  Now switch to
6295
 
        # file-change criterion
 
6497
        # file-change criterion
6296
6498
        $$Ptest_kind = 1; 
6297
6499
    }
6298
6500
    $$Pout_of_date = $$Pout_of_date_user = 0;
6300
6502
    if ( ($$Plast_result == 0) && ($return != 0) && ($return != -2) ) {
6301
6503
        $$Plast_result = 2;
6302
6504
        if ($$Plast_message eq '') {
6303
 
            $$Plast_message = "Command for '$rule' gave return code $return";
6304
 
        }
 
6505
            $$Plast_message = "Command for '$rule' gave return code $return";
 
6506
        }
6305
6507
    }
6306
6508
    elsif ( $$Pdest && (! -e $$Pdest) && ($return != -2) ) {
6307
 
        $$Plast_result = 1;
 
6509
        $$Plast_result = 1;
6308
6510
    }
6309
6511
    return $return;
6310
6512
}  # END rdb_run1
6327
6529
 
6328
6530
    if ($$Ptest_kind == 3) { 
6329
6531
        # We are time-criterion first time only.  Now switch to
6330
 
        # file-change criterion
 
6532
        # file-change criterion
6331
6533
        $$Ptest_kind = 1; 
6332
6534
    }
6333
6535
    $$Pout_of_date = $$Pout_of_date_user = 0;
6386
6588
       '%%' => '%'         # To allow literal %B, %R, etc, by %%B.
6387
6589
    );
6388
6590
    if ( ($^O eq "MSWin32" ) && $MSWin_back_slash ) {
6389
 
        foreach ( '%R', '%B', '%T', '%S', '%D', '%Y', '%Z' ) {
6390
 
            $subst{$_} =~ s(/)(\\)g;
6391
 
        }
 
6591
        foreach ( '%R', '%B', '%T', '%S', '%D', '%Y', '%Z' ) {
 
6592
            $subst{$_} =~ s(/)(\\)g;
 
6593
        }
6392
6594
    }
6393
6595
 
6394
6596
    my @tokens = split /(%.)/, $ext_cmd;
6438
6640
        my @other_fls_names = ( );
6439
6641
        if ( $rule =~ /^pdflatex/ ) {
6440
6642
            push @other_fls_names, "pdflatex.fls";
6441
 
        }
 
6643
        }
6442
6644
        else {
6443
6645
            push @other_fls_names, "latex.fls";
6444
 
        }
 
6646
        }
6445
6647
        if ( $aux_dir1 ne '' ) {
6446
6648
           push @other_fls_names, "$root_filename.fls";
6447
 
        }
 
6649
        }
6448
6650
        # Find the first non-standard fls file and copy it to the standard
6449
6651
        # place. But only do this if the file time is compatible with being
6450
6652
        # generated in the current run, as tested by the use of
6455
6657
                copy $cand, $std_fls_file;
6456
6658
                last;
6457
6659
            }
6458
 
        }
 
6660
        }
6459
6661
        if ( ! test_gen_file( $std_fls_file ) ) {
6460
6662
            warn "$My_name: fls file doesn't appear to have been made\n";
6461
 
        }
 
6663
        }
6462
6664
    }
6463
6665
 
6464
6666
    # Find current set of source files:
6492
6694
#??    &rdb_update_files;
6493
6695
 
6494
6696
    if ( $diagnostics ) {
6495
 
        print "$My_name: Rules after run: \n";
6496
 
        rdb_show();
 
6697
        print "$My_name: Rules after run: \n";
 
6698
        rdb_show();
6497
6699
    }
6498
6700
 
6499
6701
    $return = $return_latex;
6505
6707
          if (! $silent);
6506
6708
       $return = 0;
6507
6709
    }
6508
 
 
6509
6710
    # Summarize issues that may have escaped notice:
6510
6711
    my @warnings = ();
6511
6712
    if ($bad_reference) {
6512
6713
        push @warnings, "Latex failed to resolve $bad_reference reference(s)";
6513
6714
    }
 
6715
    if ($mult_defined) {
 
6716
        push @warnings, "Latex found $mult_defined multiply defined reference(s)";
 
6717
    }
6514
6718
    if ($bad_citation) {
6515
6719
        push @warnings, "Latex failed to resolve $bad_citation citation(s)";
6516
6720
    }
6517
6721
    if ($#warnings > -1) {
6518
 
        show_array( "$My_name: Summary of warnings:", @warnings );
 
6722
        show_array( "$My_name: Summary of warnings:", @warnings );
6519
6723
    }
6520
6724
    return $return;
6521
6725
} #END rdb_primary_run
6551
6755
    $dest_mtime = get_mtime($$Pdest) if ($$Pdest);
6552
6756
    rdb_do_files( \&rdb_file_change1);
6553
6757
    if ($$Pout_of_date) {
6554
 
        push @rules_to_apply, $rule;
 
6758
        push @rules_to_apply, $rule;
6555
6759
    }
6556
 
#??     print "======== flag: $rule $$Pout_of_date ==========\n";
 
6760
#??     print "======== flag: $rule $$Pout_of_date ==========\n";
6557
6761
} #END rdb_flag_changes_here
6558
6762
 
6559
6763
#************************************************************
6574
6778
#??          "    New $new_time, $new_size, $new_md5\n";
6575
6779
    my $ext_no_period = ext_no_period( $file );
6576
6780
    if ( ($new_size < 0) && ($$Psize >= 0) ) {
6577
 
        # print "Disappeared '$file' in '$rule'\n";
 
6781
        # print "Disappeared '$file' in '$rule'\n";
6578
6782
        push @disappeared, $file;
6579
6783
        # No reaction is good.  
6580
6784
        #$$Pout_of_date = 1;
6590
6794
        return;
6591
6795
    }
6592
6796
    if ( ($new_size < 0) && ($$Psize < 0) ) {
6593
 
        return;
 
6797
        return;
6594
6798
    }
6595
6799
    if ( ($new_size != $$Psize) || ($new_md5 ne $$Pmd5) ) {
6596
6800
#??        print "FC1: changed $file: ($new_size != $$Psize) $new_md5 ne $$Pmd5)\n";
6597
 
        push @changed, $file;
6598
 
        $$Pout_of_date = 1;
 
6801
        push @changed, $file;
 
6802
        $$Pout_of_date = 1;
6599
6803
        if ( ! exists $generated_exts_all{$ext_no_period} ) {
6600
6804
            $$Pout_of_date_user = 1;
6601
 
        }
 
6805
        }
6602
6806
    }
6603
6807
    elsif ( $new_time != $$Ptime ) {
6604
6808
#warn "--==-- Unchanged $file, changed time, update filetime in $rule\n";
6605
 
        $$Ptime = $new_time;
 
6809
        $$Ptime = $new_time;
6606
6810
    }
6607
6811
    if ( ( ($$Ptest_kind == 2) || ($$Ptest_kind == 3) )
6608
6812
         && (! exists $generated_exts_all{$ext_no_period} )
6609
6813
         && ( $new_time > $dest_mtime )
6610
6814
        ) {
6611
6815
#??        print "FC1: changed $file: ($new_time > $dest_mtime)\n";
6612
 
            push @changed, $file;
6613
 
            $$Pout_of_date = $$Pout_of_date_user = 1;
 
6816
            push @changed, $file;
 
6817
            $$Pout_of_date = $$Pout_of_date_user = 1;
6614
6818
    }
6615
6819
} #END rdb_file_change1
6616
6820
 
6631
6835
    my $heading = defined($_[0]) ?   $_[0]  :  "$My_name: "; 
6632
6836
 
6633
6837
    if ($#rules_never_run >= 0) {
6634
 
        warn "${heading}Rules & subrules not known to be previously run:\n";
 
6838
        warn "${heading}Rules & subrules not known to be previously run:\n";
6635
6839
        foreach (@rules_never_run) { warn "   $_\n"; }
6636
6840
    }
6637
6841
    if ( ($#changed >= 0) || ($#disappeared >= 0) || ($#no_dest >= 0) ) {
6638
6842
        warn "${heading}File changes, etc:\n";
6639
6843
        if ( $#changed >= 0 ) {
6640
 
            warn "   Changed files, or newly in use since previous run(s):\n";
6641
 
            foreach (uniqs(@changed)) { warn "      '$_'\n"; }
 
6844
            warn "   Changed files, or newly in use since previous run(s):\n";
 
6845
            foreach (uniqs(@changed)) { warn "      '$_'\n"; }
6642
6846
        }
6643
6847
        if ( $#disappeared >= 0 ) {
6644
 
            warn "   No-longer-existing files:\n";
6645
 
            foreach (uniqs(@disappeared)) { warn "      '$_'\n"; }
 
6848
            warn "   No-longer-existing files:\n";
 
6849
            foreach (uniqs(@disappeared)) { warn "      '$_'\n"; }
6646
6850
        }
6647
6851
        if ( $#no_dest >= 0 ) {
6648
 
            warn "   Non-existent destination files:\n";
6649
 
            foreach (uniqs(@no_dest)) { warn "      '$_'\n"; }
 
6852
            warn "   Non-existent destination files:\n";
 
6853
            foreach (uniqs(@no_dest)) { warn "      '$_'\n"; }
6650
6854
        }
6651
6855
    }
6652
6856
    elsif ($#rules_to_apply >=0) {
6654
6858
         foreach (@rules_to_apply) { warn "      '$_'\n"; }
6655
6859
    }
6656
6860
    else {
6657
 
        warn "${heading}No file changes\n";
 
6861
        warn "${heading}No file changes\n";
6658
6862
    }
6659
6863
}     #END rdb_diagnose_changes
6660
6864
 
6815
7019
 
6816
7020
    foreach $rule ( @heads ) {
6817
7021
        # $rule is implicitly local
6818
 
        &rdb_one_rule( $rule, @_ );
 
7022
        &rdb_one_rule( $rule, @_ );
6819
7023
    }
6820
7024
}  #END rdb_for_some
6821
7025
 
6844
7048
    # Assumes recursion context, i.e. that %visited, @heads, $depth.
6845
7049
    # We are overriding actions:
6846
7050
    my ($rule, $rule_act1, $new_file_act1, $new_file_act2, $rule_act2)
6847
 
        = @_;
 
7051
        = @_;
6848
7052
    # and must propagate the file actions:
6849
7053
    local $file_act1 = $new_file_act1;
6850
7054
    local $file_act2 = $new_file_act2;
6870
7074
    # Assumes contexts set for: Recursion, rule, and file
6871
7075
    &$file_act1 if $file_act1;
6872
7076
    rdb_recurse_rule( $$Pfrom_rule, $rule_act1, $file_act1, $file_act2,
6873
 
                      $rule_act2 )
 
7077
                      $rule_act2 )
6874
7078
        if $$Pfrom_rule;
6875
7079
    &$file_act2 if $file_act2;
6876
7080
} #END rdb_recurse_file
7001
7205
            -1, '', $PA_extra_gen ],
7002
7206
           {},
7003
7207
           {}
7004
 
        ];
 
7208
        ];
7005
7209
    if ($source) {
7006
7210
       rdb_ensure_file( $rule, $source, undef, $set_file_not_exists );  
7007
7211
    }
7047
7251
    my $rule = shift;
7048
7252
    local ( $new_file, $new_from_rule, $set_not_exists ) = @_;
7049
7253
    if ( ! rdb_rule_exists( $rule ) ) {
7050
 
        die_trace( "$My_name: BUG in rdb_ensure_file: non-existent rule '$rule'" );
 
7254
        die_trace( "$My_name: BUG in rdb_ensure_file: non-existent rule '$rule'" );
7051
7255
    }
7052
7256
    if ( ! defined $new_file ) {
7053
 
        die_trace( "$My_name: BUG in rdb_ensure_file: undefined file for '$rule'" );
 
7257
        die_trace( "$My_name: BUG in rdb_ensure_file: undefined file for '$rule'" );
7054
7258
    }
7055
7259
    if ( ! defined $set_not_exists ) { $set_not_exists = 0; }
7056
7260
    rdb_one_rule( $rule, 
7057
7261
                  sub{
7058
7262
                      if (! exists ${$PHsource}{$new_file} ) {
7059
 
                          if ( $set_not_exists ) {
 
7263
                          if ( $set_not_exists ) {
7060
7264
                              ${$PHsource}{$new_file} = [0, -1, 0, '', 0];
7061
 
                          }
7062
 
                          else {
 
7265
                          }
 
7266
                          else {
7063
7267
                              ${$PHsource}{$new_file} 
7064
7268
                              = [fdb_get($new_file, $$Prun_time), '', 0];
7065
 
                          }
7066
 
                      }
7067
 
                  }
 
7269
                          }
 
7270
                      }
 
7271
                  }
7068
7272
    );
7069
7273
    if (defined $new_from_rule ) {
7070
 
        rdb_for_one_file( $rule, $new_file, sub{ $$Pfrom_rule = $new_from_rule; });
 
7274
        rdb_for_one_file( $rule, $new_file, sub{ $$Pfrom_rule = $new_from_rule; });
7071
7275
    }
7072
7276
} #END rdb_ensure_file 
7073
7277
 
7102
7306
    local $exists = 0;
7103
7307
    rdb_one_rule( $rule, 
7104
7308
                  sub{ $exists =  exists( ${$PHsource}{$file} ) ? 1:0; } 
7105
 
                );
 
7309
                );
7106
7310
    return $exists; 
7107
7311
} #END rdb_file_exists
7108
7312
 
7112
7316
    # Assumes rule context.  Update source files of rule to current state.
7113
7317
    rdb_do_files( 
7114
7318
        sub{
7115
 
            if ( exists $generated_exts_all{ ext_no_period($file) } ) {&rdb_update1;} 
 
7319
            if ( exists $generated_exts_all{ ext_no_period($file) } ) {&rdb_update1;} 
7116
7320
        }
7117
7321
    );
7118
7322
} #END rdb_update_gen_files
7313
7517
    while() {
7314
7518
        /\G\s*/gc;
7315
7519
        if ( /\G$/ ) {
7316
 
            last ITEM;
7317
 
        }
 
7520
            last ITEM;
 
7521
        }
7318
7522
        # Now pos (and \G) is at start of item:
7319
7523
      PART:
7320
7524
        while () {
7321
 
            if (/\G([^\s\"]*)/gc) {
7322
 
                $item .= $1;
7323
 
            }
 
7525
            if (/\G([^\s\"]*)/gc) {
 
7526
                $item .= $1;
 
7527
            }
7324
7528
            if ( /\G\"([^\"]*)\"/gc ) {
7325
7529
                # Match balanced quotes
7326
 
                $item .= $1;
7327
 
                next PART;
7328
 
            }
 
7530
                $item .= $1;
 
7531
                next PART;
 
7532
            }
7329
7533
            elsif ( /\G\"(.*)$/gc ) {
7330
7534
                # Match unbalanced quote
7331
 
                $item .= $1;
 
7535
                $item .= $1;
7332
7536
                warn "====Non-matching quotes in\n    '$_'\n";
7333
 
            }
 
7537
            }
7334
7538
            push @results, $item;
7335
7539
            $item = '';
7336
7540
            last PART;
7337
 
        }
 
7541
        }
7338
7542
    }
7339
7543
    return @results;
7340
7544
} #END parse_quotes
7472
7676
    if ( $ignore_pattern ) {
7473
7677
        while (<$input>) {
7474
7678
            if ( /$ignore_pattern/ ){
7475
 
                $_= '';
7476
 
            }
 
7679
                $_= '';
 
7680
            }
7477
7681
            $md5->add($_);
7478
7682
        }
7479
7683
    }
7567
7771
    if ($suffix eq '.bib') { $file =~ s/\.bib$//; }
7568
7772
    my ($tmp_file, $find_retcode) = &find_file1( "$file$suffix", $ref_search );
7569
7773
    if ($tmp_file)  {
7570
 
        push @return_list, $tmp_file;
 
7774
        push @return_list, $tmp_file;
7571
7775
    }
7572
7776
    if ( $find_retcode != 0 ) {
7573
7777
        push @not_found, $file.$suffix;
7587
7791
    }
7588
7792
    else {
7589
7793
        foreach (@_) {
7590
 
            if (-e $_ && ! rename $_, "$del_dir/$_" ) {
 
7794
            if (-e $_ && ! rename $_, "$del_dir/$_" ) {
7591
7795
                warn "$My_name:Cannot move '$_' to '$del_dir/$_'\n";
7592
 
            }
 
7796
            }
7593
7797
        }
7594
7798
    }
7595
7799
}
7607
7811
    foreach (@args) {
7608
7812
        if ( ! /^-/ ) {
7609
7813
            $_ = "\"$_\"";
7610
 
        }
 
7814
        }
7611
7815
    }
7612
7816
    foreach ($cmd) {
7613
7817
        s/%[RBTDO]//g;
7618
7822
    open $fh, "$cmd|"
7619
7823
        or die "Cannot open pipe for \"$cmd\"\n";
7620
7824
    while ( <$fh> ) {
7621
 
        s/^\s*//;
 
7825
        s/^\s*//;
7622
7826
        s/\s*$//;
7623
7827
        push @found, $_;
7624
7828
    }
7646
7850
    while ($i <= $#cus_dep_list) {
7647
7851
        # Use \Q and \E round directory name in regex to avoid interpretation
7648
7852
        #   of metacharacters in directory name:
7649
 
        if ( $cus_dep_list[$i] =~ /^\Q$from_ext $to_ext \E/ ) {
7650
 
            splice @cus_dep_list, $i, 1;
7651
 
        }
7652
 
        else {
7653
 
            $i++;
7654
 
        }
 
7853
        if ( $cus_dep_list[$i] =~ /^\Q$from_ext $to_ext \E/ ) {
 
7854
            splice @cus_dep_list, $i, 1;
 
7855
        }
 
7856
        else {
 
7857
            $i++;
 
7858
        }
7655
7859
    }
7656
7860
}
7657
7861
 
7663
7867
 
7664
7868
####################################################
7665
7869
 
 
7870
sub add_aux_hook {
 
7871
    # Usage: add_aux_hook( sub_name )
 
7872
    # Add the name subroutine to the array of hooks for
 
7873
    # processing lines of aux files.
 
7874
    # The argument is either a string naming the subroutine, e.g.
 
7875
    #     add_aux_hook( 'subname' );
 
7876
    # or a Perl reference to the subroutine, e.g.,
 
7877
    #     add_aux_hook( \&subname );
 
7878
    # It is also possible to use an anonymous subroutine, e.g.,
 
7879
    #     add_aux_hook( sub{  code of subroutine... } );
 
7880
    my ($sub_name) = @_;
 
7881
    push @aux_hooks, $sub_name;
 
7882
}
 
7883
 
 
7884
####################################################
 
7885
 
7666
7886
sub add_input_ext {
7667
7887
    # Usage: add_input_ext( rule, ext, ... )
7668
7888
    # Add extension(s) (specified without a leading period) to the 
7725
7945
        = sub 
7726
7946
          { ## Subroutine for use in File::find
7727
7947
            ## Check to see if we have a directory
7728
 
               if (-d) { push @result, $File::Find::name; }
7729
 
          };
 
7948
               if (-d) { push @result, $File::Find::name; }
 
7949
          };
7730
7950
    foreach my $directory (@_) {
7731
7951
        my $recurse = ( $directory =~ m[//$] );
7732
7952
        # Remove all trailing /s, since directory name with trailing /
7734
7954
        $directory =~ s[/+$][];
7735
7955
        # Similarly for MSWin reverse slash
7736
7956
        $directory =~ s[\\+$][];
7737
 
        if ( ! -e $directory ){
 
7957
        if ( ! -e $directory ){
7738
7958
            next;
7739
 
        }
7740
 
        elsif ( $recurse ){
 
7959
        }
 
7960
        elsif ( $recurse ){
7741
7961
            # Recursively search directory
7742
7962
            find( $find_action, $directory );
7743
 
        }
 
7963
        }
7744
7964
        else {
7745
7965
            push @result, $directory;
7746
 
        }
 
7966
        }
7747
7967
    }
7748
7968
    return @result;
7749
7969
}
7759
7979
    my $first = 1;
7760
7980
    while (@_)
7761
7981
    {
7762
 
        $current = shift;
 
7982
        $current = shift;
7763
7983
        if ($first || ($current ne $prev) )
7764
 
        {
 
7984
        {
7765
7985
            push @sort, $current; 
7766
7986
            $prev = $current;
7767
7987
            $first = 0;
7856
8076
    my @list = split( /$separator/, $search_path);
7857
8077
    if ( $search_path =~ /$separator$/ ) {
7858
8078
        # If search path ends in a blank item, the split subroutine
7859
 
        #    won't have picked it up.
 
8079
        #    won't have picked it up.
7860
8080
        # So add it to the list by hand:
7861
8081
        push @list, "";
7862
8082
    }
7886
8106
               or next;
7887
8107
            close(TMP);
7888
8108
            return $tmp_file;
7889
 
         }
 
8109
         }
7890
8110
     }
7891
8111
     die "$My_name.tempfile1: BUG TO ARRIVE HERE\n";
7892
8112
}
7966
8186
#       or the return value of the Perl subroutine.
7967
8187
    my $cmd_line = $_[0];
7968
8188
    if ( $cmd_line eq '' ) {
7969
 
        traceback( "$My_name: Bug OR configuration error\n".
 
8189
        traceback( "$My_name: Bug OR configuration error\n".
7970
8190
                   "   In run of '$rule', attempt to run a null program" );
7971
8191
        return (0, 1);
7972
8192
    }
7976
8196
    while ( $cmd_line =~ s/^start +// ) {
7977
8197
        # But first remove extra starts (which may have been inserted
7978
8198
        # to force a command to be run detached, when the command
7979
 
        # already contained a "start").
 
8199
        # already contained a "start").
7980
8200
        $detach = 1;
7981
8201
    }
7982
8202
    if ( $cmd_line =~ s/^nostart +// ) {
7983
8203
        $detach = 0;
7984
8204
    }
7985
8205
    if ( $cmd_line =~ /^internal\s+([a-zA-Z_]\w*)\s+(.*)$/ ) {
7986
 
        my $routine = $1;
7987
 
        my @args = parse_quotes( $2 );
7988
 
        warn "$My_name: calling $routine( @args )\n";
 
8206
        my $routine = $1;
 
8207
        my @args = parse_quotes( $2 );
 
8208
        warn "$My_name: calling $routine( @args )\n";
7989
8209
        return ( 0, &$routine( @args ) );
7990
8210
    }
 
8211
    elsif ( $cmd_line =~ /^internal\s+([a-zA-Z_]\w*)\s*$/ ) {
 
8212
        my $routine = $1;
 
8213
        warn "$My_name: calling $routine()\n";
 
8214
        return ( 0, &$routine() );
 
8215
    }
7991
8216
    elsif ( $cmd_line =~ /^NONE/ ) {
7992
8217
        warn "$My_name: ",
7993
8218
             "Program not implemented for this version.  Command line:\n";
7994
 
        warn "   '$cmd_line'\n";
 
8219
        warn "   '$cmd_line'\n";
7995
8220
        return (0, 1);
7996
8221
    }
7997
8222
    elsif ($detach) {
8028
8253
    if ( $cmd_line =~ /^NONE / ) {
8029
8254
        warn "$My_name: ",
8030
8255
             "Program not implemented for this version.  Command line:\n";
8031
 
        warn "   '$cmd_line'\n";
 
8256
        warn "   '$cmd_line'\n";
8032
8257
        return (0, 1);
8033
8258
    }
8034
8259
 
8045
8270
        ## warn "Run_Detached.UNIX: B pid=$pid\n";
8046
8271
        if ( ! defined $pid ) {
8047
8272
            ## warn "Run_Detached.UNIX: C\n";
8048
 
            warn "$My_name: Could not fork to run the following command:\n";
 
8273
            warn "$My_name: Could not fork to run the following command:\n";
8049
8274
            warn "   '$cmd_line'\n";
8050
8275
            return (0, 1);
8051
 
        }
 
8276
        }
8052
8277
        elsif( $pid == 0 ){
8053
8278
           ## warn "Run_Detached.UNIX: D\n";
8054
8279
           # Forked child process arrives here
8097
8322
 
8098
8323
    shift(@ps_output);  # Discard the header line from ps
8099
8324
    foreach (@ps_output)   {
8100
 
        next unless ( /$looking_for/ ) ;
 
8325
        next unless ( /$looking_for/ ) ;
8101
8326
        my @ps_line = split ('\s+');
8102
8327
# OLD       return($ps_line[$pid_position]);
8103
8328
        push @found, $ps_line[$pid_position];
8134
8359
        chomp $Win_cwd;
8135
8360
        if ( $Win_cwd ) {
8136
8361
            $cwd = $Win_cwd;
8137
 
        }
 
8362
        }
8138
8363
        else {
8139
8364
            warn "$My_name: Could not correctly run command\n",
8140
8365
                 "      '$cmd'\n",
8142
8367
                 "     '$cwd'\n",
8143
8368
                 "  The result was\n",
8144
8369
                 "     'Win_cwd'\n";
8145
 
        }
 
8370
        }
8146
8371
    }
8147
8372
    $cache{cwd} = $cwd;
8148
8373
}  # END cache_good_cwd