summaryrefslogtreecommitdiff
path: root/lang/pypy/Makefile
blob: cfde1455f8ca58d5eb6dbf5495f898b58baa518f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Created by: David Naylor <naylor.b.david@gmail.com>
# $FreeBSD$

PORTNAME=	pypy
DISTVERSION=	1.9
PORTREVISION=	2
CATEGORIES=	lang python java
MASTER_SITES=	https://bitbucket.org/pypy/pypy/get/
DISTNAME=	release-${DISTVERSION}
DIST_SUBDIR=	pypy

MAINTAINER=	naylor.b.david@gmail.com
COMMENT=	PyPy is a fast, compliant implementation of the Python language

LICENSE=	MIT PSFL
LICENSE_COMB=	multi

LIB_DEPENDS=	expat:${PORTSDIR}/textproc/expat2 \
		ffi:${PORTSDIR}/devel/libffi

OPTIONS_DEFINE=	SANDBOX
SANDBOX_DESC=	Translate a sandboxed pypy

BUILD_WRKSRC=	${WRKDIR}
USE_BZIP2=	yes
USE_ICONV=	yes
USE_GETTEXT=	yes
PKGINSTALL=	${WRKDIR}/pkg-install
PKGDEINSTALL=	${WRKDIR}/pkg-deinstall
WRKSRC=		${WRKDIR}/pypy-pypy-341e1e3821ff

PYPY_VER=	${DISTVERSION}
PYTHON_IMPL_VER=	2.7
PYPY_LIBDIR=	lib/pypy${PYPY_VER}
PYPY_INCLUDEDIR=	include/pypy${PYPY_VER}
PYPYDIRS=	${PYPY_INCLUDEDIR} ${PYPY_LIBDIR}

PLIST_SUB+=	PYPY_LIBDIR=${PYPY_LIBDIR} \
		PYPY_INCLUDEDIR=${PYPY_INCLUDEDIR}

MAKE_ENV+=	PYPY_LOCALBASE=${LOCALBASE}
.if exists(/usr/bin/clang)
MAKE_ARGS+=	CC=clang
MAKE_JOBS_SAFE=	yes
.endif

# XXX !.include <bsd.port.pre.mk> as USE_* need to be set prior
.include <bsd.port.options.mk>
.include "${.CURDIR}/files/bsd.pypy.inst.mk"

.if defined(PACKAGE_BUILDING)
MANUAL_PACKAGE_BUILD=	fails to finish compilation on pointyhat, reason unknown
.endif

# List of PyPy instances
.if !defined(PYPY_INST)
PYPY_INST=	DEFAULT

.if ${PORT_OPTIONS:MSANDBOX}
PYPY_INST+=	SANDBOX
.endif

.endif # !defined(PYPY_INST)

PYPY_NAMES=
.for inst in ${PYPY_INST}

PYPY_NAMES+=	${PYPY_${inst}_NAME}
PYPY_PRIMARY?=	${PYPY_${inst}_NAME}

# Check if the boehm GC will be used
.if ${PYPY_${inst}_OPT} == 0 || ${PYPY_${inst}_OPT} == 1 || ${PYPY_${inst}_OPT} == size
WITH_BOEHM_GC=	yes
.endif

# Check if the CLI (mono) backend will be used
.if !empty(PYPY_${inst}_TRANSLATE_ARGS:M--backend=cli)
WITH_CLI=	yes
.endif

# Check if the JVM (java) backend will be used
.if !empty(PYPY_${inst}_TRANSLATE_ARGS:M--backend=jvm)
WITH_JVM=	yes
.endif

.endfor # inst in ${PYPY_INST}

# Use pypy if it is installed, else use python (to translate)
.if !defined(PY)
.if !defined(PYPY)
.if ${PYPY_PRIMARY} == pypy
PYPY!=		${WHICH} ${PYPY_PRIMARY} 2> /dev/null || true
.else
PYPY!=		${WHICH} ${PYPY_PRIMARY} 2> /dev/null || ${WHICH} pypy 2> /dev/null || true
.endif
.endif # !defined(PYPY)

