Makefile.pre.in 59.2 KB
Newer Older
1
# Top-level Makefile for Python
2
#
3 4 5 6 7
# As distributed, this file is called Makefile.pre.in; it is processed
# into the real Makefile by running the script ./configure, which
# replaces things like @spam@ with values appropriate for your system.
# This means that if you edit Makefile, your changes get lost the next
# time you run the configure script.  Ideally, you can do:
8
#
9 10 11 12
#	./configure
#	make
#	make test
#	make install
13
#
14 15
# If you have a previous version of Python installed that you don't
# want to overwrite, you can use "make altinstall" instead of "make
16 17
# install".  Refer to the "Installing" section in the README file for
# additional details.
18
#
19 20 21 22
# See also the section "Build instructions" in the README file.

# === Variables set by makesetup ===

23 24 25 26
MODBUILT_NAMES=    _MODBUILT_NAMES_
MODDISABLED_NAMES= _MODDISABLED_NAMES_
MODOBJS=           _MODOBJS_
MODLIBS=           _MODLIBS_
27 28 29 30 31

# === Variables set by configure
VERSION=	@VERSION@
srcdir=		@srcdir@
VPATH=		@srcdir@
32 33
abs_srcdir=	@abs_srcdir@
abs_builddir=	@abs_builddir@
34

35 36 37

CC=		@CC@
CXX=		@CXX@
38
MAINCC=		@MAINCC@
39 40 41
LINKCC=		@LINKCC@
AR=		@AR@
RANLIB=		@RANLIB@
42
READELF=	@READELF@
Georg Brandl's avatar
Georg Brandl committed
43
SOABI=		@SOABI@
44
LDVERSION=	@LDVERSION@
45 46 47
GITVERSION=	@GITVERSION@
GITTAG=		@GITTAG@
GITBRANCH=	@GITBRANCH@
48 49 50 51 52
PGO_PROF_GEN_FLAG=@PGO_PROF_GEN_FLAG@
PGO_PROF_USE_FLAG=@PGO_PROF_USE_FLAG@
LLVM_PROF_MERGER=@LLVM_PROF_MERGER@
LLVM_PROF_FILE=@LLVM_PROF_FILE@
LLVM_PROF_ERR=@LLVM_PROF_ERR@
53 54 55 56
DTRACE=         @DTRACE@
DFLAGS=         @DFLAGS@
DTRACE_HEADERS= @DTRACE_HEADERS@
DTRACE_OBJS=    @DTRACE_OBJS@
57

Georg Brandl's avatar
Georg Brandl committed
58
GNULD=		@GNULD@
59

60 61 62 63 64 65 66 67 68
# Shell used by make (some versions default to the login shell, which is bad)
SHELL=		/bin/sh

# Use this to make a link between python$(VERSION) and python in $(BINDIR)
LN=		@LN@

# Portable install script (configure doesn't always guess right)
INSTALL=	@INSTALL@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
69
INSTALL_SCRIPT= @INSTALL_SCRIPT@
70 71 72 73 74 75
INSTALL_DATA=	@INSTALL_DATA@
# Shared libraries must be installed with executable mode on some systems;
# rather than figuring out exactly which, we always give them executable mode.
# Also, making them read-only seems to be a good idea...
INSTALL_SHARED= ${INSTALL} -m 555

76 77
MKDIR_P=	@MKDIR_P@

78 79 80 81
MAKESETUP=      $(srcdir)/Modules/makesetup

