blob: 7fb0b566573ec2ff6a7aecddbc21345dfcedf5a0 [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001"""distutils.command.build
2
3Implements the Distutils 'build' command."""
4
5# created 1999/03/08, Greg Ward
6
Greg Ward3ce77fd2000-03-02 01:49:45 +00007__revision__ = "$Id$"
Greg Ward13ae1c81999-03-22 14:55:25 +00008
Greg Ward42a3bf52000-03-01 01:26:45 +00009import sys, os
Greg Ward13ae1c81999-03-22 14:55:25 +000010from distutils.core import Command
Greg Ward42a3bf52000-03-01 01:26:45 +000011from distutils.util import get_platform
Greg Ward13ae1c81999-03-22 14:55:25 +000012
Greg Ward1993f9a2000-02-18 00:13:53 +000013class build (Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000014
Greg Ward37bc8152000-01-30 18:34:15 +000015 description = "build everything needed to install"
16
Greg Wardbbeceea2000-02-18 00:25:39 +000017 user_options = [
18 ('build-base=', 'b',
19 "base directory for build library"),
Greg Ward42a3bf52000-03-01 01:26:45 +000020 ('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 Wardbbeceea2000-02-18 00:25:39 +000029 ('debug', 'g',
30 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000031 ('force', 'f',
32 "forcibly build everything (ignore file timestamps"),
Greg Wardbbeceea2000-02-18 00:25:39 +000033 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000034
Greg Warde01149c2000-02-18 00:35:22 +000035 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000036 self.build_base = 'build'
37 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000038 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000039 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000040 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000041 self.build_lib = None
42 self.build_temp = None
Greg Ward32462002000-02-09 02:19:49 +000043 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000044 self.force = 0
Greg Ward13ae1c81999-03-22 14:55:25 +000045
Greg Warde01149c2000-02-18 00:35:22 +000046 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000047
48 # Need this to name platform-specific directories, but sys.platform
49 # is not enough -- it only names the OS and version, not the
50 # hardware architecture!
51 self.plat = get_platform ()
52
53 # 'build_purelib' and 'build_platlib' just default to 'lib' and
54 # 'lib.<plat>' under the base build directory. We only use one of
55 # them for a given distribution, though --
56 if self.build_purelib is None:
57 self.build_purelib = os.path.join (self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000058 if self.build_platlib is None:
Greg Ward42a3bf52000-03-01 01:26:45 +000059 self.build_platlib = os.path.join (self.build_base,
60 'lib.' + self.plat)
61
62 # 'build_lib' is the actual directory that we will use for this
63 # particular module distribution -- if user didn't supply it, pick
64 # one of 'build_purelib' or 'build_platlib'.
65 if self.build_lib is None:
66 if self.distribution.ext_modules:
67 self.build_lib = self.build_platlib
68 else:
69 self.build_lib = self.build_purelib
70
71 # 'build_temp' -- temporary directory for compiler turds,
72 # "build/temp.<plat>"
73 if self.build_temp is None:
74 self.build_temp = os.path.join (self.build_base,
75 'temp.' + self.plat)
76 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +000077
78
79 def run (self):
80
Greg Ward13ae1c81999-03-22 14:55:25 +000081 # For now, "build" means "build_py" then "build_ext". (Eventually
82 # it should also build documentation.)
83
Greg Ward02e1c561999-09-21 18:27:55 +000084 # Invoke the 'build_py' command to "build" pure Python modules
85 # (ie. copy 'em into the build tree)
Greg Wardae45b162000-03-29 02:14:21 +000086 if self.distribution.has_pure_modules():
Greg Ward02e1c561999-09-21 18:27:55 +000087 self.run_peer ('build_py')
Greg Ward13ae1c81999-03-22 14:55:25 +000088
Greg Ward5f7c18e2000-02-05 02:24:16 +000089 # Build any standalone C libraries next -- they're most likely to
90 # be needed by extension modules, so obviously have to be done
91 # first!
Greg Wardae45b162000-03-29 02:14:21 +000092 if self.distribution.has_c_libraries():
Greg Ward76ec0d62000-03-02 01:57:12 +000093 self.run_peer ('build_clib')
Greg Ward5f7c18e2000-02-05 02:24:16 +000094
Greg Ward02e1c561999-09-21 18:27:55 +000095 # And now 'build_ext' -- compile extension modules and put them
96 # into the build tree
Greg Wardae45b162000-03-29 02:14:21 +000097 if self.distribution.has_ext_modules():
Greg Ward02e1c561999-09-21 18:27:55 +000098 self.run_peer ('build_ext')
Greg Ward13ae1c81999-03-22 14:55:25 +000099
100# end class Build