.if exists(${PYPY})
PY=		${PYPY}
.else
USE_PYTHON_BUILD=	2.5+
PY=		${PYTHON_CMD}
.endif
.endif # !defined(PY)

.if defined(WITH_BOEHM_GC)
LIB_DEPENDS+=	gc.1:${PORTSDIR}/devel/boehm-gc
.endif

.if defined(WITH_CLI)
BUILD_DEPENDS+=	mono:${PORTSDIR}/lang/mono
RUN_DEPENDS+=	mono:${PORTSDIR}/lang/mono
ONLY_FOR_ARCHS=	i386 powerpc
ONLY_FOR_ARCHS_REASON=	only translates on 32bit systems
BROKEN=		CLI backend broken, unsupported upstream
.endif

.if defined(WITH_JVM)
USE_JAVA=	yes
JAVA_VERSION=	1.6+
ONLY_FOR_ARCHS=	i386 powerpc
ONLY_FOR_ARCHS_REASON=	only translates on 32bit systems
BROKEN=		JVM backend broken, partially supported upstream
.endif

# Translate FreeBSD ARCH types to PyPy ARCH types
# Pypy officially only supports i386 and amd64, the other platforms are
# untested (and do not have jit support).
.if ${ARCH} == "i386"
PYPY_ARCH=	x86_32
PYPY_JITTABLE=	YES
.elif ${ARCH} == "amd64"
PYPY_ARCH=	x86_64
PYPY_JITTABLE=	YES
.elif ${ARCH} == "powerpc"
PYPY_ARCH=	ppc_32
.elif ${ARCH} == "powerpc64"
PYPY_ARCH=	ppc_64
.else
PYPY_ARCH=	${ARCH}
.endif
PLIST_SUB+=	PYPY_ARCH="${PYPY_ARCH}"

.if !defined(PYPY_JITTABLE)
.for inst in ${PYPY_INST}
.if ${PYPY_${inst}_OPT} == jit
PYPY_${inst}_OPT=	2
.endif
.endfor # inst in ${PYPY_INST}
.endif # !defined(PYPY_JITTABLE)

pre-fetch:
	@${ECHO} "PyPy requires a large amount of free RAM and time to translate and compile."
	@${ECHO}
	@${ECHO} "To translate, PyPy requires on 32bit 3G (min 2G) free RAM and on 64bit"
	@${ECHO} "6G (min 4G) free RAM.  Also, to compile, PyPy on amd64 gcc requires an"
	@${ECHO} "extra 4G however clang only requires 400M (CC=clang) but clang is slower"
	@${ECHO} "in compiling PyPy."
	@${ECHO}
	@${ECHO} "If memory is in short supply consider using a lower optimisation level"
	@${ECHO} "(e.g. PYPY_DEFAULT_OPT=2) however that makes PyPy much slower.  Also,"
	@${ECHO} "consider forcing the build to use python (-DPYPY) however that makes the"
	@${ECHO} "build much slower."
	@${ECHO}
	@${ECHO} "PyPy supports a large number of parameters and customisations.  This port"
	@${ECHO} "supports building multiple instances of PyPy, for example:"
	@${ECHO} "PYPY_INST=	SANDBOX CUSTOM"
	@${ECHO} "PYPY_CUSTOM_NAME=		pypy-custom"
	@${ECHO} "PYPY_CUSTOM_TRANSLATE_ARGS=	--gcrootfinder=shadowstack --gc=generation"
	@${ECHO} "PYPY_CUSTOM_OPT=		0"
	@${ECHO} "PYPY_CUSTOM_OBJSPACE_ARGS=	--no-objspace-usepycfiles --objspace=thunk"
	@${ECHO} "will produce two binaries named 'pypy-sandbox' (SANDBOX instance) and"
	@${ECHO} "'pypy-custom' (CUSTOM instance)."
	@${ECHO} "See for a list of parameters:"
	@${ECHO} "	http://readthedocs.org/docs/pypy/latest/config/index.html"
	@${ECHO} "See for predefined instances:"
	@${ECHO} "	${.CURDIR}/files/bsd.pypy.inst.mk"
	@${ECHO}
	@${ECHO} "On a fast machine PyPy takes around 45 minutes to translate and compile,"
	@${ECHO} "however an average machine takes in excess of 4 hours, per instance."
