summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/tools/check-tools.pl
blob: 8140e110aea816839e19bb66f8e2222c35b5b5e5 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
#!/usr/bin/perl

#
#//===----------------------------------------------------------------------===//
#//
#//                     The LLVM Compiler Infrastructure
#//
#// This file is dual licensed under the MIT and the University of Illinois Open
#// Source Licenses. See LICENSE.txt for details.
#//
#//===----------------------------------------------------------------------===//
#

# Pragmas.
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/lib";

# LIBOMP modules.
use Platform ":vars";
use tools;

our $VERSION = "0.015";

my $pedantic;

# --------------------------------------------------------------------------------------------------
# Helper functions
# --------------------------------------------------------------------------------------------------


sub run($\$\$;\$) {
    my ( $cmd, $stdout, $stderr, $path ) = @_;
    my ( @path, $rc );
    @path = which( $cmd->[ 0 ], -all => 1 );
    if ( @path > 0 ) {
        if ( @path > 1 and $pedantic ) {
            warning( "More than one \"$cmd->[ 0 ]\" found in PATH:", map( "    $_", @path ) );
        }; # if
        debug( "\"$cmd->[ 0 ]\" full path is \"$path[ 0 ]\"." );
        if ( defined( $path ) ) {
            $$path = $path[ 0 ];
        }; # if
        debug( "Executing command: \""  . join ( " ", @$cmd ) . "\"." );
        $rc =
            execute(
                $cmd,
                -ignore_signal => 1, -ignore_status => 1,
                -stdout => $stdout, -stderr => $stderr, -stdin => undef
            );
        if ( $rc < 0 ) {
            warning( "Cannot run \"$cmd->[ 0 ]\": $@" );
        }; # if
        debug( "stdout:", $$stdout, "(eof)", "stderr:", $$stderr, "(eof)" );
    } else {
        warning( "No \"$cmd->[ 0 ]\" found in PATH." );
        $rc = -1;
    }; # if
    return $rc;
}; # sub run


sub get_arch($$$) {
    my ( $name, $str, $exps ) = @_;
    my ( $arch, $count );
    $count = 0;
    foreach my $re ( keys( %$exps ) ) {
        if ( $str =~ $re ) {
            $arch = $exps->{ $re };
            ++ $count;
        }; # if
    }; # for
    if ( $count != 1 or not Platform::canon_arch( $arch ) ) {
        warning( "Cannot detect $name architecture: $str" );
        return undef;
    }; # if
    return $arch;
}; # sub get_arch

sub encode($) {
    my ( $str ) = @_;
    $str =~ s{ }{_}g;
    return $str;
}; # sub encode


# --------------------------------------------------------------------------------------------------
# get_xxx_version subroutines.
# --------------------------------------------------------------------------------------------------
#
# Some of get_xxx_version() subroutines accept an argument -- a tool name. For example,
# get_intel_compiler_version() can report version of C, C++, or Fortran compiler. The tool for
# report should be specified by argument, for example: get_intel_compiler_version( "ifort" ).
#
# get_xxx_version() subroutines returns list of one or two elements:
#     1. The first element is short tool name (like "gcc", "g++", "icl", etc).
#     2. The second element is version string.
# If returned list contain just one element, it means there is a problem with the tool.
#

sub get_perl_version() {
    my ( $rc, $stdout, $stderr, $version );
    my $tool = "perl";
    my ( @ret ) = ( $tool );
    $rc = run( [ $tool, "--version" ], $stdout, $stderr );
    if ( $rc >= 0 ) {
        # Typical perl output:
        #    This is perl, v5.10.0 built for x86_64-linux-thread-multi
        #    This is perl, v5.8.8 built for MSWin32-x64-multi-thread
        #    This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
        if ( $stdout !~ m{^This is perl.*v(\d+\.\d+(?:\.\d+)).*built for}m ) {
            warning( "Cannot parse perl output:", $stdout, "(oef)" );
        }; # if
        $version = $1;
        if ( $target_os eq "win" ) {
            if ( $stdout !~ m{Binary build (.*) provided by ActiveState } ) {
                warning( "Perl is not ActiveState one" );
            }; # if
        }; # if
    }; # if
    push( @ret, $version );
    return @ret;
}; # sub get_perl_version


