third_party:waf: update to upstream 2.0.4 release
[amitay/samba.git] / third_party / waf / waflib / extras / pgicc.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # Antoine Dechaume 2011
8
9 """
10 Detect the PGI C compiler
11 """
12
13 import sys, re
14 from waflib import Errors
15 from waflib.Configure import conf
16 from waflib.Tools.compiler_c import c_compiler
17 c_compiler['linux'].append('pgicc')
18
19 @conf
20 def find_pgi_compiler(conf, var, name):
21         """
22         Find the program name, and execute it to ensure it really is itself.
23         """
24         if sys.platform == 'cygwin':
25                 conf.fatal('The PGI compiler does not work on Cygwin')
26
27         v = conf.env
28         cc = None
29         if v[var]:
30                 cc = v[var]
31         elif var in conf.environ:
32                 cc = conf.environ[var]
33         if not cc:
34                 cc = conf.find_program(name, var=var)
35         if not cc:
36                 conf.fatal('PGI Compiler (%s) was not found' % name)
37
38         v[var + '_VERSION'] = conf.get_pgi_version(cc)
39         v[var] = cc
40         v[var + '_NAME'] = 'pgi'
41
42 @conf
43 def get_pgi_version(conf, cc):
44         """Find the version of a pgi compiler."""
45         version_re = re.compile(r"The Portland Group", re.I).search
46         cmd = cc + ['-V', '-E'] # Issue 1078, prevent wrappers from linking
47
48         try:
49                 out, err = conf.cmd_and_log(cmd, output=0)
50         except Errors.WafError:
51                 conf.fatal('Could not find pgi compiler %r' % cmd)
52
53         if out:
54                 match = version_re(out)
55         else:
56                 match = version_re(err)
57
58         if not match:
59                 conf.fatal('Could not verify PGI signature')
60
61         cmd = cc + ['-help=variable']
62         try:
63                 out, err = conf.cmd_and_log(cmd, output=0)
64         except Errors.WafError:
65                 conf.fatal('Could not find pgi compiler %r' % cmd)
66
67         version = re.findall('^COMPVER\s*=(.*)', out, re.M)
68         if len(version) != 1:
69                 conf.fatal('Could not determine the compiler version')
70         return version[0]
71
72 def configure(conf):
73         conf.find_pgi_compiler('CC', 'pgcc')
74         conf.find_ar()
75         conf.gcc_common_flags()
76         conf.cc_load_tools()
77         conf.cc_add_flags()
78         conf.link_add_flags()
79