Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 1 | """distutils.command.build |
| 2 | |
| 3 | Implements the Distutils 'build' command.""" |
| 4 | |
| 5 | # created 1999/03/08, Greg Ward |
| 6 | |
Greg Ward | 3ce77fd | 2000-03-02 01:49:45 +0000 | [diff] [blame] | 7 | __revision__ = "$Id$" |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 8 | |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 9 | import sys, os |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 10 | from distutils.core import Command |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 11 | from distutils.util import get_platform |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 12 | |
Greg Ward | 1993f9a | 2000-02-18 00:13:53 +0000 | [diff] [blame] | 13 | class build (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 14 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 15 | description = "build everything needed to install" |
| 16 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 17 | user_options = [ |
| 18 | ('build-base=', 'b', |
| 19 | "base directory for build library"), |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 20 | ('build-purelib=', None, |
| 21 | "build directory for platform-neutral distributions"), |
| 22 | ('build-platlib=', None, |
| 23 | "build directory for platform-specific distributions"), |
| 24 | ('build-lib=', None, |
| 25 | "build directory for all distribution (defaults to either " + |
| 26 | "build-purelib or build-platlib"), |
| 27 | ('build-temp=', 't', |
| 28 | "temporary build directory"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 29 | ('debug', 'g', |
| 30 | "compile extensions and libraries with debugging information"), |
| 31 | ] |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 32 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 33 | def initialize_options (self): |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 34 | self.build_base = 'build' |
| 35 | # these are decided only after 'build_base' has its final value |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 36 | # (unless overridden by the user or client) |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 37 | self.build_purelib = None |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 38 | self.build_platlib = None |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 39 | self.build_lib = None |
| 40 | self.build_temp = None |
Greg Ward | 3246200 | 2000-02-09 02:19:49 +0000 | [diff] [blame] | 41 | self.debug = None |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 42 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 43 | def finalize_options (self): |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 44 | |
| 45 | # Need this to name platform-specific directories, but sys.platform |
| 46 | # is not enough -- it only names the OS and version, not the |
| 47 | # hardware architecture! |
| 48 | self.plat = get_platform () |
| 49 | |
| 50 | # 'build_purelib' and 'build_platlib' just default to 'lib' and |
| 51 | # 'lib.<plat>' under the base build directory. We only use one of |
| 52 | # them for a given distribution, though -- |
| 53 | if self.build_purelib is None: |
| 54 | self.build_purelib = os.path.join (self.build_base, 'lib') |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 55 | if self.build_platlib is None: |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 56 | self.build_platlib = os.path.join (self.build_base, |
| 57 | 'lib.' + self.plat) |
| 58 | |
| 59 | # 'build_lib' is the actual directory that we will use for this |
| 60 | # particular module distribution -- if user didn't supply it, pick |
| 61 | # one of 'build_purelib' or 'build_platlib'. |
| 62 | if self.build_lib is None: |
| 63 | if self.distribution.ext_modules: |
| 64 | self.build_lib = self.build_platlib |
| 65 | else: |
| 66 | self.build_lib = self.build_purelib |
| 67 | |
| 68 | # 'build_temp' -- temporary directory for compiler turds, |
| 69 | # "build/temp.<plat>" |
| 70 | if self.build_temp is None: |
| 71 | self.build_temp = os.path.join (self.build_base, |
| 72 | 'temp.' + self.plat) |
| 73 | # finalize_options () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 74 | |
| 75 | |
| 76 | def run (self): |
| 77 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 78 | # For now, "build" means "build_py" then "build_ext". (Eventually |
| 79 | # it should also build documentation.) |
| 80 | |
Greg Ward | 02e1c56 | 1999-09-21 18:27:55 +0000 | [diff] [blame] | 81 | # Invoke the 'build_py' command to "build" pure Python modules |
| 82 | # (ie. copy 'em into the build tree) |
| 83 | if self.distribution.packages or self.distribution.py_modules: |
| 84 | self.run_peer ('build_py') |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 85 | |
Greg Ward | 5f7c18e | 2000-02-05 02:24:16 +0000 | [diff] [blame] | 86 | # Build any standalone C libraries next -- they're most likely to |
| 87 | # be needed by extension modules, so obviously have to be done |
| 88 | # first! |
| 89 | if self.distribution.libraries: |
Greg Ward | 76ec0d6 | 2000-03-02 01:57:12 +0000 | [diff] [blame] | 90 | self.run_peer ('build_clib') |
Greg Ward | 5f7c18e | 2000-02-05 02:24:16 +0000 | [diff] [blame] | 91 | |
Greg Ward | 02e1c56 | 1999-09-21 18:27:55 +0000 | [diff] [blame] | 92 | # And now 'build_ext' -- compile extension modules and put them |
| 93 | # into the build tree |
| 94 | if self.distribution.ext_modules: |
| 95 | self.run_peer ('build_ext') |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 96 | |
| 97 | # end class Build |