blob: 4fe95b0cfb0d2cd0d5368d69538f200b039cfd31 [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
Greg Ward42a3bf52000-03-01 01:26:45 +00009from distutils.util import get_platform
Greg Ward34593812000-06-24 01:23:37 +000010
11
Collin Winter5b7e9d72007-08-30 03:52:21 +000012def show_compilers():
Greg Ward34593812000-06-24 01:23:37 +000013 from distutils.ccompiler import show_compilers
14 show_compilers()
15
Greg Ward13ae1c81999-03-22 14:55:25 +000016
Collin Winter5b7e9d72007-08-30 03:52:21 +000017class build(Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000018
Greg Ward37bc8152000-01-30 18:34:15 +000019 description = "build everything needed to install"
20
Greg Wardbbeceea2000-02-18 00:25:39 +000021 user_options = [
22 ('build-base=', 'b',
23 "base directory for build library"),
Greg Ward42a3bf52000-03-01 01:26:45 +000024 ('build-purelib=', None,
25 "build directory for platform-neutral distributions"),
26 ('build-platlib=', None,
27 "build directory for platform-specific distributions"),
28 ('build-lib=', None,
29 "build directory for all distribution (defaults to either " +
30 "build-purelib or build-platlib"),
Greg Ward8d5881a2000-05-25 01:19:18 +000031 ('build-scripts=', None,
32 "build directory for scripts"),
Greg Ward42a3bf52000-03-01 01:26:45 +000033 ('build-temp=', 't',
34 "temporary build directory"),
Gregory P. Smith9668b782000-05-12 00:33:14 +000035 ('compiler=', 'c',
36 "specify the compiler type"),
Greg Wardbbeceea2000-02-18 00:25:39 +000037 ('debug', 'g',
38 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000039 ('force', 'f',
Gregory P. Smith9668b782000-05-12 00:33:14 +000040 "forcibly build everything (ignore file timestamps)"),
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000041 ('executable=', 'e',
42 "specify final destination interpreter path (build.py)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000043 ]
Greg Ward2ff78872000-06-24 00:23:20 +000044
Greg Ward99b032e2000-09-25 01:41:15 +000045 boolean_options = ['debug', 'force']
46
Greg Ward9d17a7a2000-06-07 03:00:06 +000047 help_options = [
48 ('help-compiler', None,
Greg Ward2ff78872000-06-24 00:23:20 +000049 "list available compilers", show_compilers),
Greg Wardfa9ff762000-10-14 04:06:40 +000050 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000051
Collin Winter5b7e9d72007-08-30 03:52:21 +000052 def initialize_options(self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000053 self.build_base = 'build'
54 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000055 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000056 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000057 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000058 self.build_lib = None
59 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000060 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000061 self.compiler = None
Greg Ward32462002000-02-09 02:19:49 +000062 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000063 self.force = 0
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000064 self.executable = None
Greg Ward13ae1c81999-03-22 14:55:25 +000065
Collin Winter5b7e9d72007-08-30 03:52:21 +000066 def finalize_options(self):
Greg Ward53db8152000-09-16 02:06:45 +000067 plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
Greg Ward42900942000-09-16 01:54:46 +000068
Georg Brandl86def6c2008-01-21 20:36:10 +000069 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
70 # share the same build directories. Doing so confuses the build
71 # process for C modules
72 if hasattr(sys, 'gettotalrefcount'):
73 plat_specifier += '-pydebug'
74
Greg Ward42a3bf52000-03-01 01:26:45 +000075 # 'build_purelib' and 'build_platlib' just default to 'lib' and
76 # 'lib.<plat>' under the base build directory. We only use one of
77 # them for a given distribution, though --
78 if self.build_purelib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000079 self.build_purelib = os.path.join(self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000080 if self.build_platlib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000081 self.build_platlib = os.path.join(self.build_base,
82 'lib' + plat_specifier)
Greg Ward42a3bf52000-03-01 01:26:45 +000083
84 # 'build_lib' is the actual directory that we will use for this
85 # particular module distribution -- if user didn't supply it, pick
86 # one of 'build_purelib' or 'build_platlib'.
87 if self.build_lib is None:
88 if self.distribution.ext_modules:
89 self.build_lib = self.build_platlib
90 else:
91 self.build_lib = self.build_purelib
92
93 # 'build_temp' -- temporary directory for compiler turds,
94 # "build/temp.<plat>"
95 if self.build_temp is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000096 self.build_temp = os.path.join(self.build_base,
97 'temp' + plat_specifier)
Greg Ward8d5881a2000-05-25 01:19:18 +000098 if self.build_scripts is None:
Michael W. Hudson49bdaed2001-12-10 15:28:30 +000099 self.build_scripts = os.path.join(self.build_base,
100 'scripts-' + sys.version[0:3])
Greg Ward53db8152000-09-16 02:06:45 +0000101
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +0000102 if self.executable is None:
103 self.executable = os.path.normpath(sys.executable)
Greg Ward13ae1c81999-03-22 14:55:25 +0000104
Collin Winter5b7e9d72007-08-30 03:52:21 +0000105 def run(self):
Greg Ward64d855a2000-09-30 17:08:12 +0000106 # Run all relevant sub-commands. This will be some subset of:
107 # - build_py - pure Python modules
108 # - build_clib - standalone C libraries
109 # - build_ext - Python extensions
110 # - build_scripts - (Python) scripts
111 for cmd_name in self.get_sub_commands():
112 self.run_command(cmd_name)
Greg Ward13ae1c81999-03-22 14:55:25 +0000113
Greg Ward13ae1c81999-03-22 14:55:25 +0000114
Greg Ward64d855a2000-09-30 17:08:12 +0000115 # -- Predicates for the sub-command list ---------------------------
Greg Ward5f7c18e2000-02-05 02:24:16 +0000116
Collin Winter5b7e9d72007-08-30 03:52:21 +0000117 def has_pure_modules(self):
Greg Ward64d855a2000-09-30 17:08:12 +0000118 return self.distribution.has_pure_modules()
Greg Ward13ae1c81999-03-22 14:55:25 +0000119
Collin Winter5b7e9d72007-08-30 03:52:21 +0000120 def has_c_libraries(self):
Greg Ward64d855a2000-09-30 17:08:12 +0000121 return self.distribution.has_c_libraries()
122
Collin Winter5b7e9d72007-08-30 03:52:21 +0000123 def has_ext_modules(self):
Greg Ward64d855a2000-09-30 17:08:12 +0000124 return self.distribution.has_ext_modules()
125
Collin Winter5b7e9d72007-08-30 03:52:21 +0000126 def has_scripts(self):
Greg Ward64d855a2000-09-30 17:08:12 +0000127 return self.distribution.has_scripts()
128
129
130 sub_commands = [('build_py', has_pure_modules),
131 ('build_clib', has_c_libraries),
132 ('build_ext', has_ext_modules),
133 ('build_scripts', has_scripts),
134 ]