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