# Compiler options
OPT=		@OPT@
82
BASECFLAGS=	@BASECFLAGS@
83
BASECPPFLAGS=	@BASECPPFLAGS@
84
CONFIGURE_CFLAGS=	@CFLAGS@
85 86 87 88
# CFLAGS_NODIST is used for building the interpreter and stdlib C extensions.
# Use it when a compiler flag should _not_ be part of the distutils CFLAGS
# once Python is installed (Issue #21121).
CONFIGURE_CFLAGS_NODIST=@CFLAGS_NODIST@
89 90 91 92 93 94
CONFIGURE_CPPFLAGS=	@CPPFLAGS@
CONFIGURE_LDFLAGS=	@LDFLAGS@
# Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
# command line to append to these values without stomping the pre-set
# values.
PY_CFLAGS=	$(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
95
PY_CFLAGS_NODIST=$(CONFIGURE_CFLAGS_NODIST) $(CFLAGS_NODIST)
96 97 98
# Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
# be able to build extension modules using the directories specified in the
# environment variables
99
PY_CPPFLAGS=	$(BASECPPFLAGS) -I. -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
100
PY_LDFLAGS=	$(CONFIGURE_LDFLAGS) $(LDFLAGS)
101
NO_AS_NEEDED=	@NO_AS_NEEDED@
102 103
LDLAST=		@LDLAST@
SGI_ABI=	@SGI_ABI@
104 105
CCSHARED=	@CCSHARED@
LINKFORSHARED=	@LINKFORSHARED@
106
ARFLAGS=	@ARFLAGS@
107 108 109
# Extra C flags added for building the interpreter object files.
CFLAGSFORSHARED=@CFLAGSFORSHARED@
# C flags used for building the interpreter object files
110
PY_CORE_CFLAGS=	$(PY_CFLAGS) $(PY_CFLAGS_NODIST) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
111 112
# Strict or non-strict aliasing flags used to compile dtoa.c, see above
CFLAGS_ALIASING=@CFLAGS_ALIASING@
113

114 115 116 117

# Machine-dependent subdirectories
MACHDEP=	@MACHDEP@

118 119
# Multiarch directory (may be empty)
MULTIARCH=	@MULTIARCH@
120
MULTIARCH_CPPFLAGS = @MULTIARCH_CPPFLAGS@
121

122 123 124 125 126 127
# Install prefix for architecture-independent files
prefix=		@prefix@

# Install prefix for architecture-dependent files
exec_prefix=	@exec_prefix@

128 129 130
# Install prefix for data files
datarootdir=    @datarootdir@

131
# Expanded directories
132 133
BINDIR=		@bindir@
LIBDIR=		@libdir@
134 135
MANDIR=		@mandir@
INCLUDEDIR=	@includedir@
136 137
CONFINCLUDEDIR=	$(exec_prefix)/include
SCRIPTDIR=	$(prefix)/lib
138
ABIFLAGS=	@ABIFLAGS@
139 140 141 142

# Detailed destination directories
BINLIBDEST=	$(LIBDIR)/python$(VERSION)
LIBDEST=	$(SCRIPTDIR)/python$(VERSION)
143 144
INCLUDEPY=	$(INCLUDEDIR)/python$(LDVERSION)
CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(LDVERSION)
145 146

# Symbols used for using shared libraries
147 148
SHLIB_SUFFIX=	@SHLIB_SUFFIX@
EXT_SUFFIX=	@EXT_SUFFIX@
149 150
LDSHARED=	@LDSHARED@ $(PY_LDFLAGS)
BLDSHARED=	@BLDSHARED@ $(PY_LDFLAGS)
151
LDCXXSHARED=	@LDCXXSHARED@
152 153 154
DESTSHARED=	$(BINLIBDEST)/lib-dynload

# Executable suffix (.exe on Windows and Mac OS X)
155
EXE=		@EXEEXT@
156
BUILDEXE=	@BUILDEXEEXT@
157

158
# Short name and location for Mac OS X Python framework
159
UNIVERSALSDK=@UNIVERSALSDK@
160 161 162 163
PYTHONFRAMEWORK=	@PYTHONFRAMEWORK@
PYTHONFRAMEWORKDIR=	@PYTHONFRAMEWORKDIR@
PYTHONFRAMEWORKPREFIX=	@PYTHONFRAMEWORKPREFIX@
PYTHONFRAMEWORKINSTALLDIR= @PYTHONFRAMEWORKINSTALLDIR@
164
# Deployment target selected during configure, to be checked
165 166 167 168 169
# by distutils. The export statement is needed to ensure that the
# deployment target is active during build.
MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@
@EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET

170 171 172 173 174 175
# Option to install to strip binaries
STRIPFLAG=-s

# Flags to lipo to produce a 32-bit-only universal executable
LIPO_32BIT_FLAGS=@LIPO_32BIT_FLAGS@

176 177
# Options to enable prebinding (for fast startup prior to Mac OS X 10.3)
OTHER_LIBTOOL_OPT=@OTHER_LIBTOOL_OPT@
178

179 180 181
# Environment to run shared python without installed libraries
RUNSHARED=       @RUNSHARED@

182 183 184
# ensurepip options
ENSUREPIP=      @ENSUREPIP@

185 186 187 188 189 190
# Modes for directories, executables and data files created by the
# install process.  Default to user-only-writable for all file types.
DIRMODE=	755
EXEMODE=	755
FILEMODE=	644

191 192
# configure script arguments
CONFIG_ARGS=	@CONFIG_ARGS@
193 194 195 196 197 198


# Subdirectories with code
SRCDIRS= 	@SRCDIRS@

# Other subdirectories
199
SUBDIRSTOO=	Include Lib Misc
200 201

# Files and directories to be distributed
202
CONFIGFILES=	configure configure.ac acconfig.h pyconfig.h.in Makefile.pre.in
203
DISTFILES=	README.rst ChangeLog $(CONFIGFILES)
204 205 206 207
DISTDIRS=	$(SUBDIRS) $(SUBDIRSTOO) Ext-dummy
DIST=		$(DISTFILES) $(DISTDIRS)


208
LIBRARY=	@LIBRARY@
209
LDLIBRARY=      @LDLIBRARY@
210
BLDLIBRARY=     @BLDLIBRARY@
211
PY3LIBRARY=     @PY3LIBRARY@
212
DLLLIBRARY=	@DLLLIBRARY@
213
LDLIBRARYDIR=   @LDLIBRARYDIR@
214
INSTSONAME=	@INSTSONAME@
215 216 217 218 219 220


LIBS=		@LIBS@
LIBM=		@LIBM@
LIBC=		@LIBC@
SYSLIBS=	$(LIBM) $(LIBC)
221
SHLIBS=		@SHLIBS@
222 223 224

DLINCLDIR=	@DLINCLDIR@
DYNLOADFILE=	@DYNLOADFILE@
225
MACHDEP_OBJS=	@MACHDEP_OBJS@
226 227
LIBOBJDIR=	Python/
LIBOBJS=	@LIBOBJS@
228

229
PYTHON=		python$(EXE)
230
BUILDPYTHON=	python$(BUILDEXE)
231

232
PYTHON_FOR_REGEN=@PYTHON_FOR_REGEN@
233
UPDATE_FILE=@PYTHON_FOR_REGEN@ $(srcdir)/Tools/scripts/update_file.py
234 235
PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
236 237
BUILD_GNU_TYPE=	@build@
HOST_GNU_TYPE=	@host@
238

239 240 241 242
# Tcl and Tk config info from --with-tcltk-includes and -libs options
TCLTK_INCLUDES=	@TCLTK_INCLUDES@
TCLTK_LIBS=	@TCLTK_LIBS@

243 244 245
# The task to run while instrumented when building the profile-opt target.
# We exclude unittests with -x that take a rediculious amount of time to
# run in the instrumented training build or do not provide much value.
246
PROFILE_TASK=-m test.regrtest --pgo
Christian Heimes's avatar
Christian Heimes committed
247

248 249 250 251 252 253
# report files for gcov / lcov coverage report
COVERAGE_INFO=	$(abs_builddir)/coverage.info
COVERAGE_REPORT=$(abs_builddir)/lcov-report
COVERAGE_REPORT_OPTIONS=--no-branch-coverage --title "CPython lcov report"


254 255 256 257 258 259 260 261
# === Definitions added by makesetup ===


##########################################################################
# Modules
MODULE_OBJS=	\
		Modules/config.o \
		Modules/getpath.o \
262 263
		Modules/main.o \
		Modules/gcmodule.o
264

265
IO_H=		Modules/_io/_iomodule.h
266 267

IO_OBJS=	\
268 269 270 271 272 273 274
		Modules/_io/_iomodule.o \
		Modules/_io/iobase.o \
		Modules/_io/fileio.o \
		Modules/_io/bufferedio.o \
		Modules/_io/textio.o \
		Modules/_io/bytesio.o \
		Modules/_io/stringio.o
275 276 277

##########################################################################

278 279
LIBFFI_INCLUDEDIR=	@LIBFFI_INCLUDEDIR@

280 281
##########################################################################
# Parser
282
PGEN=		Parser/pgen$(EXE)
283 284 285 286 287 288 289 290

POBJS=		\
		Parser/acceler.o \
		Parser/grammar1.o \
		Parser/listnode.o \
		Parser/node.o \
		Parser/parser.o \
		Parser/bitset.o \
291 292 293 294
		Parser/metagrammar.o \
		Parser/firstsets.o \
		Parser/grammar.o \
		Parser/pgen.o
295

296
PARSER_OBJS=	$(POBJS) Parser/myreadline.o Parser/parsetok.o Parser/tokenizer.o
297 298

PGOBJS=		\
299
		Objects/obmalloc.o \
300
		Python/dynamic_annotations.o \
301
		Python/mysnprintf.o \
302
		Python/pyctype.o \
303
		Parser/tokenizer_pgen.o \
304
		Parser/printgrammar.o \
305
		Parser/parsetok_pgen.o \
306 307
		Parser/pgenmain.o

308
PARSER_HEADERS= \
309 310 311
		$(srcdir)/Parser/parser.h \
		$(srcdir)/Include/parsetok.h \
		$(srcdir)/Parser/tokenizer.h
312

313
PGENOBJS=	$(POBJS) $(PGOBJS)
314 315 316

##########################################################################
# Python
317

318
PYTHON_OBJS=	\
Christian Heimes's avatar
Christian Heimes committed
319
		Python/_warnings.o \
Jeremy Hylton's avatar
Jeremy Hylton committed
320 321 322
		Python/Python-ast.o \
		Python/asdl.o \
		Python/ast.o \
323 324 325 326
		Python/bltinmodule.o \
		Python/ceval.o \
		Python/compile.o \
		Python/codecs.o \
327
		Python/dynamic_annotations.o \
328 329
		Python/errors.o \
		Python/frozenmain.o \
330
		Python/future.o \
331 332 333 334 335 336 337 338 339 340 341
		Python/getargs.o \
		Python/getcompiler.o \
		Python/getcopyright.o \
		Python/getplatform.o \
		Python/getversion.o \
		Python/graminit.o \
		Python/import.o \
		Python/importdl.o \
		Python/marshal.o \
		Python/modsupport.o \
		Python/mystrtoul.o \
342
		Python/mysnprintf.o \
343
		Python/peephole.o \
344
		Python/pyarena.o \
345
		Python/pyctype.o \
346
		Python/pyfpe.o \
347
		Python/pyhash.o \
348
		Python/pylifecycle.o \
349
		Python/pymath.o \
350 351
		Python/pystate.o \
		Python/pythonrun.o \
352
		Python/pytime.o \
353
		Python/bootstrap_hash.o \
354
		Python/structmember.o \
355
		Python/symtable.o \
356
		Python/sysmodule.o \
357
		Python/thread.o \
358 359
		Python/traceback.o \
		Python/getopt.o \
360
		Python/pystrcmp.o \
361
		Python/pystrtod.o \
362
		Python/pystrhex.o \
363
		Python/dtoa.o \
364
		Python/formatter_unicode.o \
Victor Stinner's avatar
Victor Stinner committed
365
		Python/fileutils.o \
366
		Python/$(DYNLOADFILE) \
367
		$(LIBOBJS) \
368
		$(MACHDEP_OBJS) \
369
		$(DTRACE_OBJS)
370 371 372 373 374 375


##########################################################################
# Objects
OBJECT_OBJS=	\
		Objects/abstract.o \
376
		Objects/accu.o \
377
		Objects/boolobject.o \
378
		Objects/bytes_methods.o \
379
		Objects/bytearrayobject.o \
380
		Objects/bytesobject.o \
381
		Objects/call.o \
Jeremy Hylton's avatar
Jeremy Hylton committed
382
		Objects/cellobject.o \
383
		Objects/classobject.o \
Jeremy Hylton's avatar
Jeremy Hylton committed
384
		Objects/codeobject.o \
385
		Objects/complexobject.o \
386
		Objects/descrobject.o \
387
		Objects/enumobject.o \
388
		Objects/exceptions.o \
389
		Objects/genobject.o \
390 391 392 393
		Objects/fileobject.o \
		Objects/floatobject.o \
		Objects/frameobject.o \
		Objects/funcobject.o \
394
		Objects/iterobject.o \
395 396 397
		Objects/listobject.o \
		Objects/longobject.o \
		Objects/dictobject.o \
398
		Objects/odictobject.o \
399
		Objects/memoryobject.o \
400 401
		Objects/methodobject.o \
		Objects/moduleobject.o \
402
		Objects/namespaceobject.o \
403
		Objects/object.o \
404
		Objects/obmalloc.o \
405
		Objects/capsule.o \
406
		Objects/rangeobject.o \
407
		Objects/setobject.o \
408
		Objects/sliceobject.o \
409
		Objects/structseq.o \
410 411
		Objects/tupleobject.o \
		Objects/typeobject.o \
412 413 414
		Objects/unicodeobject.o \
		Objects/unicodectype.o \
		Objects/weakrefobject.o
415 416 417

##########################################################################
# objects that get linked into the Python library
418
LIBRARY_OBJS_OMIT_FROZEN=	\
419
		Modules/getbuildinfo.o \
420 421 422 423 424 425
		$(PARSER_OBJS) \
		$(OBJECT_OBJS) \
		$(PYTHON_OBJS) \
		$(MODULE_OBJS) \
		$(MODOBJS)

426 427 428 429
LIBRARY_OBJS=	\
		$(LIBRARY_OBJS_OMIT_FROZEN) \
		Python/frozen.o

430 431 432 433 434 435 436 437 438
##########################################################################
# DTrace

# On some systems, object files that reference DTrace probes need to be modified
# in-place by dtrace(1).
DTRACE_DEPS = \
	Python/ceval.o
# XXX: should gcmodule, etc. be here, too?

439 440 441 442
#########################################################################
# Rules

# Default target
443
all:		@DEF_MAKE_ALL_RULE@
444
build_all:	$(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config
445

446
# Compile a binary with profile guided optimization.
Christian Heimes's avatar
Christian Heimes committed
447
profile-opt:
448
	@if [ $(LLVM_PROF_ERR) = yes ]; then \
449 450 451 452
		echo "Error: Cannot perform PGO build because llvm-profdata was not found in PATH" ;\
		echo "Please add it to PATH and run ./configure again" ;\
		exit 1;\
	fi
Christian Heimes's avatar
Christian Heimes committed
453 454
	@echo "Building with support for profile generation:"
	$(MAKE) clean
455
	$(MAKE) profile-removal
Christian Heimes's avatar
Christian Heimes committed
456 457
	$(MAKE) build_all_generate_profile
	$(MAKE) profile-removal
458
	@echo "Running code to generate profile data (this can take a while):"
Christian Heimes's avatar
Christian Heimes committed
459
	$(MAKE) run_profile_task
460
	$(MAKE) build_all_merge_profile
Christian Heimes's avatar
Christian Heimes committed
461 462 463
	@echo "Rebuilding with profile guided optimizations:"
	$(MAKE) clean
	$(MAKE) build_all_use_profile
464
	$(MAKE) profile-removal
Christian Heimes's avatar
Christian Heimes committed
465 466

build_all_generate_profile:
467
	$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_GEN_FLAG)" LDFLAGS="$(LDFLAGS) $(PGO_PROF_GEN_FLAG)" LIBS="$(LIBS)"
Christian Heimes's avatar
Christian Heimes committed
468 469

run_profile_task:
470
	@ # FIXME: can't run for a cross build
471 472 473 474
	$(LLVM_PROF_FILE) $(RUNSHARED) ./$(BUILDPYTHON) $(PROFILE_TASK) || true

build_all_merge_profile:
	$(LLVM_PROF_MERGER)
Christian Heimes's avatar
Christian Heimes committed
475 476

build_all_use_profile:
477
	$(MAKE) @DEF_MAKE_RULE@ CFLAGS_NODIST="$(CFLAGS) $(PGO_PROF_USE_FLAG)" LDFLAGS="$(LDFLAGS)"
Christian Heimes's avatar
Christian Heimes committed
478

479 480
# Compile and run with gcov
.PHONY=coverage coverage-lcov coverage-report
Georg Brandl's avatar
Georg Brandl committed
481 482
coverage:
	@echo "Building with support for coverage checking:"
483
	$(MAKE) clean profile-removal
484
	$(MAKE) @DEF_MAKE_RULE@ CFLAGS="$(CFLAGS) -O0 -pg -fprofile-arcs -ftest-coverage" LIBS="$(LIBS) -lgcov"
Georg Brandl's avatar
Georg Brandl committed
485

486 487 488 489 490 491 492 493
coverage-lcov:
	@echo "Creating Coverage HTML report with LCOV:"
	@rm -f $(COVERAGE_INFO)
	@rm -rf $(COVERAGE_REPORT)
	@lcov --capture --directory $(abs_builddir) \
	    --base-directory $(realpath $(abs_builddir)) \
	    --path $(realpath $(abs_srcdir)) \
	    --output-file $(COVERAGE_INFO)
494 495
	@ # remove 3rd party modules, system headers and internal files with
	@ # debug, test or dummy functions.
496
	@lcov --remove $(COVERAGE_INFO) \
497
	    '*/Modules/_blake2/impl/*' \
498 499
	    '*/Modules/_ctypes/libffi*/*' \
	    '*/Modules/_decimal/libmpdec/*' \
500
	    '*/Modules/_sha3/kcp/*' \
501 502 503
	    '*/Modules/expat/*' \
	    '*/Modules/zlib/*' \
	    '*/Include/*' \
504 505 506 507
	    '*/Modules/xx*.c' \
	    '*/Parser/listnode.c' \
	    '*/Python/pyfpe.c' \
	    '*/Python/pystrcmp.c' \
508 509
	    '/usr/include/*' \
	    '/usr/local/include/*' \
510
	    '/usr/lib/gcc/*' \
511 512 513 514 515 516 517
	    --output-file $(COVERAGE_INFO)
	@genhtml $(COVERAGE_INFO) --output-directory $(COVERAGE_REPORT) \
	    $(COVERAGE_REPORT_OPTIONS)
	@echo
	@echo "lcov report at $(COVERAGE_REPORT)/index.html"
	@echo

518 519
# Force regeneration of parser and importlib
coverage-report: regen-grammar regen-importlib
520
	@ # build with coverage info
521
	$(MAKE) coverage
522
	@ # run tests, ignore failures
523
	$(TESTRUNNER) $(TESTOPTS) || true
524
	@ # build lcov report
525
	$(MAKE) coverage-lcov
Georg Brandl's avatar
Georg Brandl committed
526

527 528 529
# Run "Argument Clinic" over all source files
# (depends on python having already been built)
.PHONY=clinic
530
clinic: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2s_impl.c
531
	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/clinic/clinic.py --make --srcdir $(srcdir)
532

533
# Build the interpreter
534 535
$(BUILDPYTHON):	Programs/python.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
	$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/python.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
536

537
platform: $(BUILDPYTHON) pybuilddir.txt
538
	$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%d" % (get_platform(), *sys.version_info[:2]))' >platform
539

540 541 542
# Create build directory and generate the sysconfig build-time data there.
# pybuilddir.txt contains the name of the build dir and is used for
# sys.path fixup -- see Modules/getpath.c.
543
# Since this step runs before shared modules are built, try to avoid bootstrap
544
# problems by creating a dummy pybuilddir.txt just to allow interpreter
545 546
# initialization to succeed.  It will be overwritten by generate-posix-vars
# or removed in case of failure.
547
pybuilddir.txt: $(BUILDPYTHON)
548 549 550 551 552 553 554
	@echo "none" > ./pybuilddir.txt
	$(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars ;\
	if test $$? -ne 0 ; then \
		echo "generate-posix-vars failed" ; \
		rm -f ./pybuilddir.txt ; \
		exit 1 ; \
	fi
555

556 557 558 559
# This is shared by the math and cmath modules
Modules/_math.o: Modules/_math.c Modules/_math.h
	$(CC) -c $(CCSHARED) $(PY_CORE_CFLAGS) -o $@ $<

560
# blake2s is auto-generated from blake2b
561 562 563
$(srcdir)/Modules/_blake2/blake2s_impl.c: $(BUILDPYTHON) $(srcdir)/Modules/_blake2/blake2b_impl.c $(srcdir)/Modules/_blake2/blake2b2s.py
	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Modules/_blake2/blake2b2s.py
	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/Tools/clinic/clinic.py -f $@
564

565
# Build the shared modules
566
# Under GNU make, MAKEFLAGS are sorted and normalized; the 's' for
Christian Heimes's avatar
Christian Heimes committed
567
# -s, --silent or --quiet is always the first char.
568
# Under BSD make, MAKEFLAGS might be " -s -v x=y".
569
sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o
Christian Heimes's avatar
Christian Heimes committed
570
	@case "$$MAKEFLAGS" in \
571
	    *\ -s*|s*) quiet="-q";; \
Christian Heimes's avatar
Christian Heimes committed
572 573
	    *) quiet="";; \
	esac; \
