%define qualifier 201102101200

Summary: Eclipse Compiler for Java
Name: ecj
Version: 3.6.2
Release: 1%{?_dist_release}

URL: http://www.eclipse.org
License: EPL
Group: Development/Languages

#Source0: ftp://sourceware.org/pub/java/ecj-latest.jar
#Source1: ecj-gij.sh.in
Source0: http://download.eclipse.org/eclipse/downloads/drops/R-%{version}-%{qualifier}/%{name}src-%{version}.zip
Source1: ecj.sh.in
# Use ECJ for GCJ
# cvs -d:pserver:anonymous@sourceware.org:/cvs/rhug co eclipse-gcj
# tar cjf ecj-gcj.tar.bz2 eclipse-gcj
Source2: %{name}-gcj.tar.bz2

BuildRoot: %{_tmppath}/%{name}-%{version}-root
#BuildArch: noarch
BuildRequires: jpackage-utils
BuildRequires: gcc-java >= 4.0.0
BuildRequires: fastjar
# for /usr/bin/aot-compile-rpm
BuildRequires: java-gcj-compat-devel

Requires: libgcj >= 4.0.0
# for /usr/bin/rebuild-gcj-db
Requires(post): java-gcj-compat
Requires(postun): java-gcj-compat

Provides: eclipse-ecj = %{version}-%{release}

%description
ECJ is the Java bytecode compiler of the Eclipse Platform.  It is also known as
the JDT Core batch compiler.

%prep
%setup -q -c

# Use ECJ for GCJ's bytecode compiler
tar jxf %{SOURCE2}
mv eclipse-gcj/org/eclipse/jdt/internal/compiler/batch/GCCMain.java \
  org/eclipse/jdt/internal/compiler/batch/
cat eclipse-gcj/gcc.properties >> \
  org/eclipse/jdt/internal/compiler/batch/messages.properties
rm -rf eclipse-gcj

# Remove bits of JDT Core we don't want to build
rm -r org/eclipse/jdt/internal/compiler/tool
rm -r org/eclipse/jdt/internal/compiler/apt

# JDTCompilerAdapter isn't used by the batch compiler
rm -f org/eclipse/jdt/core/JDTCompilerAdapter.java

%build
for f in `find -name '*.java' | cut -c 3- | LC_ALL=C sort`; do
    gcj -Wno-deprecated -C $f
done

find -name '*.class' -or -name '*.properties' -or -name '*.rsc' |\
    xargs fastjar cf %{name}-%{version}.jar

%install
rm -rf $RPM_BUILD_ROOT
rm -rf aot-compile-rpm

mkdir -p $RPM_BUILD_ROOT%{_javadir}
#install -m644 %{SOURCE0} $RPM_BUILD_ROOT%{_javadir}/%{name}-%{version}.jar
install -m644 *.jar $RPM_BUILD_ROOT%{_javadir}/%{name}-%{version}.jar
pushd $RPM_BUILD_ROOT%{_javadir}
ln -s %{name}-%{version}.jar %{name}.jar
ln -s %{name}-%{version}.jar eclipse-%{name}-%{version}.jar
ln -s eclipse-%{name}-%{version}.jar eclipse-%{name}.jar
ln -s %{name}-%{version}.jar jdtcore.jar
popd

# Install the ecj wrapper script
install -p -D -m0755 %{SOURCE1} $RPM_BUILD_ROOT%{_bindir}/ecj
sed --in-place "s:@JAVADIR@:%{_javadir}:" $RPM_BUILD_ROOT%{_bindir}/ecj

aot-compile-rpm


%clean
rm -rf $RPM_BUILD_ROOT

%post
if [ -x %{_bindir}/rebuild-gcj-db ]
then
  %{_bindir}/rebuild-gcj-db
fi

%postun
if [ -x %{_bindir}/rebuild-gcj-db ]
then
  %{_bindir}/rebuild-gcj-db
fi


%files
%defattr(-,root,root,-)
%{_bindir}/%{name}
%{_javadir}/%{name}*.jar
%{_javadir}/eclipse-%{name}*.jar
%{_javadir}/jdtcore.jar
%{_libdir}/gcj/%{name}

%changelog
* Sun Mar 20 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.6.2-1
- new upstream release

* Tue Aug 24 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.6.0-1
- new upstream release
- enabled AOT compile

* Mon Apr 19 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.5.1-1
- initial build for Vine Linux
