[project @ 1997-03-24 04:28:10 by sof]
[ghc-hetmet.git] / ghc / utils / hstags / hstags.prl
1 #
2 # To fully function, this script needs the following variables
3 # set:
4 #
5 #   INSTALLING
6 #   TMPDIR
7 #   TOP_PWD
8 #   libdir
9 #   PROJECTVERSION
10 #   HSP_IMPORTS
11
12 if ( $ENV{'TMPDIR'} ) { # where to make tmp file names
13     $tmp = $ENV{'TMPDIR'} . "/$$.eht";
14 } else {
15     $tmp ="${TMPDIR}/$$.eht";
16     $ENV{'TMPDIR'} = ${TMPDIR}; # set the env var as well
17 }
18
19 $TopPwd         = "${TOP_PWD}"; # *Only* needed when using it in-situ (i.e., INSTALLING=0).
20 $InstLibDirGhc  = "${libdir}";
21
22 $Unlit = ( $INSTALLING ? 
23            "${InstLibDirGhc}/unlit" : 
24            "${TopPwd}/ghc/utils/unlit/unlit" );
25 # but this is re-set to "cat" (after options) if -cpp not seen
26 $HsCpp = ( $INSTALLING ? 
27            "${InstLibDirGhc}/hscpp" : 
28            "${TopPwd}/ghc/utils/hscpp/hscpp" );
29 $HsP   = ( $INSTALLING ? 
30            "${InstLibDirGhc}/hsp" : 
31            "${TopPwd}/ghc/compiler/hsp" );
32 $HsTagsHelp = 
33          ( $INSTALLING ? 
34            "${InstLibDirGhc}/hstags-help" : 
35            "${TopPwd}/ghc/utils/hstags/hstags-help" );
36
37 $Verbose = 0;
38 $Append = '>';
39 $DoCpp = 0;
40 $Cpp_opts = '';
41 $HsP_opts = '';
42 @Files = ();
43
44 while ($ARGV[0] =~ /^-./) {
45     $_ = shift(@ARGV);
46     /^--/               && last;
47     /^-v/               && ($Verbose  =  1, next);
48     /^-a$/              && ($Append   = '>>', next);
49     /^-fglasgow-exts/   && ($HsP_opts .= ' -N', next);
50     /^-optP(.*)/        && ($Cpp_opts .= " $1", next);
51     /^-[UDI]/           && ($Cpp_opts .= " $_", next);
52     /^-cpp/             && ($DoCpp = 1, next);
53     /^-/                && next; # ignore the rest
54     push(@Files, $_);
55 }
56
57 $ghc_version_info = int(${PROJECTVERSION} * 100);
58 $DoHsCpp = ( ! $DoCpp ) ? 'cat'
59                         : "$HsCpp -D__HASKELL1__=2 -D__GLASGOW_HASKELL__=$ghc_version_info $Cpp_opts";
60
61 # to find Prelude.hi and friends.
62 $HsP_opts .= ( $INSTALLING  ? 
63                "-J${InstLibDirGhc}/imports" : 
64                ( '-J' . join(' -J',split(/:/,${HSP_IMPORTS})) ));
65
66 open(STDOUT, "$Append TAGS") || die "can't create TAGS";
67
68 foreach $f ( @ARGV ) {
69     # if file is in a dir && we are CPPing, then we add its dir to the -I list.
70     if ( $DoCpp && $f =~ /(.+)\/[^\/]+$/ ) {
71         $Idir = "-I$1";
72     } else {
73         $Idir = '';
74     }
75
76     if ( $f =~ /\.lhs$/ ) {
77         $ToDo = "$Unlit $f - | $DoHsCpp $Idir | $HsP -E $HsP_opts | $HsTagsHelp $f > $tmp";
78     } else {
79         $ToDo = "$DoHsCpp $Idir < $f | $HsP -E  $HsP_opts | $HsTagsHelp $f > $tmp";
80     }
81     print STDERR "$ToDo\n" if $Verbose;
82     system($ToDo);
83     $return_val = $?;
84     die "Fatal error $return_val\n" if $return_val != 0;
85
86     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
87      $atime,$mtime, $ctime,$blksize,$blocks) = stat("$tmp");
88   
89     print STDOUT "\f\n$f,${size}\n";
90     print STDOUT `cat $tmp`;
91 }
92
93 unlink $tmp;