blob: 5e346d6e80bc721d5a309cabb7b91126366fe117 (
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
|
# @ECLASS: dmd.eclass
# @MAINTAINER: marco.leise@gmx.de
# @BLURB: Captures most of the logic for installing DMD
# @DESCRIPTION:
# Helps with the maintenance of the various DMD versions by capturing common
# logic.
if [[ ${___ECLASS_ONCE_DMD} != "recur -_+^+_- spank" ]] ; then
___ECLASS_ONCE_DMD="recur -_+^+_- spank"
if has ${EAPI:-0} 0 1 2 3 4 5; then
die "EAPI must be >= 6 for dmd packages."
fi
DESCRIPTION="Reference compiler for the D programming language"
HOMEPAGE="http://dlang.org/"
HTML_DOCS="html/*"
# DMD supports amd64/x86 exclusively
MULTILIB_COMPAT=( abi_x86_{32,64} )
inherit multilib-build eapi7-ver toolchain-funcs
dmd_eq() {
[[ ${MAJOR} -eq ${1%.*} ]] && [[ ${MINOR} -eq $((10#${1#*.})) ]]
}
dmd_ge() {
[[ ${MAJOR} -ge ${1%.*} ]] && [[ ${MINOR} -ge $((10#${1#*.})) ]]
}
dmd_gen_exe_dir() {
if dmd_ge 2.074; then
echo dmd/generated/linux/release/$(dmd_arch_to_model)
else
echo dmd/src
fi
}
# For reliable download statistics, we don't mirror.
RESTRICT="mirror"
LICENSE="Boost-1.0"
SLOT="$(ver_cut 1-2)"
MAJOR="$(ver_cut 1)"
MINOR="$((10#$(ver_cut 2)))"
PATCH="$(ver_cut 3)"
VERSION="$(ver_cut 1-3)"
BETA="$(ver_cut 4)"
if [ "${KERNEL}" != "FreeBSD" ]; then
ARCHIVE="${ARCHIVE-linux.tar.xz}"
elif [ "${ARCH}" == "x86" ]; then
ARCHIVE="${ARCHIVE-freebsd-32.tar.xz}"
else
ARCHIVE="${ARCHIVE-freebsd-64.tar.xz}"
fi
SONAME="${SONAME-libphobos2.so.0.${MINOR}.${PATCH}}"
SONAME_SYM="${SONAME%.*}"
IUSE="doc examples static-libs tools"
# Self-hosting versions of DMD need a host compiler.
if dmd_ge 2.068; then
DLANG_VERSION_RANGE="${DLANG_VERSION_RANGE-${SLOT}}"
DLANG_PACKAGE_TYPE=dmd
inherit dlang
fi
# Call EXPORT_FUNCTIONS after any imports
EXPORT_FUNCTIONS src_prepare src_compile src_test src_install pkg_postinst pkg_postrm
if [[ -n "${BETA}" ]]; then
SRC_URI="http://downloads.dlang.org/pre-releases/${MAJOR}.x/${VERSION}/${PN}.${VERSION}-b${BETA:4}.${ARCHIVE}"
else
SRC_URI="mirror://aws/${YEAR}/${PN}.${PV}.${ARCHIVE}"
fi
COMMON_DEPEND="
net-misc/curl[${MULTILIB_USEDEP}]
>=app-eselect/eselect-dlang-20140709
"
DEPEND="
${COMMON_DEPEND}
app-arch/unzip
"
RDEPEND="
${COMMON_DEPEND}
!dev-lang/dmd-bin
"
PDEPEND="tools? ( >=dev-util/dlang-tools-${PV} )"
S="${WORKDIR}/dmd2"
PREFIX="usr/lib/${PN}/${SLOT}"
IMPORT_DIR="/${PREFIX}/import"
dmd_src_prepare() {
# Reorganize directories
mkdir dmd || die "Failed to create directories 'dmd', 'druntime' and 'phobos'"
mv src/dmd dmd/src || die "Failed to move 'src/dmd' to 'dmd/src'"
mv src/VERSION dmd/VERSION || die "Failed to move 'src/VERSION' to 'dmd/VERSION'"
mv src/druntime druntime || die "Failed to move 'src/druntime' to 'druntime'"
mv src/phobos phobos || die "Failed to move 'src/phobos' to 'phobos'"
# Symlinks used by dmd in the selfhosting case
ln -s ../druntime src/druntime || die "Failed to symlink 'druntime' to 'src/druntime'"
ln -s ../phobos src/phobos || die "Failed to symlink 'phobos' to 'src/phobos'"
# Convert line-endings of file-types that start as cr-lf and are installed later on
for file in $( find . -name "*.txt" -o -name "*.html" -o -name "*.d" -o -name "*.di" -o -name "*.ddoc" -type f ); do
edos2unix $file || die "Failed to convert DOS line-endings to Unix."
done
# Ebuild patches
default
# Run other preparations
declare -f dmd_src_prepare_extra > /dev/null && dmd_src_prepare_extra
# User patches
eapply_user
}
dmd_src_compile() {
# A native build of dmd is used to compile the runtimes for both x86 and amd64
# We cannot use multilib-minimal yet, as we have to be sure dmd for amd64
# always gets build first.
einfo "Building dmd..."
# 2.068 used HOST_DC instead of HOST_DMD
dmd_eq 2.068 && HOST_DMD="HOST_DC" || HOST_DMD="HOST_DMD"
# 2.070 and below used HOST_CC instead of HOST_CXX
dmd_ge 2.071 && HOST_CXX="HOST_CXX" || HOST_CXX="HOST_CC"
# 2.072 and 2.073 have support for LTO, but would need a Makefile patch.
# From 2.088 on, the build fails with it active.
dmd_ge 2.074 && ! dmd_eq 2.088 && ! dmd_eq 2.089 && ! dmd_eq 2.090 && ! dmd_eq 2.091 && ! dmd_eq 2.092 && LTO="ENABLE_LTO=1"
# 2.080 and below used RELEASE instead of ENABLE_RELEASE
dmd_ge 2.081 && ENABLE_RELEASE="ENABLE_RELEASE" || ENABLE_RELEASE="RELEASE"
# Special case for self-hosting (i.e. no compiler USE flag selected).
local kernel model
if [ "${DC_VERSION}" == "selfhost" ]; then
case "${KERNEL}" in
"linux") kernel="linux";;
"FreeBSD") kernel="freebsd";;
*) die "Self-hosting dmd on ${KERNEL} is not currently supported."
esac
case "${ARCH}" in
"x86") model=32;;
"amd64") model=64;;
*) die "Self-hosting dmd on ${ARCH} is not currently supported."
esac
export DMD="../../${kernel}/bin${model}/dmd"
fi
emake -C dmd/src -f posix.mak TARGET_CPU=X86 ${HOST_DMD}="${DMD}" ${HOST_CXX}="$(tc-getCXX)" ${ENABLE_RELEASE}=1 ${LTO}
# Don't pick up /etc/dmd.conf when calling $(dmd_gen_exe_dir)/dmd !
if [ ! -f "$(dmd_gen_exe_dir)/dmd.conf" ]; then
einfo "Creating a dummy dmd.conf"
touch "$(dmd_gen_exe_dir)/dmd.conf" || die "Could not create dummy dmd.conf"
fi
compile_libraries() {
einfo 'Building druntime...'
emake -C druntime -f posix.mak DMD="../$(dmd_gen_exe_dir)/dmd" MODEL=${MODEL} PIC=1 MANIFEST=
einfo 'Building Phobos 2...'
emake -C phobos -f posix.mak DMD="../$(dmd_gen_exe_dir)/dmd" MODEL=${MODEL} PIC=1 CUSTOM_DRUNTIME=1
}
dmd_foreach_abi compile_libraries
# Not needed after compilation. Would otherwise be installed as imports.
rm -r phobos/etc/c/zlib
}
dmd_src_test() {
test_hello_world() {
"$(dmd_gen_exe_dir)/dmd" -m${MODEL} -fPIC -Iphobos -Idruntime/import -L-Lphobos/generated/linux/release/${MODEL} samples/d/hello.d || die "Failed to build hello.d (${MODEL}-bit)"
./hello ${MODEL}-bit || die "Failed to run test sample (${MODEL}-bit)"
rm hello.o hello || die "Could not remove temporary files"
}
dmd_foreach_abi test_hello_world
}
dmd_src_install() {
local MODEL=$(dmd_abi_to_model)
# dmd.conf
if has_multilib_profile; then
cat > linux/bin${MODEL}/dmd.conf << EOF
[Environment]
DFLAGS=-I${IMPORT_DIR} -L--export-dynamic -defaultlib=phobos2 -fPIC
[Environment32]
DFLAGS=%DFLAGS% -L-L/${PREFIX}/lib32 -L-rpath=/${PREFIX}/lib32
[Environment64]
DFLAGS=%DFLAGS% -L-L/${PREFIX}/lib64 -L-rpath=/${PREFIX}/lib64
EOF
elif [ "${ABI:0:5}" = "amd64" ]; then
cat > linux/bin${MODEL}/dmd.conf << EOF
[Environment]
DFLAGS=-I${IMPORT_DIR} -L--export-dynamic -defaultlib=phobos2 -fPIC -L-L/${PREFIX}/lib64 -L-rpath=/${PREFIX}/lib64
EOF
else
cat > linux/bin${MODEL}/dmd.conf << EOF
[Environment]
DFLAGS=-I${IMPORT_DIR} -L--export-dynamic -defaultlib=phobos2 -fPIC -L-L/${PREFIX}/lib -L-rpath=/${PREFIX}/lib
EOF
fi
insinto "etc/dmd"
newins "linux/bin${MODEL}/dmd.conf" "${SLOT}.conf"
dosym "../../../../../etc/dmd/${SLOT}.conf" "${PREFIX}/bin/dmd.conf"
# DMD
einfo "Installing ${PN}..."
# From version 2.066 on, dmd will find dmd.conf in the executable directory, if we
# call it through a symlink in /usr/bin
dmd_ge 2.066 && dosym "../../${PREFIX}/bin/dmd" "${ROOT}/usr/bin/dmd-${SLOT}"
into ${PREFIX}
dobin "$(dmd_gen_exe_dir)/dmd"
# druntime
einfo 'Installing druntime...'
insinto ${PREFIX}
doins -r druntime/import
# Phobos 2
einfo 'Installing Phobos 2...'
into usr
install_phobos_2() {
# Copied get_libdir logic from dlang.eclass, so we can install Phobos correctly.
if has_multilib_profile || [[ "${MODEL}" == "64" ]]; then
local libdir="../${PREFIX}/lib${MODEL}"
else
local libdir="../${PREFIX}/lib"
fi
# Install shared lib.
dolib.so phobos/generated/linux/release/${MODEL}/"${SONAME}"
dosym "${SONAME}" /usr/"$(get_libdir)"/"${SONAME_SYM}"
dosym ../../../../../usr/"$(get_libdir)"/"${SONAME}" /usr/"${libdir}"/libphobos2.so
# Install static lib if requested.
if use static-libs; then
if has_multilib_profile || [[ "${MODEL}" == "64" ]]; then
export LIBDIR_${ABI}="../${PREFIX}/lib${MODEL}"
else
export LIBDIR_${ABI}="../${PREFIX}/lib"
fi
dolib.a phobos/generated/linux/release/${MODEL}/libphobos2.a
fi
}
dmd_foreach_abi install_phobos_2
insinto ${PREFIX}/import
doins -r phobos/{etc,std}
# man pages, docs and samples
insinto ${PREFIX}/man/man1
doins man/man1/dmd.1
insinto ${PREFIX}/man/man5
doins man/man5/dmd.conf.5
if use doc; then
einstalldocs
insinto "/usr/share/doc/${PF}/html"
doins "${FILESDIR}/dmd-doc.png"
make_desktop_entry "xdg-open ${ROOT}usr/share/doc/${PF}/html/d/index.html" "DMD ${PV}" "${ROOT}usr/share/doc/${PF}/html/dmd-doc.png" "Development"
fi
if use examples; then
insinto ${PREFIX}/samples
doins -r samples/d/*
docompress -x ${PREFIX}/samples/
fi
}
dmd_pkg_postinst() {
# Update active dmd
"${ROOT}"/usr/bin/eselect dlang update dmd
use examples && elog "Examples can be found in: /${PREFIX}/samples"
use doc && elog "HTML documentation is in: /usr/share/doc/${PF}/html"
}
dmd_pkg_postrm() {
"${ROOT}"/usr/bin/eselect dlang update dmd
}
dmd_foreach_abi() {
for ABI in $(multilib_get_enabled_abis); do
local MODEL=$(dmd_abi_to_model)
einfo " Executing ${1} in ${MODEL}-bit ..."
"${@}"
done
}
dmd_arch_to_model() {
[[ "${ARCH}" == "amd64" ]] && echo 64 || echo 32
}
dmd_abi_to_model() {
[[ "${ABI:0:5}" == "amd64" ]] && echo 64 || echo 32
}
fi
|