Updated for 2.1b2 distribution.
[python/dscho.git] / Lib / distutils / command / build.py
blobcf35b45d01b432e24fe69ccd767c70d2666c9117
1 """distutils.command.build
3 Implements the Distutils 'build' command."""
5 # created 1999/03/08, Greg Ward
7 __revision__ = "$Id$"
9 import sys, os
10 from distutils.core import Command
11 from distutils.util import get_platform
14 def show_compilers ():
15 from distutils.ccompiler import show_compilers
16 show_compilers()
19 class build (Command):
21 description = "build everything needed to install"
23 user_options = [
24 ('build-base=', 'b',
25 "base directory for build library"),
26 ('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"),
33 ('build-scripts=', None,
34 "build directory for scripts"),
35 ('build-temp=', 't',
36 "temporary build directory"),
37 ('compiler=', 'c',
38 "specify the compiler type"),
39 ('debug', 'g',
40 "compile extensions and libraries with debugging information"),
41 ('force', 'f',
42 "forcibly build everything (ignore file timestamps)"),
45 boolean_options = ['debug', 'force']
47 help_options = [
48 ('help-compiler', None,
49 "list available compilers", show_compilers),
52 def initialize_options (self):
53 self.build_base = 'build'
54 # these are decided only after 'build_base' has its final value
55 # (unless overridden by the user or client)
56 self.build_purelib = None
57 self.build_platlib = None
58 self.build_lib = None
59 self.build_temp = None
60 self.build_scripts = None
61 self.compiler = None
62 self.debug = None
63 self.force = 0
65 def finalize_options (self):
67 plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
69 # 'build_purelib' and 'build_platlib' just default to 'lib' and
70 # 'lib.<plat>' under the base build directory. We only use one of
71 # them for a given distribution, though --
72 if self.build_purelib is None:
73 self.build_purelib = os.path.join(self.build_base, 'lib')
74 if self.build_platlib is None:
75 self.build_platlib = os.path.join(self.build_base,
76 'lib' + plat_specifier)
78 # 'build_lib' is the actual directory that we will use for this
79 # particular module distribution -- if user didn't supply it, pick
80 # one of 'build_purelib' or 'build_platlib'.
81 if self.build_lib is None:
82 if self.distribution.ext_modules:
83 self.build_lib = self.build_platlib
84 else:
85 self.build_lib = self.build_purelib
87 # 'build_temp' -- temporary directory for compiler turds,
88 # "build/temp.<plat>"
89 if self.build_temp is None:
90 self.build_temp = os.path.join(self.build_base,
91 'temp' + plat_specifier)
92 if self.build_scripts is None:
93 self.build_scripts = os.path.join(self.build_base, 'scripts')
95 # finalize_options ()
98 def run (self):
100 # Run all relevant sub-commands. This will be some subset of:
101 # - build_py - pure Python modules
102 # - build_clib - standalone C libraries
103 # - build_ext - Python extensions
104 # - build_scripts - (Python) scripts
105 for cmd_name in self.get_sub_commands():
106 self.run_command(cmd_name)
109 # -- Predicates for the sub-command list ---------------------------
111 def has_pure_modules (self):
112 return self.distribution.has_pure_modules()
114 def has_c_libraries (self):
115 return self.distribution.has_c_libraries()
117 def has_ext_modules (self):
118 return self.distribution.has_ext_modules()
120 def has_scripts (self):
121 return self.distribution.has_scripts()
124 sub_commands = [('build_py', has_pure_modules),
125 ('build_clib', has_c_libraries),
126 ('build_ext', has_ext_modules),
127 ('build_scripts', has_scripts),
130 # class build