blob: 84e050204e145a35abb98d92c87c028c936d4fa7 [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001"""distutils.command.build
2
3Implements the Distutils 'build' command."""
4
Greg Ward3ce77fd2000-03-02 01:49:45 +00005__revision__ = "$Id$"
Greg Ward13ae1c81999-03-22 14:55:25 +00006
Greg Ward42a3bf52000-03-01 01:26:45 +00007import sys, os
Greg Ward13ae1c81999-03-22 14:55:25 +00008from distutils.core import Command
Mark Hammond495cf992008-04-07 01:53:39 +00009from distutils.errors import DistutilsOptionError
Greg Ward42a3bf52000-03-01 01:26:45 +000010from distutils.util import get_platform
Greg Ward34593812000-06-24 01:23:37 +000011
12
13def show_compilers ():
14 from distutils.ccompiler import show_compilers
15 show_compilers()
16
Greg Ward13ae1c81999-03-22 14:55:25 +000017
Greg Ward1993f9a2000-02-18 00:13:53 +000018class build (Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000019
Greg Ward37bc8152000-01-30 18:34:15 +000020 description = "build everything needed to install"
21
Greg Wardbbeceea2000-02-18 00:25:39 +000022 user_options = [
23 ('build-base=', 'b',
24 "base directory for build library"),
Greg Ward42a3bf52000-03-01 01:26:45 +000025 ('build-purelib=', None,
26 "build directory for platform-neutral distributions"),
27 ('build-platlib=', None,
28 "build directory for platform-specific distributions"),
29 ('build-lib=', None,
30 "build directory for all distribution (defaults to either " +
31 "build-purelib or build-platlib"),
Greg Ward8d5881a2000-05-25 01:19:18 +000032 ('build-scripts=', None,
33 "build directory for scripts"),
Greg Ward42a3bf52000-03-01 01:26:45 +000034 ('build-temp=', 't',
35 "temporary build directory"),
Mark Hammond495cf992008-04-07 01:53:39 +000036 ('plat-name=', 'p',
37 "platform name to build for, if supported "
38 "(default: %s)" % get_platform()),
Gregory P. Smith9668b782000-05-12 00:33:14 +000039 ('compiler=', 'c',
40 "specify the compiler type"),
Greg Wardbbeceea2000-02-18 00:25:39 +000041 ('debug', 'g',
42 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000043 ('force', 'f',
Gregory P. Smith9668b782000-05-12 00:33:14 +000044 "forcibly build everything (ignore file timestamps)"),
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000045 ('executable=', 'e',
46 "specify final destination interpreter path (build.py)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000047 ]
Greg Ward2ff78872000-06-24 00:23:20 +000048
Greg Ward99b032e2000-09-25 01:41:15 +000049 boolean_options = ['debug', 'force']
50
Greg Ward9d17a7a2000-06-07 03:00:06 +000051 help_options = [
52 ('help-compiler', None,
Greg Ward2ff78872000-06-24 00:23:20 +000053 "list available compilers", show_compilers),
Greg Wardfa9ff762000-10-14 04:06:40 +000054 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000055
Greg Warde01149c2000-02-18 00:35:22 +000056 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000057 self.build_base = 'build'
58 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000059 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000060 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000061 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000062 self.build_lib = None
63 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000064 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000065 self.compiler = None
Mark Hammond495cf992008-04-07 01:53:39 +000066 self.plat_name = None
Greg Ward32462002000-02-09 02:19:49 +000067 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000068 self.force = 0
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000069 self.executable = None
Greg Ward13ae1c81999-03-22 14:55:25 +000070
Greg Warde01149c2000-02-18 00:35:22 +000071 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000072
Mark Hammond495cf992008-04-07 01:53:39 +000073 if self.plat_name is None:
74 self.plat_name = get_platform()
75 else:
76 # plat-name only supported for windows (other platforms are
77 # supported via ./configure flags, if at all). Avoid misleading
78 # other platforms.
79 if os.name != 'nt':
80 raise DistutilsOptionError(
81 "--plat-name only supported on Windows (try "
82 "using './configure --help' on your platform)")
83
84 plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
Greg Ward42900942000-09-16 01:54:46 +000085
Georg Brandl50160152008-01-21 17:42:40 +000086 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
87 # share the same build directories. Doing so confuses the build
88 # process for C modules
89 if hasattr(sys, 'gettotalrefcount'):
90 plat_specifier += '-pydebug'
91
Greg Ward42a3bf52000-03-01 01:26:45 +000092 # 'build_purelib' and 'build_platlib' just default to 'lib' and
93 # 'lib.<plat>' under the base build directory. We only use one of
94 # them for a given distribution, though --
95 if self.build_purelib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000096 self.build_purelib = os.path.join(self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000097 if self.build_platlib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000098 self.build_platlib = os.path.join(self.build_base,
99 'lib' + plat_specifier)
Greg Ward42a3bf52000-03-01 01:26:45 +0000100
101 # 'build_lib' is the actual directory that we will use for this
102 # particular module distribution -- if user didn't supply it, pick
103 # one of 'build_purelib' or 'build_platlib'.
104 if self.build_lib is None:
105 if self.distribution.ext_modules:
106 self.build_lib = self.build_platlib
107 else:
108 self.build_lib = self.build_purelib
109
110 # 'build_temp' -- temporary directory for compiler turds,
111 # "build/temp.<plat>"
112 if self.build_temp is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000113 self.build_temp = os.path.join(self.build_base,
114 'temp' + plat_specifier)
Greg Ward8d5881a2000-05-25 01:19:18 +0000115 if self.build_scripts is None:
Michael W. Hudson49bdaed2001-12-10 15:28:30 +0000116 self.build_scripts = os.path.join(self.build_base,
117 'scripts-' + sys.version[0:3])
Greg Ward53db8152000-09-16 02:06:45 +0000118
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +0000119 if self.executable is None:
120 self.executable = os.path.normpath(sys.executable)
Greg Ward42a3bf52000-03-01 01:26:45 +0000121 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +0000122
123
124 def run (self):
125
Greg Ward64d855a2000-09-30 17:08:12 +0000126 # Run all relevant sub-commands. This will be some subset of:
127 # - build_py - pure Python modules
128 # - build_clib - standalone C libraries
129 # - build_ext - Python extensions
130 # - build_scripts - (Python) scripts
131 for cmd_name in self.get_sub_commands():
132 self.run_command(cmd_name)
Greg Ward13ae1c81999-03-22 14:55:25 +0000133
Greg Ward13ae1c81999-03-22 14:55:25 +0000134
Greg Ward64d855a2000-09-30 17:08:12 +0000135 # -- Predicates for the sub-command list ---------------------------
Greg Ward5f7c18e2000-02-05 02:24:16 +0000136
Greg Ward64d855a2000-09-30 17:08:12 +0000137 def has_pure_modules (self):
138 return self.distribution.has_pure_modules()
Greg Ward13ae1c81999-03-22 14:55:25 +0000139
Greg Ward64d855a2000-09-30 17:08:12 +0000140 def has_c_libraries (self):
141 return self.distribution.has_c_libraries()
142
143 def has_ext_modules (self):
144 return self.distribution.has_ext_modules()
145
146 def has_scripts (self):
147 return self.distribution.has_scripts()
148
149
150 sub_commands = [('build_py', has_pure_modules),
151 ('build_clib', has_c_libraries),
152 ('build_ext', has_ext_modules),
153 ('build_scripts', has_scripts),
154 ]
Greg Ward8d5881a2000-05-25 01:19:18 +0000155
Greg Wardfcd974e2000-05-25 01:10:04 +0000156# class build