xref: /trunk/main/python/makefile.mk (revision 8130eb4fe02ca63dcb4de04f2fca56de984582b9)
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.IF "$(OS)"=="MACOSX"
52# Drops setup.py's /usr/local search paths and disables the modules that
53# would link host or SDK libraries (readline, curses, sqlite3, bz2, lzma, ...).
54PATCH_FILES+=python-$(PYVERSION)-selfcontained.patch
55.ENDIF
56# python-freebsd.patch: all hunks obsolete in Python 3.11 (upstream fixes).
57# python-ssl.patch: dropped. Python 3.11's setup.py finds the bundled OpenSSL
58#   through the compiler include/lib search paths instead of the old hard-coded
59#   source edit; see python_CFLAGS/python_LDFLAGS in the UNX branch below.
60
61# Windows build deferred — Python 3 requires modern MSVC (VS2008/msvs9 not supported).
62# The msvs9 patch files below are retained for reference but are NOT applied until
63# the Windows toolchain is modernised. See python3 migration notes.
64#.IF "$(GUI)"=="WNT"
65#.IF "$(CPUNAME)"=="INTEL"
66#PATCH_FILES += python-$(PYVERSION)-msvs9.patch
67#.ELIF "$(CPUNAME)"=="X86_64"
68#PATCH_FILES += \
69#   python-$(PYVERSION)-msvs9-win64.patch \
70#   python-$(PYVERSION)-msvs9-win64-target.patch \
71#   python-$(PYVERSION)-msvs9-subsystem.patch \
72#   python-$(PYVERSION)-msvs9-dir.patch \
73#   python-$(PYVERSION)-msvs9-no-host-python.patch \
74#   python-$(PYVERSION)-msvs9-python-path.patch
75#.ENDIF
76#.ENDIF
77
78CONFIGURE_DIR=
79
80.IF "$(GUI)"=="UNX"
81BUILD_DIR=
82MYCWD=$(shell @pwd)/$(INPATH)/misc/build
83
84# CPython's own vendored expat (Modules/expat/expat.h) renames every public
85# symbol via pyexpatns.h so it can't clash with any expat also loaded into the
86# process. The solver's external include dir below also carries AOO's own
87# flat expat.h (main/expat delivers it to inc/external/expat.h for other
88# modules), which has no such renaming. Since -I dirs are searched in the
89# order given, put Python's own Modules/expat ahead of the solver dir so
90# "expat.h" resolves to CPython's copy — otherwise pyexpat.c/_elementtree.c
91# compile against the un-renamed declarations while linking against the
92# renamed symbols in libexpat.a, leaving XML_SetCommentHandler (and friends)
93# undefined at import time.
94python_CFLAGS+=-I$(MYCWD)$/$(TARFILE_NAME)$/Modules$/expat
95
96.IF "$(OS)"=="MACOSX"
97# Self-contained build: configure and setup.py must see only the bundled zlib
98# and OpenSSL, never a copy that happens to be installed on the build machine
99# (pkg-config, /usr/local, /opt/local, the SDK). The bundled libraries are
100# delivered as external/zlib/zlib.h, external/openssl/ and libzlib.a, libssl.a,
101# libcrypto.a, so give configure a private prefix where they have the names it
102# looks for. OpenSSL is linked statically into _ssl and _hashlib; the shared
103# libraries carry a packaging-time install name that cannot be loaded here, and
104# lib-dynload could not find them next to the office libraries anyway.
105PY_SHIM=$(MYCWD)$/py-shim
106python_prep=mkdir -p $(PY_SHIM)/include $(PY_SHIM)/lib &&
107python_CFLAGS+=-I$(PY_SHIM)/include
108python_LDFLAGS+=-L$(PY_SHIM)/lib
109python_env=PKG_CONFIG_PATH= PKG_CONFIG_LIBDIR=/dev/null
110# Use the copies of expat and libmpdec that come with CPython. _ctypes still
111# links the OS libffi; the OS copy is always present.
112python_conf=--without-system-expat --without-system-libmpdec --without-system-ffi
113.IF "$(SYSTEM_ZLIB)"!="YES"
114python_prep+=ln -sf $(SOLARINCDIR)/external/zlib/zlib.h $(PY_SHIM)/include/zlib.h && ln -sf $(SOLARINCDIR)/external/zlib/zconf.h $(PY_SHIM)/include/zconf.h && ln -sf $(SOLARLIBDIR)/libzlib.a $(PY_SHIM)/lib/libz.a &&
115# Given directly because configure's fallback probe looks for gzread, which the
116# bundled zlib does not contain; the zlib module itself does not use it.
117python_conf+=ZLIB_CFLAGS="-I$(PY_SHIM)/include" ZLIB_LIBS="-L$(PY_SHIM)/lib -lz"
118.ENDIF
119.IF "$(SYSTEM_OPENSSL)"!="YES"
120python_prep+=ln -sfn $(SOLARINCDIR)/external/openssl $(PY_SHIM)/include/openssl && ln -sf $(SOLARLIBDIR)/libssl.a $(PY_SHIM)/lib/libssl.a && ln -sf $(SOLARLIBDIR)/libcrypto.a $(PY_SHIM)/lib/libcrypto.a &&
121python_conf+=--with-openssl=$(PY_SHIM)
122.ENDIF
123.ELSE
124# Point Python's setup.py at the bundled OpenSSL delivered to the solver.
125# (Replaces the old python-ssl.patch: Python 3.11 discovers _ssl/_hashlib via
126# the C compiler include/lib search paths, so feeding the solver's external
127# include dir and lib dir through CFLAGS/LDFLAGS is sufficient. Headers live
128# in $(SOLARINCDIR)/external/openssl/, so the search dir is .../external so
129# that setup.py's "openssl/ssl.h" probe resolves.)
130python_CFLAGS+=-I$(SOLARINCDIR)$/external
131python_LDFLAGS+=-L$(SOLARLIBDIR)
132.ENDIF
133
134# CLFLAGS get overwritten in Makefile.pre.in
135.IF "$(SYSBASE)"!=""
136CC+:=-I$(SYSBASE)$/usr$/include
137python_LDFLAGS+=-L$(SYSBASE)/usr/lib
138.IF "$(COMNAME)"=="sunpro5"
139CC+:=$(C_RESTRICTIONFLAGS)
140.ENDIF          # "$(COMNAME)"=="sunpro5"
141.ENDIF          # "$(SYSBASE)"!=""
142
143.IF "$(OS)$(CPU)"=="SOLARISU"
144CC+:=$(ARCH_FLAGS)
145python_LDFLAGS+=$(ARCH_FLAGS)
146.ENDIF
147
148CONFIGURE_ACTION=$(python_prep) $(AUGMENT_LIBRARY_PATH) $(python_env) ./configure --prefix=$(MYCWD)/python-inst --enable-shared $(python_conf) CFLAGS="$(python_CFLAGS)" LDFLAGS="$(python_LDFLAGS)"
149.IF "$(OS)$(CPU)" == "SOLARISI"
150CONFIGURE_ACTION += --disable-ipv6
151.ENDIF
152BUILD_ACTION=$(ENV_BUILD) $(GNUMAKE) -j$(EXTMAXPROCESS) && $(GNUMAKE) install && chmod -R ug+w $(MYCWD)/python-inst && chmod g+w Include
153
154.IF "$(OS)"=="MACOSX"
155# CPython records its temporary installation prefix in the interpreter's load
156# command and the dylib ID. Both files are packaged together in program/.
157BUILD_ACTION+= && install_name_tool -id @loader_path/libpython3.11.dylib $(MYCWD)/python-inst/lib/libpython3.11.dylib
158BUILD_ACTION+= && install_name_tool -change $(MYCWD)/python-inst/lib/libpython3.11.dylib @executable_path/libpython3.11.dylib $(MYCWD)/python-inst/bin/python3.11
159# install_name_tool -change succeeds silently when the old name does not match.
160BUILD_ACTION+= && $(SOLARENV)$/bin$/macosx-check-load-commands.sh $(MYCWD)/python-inst/bin/python3.11 $(MYCWD)/python-inst/lib/libpython3.11.dylib
161.ENDIF
162
163.ELSE
164# ----------------------------------
165# WINDOWS
166# ----------------------------------
167.IF "$(COM)"=="GCC"
168#PATCH_FILES=python-$(PYVERSION)-mingw.patch
169BUILD_DIR=
170MYCWD=$(shell cygpath -m $(shell @pwd))/$(INPATH)/misc/build
171python_CFLAGS=-mno-cygwin -mthreads
172python_LDFLAGS=-mno-cygwin -mthreads
173.IF "$(MINGW_SHARED_GCCLIB)"=="YES"
174python_LDFLAGS+=-shared-libgcc
175.ENDIF
176python_LDFLAGS+=-shared-libgcc -Wl,--enable-runtime-pseudo-reloc-v2
177CONFIGURE_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)"
178BUILD_ACTION=$(ENV_BUILD) make && make install
179.ELSE
180#PYTHONPATH:=..$/Lib
181#.EXPORT : PYTHONPATH
182
183#.IF "$(CCNUMVER)" <= "001400000000"
184#EXFLAGS="/GX /YX"
185#.ELSE
186#.IF "$(WINDOWS_VISTA_PSDK)"!=""
187#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE""
188#ADDITIONALLIBS=ws2_32.lib
189#.ELSE  #"$(WINDOWS_VISTA_PSDK)"!=""
190#EXFLAGS="/EHa /Zc:wchar_t- /D "_CRT_SECURE_NO_DEPRECATE""
191#.ENDIF #"$(WINDOWS_VISTA_PSDK)"!=""
192#.ENDIF
193
194# The deferral above comes due here.  VS2008 cannot build Python 3.11 at all --
195# that is why trunk left this commented out -- but the UCRT generation can,
196# through PCbuild and MSBuild.  Same move CoinMP made on this branch, for the
197# same reason: vcbuild.exe does not exist any more.  VC9 keeps the deferral,
198# because for VC9 it is still true.
199.IF "$(COMEX)"=="14"
200
201# pcbuild.proj, not pcbuild.sln: the solution builds every project
202# unconditionally, while the .proj is what understands the switches below.
203BUILD_DIR=PCbuild
204
205# The projects are named one by one rather than letting pcbuild.proj pick them,
206# because its selection is all-or-nothing in the wrong place.  Switching its
207# IncludeExternals off drops _bz2, _lzma and _sqlite3 -- which we do want
208# dropped, their sources are downloaded by get_externals.bat and an offline
209# build cannot run it -- but the SAME property also decides whether pythoncore
210# gets zlib, and pythoncore without zlib does not compile:  binascii.c is
211# handed USE_ZLIB_CRC32 unconditionally and then cannot find zlib.h.  CPython
212# says as much itself, in a _WarnAboutZlib target reading "Not including zlib
213# is not a supported configuration."
214#
215# So: build from the solution, name the targets, and give pythoncore the zlib
216# this tree already has.  Everything below needs no external source at all.
217# Built one project at a time, and NOT through pcbuild.sln, because the
218# solution carries dependencies that have nothing to do with compilation
219# order: python.vcxproj declares one on _ctypes purely so that a developer
220# building 'python' in the IDE gets a usable interpreter.  Going through the
221# solution therefore drags in libffi, which we do not have and do not want.
222# A .vcxproj built directly honours its own ProjectReferences and ignores the
223# solution's editorial ones.
224#
225# _freeze_module is named EXPLICITLY, and first.  Relying on pythoncore's
226# reference to pull it in happens to work for Win32 and does not for x64: the
227# x64 build ran without _freeze_module ever being invoked, left
228# Python/frozen_modules holding nothing but its README, and then died a long
229# way from the cause --
230#     getpath.c(22): fatal error C1083: cannot open include file
231#                    '../Python/frozen_modules/getpath.h'
232# Naming it costs one project and does not depend on which references MSBuild
233# decides to honour.
234PYTHON_PROJECTS=_freeze_module pythoncore python pythonw _socket select unicodedata pyexpat _elementtree _multiprocessing _overlapped _asyncio _queue _uuid _zoneinfo winsound _decimal _msi
235
236# main/zlib's unpacked source, in the form MSBuild wants.  Globbed rather than
237# spelled out so a zlib version bump does not silently miss it -- pythoncore
238# compiles these sources into itself, so it needs the .c files and not just the
239# headers we deliver to solver.
240PYTHON_ZLIB_DIR=$(shell cygpath -m `ls -d $(PRJ)$/..$/zlib$/$(INPATH)$/misc$/build$/zlib-*$/ | head -1`)
241
242# PlatformToolset and WindowsTargetPlatformVersion are passed for the reason
243# CoinMP passes them: the projects default to a newer toolset than is installed.
244PYTHON_MSBUILDFLAGS=\
245    /p:Configuration=Release \
246    /p:PlatformToolset=$(VCTOOLSET) \
247    /p:WindowsTargetPlatformVersion=$(WINDOWS_SDK_VERSION) \
248    /p:zlibDir=$(PYTHON_ZLIB_DIR) \
249    /p:IncludeExternals=true \
250    /p:IncludeSSL=false \
251    /p:IncludeCTypes=false \
252    /p:IncludeTkinter=false \
253    /p:IncludeTests=false
254
255.IF "$(CPUNAME)"=="INTEL"
256PYTHON_MSBUILDPLATFORM=Win32
257.ELIF "$(CPUNAME)"=="X86_64"
258PYTHON_MSBUILDPLATFORM=x64
259.ENDIF
260
261BUILD_ACTION=for p in $(PYTHON_PROJECTS) ; do $(MSBUILD_PATH)$/MSBuild.exe $$p.vcxproj /p:Platform=$(PYTHON_MSBUILDPLATFORM) $(PYTHON_MSBUILDFLAGS) || exit 1 ; done
262
263.ENDIF          # "$(COMEX)"=="14"
264.ENDIF
265.ENDIF
266
267PYVERSIONFILE_DMAKE=$(MISC)$/pyversion_dmake.mk
268PYVERSIONFILE=$(MISC)$/pyversion.mk
269
270# --- Targets ------------------------------------------------------
271
272
273.INCLUDE : set_ext.mk
274.INCLUDE : target.mk
275.INCLUDE : tg_ext.mk
276
277.IF "$(L10N_framework)"==""
278.IF "$(GUI)" != "UNX"
279.IF "$(COM)"!="GCC"
280PYCONFIG:=$(MISC)$/build$/pyconfig.h
281$(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h : $(PACKAGE_DIR)$/$(CONFIGURE_FLAG_FILE)
282
283$(PACKAGE_DIR)$/$(BUILD_FLAG_FILE) : $(PYCONFIG)
284
285$(PYCONFIG) : $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h
286    -rm -f $@
287    cat $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h > $@
288.ENDIF
289.ENDIF
290
291ALLTAR : $(PYVERSIONFILE_DMAKE) $(PYVERSIONFILE)
292.ENDIF          # "$(L10N_framework)"==""
293
294
295$(PYVERSIONFILE_DMAKE) : pyversion_dmake.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE)
296    -rm -f $@
297    cat $? > $@
298
299$(PYVERSIONFILE) : pyversion.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE)
300    -rm -f $@
301    cat $? > $@
302