blob: bca031f73013c755711b2cdf0f5f5eaf69ef77a1 [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
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)"),
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000043 ('executable=', 'e',
44 "specify final destination interpreter path (build.py)"),
Greg Wardbbeceea2000-02-18 00:25:39 +000045 ]
Greg Ward2ff78872000-06-24 00:23:20 +000046
Greg Ward99b032e2000-09-25 01:41:15 +000047 boolean_options = ['debug', 'force']
48
Greg Ward9d17a7a2000-06-07 03:00:06 +000049 help_options = [
50 ('help-compiler', None,
Greg Ward2ff78872000-06-24 00:23:20 +000051 "list available compilers", show_compilers),
Greg Wardfa9ff762000-10-14 04:06:40 +000052 ]
Greg Ward13ae1c81999-03-22 14:55:25 +000053
Greg Warde01149c2000-02-18 00:35:22 +000054 def initialize_options (self):
Greg Warde6ac2fc1999-09-29 12:38:18 +000055 self.build_base = 'build'
56 # these are decided only after 'build_base' has its final value
Greg Ward13ae1c81999-03-22 14:55:25 +000057 # (unless overridden by the user or client)
Greg Ward42a3bf52000-03-01 01:26:45 +000058 self.build_purelib = None
Greg Warde6ac2fc1999-09-29 12:38:18 +000059 self.build_platlib = None
Greg Ward42a3bf52000-03-01 01:26:45 +000060 self.build_lib = None
61 self.build_temp = None
Greg Ward8d5881a2000-05-25 01:19:18 +000062 self.build_scripts = None
Gregory P. Smith9668b782000-05-12 00:33:14 +000063 self.compiler = None
Greg Ward32462002000-02-09 02:19:49 +000064 self.debug = None
Greg Wardc41d6b32000-04-10 00:19:42 +000065 self.force = 0
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +000066 self.executable = None
Greg Ward13ae1c81999-03-22 14:55:25 +000067
Greg Warde01149c2000-02-18 00:35:22 +000068 def finalize_options (self):
Greg Ward42a3bf52000-03-01 01:26:45 +000069
Greg Ward53db8152000-09-16 02:06:45 +000070 plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
Greg Ward42900942000-09-16 01:54:46 +000071
Georg Brandl50160152008-01-21 17:42:40 +000072 # Make it so Python 2.x and Python 2.x with --with-pydebug don't
73 # share the same build directories. Doing so confuses the build
74 # process for C modules
75 if hasattr(sys, 'gettotalrefcount'):
76 plat_specifier += '-pydebug'
77
Greg Ward42a3bf52000-03-01 01:26:45 +000078 # 'build_purelib' and 'build_platlib' just default to 'lib' and
79 # 'lib.<plat>' under the base build directory. We only use one of
80 # them for a given distribution, though --
81 if self.build_purelib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000082 self.build_purelib = os.path.join(self.build_base, 'lib')
Greg Warde6ac2fc1999-09-29 12:38:18 +000083 if self.build_platlib is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000084 self.build_platlib = os.path.join(self.build_base,
85 'lib' + plat_specifier)
Greg Ward42a3bf52000-03-01 01:26:45 +000086
87 # 'build_lib' is the actual directory that we will use for this
88 # particular module distribution -- if user didn't supply it, pick
89 # one of 'build_purelib' or 'build_platlib'.
90 if self.build_lib is None:
91 if self.distribution.ext_modules:
92 self.build_lib = self.build_platlib
93 else:
94 self.build_lib = self.build_purelib
95
96 # 'build_temp' -- temporary directory for compiler turds,
97 # "build/temp.<plat>"
98 if self.build_temp is None:
Greg Wardcb1f4c42000-09-30 18:27:54 +000099 self.build_temp = os.path.join(self.build_base,
100 'temp' + plat_specifier)
Greg Ward8d5881a2000-05-25 01:19:18 +0000101 if self.build_scripts is None:
Michael W. Hudson49bdaed2001-12-10 15:28:30 +0000102 self.build_scripts = os.path.join(self.build_base,
103 'scripts-' + sys.version[0:3])
Greg Ward53db8152000-09-16 02:06:45 +0000104
Martin v. Löwis9f5c0c42004-08-25 11:37:43 +0000105 if self.executable is None:
106 self.executable = os.path.normpath(sys.executable)
Greg Ward42a3bf52000-03-01 01:26:45 +0000107 # finalize_options ()
Greg Ward13ae1c81999-03-22 14:55:25 +0000108
109
110 def run (self):
111
Greg Ward64d855a2000-09-30 17:08:12 +0000112 # Run all relevant sub-commands. This will be some subset of:
113 # - build_py - pure Python modules
114 # - build_clib - standalone C libraries
115 # - build_ext - Python extensions
116 # - build_scripts - (Python) scripts
117 for cmd_name in self.get_sub_commands():
118 self.run_command(cmd_name)
Greg Ward13ae1c81999-03-22 14:55:25 +0000119
Greg Ward13ae1c81999-03-22 14:55:25 +0000120
Greg Ward64d855a2000-09-30 17:08:12 +0000121 # -- Predicates for the sub-command list ---------------------------
Greg Ward5f7c18e2000-02-05 02:24:16 +0000122
Greg Ward64d855a2000-09-30 17:08:12 +0000123 def has_pure_modules (self):
124 return self.distribution.has_pure_modules()
Greg Ward13ae1c81999-03-22 14:55:25 +0000125
Greg Ward64d855a2000-09-30 17:08:12 +0000126 def has_c_libraries (self):
127 return self.distribution.has_c_libraries()
128
129 def has_ext_modules (self):
130 return self.distribution.has_ext_modules()
131
132 def has_scripts (self):
133 return self.distribution.has_scripts()
134
135
136 sub_commands = [('build_py', has_pure_modules),
137 ('build_clib', has_c_libraries),
138 ('build_ext', has_ext_modules),
139 ('build_scripts', has_scripts),
140 ]
Greg Ward8d5881a2000-05-25 01:19:18 +0000141
Greg Wardfcd974e2000-05-25 01:10:04 +0000142# class build