blob: 1d901282add73caef09530ca9babb82e7ec8a9b1 [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 Ward34593812000-06-24 01:23:37 +000012
13
14def show_compilers ():
15 from distutils.ccompiler import show_compilers
16 show_compilers()
17
Greg Ward13ae1c81999-03-22 14:55:25 +000018
Greg Ward1993f9a2000-02-18 00:13:53 +000019class build (Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000020
Greg Ward37bc8152000-01-30 18:34:15 +000021 description = "build everything needed to install"
22
Greg Wardbbeceea2000-02-18 00:25:39 +000023 user_options = [
24 ('build-base=', 'b',
25 "base directory for build library"),
Greg Ward42a3bf52000-03-01 01:26:45 +000026 ('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 Ward8d5881a2000-05-25 01:19:18 +000033 ('build-scripts=', None,
34 "build directory for scripts"),
Greg Ward42a3bf52000-03-01 01:26:45 +000035 ('build-temp=', 't',
36 "temporary build directory"),
Gregory P. Smith9668b782000-05-12 00:33:14 +000037 ('compiler=', 'c',
38 "specify the compiler type"),
Greg Wardbbeceea2000-02-18 00:25:39 +000039 ('debug', 'g',
40 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000041 ('force', 'f',
Gregory P. Smith9668b782000-05-12 00:33:14 +000042 "forcibly build everything (ignore file timestamps)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000043 ]
Greg Ward2ff78872000-06-24 00:23:20 +000044
Greg Ward9d17a7a2000-06-07 03:00:06 +000045 help_options = [
46 ('help-compiler', None,
Greg Ward2ff78872000-06-24 00:23:20 +000047 "list available compilers", show_compilers),
Greg Ward9d17a7a2000-06-07 03:00:06 +000048 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000049
Greg Warde01149c2000-02-18 00:35:22 +000050 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000051 self.build_base = 'build'
52 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000053 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000054 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000055 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000056 self.build_lib = None
57 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000058 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000059 self.compiler = None
Greg Ward32462002000-02-09 02:19:49 +000060 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000061 self.force = 0
Greg Ward13ae1c81999-03-22 14:55:25 +000062
Greg Warde01149c2000-02-18 00:35:22 +000063 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000064
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
Greg Ward42900942000-09-16 01:54:46 +000070 plat_specifier = sys.version[0:3] + '-' + self.plat
71
Greg Ward42a3bf52000-03-01 01:26:45 +000072 # 'build_purelib' and 'build_platlib' just default to 'lib' and
73 # 'lib.<plat>' under the base build directory. We only use one of
74 # them for a given distribution, though --
75 if self.build_purelib is None:
76 self.build_purelib = os.path.join (self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000077 if self.build_platlib is None:
Greg Ward42a3bf52000-03-01 01:26:45 +000078 self.build_platlib = os.path.join (self.build_base,
Greg Ward42900942000-09-16 01:54:46 +000079 'lib-' + plat_specifier)
Greg Ward42a3bf52000-03-01 01:26:45 +000080
81 # 'build_lib' is the actual directory that we will use for this
82 # particular module distribution -- if user didn't supply it, pick
83 # one of 'build_purelib' or 'build_platlib'.
84 if self.build_lib is None:
85 if self.distribution.ext_modules:
86 self.build_lib = self.build_platlib
87 else:
88 self.build_lib = self.build_purelib
89
90 # 'build_temp' -- temporary directory for compiler turds,
91 # "build/temp.<plat>"
92 if self.build_temp is None:
93 self.build_temp = os.path.join (self.build_base,
Greg Ward42900942000-09-16 01:54:46 +000094 'temp-' + plat_specifier)
Greg Ward8d5881a2000-05-25 01:19:18 +000095 if self.build_scripts is None:
96 self.build_scripts = os.path.join (self.build_base, 'scripts')
Greg Ward42a3bf52000-03-01 01:26:45 +000097 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +000098
99
100 def run (self):
101
Greg Ward13ae1c81999-03-22 14:55:25 +0000102 # For now, "build" means "build_py" then "build_ext". (Eventually
103 # it should also build documentation.)
104
Greg Ward02e1c561999-09-21 18:27:55 +0000105 # Invoke the 'build_py' command to "build" pure Python modules
106 # (ie. copy 'em into the build tree)
Greg Wardae45b162000-03-29 02:14:21 +0000107 if self.distribution.has_pure_modules():
Greg Ward4fb29e52000-05-27 17:27:23 +0000108 self.run_command ('build_py')
Greg Ward13ae1c81999-03-22 14:55:25 +0000109
Greg Ward5f7c18e2000-02-05 02:24:16 +0000110 # Build any standalone C libraries next -- they're most likely to
111 # be needed by extension modules, so obviously have to be done
112 # first!
Greg Wardae45b162000-03-29 02:14:21 +0000113 if self.distribution.has_c_libraries():
Greg Ward4fb29e52000-05-27 17:27:23 +0000114 self.run_command ('build_clib')
Greg Ward5f7c18e2000-02-05 02:24:16 +0000115
Greg Ward02e1c561999-09-21 18:27:55 +0000116 # And now 'build_ext' -- compile extension modules and put them
117 # into the build tree
Greg Wardae45b162000-03-29 02:14:21 +0000118 if self.distribution.has_ext_modules():
Greg Ward4fb29e52000-05-27 17:27:23 +0000119 self.run_command ('build_ext')
Greg Ward13ae1c81999-03-22 14:55:25 +0000120
Greg Warde3d17522000-05-25 01:21:54 +0000121 if self.distribution.has_scripts():
Greg Ward4fb29e52000-05-27 17:27:23 +0000122 self.run_command ('build_scripts')
Greg Ward8d5881a2000-05-25 01:19:18 +0000123
Greg Wardfcd974e2000-05-25 01:10:04 +0000124# class build