92500a3a1a2fd6aefad7a1e5001ba32168694a1a
[ghc-hetmet.git] / ghc / utils / mkdependHS / mkdependHS.prl
1 #
2 # perl script expect the following variables to be prepended:
3 #
4 #  RAWCPP TMPDIR TOP_PWD
5 #  libdir libexecdir datadir INSTALLING
6 #  ProjectVersionInt SED 
7 #
8 # tries to work like mkdependC - capable of dealing with:
9 #
10 #  -literate Haskell code (Bird tracks or Glasgow literate style) (.lhs)
11 #  -straight Haskell source (.hs)
12 #  -literate or straight Happy specs    (.ly)
13 #  
14 # ToDo: strip out all the .h junk
15 #
16 ($Pgm = $0) =~ s/.*\/([^\/]+)$/\1/;
17 $Usage  = <<EOUSAGE;
18 Usage: $Pgm [mkdependHS options] [-- GHC options --] srcfile1 [srcfile2 ...]
19
20 Options recognised wherever they occur (mkdependHS or GHC):
21
22     -D<blah>    A cpp #define; usual meaning
23     -i<dirs>    Add <dirs> (colon-separated) to list of directories
24                 to search for "import"ed modules
25     -I<dir>     Add <dir> to list of directories to search for
26                 .h files (i.e., usual meaning)
27     -syslib <blah> This program uses this GHC system library; take
28                 appropriate action (e.g., recognise when they are
29                 "import"ing a module from that library).
30
31 mkdependHS-specific options (not between --'s):
32
33     -v          Be verbose.
34     -v -v       Be very verbose.
35     -w          No warnings
36     -f blah     Use "blah" as the makefile, rather than "makefile"
37                 or "Makefile".
38     -cpp        Wash the input files through cpp(1).
39     -o <osuf>   Use <osuf> as the "object file" suffix ( default: o)
40     -s <suf>    Make extra dependencies for files with
41                 suffix <suf><osuf>; thus, "-o hc -s _a" will
42                 make dependencies both for .hc files and for .a_hc
43                 files.  (Useful in conjunction with NoFib "ways".)
44     --exclude-module=<file> 
45                 Regard <file> as "stable"; i.e., eXclude it from having
46                 dependencies on it.
47     -x          same as --exclude-module
48     --exclude-directory=<dirs> 
49                 Regard : separated list of directories as containing stable,
50                 don't generate any dependencies on modules therein.
51     -Xdirs      same as --exclude-directory
52     --include-prelude
53                 Regard prelude libraries as unstable, i.e., generate dependencies
54                 on prelude modules. This option is normally only used by the
55                 various system libraries. If a -syslib option is used, dependencies
56                 will also be generated on the library's interfaces.
57     --include-module=<file> 
58                 Regard <file> as not "stable"; i.e., generate dependencies
59                 on it (if any). This option is normally used in conjunction 
60                 with the --exclude-directory option.
61
62 EOUSAGE
63
64 $Status     = 0; # just used for exit() status
65 $Verbose    = 0; # 1 => verbose, 2 => very verbose
66 $Warnings   = 1; # 1 => warn about duplicate interface files
67 $Dashdashes_seen = 0;
68
69 $Cpp = ${RAWCPP};
70 $Cpp_flag_set = 0; # 1 => run cpp over input files.
71
72 if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
73     $Tmp_prefix = $ENV{'TMPDIR'} . "/mkdependHS$$";
74 } else {
75     $Tmp_prefix ="${TMPDIR}/mkdependHS$$";
76     $ENV{'TMPDIR'} = "${TMPDIR}"; # set the env var as well
77 }
78
79 $TopPwd            = "${TOP_PWD}";
80 $InstLibDirGhc     = "${libdir}";
81 $InstLibExecDirGhc = "${libexecdir}";
82 $InstDataDirGhc    = "${datadir}";
83
84 $Unlit = ($INSTALLING) ? "${InstLibExecDirGhc}/unlit" 
85                        : "${TopPwd}/ghc/utils/unlit/unlit";
86
87 $Begin_magic_str = "# DO NOT DELETE: Beginning of Haskell dependencies\n";
88 $End_magic_str = "# DO NOT DELETE: End of Haskell dependencies\n";
89 @Obj_suffix =  ("o");
90 @File_suffix = ();
91
92 $Import_dirs = '.';
93 %Syslibs = ();
94 %LibIfaces  = ();  # known prelude/syslib ifaces; read from a file
95 %IgnoreMe = ();
96 # directories to considered stable.
97 @Ignore_dirs = ();
98
99 $Include_dirs = '-I.';
100 $Makefile = '';
101 @Src_files = ();
102 $Include_prelude = 0;
103
104 # Delete temp. file if script is halted.
105 sub quit_upon_signal { print STDERR "Deleting $Tmp_prefix.hs .. \n"; unlink "$Tmp_prefix.hs"; }
106 $SIG{'INT'}  = 'quit_upon_signal';
107 $SIG{'QUIT'} = 'quit_upon_signal';
108
109 &mangle_command_line_args();
110
111 if ( $Status ) {
112     print stderr $Usage;
113     exit(1);
114 }
115
116 push(@Defines,
117      ( #OLD: "-D__HASKELL1__=$Haskell_1",
118       "-D__GLASGOW_HASKELL__=$ProjectVersionInt"));
119
120 @Import_dirs  = split(/:/,$Import_dirs);
121 @Include_dirs = split(/\s+/,$Include_dirs); # still has -I's in it
122
123 # set up array of ignored modules
124 local(@dirs) = ($INSTALLING) ? 
125                ("$InstLibDirGhc/imports/std")
126              : ("$TopPwd/ghc/lib/std");
127 if (!$Include_prelude) {
128     push(@Ignore_dirs, @dirs);
129 } else {
130     push(@Import_dirs, @dirs);
131 }
132
133 foreach $lib ( @Syslibs ) {
134     local($dir);
135
136     if ( $lib eq 'win32' && ! $INSTALLING ) {
137       $dir = "${TopPwd}/hslibs/${lib}/src";
138     } else {
139       $dir = ($INSTALLING) ? "${InstLibDirGhc}/imports/${lib}" 
140                            : "${TopPwd}/ghc/lib/${lib}";
141     }
142     if (!$Include_prelude) {
143        push(@Ignore_dirs,$dir);
144     } else {
145        push(@Import_dirs, $dir);
146     }
147 }
148
149
150 # NB: We keep the scalar-variable equivalents to use in error messages
151
152 if ( ! $Makefile && -f 'makefile' ) {
153     $Makefile = 'makefile';
154 } elsif ( ! $Makefile && -f 'Makefile') {
155     $Makefile = 'Makefile';
156 } elsif ( ! $Makefile) {
157     die "$Pgm: no makefile or Makefile found\n";
158 }
159
160 print STDERR "CPP defines=@Defines\n" if $Verbose;
161 print STDERR "Import_dirs=@Import_dirs\n" if $Verbose;
162 print STDERR "Include_dirs=@Include_dirs\n" if $Verbose;
163
164 &preprocess_import_dirs();
165
166 @Depend_lines = ();
167
168 foreach $sf (@Src_files) {
169
170     # just like lit-inputter
171     # except it puts each file through CPP and
172     # a de-commenter (not implemented);
173     # builds up @Depend_lines
174     print STDERR "Here we go for source file: $sf\n" if $Verbose;
175     ($bf = $sf) =~ s/\.l?(hs|y)$//;
176
177     local($str)="";
178     foreach $obj  (@Obj_suffix) {
179         $str .= "$bf.$obj ";
180         foreach $suff (@File_suffix) {
181            $str .= "$bf.${suff}_$obj ";
182         }
183     }
184     push(@Depend_lines, "$str: $sf\n");
185     # if it's a literate file, .lhs or .ly? (happy specs), then we de-literatize it: 
186     if ( $sf !~ /\.l(hs|y)$/ ) {
187         $file_to_read = $sf;
188     } else {
189         $file_to_read = "$Tmp_prefix.hs";
190         local($to_do) = "$Unlit $sf $file_to_read";
191         &run_something($to_do, $sf, 'unlit');
192     }
193     &slurp_file_for_imports($file_to_read, $sf);
194
195     # Delete the temporary.
196     if ( $sf =~ /\.l(hs|y)$/ ) {
197         unlink "$Tmp_prefix.hs";
198     }
199 }
200
201
202 #
203 # Create backup version of output file.
204
205 if ( ! -f $Makefile ) {
206    # truncate() may not be implemented, so we
207    # play it safe here.
208    local(*TRUNC);
209    open(TRUNC,"> $Makefile.bak") && close(TRUNC);
210 } else {
211    rename($Makefile,"$Makefile.bak");
212 }
213 # now copy Makefile.bak into Makefile, rm'ing old dependencies
214 # and adding the new
215 open(OMKF,"< $Makefile.bak") || die "$Pgm: can't open $Makefile.bak: $!\n";
216 open(NMKF,"> $Makefile") || die "$Pgm: can't open $Makefile: $!\n";
217 select(NMKF);
218 $_ = <OMKF>;
219 while ($_ && $_ ne $Begin_magic_str) { # copy through, 'til Begin_magic_str
220     print $_;
221     $_ = <OMKF>;
222 }
223 while ($_ && $_ ne $End_magic_str) { # delete 'til End_magic_str
224     $_ = <OMKF>;
225 }
226 # insert dependencies
227 print "\n$Begin_magic_str", @Depend_lines, $End_magic_str || die "Failed to write out dependencies ($!)";
228
229 while (<OMKF>) { # copy the rest through
230     print $_ || die "Failed to write out dependencies ($!)";
231 }
232 close(NMKF) || exit(1);
233 close(OMKF) || exit(1);
234 exit 0;
235
236 sub mangle_command_line_args {
237     while($_ = $ARGV[0]) {
238         shift(@ARGV);
239
240         if ( /^--$/ ) {
241             $Dashdashes_seen++;
242
243         } elsif ( /^-D(.*)/ ) { # recognized wherever they occur
244             push(@Defines, $_);
245         } elsif ( /^-cpp$/ ) { # recognized wherever they occur
246             $Cpp_flag_set =1; 
247         } elsif ( /^-i$/ ) {
248             $Import_dirs = ''; # import path cleared!
249         } elsif ( /^-i(.*)/ ) {
250             $Import_dirs = "$1:$Import_dirs";
251         } elsif ( /^-I/ ) {
252             $Include_dirs .= " $_";
253         } elsif ( /^-syslib$/ ) {
254             push(@Syslibs, &grab_arg_arg($_,''));
255         } elsif ( /^-fglasgow-exts$/ ) {
256             push(@Syslibs, 'exts');
257         } elsif ( /^-concurrent$/ ) {
258             push(@Syslibs, 'concurrent');
259         } elsif ($Dashdashes_seen != 1) { # not between -- ... --
260             if ( /^-v$/ ) {
261                 $Verbose++;
262             } elsif ( /^-w$/ ) {
263                 $Warnings     = 0;
264             } elsif ( /^-f(.*)/ ) {
265                 $Makefile       = &grab_arg_arg('-f',$1);
266             } elsif ( /^-o(.*)/ ) {
267                 local($suff)    = &grab_arg_arg('-o',$1);
268                 # Weed out existing entry .. there must be a better way of doing this
269                 # with arrays (non-assoc) ! -- sof
270                 @Obj_suffix     = grep(!/$suff/,@Obj_suffix);
271                 push(@Obj_suffix, $suff);
272             #
273             # --exclude-module=mod => it's stable, trust me!
274             
275             } elsif ( /^-(x|-exclude-module=)(.*)/ ) { 
276                 local($thing) = &grab_arg_arg($1,$2);
277                 $IgnoreMe{$thing} = 'Y';
278             } elsif ( /^-(X|-exclude-directory=)(.*)/ ) { 
279                 foreach $d ( split(/:/,&grab_arg_arg($1, $2)) ) {
280                    push(@Ignore_dirs,"$d");
281                 }
282             } elsif ( /^--include-module=(.*)/ ) { 
283                 local($thing) = &grab_arg_arg($1,$2);
284                 $IgnoreMe{$thing} = 'n';
285             } elsif ( /^--include-prelude$/ ) { 
286                 $Include_prelude = 1;
287             } elsif ( /^-s(.*)/ ) {
288                 local($suff)    =  &grab_arg_arg('-s',$1);
289                 push(@File_suffix, $suff);
290             } elsif ( /^-/ ) {
291                 print STDERR "$Pgm: unknown option ignored: $_\n";
292                 $Status++;
293             } else {
294                 push(@Src_files, $_);
295             }
296         }
297         # Removed support for picking up plausible source file 
298         # names inside the ghc options chunk of the command
299         # line. It failed to deal with `option-value' stuff present
300         # on some invocations of ghc (e.g., "-ohi foo.baz").
301         #  -- sof 12/97
302         #
303         # } elsif ($Dashdashes_seen == 1) {
304         #     push(@Src_files, $_) if ! /^-/;
305         # }
306     }
307     @File_suffix = sort (@File_suffix);
308 }
309
310 sub grab_arg_arg {
311     local($option, $rest_of_arg) = @_;
312     
313     if ($rest_of_arg) {
314         return($rest_of_arg);
315     } elsif ($#ARGV >= 0) {
316         local($temp) = $ARGV[0]; shift(@ARGV); 
317         return($temp);
318     } else {
319         print STDERR "$Pgm: no argument following $option option\n";
320         $Status++;
321     }
322 }
323
324 sub preprocess_import_dirs {
325     # it's probably cheaper to find out what's in all
326     # the @Import_dirs before we start processing.
327     local($d, $thing);
328     local($_);
329     %ModuleIn = ();
330
331     foreach $d ( @Import_dirs ) {
332         # Check to see if it can be ignored
333         #print STDERR "Ignore imports from $d\n" if $Verbose && $Ignore_dirs{$d};
334         #next if $Ignore_dirs{$d};
335
336         opendir(DIR, $d) || die "$Pgm: can't open directory $d\n";
337
338         for ($_ = readdir(DIR); $_; $_ = readdir(DIR)) {
339             next unless /(.*)\.hi$/;
340             $thing = $1;
341             if ($ModuleIn{$thing} && $ModuleIn{$thing} ne $d) {
342                 print STDERR "$Pgm: warning: $thing.hi appears in both $ModuleIn{$thing} and $d!\n" if ($Warnings);
343             } else {
344                 $ModuleIn{$thing} = $d;
345             }
346         }
347         closedir(DIR); # No, don't check the error code
348     }
349
350     # Add all the modules
351     # to the IgnoreMe array before we start scanning for imports.
352     foreach $d (@Ignore_dirs) {
353
354         opendir(DIR, $d) || die "$Pgm: can't open directory $d\n";
355
356         for ($_ = readdir(DIR); $_; $_ = readdir(DIR)) {
357             next unless /(.*)\.(hi|l?hs|l?y)$/;
358             #don't tag it twice or overwrite it with a diff. value
359             next if $IgnoreMe{$1};
360             print STDERR "Module $d will be ignored\n" if $Verbose;
361
362             $IgnoreMe{$1} = 'y';
363         }
364         closedir(DIR); # No, don't check the error code
365     }
366 }
367
368 sub slurp_file_for_imports {
369     local($file_to_read, $orig_src_file) = @_;
370     local($follow_file,$read_from_file);
371     local($cleanup)=0;
372
373     local($last_seen_dir) = $orig_src_file;
374     $last_seen_dir =~ s/\/[^\/]+$//; # strip to dir name
375     $last_seen_dir = '.' if ($last_seen_dir eq $orig_src_file);
376
377     local($mod_name) = $orig_src_file;
378
379     $mod_name =~ s/.*\/([^\/]+)$/$1/g;
380     $mod_name =~ s/^([^.]+)\.(.*)$/$1/;
381
382     print STDERR "Warning: processing module $mod_name, which I was supposed to ignore.\n"
383         if ( $IgnoreMe{$mod_name} eq 'Y' && $Warnings );
384
385     &process_dependency('import',0,'Prelude') if ($Include_prelude);
386
387     # we mangle #include's so they will also leave something
388     # behind to indicate the dependency on _them_
389     
390     local ($open_cmd);
391     if ($Cpp_flag_set) {
392 #       $open_cmd = "${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines |";
393        &run_something("${SED} -e '/^# *include/{p;s/^# *include/!include/;};s/'\\''//g;s/\"//g' $file_to_read | $Cpp $Include_dirs -I$last_seen_dir @Defines 2>&1 > ${file_to_read}.i", $orig_src_file, 'cpp');
394        $read_from_file="${file_to_read}.i";
395        $cleanup=1;
396     } else {
397        $read_from_file="${file_to_read}";
398        $open_cmd = $file_to_read;
399     }
400     print STDERR "$open_cmd\n" if $Verbose;
401
402     open(SRCFILE, $read_from_file) || die "$Pgm: Can't open $file_to_read: $!\n";
403
404     while (<SRCFILE>) {
405         #
406         # import {-# SOURCE #-} Foo (bar) generates dependencies on the source file only,
407         # the compiler will deal with the absence of Foo.hi by consulting the
408         # source for Foo directly. (for dealing with recursive modules).
409         #
410         next unless (/^>?\s*(import)(\s+{-#\s*SOURCE\s*#-})?(\s+qualified)?\s+([A-Z][A-Za-z0-9_']*)/ || /^!(include)(\s+)"(\S+)"/);
411         $todo    = $1;
412         $source  = ( $2 ne '') ? 1 : 0;
413         $modname = $4;
414
415         next if $modname eq '';
416         &process_dependency($todo,$source,$modname);
417     }
418     close(SRCFILE) || exit(1);
419     # remove temporary file, if any.
420     if ($cleanup) {
421            # truncate() may not be implemented, so we
422            # play it safe here.
423            local(*TRUNC);
424            open(TRUNC,"> $read_from_file") && close(TRUNC);
425     }
426 }
427
428 #
429 # Handle
430 sub process_dependency {
431   local($todo,$source,$modname) = @_;
432
433   if ($todo eq 'import') {
434     if ( $IgnoreMe{$modname} eq 'Y' ) {
435          # user specifically asked for this module
436          # to be ignored.
437          $follow_file = '__ignore__';
438     } elsif ( $ModuleIn{$modname} ) {
439         $follow_file = "$ModuleIn{$modname}/$modname.hi";
440     } else { # hard way
441         $follow_file =
442           &find_in_Import_dirs($orig_src_file, $modname, $last_seen_dir, $source );
443     }
444   } else {
445         $follow_file
446           = &find_in_Include_dirs($orig_src_file, $modname, $last_seen_dir);
447   }
448
449   if (! $follow_file) { # it didnae find anything
450       die "$orig_src_file: Couldn't handle: $_\n";
451
452   } else { # it found something
453     if ($follow_file ne '__ignore__') {
454         local($int_file) = $follow_file;
455
456         if ( $int_file !~ /\.(l?hs|hi|l?y)$/ ) {
457             local($str) = "";
458             foreach $obj  (@Obj_suffix) {
459                 $str .= "$bf.$obj ";
460                 foreach $suff (@File_suffix) {
461                    $str .= "$bf.${suff}_$obj ";
462                 }
463             }
464             push(@Depend_lines, "$str: $int_file\n");
465         } else {
466             $int_file =~ s/\.l?hs$//;
467             $int_file =~ s/\.l?y$//;
468             $int_file =~ s/\.hi$//;
469             local($source_dep);
470
471             if ( $source ) {
472                 $source_dep = "$int_file.hi-boot";
473             } else {
474                 local($str)="";
475                 foreach $obj (@Obj_suffix) {
476                    $str .= "$bf.$obj ";
477                 }
478                 push(@Depend_lines, "$str: $int_file.hi\n");
479             }
480
481             if ( ! $source ) {
482                foreach $suff  (@File_suffix) {
483                   local($str) = "";
484                   foreach $obj (@Obj_suffix) {
485                     $str .= "$bf.${suff}_$obj ";
486                   }
487                   push(@Depend_lines, "$str: $int_file.${suff}_hi\n");
488                }
489             } else {
490                local($str) = "";
491                foreach $obj  (@Obj_suffix) {
492                    $str .= "$bf.$obj ";
493                    foreach $suff (@File_suffix) {
494                      $str .= "$bf.${suff}_$obj ";
495                    }
496                }
497                push(@Depend_lines, "$str: $source_dep\n");
498             }
499         }
500      }
501    }
502 }
503
504 # when we see something, we cache that fact ('y').
505 # also, when we get a miss, we cache that (so we don't try later); ('n')
506 %FileExists = ();
507
508 sub find_in_Import_dirs {
509     local($orig_src_file, $modname, $last_seen_dir, $source) = @_;
510     local($import_dir);
511     local($do_magical_check) = 0;
512     local($name_to_check);
513
514     # do it the old hard way: hop along Import_dir list
515     foreach $import_dir (@Import_dirs) {
516         # handle . magically
517         if ($import_dir eq '.') {
518             # record that we should do a SPECIAL try for a file in last_seen_dir (LAST)
519             $do_magical_check = 1;
520         }
521
522         $name_to_check = "$import_dir/$modname.hi";
523         if ( $FileExists{$name_to_check} ne 'n' ) { # either 'y' or nothing
524             print STDERR "trying $name_to_check...\n" if $Verbose >= 2; # very verbose
525             return($name_to_check) if $FileExists{$name_to_check} eq 'y';
526             if (-f $name_to_check) {
527                 $FileExists{$name_to_check} = 'y';
528                 return($name_to_check) ;
529             } else {
530                 $FileExists{$name_to_check} = 'n';
531             }
532         }
533
534         for $suff ('hs', 'lhs', 'ly', 'y') {
535             $name_to_check = "$import_dir/$modname.$suff";
536             print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
537             return($name_to_check) if -f $name_to_check;
538         }
539
540         if ( $source ) {
541             $name_to_check = "$import_dir/$modname.hi-boot";
542             print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
543             return($name_to_check) if -f $name_to_check;
544         }               
545     }
546     if ($do_magical_check == 1) {
547         $name_to_check = "$last_seen_dir/$modname.hi";
548
549         if ( $FileExists{$name_to_check} ne 'n' ) { # either 'y' or nothing
550             print STDERR "trying $name_to_check...\n" if $Verbose >= 2; # very verbose
551             return($name_to_check) if $FileExists{$name_to_check} eq 'y';
552             if (-f $name_to_check) {
553                 $FileExists{$name_to_check} = 'y';
554                 return($name_to_check) ;
555             } else {
556                 $FileExists{$name_to_check} = 'n';
557             }
558         }
559
560         for $suff ('lhs', 'hs', 'ly', 'y') {
561             $name_to_check = "$last_seen_dir/$modname.$suff";
562             print STDERR "trying... $name_to_check\n" if $Verbose >= 2; # very verbose
563             return($name_to_check) if -f $name_to_check;
564         }
565     }
566
567     # OK, maybe it's referring to something in a system library
568     #foreach $lib ( @Syslibs ) {
569     #   return('__ignore__') if $LibIfaces{"$lib:$modname"};
570     #}
571
572     # Last hope: referring to a Prelude interface
573     return('__ignore__') if ( $IgnoreMe{$modname} eq 'y' );
574
575     die "No file `$modname.hi', `$modname.lhs', `$modname.hs' (reqd from file `$orig_src_file')\namong import directories:\n\t$Import_dirs\n";
576 }
577
578 sub find_in_Include_dirs {
579     local($orig_src_file, $name, $last_seen_dir) = @_;
580     local($include_dir);
581     local($do_magical_check) = 0;
582
583     # no funny name guessing here
584
585     # hop along Include_dir list
586     foreach $include_dir (@Include_dirs) {
587         $include_dir =~ s/^-I//;
588
589         # handle . magically
590         if ($include_dir eq '.') {
591             # record that we should do a SPECIAL try for a file in last_seen_dir (LAST)
592             $do_magical_check = 1;
593         }
594         print STDERR "trying $include_dir/$name...\n" if $Verbose >= 2; # very verbose
595         if (-f "$include_dir/$name") {
596             return("$include_dir/$name");
597         }
598     }
599     if ($do_magical_check == 1) {
600         print STDERR "trying $last_seen_dir/$name...\n" if $Verbose >= 2; # very verbose
601         if (-f "$last_seen_dir/$name") {
602             return("$last_seen_dir/$name");
603         }
604     }
605     die "No file `$name' (reqd from file `$orig_src_file') among include directories: $Include_dirs\n";
606 }
607
608 # out of the driver, actually
609 sub run_something {
610     local($str_to_do, $file_to_read, $tidy_name) = @_;
611
612     print STDERR "\n$tidy_name:\n\t" if $Verbose;
613     print STDERR "$str_to_do\n" if $Verbose;
614
615     local($return_val) = system($str_to_do) >> 8;
616
617     if ($return_val != 0) {
618         local($die_msg) = "$Pgm: Running $tidy_name ( on $file_to_read ) failed";
619         $die_msg .= " program not found: $str_to_do " if $return_val == 255;
620         $die_msg .= " ($!)" if $Verbose && $! != 0;
621         $die_msg .= "\n";
622         print STDERR $die_msg;
623         exit $return_val;
624     }
625 }