summaryrefslogtreecommitdiff
path: root/mk/ocaml.mk
blob: 09e5b421ab64370dd2216ce9be28b35d2f64849a (plain)
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
278
279
280
281
282
283
284
285
286
287
288
289
290
# $NetBSD: ocaml.mk,v 1.32 2022/03/03 03:32:28 mrg Exp $
#
# This Makefile fragment handles the common variables used by OCaml packages.
#
# Build def variables:
# OCAML_USE_OPT_COMPILER 
# if set to yes, will enable optimised (native code) compilation
# default value: depends on architecture
#
# PLIST variable:
# PLIST.ocaml-opt for files only installed when using the optimised compiler
# Set based on OCAML_USE_OPT_COMPILER
# 
# Package-settable variables:
# OCAML_USE_FINDLIB
# package uses findlib infrastructure
# OCAML_FINDLIB_DIRS
# directories under OCAML_SITELIBDIR that this package installs into
# OCAML_FINDLIB_REGISTER
# register findlib directories into OCaml ld.conf
# OCAML_USE_OASIS [implies OCAML_USE_FINDLIB]
# package uses oasis infrastructure
# OCAML_USE_OASIS_DYNRUN [implies OCAML_USE_OASIS]
# package uses oasis.dynrun
# OCAML_USE_OPAM
# package uses OPAM installer [implies OCAML_USE_FINDLIB]
# OCAML_USE_TOPKG
# package uses topkg [implies OCAML_USE_FINDLIB]
# OCAML_USE_DUNE
# package uses dune [implies OCAML_USE_OPAM]
# OCAML_TOPKG_DOCDIR
# different targets for topkg (bytecode, optional bytecode, native)
# OASIS_BUILD_ARGS
# arguments for oasis build
# Set by this file:
# OCAML_SITELIBDIR

.if !defined(OCAML_MK)
OCAML_MK= # defined

# Text relocations errors when building packages that use
# ocamlfind on i386.
MKPIE_SUPPORTED=	no

.include "../../mk/bsd.fast.prefs.mk"

BUILD_DEFS+=	OCAML_USE_OPT_COMPILER

_VARGROUPS+=	ocaml
_PKG_VARS.ocaml=	\
	OCAML_USE_FINDLIB \
	OCAML_FINDLIB_DIRS \
	OCAML_FINDLIB_REGISTER \
	OCAML_USE_OASIS \
	OCAML_USE_OASIS_DYNRUN \
	OASIS_BUILD_ARGS \
	OCAML_USE_OPAM \
	OCAML_USE_TOPKG \
	OCAML_TOPKG_NAME \
	OCAML_TOPKG_DOCDIR \
	OCAML_TOPKG_FLAGS \
	OCAML_TOPKG_TARGETS \
	OCAML_TOPKG_OPTIONAL_TARGETS \
	JBUILDER_BUILD_FLAGS \
	JBUILDER_BUILD_PACKAGES \
	JBUILDER_BUILD_TARGETS \
	OCAML_USE_DUNE \
	DUNE_BUILD_FLAGS \
	DUNE_BUILD_PACKAGES \
	DUNE_BUILD_TARGETS \
	OCAML_BUILD_ARGS \
	OPAM_INSTALL_DIR \
	OPAM_INSTALL_FILES
_DEF_VARS.ocaml=	\
	OCAML_USE_OPT_COMPILER
_SYS_VARS.ocaml=	\
	OCAML_SITELIBDIR

# Default value of OCAML_USE_FINDLIB
OCAML_USE_FINDLIB?=	no

# Default value of OCAML_USE_OASIS
OCAML_USE_OASIS?=	no

# Default value of OCAML_USE_OASIS_DYNRUN
OCAML_USE_OASIS_DYNRUN?=	no

# Default value of OCAML_USE_TOPKG
OCAML_USE_TOPKG?=	no

# Default value of OCAML_USE_DUNE
OCAML_USE_DUNE?=	no

