1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20#************************************************************** 21 22 23 24PRJ=. 25 26PRJNAME=so_python 27TARGET=so_python 28 29# --- Settings ----------------------------------------------------- 30 31.INCLUDE : settings.mk 32.INCLUDE : pyversion_dmake.mk 33 34.IF "$(SYSTEM_PYTHON)" == "YES" 35all: 36 @echo "An already available installation of python should exist on your system." 37 @echo "Therefore the version provided here does not need to be built in addition." 38.ENDIF 39 40 41# --- Files -------------------------------------------------------- 42 43 44TARFILE_NAME=Python-$(PYVERSION) 45TARFILE_MD5=57f84cbd92d478ceff55217d88a07ded 46PATCH_FILES=\ 47 python-md5.patch \ 48 python-solver-before-std.patch \ 49 python-$(PYVERSION)-sysbase.patch \ 50 python-$(PYVERSION)-nohardlink.patch 51# python-freebsd.patch: all hunks obsolete in Python 3.11 (upstream fixes). 52# python-ssl.patch: dropped. Python 3.11's setup.py finds the bundled OpenSSL 53# through the compiler include/lib search paths instead of the old hard-coded 54# source edit; see python_CFLAGS/python_LDFLAGS in the UNX branch below. 55 56# Windows build deferred — Python 3 requires modern MSVC (VS2008/msvs9 not supported). 57# The msvs9 patch files below are retained for reference but are NOT applied until 58# the Windows toolchain is modernised. See python3 migration notes. 59#.IF "$(GUI)"=="WNT" 60#.IF "$(CPUNAME)"=="INTEL" 61#PATCH_FILES += python-$(PYVERSION)-msvs9.patch 62#.ELIF "$(CPUNAME)"=="X86_64" 63#PATCH_FILES += \ 64# python-$(PYVERSION)-msvs9-win64.patch \ 65# python-$(PYVERSION)-msvs9-win64-target.patch \ 66# python-$(PYVERSION)-msvs9-subsystem.patch \ 67# python-$(PYVERSION)-msvs9-dir.patch \ 68# python-$(PYVERSION)-msvs9-no-host-python.patch \ 69# python-$(PYVERSION)-msvs9-python-path.patch 70#.ENDIF 71#.ENDIF 72 73CONFIGURE_DIR= 74 75.IF "$(GUI)"=="UNX" 76BUILD_DIR= 77MYCWD=$(shell @pwd)/$(INPATH)/misc/build 78 79# CPython's own vendored expat (Modules/expat/expat.h) renames every public 80# symbol via pyexpatns.h so it can't clash with any expat also loaded into the 81# process. The solver's external include dir below also carries AOO's own 82# flat expat.h (main/expat delivers it to inc/external/expat.h for other 83# modules), which has no such renaming. Since -I dirs are searched in the 84# order given, put Python's own Modules/expat ahead of the solver dir so 85# "expat.h" resolves to CPython's copy — otherwise pyexpat.c/_elementtree.c 86# compile against the un-renamed declarations while linking against the 87# renamed symbols in libexpat.a, leaving XML_SetCommentHandler (and friends) 88# undefined at import time. 89python_CFLAGS+=-I$(MYCWD)$/$(TARFILE_NAME)$/Modules$/expat 90 91# Point Python's setup.py at the bundled OpenSSL delivered to the solver. 92# (Replaces the old python-ssl.patch: Python 3.11 discovers _ssl/_hashlib via 93# the C compiler include/lib search paths, so feeding the solver's external 94# include dir and lib dir through CFLAGS/LDFLAGS is sufficient. Headers live 95# in $(SOLARINCDIR)/external/openssl/, so the search dir is .../external so 96# that setup.py's "openssl/ssl.h" probe resolves.) 97python_CFLAGS+=-I$(SOLARINCDIR)$/external 98python_LDFLAGS+=-L$(SOLARLIBDIR) 99 100# CLFLAGS get overwritten in Makefile.pre.in 101.IF "$(SYSBASE)"!="" 102CC+:=-I$(SYSBASE)$/usr$/include 103python_LDFLAGS+=-L$(SYSBASE)/usr/lib 104.IF "$(COMNAME)"=="sunpro5" 105CC+:=$(C_RESTRICTIONFLAGS) 106.ENDIF # "$(COMNAME)"=="sunpro5" 107.ENDIF # "$(SYSBASE)"!="" 108 109.IF "$(OS)$(CPU)"=="SOLARISU" 110CC+:=$(ARCH_FLAGS) 111python_LDFLAGS+=$(ARCH_FLAGS) 112.ENDIF 113 114CONFIGURE_ACTION=$(AUGMENT_LIBRARY_PATH) ./configure --prefix=$(MYCWD)/python-inst --enable-shared CFLAGS="$(python_CFLAGS)" LDFLAGS="$(python_LDFLAGS)" 115.IF "$(OS)$(CPU)" == "SOLARISI" 116CONFIGURE_ACTION += --disable-ipv6 117.ENDIF 118BUILD_ACTION=$(ENV_BUILD) $(GNUMAKE) -j$(EXTMAXPROCESS) && $(GNUMAKE) install && chmod -R ug+w $(MYCWD)/python-inst && chmod g+w Include 119 120.IF "$(OS)"=="LINUX" 121# CPython's sysconfig module names its generated data module after the 122# platform/ABI (e.g. _sysconfigdata__linux_x86_64-linux-gnu.py) instead of 123# the plain "_sysconfigdata.py" that main/python/prj/d.lst delivers. Rename 124# it in place so delivery finds the name it's looking for. 125BUILD_ACTION+= && for d in $(MYCWD)/python-inst/lib/python3.11 $(MYCWD)/python-inst/lib64/python3.11; do test -d "$$d" && (cd "$$d" && for f in _sysconfigdata_*.py; do test -f "$$f" && mv -f "$$f" _sysconfigdata.py; done); done; true 126.ENDIF 127 128.ELSE 129# ---------------------------------- 130# WINDOWS 131# ---------------------------------- 132.IF "$(COM)"=="GCC" 133#PATCH_FILES=python-$(PYVERSION)-mingw.patch 134BUILD_DIR= 135MYCWD=$(shell cygpath -m $(shell @pwd))/$(INPATH)/misc/build 136python_CFLAGS=-mno-cygwin -mthreads 137python_LDFLAGS=-mno-cygwin -mthreads 138.IF "$(MINGW_SHARED_GCCLIB)"=="YES" 139python_LDFLAGS+=-shared-libgcc 140.ENDIF 141python_LDFLAGS+=-shared-libgcc -Wl,--enable-runtime-pseudo-reloc-v2 142CONFIGURE_ACTION=./configure --prefix=$(MYCWD)/python-inst --enable-shared CC="$(CC:s/guw.exe //)" CXX="$(CXX:s/guw.exe //)" MACHDEP=MINGW32 LN="cp -p" CFLAGS="$(python_CFLAGS)" LDFLAGS="$(python_LDFLAGS)" 143BUILD_ACTION=$(ENV_BUILD) make && make install 144.ELSE 145#PYTHONPATH:=..$/Lib 146#.EXPORT : PYTHONPATH 147 148#.IF "$(CCNUMVER)" <= "001400000000" 149#EXFLAGS="/GX /YX" 150#.ELSE 151#.IF "$(WINDOWS_VISTA_PSDK)"!="" 152#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE"" 153#ADDITIONALLIBS=ws2_32.lib 154#.ELSE #"$(WINDOWS_VISTA_PSDK)"!="" 155#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE"" 156#.ENDIF #"$(WINDOWS_VISTA_PSDK)"!="" 157#.ENDIF 158 159# The deferral above comes due here. VS2008 cannot build Python 3.11 at all -- 160# that is why trunk left this commented out -- but the UCRT generation can, 161# through PCbuild and MSBuild. Same move CoinMP made on this branch, for the 162# same reason: vcbuild.exe does not exist any more. VC9 keeps the deferral, 163# because for VC9 it is still true. 164.IF "$(COMEX)"=="14" 165 166# pcbuild.proj, not pcbuild.sln: the solution builds every project 167# unconditionally, while the .proj is what understands the switches below. 168BUILD_DIR=PCbuild 169 170# The projects are named one by one rather than letting pcbuild.proj pick them, 171# because its selection is all-or-nothing in the wrong place. Switching its 172# IncludeExternals off drops _bz2, _lzma and _sqlite3 -- which we do want 173# dropped, their sources are downloaded by get_externals.bat and an offline 174# build cannot run it -- but the SAME property also decides whether pythoncore 175# gets zlib, and pythoncore without zlib does not compile: binascii.c is 176# handed USE_ZLIB_CRC32 unconditionally and then cannot find zlib.h. CPython 177# says as much itself, in a _WarnAboutZlib target reading "Not including zlib 178# is not a supported configuration." 179# 180# So: build from the solution, name the targets, and give pythoncore the zlib 181# this tree already has. Everything below needs no external source at all. 182# Built one project at a time, and NOT through pcbuild.sln, because the 183# solution carries dependencies that have nothing to do with compilation 184# order: python.vcxproj declares one on _ctypes purely so that a developer 185# building 'python' in the IDE gets a usable interpreter. Going through the 186# solution therefore drags in libffi, which we do not have and do not want. 187# A .vcxproj built directly honours its own ProjectReferences and ignores the 188# solution's editorial ones. 189# 190# _freeze_module is named EXPLICITLY, and first. Relying on pythoncore's 191# reference to pull it in happens to work for Win32 and does not for x64: the 192# x64 build ran without _freeze_module ever being invoked, left 193# Python/frozen_modules holding nothing but its README, and then died a long 194# way from the cause -- 195# getpath.c(22): fatal error C1083: cannot open include file 196# '../Python/frozen_modules/getpath.h' 197# Naming it costs one project and does not depend on which references MSBuild 198# decides to honour. 199PYTHON_PROJECTS=_freeze_module pythoncore python pythonw _socket select unicodedata pyexpat _elementtree _multiprocessing _overlapped _asyncio _queue _uuid _zoneinfo winsound _decimal _msi 200 201# main/zlib's unpacked source, in the form MSBuild wants. Globbed rather than 202# spelled out so a zlib version bump does not silently miss it -- pythoncore 203# compiles these sources into itself, so it needs the .c files and not just the 204# headers we deliver to solver. 205PYTHON_ZLIB_DIR=$(shell cygpath -m `ls -d $(PRJ)$/..$/zlib$/$(INPATH)$/misc$/build$/zlib-*$/ | head -1`) 206 207# PlatformToolset and WindowsTargetPlatformVersion are passed for the reason 208# CoinMP passes them: the projects default to a newer toolset than is installed. 209PYTHON_MSBUILDFLAGS=\ 210 /p:Configuration=Release \ 211 /p:PlatformToolset=$(VCTOOLSET) \ 212 /p:WindowsTargetPlatformVersion=$(WINDOWS_SDK_VERSION) \ 213 /p:zlibDir=$(PYTHON_ZLIB_DIR) \ 214 /p:IncludeExternals=true \ 215 /p:IncludeSSL=false \ 216 /p:IncludeCTypes=false \ 217 /p:IncludeTkinter=false \ 218 /p:IncludeTests=false 219 220.IF "$(CPUNAME)"=="INTEL" 221PYTHON_MSBUILDPLATFORM=Win32 222.ELIF "$(CPUNAME)"=="X86_64" 223PYTHON_MSBUILDPLATFORM=x64 224.ENDIF 225 226BUILD_ACTION=for p in $(PYTHON_PROJECTS) ; do $(MSBUILD_PATH)$/MSBuild.exe $$p.vcxproj /p:Platform=$(PYTHON_MSBUILDPLATFORM) $(PYTHON_MSBUILDFLAGS) || exit 1 ; done 227 228.ENDIF # "$(COMEX)"=="14" 229.ENDIF 230.ENDIF 231 232PYVERSIONFILE_DMAKE=$(MISC)$/pyversion_dmake.mk 233PYVERSIONFILE=$(MISC)$/pyversion.mk 234 235# --- Targets ------------------------------------------------------ 236 237 238.INCLUDE : set_ext.mk 239.INCLUDE : target.mk 240.INCLUDE : tg_ext.mk 241 242.IF "$(L10N_framework)"=="" 243.IF "$(GUI)" != "UNX" 244.IF "$(COM)"!="GCC" 245PYCONFIG:=$(MISC)$/build$/pyconfig.h 246$(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h : $(PACKAGE_DIR)$/$(CONFIGURE_FLAG_FILE) 247 248$(PACKAGE_DIR)$/$(BUILD_FLAG_FILE) : $(PYCONFIG) 249 250$(PYCONFIG) : $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h 251 -rm -f $@ 252 cat $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h > $@ 253.ENDIF 254.ENDIF 255 256ALLTAR : $(PYVERSIONFILE_DMAKE) $(PYVERSIONFILE) 257.ENDIF # "$(L10N_framework)"=="" 258 259 260$(PYVERSIONFILE_DMAKE) : pyversion_dmake.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE) 261 -rm -f $@ 262 cat $? > $@ 263 264$(PYVERSIONFILE) : pyversion.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE) 265 -rm -f $@ 266 cat $? > $@ 267