summaryrefslogtreecommitdiff
blob: 258dd6f756ce00a24174852de618a7b2a8f3f3c4 (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
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/dev-util/eclipse-sdk/eclipse-sdk-3.1.ebuild,v 1.3 2005/07/04 21:39:09 karltk Exp $

inherit eutils java-utils

MY_A="eclipse-sourceBuild-srcIncluded-3.1.zip"
DESCRIPTION="Eclipse Tools Platform"
HOMEPAGE="http://www.eclipse.org/"
SRC_URI="http://download.eclipse.org/eclipse/downloads/drops/R-3.1-200506271435/${MY_A}"
IUSE="gnome mozilla firefox nosrc nodoc atk" #gcj
SLOT="3.1"
LICENSE="CPL-1.0"
KEYWORDS="~x86 ~ppc ~amd64"

RDEPEND="
	>=virtual/jdk-1.4.2
	>=x11-libs/gtk+-2.2.4
	mozilla? ( >=www-client/mozilla-1.7 )
	atk? ( >=dev-libs/atk-1.6 )
	firefox? ( >=www-client/mozilla-firefox-1.0.2 )
	gnome? ( =gnome-base/gnome-vfs-2* =gnome-base/libgnomeui-2* )"

#	gcj? ( >=sys-devel/gcc-4.0.0_beta20050305 )

DEPEND="${RDEPEND}
	>=dev-java/ant-1.6.2
	>=sys-apps/findutils-4.1.7
	app-arch/unzip
	app-arch/zip"

# TODO:
# - use CFLAGS from make.conf when building native libraries
#   - must patch eclipse build files
#   - also submit patch to bugs.eclipse
# - intergration to eclipse plugin ebuilds most likely broken
# - remove gcj IUSE because it most propably won't work
# - ppc support not tested, but not explicitly broken either

pkg_setup() {

	einfo "Checking for sufficient physical RAM"
	check-ram
	check-cflags

	java-utils_setup-vm

	java-utils_ensure-vm-version-ge 1 4 2

	# all other gentoo archs match in eclipse build system except amd64
	if [ ${ARCH} == 'amd64' ] ; then
		eclipsearch=x86_64
	else
		eclipsearch=${ARCH}
	fi

	# all other gentoo archs match in sun jdk library patch except x86
	if [ ${ARCH} == 'x86' ] ; then
		jvmarch=i386
	else
		jvmarch=${ARCH}
	fi
}

src_unpack() {

	mkdir ${S}
	cd ${S}
	unpack ${MY_A} || die "Could not unpack ${MY_A}"

	epatch ${FILESDIR}/06-path-fixups.patch

	einfo "Setting up virtual machine"
	java-utils_setup-vm

	einfo "Cleaning out prebuilt code"
	clean-prebuilt-code

	einfo "Patching build"
	process-build

	einfo "Patching makefiles"
	process-makefiles

	einfo "Patching makefiles"
	process-makefiles

	patch_amd64_ibm_jvm
}

src_compile() {

	# karltk: this should be handled by the java-pkg eclass in setup-vm 
	addwrite "/proc/self/maps"
	addwrite "/proc/cpuinfo"
	addwrite "/dev/random"

	# Figure out VM, set up ant classpath and native library paths
	setup-jvm-opts

	${use_gtk} && use mozilla && setup-mozilla-opts

	einfo "Compiling eclipse -- see compilelog.txt for details"
	./build \
		-os linux \
		-arch ${eclipsearch} \
		-ws gtk -compilelibs \
		-bc "${bootclasspath}" \
		|| die "Failed to compile eclipse code (gtk+)"

	# The only mystery still to be solved: why the eclipe binary does not
	# end up in result tar.gz
	# rename the eclipse launcher to stay compatible with previous ebuilds
	mv launchertmp/eclipse eclipse-gtk

	einfo "Creating .desktop entry"
	create-desktop-entry
}

src_install() {

	eclipse_dir="/usr/lib/eclipse-${SLOT}"

	dodir /usr/lib

	einfo "Installing features and plugins"

	[ -f result/linux-gtk-${eclipsearch}-sdk.tar.gz ] || die "tar.gz bundle was not built properly!"
	tar zxf result/linux-gtk-${eclipsearch}-sdk.tar.gz -C ${D}/usr/lib || die "Failed to extract the built package"


	mv ${D}/usr/lib/eclipse ${D}/${eclipse_dir}

	insinto ${eclipse_dir}

	# Install launchers and native code
	exeinto ${eclipse_dir}

	einfo "Installing eclipse-gtk binary"
	doexe eclipse-gtk || die "Failed to install eclipse binary"

	if use nosrc ; then
		einfo "Stripping away source code"
		strip-src
	fi

	if use nodoc ; then
		einfo "Stripping away documentation"
		strip-docs
	fi

	# Install startup script
	exeinto /usr/bin
	doexe ${FILESDIR}/eclipse-${SLOT}

	install-desktop-entry

	doman ${FILESDIR}/eclipse.1

	install-link-files
}

# -----------------------------------------------------------------------------
#  Helper functions
# -----------------------------------------------------------------------------

function setup-mozilla-opts()
{
	mozilla_dir="--mozdir-unset---"

	if [ -f ${ROOT}/usr/lib/MozillaFirefox/libgtkembedmoz.so ] ; then
		einfo "Compiling against www-client/mozilla-firefox"
		mozilla_dir=/usr/lib/MozillaFirefox
	elif [ -f ${ROOT}/usr/lib/mozilla/libgtkembedmoz.so ] ; then
		einfo "Compiling against www-client/mozilla"
		mozilla_dir=/usr/lib/mozilla
	else
		eerror "You have enabled the embedded mozilla component, but no suitable"
		eerror "provider was found. You need Mozilla or Firefox compiled against"
		eerror "gtk+ v2.0 or newer."
		eerror "To merge it, execute 'USE=\"gtk2\" emerge mozilla' as root."
		eerror "To disable embedded mozilla, remove \"mozilla\" from your USE flags."
		die "Need Mozilla compiled with gtk+-2.x support"
	fi

	export GECKO_SDK="${mozilla_dir}"
	export GECKO_INCLUDES="-include ${GECKO_SDK}/include/mozilla-config.h \
		-I${GECKO_SDK}/include/nspr \
		-I${GECKO_SDK}/include/nspr \
		-I${GECKO_SDK}/include/xpcom \
		-I${GECKO_SDK}/include/string \
		-I${GECKO_SDK}/include/embed_base \
		-I${JAVA_HOME}/include/linux"
	export GECKO_LIBS="-L${GECKO_SDK} -lgtkembedmoz"
}

function process-build() {

	local targetOptimization="1.4"
	local ant_opts="-Xmx768M"

# Eclipse has ~10 classes that do not yet compile with java 5.0
#	if (java-utils_is-vm-version-ge 1 5 0) ; then
#		targetOptimization="1.5"
#	fi

	einfo "Optimizing for Java ${targetOptimization} VM"

	# Some sun JVM's have only server VM and no client VM. To speed up things
	# use a same compiler threshold that client VM defaults to
	if [ ! -z "`java-config --java-version | fgrep "Server VM"`" ] ; then
		ant_opts="${ant_opts} -XX:CompileThreshold=1500"
	fi

	# Eclipse has started to respect global flags so patching the main build is enough
	local properties="-DjavacTarget=${targetOptimization} \
	 -DjavacSource=${targetOptimization} \
	 -DjavacVerbose=false \
	 -DjavacFailOnError=true \
	 -DjavacDebugInfo=true \
	 -DbuildId=\"Gentoo Linux ${PF}\""

	sed \
		-e "s/ant -q /ant -q ${properties} /" \
		-e "s/ANT_OPTS=-Xmx1000M/ANT_OPTS=\"${ant_opts}\"/" \
		-i build || die "Failed to patch build script"
}

function process-makefiles() {

	# Comment out hard-coded JAVA_HOME
	sed -i 's/^JAVA_HOME/#JAVA_HOME/' plugins/org.eclipse.core.resources.linux/src/Makefile || die "Failed to patch Makefile"

	# Select the set of native libraries to compile
	local libs="make_swt make_awt make_atk"

	if use gnome ; then
		einfo "Building GNOME VFS support"
		libs="${libs} make_gnome"
	fi

	if use mozilla ; then
		einfo "Building Mozilla embed support"
		libs="${libs} make_mozilla"
	fi

	if use atk ; then
		einfo "Building ATK support"
		libs="${libs} make_atk"
	fi

	sed -i "s/^all:.*/all: ${libs}/" "plugins/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak" || die "Failed to patch make_linux.mak"
}

function create-desktop-entry() {

	cat ${FILESDIR}/eclipse-${SLOT}.desktop | \
		sed -e "s/@PV@/${PV}/" \
		> eclipse-${SLOT}.desktop || die "Failed to create desktop entry"
}

function install-desktop-entry() {

	dodir /usr/share/applications
	insinto /usr/share/applications
	doins eclipse-${SLOT}.desktop
}

function clean-prebuilt-code() {

	find ${S} -type f \( -name '*.class' -o -name '*.so' -o -name '*.so.*' -o -name 'eclipse' \) | xargs rm -f
}

function get-memory-total() {
	cat /proc/meminfo | grep MemTotal | sed -r "s/[^0-9]*([0-9]+).*/\1/"
}

function check-ram() {

	local mem=$(get-memory-total)
	[ $(get-memory-total) -lt 775000 ] &&
		(
		echo
		ewarn "To build Eclipse, at least 768MB of RAM is recommended."
		ewarn "Your machine has less RAM. Continuing anyway. If the build"
		ewarn "stops with an error about invalid memory, increase your swap."
		echo
		)
}

function install-link-files() {

	einfo "Installing link files"

	dodir /usr/lib/eclipse-${SLOT}/links

	echo "path=/opt/eclipse-extensions-3" > ${D}/${eclipse_dir}/links/eclipse-binary-extensions-3.link
	echo "path=/opt/eclipse-extensions-3.1" > ${D}/${eclipse_dir}/links/eclipse-binary-extensions-3.1.link

	echo "path=/usr/lib/eclipse-extensions-3" > ${D}/${eclipse_dir}/links/eclipse-extensions-3.link
	echo "path=/usr/lib/eclipse-extensions-3.1" > ${D}/${eclipse_dir}/links/eclipse-extensions-3.1.link
}

function patch_amd64_ibm_jvm() {
	# the ibm jdk ebuild should have fixed headers, but until then
	# we just fix the compiling here (see bug #97421)
	if [ ${ARCH} == 'amd64' ]; then
	    if [ ! -z "`java-config --java-version | grep IBM`" ] ; then
		einfo "Fixing IBM jdk header problem"
		find plugins -name "make_linux.mak" -print0 | xargs -0 sed -i -e 's/^CFLAGS =/CFLAGS = -D_JNI_IMPORT_OR_EXPORT_= /'
	    fi
	fi
}

function setup-jvm-opts() {

	# Figure out correct boot classpath
	# karltk: this should be handled by the java-pkg eclass in setup-vm
	if [ ! -z "`java-config --java-version | grep IBM`" ] ; then
		# IBM JRE
		local bp="$(java-config --jdk-home)/jre/lib"
		bootclasspath="${bp}/core.jar:${bp}/xml.jar:${bp}/graphics.jar:${bp}/security.jar:${bp}/server.jar"
	        JAVA_LIB_DIR="$(java-config --jdk-home)/jre/bin"
	else
		# Sun derived JREs (Blackdown, Sun)
		local bp="$(java-config --jdk-home)/jre/lib"
		bootclasspath="${bp}/rt.jar:${bp}/jsse.jar"
	        JAVA_LIB_DIR="$(java-config --jdk-home)/jre/lib/${jvmarch}"
	fi
	einfo "Using bootclasspath ${bootclasspath}"
	einfo "Using JVM library path ${JAVA_LIB_DIR}"

	if [ ! -f ${JAVA_LIB_DIR}/libawt.so ] ; then
	    die "Could not find libawt.so native library"
	fi

	export AWT_LIB_PATH=${JAVA_LIB_DIR}
}

function strip-src() {

	local bp=${D}/${eclipse_dir}

	rm -rf ${bp}/plugins/org.eclipse.pde.source_3*
	rm -rf ${bp}/plugins/org.eclipse.jdt.source_3*
	rm -rf ${bp}/plugins/org.eclipse.platform.source.linux.*
	rm -rf ${bp}/plugins/org.eclipse.platform.source_3*

	rm -rf ${bp}/features/org.eclipse.jdt.source_3*/
	rm -rf ${bp}/features/org.eclipse.pde.source_3*/
	rm -rf ${bp}/features/org.eclipse.platform.source_3*/
}

function strip-docs() {
	local bp=${D}/${eclipse_dir}

	rm -rf ${bp}/plugins/org.eclipse.platform.doc.*
	rm -rf ${bp}/plugins/org.eclipse.jdt.doc.*
	rm -rf ${bp}/plugins/org.eclipse.pde.doc.*
}

function recompile-with-gcj() {
	:;
}

function check-cflags() {

	einfo "Checking for bad CFLAGS"

	local badflags="-fomit-frame-pointer -msse2"
	local error=false

	for x in ${badflags} ; do
		if [ ! -z "$(echo ${CFLAGS} | grep -- $x)" ] ; then
			ewarn "Found offending option $x in your CFLAGS"
			error=true
		fi
	done
	if [ ${error} == "true" ]; then
		echo
		ewarn "One or more potentially gruesome CFLAGS detected. When you run into trouble,"
		ewarn "please edit /etc/make.conf and remove all offending flags, then recompile"
		ewarn "Eclipse and all its dependencies before submitting a bug report."
		echo
		ewarn "In particular, gtk+ is extremely sensitive to which which flags it was"
		ewarn "compiled with."
		echo
		einfo "Tip: use equery depgraph \"=${PF}\" to list all dependencies."
		echo
		ebeep
	fi
}