File: mingw32ccompiler.py

package info (click to toggle)
pygame 1.9.1release%2Bdfsg-10
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 7,280 kB
  • ctags: 6,685
  • sloc: ansic: 41,205; python: 21,987; cpp: 537; objc: 196; php: 92; sh: 77; makefile: 41
file content (142 lines) | stat: -rw-r--r-- 4,944 bytes parent folder | download | duplicates (3)
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
# module mingw32ccompiler.py
# Requires Python 2.1 or better.

"""Win32 GUI/console versions of the distutils mingw32 compiler classes."""

from distutils.cygwinccompiler import Mingw32CCompiler

def intersect (sequence_a, sequence_b):
    """Return true if the two sequences contain items in common

    If sequence_a is a non-sequence then return false.
    """
    try:
        for item in sequence_a:
            if item in sequence_b:
                return 1
    except TypeError:
        return 0
    return 0

def difference (sequence_a, sequence_b):
    """Return a list of items in sequence_a but not in sequence_b

    Will raise a ValueError if either argument is not a sequence.
    """
    new_sequence = []
    for item in sequence_a:
        if item not in sequence_b:
            new_sequence.append(item)
    return new_sequence

subsystem_options = ['-mwindows', '-mconsole']  # Item position is critical.

class Mingw32DefaultCCompiler (Mingw32CCompiler):
    """This mingw32 compiler class builds a Win32 GUI DLL by default.

    It is overridden by subsystem options in the linker extras.
    """

    def set_executables (self, **args):
        """Has no linker subsystem option for shared libraries"""
        Mingw32CCompiler.set_executables(self, **args)
        try:
            self.linker_so = difference (self.linker_so, subsystem_options)
        except TypeError:
            pass
                          
    def link (self,
              target_desc,
              objects,
              output_filename,
              output_dir=None,
              libraries=None,
              library_dirs=None,
              runtime_library_dirs=None,
              export_symbols=None,
              debug=0,
              extra_preargs=None,
              extra_postargs=None,
              build_temp=None,
              target_lang=None):
        """Do a Win32 GUI link if no subsystem option given."""

        if (target_desc != self.EXECUTABLE and
            not intersect(subsystem_options, extra_preargs) and
            not intersect(subsystem_options, extra_postargs)):
            try:
                extra_preargs = extra_preargs + subsystem_options[0]
            except TypeError:
                extra_preargs = subsystem_options[0:1]

        Mingw32CCompiler.link (self,
                               target_desc,
                               objects,
                               output_filename,
                               output_dir,
                               libraries,
                               library_dirs,
                               runtime_library_dirs,
                               export_symbols,
                               debug,
                               extra_preargs,
                               extra_postargs,
                               build_temp,
                               target_lang)

class Mingw32ConsoleCCompiler (Mingw32CCompiler):
    """This mingw32 compiler class builds a console DLL.

    It is not overridden by subsystem options in the linker extras.
    """

    def set_executables (self, **args):
        """Has console subsystem linker option for shared libraries."""
        Mingw32CCompiler.set_executables(self, **args)
        try:
            linker_so = difference(self.linker_so, subsystem_options)
        except TypeError:
            linker_so = subsystem_options[1:2]
        else:
            linker_so.append(subsystem_options[1])
        self.linker_so = linker_so
                          
    def link (self,
              target_desc,
              objects,
              output_filename,
              output_dir=None,
              libraries=None,
              library_dirs=None,
              runtime_library_dirs=None,
              export_symbols=None,
              debug=0,
              extra_preargs=None,
              extra_postargs=None,
              build_temp=None,
              target_lang=None):
        """Do a console link."""

        if target_desc != self.EXECUTABLE:
            try:
                extra_preargs = difference(extra_preargs, subsystem_options)
            except TypeError:
                pass
            try:
                extra_postargs = difference(extra_postargs, subsystem_options)
            except TypeError:
                pass
        Mingw32CCompiler.link (self,
                               target_desc,
                               objects,
                               output_filename,
                               output_dir,
                               libraries,
                               library_dirs,
                               runtime_library_dirs,
                               export_symbols,
                               debug,
                               extra_preargs,
                               extra_postargs,
                               build_temp,
                               target_lang)