Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 1 | **************** |
| 2 | Configure Python |
| 3 | **************** |
| 4 | |
| 5 | .. _configure-options: |
| 6 | |
| 7 | Configure Options |
| 8 | ================= |
| 9 | |
| 10 | List all ``./configure`` script options using:: |
| 11 | |
| 12 | ./configure --help |
| 13 | |
| 14 | See also the :file:`Misc/SpecialBuilds.txt` in the Python source distribution. |
| 15 | |
| 16 | General Options |
| 17 | --------------- |
| 18 | |
| 19 | .. cmdoption:: --enable-loadable-sqlite-extensions |
| 20 | |
| 21 | Support loadable extensions in the :mod:`_sqlite` extension module (default |
Victor Stinner | 85918e4 | 2021-04-12 23:27:35 +0200 | [diff] [blame^] | 22 | is no). |
| 23 | |
| 24 | See the :meth:`sqlite3.Connection.enable_load_extension` method of the |
| 25 | :mod:`sqlite3` module. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 26 | |
| 27 | .. versionadded:: 3.6 |
| 28 | |
| 29 | .. cmdoption:: --disable-ipv6 |
| 30 | |
| 31 | Disable IPv6 support (enabled by default if supported), see the |
| 32 | :mod:`socket` module. |
| 33 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 34 | .. cmdoption:: --enable-big-digits=[15|30] |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 35 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 36 | Define the size in bits of Python :class:`int` digits: 15 or 30 bits. |
| 37 | |
| 38 | By default, the number of bits is selected depending on ``sizeof(void*)``: |
| 39 | 30 bits if ``void*`` size is 64-bit or larger, 15 bits otherwise. |
| 40 | |
| 41 | Define the ``PYLONG_BITS_IN_DIGIT`` to ``15`` or ``30``. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 42 | |
| 43 | See :data:`sys.int_info.bits_per_digit <sys.int_info>`. |
| 44 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 45 | .. cmdoption:: --with-cxx-main |
| 46 | .. cmdoption:: --with-cxx-main=COMPILER |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 47 | |
| 48 | Compile the Python ``main()`` function and link Python executable with C++ |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 49 | compiler: ``$CXX``, or *COMPILER* if specified. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 50 | |
| 51 | .. cmdoption:: --with-suffix=SUFFIX |
| 52 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 53 | Set the Python executable suffix to *SUFFIX*. |
| 54 | |
| 55 | The default suffix is ``.exe`` on Windows and macOS (``python.exe`` |
| 56 | executable), and an empty string on other platforms (``python`` executable). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 57 | |
| 58 | .. cmdoption:: --with-tzpath=<list of absolute paths separated by pathsep> |
| 59 | |
Victor Stinner | 85918e4 | 2021-04-12 23:27:35 +0200 | [diff] [blame^] | 60 | Select the default time zone search path for :data:`zoneinfo.TZPATH`. |
| 61 | See the :ref:`Compile-time configuration |
| 62 | <zoneinfo_data_compile_time_config>` of the :mod:`zoneinfo` module. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 63 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 64 | Default: ``/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo``. |
| 65 | |
| 66 | See :data:`os.pathsep` path separator. |
| 67 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 68 | .. versionadded:: 3.9 |
| 69 | |
| 70 | .. cmdoption:: --without-decimal-contextvar |
| 71 | |
| 72 | Build the ``_decimal`` extension module using a thread-local context rather |
| 73 | than a coroutine-local context (default), see the :mod:`decimal` module. |
| 74 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 75 | See :data:`decimal.HAVE_CONTEXTVAR` and the :mod:`contextvars` module. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 76 | |
| 77 | .. versionadded:: 3.9 |
| 78 | |
| 79 | .. cmdoption:: --with-dbmliborder=db1:db2:... |
| 80 | |
| 81 | Override order to check db backends for the :mod:`dbm` module |
| 82 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 83 | A valid value is a colon (``:``) separated string with the backend names: |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 84 | |
| 85 | * ``ndbm``; |
| 86 | * ``gdbm``; |
| 87 | * ``bdb``. |
| 88 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 89 | .. cmdoption:: --without-c-locale-coercion |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 90 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 91 | Disable C locale coercion to a UTF-8 based locale (enabled by default). |
| 92 | |
| 93 | Don't define the ``PY_COERCE_C_LOCALE`` macro. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 94 | |
| 95 | See :envvar:`PYTHONCOERCECLOCALE` and the :pep:`538`. |
| 96 | |
| 97 | .. cmdoption:: --with-platlibdir=DIRNAME |
| 98 | |
| 99 | Python library directory name (default is ``lib``). |
| 100 | |
| 101 | Fedora and SuSE use ``lib64`` on 64-bit platforms. |
| 102 | |
| 103 | See :data:`sys.platlibdir`. |
| 104 | |
| 105 | .. versionadded:: 3.9 |
| 106 | |
| 107 | .. cmdoption:: --with-wheel-pkg-dir=PATH |
| 108 | |
| 109 | Directory of wheel packages used by the :mod:`ensurepip` module |
| 110 | (none by default). |
| 111 | |
| 112 | Some Linux distribution packaging policies recommend against bundling |
| 113 | dependencies. For example, Fedora installs wheel packages in the |
| 114 | ``/usr/share/python-wheels/`` directory and don't install the |
| 115 | :mod:`ensurepip._bundled` package. |
| 116 | |
| 117 | .. versionadded:: 3.10 |
| 118 | |
| 119 | |
| 120 | Install Options |
| 121 | --------------- |
| 122 | |
| 123 | .. cmdoption:: --disable-test-modules |
| 124 | |
| 125 | Don't build nor install test modules, like the :mod:`test` package or the |
| 126 | :mod:`_testcapi` extension module (built and installed by default). |
| 127 | |
| 128 | .. versionadded:: 3.10 |
| 129 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 130 | .. cmdoption:: --with-ensurepip=[upgrade|install|no] |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 131 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 132 | Select the :mod:`ensurepip` command run on Python installation: |
| 133 | |
| 134 | * ``upgrade`` (default): run ``python -m ensurepip --altinstall --upgrade`` |
| 135 | command. |
| 136 | * ``install``: run ``python -m ensurepip --altinstall`` command; |
| 137 | * ``no``: don't run ensurepip; |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 138 | |
| 139 | .. versionadded:: 3.6 |
| 140 | |
| 141 | |
| 142 | Performance options |
| 143 | ------------------- |
| 144 | |
| 145 | Configuring Python using ``--enable-optimizations --with-lto`` (PGO + LTO) is |
| 146 | recommended for best performance. |
| 147 | |
| 148 | .. cmdoption:: --enable-optimizations |
| 149 | |
| 150 | Enable Profile Guided Optimization (PGO) using :envvar:`PROFILE_TASK` |
| 151 | (disabled by default). |
| 152 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 153 | The C compiler Clang requires ``llvm-profdata`` program for PGO. On |
| 154 | macOS, GCC also requires it: GCC is just an alias to Clang on macOS. |
| 155 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 156 | Disable also semantic interposition in libpython if ``--enable-shared`` and |
| 157 | GCC is used: add ``-fno-semantic-interposition`` to the compiler and linker |
| 158 | flags. |
| 159 | |
| 160 | .. versionadded:: 3.6 |
| 161 | |
| 162 | .. versionchanged:: 3.10 |
| 163 | Use ``-fno-semantic-interposition`` on GCC. |
| 164 | |
| 165 | .. envvar:: PROFILE_TASK |
| 166 | |
| 167 | Environment variable used in the Makefile: Python command line arguments for |
| 168 | the PGO generation task. |
| 169 | |
| 170 | Default: ``-m test --pgo --timeout=$(TESTTIMEOUT)``. |
| 171 | |
| 172 | .. versionadded:: 3.8 |
| 173 | |
| 174 | .. cmdoption:: --with-lto |
| 175 | |
| 176 | Enable Link Time Optimization (LTO) in any build (disabled by default). |
| 177 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 178 | The C compiler Clang requires ``llvm-ar`` for LTO, as well as an LTO-aware |
| 179 | linker (``ld.gold`` or ``lld``). |
| 180 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 181 | .. versionadded:: 3.6 |
| 182 | |
| 183 | .. cmdoption:: --with-computed-gotos |
| 184 | |
| 185 | Enable computed gotos in evaluation loop (enabled by default on supported |
| 186 | compilers). |
| 187 | |
| 188 | .. cmdoption:: --without-pymalloc |
| 189 | |
| 190 | Disable the specialized Python memory allocator :ref:`pymalloc <pymalloc>` |
| 191 | (enabled by default). |
| 192 | |
| 193 | See also :envvar:`PYTHONMALLOC` environment variable. |
| 194 | |
| 195 | .. cmdoption:: --without-doc-strings |
| 196 | |
| 197 | Disable static documentation strings to reduce the memory footprint (enabled |
| 198 | by default). Documentation strings defined in Python are not affected. |
| 199 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 200 | Don't define the ``WITH_DOC_STRINGS`` macro. |
| 201 | |
| 202 | See the ``PyDoc_STRVAR()`` macro. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 203 | |
| 204 | .. cmdoption:: --enable-profiling |
| 205 | |
| 206 | Enable C-level code profiling with ``gprof`` (disabled by default). |
| 207 | |
| 208 | |
| 209 | .. _debug-build: |
| 210 | |
| 211 | Debug build |
| 212 | ----------- |
| 213 | |
| 214 | A debug build is Python built with the :option:`--with-pydebug` configure |
| 215 | option. |
| 216 | |
| 217 | Effects of a debug build: |
| 218 | |
| 219 | * Define ``Py_DEBUG`` and ``Py_REF_DEBUG`` macros. |
| 220 | * Add ``d`` to :data:`sys.abiflags`. |
| 221 | * Add :func:`sys.gettotalrefcount` function. |
| 222 | * Add :option:`-X showrefcount <-X>` command line option. |
| 223 | * Add :envvar:`PYTHONTHREADDEBUG` environment variable. |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 224 | * Add support for the ``__ltrace__`` variable: enable low-level tracing in the |
| 225 | bytecode evaluation loop if the variable is defined. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 226 | * The list of default warning filters is empty in the :mod:`warnings` module. |
| 227 | * Install debug hooks on memory allocators to detect buffer overflow and other |
| 228 | memory errors: see :c:func:`PyMem_SetupDebugHooks`. |
| 229 | * Build Python with assertions (don't set ``NDEBUG`` macro): |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 230 | ``assert(...);`` and ``_PyObject_ASSERT(...);``. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 231 | See also the :option:`--with-assertions` configure option. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 232 | * Unicode and int objects are created with their memory filled with a pattern |
| 233 | to help detecting uninitialized bytes. |
| 234 | * Many functions ensure that are not called with an exception raised, since |
| 235 | they can clear or replace the current exception. |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 236 | * The garbage collector (:func:`gc.collect` function) runs some basic checks on |
| 237 | objects consistency. |
| 238 | * More generally, add runtime checks, code surroundeded by ``#ifdef Py_DEBUG`` |
| 239 | and ``#endif``. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 240 | |
| 241 | See also the :ref:`Python Development Mode <devmode>` and the |
| 242 | :option:`--with-trace-refs` configure option. |
| 243 | |
| 244 | .. versionchanged:: 3.8 |
| 245 | Release builds and debug builds are now ABI compatible: defining the |
| 246 | ``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro, which |
| 247 | introduces the only ABI incompatibility. |
| 248 | |
| 249 | |
| 250 | Debug options |
| 251 | ------------- |
| 252 | |
| 253 | .. cmdoption:: --with-pydebug |
| 254 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 255 | :ref:`Build Python in debug mode <debug-build>`: define the ``Py_DEBUG`` |
| 256 | macro (disabled by default). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 257 | |
| 258 | .. cmdoption:: --with-trace-refs |
| 259 | |
| 260 | Enable tracing references for debugging purpose (disabled by default). |
| 261 | |
| 262 | Effects: |
| 263 | |
| 264 | * Define the ``Py_TRACE_REFS`` macro. |
| 265 | * Add :func:`sys.getobjects` function. |
| 266 | * Add :envvar:`PYTHONDUMPREFS` environment variable. |
| 267 | |
| 268 | This build is not ABI compatible with release build (default build) or debug |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 269 | build (``Py_DEBUG`` and ``Py_REF_DEBUG`` macros). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 270 | |
| 271 | .. versionadded:: 3.8 |
| 272 | |
| 273 | .. cmdoption:: --with-assertions |
| 274 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 275 | Build with C assertions enabled (default is no): ``assert(...);`` and |
| 276 | ``_PyObject_ASSERT(...);``. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 277 | |
| 278 | If set, the ``NDEBUG`` macro is not defined in the :envvar:`OPT` compiler |
| 279 | variable. |
| 280 | |
| 281 | See also the :option:`--with-pydebug` option (:ref:`debug build |
| 282 | <debug-build>`) which also enables assertions. |
| 283 | |
| 284 | .. versionadded:: 3.6 |
| 285 | |
| 286 | .. cmdoption:: --with-valgrind |
| 287 | |
| 288 | Enable Valgrind support (default is no). |
| 289 | |
| 290 | .. cmdoption:: --with-dtrace |
| 291 | |
| 292 | Enable DTrace support (default is no). |
| 293 | |
Victor Stinner | 85918e4 | 2021-04-12 23:27:35 +0200 | [diff] [blame^] | 294 | See :ref:`Instrumenting CPython with DTrace and SystemTap |
| 295 | <instrumentation>`. |
| 296 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 297 | .. versionadded:: 3.6 |
| 298 | |
| 299 | .. cmdoption:: --with-address-sanitizer |
| 300 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 301 | Enable AddressSanitizer memory error detector, ``asan`` (default is no). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 302 | |
| 303 | .. versionadded:: 3.6 |
| 304 | |
| 305 | .. cmdoption:: --with-memory-sanitizer |
| 306 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 307 | Enable MemorySanitizer allocation error detector, ``msan`` (default is no). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 308 | |
| 309 | .. versionadded:: 3.6 |
| 310 | |
| 311 | .. cmdoption:: --with-undefined-behavior-sanitizer |
| 312 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 313 | Enable UndefinedBehaviorSanitizer undefined behaviour detector, ``ubsan`` |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 314 | (default is no). |
| 315 | |
| 316 | .. versionadded:: 3.6 |
| 317 | |
| 318 | |
| 319 | Linker options |
| 320 | -------------- |
| 321 | |
| 322 | .. cmdoption:: --enable-shared |
| 323 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 324 | Enable building a shared Python library: ``libpython`` (default is no). |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 325 | |
| 326 | .. cmdoption:: --without-static-libpython |
| 327 | |
| 328 | Do not build ``libpythonMAJOR.MINOR.a`` and do not install ``python.o`` |
| 329 | (built and enabled by default). |
| 330 | |
| 331 | .. versionadded:: 3.10 |
| 332 | |
| 333 | |
| 334 | Libraries options |
| 335 | ----------------- |
| 336 | |
| 337 | .. cmdoption:: --with-libs='lib1 ...' |
| 338 | |
| 339 | Link against additional libraries (default is no). |
| 340 | |
| 341 | .. cmdoption:: --with-system-expat |
| 342 | |
| 343 | Build the :mod:`pyexpat` module using an installed ``expat`` library |
| 344 | (default is no). |
| 345 | |
| 346 | .. cmdoption:: --with-system-ffi |
| 347 | |
| 348 | Build the :mod:`_ctypes` extension module using an installed ``ffi`` |
| 349 | library, see the :mod:`ctypes` module (default is system-dependent). |
| 350 | |
| 351 | .. cmdoption:: --with-system-libmpdec |
| 352 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 353 | Build the ``_decimal`` extension module using an installed ``mpdec`` |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 354 | library, see the :mod:`decimal` module (default is no). |
| 355 | |
| 356 | .. versionadded:: 3.3 |
| 357 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 358 | .. cmdoption:: --with-readline=editline |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 359 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 360 | Use ``editline`` library for backend of the :mod:`readline` module. |
| 361 | |
| 362 | Define the ``WITH_EDITLINE`` macro. |
| 363 | |
| 364 | .. versionadded:: 3.10 |
| 365 | |
| 366 | .. cmdoption:: --without-readline |
| 367 | |
| 368 | Don't build the :mod:`readline` module (built by default). |
| 369 | |
| 370 | Don't define the ``HAVE_LIBREADLINE`` macro. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 371 | |
| 372 | .. versionadded:: 3.10 |
| 373 | |
| 374 | .. cmdoption:: --with-tcltk-includes='-I...' |
| 375 | |
| 376 | Override search for Tcl and Tk include files. |
| 377 | |
| 378 | .. cmdoption:: --with-tcltk-libs='-L...' |
| 379 | |
| 380 | Override search for Tcl and Tk libraries. |
| 381 | |
| 382 | .. cmdoption:: --with-libm=STRING |
| 383 | |
| 384 | Override ``libm`` math library to *STRING* (default is system-dependent). |
| 385 | |
| 386 | .. cmdoption:: --with-libc=STRING |
| 387 | |
| 388 | Override ``libc`` C library to *STRING* (default is system-dependent). |
| 389 | |
| 390 | .. cmdoption:: --with-openssl=DIR |
| 391 | |
| 392 | Root of the OpenSSL directory. |
| 393 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 394 | .. versionadded:: 3.7 |
| 395 | |
| 396 | .. cmdoption:: --with-openssl-rpath=[no|auto|DIR] |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 397 | |
| 398 | Set runtime library directory (rpath) for OpenSSL libraries: |
| 399 | |
| 400 | * ``no`` (default): don't set rpath; |
| 401 | * ``auto``: auto-detect rpath from :option:`--with-openssl` and |
| 402 | ``pkg-config``; |
| 403 | * *DIR*: set an explicit rpath. |
| 404 | |
| 405 | .. versionadded:: 3.10 |
| 406 | |
| 407 | |
| 408 | Security Options |
| 409 | ---------------- |
| 410 | |
| 411 | .. cmdoption:: --with-hash-algorithm=[fnv|siphash24] |
| 412 | |
| 413 | Select hash algorithm for use in ``Python/pyhash.c``: |
| 414 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 415 | * ``siphash24`` (default). |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 416 | * ``fnv``; |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 417 | |
| 418 | .. versionadded:: 3.4 |
| 419 | |
| 420 | .. cmdoption:: --with-builtin-hashlib-hashes=md5,sha1,sha256,sha512,sha3,blake2 |
| 421 | |
| 422 | Built-in hash modules: |
| 423 | |
| 424 | * ``md5``; |
| 425 | * ``sha1``; |
| 426 | * ``sha256``; |
| 427 | * ``sha512``; |
| 428 | * ``sha3`` (with shake); |
| 429 | * ``blake2``. |
| 430 | |
| 431 | .. versionadded:: 3.9 |
| 432 | |
| 433 | .. cmdoption:: --with-ssl-default-suites=[python|openssl|STRING] |
| 434 | |
| 435 | Override the OpenSSL default cipher suites string: |
| 436 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 437 | * ``python`` (default): use Python's preferred selection; |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 438 | * ``openssl``: leave OpenSSL's defaults untouched; |
| 439 | * *STRING*: use a custom string, PROTOCOL_SSLv2 ignores the setting. |
| 440 | |
| 441 | See the :mod:`ssl` module. |
| 442 | |
| 443 | .. versionadded:: 3.7 |
| 444 | |
| 445 | |
| 446 | macOS Options |
| 447 | ------------- |
| 448 | |
| 449 | See ``Mac/README.rst``. |
| 450 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 451 | .. cmdoption:: --enable-universalsdk |
| 452 | .. cmdoption:: --enable-universalsdk=SDKDIR |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 453 | |
| 454 | Create a universal binary build. *SDKDIR* specifies which macOS SDK should |
| 455 | be used to perform the build (default is no). |
| 456 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 457 | .. cmdoption:: --enable-framework |
| 458 | .. cmdoption:: --enable-framework=INSTALLDIR |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 459 | |
| 460 | Create a Python.framework rather than a traditional Unix install. Optional |
| 461 | *INSTALLDIR* specifies the installation path (default is no). |
| 462 | |
| 463 | .. cmdoption:: --with-universal-archs=ARCH |
| 464 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 465 | Specify the kind of universal binary that should be created. This option is |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 466 | only valid when :option:`--enable-universalsdk` is set. |
| 467 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 468 | Options: |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 469 | |
| 470 | * ``universal2``; |
| 471 | * ``32-bit``; |
| 472 | * ``64-bit``; |
| 473 | * ``3-way``; |
| 474 | * ``intel``; |
| 475 | * ``intel-32``; |
| 476 | * ``intel-64``; |
| 477 | * ``all``. |
| 478 | |
| 479 | .. cmdoption:: --with-framework-name=FRAMEWORK |
| 480 | |
| 481 | Specify the name for the python framework on macOS only valid when |
| 482 | :option:`--enable-framework` is set (default: ``Python``). |
| 483 | |
| 484 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 485 | Python Build System |
| 486 | =================== |
| 487 | |
| 488 | Main files of the build system |
| 489 | ------------------------------ |
| 490 | |
| 491 | * :file:`configure.ac` => :file:`configure`; |
| 492 | * :file:`Makefile.pre.in` => :file:`Makefile` (created by :file:`configure`); |
| 493 | * :file:`pyconfig.h` (created by :file:`configure`); |
| 494 | * :file:`Modules/Setup`: C extensions built by the Makefile using |
| 495 | :file:`Module/makesetup` shell script; |
| 496 | * :file:`setup.py`: C extensions built using the :mod:`distutils` module. |
| 497 | |
| 498 | Main build steps |
| 499 | ---------------- |
| 500 | |
| 501 | * C files (``.c``) are built as object files (``.o``). |
| 502 | * A static ``libpython`` library (``.a``) is created from objects files. |
| 503 | * ``python.o`` and the static ``libpython`` library are linked into the |
| 504 | final ``python`` program. |
| 505 | * C extensions are built by the Makefile (see :file:`Modules/Setup`) |
| 506 | and ``python setup.py build``. |
| 507 | |
| 508 | Main Makefile targets |
| 509 | --------------------- |
| 510 | |
| 511 | * ``make``: Build Python with the standard library. |
| 512 | * ``make platform:``: build the ``python`` program, but don't build the |
| 513 | standard library extension modules. |
| 514 | * ``make profile-opt``: build Python using Profile Guided Optimization (PGO). |
| 515 | You can use the configure :option:`--enable-optimizations` option to make |
| 516 | this the default target of the ``make`` command (``make all`` or just |
| 517 | ``make``). |
| 518 | * ``make buildbottest``: Build Python and run the Python test suite, the same |
| 519 | way than buildbots test Python. Set ``TESTTIMEOUT`` variable (in seconds) |
| 520 | to change the test timeout (1200 by default: 20 minutes). |
| 521 | * ``make install``: Build and install Python. |
| 522 | * ``make regen-all``: Regenerate (almost) all generated files; |
| 523 | ``make regen-stdlib-module-names`` and ``autoconf`` must be run separately |
| 524 | for the remaining generated files. |
| 525 | * ``make clean``: Remove built files. |
| 526 | * ``make distclean``: Same than ``make clean``, but remove also files created |
| 527 | by the configure script. |
| 528 | |
| 529 | C extensions |
| 530 | ------------ |
| 531 | |
| 532 | Some C extensions are built as built-in modules, like the ``sys`` module. |
| 533 | They are built with the ``Py_BUILD_CORE_BUILTIN`` macro defined. |
| 534 | Built-in modules have no ``__file__`` attribute:: |
| 535 | |
| 536 | >>> import sys |
| 537 | >>> sys |
| 538 | <module 'sys' (built-in)> |
| 539 | >>> sys.__file__ |
| 540 | Traceback (most recent call last): |
| 541 | File "<stdin>", line 1, in <module> |
| 542 | AttributeError: module 'sys' has no attribute '__file__' |
| 543 | |
| 544 | Other C extensins are built as dynamic libraires, like the ``_asyncio`` module. |
| 545 | They are built with the ``Py_BUILD_CORE_MODULE`` macro defined. |
| 546 | Example on Linux x86-64:: |
| 547 | |
| 548 | >>> import _asyncio |
| 549 | >>> _asyncio |
| 550 | <module '_asyncio' from '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so'> |
| 551 | >>> _asyncio.__file__ |
| 552 | '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so' |
| 553 | |
| 554 | :file:`Modules/Setup` is used to generate Makefile targets to build C extensions. |
| 555 | At the beginning of the files, C extensions are built as built-in modules. |
| 556 | Extensions defined after the ``*shared*`` marker are built as dynamic libraries. |
| 557 | |
| 558 | The :file:`setup.py` script only builds C extensions as shared libraries using |
| 559 | the :mod:`distutils` module. |
| 560 | |
| 561 | The :c:macro:`PyAPI_FUNC()`, :c:macro:`PyAPI_API()` and |
| 562 | :c:macro:`PyMODINIT_FUNC()` macros of :file:`Include/pyport.h` are defined |
| 563 | differently depending if the ``Py_BUILD_CORE_MODULE`` macro is defined: |
| 564 | |
| 565 | * Use ``Py_EXPORTED_SYMBOL`` if the ``Py_BUILD_CORE_MODULE`` is defined |
| 566 | * Use ``Py_IMPORTED_SYMBOL`` otherwise. |
| 567 | |
| 568 | If the ``Py_BUILD_CORE_BUILTIN`` macro is used by mistake on a C extension |
| 569 | built as a shared library, its ``PyInit_xxx()`` function is not exported, |
| 570 | causing an :exc:`ImportError` on import. |
| 571 | |
| 572 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 573 | Compiler and linker flags |
| 574 | ========================= |
| 575 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 576 | Options set by the ``./configure`` script and environment variables and used by |
| 577 | ``Makefile``. |
| 578 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 579 | Preprocessor flags |
| 580 | ------------------ |
| 581 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 582 | .. envvar:: CONFIGURE_CPPFLAGS |
| 583 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 584 | Value of :envvar:`CPPFLAGS` variable passed to the ``./configure`` script. |
| 585 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 586 | .. versionadded:: 3.6 |
| 587 | |
| 588 | .. envvar:: CPPFLAGS |
| 589 | |
| 590 | (Objective) C/C++ preprocessor flags, e.g. ``-I<include dir>`` if you have |
| 591 | headers in a nonstandard directory ``<include dir>``. |
| 592 | |
| 593 | Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's |
| 594 | value for setup.py to be able to build extension modules using the |
| 595 | directories specified in the environment variables. |
| 596 | |
| 597 | .. envvar:: BASECPPFLAGS |
| 598 | |
| 599 | .. versionadded:: 3.4 |
| 600 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 601 | .. envvar:: PY_CPPFLAGS |
| 602 | |
| 603 | Extra preprocessor flags added for building the interpreter object files. |
| 604 | |
| 605 | Default: ``$(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)``. |
| 606 | |
| 607 | .. versionadded:: 3.2 |
| 608 | |
| 609 | Compiler flags |
| 610 | -------------- |
| 611 | |
| 612 | .. envvar:: CC |
| 613 | |
| 614 | C compiler command. |
| 615 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 616 | Example: ``gcc -pthread``. |
| 617 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 618 | .. envvar:: MAINCC |
| 619 | |
| 620 | C compiler command used to build the ``main()`` function of programs like |
| 621 | ``python``. |
| 622 | |
| 623 | Variable set by the :option:`--with-cxx-main` option of the configure |
| 624 | script. |
| 625 | |
| 626 | Default: ``$(CC)``. |
| 627 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 628 | .. envvar:: CXX |
| 629 | |
| 630 | C++ compiler command. |
| 631 | |
| 632 | Used if the :option:`--with-cxx-main` option is used. |
| 633 | |
| 634 | Example: ``g++ -pthread``. |
| 635 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 636 | .. envvar:: CFLAGS |
| 637 | |
| 638 | C compiler flags. |
| 639 | |
| 640 | .. envvar:: CFLAGS_NODIST |
| 641 | |
| 642 | :envvar:`CFLAGS_NODIST` is used for building the interpreter and stdlib C |
| 643 | extensions. Use it when a compiler flag should *not* be part of the |
| 644 | distutils :envvar:`CFLAGS` once Python is installed (:issue:`21121`). |
| 645 | |
| 646 | .. versionadded:: 3.5 |
| 647 | |
| 648 | .. envvar:: EXTRA_CFLAGS |
| 649 | |
| 650 | Extra C compiler flags. |
| 651 | |
| 652 | .. envvar:: CONFIGURE_CFLAGS |
| 653 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 654 | Value of :envvar:`CFLAGS` variable passed to the ``./configure`` |
| 655 | script. |
| 656 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 657 | .. versionadded:: 3.2 |
| 658 | |
| 659 | .. envvar:: CONFIGURE_CFLAGS_NODIST |
| 660 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 661 | Value of :envvar:`CFLAGS_NODIST` variable passed to the ``./configure`` |
| 662 | script. |
| 663 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 664 | .. versionadded:: 3.5 |
| 665 | |
| 666 | .. envvar:: BASECFLAGS |
| 667 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 668 | Base compiler flags. |
| 669 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 670 | .. envvar:: OPT |
| 671 | |
| 672 | Optimization flags. |
| 673 | |
| 674 | .. envvar:: CFLAGS_ALIASING |
| 675 | |
| 676 | Strict or non-strict aliasing flags used to compile ``Python/dtoa.c``. |
| 677 | |
| 678 | .. versionadded:: 3.7 |
| 679 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 680 | .. envvar:: CCSHARED |
| 681 | |
| 682 | Compiler flags used to build a shared library. |
| 683 | |
| 684 | For example, ``-fPIC`` is used on Linux and on BSD. |
| 685 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 686 | .. envvar:: CFLAGSFORSHARED |
| 687 | |
| 688 | Extra C flags added for building the interpreter object files. |
| 689 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 690 | Default: ``$(CCSHARED)`` when :option:`--enable-shared` is used, or an empty |
| 691 | string otherwise. |
| 692 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 693 | .. envvar:: PY_CFLAGS |
| 694 | |
| 695 | Default: ``$(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)``. |
| 696 | |
| 697 | .. envvar:: PY_CFLAGS_NODIST |
| 698 | |
| 699 | Default: ``$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include/internal``. |
| 700 | |
| 701 | .. versionadded:: 3.5 |
| 702 | |
| 703 | .. envvar:: PY_STDMODULE_CFLAGS |
| 704 | |
| 705 | C flags used for building the interpreter object files. |
| 706 | |
| 707 | Default: ``$(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED)``. |
| 708 | |
| 709 | .. versionadded:: 3.7 |
| 710 | |
| 711 | .. envvar:: PY_CORE_CFLAGS |
| 712 | |
| 713 | Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE``. |
| 714 | |
| 715 | .. versionadded:: 3.2 |
| 716 | |
| 717 | .. envvar:: PY_BUILTIN_MODULE_CFLAGS |
| 718 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 719 | Compiler flags to build a standard library extension module as a built-in |
| 720 | module, like the :mod:`posix` module. |
| 721 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 722 | Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN``. |
| 723 | |
| 724 | .. versionadded:: 3.8 |
| 725 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 726 | .. envvar:: PURIFY |
| 727 | |
| 728 | Purify command. Purify is a memory debugger program. |
| 729 | |
| 730 | Default: empty string (not used). |
| 731 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 732 | |
| 733 | Linker flags |
| 734 | ------------ |
| 735 | |
Victor Stinner | bd88ccb | 2021-04-09 14:35:10 +0200 | [diff] [blame] | 736 | .. envvar:: LINKCC |
| 737 | |
| 738 | Linker command used to build programs like ``python`` and ``_testembed``. |
| 739 | |
| 740 | Default: ``$(PURIFY) $(MAINCC)``. |
| 741 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 742 | .. envvar:: CONFIGURE_LDFLAGS |
| 743 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 744 | Value of :envvar:`LDFLAGS` variable passed to the ``./configure`` script. |
| 745 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 746 | Avoid assigning :envvar:`CFLAGS`, :envvar:`LDFLAGS`, etc. so users can use |
| 747 | them on the command line to append to these values without stomping the |
| 748 | pre-set values. |
| 749 | |
| 750 | .. versionadded:: 3.2 |
| 751 | |
| 752 | .. envvar:: LDFLAGS_NODIST |
| 753 | |
| 754 | :envvar:`LDFLAGS_NODIST` is used in the same manner as |
| 755 | :envvar:`CFLAGS_NODIST`. Use it when a linker flag should *not* be part of |
| 756 | the distutils :envvar:`LDFLAGS` once Python is installed (:issue:`35257`). |
| 757 | |
| 758 | .. envvar:: CONFIGURE_LDFLAGS_NODIST |
| 759 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 760 | Value of :envvar:`LDFLAGS_NODIST` variable passed to the ``./configure`` |
| 761 | script. |
| 762 | |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 763 | .. versionadded:: 3.8 |
| 764 | |
| 765 | .. envvar:: LDFLAGS |
| 766 | |
| 767 | Linker flags, e.g. ``-L<lib dir>`` if you have libraries in a nonstandard |
| 768 | directory ``<lib dir>``. |
| 769 | |
| 770 | Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's |
| 771 | value for setup.py to be able to build extension modules using the |
| 772 | directories specified in the environment variables. |
| 773 | |
| 774 | .. envvar:: LIBS |
| 775 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 776 | Linker flags to pass libraries to the linker when linking the Python |
| 777 | executable. |
| 778 | |
| 779 | Example: ``-lrt``. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 780 | |
| 781 | .. envvar:: LDSHARED |
| 782 | |
| 783 | Command to build a shared library. |
| 784 | |
| 785 | Default: ``@LDSHARED@ $(PY_LDFLAGS)``. |
| 786 | |
| 787 | .. envvar:: BLDSHARED |
| 788 | |
Victor Stinner | 5436695 | 2021-04-09 01:58:20 +0200 | [diff] [blame] | 789 | Command to build ``libpython`` shared library. |
Victor Stinner | a41782c | 2021-04-08 22:32:21 +0200 | [diff] [blame] | 790 | |
| 791 | Default: ``@BLDSHARED@ $(PY_CORE_LDFLAGS)``. |
| 792 | |
| 793 | .. envvar:: PY_LDFLAGS |
| 794 | |
| 795 | Default: ``$(CONFIGURE_LDFLAGS) $(LDFLAGS)``. |
| 796 | |
| 797 | .. envvar:: PY_LDFLAGS_NODIST |
| 798 | |
| 799 | Default: ``$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST)``. |
| 800 | |
| 801 | .. versionadded:: 3.8 |
| 802 | |
| 803 | .. envvar:: PY_CORE_LDFLAGS |
| 804 | |
| 805 | Linker flags used for building the interpreter object files. |
| 806 | |
| 807 | .. versionadded:: 3.8 |