blob: d9eed7685c4ac4de059b8445dadeb8be0ee315ef [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"),
Greg Ward8d5881a2000-05-25 01:19:18 +000027 ('build-scripts=', None,
28 "build directory for scripts"),
Greg Ward42a3bf52000-03-01 01:26:45 +000029 ('build-temp=', 't',
30 "temporary build directory"),
Gregory P. Smith9668b782000-05-12 00:33:14 +000031 ('compiler=', 'c',
32 "specify the compiler type"),
Greg Wardbbeceea2000-02-18 00:25:39 +000033 ('debug', 'g',
34 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000035 ('force', 'f',
Gregory P. Smith9668b782000-05-12 00:33:14 +000036 "forcibly build everything (ignore file timestamps)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000037 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000038
Greg Warde01149c2000-02-18 00:35:22 +000039 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000040 self.build_base = 'build'
41 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000042 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000043 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000044 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000045 self.build_lib = None
46 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000047 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000048 self.compiler = None
Greg Ward32462002000-02-09 02:19:49 +000049 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000050 self.force = 0
Greg Ward13ae1c81999-03-22 14:55:25 +000051
Greg Warde01149c2000-02-18 00:35:22 +000052 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000053
54 # Need this to name platform-specific directories, but sys.platform
55 # is not enough -- it only names the OS and version, not the
56 # hardware architecture!
57 self.plat = get_platform ()
58
59 # 'build_purelib' and 'build_platlib' just default to 'lib' and
60 # 'lib.<plat>' under the base build directory. We only use one of
61 # them for a given distribution, though --
62 if self.build_purelib is None:
63 self.build_purelib = os.path.join (self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000064 if self.build_platlib is None:
Greg Ward42a3bf52000-03-01 01:26:45 +000065 self.build_platlib = os.path.join (self.build_base,
66 'lib.' + self.plat)
67
68 # 'build_lib' is the actual directory that we will use for this
69 # particular module distribution -- if user didn't supply it, pick
70 # one of 'build_purelib' or 'build_platlib'.
71 if self.build_lib is None:
72 if self.distribution.ext_modules:
73 self.build_lib = self.build_platlib
74 else:
75 self.build_lib = self.build_purelib
76
77 # 'build_temp' -- temporary directory for compiler turds,
78 # "build/temp.<plat>"
79 if self.build_temp is None:
80 self.build_temp = os.path.join (self.build_base,
81 'temp.' + self.plat)
Greg Ward8d5881a2000-05-25 01:19:18 +000082 if self.build_scripts is None:
83 self.build_scripts = os.path.join (self.build_base, 'scripts')
Greg Ward42a3bf52000-03-01 01:26:45 +000084 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +000085
86
87 def run (self):
88
Greg Ward13ae1c81999-03-22 14:55:25 +000089 # For now, "build" means "build_py" then "build_ext". (Eventually
90 # it should also build documentation.)
91
Greg Ward02e1c561999-09-21 18:27:55 +000092 # Invoke the 'build_py' command to "build" pure Python modules
93 # (ie. copy 'em into the build tree)
Greg Wardae45b162000-03-29 02:14:21 +000094 if self.distribution.has_pure_modules():
Greg Ward02e1c561999-09-21 18:27:55 +000095 self.run_peer ('build_py')
Greg Ward13ae1c81999-03-22 14:55:25 +000096
Greg Ward5f7c18e2000-02-05 02:24:16 +000097 # Build any standalone C libraries next -- they're most likely to
98 # be needed by extension modules, so obviously have to be done
99 # first!
Greg Wardae45b162000-03-29 02:14:21 +0000100 if self.distribution.has_c_libraries():
Greg Ward76ec0d62000-03-02 01:57:12 +0000101 self.run_peer ('build_clib')
Greg Ward5f7c18e2000-02-05 02:24:16 +0000102
Greg Ward02e1c561999-09-21 18:27:55 +0000103 # And now 'build_ext' -- compile extension modules and put them
104 # into the build tree
Greg Wardae45b162000-03-29 02:14:21 +0000105 if self.distribution.has_ext_modules():
Greg Ward02e1c561999-09-21 18:27:55 +0000106 self.run_peer ('build_ext')
Greg Ward13ae1c81999-03-22 14:55:25 +0000107
Greg Warde3d17522000-05-25 01:21:54 +0000108 if self.distribution.has_scripts():
Greg Ward8d5881a2000-05-25 01:19:18 +0000109 self.run_peer ('build_scripts')
110
Greg Wardfcd974e2000-05-25 01:10:04 +0000111# class build