sub get_gnu_make_version() {
    my ( $rc, $stdout, $stderr, $version );
    my $tool = "make";
    my ( @ret ) = ( $tool );
    my ( $path );
    $rc = run( [ $tool, "--version" ], $stdout, $stderr, $path );
    if ( $rc >= 0 ) {
        # Typical make output:
        #     GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
        #     GNU Make 3.81
        if ( $stdout =~ m{^GNU Make (?:version )?(\d+\.\d+(?:\.\d+)?)(?:,|\s)} ) {
            $version = $1;
        }; # if
        if ( $target_os eq "win" and $stdout =~ m{built for ([a-z0-9-]+)} ) {
            my $built_for = $1;
            debug( "GNU Make built for: \"$built_for\"." );
            if ( $built_for =~ m{cygwin}i ) {
                warning( "\"$path\" is a Cygwin make, it is *not* suitable." );
                return @ret;
            }; # if
        }; # if
    }; # if
    push( @ret, $version );
    return @ret;
}; # sub get_gnu_make_version


sub get_intel_compiler_version($) {
    my ( $tool ) = @_;    # Tool name, like "icc", "icpc", "icl", or "ifort".
    my ( @ret ) = ( $tool );
    my ( $rc, $stdout, $stderr, $tool_re );
    my $version;
    my $ic_archs = {
        qr{32-bit|IA-32}        => "32",
        qr{Intel\(R\) 64} => "32e",
        qr{Intel\(R\) [M][I][C] Architecture} => "32e",
    };
    $tool_re = quotemeta( $tool );
    $rc = run( [ $tool, ( $target_os eq "win" ? () : ( "-V" ) ) ], $stdout, $stderr );
    if ( $rc < 0 ) {
        return @ret;
    }; # if
    # Intel compiler version string is in the first line of stderr. Get it.
    #$stderr =~ m{\A(.*\n?)};
    # AC: Let's look for version string in the first line which contains "Intel" string.
    #     This allows to use 11.1 and 12.0 compilers on new MAC machines by ignoring
    #     huge number of warnings issued by old compilers.
    $stderr =~ m{^(Intel.*)$}m;
    my $vstr = $1;
    my ( $apl, $ver, $bld, $pkg );
    if ( 0 ) {
    } elsif ( $vstr =~ m{^Intel.*?Compiler\s+(.*?),?\s+Version\s+(.*?)\s+Build\s+(\S+)(?:\s+Package ID: (\S+))?} ) {
        # 9.x, 10.x, 11.0.
        ( $apl, $ver, $bld, $pkg ) = ( $1, $2, $3, $4 );
    } elsif ( $vstr =~ m{^Intel's (.*?) Compiler,?\s+Version\s+(.*?)\s+Build\s+(\S+)} ) {
        # 11.1
        ( $apl, $ver, $bld ) = ( $1, $2, $3 );
    } else {
        warning( "Cannot parse ${tool}'s stderr:", $stderr, "(eof)" );
        return @ret;
    }; # if
    my $ic_arch = get_arch( "Intel compiler", $apl, $ic_archs );
    if ( not defined( $ic_arch ) ) {
        return @ret;
    }; # if
    if ( Platform::canon_arch( $ic_arch ) ne $target_arch ) {
        warning( "Target architecture is $target_arch, $tool for $ic_arch found." );
        return @ret;
    }; # if
    # Normalize version.
    my $stage;
    $ver =~ s{\s+}{ }g;
    $ver = lc( $ver );
    if ( $ver =~ m{\A(\d+\.\d+(?:\.\d+)?) ([a-z]+)\a}i ) {
        ( $version, $stage ) = ( $1, $2 );
    } else {
        ( $version, $stage ) = ( $ver, "" );
    }; # if
    # Parse package.
    if ( defined( $pkg ) ) {
        if ( $pkg !~ m{\A[lwm]_[a-z]+_[a-z]_(\d+\.\d+\.\d+)\z}i ) {
            warning( "Cannot parse Intel compiler package: $pkg" );
            return @ret;
        }; # if
        $pkg = $1;
        $version = $pkg;
    }; # if
    push( @ret, "$version " . ( $stage ? "$stage " : "" ) . "($bld) for $ic_arch" );
    # Ok, version of Intel compiler found successfully. Now look at config file.
    # Installer of Intel compiler tends to add a path to MS linker into compiler config file.
    # It leads to troubles. For example, all the environment set up for MS VS 2005, but Intel
    # compiler uses lnker from MS VS 2003 because it is specified in config file.
    # To avoid such troubles, make sure:
    #     ICLCFG/IFORTCFG environment variable exists or
    #     compiler config file does not exist, or
    #     compiler config file does not specify linker.
    if ( $target_os eq "win" ) {
        if ( not exists( $ENV{ uc( $tool . "cfg" ) } ) ) {
            # If ICLCFG/IFORTCFG environment varianle exists, everything is ok.
            # Otherwise check compiler's config file.
            my $path = which( $tool );
            $path =~ s{\.exe\z}{}i;     # Drop ".exe" suffix.
            $path .= ".cfg";            # And add ".cfg" one.
            if ( -f $path ) {
                # If no config file exists, it is ok.
                # Otherwise analyze its content.
                my $bulk = read_file( $path );
                $bulk =~ s{#.*\n}{}g;    # Remove comments.
                my @options = ( "Qvc", "Qlocation,link," );
                foreach my  $opt ( @options ) {
                    if ( $bulk =~ m{[-/]$opt} ) {
                        warning( "Compiler config file \"$path\" contains \"-$opt\" option." );
                    }; # if
                }; # foreach
            }; # if
        }; # if
    }; # if
    return @ret;
}; # sub get_intel_compiler_version


sub get_gnu_compiler_version($) {
    my ( $tool ) = @_;
    my ( @ret ) = ( $tool );
    my ( $rc, $stdout, $stderr, $version );
    $rc = run( [ $tool, "--version" ], $stdout, $stderr );
    if ( $rc >= 0 ) {
        my ( $ver, $bld );
        if ( $target_os eq "mac" ) {
            # i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
            # i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5484)
            # i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
            $stdout =~ m{^.*? \(GCC\) (\d+\.\d+\.\d+) \(.*Apple.*?Inc\. build (\d+)\)}m;
            ( $ver, $bld ) = ( $1, $2 );
        } else {
            if ( 0 ) {
            } elsif ( $stdout =~ m{^.*? \(GCC\) (\d+\.\d+\.\d+)(?: (\d+))?}m ) {
                # g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)
                # GNU Fortran (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)
                ( $ver, $bld ) = ( $1, $2 );
            } elsif ( $stdout =~ m{^.*? \(SUSE Linux\) (\d+\.\d+\.\d+)\s+\[.*? (\d+)\]}m ) {
                # gcc (SUSE Linux) 4.3.2 [gcc-4_3-branch revision 141291]
                ( $ver, $bld ) = ( $1, $2 );
            } elsif ( $stdout =~ m{^.*? \((Debian|Ubuntu).*?\) (\d+\.\d+\.\d+)}m ) {
                # gcc (Debian 4.7.2-22) 4.7.2
                # Debian support from Sylvestre Ledru 
                # Thanks!
                $ver = $2;
            }; # if
        }; # if
        if ( defined( $ver ) ) {
            $version = $ver . ( defined( $bld ) ? " ($bld)" : "" );
        } else {
            warning( "Cannot parse GNU compiler version:", $stdout, "(eof)" );
        }; # if
    }; # if
    push( @ret, $version );
    return @ret;
}; # sub get_gnu_compiler_version


sub get_ms_compiler_version() {
    my ( $rc, $stdout, $stderr, $version );
    my $tool = "cl";
    my ( @ret ) = ( $tool );
    my $mc_archs = {
        qr{80x86}         => "IA-32 architecture",
        qr{AMD64|x64}     => "Intel(R) 64",
    };
    $rc = run( [ $tool ], $stdout, $stderr );
    if ( $rc < 0 ) {
        return @ret;
    }; # if
    if ( $stderr !~ m{^Microsoft .* Compiler Version (.*?) for (.*)\s*$}m ) {
        warning( "Cannot parse MS compiler output:", $stderr, "(eof)" );
        return @ret;
    }; # if
    my ( $ver, $apl ) = ( $1, $2 );
    if ( $ver !~ m{\A\d+(?:\.\d+)+\z} ) {
        warning( "Cannot parse MS compiler version: $ver" );
        return @ret;
    }; # if
    my $mc_arch = get_arch( "MS compiler", $apl, $mc_archs );
    if ( not defined( $mc_arch ) ) {
        return @ret;
    }; # if
    if ( Platform::canon_arch( $mc_arch ) ne $target_arch ) {
        warning( "Target architecture is $target_arch, $tool for $mc_arch found" );
        return @ret;
    }; # if
    $version = "$ver for $target_arch";
    push( @ret, $version );
    return @ret;
}; # sub get_ms_compiler_version


sub get_ms_linker_version() {
    my ( $rc, $stdout, $stderr, $version );
    my $tool = "link";
    my ( @ret ) = ( $tool );
    my ( $path );
    $rc = run( [ $tool ], $stdout, $stderr, $path );
    if ( $rc < 0 ) {
        return @ret;
    }; # if
    if ( $stdout !~ m{^Microsoft \(R\) Incremental Linker Version (\d+(?:\.\d+)+)\s*$}m ) {
        warning( "Cannot parse MS linker output:", $stdout, "(eof)" );
        if ( $stderr =~ m{^link: missing operand} ) {
            warning( "Seems \"$path\" is a Unix-like \"link\" program, not MS linker." );
        }; # if
        return @ret;
    }; # if
    $version = ( $1 );
    push( @ret, $version );
    return @ret;
}; # sub get_ms_linker_version


# --------------------------------------------------------------------------------------------------
# "main" program.
# --------------------------------------------------------------------------------------------------

my $make;
my $intel       = 1;             # Check Intel compilers.
my $gnu_fortran = 0;             # Check GNU Fortran.
my $intel_compilers = {
    "lin" => { c => "icc", cpp => "icpc", f => "ifort" },
    "lrb" => { c => "icc", cpp => "icpc", f => "ifort" },
    "mac" => { c => "icc", cpp => "icpc", f => "ifort" },
    "win" => { c => "icl", cpp => undef,  f => "ifort" },
};

get_options(
    Platform::target_options(),
    "intel!"         => \$intel,
    "gnu-fortran!"   => \$gnu_fortran,
    "make"           => \$make,
    "pedantic"       => \$pedantic,
);

my @versions;
push( @versions, [ "Perl",     get_perl_version() ] );
push( @versions, [ "GNU Make", get_gnu_make_version() ] );
if ( $intel ) {
    my $ic = $intel_compilers->{ $target_os };
    push( @versions, [ "Intel C Compiler",       get_intel_compiler_version( $ic->{ c } ) ] );
    if ( defined( $ic->{ cpp } ) ) {
        # If Intel C++ compiler has a name different from C compiler, check it as well.
        push( @versions, [ "Intel C++ Compiler", get_intel_compiler_version( $ic->{ cpp } ) ] );
    }; # if
    if ( defined( $ic->{ f } ) ) {
        push( @versions, [ "Intel Fortran Compiler", get_intel_compiler_version( $ic->{ f } ) ] );
    }; # if
}; # if
if ( $target_os eq "lin" or $target_os eq "mac" ) {
    push( @versions, [ "GNU C Compiler",     get_gnu_compiler_version( "gcc" ) ] );
    push( @versions, [ "GNU C++ Compiler",   get_gnu_compiler_version( "g++" ) ] );
    if ( $gnu_fortran ) {
        push( @versions, [ "GNU Fortran Compiler", get_gnu_compiler_version( "gfortran" ) ] );
    }; # if
}; # if
if ( $target_os eq "win" ) {
    push( @versions, [ "MS C/C++ Compiler",  get_ms_compiler_version() ] );
    push( @versions, [ "MS Linker",          get_ms_linker_version() ] );
}; # if
my $count = 0;
foreach my $item ( @versions ) {
    my ( $title, $tool, $version ) = @$item;
    if ( not defined( $version ) ) {
        $version = "--- N/A ---";
        ++ $count;
    }; # if
    if ( $make ) {
        printf( "%s=%s\n", encode( $tool ), encode( $version ) );
    } else {
        printf( "%-25s: %s\n", $title, $version );
    }; # if
}; # foreach

exit( $count == 0 ? 0 : 1 );

__END__

=pod

=head1 NAME

B<check-tools.pl> -- Check development tools availability and versions.

=head1 SYNOPSIS

B<check-tools.pl> I<OPTION>...

=head1 OPTIONS

=over

=item B<--make>

Produce output suitable for using in makefile: short tool names (e. g. "icc" instead of "Intel C
Compiler"), spaces in version strings replaced with underscores.

=item Tools selection

=over

=item B<-->[B<no->]B<-gnu-fortran>

Check GNU Fortran compiler. By default, it is not checked.

=item B<-->[B<no->]B<intel>

Check Intel C, C++ and Fortran compilers. This is default.

=back

=item Platform selection

=over

=item B<--architecture=>I<str>

Specify target architecture. Used in cross-builds, for example when building 32-bit applications on
Intel(R) 64 machine.

If architecture is not specified explicitly, value of LIBOMP_ARCH environment variable is used.
If LIBOMP_ARCH is not defined, host architecture detected.

=item B<--os=>I<str>

Specify target OS name. Used in cross-builds, for example when building Intel(R) Many Integrated Core Architecture applications on
Windows* OS.

If OS is not specified explicitly, value of LIBOMP_OS environment variable is used.
If LIBOMP_OS is not defined, host OS detected.

=back

=back

=head2 Standard Options

=over

=item B<--doc>

=item B<--manual>

Print full help message and exit.

=item B<--help>

Print short help message and exit.

=item B<--usage>

Print very short usage message and exit.

=item B<--verbose>

Do print informational messages.

=item B<--version>

Print version and exit.

=item B<--quiet>

Work quiet, do not print informational messages.

=back

=head1 DESCRIPTION

This script checks availability and versions of development tools. By default, the script checks:
Perl, GNU Make, Intel compilers, GNU C and C++ compilers (Linux* OS and OS X*),
Microsoft C/C++ compiler and linker (Windows* OS).

The sript prints nice looking table or machine-readable strings.

=head2 EXIT

=over

=item *

0 -- All programs found.

=item *

1 -- Some of tools are not found.

=back

=head1 EXAMPLES

    $ check-tools.pl
    Perl                     : 5.8.0
    GNU Make                 : 3.79.1
    Intel C Compiler         : 11.0 (20080930) for 32e
    Intel C++ Compiler       : 11.0 (20080930) for 32e
    Intel Fortran Compiler   : 10.1.008 (20070913) for 32e
    GNU C Compiler           : 3.2.3 (20030502)
    GNU C++ Compiler         : 3.2.3 (20030502)

    > check-tools.pl --make
    perl=5.8.8
    make=3.81
    icl=10.1_(20070913)_for_32e
    ifort=10.1_(20070913)_for_32e
    cl=14.00.40310.41_for_32e
    link=8.00.40310.39

=back

=cut

# end of file #

OpenPOWER on IntegriCloud