blob: 7462e9348fcddb271b7e12800b2696cf46d0fcbb [file] [log] [blame]
Greg Ward13ae1c81999-03-22 14:55:25 +00001"""distutils.command.build
2
3Implements the Distutils 'build' command."""
4
Martin v. Löwis5a6601c2004-11-10 22:23:15 +00005# This module should be kept compatible with Python 2.1.
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +00006
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
Mark Hammond495cf992008-04-07 01:53:39 +000011from distutils.errors import DistutilsOptionError
Greg Ward42a3bf52000-03-01 01:26:45 +000012from distutils.util import get_platform
Greg Ward34593812000-06-24 01:23:37 +000013
14
15def show_compilers ():
16 from distutils.ccompiler import show_compilers
17 show_compilers()
18
Greg Ward13ae1c81999-03-22 14:55:25 +000019
Greg Ward1993f9a2000-02-18 00:13:53 +000020class build (Command):
Greg Ward13ae1c81999-03-22 14:55:25 +000021
Greg Ward37bc8152000-01-30 18:34:15 +000022 description = "build everything needed to install"
23
Greg Wardbbeceea2000-02-18 00:25:39 +000024 user_options = [
25 ('build-base=', 'b',
26 "base directory for build library"),
Greg Ward42a3bf52000-03-01 01:26:45 +000027 ('build-purelib=', None,
28 "build directory for platform-neutral distributions"),
29 ('build-platlib=', None,
30 "build directory for platform-specific distributions"),
31 ('build-lib=', None,
32 "build directory for all distribution (defaults to either " +
33 "build-purelib or build-platlib"),
Greg Ward8d5881a2000-05-25 01:19:18 +000034 ('build-scripts=', None,
35 "build directory for scripts"),
Greg Ward42a3bf52000-03-01 01:26:45 +000036 ('build-temp=', 't',
37 "temporary build directory"),
Mark Hammond495cf992008-04-07 01:53:39 +000038 ('plat-name=', 'p',
39 "platform name to build for, if supported "
40 "(default: %s)" % get_platform()),
Gregory P. Smith9668b782000-05-12 00:33:14 +000041 ('compiler=', 'c',
42 "specify the compiler type"),
Greg Wardbbeceea2000-02-18 00:25:39 +000043 ('debug', 'g',
44 "compile extensions and libraries with debugging information"),
Greg Wardc41d6b32000-04-10 00:19:42 +000045 ('force', 'f',
Gregory P. Smith9668b782000-05-12 00:33:14 +000046 "forcibly build everything (ignore file timestamps)"),
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000047 ('executable=', 'e',
48 "specify final destination interpreter path (build.py)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000049 ]
Greg Ward2ff78872000-06-24 00:23:20 +000050
Greg Ward99b032e2000-09-25 01:41:15 +000051 boolean_options = ['debug', 'force']
52
Greg Ward9d17a7a2000-06-07 03:00:06 +000053 help_options = [
54 ('help-compiler', None,
Greg Ward2ff78872000-06-24 00:23:20 +000055 "list available compilers", show_compilers),
Greg Wardfa9ff762000-10-14 04:06:40 +000056 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000057
Greg Warde01149c2000-02-18 00:35:22 +000058 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000059 self.build_base = 'build'
60 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000061 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000062 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000063 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000064 self.build_lib = None
65 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000066 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000067 self.compiler = None
Mark Hammond495cf992008-04-07 01:53:39 +000068 self.plat_name = None
Greg Ward32462002000-02-09 02:19:49 +000069 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000070 self.force = 0
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000071 self.executable = None
Greg Ward13ae1c81999-03-22 14:55:25 +000072
Greg Warde01149c2000-02-18 00:35:22 +000073 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000074
Mark Hammond495cf992008-04-07 01:53:39 +000075 if self.plat_name is None:
76 self.plat_name = get_platform()
77 else:
78 # plat-name only supported for windows (other platforms are
79 # supported via ./configure flags, if at all). Avoid misleading
80 # other platforms.
81 if os.name != 'nt':
82 raise DistutilsOptionError(
83 "--plat-name only supported on Windows (try "
84 "using './configure --help' on your platform)")
85
86 plat_specifier = ".%s-%s" % (self.plat_name, sys.version[0:3])
Greg Ward42900942000-09-16 01:54:46 +000087
Georg Brandl50160152008-01-21 17:42:40 +000088 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
89 # share the same build directories. Doing so confuses the build
90 # process for C modules
91 if hasattr(sys, 'gettotalrefcount'):
92 plat_specifier += '-pydebug'
93
Greg Ward42a3bf52000-03-01 01:26:45 +000094 # 'build_purelib' and 'build_platlib' just default to 'lib' and
95 # 'lib.<plat>' under the base build directory. We only use one of
96 # them for a given distribution, though --
97 if self.build_purelib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000098 self.build_purelib = os.path.join(self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000099 if self.build_platlib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000100 self.build_platlib = os.path.join(self.build_base,
101 'lib' + plat_specifier)
Greg Ward42a3bf52000-03-01 01:26:45 +0000102
103 # 'build_lib' is the actual directory that we will use for this
104 # particular module distribution -- if user didn't supply it, pick
105 # one of 'build_purelib' or 'build_platlib'.
106 if self.build_lib is None:
107 if self.distribution.ext_modules:
108 self.build_lib = self.build_platlib
109 else:
110 self.build_lib = self.build_purelib
111
112 # 'build_temp' -- temporary directory for compiler turds,
113 # "build/temp.<plat>"
114 if self.build_temp is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +0000115 self.build_temp = os.path.join(self.build_base,
116 'temp' + plat_specifier)
Greg Ward8d5881a2000-05-25 01:19:18 +0000117 if self.build_scripts is None:
Michael W. Hudson49bdaed2001-12-10 15:28:30 +0000118 self.build_scripts = os.path.join(self.build_base,
119 'scripts-' + sys.version[0:3])
Greg Ward53db8152000-09-16 02:06:45 +0000120
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +0000121 if self.executable is None:
122 self.executable = os.path.normpath(sys.executable)
Greg Ward42a3bf52000-03-01 01:26:45 +0000123 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +0000124
125
126 def run (self):
127
Greg Ward64d855a2000-09-30 17:08:12 +0000128 # Run all relevant sub-commands. This will be some subset of:
129 # - build_py - pure Python modules
130 # - build_clib - standalone C libraries
131 # - build_ext - Python extensions
132 # - build_scripts - (Python) scripts
133 for cmd_name in self.get_sub_commands():
134 self.run_command(cmd_name)
Greg Ward13ae1c81999-03-22 14:55:25 +0000135
Greg Ward13ae1c81999-03-22 14:55:25 +0000136
Greg Ward64d855a2000-09-30 17:08:12 +0000137 # -- Predicates for the sub-command list ---------------------------
Greg Ward5f7c18e2000-02-05 02:24:16 +0000138
Greg Ward64d855a2000-09-30 17:08:12 +0000139 def has_pure_modules (self):
140 return self.distribution.has_pure_modules()
Greg Ward13ae1c81999-03-22 14:55:25 +0000141
Greg Ward64d855a2000-09-30 17:08:12 +0000142 def has_c_libraries (self):
143 return self.distribution.has_c_libraries()
144
145 def has_ext_modules (self):
146 return self.distribution.has_ext_modules()
147
148 def has_scripts (self):
149 return self.distribution.has_scripts()
150
151
152 sub_commands = [('build_py', has_pure_modules),
153 ('build_clib', has_c_libraries),
154 ('build_ext', has_ext_modules),
155 ('build_scripts', has_scripts),
156 ]
Greg Ward8d5881a2000-05-25 01:19:18 +0000157
Greg Wardfcd974e2000-05-25 01:10:04 +0000158# class build