1from distutils.core import Command
2from numpy.distutils import log
3
4#XXX: Linker flags
5
6def show_fortran_compilers(_cache=None):
7    # Using cache to prevent infinite recursion.
8    if _cache:
9        return
10    elif _cache is None:
11        _cache = []
12    _cache.append(1)
13    from numpy.distutils.fcompiler import show_fcompilers
14    import distutils.core
15    dist = distutils.core._setup_distribution
16    show_fcompilers(dist)
17
18class config_fc(Command):
19    """ Distutils command to hold user specified options
20    to Fortran compilers.
21
22    config_fc command is used by the FCompiler.customize() method.
23    """
24
25    description = "specify Fortran 77/Fortran 90 compiler information"
26
27    user_options = [
28        ('fcompiler=', None, "specify Fortran compiler type"),
29        ('f77exec=', None, "specify F77 compiler command"),
30        ('f90exec=', None, "specify F90 compiler command"),
31        ('f77flags=', None, "specify F77 compiler flags"),
32        ('f90flags=', None, "specify F90 compiler flags"),
33        ('opt=', None, "specify optimization flags"),
34        ('arch=', None, "specify architecture specific optimization flags"),
35        ('debug', 'g', "compile with debugging information"),
36        ('noopt', None, "compile without optimization"),
37        ('noarch', None, "compile without arch-dependent optimization"),
38        ]
39
40    help_options = [
41        ('help-fcompiler', None, "list available Fortran compilers",
42         show_fortran_compilers),
43        ]
44
45    boolean_options = ['debug', 'noopt', 'noarch']
46
47    def initialize_options(self):
48        self.fcompiler = None
49        self.f77exec = None
50        self.f90exec = None
51        self.f77flags = None
52        self.f90flags = None
53        self.opt = None
54        self.arch = None
55        self.debug = None
56        self.noopt = None
57        self.noarch = None
58
59    def finalize_options(self):
60        log.info('unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options')
61        build_clib = self.get_finalized_command('build_clib')
62        build_ext = self.get_finalized_command('build_ext')
63        config = self.get_finalized_command('config')
64        build = self.get_finalized_command('build')
65        cmd_list = [self, config, build_clib, build_ext, build]
66        for a in ['fcompiler']:
67            l = []
68            for c in cmd_list:
69                v = getattr(c, a)
70                if v is not None:
71                    if not isinstance(v, str): v = v.compiler_type
72                    if v not in l: l.append(v)
73            if not l: v1 = None
74            else: v1 = l[0]
75            if len(l)>1:
76                log.warn('  commands have different --%s options: %s'\
77                         ', using first in list as default' % (a, l))
78            if v1:
79                for c in cmd_list:
80                    if getattr(c, a) is None: setattr(c, a, v1)
81
82    def run(self):
83        # Do nothing.
84        return
85
86class config_cc(Command):
87    """ Distutils command to hold user specified options
88    to C/C++ compilers.
89    """
90
91    description = "specify C/C++ compiler information"
92
93    user_options = [
94        ('compiler=', None, "specify C/C++ compiler type"),
95        ]
96
97    def initialize_options(self):
98        self.compiler = None
99
100    def finalize_options(self):
101        log.info('unifing config_cc, config, build_clib, build_ext, build commands --compiler options')
102        build_clib = self.get_finalized_command('build_clib')
103        build_ext = self.get_finalized_command('build_ext')
104        config = self.get_finalized_command('config')
105        build = self.get_finalized_command('build')
106        cmd_list = [self, config, build_clib, build_ext, build]
107        for a in ['compiler']:
108            l = []
109            for c in cmd_list:
110                v = getattr(c, a)
111                if v is not None:
112                    if not isinstance(v, str): v = v.compiler_type
113                    if v not in l: l.append(v)
114            if not l: v1 = None
115            else: v1 = l[0]
116            if len(l)>1:
117                log.warn('  commands have different --%s options: %s'\
118                         ', using first in list as default' % (a, l))
119            if v1:
120                for c in cmd_list:
121                    if getattr(c, a) is None: setattr(c, a, v1)
122        return
123
124    def run(self):
125        # Do nothing.
126        return
127