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