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)"=="MACOSX" 121# CPython records its temporary installation prefix in the interpreter's load 122# command and the dylib ID. Both files are packaged together in program/. 123BUILD_ACTION+= && install_name_tool -id @loader_path/libpython3.11.dylib $(MYCWD)/python-inst/lib/libpython3.11.dylib 124BUILD_ACTION+= && install_name_tool -change $(MYCWD)/python-inst/lib/libpython3.11.dylib @executable_path/libpython3.11.dylib $(MYCWD)/python-inst/bin/python3.11 125# install_name_tool -change succeeds silently when the old name does not match. 126BUILD_ACTION+= && $(SOLARENV)$/bin$/macosx-check-load-commands.sh $(MYCWD)/python-inst/bin/python3.11 $(MYCWD)/python-inst/lib/libpython3.11.dylib 127.ENDIF 128 129.ELSE 130# ---------------------------------- 131# WINDOWS 132# ---------------------------------- 133.IF "$(COM)"=="GCC" 134#PATCH_FILES=python-$(PYVERSION)-mingw.patch 135BUILD_DIR= 136MYCWD=$(shell cygpath -m $(shell @pwd))/$(INPATH)/misc/build 137python_CFLAGS=-mno-cygwin -mthreads 138python_LDFLAGS=-mno-cygwin -mthreads 139.IF "$(MINGW_SHARED_GCCLIB)"=="YES" 140python_LDFLAGS+=-shared-libgcc 141.ENDIF 142python_LDFLAGS+=-shared-libgcc -Wl,--enable-runtime-pseudo-reloc-v2 143CONFIGURE_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)" 144BUILD_ACTION=$(ENV_BUILD) make && make install 145.ELSE 146#PYTHONPATH:=..$/Lib 147#.EXPORT : PYTHONPATH 148 149#.IF "$(CCNUMVER)" <= "001400000000" 150#EXFLAGS="/GX /YX" 151#.ELSE 152#.IF "$(WINDOWS_VISTA_PSDK)"!="" 153#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE"" 154#ADDITIONALLIBS=ws2_32.lib 155#.ELSE #"$(WINDOWS_VISTA_PSDK)"!="" 156#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE"" 157#.ENDIF #"$(WINDOWS_VISTA_PSDK)"!="" 158#.ENDIF 159 160# The deferral above comes due here. VS2008 cannot build Python 3.11 at all -- 161# that is why trunk left this commented out -- but the UCRT generation can, 162# through PCbuild and MSBuild. Same move CoinMP made on this branch, for the 163# same reason: vcbuild.exe does not exist any more. VC9 keeps the deferral, 164# because for VC9 it is still true. 165.IF "$(COMEX)"=="14" 166 167# pcbuild.proj, not pcbuild.sln: the solution builds every project 168# unconditionally, while the .proj is what understands the switches below. 169BUILD_DIR=PCbuild 170 171# The projects are named one by one rather than letting pcbuild.proj pick them, 172# because its selection is all-or-nothing in the wrong place. Switching its 173# IncludeExternals off drops _bz2, _lzma and _sqlite3 -- which we do want 174# dropped, their sources are downloaded by get_externals.bat and an offline 175# build cannot run it -- but the SAME property also decides whether pythoncore 176# gets zlib, and pythoncore without zlib does not compile: binascii.c is 177# handed USE_ZLIB_CRC32 unconditionally and then cannot find zlib.h. CPython 178# says as much itself, in a _WarnAboutZlib target reading "Not including zlib 179# is not a supported configuration." 180# 181# So: build from the solution, name the targets, and give pythoncore the zlib 182# this tree already has. Everything below needs no external source at all. 183# Built one project at a time, and NOT through pcbuild.sln, because the 184# solution carries dependencies that have nothing to do with compilation 185# order: python.vcxproj declares one on _ctypes purely so that a developer 186# building 'python' in the IDE gets a usable interpreter. Going through the 187# solution therefore drags in libffi, which we do not have and do not want. 188# A .vcxproj built directly honours its own ProjectReferences and ignores the 189# solution's editorial ones. 190# 191# _freeze_module is named EXPLICITLY, and first. Relying on pythoncore's 192# reference to pull it in happens to work for Win32 and does not for x64: the 193# x64 build ran without _freeze_module ever being invoked, left 194# Python/frozen_modules holding nothing but its README, and then died a long 195# way from the cause -- 196# getpath.c(22): fatal error C1083: cannot open include file 197# '../Python/frozen_modules/getpath.h' 198# Naming it costs one project and does not depend on which references MSBuild 199# decides to honour. 200PYTHON_PROJECTS=_freeze_module pythoncore python pythonw _socket select unicodedata pyexpat _elementtree _multiprocessing _overlapped _asyncio _queue _uuid _zoneinfo winsound _decimal _msi 201 202# main/zlib's unpacked source, in the form MSBuild wants. Globbed rather than 203# spelled out so a zlib version bump does not silently miss it -- pythoncore 204# compiles these sources into itself, so it needs the .c files and not just the 205# headers we deliver to solver. 206PYTHON_ZLIB_DIR=$(shell cygpath -m `ls -d $(PRJ)$/..$/zlib$/$(INPATH)$/misc$/build$/zlib-*$/ | head -1`) 207 208# PlatformToolset and WindowsTargetPlatformVersion are passed for the reason 209# CoinMP passes them: the projects default to a newer toolset than is installed. 210PYTHON_MSBUILDFLAGS=\ 211 /p:Configuration=Release \ 212 /p:PlatformToolset=$(VCTOOLSET) \ 213 /p:WindowsTargetPlatformVersion=$(WINDOWS_SDK_VERSION) \ 214 /p:zlibDir=$(PYTHON_ZLIB_DIR) \ 215 /p:IncludeExternals=true \ 216 /p:IncludeSSL=false \ 217 /p:IncludeCTypes=false \ 218 /p:IncludeTkinter=false \ 219 /p:IncludeTests=false 220 221.IF "$(CPUNAME)"=="INTEL" 222PYTHON_MSBUILDPLATFORM=Win32 223.ELIF "$(CPUNAME)"=="X86_64" 224PYTHON_MSBUILDPLATFORM=x64 225.ENDIF 226 227BUILD_ACTION=for p in $(PYTHON_PROJECTS) ; do $(MSBUILD_PATH)$/MSBuild.exe $$p.vcxproj /p:Platform=$(PYTHON_MSBUILDPLATFORM) $(PYTHON_MSBUILDFLAGS) || exit 1 ; done 228 229.ENDIF # "$(COMEX)"=="14" 230.ENDIF 231.ENDIF 232 233PYVERSIONFILE_DMAKE=$(MISC)$/pyversion_dmake.mk 234PYVERSIONFILE=$(MISC)$/pyversion.mk 235 236# --- Targets ------------------------------------------------------ 237 238 239.INCLUDE : set_ext.mk 240.INCLUDE : target.mk 241.INCLUDE : tg_ext.mk 242 243.IF "$(L10N_framework)"=="" 244.IF "$(GUI)" != "UNX" 245.IF "$(COM)"!="GCC" 246PYCONFIG:=$(MISC)$/build$/pyconfig.h 247$(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h : $(PACKAGE_DIR)$/$(CONFIGURE_FLAG_FILE) 248 249$(PACKAGE_DIR)$/$(BUILD_FLAG_FILE) : $(PYCONFIG) 250 251$(PYCONFIG) : $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h 252 -rm -f $@ 253 cat $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h > $@ 254.ENDIF 255.ENDIF 256 257ALLTAR : $(PYVERSIONFILE_DMAKE) $(PYVERSIONFILE) 258.ENDIF # "$(L10N_framework)"=="" 259 260 261$(PYVERSIONFILE_DMAKE) : pyversion_dmake.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE) 262 -rm -f $@ 263 cat $? > $@ 264 265$(PYVERSIONFILE) : pyversion.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE) 266 -rm -f $@ 267 cat $? > $@ 268