1# MIT License
2#
3# Copyright The SCons Foundation
4#
5# Permission is hereby granted, free of charge, to any person obtaining
6# a copy of this software and associated documentation files (the
7# "Software"), to deal in the Software without restriction, including
8# without limitation the rights to use, copy, modify, merge, publish,
9# distribute, sublicense, and/or sell copies of the Software, and to
10# permit persons to whom the Software is furnished to do so, subject to
11# the following conditions:
12#
13# The above copyright notice and this permission notice shall be included
14# in all copies or substantial portions of the Software.
15#
16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24"""Platform-specific initialization for IBM AIX systems.
25
26There normally shouldn't be any need to import this module directly.  It
27will usually be imported through the generic SCons.Platform.Platform()
28selection method.
29"""
30
31import subprocess
32
33from . import posix
34
35import SCons.Util
36import SCons.Action
37
38def get_xlc(env, xlc=None, packages=[]):
39    # Use the AIX package installer tool lslpp to figure out where a
40    # given xl* compiler is installed and what version it is.
41    xlcPath = None
42    xlcVersion = None
43
44    if xlc is None:
45        xlc = env.get('CC', 'xlc')
46    if SCons.Util.is_List(xlc):
47        xlc = xlc[0]
48    for package in packages:
49        # find the installed filename, which may be a symlink as well
50        pipe = SCons.Action._subproc(env, ['lslpp', '-fc', package],
51                stdin = 'devnull',
52                stderr = 'devnull',
53                universal_newlines=True,
54                stdout = subprocess.PIPE)
55        # output of lslpp is something like this:
56        #     #Path:Fileset:File
57        #     /usr/lib/objrepos:vac.C 6.0.0.0:/usr/vac/exe/xlCcpp
58        #     /usr/lib/objrepos:vac.C 6.0.0.0:/usr/vac/bin/xlc_r -> /usr/vac/bin/xlc
59        for line in pipe.stdout:
60            if xlcPath:
61                continue # read everything to let lslpp terminate
62            fileset, filename = line.split(':')[1:3]
63            filename = filename.split()[0]
64            if ('/' in xlc and filename == xlc) \
65            or ('/' not in xlc and filename.endswith('/' + xlc)):
66                xlcVersion = fileset.split()[1]
67                xlcPath, sep, xlc = filename.rpartition('/')
68    return (xlcPath, xlc, xlcVersion)
69
70def generate(env):
71    posix.generate(env)
72    #Based on AIX 5.2: ARG_MAX=24576 - 3000 for environment expansion
73    env['MAXLINELENGTH']  = 21576
74    env['SHLIBSUFFIX'] = '.a'
75
76# Local Variables:
77# tab-width:4
78# indent-tabs-mode:nil
79# End:
80# vim: set expandtab tabstop=4 shiftwidth=4:
81