File ecj-bootstrap.spec of Package ecj-bootstrap

# vim:fdm=marker:foldmarker=#>>>,#<<<:foldcolumn=6:foldlevel=42:
#
# spec file for package ecj-bootstrap
#
# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           ecj-bootstrap
BuildRequires:  fastjar
BuildRequires:  gcc-gij
BuildRequires:  gcc-java
BuildRequires:  libgcj-devel
BuildRequires:  unzip
BuildRequires:  zip
%define         eclipse_version 3.4
%define         jarname eclipse-ecj
Summary:        Eclipse Java Compiler
License:        EPL-1.0
Group:          Development/Libraries/Java
Version:        0.755
Release:        0
Url:            http://www.eclipse.org
Conflicts:      ecj
Source0:        eclipse-sourceBuild-srcIncluded-%{eclipse_version}.tar.bz2
Source1:        manifest.ecj
#Source2:        strange-mandriva-bug.patch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
#BuildArchitectures: noarch
#ExclusiveArch: %ix86
BuildArch:      noarch
Provides:       eclipse-ecj = %{eclipse_version}

%description
This is the Eclipse Java Compiler, which is used in the
java-1_4_2-gcj-compat-devel package



%prep 
#<<< package descriptions end 
#>>> %prep
%setup -c -T ecj-bootstrap
tar -jxf %{SOURCE0} 
#<<<
#>>> %build 

%build 
#>>> some useful functions ... used throughout bootstrap packages
TARGET_DIR=`pwd`
CLASSPATH_ORIG="$CLASSPATH"
LIB_GCJ="`ls %{_javadir}/libgcj-*.jar`"
#>>> delete binary file and files not needed
TARGET_DIR=`pwd`
function delBinaryFiles() {
  set +x
  echo deleting binary files ...
  for file in `find . -name "*.class" -o -name "*.jar" -o -name "*DELETED-BY-PACKAGER*"` 
  do 
    rm -rf $file
  done
  set -x
}
#<<<
#>>> make a string with all jar files found in target folder that can be used for a classpath string
# string is saved in JAR_CLASSPATH
function mkTargetClasspath() {
  set +x
  JAR_CLASSPATH=""
  for file in `find %{_javadir} -name "*.jar"`
  do
    JAR_CLASSPATH=$file:$JAR_CLASSPATH
  done
  set -x
}
#<<<
#>>> compiles all *.java file in the current directory tree
# uses mkTargetClasspath for CLASSPATH  variable
# uses LIB_GCJ for CLASSPATH
function compileFiles() {
  mkTargetClasspath
  set +x
  COMPILE_CLASSPATH_PATH=.:${JAR_CLASSPATH}
  echo using: $COMPILER_COMMAND $COMPILE_CLASSPATH_PATH \$file
  export LANG=en_US
  find . -name "*.java" -exec $COMPILER_COMMAND $COMPILE_CLASSPATH_PATH {} +
#  for file in `find . -name "*.java"`
#  do
#    echo -e "$COMPILER_COMMAND $COMPILE_CLASSPATH_PATH $file ... \c"
#    $COMPILER_COMMAND $COMPILE_CLASSPATH_PATH $file
#    # check for errors
#    if [ $? != 0 ]
#    then
#      echo ERROR
#      exit 1;
#    fi
#    echo done
#  done
  set -x
}
#<<<
#>>> make jar archive
# PARAM#1: name of jar archive (without .jar suffix)
# uses $TARGET_DIR to move created jar to
function mkJar() {
  find  -name "version.txt" -or -name "*.class" -or -name "*.properties" -or -name "*.rsc" -or -name "*manifest*" |\
      xargs /usr/bin/fastjar -m manifest.* -cf ${1}.jar ;
  mv ${1}.jar $TARGET_DIR
}
#<<<
COMPILER_COMMAND="gij -jar %{_javadir}/%{jarname}.jar -cp  "
#<<< end functions
delBinaryFiles
#>>> ecj compiler 
# we do this twice ... so let's create a function:
function compileEcj() {
  pushd jdtcoresrc/src
  mkdir tmp
  cd tmp
  unzip ../ecj.zip
  # we have to delete the following class ... it needs ant to compile ... it will be left in later
  rm ./org/eclipse/jdt/core/JDTCompilerAdapter.java
  # copy the manifest ...
  cp %{SOURCE1} .
  # Mandriva does not compile without problems ...
  # /me ducks: 
#  %if %{?mandriva_release:1}0
#    if [ $1 = "stage1" ]
#    then
#      cat %{SOURCE2} | patch -p0
#    fi
#  %endif
  compileFiles
  mkJar %{jarname}
  cd ..
  rm -r tmp
  popd
}
# compile with gcj
COMPILER_COMMAND="gcj  -Wno-deprecated -Bsymbolic -C --classpath "
compileEcj stage1
# compile with ecj
COMPILER_COMMAND="gij -jar $TARGET_DIR/%{jarname}.jar -cp  "
compileEcj stage2
#>>> wrapper script
# wrapper script to call ecj:
# ecj script:
mkdir -p $RPM_BUILD_ROOT/%{_bindir}
cat >>$RPM_BUILD_ROOT/%{_bindir}/ecj<<EOF
#!/bin/bash
# remove double bootclasspath entries:
BOOTCLASSPATH=""
BOOTCLASSPATH=\$(find %{_javadir} -name "libgcj*.jar" -print | tr "\n" ":"):\$(find %{_javadir}/ -name "glibj*.jar" -print | tr "\n" ":")
OPTIONS=""
while [ \$# -gt 0 ]
do
  if [ \$1 = "-bootclasspath" ]
  then
    BOOTCLASSPATH=\$2:\$BOOTCLASSPATH
    shift
    shift
    continue
  fi
  OPTIONS="\$OPTIONS \$1"
  shift
done
GIJ_EXECUTABLE=\$(ls /usr/bin/gij* | tail -n1)
if [ -e /usr/bin/java ]
then
  exec /usr/bin/java -jar %{_javadir}/%{jarname}.jar -bootclasspath \$BOOTCLASSPATH \$OPTIONS
elif [ -e /usr/bin/cacao ]
then
  exec /usr/bin/cacao -jar %{_javadir}/%{jarname}.jar -bootclasspath \$BOOTCLASSPATH \$OPTIONS
elif [ -e  ]
then
  exec \$GIJ_EXECUTABLE -jar %{_javadir}/%{jarname}.jar -bootclasspath \$BOOTCLASSPATH \$OPTIONS
else
  echo "no java vm found :("
  exit -1
fi
EOF
#<<< wrapper script
# build a jar with a correct manifest
#mkdir manifest-tmp
#pushd manifest-tmp
#/usr/bin/fastjar -xf $TARGET_DIR/%{jarname}.jar
#rm -r META-INF
#/usr/bin/fastjar -m %{SOURCE1} -cf ../%{jarname}.jar *
#popd
#
#<<< ecj compiler end
#<<<
#>>> install

%install
mkdir -p $RPM_BUILD_ROOT/%{_javadir}
cp %{jarname}.jar $RPM_BUILD_ROOT/%{_javadir}
ln -sf %{_javadir}/%{jarname}.jar $RPM_BUILD_ROOT/%{_javadir}/jdtcore.jar
#<<< install end

#>>> files

%files
%defattr(-,root,root)   
%{_javadir}/*
%attr(0755,root,root) %{_bindir}/*
#<<<

%changelog
openSUSE Build Service is sponsored by