summaryrefslogtreecommitdiff
blob: 29d3f055a11964feef98e0e7d0c1b240e46c1f0e (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit multilib toolchain-funcs vcs-clean

PATCHSET_VER="0"
MY_P=mercury-srcdist-${PV}

DESCRIPTION="Additional libraries and tools that are not part of the Mercury standard library"
HOMEPAGE="https://www.mercurylang.org/index.html"
SRC_URI="https://dl.mercurylang.org/release/${MY_P}.tar.gz
	https://dev.gentoo.org/~keri/distfiles/mercury-extras/${P}-gentoo-patchset-${PATCHSET_VER}.tar.gz"

LICENSE="GPL-2 LGPL-2"
SLOT="0"
KEYWORDS="amd64 x86"

IUSE="cairo examples glut gmp iodbc ncurses odbc opengl ssl tk tommath X xml"
REQUIRED_USE="?? ( odbc iodbc )"

RDEPEND="
	~dev-lang/mercury-${PV}
	cairo? ( >=x11-libs/cairo-1.10.0 )
	gmp? ( dev-libs/gmp:0 )
	glut? ( media-libs/freeglut )
	odbc? ( dev-db/unixODBC )
	iodbc? ( dev-db/libiodbc )
	tommath? ( dev-libs/libtommath )
	ncurses? ( sys-libs/ncurses:= )
	opengl? (
		virtual/opengl
		virtual/glu
	)
	tk? (
		dev-lang/tcl:0
		dev-lang/tk:0
	)
	X? ( x11-libs/libX11 )"

DEPEND="${RDEPEND}"

BDEPEND="virtual/pkgconfig"

S="${WORKDIR}"/${MY_P}/extras

mercury_pkgs() {
	echo "
		align_right/align_right:bin:
		base64/mercury_base64:lib:
		cgi/mercury_www:lib:
		complex_numbers/complex_numbers:lib:
		$(use ncurses && echo \
			curs/curs:lib:ncurses,panel curses/mcurses:lib:ncurses)
		dynamic_linking/dl:lib:
		error/error:bin:
		fixed/fixed:lib:
		$(use gmp && echo gmp_int/gmp_int:lib:)
		$(use tommath && echo mp_int/mp_int:lib:libtommath)
		$(use X && echo graphics/easyx/easyx:lib:x11)
		$(use cairo && echo graphics/mercury_cairo/mercury_cairo:lib:cairo)
		$(use glut && echo graphics/mercury_glut/mercury_glut:lib:freeglut)
		$(use opengl && echo graphics/mercury_opengl/mercury_opengl:lib:gl,glu)
		$(use tk && echo graphics/mercury_tcltk/mercury_tcltk:lib:tk)
		lex/lex:lib:
		lex/regex:lib:
		moose/moose:bin:
		net/net:lib:
		net/echo:bin:
		$(use ssl && echo mopenssl/mopenssl:lib:openssl)
		$(use odbc && echo odbc/odbc:lib:odbc)
		$(use iodbc && echo odbc/odbc:lib:libiodbc)
		posix/posix:lib:
		$(has_version dev-lang/mercury[trail] && echo \
			references/global:lib:)
		show_ops/show_ops:bin:
		solver_types/library/any:lib:
		$(use xml && echo xml/xml:lib:)"
}

mercury_pkg_setup() {
	mercury_pkg=${1%%:*}
	mercury_pkg_dir=${mercury_pkg%/*}
	mercury_pkg_name=${mercury_pkg##*/}

	mercury_pkg_atts=${1#*:}
	mercury_pkg_type=${mercury_pkg_atts%%:*}
	mercury_pkg_deps=${mercury_pkg_atts#*:}

	cd "${S}"/${mercury_pkg_dir} || die

	echo ">> Preparing Mercury package: ${mercury_pkg}"

	echo "MCFLAGS += --libgrades-exclude java" \
		>> "${S}"/${mercury_pkg_dir}/Mercury.options
	echo "MCFLAGS += --libgrades-exclude erlang" \
		>> "${S}"/${mercury_pkg_dir}/Mercury.options
	echo "MCFLAGS += --libgrades-exclude csharp" \
		>> "${S}"/${mercury_pkg_dir}/Mercury.options

	if test -n "$mercury_pkg_deps"; then
		echo "EXTRA_CFLAGS += $($(tc-getPKG_CONFIG) --cflags ${mercury_pkg_deps/,/ })" \
			>> "${S}"/${mercury_pkg_dir}/Mercury.options
		echo "EXTRA_LDFLAGS += $($(tc-getPKG_CONFIG) --libs ${mercury_pkg_deps/,/ })" \
			>> "${S}"/${mercury_pkg_dir}/Mercury.options
	fi

	if test ${mercury_pkg_name} = dl; then
		echo "EXTRA_LDFLAGS += -ldl" >> "${S}"/${mercury_pkg_dir}/Mercury.options
	elif test ${mercury_pkg_name} = gmp_int; then
		echo "EXTRA_LDFLAGS += -lgmp" >> "${S}"/${mercury_pkg_dir}/Mercury.options
	elif test ${mercury_pkg_name} = mercury_tcltk; then
		echo "EXTRA_CFLAGS += -DUSE_INTERP_RESULT" \
			>> "${S}"/${mercury_pkg_dir}/Mercury.options
	elif test ${mercury_pkg_name} = odbc && use odbc; then
		echo "EXTRA_CFLAGS += -DMODBC_UNIX -DMODBC_MYSQL" \
			>> "${S}"/${mercury_pkg_dir}/Mercury.options
	elif test ${mercury_pkg_name} = odbc && use iodbc; then
		echo "EXTRA_CFLAGS += -DMODBC_IODBC -DMODBC_MYSQL" \
			>> "${S}"/${mercury_pkg_dir}/Mercury.options
	fi
}

mercury_pkg_compile() {
	mercury_pkg=${1%%:*}
	mercury_pkg_dir=${mercury_pkg%/*}
	mercury_pkg_name=${mercury_pkg##*/}

	mercury_pkg_atts=${1#*:}
	mercury_pkg_type=${mercury_pkg_atts%:*}

	cd "${S}"/${mercury_pkg_dir} || die

	echo ">> Compiling Mercury package: ${mercury_pkg}"

	if test "${mercury_pkg_type}" = "bin"; then
		mercury_mmc_target=${mercury_pkg_name}
	else
		mercury_mmc_target=lib${mercury_pkg_name}
	fi

	mmc -f *.m || die "mmc -f .m failed"

	mmc \
		--make \
		--verbose-commands \
		--no-strip \
		--cflags "${CFLAGS}" \
		--ld-flags "${LDFLAGS}" \
		--ld-libflags "${LDFLAGS}" \
		${mercury_mmc_target} || die "mmc ${mercury_mmc_target} failed"
}

mercury_pkg_install() {
	mercury_pkg=${1%%:*}
	mercury_pkg_dir=${mercury_pkg%/*}
	mercury_pkg_name=${mercury_pkg##*/}

	mercury_pkg_atts=${1#*:}
	mercury_pkg_type=${mercury_pkg_atts%:*}

	cd "${S}"/${mercury_pkg_dir} || die

	echo ">> Installing Mercury package: ${mercury_pkg}"

	if test "${mercury_pkg_type}" = "bin"; then
		into /usr/$(get_libdir)/mercury/extras
		dobin ${mercury_pkg_name}
	else
		mmc \
			--make \
			--verbose-commands \
			--no-strip \
			--cflags "${CFLAGS}" \
			--ld-flags "${LDFLAGS}" \
			--ld-libflags "${LDFLAGS}" \
			--install-prefix "${D}/usr/$(get_libdir)/mercury/extras" \
			lib${mercury_pkg_name}.install || die "mmc lib${mercury_pkg_name}.install failed"
	fi
}

src_prepare() {
	cd "${WORKDIR}"/${MY_P}
	if [[ -d "${WORKDIR}"/${PV} ]] ; then
		eapply "${WORKDIR}"/${PV}
	fi
	eapply_user

	cd "${S}"
	for mercury_pkg in $(mercury_pkgs); do
		mercury_pkg_setup ${mercury_pkg}
	done

	cp "${S}"/net/*.m "${S}"/mopenssl/ || die
}

src_compile() {
	for mercury_pkg in $(mercury_pkgs); do
		mercury_pkg_compile ${mercury_pkg}
	done
}

src_install() {
	for mercury_pkg in $(mercury_pkgs); do
		mercury_pkg_install ${mercury_pkg}
	done

	cd "${S}"
	dodoc README

	if use examples; then
		docinto samples/cgi
		dodoc cgi/form_test.m

		docinto samples/complex_numbers
		dodoc complex_numbers/samples/*.m

		if use ncurses; then
			docinto samples/curs
			dodoc curs/samples/*.m

			docinto samples/curses
			dodoc curses/sample/*.m
		fi

		docinto samples/dynamic_linking
		dodoc dynamic_linking/{hello,dl_test}.m

		docinto samples/gator
		dodoc -r gator/*

		if use gmp; then
			docinto samples/gmp_int
			dodoc gmp_int/gmp_int_test.m
		fi

		if use tommath; then
			docinto samples/mp_int
			dodoc mp_int/mp_int_test.m
		fi

		if use X; then
			docinto samples/graphics
			dodoc graphics/easyx/samples/*.m
		fi

		if use glut && use opengl; then
			docinto samples/graphics
			dodoc graphics/samples/gears/*.m
			dodoc graphics/samples/maze/*.m
		fi

		if use tk; then
			docinto samples/graphics
			dodoc graphics/samples/calc/*.m
		fi

		if use opengl && use tk; then
			docinto samples/graphics
			dodoc graphics/samples/pent/*.m
		fi

		docinto samples/lex
		dodoc lex/samples/*.m

		docinto samples/log4m
		dodoc log4m/*.m

		docinto samples/monte
		dodoc monte/*.m

		docinto samples/moose
		dodoc moose/samples/*

		docinto samples/net
		dodoc net/test_lookups.m

		if use odbc || use iodbc; then
			docinto samples/odbc
			dodoc odbc/odbc_test.m
		fi

		docinto samples/posix
		dodoc posix/samples/*.m

		docinto samples/random
		dodoc random/*.m

		if has_version dev-lang/mercury[trail]; then
			docinto samples/references
			dodoc references/samples/*.m

			docinto samples/trail
			dodoc trail/*.m
		fi

		if use xml; then
			docinto samples/xml
			dodoc xml/tryit.m
			dodoc xml/samples/*
			dodoc xml_stylesheets/*.xsl
		fi

		ecvs_clean
	fi
}