.if !defined(PYPY_IGNORE_MEM) && (${PYPY_ARCH} == "x86_32" || ${PYPY_ARCH} == "ppc_32")
	@if [ $$((`sysctl -n hw.physmem` / 1024 / 1024)) -le 2000 ]; then \
		${ECHO}; \
		${ECHO} "err: this system has insufficient memory, expected at least 2G RAM",; \
		${ECHO} "err: to overwrite this error define -DPYPY_IGNORE_MEM and try again"; \
		exit 1; \
	fi
.elif !defined(PYPY_IGNORE_MEM)
	@if [ $$((`sysctl -n hw.physmem` / 1024 / 1024)) -le 4000 ]; then \
		${ECHO}; \
		${ECHO} "err: this system has insufficient memory, expected at least 4G RAM",; \
		${ECHO} "err: to overwrite this error define -DPYPY_IGNORE_MEM and try again"; \
		exit 1; \
	fi
.endif
	@sleep 1

post-extract:
	${MKDIR} ${WRKSRC}/lib
	${MV} ${WRKSRC}/lib-python/${PYTHON_IMPL_VER} ${WRKSRC}/${PYPY_LIBDIR}
	${MV} ${WRKSRC}/lib_pypy ${WRKSRC}/${PYPY_LIBDIR}/

post-patch:
	${FIND} ${WRKSRC}/lib -name '*.orig' -delete

do-configure:
	${SED} -e 's|%%PREFIX%%|${PREFIX}|g' \
		-e 's|%%PYPY_NAMES%%|${PYPY_NAMES}|g' \
		-e 's|%%PYPY_VER%%|${PYPY_VER}|g' \
		${FILESDIR}/use.pypy > ${WRKDIR}/use.pypy
	${CP} ${WRKDIR}/use.pypy ${PKGINSTALL}
	${CP} ${WRKDIR}/use.pypy ${PKGDEINSTALL}
	${ECHO} "all: ${PYPY_NAMES}" > ${WRKDIR}/Makefile
	${ECHO} >> ${WRKDIR}/Makefile
.for inst in ${PYPY_INST}
	${ECHO} "${PYPY_${inst}_NAME}: build_${PYPY_${inst}_NAME}/usession-release-${DISTVERSION}-0/testing_1/pypy-c" >> ${WRKDIR}/Makefile
	${ECHO} "	${CP} build_${PYPY_${inst}_NAME}/usession-release-${DISTVERSION}-0/testing_1/pypy-c ${PYPY_${inst}_NAME}" >> ${WRKDIR}/Makefile
	${ECHO} >> ${WRKDIR}/Makefile
	${ECHO} ".done_translate_${PYPY_${inst}_NAME}:" >> ${WRKDIR}/Makefile
	${ECHO} "	${RM} -rf build_${PYPY_${inst}_NAME}" >> ${WRKDIR}/Makefile
	${ECHO} "	${MKDIR} build_${PYPY_${inst}_NAME}" >> ${WRKDIR}/Makefile
	${ECHO} "	(cd ${WRKSRC}/pypy/translator/goal; \
				${SETENV} TMPDIR=${WRKDIR}/build_${PYPY_${inst}_NAME} \
				${PY} translate.py --source ${PYPY_${inst}_TRANSLATE_ARGS} -O${PYPY_${inst}_OPT} \
					targetpypystandalone.py ${PYPY_${inst}_OBJSPACE_ARGS} )" >> ${WRKDIR}/Makefile
	${ECHO} "	${TOUCH} .done_translate_${PYPY_${inst}_NAME}" >> ${WRKDIR}/Makefile
	${ECHO} >> ${WRKDIR}/Makefile
	${ECHO} "build_${PYPY_${inst}_NAME}/usession-release-${DISTVERSION}-0/testing_1/pypy-c: .done_translate_${PYPY_${inst}_NAME}" >> ${WRKDIR}/Makefile
	${ECHO} "	${REINPLACE_CMD} -e 's|^%.o: %.c\$$\$$|.c.o:|g' build_${PYPY_${inst}_NAME}/usession-release-${DISTVERSION}-0/testing_1/Makefile" >> ${WRKDIR}/Makefile
	${ECHO} "	${MAKE} -C build_${PYPY_${inst}_NAME}/usession-release-${DISTVERSION}-0/testing_1 pypy-c" >> ${WRKDIR}/Makefile
	${ECHO} >> ${WRKDIR}/Makefile
