blob: c37540c7e031d65d57850cabf74b8a32035ec232 [file] [log] [blame]
Victor Stinnera41782c2021-04-08 22:32:21 +02001****************
2Configure Python
3****************
4
5.. _configure-options:
6
7Configure Options
8=================
9
10List all ``./configure`` script options using::
11
12 ./configure --help
13
14See also the :file:`Misc/SpecialBuilds.txt` in the Python source distribution.
15
16General Options
17---------------
18
19.. cmdoption:: --enable-loadable-sqlite-extensions
20
21 Support loadable extensions in the :mod:`_sqlite` extension module (default
Victor Stinner85918e42021-04-12 23:27:35 +020022 is no).
23
24 See the :meth:`sqlite3.Connection.enable_load_extension` method of the
25 :mod:`sqlite3` module.
Victor Stinnera41782c2021-04-08 22:32:21 +020026
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 Stinner54366952021-04-09 01:58:20 +020034.. cmdoption:: --enable-big-digits=[15|30]
Victor Stinnera41782c2021-04-08 22:32:21 +020035
Victor Stinner54366952021-04-09 01:58:20 +020036 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 Stinnera41782c2021-04-08 22:32:21 +020042
43 See :data:`sys.int_info.bits_per_digit <sys.int_info>`.
44
Victor Stinner54366952021-04-09 01:58:20 +020045.. cmdoption:: --with-cxx-main
46.. cmdoption:: --with-cxx-main=COMPILER
Victor Stinnera41782c2021-04-08 22:32:21 +020047
48 Compile the Python ``main()`` function and link Python executable with C++
Victor Stinner54366952021-04-09 01:58:20 +020049 compiler: ``$CXX``, or *COMPILER* if specified.
Victor Stinnera41782c2021-04-08 22:32:21 +020050
51.. cmdoption:: --with-suffix=SUFFIX
52
Victor Stinner54366952021-04-09 01:58:20 +020053 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 Stinnera41782c2021-04-08 22:32:21 +020057
58.. cmdoption:: --with-tzpath=<list of absolute paths separated by pathsep>
59
Victor Stinner85918e42021-04-12 23:27:35 +020060 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 Stinnera41782c2021-04-08 22:32:21 +020063
Victor Stinner54366952021-04-09 01:58:20 +020064 Default: ``/usr/share/zoneinfo:/usr/lib/zoneinfo:/usr/share/lib/zoneinfo:/etc/zoneinfo``.
65
66 See :data:`os.pathsep` path separator.
67
Victor Stinnera41782c2021-04-08 22:32:21 +020068 .. 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 Stinner54366952021-04-09 01:58:20 +020075 See :data:`decimal.HAVE_CONTEXTVAR` and the :mod:`contextvars` module.
Victor Stinnera41782c2021-04-08 22:32:21 +020076
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 Stinner54366952021-04-09 01:58:20 +020083 A valid value is a colon (``:``) separated string with the backend names:
Victor Stinnera41782c2021-04-08 22:32:21 +020084
85 * ``ndbm``;
86 * ``gdbm``;
87 * ``bdb``.
88
Victor Stinner54366952021-04-09 01:58:20 +020089.. cmdoption:: --without-c-locale-coercion
Victor Stinnera41782c2021-04-08 22:32:21 +020090
Victor Stinner54366952021-04-09 01:58:20 +020091 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 Stinnera41782c2021-04-08 22:32:21 +020094
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
120Install 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 Stinner54366952021-04-09 01:58:20 +0200130.. cmdoption:: --with-ensurepip=[upgrade|install|no]
Victor Stinnera41782c2021-04-08 22:32:21 +0200131
Victor Stinner54366952021-04-09 01:58:20 +0200132 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 Stinnera41782c2021-04-08 22:32:21 +0200138
139 .. versionadded:: 3.6
140
141
142Performance options
143-------------------
144
145Configuring Python using ``--enable-optimizations --with-lto`` (PGO + LTO) is
146recommended 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 Stinnerbd88ccb2021-04-09 14:35:10 +0200153 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 Stinnera41782c2021-04-08 22:32:21 +0200156 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 Stinnerbd88ccb2021-04-09 14:35:10 +0200178 The C compiler Clang requires ``llvm-ar`` for LTO, as well as an LTO-aware
179 linker (``ld.gold`` or ``lld``).
180
Victor Stinnera41782c2021-04-08 22:32:21 +0200181 .. 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 Stinner54366952021-04-09 01:58:20 +0200200 Don't define the ``WITH_DOC_STRINGS`` macro.
201
202 See the ``PyDoc_STRVAR()`` macro.
Victor Stinnera41782c2021-04-08 22:32:21 +0200203
204.. cmdoption:: --enable-profiling
205
206 Enable C-level code profiling with ``gprof`` (disabled by default).
207
208
209.. _debug-build:
210
Victor Stinnerabfd6382021-04-29 13:06:59 +0200211Python Debug Build
212------------------
Victor Stinnera41782c2021-04-08 22:32:21 +0200213
214A debug build is Python built with the :option:`--with-pydebug` configure
215option.
216
217Effects of a debug build:
218
Victor Stinnerabfd6382021-04-29 13:06:59 +0200219* Display all warnings by default: the list of default warning filters is empty
220 in the :mod:`warnings` module.
Victor Stinnera41782c2021-04-08 22:32:21 +0200221* Add ``d`` to :data:`sys.abiflags`.
222* Add :func:`sys.gettotalrefcount` function.
223* Add :option:`-X showrefcount <-X>` command line option.
224* Add :envvar:`PYTHONTHREADDEBUG` environment variable.
Victor Stinner54366952021-04-09 01:58:20 +0200225* Add support for the ``__ltrace__`` variable: enable low-level tracing in the
226 bytecode evaluation loop if the variable is defined.
Victor Stinnerabfd6382021-04-29 13:06:59 +0200227* Install :ref:`debug hooks on memory allocators <default-memory-allocators>`
228 to detect buffer overflow and other memory errors.
229* Define ``Py_DEBUG`` and ``Py_REF_DEBUG`` macros.
230* Add runtime checks: code surroundeded by ``#ifdef Py_DEBUG`` and ``#endif``.
231 Enable ``assert(...)`` and ``_PyObject_ASSERT(...)`` assertions: don't set
232 the ``NDEBUG`` macro (see also the :option:`--with-assertions` configure
233 option). Main runtime checks:
234
235 * Add sanity checks on the function arguments.
236 * Unicode and int objects are created with their memory filled with a pattern
237 to detect usage of uninitialized objects.
238 * Ensure that functions which can clear or replace the current exception are
239 not called with an exception raised.
240 * The garbage collector (:func:`gc.collect` function) runs some basic checks
241 on objects consistency.
242 * The :c:macro:`Py_SAFE_DOWNCAST()` macro checks for integer underflow and
243 overflow when downcasting from wide types to narrow types.
Victor Stinnera41782c2021-04-08 22:32:21 +0200244
245See also the :ref:`Python Development Mode <devmode>` and the
246:option:`--with-trace-refs` configure option.
247
248.. versionchanged:: 3.8
249 Release builds and debug builds are now ABI compatible: defining the
Victor Stinnerabfd6382021-04-29 13:06:59 +0200250 ``Py_DEBUG`` macro no longer implies the ``Py_TRACE_REFS`` macro (see the
251 :option:`--with-trace-refs` option), which introduces the only ABI
252 incompatibility.
Victor Stinnera41782c2021-04-08 22:32:21 +0200253
254
255Debug options
256-------------
257
258.. cmdoption:: --with-pydebug
259
Victor Stinner54366952021-04-09 01:58:20 +0200260 :ref:`Build Python in debug mode <debug-build>`: define the ``Py_DEBUG``
261 macro (disabled by default).
Victor Stinnera41782c2021-04-08 22:32:21 +0200262
263.. cmdoption:: --with-trace-refs
264
265 Enable tracing references for debugging purpose (disabled by default).
266
267 Effects:
268
269 * Define the ``Py_TRACE_REFS`` macro.
270 * Add :func:`sys.getobjects` function.
271 * Add :envvar:`PYTHONDUMPREFS` environment variable.
272
273 This build is not ABI compatible with release build (default build) or debug
Victor Stinner54366952021-04-09 01:58:20 +0200274 build (``Py_DEBUG`` and ``Py_REF_DEBUG`` macros).
Victor Stinnera41782c2021-04-08 22:32:21 +0200275
276 .. versionadded:: 3.8
277
278.. cmdoption:: --with-assertions
279
Victor Stinner54366952021-04-09 01:58:20 +0200280 Build with C assertions enabled (default is no): ``assert(...);`` and
281 ``_PyObject_ASSERT(...);``.
Victor Stinnera41782c2021-04-08 22:32:21 +0200282
283 If set, the ``NDEBUG`` macro is not defined in the :envvar:`OPT` compiler
284 variable.
285
286 See also the :option:`--with-pydebug` option (:ref:`debug build
287 <debug-build>`) which also enables assertions.
288
289 .. versionadded:: 3.6
290
291.. cmdoption:: --with-valgrind
292
293 Enable Valgrind support (default is no).
294
295.. cmdoption:: --with-dtrace
296
297 Enable DTrace support (default is no).
298
Victor Stinner85918e42021-04-12 23:27:35 +0200299 See :ref:`Instrumenting CPython with DTrace and SystemTap
300 <instrumentation>`.
301
Victor Stinnera41782c2021-04-08 22:32:21 +0200302 .. versionadded:: 3.6
303
304.. cmdoption:: --with-address-sanitizer
305
Victor Stinner54366952021-04-09 01:58:20 +0200306 Enable AddressSanitizer memory error detector, ``asan`` (default is no).
Victor Stinnera41782c2021-04-08 22:32:21 +0200307
308 .. versionadded:: 3.6
309
310.. cmdoption:: --with-memory-sanitizer
311
Victor Stinner54366952021-04-09 01:58:20 +0200312 Enable MemorySanitizer allocation error detector, ``msan`` (default is no).
Victor Stinnera41782c2021-04-08 22:32:21 +0200313
314 .. versionadded:: 3.6
315
316.. cmdoption:: --with-undefined-behavior-sanitizer
317
Victor Stinner54366952021-04-09 01:58:20 +0200318 Enable UndefinedBehaviorSanitizer undefined behaviour detector, ``ubsan``
Victor Stinnera41782c2021-04-08 22:32:21 +0200319 (default is no).
320
321 .. versionadded:: 3.6
322
323
324Linker options
325--------------
326
327.. cmdoption:: --enable-shared
328
Victor Stinner54366952021-04-09 01:58:20 +0200329 Enable building a shared Python library: ``libpython`` (default is no).
Victor Stinnera41782c2021-04-08 22:32:21 +0200330
331.. cmdoption:: --without-static-libpython
332
333 Do not build ``libpythonMAJOR.MINOR.a`` and do not install ``python.o``
334 (built and enabled by default).
335
336 .. versionadded:: 3.10
337
338
339Libraries options
340-----------------
341
342.. cmdoption:: --with-libs='lib1 ...'
343
344 Link against additional libraries (default is no).
345
346.. cmdoption:: --with-system-expat
347
348 Build the :mod:`pyexpat` module using an installed ``expat`` library
349 (default is no).
350
351.. cmdoption:: --with-system-ffi
352
353 Build the :mod:`_ctypes` extension module using an installed ``ffi``
354 library, see the :mod:`ctypes` module (default is system-dependent).
355
356.. cmdoption:: --with-system-libmpdec
357
Victor Stinner54366952021-04-09 01:58:20 +0200358 Build the ``_decimal`` extension module using an installed ``mpdec``
Victor Stinnera41782c2021-04-08 22:32:21 +0200359 library, see the :mod:`decimal` module (default is no).
360
361 .. versionadded:: 3.3
362
Victor Stinner54366952021-04-09 01:58:20 +0200363.. cmdoption:: --with-readline=editline
Victor Stinnera41782c2021-04-08 22:32:21 +0200364
Victor Stinner54366952021-04-09 01:58:20 +0200365 Use ``editline`` library for backend of the :mod:`readline` module.
366
367 Define the ``WITH_EDITLINE`` macro.
368
369 .. versionadded:: 3.10
370
371.. cmdoption:: --without-readline
372
373 Don't build the :mod:`readline` module (built by default).
374
375 Don't define the ``HAVE_LIBREADLINE`` macro.
Victor Stinnera41782c2021-04-08 22:32:21 +0200376
377 .. versionadded:: 3.10
378
379.. cmdoption:: --with-tcltk-includes='-I...'
380
381 Override search for Tcl and Tk include files.
382
383.. cmdoption:: --with-tcltk-libs='-L...'
384
385 Override search for Tcl and Tk libraries.
386
387.. cmdoption:: --with-libm=STRING
388
389 Override ``libm`` math library to *STRING* (default is system-dependent).
390
391.. cmdoption:: --with-libc=STRING
392
393 Override ``libc`` C library to *STRING* (default is system-dependent).
394
395.. cmdoption:: --with-openssl=DIR
396
397 Root of the OpenSSL directory.
398
Victor Stinner54366952021-04-09 01:58:20 +0200399 .. versionadded:: 3.7
400
401.. cmdoption:: --with-openssl-rpath=[no|auto|DIR]
Victor Stinnera41782c2021-04-08 22:32:21 +0200402
403 Set runtime library directory (rpath) for OpenSSL libraries:
404
405 * ``no`` (default): don't set rpath;
406 * ``auto``: auto-detect rpath from :option:`--with-openssl` and
407 ``pkg-config``;
408 * *DIR*: set an explicit rpath.
409
410 .. versionadded:: 3.10
411
412
413Security Options
414----------------
415
416.. cmdoption:: --with-hash-algorithm=[fnv|siphash24]
417
418 Select hash algorithm for use in ``Python/pyhash.c``:
419
Victor Stinnera41782c2021-04-08 22:32:21 +0200420 * ``siphash24`` (default).
Victor Stinner54366952021-04-09 01:58:20 +0200421 * ``fnv``;
Victor Stinnera41782c2021-04-08 22:32:21 +0200422
423 .. versionadded:: 3.4
424
425.. cmdoption:: --with-builtin-hashlib-hashes=md5,sha1,sha256,sha512,sha3,blake2
426
427 Built-in hash modules:
428
429 * ``md5``;
430 * ``sha1``;
431 * ``sha256``;
432 * ``sha512``;
433 * ``sha3`` (with shake);
434 * ``blake2``.
435
436 .. versionadded:: 3.9
437
438.. cmdoption:: --with-ssl-default-suites=[python|openssl|STRING]
439
440 Override the OpenSSL default cipher suites string:
441
Victor Stinner54366952021-04-09 01:58:20 +0200442 * ``python`` (default): use Python's preferred selection;
Victor Stinnera41782c2021-04-08 22:32:21 +0200443 * ``openssl``: leave OpenSSL's defaults untouched;
Christian Heimese9832522021-05-01 20:53:10 +0200444 * *STRING*: use a custom string
Victor Stinnera41782c2021-04-08 22:32:21 +0200445
446 See the :mod:`ssl` module.
447
448 .. versionadded:: 3.7
449
Christian Heimese9832522021-05-01 20:53:10 +0200450 .. versionchanged:: 3.10
451
452 The settings ``python`` and *STRING* also set TLS 1.2 as minimum
453 protocol version.
Victor Stinnera41782c2021-04-08 22:32:21 +0200454
455macOS Options
456-------------
457
458See ``Mac/README.rst``.
459
Victor Stinner54366952021-04-09 01:58:20 +0200460.. cmdoption:: --enable-universalsdk
461.. cmdoption:: --enable-universalsdk=SDKDIR
Victor Stinnera41782c2021-04-08 22:32:21 +0200462
463 Create a universal binary build. *SDKDIR* specifies which macOS SDK should
464 be used to perform the build (default is no).
465
Victor Stinner54366952021-04-09 01:58:20 +0200466.. cmdoption:: --enable-framework
467.. cmdoption:: --enable-framework=INSTALLDIR
Victor Stinnera41782c2021-04-08 22:32:21 +0200468
469 Create a Python.framework rather than a traditional Unix install. Optional
470 *INSTALLDIR* specifies the installation path (default is no).
471
472.. cmdoption:: --with-universal-archs=ARCH
473
Victor Stinner54366952021-04-09 01:58:20 +0200474 Specify the kind of universal binary that should be created. This option is
Victor Stinnera41782c2021-04-08 22:32:21 +0200475 only valid when :option:`--enable-universalsdk` is set.
476
Victor Stinner54366952021-04-09 01:58:20 +0200477 Options:
Victor Stinnera41782c2021-04-08 22:32:21 +0200478
479 * ``universal2``;
480 * ``32-bit``;
481 * ``64-bit``;
482 * ``3-way``;
483 * ``intel``;
484 * ``intel-32``;
485 * ``intel-64``;
486 * ``all``.
487
488.. cmdoption:: --with-framework-name=FRAMEWORK
489
490 Specify the name for the python framework on macOS only valid when
491 :option:`--enable-framework` is set (default: ``Python``).
492
493
Victor Stinnerbd88ccb2021-04-09 14:35:10 +0200494Python Build System
495===================
496
497Main files of the build system
498------------------------------
499
500* :file:`configure.ac` => :file:`configure`;
501* :file:`Makefile.pre.in` => :file:`Makefile` (created by :file:`configure`);
502* :file:`pyconfig.h` (created by :file:`configure`);
503* :file:`Modules/Setup`: C extensions built by the Makefile using
504 :file:`Module/makesetup` shell script;
505* :file:`setup.py`: C extensions built using the :mod:`distutils` module.
506
507Main build steps
508----------------
509
510* C files (``.c``) are built as object files (``.o``).
511* A static ``libpython`` library (``.a``) is created from objects files.
512* ``python.o`` and the static ``libpython`` library are linked into the
513 final ``python`` program.
514* C extensions are built by the Makefile (see :file:`Modules/Setup`)
515 and ``python setup.py build``.
516
517Main Makefile targets
518---------------------
519
520* ``make``: Build Python with the standard library.
521* ``make platform:``: build the ``python`` program, but don't build the
522 standard library extension modules.
523* ``make profile-opt``: build Python using Profile Guided Optimization (PGO).
524 You can use the configure :option:`--enable-optimizations` option to make
525 this the default target of the ``make`` command (``make all`` or just
526 ``make``).
527* ``make buildbottest``: Build Python and run the Python test suite, the same
528 way than buildbots test Python. Set ``TESTTIMEOUT`` variable (in seconds)
529 to change the test timeout (1200 by default: 20 minutes).
530* ``make install``: Build and install Python.
531* ``make regen-all``: Regenerate (almost) all generated files;
532 ``make regen-stdlib-module-names`` and ``autoconf`` must be run separately
533 for the remaining generated files.
534* ``make clean``: Remove built files.
535* ``make distclean``: Same than ``make clean``, but remove also files created
536 by the configure script.
537
538C extensions
539------------
540
541Some C extensions are built as built-in modules, like the ``sys`` module.
542They are built with the ``Py_BUILD_CORE_BUILTIN`` macro defined.
543Built-in modules have no ``__file__`` attribute::
544
545 >>> import sys
546 >>> sys
547 <module 'sys' (built-in)>
548 >>> sys.__file__
549 Traceback (most recent call last):
550 File "<stdin>", line 1, in <module>
551 AttributeError: module 'sys' has no attribute '__file__'
552
553Other C extensins are built as dynamic libraires, like the ``_asyncio`` module.
554They are built with the ``Py_BUILD_CORE_MODULE`` macro defined.
555Example on Linux x86-64::
556
557 >>> import _asyncio
558 >>> _asyncio
559 <module '_asyncio' from '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so'>
560 >>> _asyncio.__file__
561 '/usr/lib64/python3.9/lib-dynload/_asyncio.cpython-39-x86_64-linux-gnu.so'
562
563:file:`Modules/Setup` is used to generate Makefile targets to build C extensions.
564At the beginning of the files, C extensions are built as built-in modules.
565Extensions defined after the ``*shared*`` marker are built as dynamic libraries.
566
567The :file:`setup.py` script only builds C extensions as shared libraries using
568the :mod:`distutils` module.
569
570The :c:macro:`PyAPI_FUNC()`, :c:macro:`PyAPI_API()` and
571:c:macro:`PyMODINIT_FUNC()` macros of :file:`Include/pyport.h` are defined
572differently depending if the ``Py_BUILD_CORE_MODULE`` macro is defined:
573
574* Use ``Py_EXPORTED_SYMBOL`` if the ``Py_BUILD_CORE_MODULE`` is defined
575* Use ``Py_IMPORTED_SYMBOL`` otherwise.
576
577If the ``Py_BUILD_CORE_BUILTIN`` macro is used by mistake on a C extension
578built as a shared library, its ``PyInit_xxx()`` function is not exported,
579causing an :exc:`ImportError` on import.
580
581
Victor Stinnera41782c2021-04-08 22:32:21 +0200582Compiler and linker flags
583=========================
584
Victor Stinner54366952021-04-09 01:58:20 +0200585Options set by the ``./configure`` script and environment variables and used by
586``Makefile``.
587
Victor Stinnera41782c2021-04-08 22:32:21 +0200588Preprocessor flags
589------------------
590
Victor Stinnera41782c2021-04-08 22:32:21 +0200591.. envvar:: CONFIGURE_CPPFLAGS
592
Victor Stinner54366952021-04-09 01:58:20 +0200593 Value of :envvar:`CPPFLAGS` variable passed to the ``./configure`` script.
594
Victor Stinnera41782c2021-04-08 22:32:21 +0200595 .. versionadded:: 3.6
596
597.. envvar:: CPPFLAGS
598
599 (Objective) C/C++ preprocessor flags, e.g. ``-I<include dir>`` if you have
600 headers in a nonstandard directory ``<include dir>``.
601
602 Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's
603 value for setup.py to be able to build extension modules using the
604 directories specified in the environment variables.
605
606.. envvar:: BASECPPFLAGS
607
608 .. versionadded:: 3.4
609
Victor Stinnera41782c2021-04-08 22:32:21 +0200610.. envvar:: PY_CPPFLAGS
611
612 Extra preprocessor flags added for building the interpreter object files.
613
614 Default: ``$(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)``.
615
616 .. versionadded:: 3.2
617
618Compiler flags
619--------------
620
621.. envvar:: CC
622
623 C compiler command.
624
Victor Stinner54366952021-04-09 01:58:20 +0200625 Example: ``gcc -pthread``.
626
Victor Stinnerbd88ccb2021-04-09 14:35:10 +0200627.. envvar:: MAINCC
628
629 C compiler command used to build the ``main()`` function of programs like
630 ``python``.
631
632 Variable set by the :option:`--with-cxx-main` option of the configure
633 script.
634
635 Default: ``$(CC)``.
636
Victor Stinner54366952021-04-09 01:58:20 +0200637.. envvar:: CXX
638
639 C++ compiler command.
640
641 Used if the :option:`--with-cxx-main` option is used.
642
643 Example: ``g++ -pthread``.
644
Victor Stinnera41782c2021-04-08 22:32:21 +0200645.. envvar:: CFLAGS
646
647 C compiler flags.
648
649.. envvar:: CFLAGS_NODIST
650
651 :envvar:`CFLAGS_NODIST` is used for building the interpreter and stdlib C
652 extensions. Use it when a compiler flag should *not* be part of the
653 distutils :envvar:`CFLAGS` once Python is installed (:issue:`21121`).
654
655 .. versionadded:: 3.5
656
657.. envvar:: EXTRA_CFLAGS
658
659 Extra C compiler flags.
660
661.. envvar:: CONFIGURE_CFLAGS
662
Victor Stinner54366952021-04-09 01:58:20 +0200663 Value of :envvar:`CFLAGS` variable passed to the ``./configure``
664 script.
665
Victor Stinnera41782c2021-04-08 22:32:21 +0200666 .. versionadded:: 3.2
667
668.. envvar:: CONFIGURE_CFLAGS_NODIST
669
Victor Stinner54366952021-04-09 01:58:20 +0200670 Value of :envvar:`CFLAGS_NODIST` variable passed to the ``./configure``
671 script.
672
Victor Stinnera41782c2021-04-08 22:32:21 +0200673 .. versionadded:: 3.5
674
675.. envvar:: BASECFLAGS
676
Victor Stinner54366952021-04-09 01:58:20 +0200677 Base compiler flags.
678
Victor Stinnera41782c2021-04-08 22:32:21 +0200679.. envvar:: OPT
680
681 Optimization flags.
682
683.. envvar:: CFLAGS_ALIASING
684
685 Strict or non-strict aliasing flags used to compile ``Python/dtoa.c``.
686
687 .. versionadded:: 3.7
688
Victor Stinner54366952021-04-09 01:58:20 +0200689.. envvar:: CCSHARED
690
691 Compiler flags used to build a shared library.
692
693 For example, ``-fPIC`` is used on Linux and on BSD.
694
Victor Stinnera41782c2021-04-08 22:32:21 +0200695.. envvar:: CFLAGSFORSHARED
696
697 Extra C flags added for building the interpreter object files.
698
Victor Stinner54366952021-04-09 01:58:20 +0200699 Default: ``$(CCSHARED)`` when :option:`--enable-shared` is used, or an empty
700 string otherwise.
701
Victor Stinnera41782c2021-04-08 22:32:21 +0200702.. envvar:: PY_CFLAGS
703
704 Default: ``$(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)``.
705
706.. envvar:: PY_CFLAGS_NODIST
707
708 Default: ``$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST) -I$(srcdir)/Include/internal``.
709
710 .. versionadded:: 3.5
711
712.. envvar:: PY_STDMODULE_CFLAGS
713
714 C flags used for building the interpreter object files.
715
716 Default: ``$(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED)``.
717
718 .. versionadded:: 3.7
719
720.. envvar:: PY_CORE_CFLAGS
721
722 Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE``.
723
724 .. versionadded:: 3.2
725
726.. envvar:: PY_BUILTIN_MODULE_CFLAGS
727
Victor Stinner54366952021-04-09 01:58:20 +0200728 Compiler flags to build a standard library extension module as a built-in
729 module, like the :mod:`posix` module.
730
Victor Stinnera41782c2021-04-08 22:32:21 +0200731 Default: ``$(PY_STDMODULE_CFLAGS) -DPy_BUILD_CORE_BUILTIN``.
732
733 .. versionadded:: 3.8
734
Victor Stinnerbd88ccb2021-04-09 14:35:10 +0200735.. envvar:: PURIFY
736
737 Purify command. Purify is a memory debugger program.
738
739 Default: empty string (not used).
740
Victor Stinnera41782c2021-04-08 22:32:21 +0200741
742Linker flags
743------------
744
Victor Stinnerbd88ccb2021-04-09 14:35:10 +0200745.. envvar:: LINKCC
746
747 Linker command used to build programs like ``python`` and ``_testembed``.
748
749 Default: ``$(PURIFY) $(MAINCC)``.
750
Victor Stinnera41782c2021-04-08 22:32:21 +0200751.. envvar:: CONFIGURE_LDFLAGS
752
Victor Stinner54366952021-04-09 01:58:20 +0200753 Value of :envvar:`LDFLAGS` variable passed to the ``./configure`` script.
754
Victor Stinnera41782c2021-04-08 22:32:21 +0200755 Avoid assigning :envvar:`CFLAGS`, :envvar:`LDFLAGS`, etc. so users can use
756 them on the command line to append to these values without stomping the
757 pre-set values.
758
759 .. versionadded:: 3.2
760
761.. envvar:: LDFLAGS_NODIST
762
763 :envvar:`LDFLAGS_NODIST` is used in the same manner as
764 :envvar:`CFLAGS_NODIST`. Use it when a linker flag should *not* be part of
765 the distutils :envvar:`LDFLAGS` once Python is installed (:issue:`35257`).
766
767.. envvar:: CONFIGURE_LDFLAGS_NODIST
768
Victor Stinner54366952021-04-09 01:58:20 +0200769 Value of :envvar:`LDFLAGS_NODIST` variable passed to the ``./configure``
770 script.
771
Victor Stinnera41782c2021-04-08 22:32:21 +0200772 .. versionadded:: 3.8
773
774.. envvar:: LDFLAGS
775
776 Linker flags, e.g. ``-L<lib dir>`` if you have libraries in a nonstandard
777 directory ``<lib dir>``.
778
779 Both :envvar:`CPPFLAGS` and :envvar:`LDFLAGS` need to contain the shell's
780 value for setup.py to be able to build extension modules using the
781 directories specified in the environment variables.
782
783.. envvar:: LIBS
784
Victor Stinner54366952021-04-09 01:58:20 +0200785 Linker flags to pass libraries to the linker when linking the Python
786 executable.
787
788 Example: ``-lrt``.
Victor Stinnera41782c2021-04-08 22:32:21 +0200789
790.. envvar:: LDSHARED
791
792 Command to build a shared library.
793
794 Default: ``@LDSHARED@ $(PY_LDFLAGS)``.
795
796.. envvar:: BLDSHARED
797
Victor Stinner54366952021-04-09 01:58:20 +0200798 Command to build ``libpython`` shared library.
Victor Stinnera41782c2021-04-08 22:32:21 +0200799
800 Default: ``@BLDSHARED@ $(PY_CORE_LDFLAGS)``.
801
802.. envvar:: PY_LDFLAGS
803
804 Default: ``$(CONFIGURE_LDFLAGS) $(LDFLAGS)``.
805
806.. envvar:: PY_LDFLAGS_NODIST
807
808 Default: ``$(CONFIGURE_LDFLAGS_NODIST) $(LDFLAGS_NODIST)``.
809
810 .. versionadded:: 3.8
811
812.. envvar:: PY_CORE_LDFLAGS
813
814 Linker flags used for building the interpreter object files.
815
816 .. versionadded:: 3.8