xref: /trunk/main/python/makefile.mk (revision 6ebe52f808faa3285ea18ab8e983eb89d5cfb82c)
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# Windows build deferred — Python 3 requires modern MSVC (PCbuild); VS9.0/vcbuild
160# no longer supported. Retained for reference. See python3 migration notes.
161#BUILD_DIR=PC/VS9.0
162#.IF "$(CPUNAME)"=="INTEL"
163#BUILD_ACTION=$(COMPATH)$/vcpackages$/vcbuild.exe -useenv pcbuild.sln "Release|Win32"
164#.ELIF "$(CPUNAME)"=="X86_64"
165#BUILD_ACTION=$(COMPATH)$/vcpackages$/vcbuild.exe -useenv pcbuild.sln "Release|x64"
166#.ENDIF
167.ENDIF
168.ENDIF
169
170PYVERSIONFILE_DMAKE=$(MISC)$/pyversion_dmake.mk
171PYVERSIONFILE=$(MISC)$/pyversion.mk
172
173# --- Targets ------------------------------------------------------
174
175
176.INCLUDE : set_ext.mk
177.INCLUDE : target.mk
178.INCLUDE : tg_ext.mk
179
180.IF "$(L10N_framework)"==""
181.IF "$(GUI)" != "UNX"
182.IF "$(COM)"!="GCC"
183PYCONFIG:=$(MISC)$/build$/pyconfig.h
184$(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h : $(PACKAGE_DIR)$/$(CONFIGURE_FLAG_FILE)
185
186$(PACKAGE_DIR)$/$(BUILD_FLAG_FILE) : $(PYCONFIG)
187
188$(PYCONFIG) : $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h
189    -rm -f $@
190    cat $(MISC)$/build$/$(TARFILE_NAME)$/PC$/pyconfig.h > $@
191.ENDIF
192.ENDIF
193
194ALLTAR : $(PYVERSIONFILE_DMAKE) $(PYVERSIONFILE)
195.ENDIF          # "$(L10N_framework)"==""
196
197
198$(PYVERSIONFILE_DMAKE) : pyversion_dmake.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE)
199    -rm -f $@
200    cat $? > $@
201
202$(PYVERSIONFILE) : pyversion.mk $(PACKAGE_DIR)$/$(PREDELIVER_FLAG_FILE)
203    -rm -f $@
204    cat $? > $@
205