574
	$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
575
		_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
Christian Heimes's avatar
Christian Heimes committed
576
		$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
577

578

579
# Build static library
580
# avoid long command lines, same as LIBRARY_OBJS
581 582
$(LIBRARY): $(LIBRARY_OBJS)
	-rm -f $@
583 584 585
	$(AR) $(ARFLAGS) $@ Modules/getbuildinfo.o
	$(AR) $(ARFLAGS) $@ $(PARSER_OBJS)
	$(AR) $(ARFLAGS) $@ $(OBJECT_OBJS)
586
	$(AR) $(ARFLAGS) $@ $(PYTHON_OBJS) Python/frozen.o
587
	$(AR) $(ARFLAGS) $@ $(MODULE_OBJS)
588
	$(AR) $(ARFLAGS) $@ $(MODOBJS)
589 590
	$(RANLIB) $@

591
libpython$(LDVERSION).so: $(LIBRARY_OBJS)
592
	if test $(INSTSONAME) != $(LDLIBRARY); then \
593
		$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
594
		$(LN) -f $(INSTSONAME) $@; \
595
	else \
596
		$(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
597
	fi
598

599
libpython3.so:	libpython$(LDVERSION).so
600
	$(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^
601

602 603
libpython$(LDVERSION).dylib: $(LIBRARY_OBJS)
	 $(CC) -dynamiclib -Wl,-single_module $(PY_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(LDVERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
Victor Stinner's avatar
Victor Stinner committed
604

605

606
libpython$(VERSION).sl: $(LIBRARY_OBJS)
607
	$(LDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
608

609 610 611 612 613 614 615 616 617 618 619
# Copy up the gdb python hooks into a position where they can be automatically
# loaded by gdb during Lib/test/test_gdb.py
#
# Distributors are likely to want to install this somewhere else e.g. relative
# to the stripped DWARF data for the shared library.
gdbhooks: $(BUILDPYTHON)-gdb.py

SRC_GDB_HOOKS=$(srcdir)/Tools/gdb/libpython.py
$(BUILDPYTHON)-gdb.py: $(SRC_GDB_HOOKS)
	$(INSTALL_DATA) $(SRC_GDB_HOOKS) $(BUILDPYTHON)-gdb.py

620 621 622
# This rule is here for OPENSTEP/Rhapsody/MacOSX. It builds a temporary
# minimal framework (not including the Lib directory and such) in the current
# directory.
Christian Heimes's avatar
Christian Heimes committed
623
RESSRCDIR=Mac/Resources/framework
624 625
$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK): \
		$(LIBRARY) \
Christian Heimes's avatar
Christian Heimes committed
626
		$(RESSRCDIR)/Info.plist
627
	$(INSTALL) -d -m $(DIRMODE) $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)
628
	$(CC) -o $(LDLIBRARY) $(PY_LDFLAGS) -dynamiclib \
629 630 631 632
		-all_load $(LIBRARY) -Wl,-single_module \
		-install_name $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK) \
		-compatibility_version $(VERSION) \
		-current_version $(VERSION) \
633
		-framework CoreFoundation $(LIBS);
634 635 636 637
	$(INSTALL) -d -m $(DIRMODE)  \
		$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/English.lproj
	$(INSTALL_DATA) $(RESSRCDIR)/Info.plist \
		$(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/Resources/Info.plist
638
	$(LN) -fsn $(VERSION) $(PYTHONFRAMEWORKDIR)/Versions/Current
639
	$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)
640
	$(LN) -fsn Versions/Current/Resources $(PYTHONFRAMEWORKDIR)/Resources
641

642 643
# This rule builds the Cygwin Python DLL and import library if configured
# for a shared core library; otherwise, this rule is a noop.
644
$(DLLLIBRARY) libpython$(LDVERSION).dll.a: $(LIBRARY_OBJS)
645
	if test -n "$(DLLLIBRARY)"; then \
646
		$(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
Benjamin Peterson's avatar
Benjamin Peterson committed
647
			$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
648 649
	else true; \
	fi
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673


oldsharedmods: $(SHAREDMODS)


Makefile Modules/config.c: Makefile.pre \
				$(srcdir)/Modules/config.c.in \
				$(MAKESETUP) \
				Modules/Setup \
				Modules/Setup.local
	$(SHELL) $(MAKESETUP) -c $(srcdir)/Modules/config.c.in \
				-s Modules \
				Modules/Setup.local \
				Modules/Setup
	@mv config.c Modules
	@echo "The Makefile was updated, you may need to re-run make."


Modules/Setup: $(srcdir)/Modules/Setup.dist
	@if test -f Modules/Setup; then \
		echo "-----------------------------------------------"; \
		echo "Modules/Setup.dist is newer than Modules/Setup;"; \
		echo "check to make sure you have all the updates you"; \
		echo "need in your Modules/Setup file."; \
674
		echo "Usually, copying Modules/Setup.dist to Modules/Setup will work."; \
675
		echo "-----------------------------------------------"; \
676
	fi
677

678 679
Programs/_testembed: Programs/_testembed.o $(LIBRARY) $(LDLIBRARY) $(PY3LIBRARY)
	$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ Programs/_testembed.o $(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
680

681 682
############################################################################
# Importlib
683

684
Programs/_freeze_importlib.o: Programs/_freeze_importlib.c Makefile
685

686 687
Programs/_freeze_importlib: Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN)
	$(LINKCC) $(PY_LDFLAGS) -o $@ Programs/_freeze_importlib.o $(LIBRARY_OBJS_OMIT_FROZEN) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
688

689 690 691 692
.PHONY: regen-importlib
regen-importlib: Programs/_freeze_importlib
	# Regenerate Python/importlib_external.h
	# from Lib/importlib/_bootstrap_external.py using _freeze_importlib
693
	./Programs/_freeze_importlib \
694
	    $(srcdir)/Lib/importlib/_bootstrap_external.py \
695 696
	    $(srcdir)/Python/importlib_external.h.new
	$(UPDATE_FILE) $(srcdir)/Python/importlib_external.h $(srcdir)/Python/importlib_external.h.new
697 698
	# Regenerate Python/importlib.h from Lib/importlib/_bootstrap.py
	# using _freeze_importlib
699
	./Programs/_freeze_importlib \
700
	    $(srcdir)/Lib/importlib/_bootstrap.py \
701 702
	    $(srcdir)/Python/importlib.h.new
	$(UPDATE_FILE) $(srcdir)/Python/importlib.h $(srcdir)/Python/importlib.h.new
703 704 705 706


############################################################################
# Regenerate all generated files
707

708
regen-all: regen-opcode regen-opcode-targets regen-typeslots regen-grammar regen-ast regen-importlib
709

710 711 712
############################################################################
# Special rules for object files

713 714 715 716 717 718
Modules/getbuildinfo.o: $(PARSER_OBJS) \
		$(OBJECT_OBJS) \
		$(PYTHON_OBJS) \
		$(MODULE_OBJS) \
		$(MODOBJS) \
		$(srcdir)/Modules/getbuildinfo.c
719
	$(CC) -c $(PY_CORE_CFLAGS) \
720 721 722
	      -DGITVERSION="\"`LC_ALL=C $(GITVERSION)`\"" \
	      -DGITTAG="\"`LC_ALL=C $(GITTAG)`\"" \
	      -DGITBRANCH="\"`LC_ALL=C $(GITBRANCH)`\"" \
723
	      -o $@ $(srcdir)/Modules/getbuildinfo.c
724

725
Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
726
	$(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
727 728 729 730
		-DPREFIX='"$(prefix)"' \
		-DEXEC_PREFIX='"$(exec_prefix)"' \
		-DVERSION='"$(VERSION)"' \
		-DVPATH='"$(VPATH)"' \
731
		-o $@ $(srcdir)/Modules/getpath.c
732

733 734
Programs/python.o: $(srcdir)/Programs/python.c
	$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/python.c
735

736 737
Programs/_testembed.o: $(srcdir)/Programs/_testembed.c
	$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Programs/_testembed.c
738

739 740
Modules/_sre.o: $(srcdir)/Modules/_sre.c $(srcdir)/Modules/sre.h $(srcdir)/Modules/sre_constants.h $(srcdir)/Modules/sre_lib.h

741 742 743 744 745 746 747 748
Modules/posixmodule.o: $(srcdir)/Modules/posixmodule.c $(srcdir)/Modules/posixmodule.h

Modules/grpmodule.o: $(srcdir)/Modules/grpmodule.c $(srcdir)/Modules/posixmodule.h

Modules/pwdmodule.o: $(srcdir)/Modules/pwdmodule.c $(srcdir)/Modules/posixmodule.h

Modules/signalmodule.o: $(srcdir)/Modules/signalmodule.c $(srcdir)/Modules/posixmodule.h

Barry Warsaw's avatar
Barry Warsaw committed
749 750 751 752 753
Python/dynload_shlib.o: $(srcdir)/Python/dynload_shlib.c Makefile
	$(CC) -c $(PY_CORE_CFLAGS) \
		-DSOABI='"$(SOABI)"' \
		-o $@ $(srcdir)/Python/dynload_shlib.c

754 755 756 757 758
Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile
	$(CC) -c $(PY_CORE_CFLAGS) \
		-DSHLIB_EXT='"$(EXT_SUFFIX)"' \
		-o $@ $(srcdir)/Python/dynload_hpux.c

759 760 761
Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile
	$(CC) -c $(PY_CORE_CFLAGS) \
		-DABIFLAGS='"$(ABIFLAGS)"' \
762
		$(MULTIARCH_CPPFLAGS) \
763 764
		-o $@ $(srcdir)/Python/sysmodule.c

765
$(IO_OBJS): $(IO_H)
766

767
$(PGEN): $(PGENOBJS)
768
		$(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
769

770 771 772 773 774 775
.PHONY: regen-grammar
regen-grammar: $(PGEN)
	# Regenerate Include/graminit.h and Python/graminit.c
	# from Grammar/Grammar using pgen
	@$(MKDIR_P) Include
	$(PGEN) $(srcdir)/Grammar/Grammar \
776 777 778 779
		$(srcdir)/Include/graminit.h.new \
		$(srcdir)/Python/graminit.c.new
	$(UPDATE_FILE) $(srcdir)/Include/graminit.h $(srcdir)/Include/graminit.h.new
	$(UPDATE_FILE) $(srcdir)/Python/graminit.c $(srcdir)/Python/graminit.c.new
780

781 782 783 784 785
Parser/grammar.o:	$(srcdir)/Parser/grammar.c \
				$(srcdir)/Include/token.h \
				$(srcdir)/Include/grammar.h
Parser/metagrammar.o:	$(srcdir)/Parser/metagrammar.c

786
Parser/tokenizer_pgen.o:	$(srcdir)/Parser/tokenizer.c
787
Parser/parsetok_pgen.o:	$(srcdir)/Parser/parsetok.c
788
Parser/printgrammar.o: $(srcdir)/Parser/printgrammar.c
789

790 791
Parser/pgenmain.o:	$(srcdir)/Include/parsetok.h

792 793 794 795 796
.PHONY=regen-ast
regen-ast:
	# Regenerate Include/Python-ast.h using Parser/asdl_c.py -h
	$(MKDIR_P) $(srcdir)/Include
	$(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
797
		-h $(srcdir)/Include/Python-ast.h.new \
798
		$(srcdir)/Parser/Python.asdl
799
	$(UPDATE_FILE) $(srcdir)/Include/Python-ast.h $(srcdir)/Include/Python-ast.h.new
800 801 802
	# Regenerate Python/Python-ast.c using Parser/asdl_c.py -c
	$(MKDIR_P) $(srcdir)/Python
	$(PYTHON_FOR_REGEN) $(srcdir)/Parser/asdl_c.py \
803
		-c $(srcdir)/Python/Python-ast.c.new \
804
		$(srcdir)/Parser/Python.asdl
805
	$(UPDATE_FILE) $(srcdir)/Python/Python-ast.c $(srcdir)/Python/Python-ast.c.new
806 807 808 809 810 811 812

.PHONY: regen-opcode
regen-opcode:
	# Regenerate Include/opcode.h from Lib/opcode.py
	# using Tools/scripts/generate_opcode_h.py
	$(PYTHON_FOR_REGEN) $(srcdir)/Tools/scripts/generate_opcode_h.py \
		$(srcdir)/Lib/opcode.py \
813 814
		$(srcdir)/Include/opcode.h.new
	$(UPDATE_FILE) $(srcdir)/Include/opcode.h $(srcdir)/Include/opcode.h.new
815 816

Python/compile.o Python/symtable.o Python/ast.o: $(srcdir)/Include/graminit.h $(srcdir)/Include/Python-ast.h
817

818
Python/getplatform.o: $(srcdir)/Python/getplatform.c
819
		$(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
820 821

Python/importdl.o: $(srcdir)/Python/importdl.c
822
		$(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
823 824 825 826

Objects/unicodectype.o:	$(srcdir)/Objects/unicodectype.c \
				$(srcdir)/Objects/unicodetype_db.h

827 828 829 830 831
BYTESTR_DEPS = \
		$(srcdir)/Objects/stringlib/count.h \
		$(srcdir)/Objects/stringlib/ctype.h \
		$(srcdir)/Objects/stringlib/fastsearch.h \
		$(srcdir)/Objects/stringlib/find.h \
832
		$(srcdir)/Objects/stringlib/join.h \
833
		$(srcdir)/Objects/stringlib/partition.h \
834
		$(srcdir)/Objects/stringlib/split.h \
835
		$(srcdir)/Objects/stringlib/stringdefs.h \
836
		$(srcdir)/Objects/stringlib/transmogrify.h
837

838
UNICODE_DEPS = \
839
		$(srcdir)/Objects/stringlib/asciilib.h \
840
		$(srcdir)/Objects/stringlib/codecs.h \
841 842 843 844 845 846
		$(srcdir)/Objects/stringlib/count.h \
		$(srcdir)/Objects/stringlib/fastsearch.h \
		$(srcdir)/Objects/stringlib/find.h \
		$(srcdir)/Objects/stringlib/find_max_char.h \
		$(srcdir)/Objects/stringlib/localeutil.h \
		$(srcdir)/Objects/stringlib/partition.h \
847
		$(srcdir)/Objects/stringlib/replace.h \
848
		$(srcdir)/Objects/stringlib/split.h \
849 850 851
		$(srcdir)/Objects/stringlib/ucs1lib.h \
		$(srcdir)/Objects/stringlib/ucs2lib.h \
		$(srcdir)/Objects/stringlib/ucs4lib.h \
852
		$(srcdir)/Objects/stringlib/undef.h \
853 854
		$(srcdir)/Objects/stringlib/unicode_format.h \
		$(srcdir)/Objects/stringlib/unicodedefs.h
855

856
Objects/bytes_methods.o: $(srcdir)/Objects/bytes_methods.c $(BYTESTR_DEPS)
857
Objects/bytesobject.o: $(srcdir)/Objects/bytesobject.c $(BYTESTR_DEPS)
Victor Stinner's avatar
Victor Stinner committed
858
Objects/bytearrayobject.o: $(srcdir)/Objects/bytearrayobject.c $(BYTESTR_DEPS)
859

860
Objects/unicodeobject.o: $(srcdir)/Objects/unicodeobject.c $(UNICODE_DEPS)
861

862 863
Objects/odictobject.o: $(srcdir)/Objects/dict-common.h
Objects/dictobject.o: $(srcdir)/Objects/stringlib/eq.h $(srcdir)/Objects/dict-common.h
864 865
Objects/setobject.o: $(srcdir)/Objects/stringlib/eq.h

866 867 868 869 870
.PHONY: regen-opcode-targets
regen-opcode-targets:
	# Regenerate Python/opcode_targets.h from Lib/opcode.py
	# using Python/makeopcodetargets.py
	$(PYTHON_FOR_REGEN) $(srcdir)/Python/makeopcodetargets.py \
871 872
		$(srcdir)/Python/opcode_targets.h.new
	$(UPDATE_FILE) $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/opcode_targets.h.new
873

874
Python/ceval.o: $(srcdir)/Python/opcode_targets.h $(srcdir)/Python/ceval_gil.h
875

876
Python/frozen.o: $(srcdir)/Python/importlib.h $(srcdir)/Python/importlib_external.h
877

878 879 880 881
# Generate DTrace probe macros, then rename them (PYTHON_ -> PyDTrace_) to
# follow our naming conventions. dtrace(1) uses the output filename to generate
# an include guard, so we can't use a pipeline to transform its output.
Include/pydtrace_probes.h: $(srcdir)/Include/pydtrace.d
882
	$(MKDIR_P) Include
883 884 885 886 887 888 889 890
	$(DTRACE) $(DFLAGS) -o $@ -h -s $<
	: sed in-place edit with POSIX-only tools
	sed 's/PYTHON_/PyDTrace_/' $@ > $@.tmp
	mv $@.tmp $@

Python/pydtrace.o: $(srcdir)/Include/pydtrace.d $(DTRACE_DEPS)
	$(DTRACE) $(DFLAGS) -o $@ -G -s $< $(DTRACE_DEPS)

891
Objects/typeobject.o: Objects/typeslots.inc
892 893 894 895 896 897 898

.PHONY: regen-typeslots
regen-typeslots:
	# Regenerate Objects/typeslots.inc from Include/typeslotsh
	# using Objects/typeslots.py
	$(PYTHON_FOR_REGEN) $(srcdir)/Objects/typeslots.py \
		< $(srcdir)/Include/typeslots.h \
899 900
		$(srcdir)/Objects/typeslots.inc.new
	$(UPDATE_FILE) $(srcdir)/Objects/typeslots.inc $(srcdir)/Objects/typeslots.inc.new
901

902 903 904
############################################################################
# Header files

905
PYTHON_HEADERS= \
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948
		$(srcdir)/Include/Python.h \
		$(srcdir)/Include/abstract.h \
		$(srcdir)/Include/accu.h \
		$(srcdir)/Include/asdl.h \
		$(srcdir)/Include/ast.h \
		$(srcdir)/Include/bltinmodule.h \
		$(srcdir)/Include/bitset.h \
		$(srcdir)/Include/boolobject.h \
		$(srcdir)/Include/bytes_methods.h \
		$(srcdir)/Include/bytearrayobject.h \
		$(srcdir)/Include/bytesobject.h \
		$(srcdir)/Include/cellobject.h \
		$(srcdir)/Include/ceval.h \
		$(srcdir)/Include/classobject.h \
		$(srcdir)/Include/code.h \
		$(srcdir)/Include/codecs.h \
		$(srcdir)/Include/compile.h \
		$(srcdir)/Include/complexobject.h \
		$(srcdir)/Include/descrobject.h \
		$(srcdir)/Include/dictobject.h \
		$(srcdir)/Include/dtoa.h \
		$(srcdir)/Include/dynamic_annotations.h \
		$(srcdir)/Include/enumobject.h \
		$(srcdir)/Include/errcode.h \
		$(srcdir)/Include/eval.h \
		$(srcdir)/Include/fileobject.h \
		$(srcdir)/Include/fileutils.h \
		$(srcdir)/Include/floatobject.h \
		$(srcdir)/Include/frameobject.h \
		$(srcdir)/Include/funcobject.h \
		$(srcdir)/Include/genobject.h \
		$(srcdir)/Include/import.h \
		$(srcdir)/Include/intrcheck.h \
		$(srcdir)/Include/iterobject.h \
		$(srcdir)/Include/listobject.h \
		$(srcdir)/Include/longintrepr.h \
		$(srcdir)/Include/longobject.h \
		$(srcdir)/Include/marshal.h \
		$(srcdir)/Include/memoryobject.h \
		$(srcdir)/Include/metagrammar.h \
		$(srcdir)/Include/methodobject.h \
		$(srcdir)/Include/modsupport.h \
		$(srcdir)/Include/moduleobject.h \
949
		$(srcdir)/Include/namespaceobject.h \
950 951 952
		$(srcdir)/Include/node.h \
		$(srcdir)/Include/object.h \
		$(srcdir)/Include/objimpl.h \
953
		$(srcdir)/Include/opcode.h \
954
		$(srcdir)/Include/osdefs.h \
955
		$(srcdir)/Include/osmodule.h \
956 957 958 959 960 961 962 963
		$(srcdir)/Include/patchlevel.h \
		$(srcdir)/Include/pgen.h \
		$(srcdir)/Include/pgenheaders.h \
		$(srcdir)/Include/pyarena.h \
		$(srcdir)/Include/pyatomic.h \
		$(srcdir)/Include/pycapsule.h \
		$(srcdir)/Include/pyctype.h \
		$(srcdir)/Include/pydebug.h \
964
		$(srcdir)/Include/pydtrace.h \
965 966
		$(srcdir)/Include/pyerrors.h \
		$(srcdir)/Include/pyfpe.h \
967
		$(srcdir)/Include/pyhash.h \
968
		$(srcdir)/Include/pylifecycle.h \
969 970 971 972 973 974 975 976
		$(srcdir)/Include/pymath.h \
		$(srcdir)/Include/pygetopt.h \
		$(srcdir)/Include/pymacro.h \
		$(srcdir)/Include/pymem.h \
		$(srcdir)/Include/pyport.h \
		$(srcdir)/Include/pystate.h \
		$(srcdir)/Include/pystrcmp.h \
		$(srcdir)/Include/pystrtod.h \
977
		$(srcdir)/Include/pystrhex.h \
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993
		$(srcdir)/Include/pythonrun.h \
		$(srcdir)/Include/pythread.h \
		$(srcdir)/Include/pytime.h \
		$(srcdir)/Include/rangeobject.h \
		$(srcdir)/Include/setobject.h \
		$(srcdir)/Include/sliceobject.h \
		$(srcdir)/Include/structmember.h \
		$(srcdir)/Include/structseq.h \
		$(srcdir)/Include/symtable.h \
		$(srcdir)/Include/sysmodule.h \
		$(srcdir)/Include/traceback.h \
		$(srcdir)/Include/tupleobject.h \
		$(srcdir)/Include/ucnhash.h \
		$(srcdir)/Include/unicodeobject.h \
		$(srcdir)/Include/warnings.h \
		$(srcdir)/Include/weakrefobject.h \
994
		pyconfig.h \
995
		$(PARSER_HEADERS) \
996
		$(srcdir)/Include/Python-ast.h \
997 998 999 1000 1001 1002
		$(srcdir)/Include/internal/ceval.h \
		$(srcdir)/Include/internal/gil.h \
		$(srcdir)/Include/internal/mem.h \
		$(srcdir)/Include/internal/pymalloc.h \
		$(srcdir)/Include/internal/pystate.h \
		$(srcdir)/Include/internal/warnings.h \
1003
		$(DTRACE_HEADERS)
1004

1005
$(LIBRARY_OBJS) $(MODOBJS) Programs/python.o: $(PYTHON_HEADERS)
1006

1007 1008 1009

######################################################################

1010
TESTOPTS=	$(EXTRATESTOPTS)
1011 1012
TESTPYTHON=	$(RUNSHARED) ./$(BUILDPYTHON) $(TESTPYTHONOPTS)
TESTRUNNER=	$(TESTPYTHON) $(srcdir)/Tools/scripts/run_tests.py
1013
TESTTIMEOUT=	1200
1014

1015 1016
.PHONY: test testall testuniversal buildbottest pythoninfo

1017 1018
# Run a basic set of regression tests.
# This excludes some tests that are particularly resource-intensive.
1019
test:		@DEF_MAKE_RULE@ platform
1020
		$(TESTRUNNER) $(TESTOPTS)
1021

1022 1023 1024 1025 1026 1027 1028
# Run the full test suite twice - once without .pyc files, and once with.
# In the past, we've had problems where bugs in the marshalling or
# elsewhere caused bytecode read from .pyc files to behave differently
# than bytecode generated directly from a .py source file.  Sometimes
# the bytecode read from a .pyc file had the bug, sometimes the directly
# generated bytecode.  This is sometimes a very shy bug needing a lot of
# sample data.
1029
testall:	@DEF_MAKE_RULE@ platform
Christian Heimes's avatar
Christian Heimes committed
1030
		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
1031
		$(TESTPYTHON) -E $(srcdir)/Lib/compileall.py
1032
		-find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f
1033 1034
		-$(TESTRUNNER) -u all $(TESTOPTS)
		$(TESTRUNNER) -u all $(TESTOPTS)
1035

1036 1037
# Run the test suite for both architectures in a Universal build on OSX.
# Must be run on an Intel box.
1038
testuniversal:	@DEF_MAKE_RULE@ platform
1039
		@if [ `arch` != 'i386' ]; then \
1040 1041 1042
			echo "This can only be used on OSX/i386" ;\
			exit 1 ;\
		fi
1043 1044 1045
		$(TESTRUNNER) -u all $(TESTOPTS)
		$(RUNSHARED) /usr/libexec/oah/translate \
			./$(BUILDPYTHON) -E -m test -j 0 -u all $(TESTOPTS)
1046

1047
# Like testall, but with only one pass and without multiple processes.
1048
# Run an optional script to include information about the build environment.
1049
buildbottest:	build_all platform
1050 1051 1052
		-@if which pybuildbot.identify >/dev/null 2>&1; then \
			pybuildbot.identify "CC='$(CC)'" "CXX='$(CXX)'"; \
		fi
1053
		$(TESTRUNNER) -j 1 -u all -W --slowest --fail-env-changed --timeout=$(TESTTIMEOUT) $(TESTOPTS)
1054

1055 1056 1057
pythoninfo: build_all
		$(RUNSHARED) ./$(BUILDPYTHON) -m test.pythoninfo

1058 1059
QUICKTESTOPTS=	$(TESTOPTS) -x test_subprocess test_io test_lib2to3 \
		test_multibytecodec test_urllib2_localnet test_itertools \
1060 1061 1062
		test_multiprocessing_fork test_multiprocessing_spawn \
		test_multiprocessing_forkserver \
		test_mailbox test_socket test_poll \
1063
		test_select test_zipfile test_concurrent_futures
1064
quicktest:	@DEF_MAKE_RULE@ platform
1065
		$(TESTRUNNER) $(QUICKTESTOPTS)
1066

1067 1068 1069 1070 1071 1072 1073
# SSL tests
.PHONY: multisslcompile multissltest
multisslcompile: build_all
	$(RUNSHARED) ./$(BUILDPYTHON) Tools/ssl/multissltests.py --compile-only

multissltest: build_all
	$(RUNSHARED) ./$(BUILDPYTHON) Tools/ssl/multissltests.py
1074

1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
install: @FRAMEWORKINSTALLFIRST@ commoninstall bininstall maninstall @FRAMEWORKINSTALLLAST@
	if test "x$(ENSUREPIP)" != "xno"  ; then \
		case $(ENSUREPIP) in \
			upgrade) ensurepip="--upgrade" ;; \
			install|*) ensurepip="" ;; \
		esac; \
		$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
			$$ensurepip --root=$(DESTDIR)/ ; \
	fi

altinstall: commoninstall
	if test "x$(ENSUREPIP)" != "xno"  ; then \
		case $(ENSUREPIP) in \
			upgrade) ensurepip="--altinstall --upgrade" ;; \
			install|*) ensurepip="--altinstall" ;; \
		esac; \
		$(RUNSHARED) $(PYTHON_FOR_BUILD) -m ensurepip \
			$$ensurepip --root=$(DESTDIR)/ ; \
	fi
1094

1095 1096 1097 1098
commoninstall:  @FRAMEWORKALTINSTALLFIRST@ \
		altbininstall libinstall inclinstall libainstall \
		sharedinstall oldsharedinstall altmaninstall \
		@FRAMEWORKALTINSTALLLAST@
1099 1100 1101 1102 1103 1104

# Install shared libraries enabled by Setup
DESTDIRS=	$(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED)

oldsharedinstall: $(DESTSHARED) $(SHAREDMODS)
		@for i in X $(SHAREDMODS); do \
1105 1106
		  if test $$i != X; then \
		    echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
1107
		    $(INSTALL_SHARED) $$i $(DESTDIR)$(DESTSHARED)/`basename $$i`; \
1108
		  fi; \
1109 1110
		done

1111
$(DESTSHARED):
1112 1113
		@for i in $(DESTDIRS); \
		do \
1114
			if test ! -d $(DESTDIR)$$i; then \
1115
				echo "Creating directory $$i"; \
1116
				$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1117 1118 1119 1120 1121 1122
			else    true; \
			fi; \
		done

# Install the interpreter with $(VERSION) affixed
# This goes into $(exec_prefix)
1123
altbininstall: $(BUILDPYTHON) @FRAMEWORKPYTHONW@
1124
	@for i in $(BINDIR) $(LIBDIR); \
1125
	do \
1126
		if test ! -d $(DESTDIR)$$i; then \
1127
			echo "Creating directory $$i"; \
1128
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1129 1130 1131
		else	true; \
		fi; \
	done
1132 1133 1134 1135 1136
	if test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
		$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
	else \
		$(INSTALL_PROGRAM) $(STRIPFLAG) Mac/pythonw $(DESTDIR)$(BINDIR)/python$(LDVERSION)$(EXE); \
	fi
1137
	-if test "$(VERSION)" != "$(LDVERSION)"; then \
1138
		if test -f $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE) -o -h $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
1139 1140 1141
		then rm -f $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
		fi; \
		(cd $(DESTDIR)$(BINDIR); $(LN) python$(LDVERSION)$(EXE) python$(VERSION)$(EXE)); \
1142
	fi
1143
	if test -f $(LDLIBRARY) && test "$(PYTHONFRAMEWORKDIR)" = "no-framework" ; then \
1144 1145
		if test -n "$(DLLLIBRARY)" ; then \
			$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
1146
		else \
1147 1148 1149
			$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(LIBDIR)/$(INSTSONAME); \
			if test $(LDLIBRARY) != $(INSTSONAME); then \
				(cd $(DESTDIR)$(LIBDIR); $(LN) -sf $(INSTSONAME) $(LDLIBRARY)) \
1150
			fi \
1151
		fi; \
1152 1153 1154
		if test -n "$(PY3LIBRARY)"; then \
			$(INSTALL_SHARED) $(PY3LIBRARY) $(DESTDIR)$(LIBDIR)/$(PY3LIBRARY); \
		fi; \
1155 1156
	else	true; \
	fi
1157 1158 1159 1160 1161 1162
	if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \
		rm -f $(DESTDIR)$(BINDIR)python$(VERSION)-32$(EXE); \
		lipo $(LIPO_32BIT_FLAGS) \
			-output $(DESTDIR)$(BINDIR)/python$(VERSION)-32$(EXE) \
			$(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE); \
	fi
1163 1164

bininstall: altbininstall
1165
	if test ! -d $(DESTDIR)$(LIBPC); then \
1166 1167 1168
		echo "Creating directory $(LIBPC)"; \
		$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBPC); \
	fi
1169 1170
	-if test -f $(DESTDIR)$(BINDIR)/python3$(EXE) -o -h $(DESTDIR)$(BINDIR)/python3$(EXE); \
	then rm -f $(DESTDIR)$(BINDIR)/python3$(EXE); \
1171 1172
	else true; \
	fi
1173
	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) python3$(EXE))
