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