Greg Ward | 3ca54bc | 2000-05-31 01:05:35 +0000 | [diff] [blame] | 1 | """distutils.extension |
| 2 | |
| 3 | Provides the Extension class, used to describe C/C++ extension |
| 4 | modules in setup scripts.""" |
| 5 | |
| 6 | # created 2000/05/30, Greg Ward |
| 7 | |
| 8 | __revision__ = "$Id$" |
| 9 | |
| 10 | from 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 | |
| 23 | class 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 Ward | cb18557 | 2000-06-24 00:18:24 +0000 | [diff] [blame] | 34 | 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 Ward | 3ca54bc | 2000-05-31 01:05:35 +0000 | [diff] [blame] | 39 | 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. |
| 76 | export_symbol_file : string |
| 77 | name of file that lists symbols to export; the format of this |
| 78 | file is platform- and compiler-specific. This is even more |
| 79 | gratuitous and unnecessary than 'export_symbols'; I'll be happy |
| 80 | when it goes away forever. |
| 81 | """ |
| 82 | |
| 83 | def __init__ (self, name, sources, |
| 84 | include_dirs=None, |
| 85 | define_macros=None, |
| 86 | undef_macros=None, |
| 87 | library_dirs=None, |
| 88 | libraries=None, |
| 89 | runtime_library_dirs=None, |
| 90 | extra_objects=None, |
| 91 | extra_compile_args=None, |
| 92 | extra_link_args=None, |
| 93 | export_symbols=None, |
| 94 | export_symbol_file=None, |
| 95 | ): |
| 96 | |
| 97 | assert type(name) is StringType, "'name' must be a string" |
| 98 | assert (type(sources) is ListType and |
| 99 | len(sources) >= 1 and |
| 100 | map(type, sources) == [StringType]*len(sources)), \ |
| 101 | "'sources' must be a non-empty list of strings" |
| 102 | |
| 103 | self.name = name |
| 104 | self.sources = sources |
| 105 | self.include_dirs = include_dirs or [] |
| 106 | self.define_macros = define_macros or [] |
| 107 | self.undef_macros = undef_macros or [] |
| 108 | self.library_dirs = library_dirs or [] |
| 109 | self.libraries = libraries or [] |
| 110 | self.runtime_library_dirs = runtime_library_dirs or [] |
| 111 | self.extra_objects = extra_objects or [] |
| 112 | self.extra_compile_args = extra_compile_args or [] |
| 113 | self.extra_link_args = extra_link_args or [] |
| 114 | self.export_symbols = export_symbols or [] |
| 115 | self.export_symbol_file = export_symbol_file |
| 116 | |
| 117 | # class Extension |