ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/JSOC/moreconfigure.pl
Revision: 1.11
Committed: Wed Jan 19 20:40:37 2011 UTC (12 years, 8 months ago) by arta
Content type: text/plain
Branch: MAIN
Changes since 1.10: +106 -62 lines
Log Message:
Make the compiler autoconfiguration configurable - it can be turned off so that only manual configuration occurs.

File Contents

# Content
1 #!/usr/bin/perl -w
2
3 # Determine which compilers are installed; then set make variables to indicate that
4 # Also, set DEFAULT values for Stanford-specific (if running at Stanford) make variables.
5 # To override the DEFAULT Stanford values, create a config.local file.
6
7 use constant ICCMAJOR => 9;
8 use constant ICCMINOR => 0;
9 use constant IFORTMAJOR => 9;
10 use constant IFORTMINOR => 0;
11 use constant GCCMAJOR => 3;
12 use constant GCCMINOR => 0;
13 use constant GFORTMAJOR => 4;
14 use constant GFORTMINOR => 2;
15
16 my($arg);
17 my($pos);
18 my($outdir);
19 my($outfile);
20 my($customdefsfile);
21 my($major);
22 my($minor);
23 my($hasicc);
24 my($hasifort);
25 my($hasgcc);
26 my($hasgfort);
27 my($skipautocomp);
28 my($line);
29
30 while ($arg = shift(@ARGV))
31 {
32 if (($pos = index($arg, "-d", 0)) == 0)
33 {
34 $outdir = substr($arg, 2);
35 }
36 elsif (($pos = index($arg, "-f", 0)) == 0)
37 {
38 $outfile = substr($arg, 2);
39 }
40 elsif (($pos = index($arg, "-c", 0)) == 0)
41 {
42 $customdefsfile = substr($arg, 2);
43 }
44 }
45
46 $outfile = "$outdir/$outfile";
47
48 $hasicc = 0;
49 $hasifort = 0;
50 $hasgcc = 0;
51 $hasgfort = 0;
52 $skipautocomp = 0;
53
54 if (defined($outdir) && defined($outfile))
55 {
56 # Check to see if user does not want to auto-configure compiler make variables
57 # Read the file containing the defs (right now, customizeddefs.h for Stanford,
58 # localization.h for non-Stanford).
59 if (defined($customdefsfile) && -e $customdefsfile)
60 {
61 if (open(DEFSFILE, "<$customdefsfile"))
62 {
63 my($doautocomp) = 0;
64
65 while (defined($line = <DEFSFILE>))
66 {
67 if ($line =~ /AUTOSELCOMP\s+(.+)/)
68 {
69 $doautocomp = $1;
70 $skipautocomp = !$doautocomp;
71 last;
72 }
73 }
74
75 close(DEFSFILE);
76 }
77 }
78
79 if (!$skipautocomp)
80 {
81 # Try icc
82 $ans = `icc -V 2>&1`;
83
84 if (defined($ans) && $ans =~ /Version\s+(\d+)\.(\d+)/)
85 {
86 $major = $1;
87 $minor = $2;
88
89 if (IsVersion($major, $minor, ICCMAJOR, ICCMINOR))
90 {
91 $hasicc = 1;
92 }
93 }
94
95 # Try gcc
96 if (!$hasicc)
97 {
98 $ans = `gcc -v 2>&1`;
99 if (defined($ans) && $ans =~ /gcc\s+version\s+(\d+)\.(\d+)/)
100 {
101 $major = $1;
102 $minor = $2;
103
104 if (IsVersion($major, $minor, GCCMAJOR, GCCMINOR))
105 {
106 $hasgcc = 1;
107 }
108 }
109 }
110
111 # Try ifort
112 $ans = `ifort -V 2>&1`;
113 if (defined($ans) && $ans =~ /Version\s+(\d+)\.(\d+)/)
114 {
115 $major = $1;
116 $minor = $2;
117
118 if (IsVersion($major, $minor, IFORTMAJOR, IFORTMINOR))
119 {
120 $hasifort = 1;
121 }
122 }
123
124 # Try gfortran
125 if (!$hasifort)
126 {
127 $ans = `gfortran -v 2>&1`;
128 if (defined($ans) && $ans =~ /gcc\s+version\s+(\d+)\.(\d+)/)
129 {
130 $major = $1;
131 $minor = $2;
132
133 if (IsVersion($major, $minor, GFORTMAJOR, GFORTMINOR))
134 {
135 $hasgfort = 1;
136 }
137 }
138 }
139 }
140
141 open(OUTFILE, ">>$outfile") || die "Couldn't open file $outfile for writing.\n";
142
143 # Error messages
144 if (!$skipautocomp)
145 {
146 if (!$hasicc && !$hasgcc)
147 {
148 print "Fatal error: Acceptable C compiler not found! You will be unable to build the DRMS library.\n";
149 }
150 elsif ($hasicc)
151 {
152 print OUTFILE "COMPILER = icc\n";
153 }
154 else
155 {
156 print OUTFILE "COMPILER = gcc\n";
157 }
158
159 if (!$hasifort && !$hasgfort)
160 {
161 print "Warning: Acceptable Fortran compiler not found! Fortran interface will not be built, and you will be unable to build Fortran modules.\n";
162 }
163 elsif ($hasifort)
164 {
165 print OUTFILE "FCOMPILER = ifort\n";
166 }
167 else
168 {
169 print OUTFILE "FCOMPILER = gfortran\n";
170 }
171 }
172
173 # Print out env var override logic - otherwise we lose this logic in make_basic.mk
174 # as the include of custom.mk comes after this logic in make_basic.mk
175 print OUTFILE "ifneq (\$(JSOC_COMPILER),)\n COMPILER = \$(JSOC_COMPILER)\nendif\n";
176 print OUTFILE "ifneq (\$(JSOC_FCOMPILER),)\n FCOMPILER = \$(JSOC_FCOMPILER)\nendif\n\n";
177
178 # Set DEFAULT values for Stanford-specific (if running at Stanford) make variables.
179 if (-e "suflag.txt")
180 {
181 my($line);
182
183 if (open(SUFLAG, "<suflag.txt"))
184 {
185 while (defined($line = <SUFLAG>))
186 {
187 chomp($line);
188 if ($line !~ /^#/ && $line =~ /\S+/)
189 {
190 print OUTFILE "$line\n";
191 }
192 }
193
194 close(SUFLAG);
195 }
196 }
197
198 close(OUTFILE);
199 }
200
201 sub IsVersion
202 {
203 my($maj1) = $_[0];
204 my($min1) = $_[1];
205 my($maj2) = $_[2];
206 my($min2) = $_[3];
207
208 my($res) = 0;
209
210 if ($maj1 > $maj2 || ($maj1 == $maj2 && $min1 >= $min2))
211 {
212 $res = 1;
213 }
214
215 return $res;
216 }