summaryrefslogtreecommitdiff
path: root/eclass/gcc-java.eclass
blob: 55b9dca6bcb39c95968ba6d5226b3561a2c908ce (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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# Copyright 1999-2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Header: $

ECLASS=gcc-java

ETYPE="gcc-compiler"
GCC_LANG="java"

# get the version parsing functions.
inherit versionator gnuconfig libtool

EXPORT_FUNCTIONS src_unpack src_compile src_test src_install

gcc-java_src_unpack() {
	gcj_src_unpack
}
gcc-java_src_compile() {
	gcj_src_compile
}
gcc-java_src_test() {
	gcj_src_test
}
gcc-java_src_install() {
	gcj_src_install
}

IUSE="nogtk cairo"

RDEPEND="virtual/libc
	>=sys-libs/zlib-1.1.4
	!nogtk? ( >=x11-libs/gtk+-2.8
		cairo? ( >=x11-libs/cairo-1.0.2 ) )
	>=media-libs/libart_lgpl-2.1
	>=sys-libs/ncurses-5.2-r2
	nls? ( sys-devel/gettext )"

DEPEND="${RDEPEND}
	>=sys-apps/texinfo-4.2-r4
	>=sys-devel/bison-1.875
	>=sys-devel/binutils-2.16.1"

export CTARGET=${CTARGET:-${CHOST}}
if [[ ${CTARGET} = ${CHOST} ]] ; then
	if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
		export CTARGET=${CATEGORY/cross-}
	fi
fi

GCC_RELEASE_VER=$(get_version_component_range 1-3)
GCC_BRANCH_VER=$(get_version_component_range 1-2)
GCCMAJOR=$(get_version_component_range 1)
GCCMINOR=$(get_version_component_range 2)
GCCMICRO=$(get_version_component_range 3)
[[ ${BRANCH_UPDATE:-notset} == "notset" ]] && BRANCH_UPDATE=$(get_version_component_range 4)

# According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
# ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
GCC_CONFIG_VER=${GCC_CONFIG_VER:-"$(replace_version_separator 3 '-')"}

# Pre-release support
if [[ ${PV} != ${PV/_pre/-} ]] ; then
	PRERELEASE=${PV/_pre/-}
fi
# make _alpha and _beta ebuilds automatically use a snapshot
if [[ ${PV} != ${PV/_alpha/} ]] ; then
	SNAPSHOT=${GCC_BRANCH_VER}-${PV##*_alpha}
elif [[ ${PV} != ${PV/_beta/} ]] ; then
	SNAPSHOT=${GCC_BRANCH_VER}-${PV##*_beta}
fi
export GCC_FILESDIR=${GCC_FILESDIR:-${FILESDIR}}

GCC_VAR_TYPE=${GCC_VAR_TYPE:-versioned}
GCC_LIB_COMPAT_ONLY="false"
GCC_TARGET_NO_MULTILIB=${GCC_TARGET_NO_MULTILIB:-false}

#---->> S + SRC_URI essentials <<----

# This function sets the source directory depending on whether we're using
# a prerelease, snapshot, or release tarball. To use it, just set S with:
#
#	S="$(gcc_get_s_dir)"

gcc_get_s_dir() {
	if [[ -n ${PRERELEASE} ]] ; then
		GCC_S=${WORKDIR}/gcc-${PRERELEASE}
	elif [[ -n ${SNAPSHOT} ]] ; then
		GCC_S=${WORKDIR}/gcc-${SNAPSHOT}
	else
		GCC_S=${WORKDIR}/gcc-${GCC_RELEASE_VER}
	fi

	echo "${GCC_S}"
}

# This function handles the basics of setting the SRC_URI for a gcc ebuild.
# To use, set SRC_URI with:
#
#	SRC_URI="$(get_gcc_src_uri)"
#
# Other than the variables normally set by portage, this function's behavior
# can be altered by setting the following:
#
#	SNAPSHOT
#			If set, this variable signals that we should be using a snapshot
#			of gcc from ftp://sources.redhat.com/pub/gcc/snapshots/. It is
#			expected to be in the format "YYYY-MM-DD". Note that if the ebuild
#			has a _pre suffix, this variable is ignored and the prerelease
#			tarball is used instead.
#
#	BRANCH_UPDATE
#			If set, this variable signals that we should be using the main
#			release tarball (determined by ebuild version) and applying a
#			CVS branch update patch against it. The location of this branch
#			update patch is assumed to be in ${GENTOO_TOOLCHAIN_BASE_URI}.
#			Just like with SNAPSHOT, this variable is ignored if the ebuild
#			has a _pre suffix.
#
#	PATCH_VER
#	PATCH_GCC_VER
#			This should be set to the version of the gentoo patch tarball.
#			The resulting filename of this tarball will be:
#			gcc-${PATCH_GCC_VER:-${GCC_RELEASE_VER}}-patches-${PATCH_VER}.tar.bz2

gentoo_urls() {
	local devspace="HTTP~lv/GCC/URI HTTP~eradicator/gcc/URI HTTP~vapier/dist/URI
	HTTP~halcy0n/patches/URI"
	devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/}
	echo mirror://gentoo/$1 ${devspace//URI/$1}
}

get_gcc_src_uri() {
	export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}

	# Set where to download gcc itself depending on whether we're using a
	# prerelease, snapshot, or release tarball.
	if [[ -n ${PRERELEASE} ]] ; then
		GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
	elif [[ -n ${SNAPSHOT} ]] ; then
		GCC_SRC_URI="ftp://sources.redhat.com/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
	else
		GCC_SRC_URI="mirror://gnu/gcc/gcc-${PV}/gcc-${GCC_RELEASE_VER}.tar.bz2"
		# we want all branch updates to be against the main release
		[[ -n ${BRANCH_UPDATE} ]] && \
			GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)"
	fi

	# various gentoo patches
	[[ -n ${PATCH_VER} ]] && \
		GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)"

	echo "${GCC_SRC_URI}"
}

