blob: 8140e110aea816839e19bb66f8e2222c35b5b5e5 [file] [log] [blame]
Jim Cownie5e8470a2013-09-27 10:38:44 +00001#!/usr/bin/perl
2
3#
4#//===----------------------------------------------------------------------===//
5#//
6#// The LLVM Compiler Infrastructure
7#//
8#// This file is dual licensed under the MIT and the University of Illinois Open
9#// Source Licenses. See LICENSE.txt for details.
10#//
11#//===----------------------------------------------------------------------===//
12#
13
14# Pragmas.
15use strict;
16use warnings;
17
18use FindBin;
19use lib "$FindBin::Bin/lib";
20
21# LIBOMP modules.
22use Platform ":vars";
23use tools;
24
25our $VERSION = "0.015";
26
27my $pedantic;
28
29# --------------------------------------------------------------------------------------------------
30# Helper functions
31# --------------------------------------------------------------------------------------------------
32
33
34sub run($\$\$;\$) {
35 my ( $cmd, $stdout, $stderr, $path ) = @_;
36 my ( @path, $rc );
37 @path = which( $cmd->[ 0 ], -all => 1 );
38 if ( @path > 0 ) {
39 if ( @path > 1 and $pedantic ) {
40 warning( "More than one \"$cmd->[ 0 ]\" found in PATH:", map( " $_", @path ) );
41 }; # if
42 debug( "\"$cmd->[ 0 ]\" full path is \"$path[ 0 ]\"." );
43 if ( defined( $path ) ) {
44 $$path = $path[ 0 ];
45 }; # if
46 debug( "Executing command: \"" . join ( " ", @$cmd ) . "\"." );
47 $rc =
48 execute(
49 $cmd,
50 -ignore_signal => 1, -ignore_status => 1,
51 -stdout => $stdout, -stderr => $stderr, -stdin => undef
52 );
53 if ( $rc < 0 ) {
54 warning( "Cannot run \"$cmd->[ 0 ]\": $@" );
55 }; # if
56 debug( "stdout:", $$stdout, "(eof)", "stderr:", $$stderr, "(eof)" );
57 } else {
58 warning( "No \"$cmd->[ 0 ]\" found in PATH." );
59 $rc = -1;
60 }; # if
61 return $rc;
62}; # sub run
63
64
65sub get_arch($$$) {
66 my ( $name, $str, $exps ) = @_;
67 my ( $arch, $count );
68 $count = 0;
69 foreach my $re ( keys( %$exps ) ) {
70 if ( $str =~ $re ) {
71 $arch = $exps->{ $re };
72 ++ $count;
73 }; # if
74 }; # for
75 if ( $count != 1 or not Platform::canon_arch( $arch ) ) {
76 warning( "Cannot detect $name architecture: $str" );
77 return undef;
78 }; # if
79 return $arch;
80}; # sub get_arch
81
82sub encode($) {
83 my ( $str ) = @_;
84 $str =~ s{ }{_}g;
85 return $str;
86}; # sub encode
87
88
89# --------------------------------------------------------------------------------------------------
90# get_xxx_version subroutines.
91# --------------------------------------------------------------------------------------------------
92#
93# Some of get_xxx_version() subroutines accept an argument -- a tool name. For example,
94# get_intel_compiler_version() can report version of C, C++, or Fortran compiler. The tool for
95# report should be specified by argument, for example: get_intel_compiler_version( "ifort" ).
96#
97# get_xxx_version() subroutines returns list of one or two elements:
98# 1. The first element is short tool name (like "gcc", "g++", "icl", etc).
99# 2. The second element is version string.
100# If returned list contain just one element, it means there is a problem with the tool.
101#
102
103sub get_perl_version() {
104 my ( $rc, $stdout, $stderr, $version );
105 my $tool = "perl";
106 my ( @ret ) = ( $tool );
107 $rc = run( [ $tool, "--version" ], $stdout, $stderr );
108 if ( $rc >= 0 ) {
109 # Typical perl output:
110 # This is perl, v5.10.0 built for x86_64-linux-thread-multi
111 # This is perl, v5.8.8 built for MSWin32-x64-multi-thread
112 # This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
113 if ( $stdout !~ m{^This is perl.*v(\d+\.\d+(?:\.\d+)).*built for}m ) {
114 warning( "Cannot parse perl output:", $stdout, "(oef)" );
115 }; # if
116 $version = $1;
117 if ( $target_os eq "win" ) {
118 if ( $stdout !~ m{Binary build (.*) provided by ActiveState } ) {
119 warning( "Perl is not ActiveState one" );
120 }; # if
121 }; # if
122 }; # if
123 push( @ret, $version );
124 return @ret;
125}; # sub get_perl_version
126
127
128sub get_gnu_make_version() {
129 my ( $rc, $stdout, $stderr, $version );
130 my $tool = "make";
131 my ( @ret ) = ( $tool );
132 my ( $path );
133 $rc = run( [ $tool, "--version" ], $stdout, $stderr, $path );
134 if ( $rc >= 0 ) {
135 # Typical make output:
136 # GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
137 # GNU Make 3.81
138 if ( $stdout =~ m{^GNU Make (?:version )?(\d+\.\d+(?:\.\d+)?)(?:,|\s)} ) {
139 $version = $1;
140 }; # if
141 if ( $target_os eq "win" and $stdout =~ m{built for ([a-z0-9-]+)} ) {
142 my $built_for = $1;
143 debug( "GNU Make built for: \"$built_for\"." );
144 if ( $built_for =~ m{cygwin}i ) {
145 warning( "\"$path\" is a Cygwin make, it is *not* suitable." );
146 return @ret;
147 }; # if
148 }; # if
149 }; # if
150 push( @ret, $version );
151 return @ret;
152}; # sub get_gnu_make_version
153
154
155sub get_intel_compiler_version($) {
156 my ( $tool ) = @_; # Tool name, like "icc", "icpc", "icl", or "ifort".
157 my ( @ret ) = ( $tool );
158 my ( $rc, $stdout, $stderr, $tool_re );
159 my $version;
160 my $ic_archs = {
161 qr{32-bit|IA-32} => "32",
162 qr{Intel\(R\) 64} => "32e",
163 qr{Intel\(R\) [M][I][C] Architecture} => "32e",
164 };
165 $tool_re = quotemeta( $tool );
166 $rc = run( [ $tool, ( $target_os eq "win" ? () : ( "-V" ) ) ], $stdout, $stderr );
167 if ( $rc < 0 ) {
168 return @ret;
169 }; # if
170 # Intel compiler version string is in the first line of stderr. Get it.
171 #$stderr =~ m{\A(.*\n?)};
172 # AC: Let's look for version string in the first line which contains "Intel" string.
173 # This allows to use 11.1 and 12.0 compilers on new MAC machines by ignoring
174 # huge number of warnings issued by old compilers.
175 $stderr =~ m{^(Intel.*)$}m;
176 my $vstr = $1;
177 my ( $apl, $ver, $bld, $pkg );
178 if ( 0 ) {
179 } elsif ( $vstr =~ m{^Intel.*?Compiler\s+(.*?),?\s+Version\s+(.*?)\s+Build\s+(\S+)(?:\s+Package ID: (\S+))?} ) {
180 # 9.x, 10.x, 11.0.
181 ( $apl, $ver, $bld, $pkg ) = ( $1, $2, $3, $4 );
182 } elsif ( $vstr =~ m{^Intel's (.*?) Compiler,?\s+Version\s+(.*?)\s+Build\s+(\S+)} ) {
183 # 11.1
184 ( $apl, $ver, $bld ) = ( $1, $2, $3 );
185 } else {
186 warning( "Cannot parse ${tool}'s stderr:", $stderr, "(eof)" );
187 return @ret;
188 }; # if
189 my $ic_arch = get_arch( "Intel compiler", $apl, $ic_archs );
190 if ( not defined( $ic_arch ) ) {
191 return @ret;
192 }; # if
193 if ( Platform::canon_arch( $ic_arch ) ne $target_arch ) {
194 warning( "Target architecture is $target_arch, $tool for $ic_arch found." );
195 return @ret;
196 }; # if
197 # Normalize version.
198 my $stage;
199 $ver =~ s{\s+}{ }g;
200 $ver = lc( $ver );
201 if ( $ver =~ m{\A(\d+\.\d+(?:\.\d+)?) ([a-z]+)\a}i ) {
202 ( $version, $stage ) = ( $1, $2 );
203 } else {
204 ( $version, $stage ) = ( $ver, "" );
205 }; # if
206 # Parse package.
207 if ( defined( $pkg ) ) {
208 if ( $pkg !~ m{\A[lwm]_[a-z]+_[a-z]_(\d+\.\d+\.\d+)\z}i ) {
209 warning( "Cannot parse Intel compiler package: $pkg" );
210 return @ret;
211 }; # if
212 $pkg = $1;
213 $version = $pkg;
214 }; # if
215 push( @ret, "$version " . ( $stage ? "$stage " : "" ) . "($bld) for $ic_arch" );
216 # Ok, version of Intel compiler found successfully. Now look at config file.
217 # Installer of Intel compiler tends to add a path to MS linker into compiler config file.
218 # It leads to troubles. For example, all the environment set up for MS VS 2005, but Intel
219 # compiler uses lnker from MS VS 2003 because it is specified in config file.
220 # To avoid such troubles, make sure:
221 # ICLCFG/IFORTCFG environment variable exists or
222 # compiler config file does not exist, or
223 # compiler config file does not specify linker.
224 if ( $target_os eq "win" ) {
225 if ( not exists( $ENV{ uc( $tool . "cfg" ) } ) ) {
226 # If ICLCFG/IFORTCFG environment varianle exists, everything is ok.
227 # Otherwise check compiler's config file.
228 my $path = which( $tool );
229 $path =~ s{\.exe\z}{}i; # Drop ".exe" suffix.
230 $path .= ".cfg"; # And add ".cfg" one.
231 if ( -f $path ) {
232 # If no config file exists, it is ok.
233 # Otherwise analyze its content.
234 my $bulk = read_file( $path );
235 $bulk =~ s{#.*\n}{}g; # Remove comments.
236 my @options = ( "Qvc", "Qlocation,link," );
237 foreach my $opt ( @options ) {
238 if ( $bulk =~ m{[-/]$opt} ) {
239 warning( "Compiler config file \"$path\" contains \"-$opt\" option." );
240 }; # if
241 }; # foreach
242 }; # if
243 }; # if
244 }; # if
245 return @ret;
246}; # sub get_intel_compiler_version
247
248
249sub get_gnu_compiler_version($) {
250 my ( $tool ) = @_;
251 my ( @ret ) = ( $tool );
252 my ( $rc, $stdout, $stderr, $version );
253 $rc = run( [ $tool, "--version" ], $stdout, $stderr );
254 if ( $rc >= 0 ) {
255 my ( $ver, $bld );
256 if ( $target_os eq "mac" ) {
257 # i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
258 # i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5484)
259 # i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
260 $stdout =~ m{^.*? \(GCC\) (\d+\.\d+\.\d+) \(.*Apple.*?Inc\. build (\d+)\)}m;
261 ( $ver, $bld ) = ( $1, $2 );
262 } else {
263 if ( 0 ) {
264 } elsif ( $stdout =~ m{^.*? \(GCC\) (\d+\.\d+\.\d+)(?: (\d+))?}m ) {
265 # g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
266 # GNU Fortran (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)
267 ( $ver, $bld ) = ( $1, $2 );
268 } elsif ( $stdout =~ m{^.*? \(SUSE Linux\) (\d+\.\d+\.\d+)\s+\[.*? (\d+)\]}m ) {
269 # gcc (SUSE Linux) 4.3.2 [gcc-4_3-branch revision 141291]
270 ( $ver, $bld ) = ( $1, $2 );
271 } elsif ( $stdout =~ m{^.*? \((Debian|Ubuntu).*?\) (\d+\.\d+\.\d+)}m ) {
272 # gcc (Debian 4.7.2-22) 4.7.2
273 # Debian support from Sylvestre Ledru
274 # Thanks!
275 $ver = $2;
276 }; # if
277 }; # if
278 if ( defined( $ver ) ) {
279 $version = $ver . ( defined( $bld ) ? " ($bld)" : "" );
280 } else {
281 warning( "Cannot parse GNU compiler version:", $stdout, "(eof)" );
282 }; # if
283 }; # if
284 push( @ret, $version );
285 return @ret;
286}; # sub get_gnu_compiler_version
287
288
289sub get_ms_compiler_version() {
290 my ( $rc, $stdout, $stderr, $version );
291 my $tool = "cl";
292 my ( @ret ) = ( $tool );
293 my $mc_archs = {
294 qr{80x86} => "IA-32 architecture",
295 qr{AMD64|x64} => "Intel(R) 64",
296 };
297 $rc = run( [ $tool ], $stdout, $stderr );
298 if ( $rc < 0 ) {
299 return @ret;
300 }; # if
301 if ( $stderr !~ m{^Microsoft .* Compiler Version (.*?) for (.*)\s*$}m ) {
302 warning( "Cannot parse MS compiler output:", $stderr, "(eof)" );
303 return @ret;
304 }; # if
305 my ( $ver, $apl ) = ( $1, $2 );
306 if ( $ver !~ m{\A\d+(?:\.\d+)+\z} ) {
307 warning( "Cannot parse MS compiler version: $ver" );
308 return @ret;
309 }; # if
310 my $mc_arch = get_arch( "MS compiler", $apl, $mc_archs );
311 if ( not defined( $mc_arch ) ) {
312 return @ret;
313 }; # if
314 if ( Platform::canon_arch( $mc_arch ) ne $target_arch ) {
315 warning( "Target architecture is $target_arch, $tool for $mc_arch found" );
316 return @ret;
317 }; # if
318 $version = "$ver for $target_arch";
319 push( @ret, $version );
320 return @ret;
321}; # sub get_ms_compiler_version
322
323
324sub get_ms_linker_version() {
325 my ( $rc, $stdout, $stderr, $version );
326 my $tool = "link";
327 my ( @ret ) = ( $tool );
328 my ( $path );
329 $rc = run( [ $tool ], $stdout, $stderr, $path );
330 if ( $rc < 0 ) {
331 return @ret;
332 }; # if
333 if ( $stdout !~ m{^Microsoft \(R\) Incremental Linker Version (\d+(?:\.\d+)+)\s*$}m ) {
334 warning( "Cannot parse MS linker output:", $stdout, "(eof)" );
335 if ( $stderr =~ m{^link: missing operand} ) {
336 warning( "Seems \"$path\" is a Unix-like \"link\" program, not MS linker." );
337 }; # if
338 return @ret;
339 }; # if
340 $version = ( $1 );
341 push( @ret, $version );
342 return @ret;
343}; # sub get_ms_linker_version
344
345
346# --------------------------------------------------------------------------------------------------
347# "main" program.
348# --------------------------------------------------------------------------------------------------
349
350my $make;
351my $intel = 1; # Check Intel compilers.
352my $gnu_fortran = 0; # Check GNU Fortran.
353my $intel_compilers = {
354 "lin" => { c => "icc", cpp => "icpc", f => "ifort" },
355 "lrb" => { c => "icc", cpp => "icpc", f => "ifort" },
356 "mac" => { c => "icc", cpp => "icpc", f => "ifort" },
357 "win" => { c => "icl", cpp => undef, f => "ifort" },
358};
359
360get_options(
361 Platform::target_options(),
362 "intel!" => \$intel,
363 "gnu-fortran!" => \$gnu_fortran,
364 "make" => \$make,
365 "pedantic" => \$pedantic,
366);
367
368my @versions;
369push( @versions, [ "Perl", get_perl_version() ] );
370push( @versions, [ "GNU Make", get_gnu_make_version() ] );
371if ( $intel ) {
372 my $ic = $intel_compilers->{ $target_os };
373 push( @versions, [ "Intel C Compiler", get_intel_compiler_version( $ic->{ c } ) ] );
374 if ( defined( $ic->{ cpp } ) ) {
375 # If Intel C++ compiler has a name different from C compiler, check it as well.
376 push( @versions, [ "Intel C++ Compiler", get_intel_compiler_version( $ic->{ cpp } ) ] );
377 }; # if
378 if ( defined( $ic->{ f } ) ) {
379 push( @versions, [ "Intel Fortran Compiler", get_intel_compiler_version( $ic->{ f } ) ] );
380 }; # if
381}; # if
382if ( $target_os eq "lin" or $target_os eq "mac" ) {
383 push( @versions, [ "GNU C Compiler", get_gnu_compiler_version( "gcc" ) ] );
384 push( @versions, [ "GNU C++ Compiler", get_gnu_compiler_version( "g++" ) ] );
385 if ( $gnu_fortran ) {
386 push( @versions, [ "GNU Fortran Compiler", get_gnu_compiler_version( "gfortran" ) ] );
387 }; # if
388}; # if
389if ( $target_os eq "win" ) {
390 push( @versions, [ "MS C/C++ Compiler", get_ms_compiler_version() ] );
391 push( @versions, [ "MS Linker", get_ms_linker_version() ] );
392}; # if
393my $count = 0;
394foreach my $item ( @versions ) {
395 my ( $title, $tool, $version ) = @$item;
396 if ( not defined( $version ) ) {
397 $version = "--- N/A ---";
398 ++ $count;
399 }; # if
400 if ( $make ) {
401 printf( "%s=%s\n", encode( $tool ), encode( $version ) );
402 } else {
403 printf( "%-25s: %s\n", $title, $version );
404 }; # if
405}; # foreach
406
407exit( $count == 0 ? 0 : 1 );
408
409__END__
410
411=pod
412
413=head1 NAME
414
415B<check-tools.pl> -- Check development tools availability and versions.
416
417=head1 SYNOPSIS
418
419B<check-tools.pl> I<OPTION>...
420
421=head1 OPTIONS
422
423=over
424
425=item B<--make>
426
427Produce output suitable for using in makefile: short tool names (e. g. "icc" instead of "Intel C
428Compiler"), spaces in version strings replaced with underscores.
429
430=item Tools selection
431
432=over
433
434=item B<-->[B<no->]B<-gnu-fortran>
435
436Check GNU Fortran compiler. By default, it is not checked.
437
438=item B<-->[B<no->]B<intel>
439
440Check Intel C, C++ and Fortran compilers. This is default.
441
442=back
443
444=item Platform selection
445
446=over
447
448=item B<--architecture=>I<str>
449
450Specify target architecture. Used in cross-builds, for example when building 32-bit applications on
451Intel(R) 64 machine.
452
453If architecture is not specified explicitly, value of LIBOMP_ARCH environment variable is used.
454If LIBOMP_ARCH is not defined, host architecture detected.
455
456=item B<--os=>I<str>
457
458Specify target OS name. Used in cross-builds, for example when building Intel(R) Many Integrated Core Architecture applications on
459Windows* OS.
460
461If OS is not specified explicitly, value of LIBOMP_OS environment variable is used.
462If LIBOMP_OS is not defined, host OS detected.
463
464=back
465
466=back
467
468=head2 Standard Options
469
470=over
471
472=item B<--doc>
473
474=item B<--manual>
475
476Print full help message and exit.
477
478=item B<--help>
479
480Print short help message and exit.
481
482=item B<--usage>
483
484Print very short usage message and exit.
485
486=item B<--verbose>
487
488Do print informational messages.
489
490=item B<--version>
491
492Print version and exit.
493
494=item B<--quiet>
495
496Work quiet, do not print informational messages.
497
498=back
499
500=head1 DESCRIPTION
501
502This script checks availability and versions of development tools. By default, the script checks:
503Perl, GNU Make, Intel compilers, GNU C and C++ compilers (Linux* OS and OS X*),
504Microsoft C/C++ compiler and linker (Windows* OS).
505
506The sript prints nice looking table or machine-readable strings.
507
508=head2 EXIT
509
510=over
511
512=item *
513
5140 -- All programs found.
515
516=item *
517
5181 -- Some of tools are not found.
519
520=back
521
522=head1 EXAMPLES
523
524 $ check-tools.pl
525 Perl : 5.8.0
526 GNU Make : 3.79.1
527 Intel C Compiler : 11.0 (20080930) for 32e
528 Intel C++ Compiler : 11.0 (20080930) for 32e
529 Intel Fortran Compiler : 10.1.008 (20070913) for 32e
530 GNU C Compiler : 3.2.3 (20030502)
531 GNU C++ Compiler : 3.2.3 (20030502)
532
533 > check-tools.pl --make
534 perl=5.8.8
535 make=3.81
536 icl=10.1_(20070913)_for_32e
537 ifort=10.1_(20070913)_for_32e
538 cl=14.00.40310.41_for_32e
539 link=8.00.40310.39
540
541=back
542
543=cut
544
545# end of file #
546