1PORTNAME=	python
2DISTVERSION=	${PYTHON_DISTVERSION}
3PORTREVISION=	2
4CATEGORIES=	lang python
5MASTER_SITES=	PYTHON/ftp/python/${DISTVERSION:C/[a-z].*//}
6PKGNAMESUFFIX=	${PYTHON_SUFFIX}
7DISTNAME=	Python-${DISTVERSION}
8DIST_SUBDIR=	python
9
10PATCH_SITES=	https://github.com/python/cpython/commit/
11PATCHFILES=	a46c10ec9d4050ab67b8a932e0859a2ea60c3cb8.patch:-p1 \
12		afc40bdd3dd71f343fd9016f6d8eebbacbd6587c.patch:-p1 \
13		842ce19a0c0b58d61591e8f6a708c38db1fb94e4.patch:-p1 \
14		e9970f077240c7c670e8a6fc6662f2b30d3b6ad0.patch:-p1 \
15		3f396ca9d7bbe2a50ea6b8c9b27c0082884d9f80.patch:-p1 \
16		b1869ff648bbee0717221d09e6deff46617f3e85.patch:-p1 \
17		e4846a93ac07a8ae9aa18203af0dd13d6e7a6995.patch:-p1
18
19MAINTAINER=	ports@MidnightBSD.org
20COMMENT=	Interpreted object-oriented programming language
21WWW=		https://www.python.org/
22
23LICENSE=	python
24
25LIB_DEPENDS=	libffi.so:devel/libffi
26
27USES=		compiler:c11 cpe ncurses pathfix pkgconfig \
28		python:${PYTHON_DISTVERSION:R},env readline shebangfix ssl tar:xz
29PATHFIX_MAKEFILEIN=	Makefile.pre.in
30USE_LDCONFIG=	yes
31GNU_CONFIGURE=	yes
32python_CMD=	${PREFIX}/bin/python${PYTHON_DISTVERSION:R}
33SHEBANG_FILES=	Lib/*.py Lib/*/*.py Lib/*/*/*.py Lib/*/*/*/*.py
34SHEBANG_FILES+=	Lib/test/ziptestdata/exe_with_z64 \
35		Lib/test/ziptestdata/exe_with_zip \
36		Lib/test/ziptestdata/header.sh
37
38# Duplicate python.mk variables. TODO: Let lang/python?? ports use python.mk bits.
39PYTHON_VER=		${PYTHON_DISTVERSION:R}
40PYTHON_VERSION=		python${PYTHON_VER}
41PYTHON_SUFFIX=		${PYTHON_VER:S/.//g}
42
43DISABLED_EXTENSIONS=	_sqlite3 _tkinter _gdbm
44CONFIGURE_ARGS+=	--enable-shared --without-ensurepip \
45			--with-system-ffi
46CONFIGURE_ENV+=		ax_cv_c_float_words_bigendian=no
47CONFIGURE_ENV+=		OPT="" # Null out OPT to respect user CFLAGS and remove optimizations
48
49INSTALL_TARGET=		altinstall						# Don't want cloberring of unprefixed files
50
51TEST_TARGET=		buildbottest
52TEST_ARGS=		TESTOPTS=-j${MAKE_JOBS_NUMBER}
53
54MAKE_ARGS+=		INSTALL_SHARED="${INSTALL_LIB}"				# Strip shared library
55
56SUB_FILES=		pkg-message
57SUB_LIST=		PYTHON_SUFFIX=${PYTHON_SUFFIX}
58
59PLIST_SUB=		ABI=${ABIFLAGS} \
60			XY=${PYTHON_SUFFIX} \
61			DISTVERSION=${DISTVERSION} \
62			XYDOT=${PYTHON_VER} \
63			XYZDOT=${DISTVERSION:C/[a-z].*//} \
64			OSMAJOR=${OSVERSION:C/([0-9]*)[0-9]{5}/\1/}		# For plat-freebsd* in pkg-plist. https://bugs.python.org/issue19554
65
66OPTIONS_DEFINE=		DEBUG IPV6 LIBMPDEC LTO NLS PYMALLOC
67OPTIONS_DEFAULT=	LIBMPDEC PYMALLOC
68OPTIONS_EXCLUDE_powerpc64=	LTO
69OPTIONS_EXCLUDE_riscv64=	LTO
70OPTIONS_RADIO=		HASH
71OPTIONS_RADIO_HASH=	FNV SIPHASH
72OPTIONS_SUB=		yes
73
74LIBMPDEC_DESC=		Use libmpdec from ports instead of bundled version
75NLS_DESC=		Enable gettext support for the locale module
76PYMALLOC_DESC=		Enable specialized mallocs
77
78HASH_DESC=		Hash Algorithm (PEP-456)
79FNV_DESC=		Modified Fowler-Noll-Vo Algorithm
80SIPHASH_DESC=		SipHash24 Algorithm
81
82FNV_CONFIGURE_ON=	--with-hash-algorithm=fnv
83SIPHASH_CONFIGURE_ON=	--with-hash-algorithm=siphash24
84
85DEBUG_CONFIGURE_WITH=	pydebug
86IPV6_CONFIGURE_ENABLE=	ipv6
87
88LIBMPDEC_CONFIGURE_ON=	--with-system-libmpdec
89LIBMPDEC_LIB_DEPENDS=	libmpdec.so:math/mpdecimal
90
91LTO_CONFIGURE_ON=	--with-lto=thin
92
93# Use CPPFLAGS over CFLAGS due to -I ordering, causing elementtree and pyexpat
94# to break in Python 2.7, or preprocessor complaints in Python >= 3.3
95# Upstream Issue: https://bugs.python.org/issue6299
96NLS_USES=		gettext
97NLS_CPPFLAGS=		-I${LOCALBASE}/include
98NLS_LIBS=		-L${LOCALBASE}/lib -lintl
99NLS_CONFIGURE_ENV_OFF=	ac_cv_lib_intl_textdomain=no ac_cv_header_libintl_h=no
100
101PYMALLOC_CONFIGURE_WITH=	pymalloc
102
103NO_TEST=	yes
104
105.include "${.CURDIR}/Makefile.version"
106.include <bsd.mport.options.mk>
107
108.if ${PORT_OPTIONS:MDEBUG}
109ABIFLAGS:=	d${ABIFLAGS}
110.endif
111
112.if !empty(ABIFLAGS)
113PLIST_FILES+=	bin/python${PYTHON_VER}${ABIFLAGS} \
114		bin/python${PYTHON_VER}${ABIFLAGS}-config \
115		libdata/pkgconfig/python-${PYTHON_VER}${ABIFLAGS}.pc \
116		libdata/pkgconfig/python-${PYTHON_VER}${ABIFLAGS}-embed.pc
117.endif
118
119# See https://bugs.freebsd.org/115940 and https://bugs.freebsd.org/193650
120.if !exists(/usr/bin/ypcat) || defined(WITHOUT_NIS)
121PLIST_SUB+=	NO_NIS="@comment "
122DISABLED_EXTENSIONS+=	nis
123.else
124PLIST_SUB+=	NO_NIS=""
125.endif
126
127# Python 3.10 requires OpenSSL >= 1.1.1 (PEP 644), so with
128# libressl, some modules are not built
129#.if ${SSL_DEFAULT:Mlibressl*}
130PLIST_SUB+=	SUPPORTED_OPENSSL="@comment "
131#.else
132#PLIST_SUB+=	SUPPORTED_OPENSSL=""
133#.endif
134
135post-patch:
136# disable the detection of includes and library from e2fsprogs-libuuid,
137# which introduces hidden dependency and breaks build
138	@${REINPLACE_CMD} -e 's|uuid/uuid.h|ignore_&|' ${WRKSRC}/configure
139	@${REINPLACE_CMD} -e '/find_library_file/ s|uuid|ignore_&|' ${WRKSRC}/setup.py
140# disable detection of multiarch as it breaks with clang >= 13, which adds a
141# major.minor version number in -print-multiarch output, confusing Python
142	@${REINPLACE_CMD} -e 's|^\( *MULTIARCH=\).*--print-multiarch.*|\1|' ${WRKSRC}/configure
143# Apply DISABLED_EXTENSIONS
144	@${ECHO_CMD} '*disabled*' > ${WRKSRC}/Modules/Setup.local
145.  for _module in ${DISABLED_EXTENSIONS}
146		@${ECHO_CMD} ${_module} >> ${WRKSRC}/Modules/Setup.local
147.  endfor
148
149post-install:
150.if ! ${PORT_OPTIONS:MDEBUG}
151	${RM} ${PREFIX}/lib/libpython3.so						# Upstream Issue: https://bugs.python.org/issue17975
152.endif
153	${LN} -sf libpython${PYTHON_VER}${ABIFLAGS}.so.1.0 ${PREFIX}/lib/libpython${PYTHON_VER}${ABIFLAGS}.so.1
154# This code block exists for the qemu-user enabled cross build environment.
155# When using this environment in poudriere, CC is not set to the default
156# of /usr/bin/cc and a cross-compile toolchain is used.  We need to hand
157# edit this so that the run time configuration for python matches what the
158# FreeBSD base system provides.  sbruno 02Aug2017
159.if ${CC} == /nxb-bin/usr/bin/cc
160	@${REINPLACE_CMD} -e 's=/nxb-bin==' \
161		${PREFIX}/lib/python${PYTHON_VER}/_sysconfigdata_${ABIFLAGS}_midnightbsd${OSREL:R}_.py
162	@cd ${WRKSRC} && ${SETENV} LD_LIBRARY_PATH=${WRKSRC} \
163		./python -E -m compileall -d ${PREFIX}/lib/python${PYTHON_VER} \
164		${PREFIX}/lib/python${PYTHON_VER}/_sysconfigdata_${ABIFLAGS}_midnightbsd${OSREL:R}_.py
165	@cd ${WRKSRC} && ${SETENV} LD_LIBRARY_PATH=${WRKSRC} \
166		./python -E -O -m compileall -d ${PREFIX}/lib/python${PYTHON_VER} \
167		${PREFIX}/lib/python${PYTHON_VER}/_sysconfigdata_${ABIFLAGS}_midnightbsd${OSREL:R}_.py
168	@${REINPLACE_CMD} -e 's=/nxb-bin==' \
169		${PREFIX}/lib/python${PYTHON_VER}/config-${PYTHON_VER}${ABIFLAGS}/Makefile
170.endif
171	for i in ${PREFIX}/lib/python${PYTHON_VER}/lib-dynload/*.so; do \
172		${STRIP_CMD} $$i; done								# Strip shared extensions
173	${INSTALL_DATA} ${WRKSRC}/Tools/gdb/libpython.py \
174		${PREFIX}/lib/libpython${PYTHON_VER}${ABIFLAGS}.so.1.0-gdb.py
175	-${CP} ${FAKE_DESTDIR}${PREFIX}/libdata/pkgconfig/*.pc ${PREFIX}/libdata/pkgconfig/
176
177.include <bsd.port.mk>
178