.endfor

post-build:
	-${FIND} ${WRKSRC}/${PYPY_LIBDIR} -type d | \
		${SETENV} PYTHON_PATH=${WRKSRC} ${XARGS} \
		${WRKDIR}/${PYPY_PRIMARY} -m compileall -fl
	${MV} ${WRKSRC}/include ${WRKSRC}/include~
	${MKDIR} ${WRKSRC}/include
	${MV} ${WRKSRC}/include~ ${WRKSRC}/${PYPY_INCLUDEDIR}

do-install:
.for dir in ${PYPYDIRS}
	(cd ${WRKSRC}/${dir}; ${COPYTREE_SHARE} . ${PREFIX}/${dir})
.endfor
.for name in ${PYPY_NAMES:O}
	${INSTALL_PROGRAM} ${WRKDIR}/${name} ${PREFIX}/bin/${name}${PYPY_VER}
	${ECHO} bin/${name}${DISTVERSION} >> ${TMPPLIST}
.endfor

post-install:
	${SH} ${PKGINSTALL} ${PKGNAME} POST-INSTALL

test: patch
.for inst in ${PYPY_INST}
	@${WHICH} ${PYPY_${inst}_NAME} > /dev/null 2>&1 || (${ECHO} "Unable to find ${PYPY_${inst}_NAME}, please install port first!"; exit 1)
	(${CD} ${PYPY_LIBDIR}; ${PYPY_${inst}_NAME} ../../pypy/test_all.py)
.endfor

pkg-plist: build
	${RM} -f ${WRKDIR}/.plist-files-gen ${WRKDIR}/.plist-dirs-gen
.for dir in ${PYPYDIRS}
	cd ${WRKSRC} && ${FIND} ${dir} -type f >> ${WRKDIR}/.plist-files-gen
	cd ${WRKSRC} && ${FIND} ${dir} -type d >> ${WRKDIR}/.plist-dirs-gen
.endfor
	${REINPLACE_CMD} -e 's|^${PYPY_LIBDIR}|%%PYPY_LIBDIR%%|g' \
		-e 's|^${PYPY_INCLUDEDIR}|%%PYPY_INCLUDEDIR%%|g' \
		-e 's|${PYPY_ARCH}|%%PYPY_ARCH%%|g' \
			${WRKDIR}/.plist-files-gen
	${REINPLACE_CMD} -e 's|^${PYPY_LIBDIR}|@dirrm %%PYPY_LIBDIR%%|g' \
		-e 's|^${PYPY_INCLUDEDIR}|@dirrm %%PYPY_INCLUDEDIR%%|g' \
			${WRKDIR}/.plist-dirs-gen
	${SORT} ${WRKDIR}/.plist-files-gen > ${WRKDIR}/pkg-plist
	${SORT} -r ${WRKDIR}/.plist-dirs-gen >> ${WRKDIR}/pkg-plist
	${CP} ${WRKDIR}/pkg-plist ${.CURDIR}/pkg-plist

.include <bsd.port.mk>