S=$(gcc_get_s_dir)
SRC_URI=$(get_gcc_src_uri)

#create_vanilla_specs_file() {
#	pushd ${WORKDIR}/build/gcc > /dev/null
#	einfo "Creating a vanilla gcc specs file"
#	./xgcc -dumpspecs > ${WORKDIR}/build/vanilla.specs
#	popd > /dev/null
#}

#guess_patch_type_in_dir() {
#	[[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] \
#		&& EPATCH_SUFFIX="patch.bz2" \
#		|| EPATCH_SUFFIX="patch"
#}

gcj_src_unpack() {
	local release_version="Gentoo ${PVR}"

	gcc_quick_unpack

	cd ${S:=$(gcc_get_s_dir)}

	version_string="${version_string} (${release_version})"
	einfo "patching gcc version: ${version_string}"
	gcc_version_patch "${version_string}"

	# Misdesign in libstdc++ (Redhat)
	if [[ ${GCCMAJOR} -ge 3 ]] && [[ -e ${S}/libstdc++-v3/config/cpu/i486/atomicity.h ]] ; then
		cp -pPR "${S}"/libstdc++-v3/config/cpu/i{4,3}86/atomicity.h
	fi

	# Fixup libtool to correctly generate .la files with portage
	cd "${S}"
	elibtoolize --portage --shallow --no-uclibc

	gnuconfig_update

	# update configure files
	einfo "Fixing misc issues in configure files"
	for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
		ebegin "  Updating ${f/${S}\/}"
		patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
			|| die "Please file a bug about this"
		eend $?
	done

	./contrib/gcc_update --touch &> /dev/null

}

gcj_src_test() {
	cd "${WORKDIR}"/build
	make check || ewarn "check failed and that sucks :("
}



