ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ToolBox.pm
Revision: 1.3
Committed: Wed Mar 3 17:04:14 1999 UTC (26 years, 2 months ago) by williamc
Content type: text/plain
Branch: MAIN
CVS Tags: V0_10_19, V0_10_18, V0_10_17, V0_10_16, V0_10_15, V0_10_14, V0_10_13, V0_10_12, V0_10_11, V0_10_10, V0_10_9, V0_10_8, V0_10_7, V0_10_6, V0_10_5, V0_10_4, V0_10_3, V0_10_2, V0_10_1, V0_10_0, V0_10_0beta, V0_9_42, V0_9_41, V0_9_40, V0_9_39, V0_9_38, V0_9_37, V0_9_36, V0_9_35, V0_9_34, V0_9_33, V0_9_32, V0_9_31, V0_9_30, V0_9_29, V0_9_28, V0_9_27, V0_9_26, V0_9_25, V0_9_24, V0_9_23, V0_9_22, V0_9_21, V0_9_20, V0_9_19, V0_9_18, V0_9_17, V0_9_16, V0_9_15, V0_9_14, V0_9_13, V0_9_12, V0_9_11, V0_9_10, V0_9_9, V0_9_8, V0_9_7, V0_9_6, V0_9_5, V0_9_4, V0_9_3, V0_9_2, V0_9_1, V0_9, V0_8, V0_7, V0_6, V0_5, V0_4, V0_3, V0_2, V0_1
Branch point for: V0_9branch
Changes since 1.2: +1 -1 lines
Log Message:
Updates towardsa release

File Contents

# User Rev Content
1 williamc 1.1 # Toolbox Class to process tool functionality information
2     #
3     #
4    
5     package ToolBox;
6 williamc 1.2 require 5.001;
7 williamc 1.1 require Exporter;
8     @ISA=qw(Exporter);
9     use Carp;
10 williamc 1.2 use Utilities::SCRAMUtils;
11 williamc 1.1
12     # A new toolbox object
13     sub new {
14     $self = {};
15     bless $self;
16     $self->{toolboxfile}=SCRAMUtils::checkfile("$ENV{INTwork}/Toolfile");
17     if ( $self->{toolboxfile} eq "" ) {
18     $self->{toolboxfile}="$ENV{LOCALTOP}/$ENV{INTwork}/Toolfile";
19     }
20     #print "ToolboxFile = ".$self->{toolboxfile}."\n";
21     $self->readtoolfile;
22     $self->typehashdefaults;
23     $self->readtypehash;
24     return $self;
25     }
26    
27     sub readtoolfile {
28     my $self=shift;
29    
30     open ( FILEIN, $self->{toolboxfile} );
31     #or print "Unable to find $self->{toolboxfile} \n";
32     while ( <FILEIN> ) {
33     next if /^\s*$/;
34     next if /^\s*#/;
35     ($out,$in,@functions)=split /:/, $_;
36     ${$self->{toolhash}}{$name}=@functions;
37     }
38     close FILEIN;
39     }
40    
41     # temporary for now
42     sub typehashdefaults {
43     my $self=shift;
44    
45     %{$self->{typehash}}=(
46     '.C' => 'C++Src',
47     '.cc' => 'C++Src',
48     '.cpp' => 'C++Src',
49     '.F' => 'FortranSrc',
50     '.f' => 'FortranSrc'
51     )
52     }
53    
54     sub readtypehash {
55     my $self=shift;
56     my $toolfile="$ENV{INTwork}/filetypes";
57     my $type;
58     my $ext;
59    
60     $toolfile=SCRAMUtils::checkfile($toolfile);
61     open ( FILEIN, $toolfile ) or return;
62     while ( <FILEIN> ) {
63     next if /^\s*$/;
64     next if /^\s*#/;
65     ($ext,$type)=split /:/, $_;
66     ${$self->{typehash}}{$ext}=$type;
67     }
68     close FILEIN;
69     }
70    
71     sub gettool {
72     my $self=shift;
73     my $out=shift;
74     my $in=shift;
75    
76     if ( exists ${$self->{toolhash}}{"$out:$in"}){
77     return ${$self->{toolhash}}{"$out:$in"};
78     }
79     else {
80     # autofinding mechanism not yet implemented
81     carp "ToolBox: Unable to find a tool to convert $in -> $out\n";
82     }
83     }
84    
85     #
86     # return the class of a given file extension
87     #
88     sub getclass {
89     my $self=shift;
90     my $file=shift;
91    
92     chomp $file;
93     foreach $key ( keys %{$self->{typehash}}) {
94     if ( $file=~/$key\Z/ ) {
95     return ${$self->{$typehash}}{$key};
96     }
97     }
98     carp "ToolBox: Unknown File Type $file\n";
99     }
100    
101     #
102     # Make targets for all types that match out, in combination
103     sub maketargets ($output, $input, $target, $deps) {
104     my $self=shift;
105     my $output=shift;
106     my $input=shift;
107     my $target=shift;
108     my $deps=shift;
109     my $tool;
110    
111     my @tools;
112    
113     @tools=$self->gettool($output,$input);
114     foreach $tool ( @tools ) {
115     ($typesstring, $toolname, $toolversion, @rest) = split ":", $tool;
116     $toolline = join '', @rest;
117     @rest=split ';', $toolline;
118     $typesstring=~s/:/_/g;;
119     print GNUmakefile $target."_".$typesstring.": $deps\n";
120     foreach $toolline (@rest) {
121     $toolline=~s/\$outfile/$target/g;
122     $toolline=~s/\$infile/$deps/g;
123     print GNUmakefile "\t$toolline\n";
124     }
125     print "\n";
126     }
127     }
128    
129     sub addtotoolbox {
130     my $self=shift;
131 williamc 1.2 use Utilities::SCRAMUtils;
132 williamc 1.1 my $out=shift;
133     my $in=shift;
134     my $toolkey=shift;
135     my $commandstring =shift;
136     my @types = @_;
137    
138     my $fulltypes=join ';', @types;
139     my $key="$out:$in";
140     my $fullkey=$key.";$fulltypes:$toolkey:";
141     $fullkey=~s/;;*/;/g;
142 williamc 1.3 SCRAMUtils::updatelookup($self->{toolboxfile}, $fullkey, $commandstring);
143 williamc 1.1 }