1174 1175 1176 1177 1178 1179
	-if test "$(VERSION)" != "$(LDVERSION)"; then \
		rm -f $(DESTDIR)$(BINDIR)/python$(VERSION)-config; \
		(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(LDVERSION)-config python$(VERSION)-config); \
		rm -f $(DESTDIR)$(LIBPC)/python-$(LDVERSION).pc; \
		(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION).pc python-$(LDVERSION).pc); \
	fi
1180 1181
	-rm -f $(DESTDIR)$(BINDIR)/python3-config
	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-config python3-config)
1182 1183
	-rm -f $(DESTDIR)$(LIBPC)/python3.pc
	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION).pc python3.pc)
1184 1185 1186 1187 1188 1189
	-rm -f $(DESTDIR)$(BINDIR)/idle3
	(cd $(DESTDIR)$(BINDIR); $(LN) -s idle$(VERSION) idle3)
	-rm -f $(DESTDIR)$(BINDIR)/pydoc3
	(cd $(DESTDIR)$(BINDIR); $(LN) -s pydoc$(VERSION) pydoc3)
	-rm -f $(DESTDIR)$(BINDIR)/2to3
	(cd $(DESTDIR)$(BINDIR); $(LN) -s 2to3-$(VERSION) 2to3)
1190 1191
	-rm -f $(DESTDIR)$(BINDIR)/pyvenv
	(cd $(DESTDIR)$(BINDIR); $(LN) -s pyvenv-$(VERSION) pyvenv)