# gcc_quick_unpack will unpack the gcc tarball and patches in a way that is
# consistant with the behavior of get_gcc_src_uri. The only patch it applies
# itself is the branch update if present.
#
gcc_quick_unpack() {
	pushd ${WORKDIR} > /dev/null
	export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}

	if [[ -n ${GCC_A_FAKEIT} ]] ; then
		unpack ${GCC_A_FAKEIT}.tar.bz2
		mv ${GCC_A_FAKEIT} "${S}"
	elif [[ -n ${PRERELEASE} ]] ; then
		unpack gcc-${PRERELEASE}.tar.bz2
	elif [[ -n ${SNAPSHOT} ]] ; then
		unpack gcc-${SNAPSHOT}.tar.bz2
	else
		unpack gcc-${GCC_RELEASE_VER}.tar.bz2
		# We want branch updates to be against a release tarball
		if [[ -n ${BRANCH_UPDATE} ]] ; then
			pushd ${S:-"$(gcc_get_s_dir)"} > /dev/null
			epatch ${DISTDIR}/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2
			popd > /dev/null
		fi
	fi

	[[ -n ${PATCH_VER} ]] && \
		unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2

	popd > /dev/null
}


# Try to apply some stub patches so that gcc won't error out when
# passed parameters like -fstack-protector but no ssp is found
do_gcc_stub() {
	local v stub_patch=""
	for v in ${GCC_RELEASE_VER} ${GCC_BRANCH_VER} ; do
		stub_patch=${GCC_FILESDIR}/stubs/gcc-${v}-$1-stub.patch
		if [[ -e ${stub_patch} ]] ; then
			EPATCH_SINGLE_MSG="Applying stub patch for $1 ..." \
			epatch "${stub_patch}"
			return 0
		fi
	done
}

# This function allows us to gentoo-ize gcc's version number and bugzilla
# URL without needing to use patches.
gcc_version_patch() {
	[[ -z $1 ]] && die "no arguments to gcc_version_patch"

	sed -i -e "s~\(const char version_string\[\] = \"\).*\(\".*\)~\1$1\2~" \
	       -e 's~http:\/\/gcc\.gnu\.org\/bugs\.html~http:\/\/bugs\.gentoo\.org\/~' ${S}/gcc/version.c || die "failed to update version.c with Gentoo branding."
}

fix_libtool_libdir_paths() {
	local dirpath
	for archive in $* ; do
		dirpath=$(dirname ${archive} | sed -e "s:^${D}::")
		sed -i ${archive} -e "s:^libdir.*:libdir=\'${dirpath}\':"
	done
}

gcj_src_compile() {
	local conf
	
	# GCC must be built from an alternate (tmp) directory

	mkdir -p ${WORKDIR}/build
	pushd ${WORKDIR}/build >/dev/null

	# global configure defaults from toolchain.eclass
	conf="--with-system-zlib \
			--disable-checking \
			--disable-werror \
			--disable-libunwind-exceptions \
			--enable-nls --without-included-gettext"

	# our build specific configuration
	conf="--prefix=/opt/${PN}-${GCC_BRANCH_VER} \
		--with-languages=c++,java \
		$(use_enable !nogtk java-awt gtk) \
		$(use_enable cairo gtk-cairo) \
		--disable-gtktest \
		--disable-glibtest \
		--disable-libarttest \
		--disable-multilib \
		--disable-maintainer-mode \
		--disable-libada \
		--enable-threads=posix \
		${conf}"

	echo
	einfo "Configuring GCC with: ${conf//--/\n\t--} ${@} ${EXTRA_ECONF}"
	echo


	${S}/configure ${conf} || die "configure failed!"

	make || die "make failed!"

	popd >/dev/null
}

gcj_src_install() {
	einfo "Installing GCJ ..."
	pushd ${WORKDIR}/build >/dev/null

	make DESTDIR="${D}" install || die "install failed!"

	# Punt some tools which are really only useful while building gcc
	#rm -r "${D}${LIBEXECPATH}"/install-tools
	# This one comes with binutils
	find "${D}" -name libiberty.a -exec rm -f {} \;

	# Now do the fun stripping stuff
	env RESTRICT="" STRIP=${CHOST}-strip prepstrip "${D}${BINPATH}" "${D}${LIBEXECPATH}"
	env RESTRICT="" STRIP=${CTARGET}-strip prepstrip "${D}${LIBPATH}"

	# create env file
	mkdir -p "${D}"/etc/env.d/
	sed -e "s:@P@:${PN}-${GCC_BRANCH_VER}:g" \
		< ${FILESDIR}/gcj.env \
		> "${D}"etc/env.d/99gcj \
		|| die "build of env file failed!"

	popd >/dev/null
}