summaryrefslogtreecommitdiff
path: root/lib/sbin/configure.pl
blob: 87193dc4f508fc1541c5665ee333debfa9c3f62f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/perl
#/*@@
#  @file      configure.pl
#  @date      Fri Jan  8 15:06:22 1999
#  @author    Tom Goodale
#  @desc 
#  Prototype configure script for the CCTK
#  @enddesc 
#@@*/

$tmphome = shift(@ARGV);

print "Determining number of fortran underscores...\n";

# Create a test file
open(OUT, ">fname_test.f") || die "Cannot open fname_test.f\n";

print OUT <<EOT;
      subroutine test_name(a)
      integer a
      a = 1
      return
      end

EOT

close OUT;

# Compile the test file
system("f90 -c fname_test.f");

$retcode = $? >> 8;

if($retcode > 0)
{
    print "Failed to compile fname_test.f\n";
}


# Search the object file for the appropriate symbols
open(IN, "<fname_test.o") || die "Cannot open fname_test.o\n";

while(<IN>)
{
    $line = $_;
    if($line =~ m:(TEST_NAME)(_*):i)
    {
	$name = $1;
	$underscores = $2;

	if($name =~ m:TEST_NAME:)
	{
	    print "Uppercase - ";
	    $case = 1;
	}
	if($name =~ m:test_name:)
	{
	    print "Lowercase - ";
	    $case = 0;
	}
	if($underscores eq "")
	{
	    print " No trailing underscore\n";
	    $n_underscores = 0;
	}
	if($underscores eq "_")
	{
	    print "One trailing underscore\n";
	    $n_underscores = 1;
	}
	if($underscores eq "__")
	{
	    print "Two trailing underscores\n";
	    $n_underscores = 2;
	}
    }
    
}

close IN;

# Delete the temporary files
unlink <fname_test.*>;

# Determine the case and number of underscores
if($n_underscores == 0)
{
    $normal_suffix = "";
    $underscore_suffix = "";
}

if($n_underscores == 1)
{
    $normal_suffix = "_";
    $underscore_suffix = "_";
}

if($n_underscores == 2)
{
    $normal_suffix = "_";
    $underscore_suffix = "__";
}

if($case = 0)
{
    $case_prefix = "\\L";
}
if($case = 1)
{
    $case_prefix = "\\L";
}


# Create the perl module to map the fortran names.
open(OUT, ">$tmphome/fortran_name.pl") || die "Cannot create fortran_name.pl\n";
print OUT <<EOT;
#!/bin/perl

sub fortran_name
{
    local(\$old_name) = \@_;
    local(\$new_name);

    \$new_name = "$case_prefix\$old_name\\E";

    if(\$new_name =~ m:_: ) 
    {
	\$new_name = \$new_name."$underscore_suffix";
    }
    else
    {
	\$new_name = \$new_name."$normal_suffix";
    }

    return \$new_name;
}

1;
    
EOT

close OUT;