1192 1193 1194 1195
	if test "x$(LIPO_32BIT_FLAGS)" != "x" ; then \
		rm -f $(DESTDIR)$(BINDIR)/python3-32$(EXE); \
		(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-32$(EXE) python3-32$(EXE)) \
	fi
1196

1197 1198
# Install the versioned manual page
altmaninstall:
1199 1200
	@for i in $(MANDIR) $(MANDIR)/man1; \
	do \
1201
		if test ! -d $(DESTDIR)$$i; then \
1202
			echo "Creating directory $$i"; \
1203
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1204 1205 1206 1207
		else	true; \
		fi; \
	done
	$(INSTALL_DATA) $(srcdir)/Misc/python.man \
Benjamin Peterson's avatar
Benjamin Peterson committed
1208
		$(DESTDIR)$(MANDIR)/man1/python$(VERSION).1
1209

1210 1211 1212 1213 1214
# Install the unversioned manual page
maninstall:	altmaninstall
	-rm -f $(DESTDIR)$(MANDIR)/man1/python3.1
	(cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python$(VERSION).1 python3.1)

1215
# Install the library
1216
XMLLIBSUBDIRS=  xml xml/dom xml/etree xml/parsers xml/sax
1217
LIBSUBDIRS=	tkinter tkinter/test tkinter/test/test_tkinter \
1218
		tkinter/test/test_ttk site-packages test \
