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 | 3459381 | 2000-06-24 01:23:37 +0000 | [diff] [blame] | 12 | |
| 13 | |
| 14 | def show_compilers (): |
| 15 | from distutils.ccompiler import show_compilers |
| 16 | show_compilers() |
| 17 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 18 | |
Greg Ward | 1993f9a | 2000-02-18 00:13:53 +0000 | [diff] [blame] | 19 | class build (Command): |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 20 | |
Greg Ward | 37bc815 | 2000-01-30 18:34:15 +0000 | [diff] [blame] | 21 | description = "build everything needed to install" |
| 22 | |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 23 | user_options = [ |
| 24 | ('build-base=', 'b', |
| 25 | "base directory for build library"), |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 26 | ('build-purelib=', None, |
| 27 | "build directory for platform-neutral distributions"), |
| 28 | ('build-platlib=', None, |
| 29 | "build directory for platform-specific distributions"), |
| 30 | ('build-lib=', None, |
| 31 | "build directory for all distribution (defaults to either " + |
| 32 | "build-purelib or build-platlib"), |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 33 | ('build-scripts=', None, |
| 34 | "build directory for scripts"), |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 35 | ('build-temp=', 't', |
| 36 | "temporary build directory"), |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 37 | ('compiler=', 'c', |
| 38 | "specify the compiler type"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 39 | ('debug', 'g', |
| 40 | "compile extensions and libraries with debugging information"), |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 41 | ('force', 'f', |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 42 | "forcibly build everything (ignore file timestamps)"), |
Greg Ward | bbeceea | 2000-02-18 00:25:39 +0000 | [diff] [blame] | 43 | ] |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 44 | |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 45 | help_options = [ |
| 46 | ('help-compiler', None, |
Greg Ward | 2ff7887 | 2000-06-24 00:23:20 +0000 | [diff] [blame] | 47 | "list available compilers", show_compilers), |
Greg Ward | 9d17a7a | 2000-06-07 03:00:06 +0000 | [diff] [blame] | 48 | ] |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 49 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 50 | def initialize_options (self): |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 51 | self.build_base = 'build' |
| 52 | # these are decided only after 'build_base' has its final value |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 53 | # (unless overridden by the user or client) |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 54 | self.build_purelib = None |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 55 | self.build_platlib = None |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 56 | self.build_lib = None |
| 57 | self.build_temp = None |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 58 | self.build_scripts = None |
Gregory P. Smith | 9668b78 | 2000-05-12 00:33:14 +0000 | [diff] [blame] | 59 | self.compiler = None |
Greg Ward | 3246200 | 2000-02-09 02:19:49 +0000 | [diff] [blame] | 60 | self.debug = None |
Greg Ward | c41d6b3 | 2000-04-10 00:19:42 +0000 | [diff] [blame] | 61 | self.force = 0 |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 62 | |
Greg Ward | e01149c | 2000-02-18 00:35:22 +0000 | [diff] [blame] | 63 | def finalize_options (self): |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 64 | |
| 65 | # Need this to name platform-specific directories, but sys.platform |
| 66 | # is not enough -- it only names the OS and version, not the |
| 67 | # hardware architecture! |
| 68 | self.plat = get_platform () |
| 69 | |
| 70 | # 'build_purelib' and 'build_platlib' just default to 'lib' and |
| 71 | # 'lib.<plat>' under the base build directory. We only use one of |
| 72 | # them for a given distribution, though -- |
| 73 | if self.build_purelib is None: |
| 74 | self.build_purelib = os.path.join (self.build_base, 'lib') |
Greg Ward | e6ac2fc | 1999-09-29 12:38:18 +0000 | [diff] [blame] | 75 | if self.build_platlib is None: |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 76 | self.build_platlib = os.path.join (self.build_base, |
| 77 | 'lib.' + self.plat) |
| 78 | |
| 79 | # 'build_lib' is the actual directory that we will use for this |
| 80 | # particular module distribution -- if user didn't supply it, pick |
| 81 | # one of 'build_purelib' or 'build_platlib'. |
| 82 | if self.build_lib is None: |
| 83 | if self.distribution.ext_modules: |
| 84 | self.build_lib = self.build_platlib |
| 85 | else: |
| 86 | self.build_lib = self.build_purelib |
| 87 | |
| 88 | # 'build_temp' -- temporary directory for compiler turds, |
| 89 | # "build/temp.<plat>" |
| 90 | if self.build_temp is None: |
| 91 | self.build_temp = os.path.join (self.build_base, |
| 92 | 'temp.' + self.plat) |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 93 | if self.build_scripts is None: |
| 94 | self.build_scripts = os.path.join (self.build_base, 'scripts') |
Greg Ward | 42a3bf5 | 2000-03-01 01:26:45 +0000 | [diff] [blame] | 95 | # finalize_options () |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | def run (self): |
| 99 | |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 100 | # For now, "build" means "build_py" then "build_ext". (Eventually |
| 101 | # it should also build documentation.) |
| 102 | |
Greg Ward | 02e1c56 | 1999-09-21 18:27:55 +0000 | [diff] [blame] | 103 | # Invoke the 'build_py' command to "build" pure Python modules |
| 104 | # (ie. copy 'em into the build tree) |
Greg Ward | ae45b16 | 2000-03-29 02:14:21 +0000 | [diff] [blame] | 105 | if self.distribution.has_pure_modules(): |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 106 | self.run_command ('build_py') |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 107 | |
Greg Ward | 5f7c18e | 2000-02-05 02:24:16 +0000 | [diff] [blame] | 108 | # Build any standalone C libraries next -- they're most likely to |
| 109 | # be needed by extension modules, so obviously have to be done |
| 110 | # first! |
Greg Ward | ae45b16 | 2000-03-29 02:14:21 +0000 | [diff] [blame] | 111 | if self.distribution.has_c_libraries(): |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 112 | self.run_command ('build_clib') |
Greg Ward | 5f7c18e | 2000-02-05 02:24:16 +0000 | [diff] [blame] | 113 | |
Greg Ward | 02e1c56 | 1999-09-21 18:27:55 +0000 | [diff] [blame] | 114 | # And now 'build_ext' -- compile extension modules and put them |
| 115 | # into the build tree |
Greg Ward | ae45b16 | 2000-03-29 02:14:21 +0000 | [diff] [blame] | 116 | if self.distribution.has_ext_modules(): |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 117 | self.run_command ('build_ext') |
Greg Ward | 13ae1c8 | 1999-03-22 14:55:25 +0000 | [diff] [blame] | 118 | |
Greg Ward | e3d1752 | 2000-05-25 01:21:54 +0000 | [diff] [blame] | 119 | if self.distribution.has_scripts(): |
Greg Ward | 4fb29e5 | 2000-05-27 17:27:23 +0000 | [diff] [blame] | 120 | self.run_command ('build_scripts') |
Greg Ward | 8d5881a | 2000-05-25 01:19:18 +0000 | [diff] [blame] | 121 | |
Greg Ward | fcd974e | 2000-05-25 01:10:04 +0000 | [diff] [blame] | 122 | # class build |