OCAML_TOPKG_NAME?=	${PKGBASE:S/^ocaml-//}
OCAML_TOPKG_DOCDIR?=	${PREFIX}/share/doc
OCAML_TOPKG_FLAGS?=	# empty
OCAML_TOPKG_TARGETS?=	# empty
OCAML_TOPKG_OPTIONAL_TARGETS?=	# empty
OCAML_TOPKG_NATIVE_TARGETS?=	# empty

OPAM_INSTALL_FILES?=	${OCAML_TOPKG_NAME}
JBUILDER_BUILD_FLAGS?=	# empty
JBUILDER_BUILD_TARGETS?=	@install
JBUILDER_BUILD_PACKAGES?=	# empty
DUNE_BUILD_FLAGS?=	# empty
DUNE_BUILD_TARGETS?=	@install
DUNE_BUILD_PACKAGES?=	# empty

# Default value of OASIS_BUILD_ARGS
OASIS_BUILD_ARGS?=	# empty

# Default value of OCAML_USE_OPT_COMPILER
.if (${MACHINE_ARCH} == "i386") || (${MACHINE_ARCH} == "powerpc") || \
    !empty(MACHINE_ARCH:M*arm*) || (${MACHINE_ARCH} == "aarch64") || \
    (${MACHINE_ARCH} == "aarch64eb") || (${MACHINE_ARCH} == "x86_64")
OCAML_USE_OPT_COMPILER?=	yes
.else
OCAML_USE_OPT_COMPILER?=	no
.endif

#
# Configure stuff for OASIS_DYNRUN
#
.if ${OCAML_USE_OASIS_DYNRUN} == "yes"
.include "../../devel/ocaml-oasis/buildlink3.mk"
OCAML_USE_OASIS=	yes
.endif

#
# Configure stuff for OASIS
#
.if ${OCAML_USE_OASIS} == "yes"
OCAML_USE_FINDLIB=	yes
HAS_CONFIGURE=	yes
CONFIGURE_ARGS+=	--destdir "${DESTDIR}"
CONFIGURE_ARGS+=	--prefix "${PREFIX}"
# Force use of native code compiler according to setting
.if ${OCAML_USE_OPT_COMPILER} == "yes"
CONFIGURE_ARGS+=	--override is_native true
.else
CONFIGURE_ARGS+=	--override is_native false
.endif
.endif

# Configure stuff for DUNE
.if ${OCAML_USE_DUNE} == "yes"
.include "../../devel/ocaml-dune/buildlink3.mk"
OCAML_USE_OPAM?=	yes
OPAM_INSTALL_DIR?=	_build/default
.else
OCAML_USE_OPAM?=	no
.endif

# Configure stuff for OPAM
.if ${OCAML_USE_OPAM} == "yes"
.include "../../misc/ocaml-opaline/buildlink3.mk"
OCAML_USE_FINDLIB=	yes
.endif

# Configure stuff for TOPKG
.if ${OCAML_USE_TOPKG} == "yes"
.include "../../misc/ocaml-topkg/buildlink3.mk"
OCAML_USE_FINDLIB=	yes
INSTALLATION_DIRS+=	${OCAML_SITELIBDIR}/${OCAML_TOPKG_NAME}
.endif

# Fallback value for OPAM_INSTALL_DIR
OPAM_INSTALL_DIR?=	.

# Value for OCAML_SITELIBDIR
OCAML_SITELIBDIR=	lib/ocaml/site-lib
MAKE_ENV+=	OCAML_SITELIBDIR="${OCAML_SITELIBDIR}"
PLIST_SUBST+=	OCAML_SITELIB="${OCAML_SITELIBDIR}"

PRINT_PLIST_AWK+=	{ gsub(/^.+\.cmx/, "$${PLIST.ocaml-opt}&") }
PRINT_PLIST_AWK+=	{ gsub(/^.+\.a$$/, "$${PLIST.ocaml-opt}&") }
PRINT_PLIST_AWK+=	{ gsub(/${OCAML_SITELIBDIR:S|/|\\/|g}/, \
			"$${OCAML_SITELIB}"); \
			print; next; }

.if ${OCAML_USE_FINDLIB} == "yes"
.include "../../devel/ocaml-findlib/buildlink3.mk"
INSTALLATION_DIRS+=	${OCAML_SITELIBDIR}
OCAML_FINDLIB_DIRS?=	${PKGBASE:S/^ocaml-//}
OCAML_FINDLIB_REGISTER?=	yes
.endif

#
# Compiler stuff
#

# Things that get installed with the opt compiler
PLIST_VARS+=	ocaml-opt

.if ${OCAML_USE_OPT_COMPILER} == "yes"
# The opt compiler needs the C compiler suite
USE_LANGUAGES+=	c
PLIST.ocaml-opt=	yes
.else
# If we're bytecode compiling, don't strip executables
INSTALL_UNSTRIPPED=	yes
.endif

#
# OASIS targets
#
.if ${OCAML_USE_OASIS} == "yes"
# OASIS uses ocamlbuild
.include "../../devel/ocamlbuild/buildlink3.mk"
.if ${OCAML_USE_OASIS_DYNRUN} == "yes"
pre-configure:
	${RUN} cd ${WRKSRC} && ocamlfind ocamlc -linkpkg -package oasis.dynrun -o setup setup.ml && ${RM} setup.cmo setup.cmi

OASIS_EXEC=./setup
.else
OASIS_EXEC=ocaml setup.ml
.endif

# Redefine configure target
do-configure:
	${RUN} cd ${WRKSRC} && \
		${SETENV} ${CONFIGURE_ENV} ${OASIS_EXEC} -configure ${CONFIGURE_ARGS}

# Redefine build target
do-build:
	${RUN} ${_ULIMIT_CMD} cd ${WRKSRC} && \
		${SETENV} ${MAKE_ENV} ${OASIS_EXEC} -build ${OASIS_BUILD_ARGS}

# Redefine install target
do-install:
	${RUN} cd ${WRKSRC} && \
		${OASIS_EXEC} -install --destdir ${DESTDIR} --prefix ${PREFIX}
.endif

#
# topkg targets
#
.if ${OCAML_USE_TOPKG} == "yes"

do-build:
	${RUN} ${_ULIMIT_CMD} cd ${WRKSRC} && \
		${SETENV} ${MAKE_ENV} ocaml pkg/pkg.ml build ${OCAML_TOPKG_FLAGS}

.endif # topkg

#
# opam targets
#
.if ${OCAML_USE_OPAM} == "yes" 

do-install:
	${RUN} for i in ${OPAM_INSTALL_FILES}; do \
		cd ${WRKSRC} && opaline -install-cmd "${INSTALL_DATA}" \
		-exec-install-cmd "${INSTALL_PROGRAM}" \
		-name $$i \
		-destdir ${DESTDIR} \
		-prefix ${PREFIX} \
		-libdir ${PREFIX}/${OCAML_SITELIBDIR} \
		-docdir ${OCAML_TOPKG_DOCDIR}/$$i \
		-stublibsdir ${PREFIX}/${OCAML_SITELIBDIR}/stublibs \
		-bindir ${PREFIX}/bin \
		${OPAM_INSTALL_DIR}/$$i.install; \
	done

.endif # opam

#
# dune targets
#
.if ${OCAML_USE_DUNE} == "yes"

do-build:
.if !empty(DUNE_BUILD_PACKAGES)
	${RUN} ${_ULIMIT_CMD} \
		cd ${WRKSRC} && ${SETENV} ${MAKE_ENV} \
		dune build -j ${MAKE_JOBS:U1} \
		${DUNE_BUILD_FLAGS} -p ${DUNE_BUILD_PACKAGES:ts,} \
		${DUNE_BUILD_TARGETS}
.else
	${RUN} ${_ULIMIT_CMD} \
		cd ${WRKSRC} && dune build --profile release -j ${MAKE_JOBS:U1} \
		${DUNE_BUILD_FLAGS} ${DUNE_BUILD_TARGETS}
.endif

.endif # dune

# Add dependency on ocaml.
.include "../../lang/ocaml/buildlink3.mk"

.endif # OCAML_MK