1219
		test/audiodata \
1220
		test/capath test/data \
1221
		test/cjkencodings test/decimaltestdata test/xmltestdata \
1222
		test/dtracedata \
1223
		test/eintrdata \
1224
		test/imghdrdata \
1225
		test/libregrtest \
1226
		test/subprocessdata test/sndhdrdata test/support \
1227
		test/tracedmodules test/encoded_modules \
1228 1229 1230 1231
		test/test_import \
		test/test_import/data \
		test/test_import/data/circular_imports \
		test/test_import/data/circular_imports/subpkg \
1232 1233
		test/test_import/data/package \
		test/test_import/data/package2 \
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
		test/test_importlib/namespace_pkgs \
		test/test_importlib/namespace_pkgs/both_portions \
		test/test_importlib/namespace_pkgs/both_portions/foo \
		test/test_importlib/namespace_pkgs/not_a_namespace_pkg \
		test/test_importlib/namespace_pkgs/not_a_namespace_pkg/foo \
		test/test_importlib/namespace_pkgs/portion1 \
		test/test_importlib/namespace_pkgs/portion1/foo \
		test/test_importlib/namespace_pkgs/portion2 \
		test/test_importlib/namespace_pkgs/portion2/foo \
		test/test_importlib/namespace_pkgs/project1 \
		test/test_importlib/namespace_pkgs/project1/parent \
		test/test_importlib/namespace_pkgs/project1/parent/child \
		test/test_importlib/namespace_pkgs/project2 \
		test/test_importlib/namespace_pkgs/project2/parent \
		test/test_importlib/namespace_pkgs/project2/parent/child \
		test/test_importlib/namespace_pkgs/project3 \
		test/test_importlib/namespace_pkgs/project3/parent \
		test/test_importlib/namespace_pkgs/project3/parent/child \
                test/test_importlib/namespace_pkgs/module_and_namespace_package \
                test/test_importlib/namespace_pkgs/module_and_namespace_package/a_test \
1254 1255
		asyncio \
		test/test_asyncio \
1256
		collections concurrent concurrent/futures encodings \
1257
		email email/mime test/test_email test/test_email/data \
1258
		ensurepip ensurepip/_bundled \
1259
		html json test/test_json http dbm xmlrpc \
1260
		sqlite3 sqlite3/test \
1261
		logging csv wsgiref urllib \
1262
		lib2to3 lib2to3/fixes lib2to3/pgen2 lib2to3/tests \
1263 1264
		lib2to3/tests/data lib2to3/tests/data/fixers \
		lib2to3/tests/data/fixers/myfixes \
1265 1266
		ctypes ctypes/test ctypes/macholib \
		idlelib idlelib/Icons idlelib/idle_test \
1267
		distutils distutils/command distutils/tests $(XMLLIBSUBDIRS) \
1268 1269 1270
		importlib test/test_importlib test/test_importlib/builtin \
		test/test_importlib/extension test/test_importlib/frozen \
		test/test_importlib/import_ test/test_importlib/source \
1271
		test/test_tools test/test_warnings test/test_warnings/data \
1272
		turtledemo \
1273
		multiprocessing multiprocessing/dummy \
1274
		unittest unittest/test unittest/test/testmock \
1275
		venv venv/scripts venv/scripts/common venv/scripts/posix \
1276 1277
		curses pydoc_data
libinstall:	build_all $(srcdir)/Modules/xxmodule.c
1278 1279
	@for i in $(SCRIPTDIR) $(LIBDEST); \
	do \
1280
		if test ! -d $(DESTDIR)$$i; then \
1281
			echo "Creating directory $$i"; \
1282
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1283 1284 1285 1286 1287 1288 1289 1290
		else	true; \
		fi; \
	done
	@for d in $(LIBSUBDIRS); \
	do \
		a=$(srcdir)/Lib/$$d; \
		if test ! -d $$a; then continue; else true; fi; \
		b=$(LIBDEST)/$$d; \
