blob: 95a2ece8e8ea881065805ab7f9823c6a66119af8 [file] [log] [blame]
Greg Ward3ca54bc2000-05-31 01:05:35 +00001"""distutils.extension
2
3Provides the Extension class, used to describe C/C++ extension
4modules in setup scripts."""
5
6# created 2000/05/30, Greg Ward
7
8__revision__ = "$Id$"
9
10from types import *
11
12
13# This class is really only used by the "build_ext" command, so it might
14# make sense to put it in distutils.command.build_ext. However, that
15# module is already big enough, and I want to make this class a bit more
16# complex to simplify some common cases ("foo" module in "foo.c") and do
17# better error-checking ("foo.c" actually exists).
18#
19# Also, putting this in build_ext.py means every setup script would have to
20# import that large-ish module (indirectly, through distutils.core) in
21# order to do anything.
22
23class Extension:
24 """Just a collection of attributes that describes an extension
25 module and everything needed to build it (hopefully in a portable
26 way, but there are hooks that let you can be as unportable as you
27 need).
28
29 Instance attributes:
30 name : string
31 the full name of the extension, including any packages -- ie.
32 *not* a filename or pathname, but Python dotted name
33 sources : [string]
Greg Wardcb185572000-06-24 00:18:24 +000034 list of source filenames, relative to the distribution root
35 (where the setup script lives), in Unix form (slash-separated)
36 for portability. Source files may be C, C++, SWIG (.i),
37 platform-specific resource files, or whatever else is recognized
38 by the "build_ext" command as source for a Python extension.
Greg Ward3ca54bc2000-05-31 01:05:35 +000039 include_dirs : [string]
40 list of directories to search for C/C++ header files (in Unix
41 form for portability)
42 define_macros : [(name : string, value : string|None)]
43 list of macros to define; each macro is defined using a 2-tuple,
44 where 'value' is either the string to define it to or None to
45 define it without a particular value (equivalent of "#define
46 FOO" in source or -DFOO on Unix C compiler command line)
47 undef_macros : [string]
48 list of macros to undefine explicitly
49 library_dirs : [string]
50 list of directories to search for C/C++ libraries at link time
51 libraries : [string]
52 list of library names (not filenames or paths) to link against
53 runtime_library_dirs : [string]
54 list of directories to search for C/C++ libraries at run time
55 (for shared extensions, this is when the extension is loaded)
56 extra_objects : [string]
57 list of extra files to link with (eg. object files not implied
58 by 'sources', static library that must be explicitly specified,
59 binary resource files, etc.)
60 extra_compile_args : [string]
61 any extra platform- and compiler-specific information to use
62 when compiling the source files in 'sources'. For platforms and
63 compilers where "command line" makes sense, this is typically a
64 list of command-line arguments, but for other platforms it could
65 be anything.
66 extra_link_args : [string]
67 any extra platform- and compiler-specific information to use
68 when linking object files together to create the extension (or
69 to create a new static Python interpreter). Similar
70 interpretation as for 'extra_compile_args'.
71 export_symbols : [string]
72 list of symbols to be exported from a shared extension. Not
73 used on all platforms, and not generally necessary for Python
74 extensions, which typically export exactly one symbol: "init" +
75 extension_name.
Greg Ward3ca54bc2000-05-31 01:05:35 +000076 """
77
78 def __init__ (self, name, sources,
79 include_dirs=None,
80 define_macros=None,
81 undef_macros=None,
82 library_dirs=None,
83 libraries=None,
84 runtime_library_dirs=None,
85 extra_objects=None,
86 extra_compile_args=None,
87 extra_link_args=None,
88 export_symbols=None,
Greg Ward3ca54bc2000-05-31 01:05:35 +000089 ):
90
91 assert type(name) is StringType, "'name' must be a string"
92 assert (type(sources) is ListType and
93 len(sources) >= 1 and
94 map(type, sources) == [StringType]*len(sources)), \
95 "'sources' must be a non-empty list of strings"
96
97 self.name = name
98 self.sources = sources
99 self.include_dirs = include_dirs or []
100 self.define_macros = define_macros or []
101 self.undef_macros = undef_macros or []
102 self.library_dirs = library_dirs or []
103 self.libraries = libraries or []
104 self.runtime_library_dirs = runtime_library_dirs or []
105 self.extra_objects = extra_objects or []
106 self.extra_compile_args = extra_compile_args or []
107 self.extra_link_args = extra_link_args or []
Greg Wardc6a18a52000-08-02 00:04:13 +0000108 self.export_symbols = export_symbols
Greg Ward3ca54bc2000-05-31 01:05:35 +0000109
110# class Extension