1291
		if test ! -d $(DESTDIR)$$b; then \
1292
			echo "Creating directory $$b"; \
1293
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$b; \
1294 1295 1296
		else	true; \
		fi; \
	done
1297
	@for i in $(srcdir)/Lib/*.py; \
1298 1299
	do \
		if test -x $$i; then \
1300
			$(INSTALL_SCRIPT) $$i $(DESTDIR)$(LIBDEST); \
1301
			echo $(INSTALL_SCRIPT) $$i $(LIBDEST); \
1302
		else \
1303
			$(INSTALL_DATA) $$i $(DESTDIR)$(LIBDEST); \
1304 1305 1306 1307 1308 1309 1310
			echo $(INSTALL_DATA) $$i $(LIBDEST); \
		fi; \
	done
	@for d in $(LIBSUBDIRS); \
	do \
		a=$(srcdir)/Lib/$$d; \
		if test ! -d $$a; then continue; else true; fi; \
1311
		if test `ls $$a | wc -l` -lt 1; then continue; fi; \
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322
		b=$(LIBDEST)/$$d; \
		for i in $$a/*; \
		do \
			case $$i in \
			*CVS) ;; \
			*.py[co]) ;; \
			*.orig) ;; \
			*~) ;; \
			*) \
				if test -d $$i; then continue; fi; \
				if test -x $$i; then \
1323
				    echo $(INSTALL_SCRIPT) $$i $$b; \
1324
				    $(INSTALL_SCRIPT) $$i $(DESTDIR)$$b; \
1325 1326
				else \
				    echo $(INSTALL_DATA) $$i $$b; \
1327
				    $(INSTALL_DATA) $$i $(DESTDIR)$$b; \
1328 1329 1330 1331
				fi;; \
			esac; \
		done; \
	done
1332 1333
	$(INSTALL_DATA) `cat pybuilddir.txt`/_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH).py \
		$(DESTDIR)$(LIBDEST); \
1334
	$(INSTALL_DATA) $(srcdir)/LICENSE $(DESTDIR)$(LIBDEST)/LICENSE.txt
1335 1336 1337 1338
	if test -d $(DESTDIR)$(LIBDEST)/distutils/tests; then \
		$(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
			$(DESTDIR)$(LIBDEST)/distutils/tests ; \
	fi
1339
	-PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
1340
		$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
1341
		-d $(LIBDEST) -f \
1342
		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
Benjamin Peterson's avatar
Benjamin Peterson committed
1343
		$(DESTDIR)$(LIBDEST)
1344
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
1345
		$(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
1346
		-d $(LIBDEST) -f \
1347
		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
Benjamin Peterson's avatar
Benjamin Peterson committed
1348
		$(DESTDIR)$(LIBDEST)
1349 1350 1351 1352 1353 1354
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
		$(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
		-d $(LIBDEST) -f \
		-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
		$(DESTDIR)$(LIBDEST)
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
1355
		$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
1356
		-d $(LIBDEST)/site-packages -f \
1357
		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
1358
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
1359
		$(PYTHON_FOR_BUILD) -Wi -O $(DESTDIR)$(LIBDEST)/compileall.py \
1360
		-d $(LIBDEST)/site-packages -f \
1361
		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
1362 1363 1364 1365
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
		$(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
		-d $(LIBDEST)/site-packages -f \
		-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
1366 1367 1368 1369
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
		$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
	-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
		$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt
1370

1371
python-config: $(srcdir)/Misc/python-config.in Misc/python-config.sh
1372 1373
	@ # Substitution happens here, as the completely-expanded BINDIR
	@ # is not available in configure
1374
	sed -e "s,@EXENAME@,$(BINDIR)/python$(LDVERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config.py
1375
	@ # Replace makefile compat. variable references with shell script compat. ones; $(VAR) -> ${VAR}
1376
	LC_ALL=C sed -e 's,\$$(\([A-Za-z0-9_]*\)),\$$\{\1\},g' < Misc/python-config.sh >python-config
1377 1378 1379 1380
	@ # On Darwin, always use the python version of the script, the shell
	@ # version doesn't use the compiler customizations that are provided
	@ # in python (_osx_support.py).
	@if test `uname -s` = Darwin; then \
1381 1382 1383
		cp python-config.py python-config; \
	fi

1384

1385 1386 1387 1388 1389
# Install the include files
INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
inclinstall:
	@for i in $(INCLDIRSTOMAKE); \
	do \
1390
		if test ! -d $(DESTDIR)$$i; then \
1391
			echo "Creating directory $$i"; \
1392
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1393 1394 1395 1396 1397 1398
		else	true; \
		fi; \
	done
	@for i in $(srcdir)/Include/*.h; \
	do \
		echo $(INSTALL_DATA) $$i $(INCLUDEPY); \
1399
		$(INSTALL_DATA) $$i $(DESTDIR)$(INCLUDEPY); \
1400
	done
1401
	$(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h
1402 1403 1404

# Install the library and miscellaneous stuff needed for extending/embedding
# This goes into $(exec_prefix)
1405
LIBPL=		@LIBPL@
1406 1407 1408 1409

# pkgconfig directory
LIBPC=		$(LIBDIR)/pkgconfig

1410
libainstall:	@DEF_MAKE_RULE@ python-config
1411
	@for i in $(LIBDIR) $(LIBPL) $(LIBPC); \
1412
	do \
1413
		if test ! -d $(DESTDIR)$$i; then \
1414
			echo "Creating directory $$i"; \
1415
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1416 1417 1418
		else	true; \
		fi; \
	done
1419
	@if test -d $(LIBRARY); then :; else \
1420
		if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1421
			if test "$(SHLIB_SUFFIX)" = .dll; then \
1422
				$(INSTALL_DATA) $(LDLIBRARY) $(DESTDIR)$(LIBPL) ; \
1423
			else \
1424 1425
				$(INSTALL_DATA) $(LIBRARY) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
				$(RANLIB) $(DESTDIR)$(LIBPL)/$(LIBRARY) ; \
1426
			fi; \
1427
		else \
1428
			echo Skip install of $(LIBRARY) - use make frameworkinstall; \
1429
		fi; \
1430
	fi
1431
	$(INSTALL_DATA) Modules/config.c $(DESTDIR)$(LIBPL)/config.c
1432
	$(INSTALL_DATA) Programs/python.o $(DESTDIR)$(LIBPL)/python.o
1433 1434 1435 1436
	$(INSTALL_DATA) $(srcdir)/Modules/config.c.in $(DESTDIR)$(LIBPL)/config.c.in
	$(INSTALL_DATA) Makefile $(DESTDIR)$(LIBPL)/Makefile
	$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup
	$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
1437
	$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
1438 1439
	$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
	$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
1440
	$(INSTALL_SCRIPT) python-config.py $(DESTDIR)$(LIBPL)/python-config.py
1441
	$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(LDVERSION)-config
1442
	@if [ -s Modules/python.exp -a \
1443 1444
		"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
		echo; echo "Installing support files for building shared extension modules on AIX:"; \
1445
		$(INSTALL_DATA) Modules/python.exp		\
1446
				$(DESTDIR)$(LIBPL)/python.exp;		\
1447
		echo; echo "$(LIBPL)/python.exp";		\
1448
		$(INSTALL_SCRIPT) $(srcdir)/Modules/makexp_aix	\
1449
				$(DESTDIR)$(LIBPL)/makexp_aix;		\
1450
		echo "$(LIBPL)/makexp_aix";			\
1451
		$(INSTALL_SCRIPT) Modules/ld_so_aix	\
1452
				$(DESTDIR)$(LIBPL)/ld_so_aix;		\
1453 1454 1455 1456 1457 1458 1459
		echo "$(LIBPL)/ld_so_aix";			\
		echo; echo "See Misc/AIX-NOTES for details.";	\
	else true; \
	fi

# Install the dynamically loadable modules
# This goes into $(exec_prefix)
1460
sharedinstall: sharedmods
1461
	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
1462
	   	--prefix=$(prefix) \
1463
		--install-scripts=$(BINDIR) \
1464
		--install-platlib=$(DESTSHARED) \
1465
		--root=$(DESTDIR)/
1466
	-rm $(DESTDIR)$(DESTSHARED)/_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH).py
1467
	-rm -r $(DESTDIR)$(DESTSHARED)/__pycache__
1468

1469 1470 1471
# Here are a couple of targets for MacOSX again, to install a full
# framework-based Python. frameworkinstall installs everything, the
# subtargets install specific parts. Much of the actual work is offloaded to
1472
# the Makefile in Mac
1473
#
1474
#
1475
# This target is here for backward compatibility, previous versions of Python
1476 1477
# hadn't integrated framework installation in the normal install process.
frameworkinstall: install
1478

1479 1480 1481 1482 1483 1484
# On install, we re-make the framework
# structure in the install location, /Library/Frameworks/ or the argument to
# --enable-framework. If --enable-framework has been specified then we have
# automatically set prefix to the location deep down in the framework, so we
# only have to cater for the structural bits of the framework.

1485 1486 1487
frameworkinstallframework: frameworkinstallstructure install frameworkinstallmaclib

frameworkinstallstructure:	$(LDLIBRARY)
1488
	@if test "$(PYTHONFRAMEWORKDIR)" = no-framework; then \
1489
		echo Not configured with --enable-framework; \
1490
		exit 1; \
1491 1492
	else true; \
	fi
1493
	@for i in $(prefix)/Resources/English.lproj $(prefix)/lib; do\
1494
		if test ! -d $(DESTDIR)$$i; then \
1495 1496
			echo "Creating directory $(DESTDIR)$$i"; \
			$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$$i; \
1497 1498 1499
		else	true; \
		fi; \
	done
1500
	$(LN) -fsn include/python$(LDVERSION) $(DESTDIR)$(prefix)/Headers
Benjamin Peterson's avatar
Benjamin Peterson committed
1501
	sed 's/%VERSION%/'"`$(RUNSHARED) ./$(BUILDPYTHON) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(prefix)/Resources/Info.plist
1502
	$(LN) -fsn $(VERSION) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Versions/Current
Christian Heimes's avatar
Christian Heimes committed
1503
	$(LN) -fsn Versions/Current/$(PYTHONFRAMEWORK) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/$(PYTHONFRAMEWORK)
1504 1505
	$(LN) -fsn Versions/Current/Headers $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers
	$(LN) -fsn Versions/Current/Resources $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Resources
1506
	$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
1507

1508
# This installs Mac/Lib into the framework
1509 1510
# Install a number of symlinks to keep software that expects a normal unix
# install (which includes python-config) happy.
1511
frameworkinstallmaclib:
1512 1513 1514 1515
	$(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(LIBPL)/libpython$(LDVERSION).a"
	$(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(LIBPL)/libpython$(LDVERSION).dylib"
	$(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(LIBPL)/libpython$(VERSION).a"
	$(LN) -fs "../../../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(LIBPL)/libpython$(VERSION).dylib"
1516 1517
	$(LN) -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib"
	$(LN) -fs "../$(PYTHONFRAMEWORK)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib"
1518 1519 1520

# This installs the IDE, the Launcher and other apps into /Applications
frameworkinstallapps:
1521
	cd Mac && $(MAKE) installapps DESTDIR="$(DESTDIR)"
1522

1523 1524 1525 1526 1527 1528 1529 1530
# Build the bootstrap executable that will spawn the interpreter inside
# an app bundle within the framework.  This allows the interpreter to
# run OS X GUI APIs.
frameworkpythonw:
	cd Mac && $(MAKE) pythonw

# This installs the python* and other bin symlinks in $prefix/bin or in
# a bin directory relative to the framework root
1531
frameworkinstallunixtools:
1532 1533 1534 1535
	cd Mac && $(MAKE) installunixtools DESTDIR="$(DESTDIR)"

frameworkaltinstallunixtools:
	cd Mac && $(MAKE) altinstallunixtools DESTDIR="$(DESTDIR)"
1536

1537
# This installs the Tools into the applications directory.
1538 1539
# It is not part of a normal frameworkinstall
frameworkinstallextras:
1540
	cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)"
1541

1542 1543
# This installs a few of the useful scripts in Tools/scripts
scriptsinstall:
1544
	SRCDIR=$(srcdir) $(RUNSHARED) \
1545
	$(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \
1546
	--prefix=$(prefix) \
1547
	--install-scripts=$(BINDIR) \
1548
	--root=$(DESTDIR)/
1549

1550
# Build the toplevel Makefile
1551
Makefile.pre: $(srcdir)/Makefile.pre.in config.status
1552 1553 1554
	CONFIG_FILES=Makefile.pre CONFIG_HEADERS= $(SHELL) config.status
	$(MAKE) -f Makefile.pre Makefile

1555
# Run the configure script.
1556
config.status:	$(srcdir)/configure
1557
	$(SHELL) $(srcdir)/configure $(CONFIG_ARGS)
1558

1559
.PRECIOUS: config.status $(BUILDPYTHON) Makefile Makefile.pre
1560 1561 1562

# Some make's put the object file in the current directory
.c.o:
1563
	$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
1564

1565 1566 1567 1568 1569 1570 1571
# bpo-30104: dtoa.c uses union to cast double to unsigned long[2]. clang 4.0
# with -O2 or higher and strict aliasing miscompiles the ratio() function
# causing rounding issues. Compile dtoa.c using -fno-strict-aliasing on clang.
# https://bugs.llvm.org//show_bug.cgi?id=31928
Python/dtoa.o: Python/dtoa.c
	$(CC) -c $(PY_CORE_CFLAGS) $(CFLAGS_ALIASING) -o $@ $<

1572 1573
# Run reindent on the library
reindent:
1574
	./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
1575

1576 1577 1578 1579 1580 1581
# Rerun configure with the same options as it was run last time,
# provided the config.status script exists
recheck:
	$(SHELL) config.status --recheck
	$(SHELL) config.status

1582 1583
# Regenerate configure and pyconfig.h.in
.PHONY: autoconf
1584
autoconf:
1585
	# Regenerate the configure script from configure.ac using autoconf
1586
	(cd $(srcdir); autoconf -Wall)
1587
	# Regenerate pyconfig.h.in from configure.ac using autoheader
1588
	(cd $(srcdir); autoheader -Wall)
1589 1590 1591 1592

# Create a tags file for vi
tags::
	cd $(srcdir); \
1593
	ctags -w Include/*.h Include/internal/*.h; \
1594
	for i in $(SRCDIRS); do ctags -f tags -w -a $$i/*.[ch]; \
1595
	done; \
1596
	LC_ALL=C sort -o tags tags
1597 1598 1599 1600

# Create a tags file for GNU Emacs
TAGS::
	cd $(srcdir); \
1601
	etags Include/*.h Include/internal/*.h; \
1602 1603 1604
	for i in $(SRCDIRS); do etags -a $$i/*.[ch]; done

# Sanitation targets -- clean leaves libraries, executables and tags
1605
# files, which clobber removes as well
1606
pycremoval:
1607
	-find $(srcdir) -depth -name '__pycache__' -exec rm -rf {} ';'
Barry Warsaw's avatar
Barry Warsaw committed
1608
	-find $(srcdir) -name '*.py[co]' -exec rm -f {} ';'
1609

1610 1611 1612 1613 1614 1615 1616
rmtestturds:
	-rm -f *BAD *GOOD *SKIPPED
	-rm -rf OUT
	-rm -f *.TXT
	-rm -f *.txt
	-rm -f gb-18030-2000.xml

1617 1618 1619 1620
docclean:
	-rm -rf Doc/build
	-rm -rf Doc/tools/sphinx Doc/tools/pygments Doc/tools/docutils

1621
clean: pycremoval
1622
	find . -name '*.[oa]' -exec rm -f {} ';'
1623
	find . -name '*.s[ol]' -exec rm -f {} ';'
1624
	find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';'
1625
	find build -name 'fficonfig.h' -exec rm -f {} ';' || true
1626 1627 1628
	find build -name '*.py' -exec rm -f {} ';' || true
	find build -name '*.py[co]' -exec rm -f {} ';' || true
	-rm -f pybuilddir.txt
1629
	-rm -f Lib/lib2to3/*Grammar*.pickle
1630
	-rm -f Programs/_testembed Programs/_freeze_importlib
1631
	-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
1632
	-rm -f Include/pydtrace_probes.h
1633

Christian Heimes's avatar
Christian Heimes committed
1634 1635
profile-removal:
	find . -name '*.gc??' -exec rm -f {} ';'
1636
	find . -name '*.profclang?' -exec rm -f {} ';'
1637
	find . -name '*.dyn' -exec rm -f {} ';'
1638 1639
	rm -f $(COVERAGE_INFO)
	rm -rf $(COVERAGE_REPORT)
Christian Heimes's avatar
Christian Heimes committed
1640 1641

clobber: clean profile-removal
1642
	-rm -f $(BUILDPYTHON) $(PGEN) $(LIBRARY) $(LDLIBRARY) $(DLLLIBRARY) \
1643
		tags TAGS \
1644
		config.cache config.log pyconfig.h Modules/config.c
1645
	-rm -rf build platform
1646
	-rm -rf $(PYTHONFRAMEWORKDIR)
1647
	-rm -f python-config.py python-config
1648 1649 1650

# Make things extra clean, before making a distribution:
# remove all generated files, even Makefile[.pre]
1651
# Keep configure and Python-ast.[ch], it's possible they can't be generated
1652
distclean: clobber
1653 1654
	for file in $(srcdir)/Lib/test/data/* ; do \
	    if test "$$file" != "$(srcdir)/Lib/test/data/README"; then rm "$$file"; fi; \
1655
	done
1656
	-rm -f core Makefile Makefile.pre config.status \
1657
		Modules/Setup Modules/Setup.local \
1658 1659
		Modules/ld_so_aix Modules/python.exp Misc/python.pc \
		Misc/python-config.sh
1660
	-rm -f python*-gdb.py
1661 1662 1663 1664
	# Issue #28258: set LC_ALL to avoid issues with Estonian locale.
	# Expansion is performed here by shell (spawned by make) itself before
	# arguments are passed to find. So LC_ALL=C must be set as a separate
	# command.
1665
	LC_ALL=C; find $(srcdir)/[a-zA-Z]* '(' -name '*.fdc' -o -name '*~' \
1666 1667 1668 1669
				     -o -name '[@,#]*' -o -name '*.old' \
				     -o -name '*.orig' -o -name '*.rej' \
				     -o -name '*.bak' ')' \
				     -exec rm -f {} ';'
1670 1671

# Check for smelly exported symbols (not starting with Py/_Py)
1672
smelly: @DEF_MAKE_RULE@
1673 1674 1675 1676 1677
	nm -p $(LIBRARY) | \
		sed -n "/ [TDB] /s/.* //p" | grep -v "^_*Py" | sort -u; \

# Find files with funny names
funny:
1678
	find $(SUBDIRS) $(SUBDIRSTOO) \
Éric Araujo's avatar
Éric Araujo committed
1679
		-type d \
1680 1681
		-o -name '*.[chs]' \
		-o -name '*.py' \
1682
		-o -name '*.pyw' \
1683 1684 1685 1686
		-o -name '*.dat' \
		-o -name '*.el' \
		-o -name '*.fd' \
		-o -name '*.in' \
1687 1688 1689 1690 1691 1692 1693
		-o -name '*.gif' \
		-o -name '*.txt' \
		-o -name '*.xml' \
		-o -name '*.xbm' \
		-o -name '*.xpm' \
		-o -name '*.uue' \
		-o -name '*.decTest' \
1694 1695
		-o -name '*.tmCommand' \
		-o -name '*.tmSnippet' \
1696 1697 1698
		-o -name 'Setup' \
		-o -name 'Setup.*' \
		-o -name README \
1699 1700
		-o -name NEWS \
		-o -name HISTORY \
1701 1702
		-o -name Makefile \
		-o -name ChangeLog \
1703
		-o -name .hgignore \
1704
		-o -name MANIFEST \
1705
		-o -print
1706

1707
# Perform some verification checks on any modified files.
1708
patchcheck: @DEF_MAKE_RULE@
1709
	$(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/patchcheck.py
1710

1711 1712
# Dependencies

1713
Python/thread.o: @THREADHEADERS@
1714

1715
# Declare targets that aren't real files
1716
.PHONY: all build_all sharedmods oldsharedmods test quicktest
1717 1718 1719 1720
.PHONY: install altinstall oldsharedinstall bininstall altbininstall
.PHONY: maninstall libinstall inclinstall libainstall sharedinstall
.PHONY: frameworkinstall frameworkinstallframework frameworkinstallstructure
.PHONY: frameworkinstallmaclib frameworkinstallapps frameworkinstallunixtools
1721
.PHONY: frameworkaltinstallunixtools recheck clean clobber distclean
1722
.PHONY: smelly funny patchcheck touch altmaninstall commoninstall
1723
.PHONY: gdbhooks
1724

1725
# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
1726 1727 1728
# Local Variables:
# mode: makefile
# End: