# $Id: PKGBUILD 178352 2013-02-20 17:00:42Z andyrtr $
# Maintainer (Arch): Andreas Radke <andyrtr@archlinux.org>
# Contributor (Arch): Jan de Groot <jgc@archlinux.org>

pkgname='openjdk6-old'
pkgbase="openjdk6"
_javaver=6
_icedteaver=1.12.3
_openjdk_version=b27
_openjdk_date=26_oct_2012
pkgver=${_javaver}.${_openjdk_version}_${_icedteaver}
pkgrel=1.1
url='http://icedtea.classpath.org'
arch=('i686' 'x86_64' 'mips64el')
license=('custom')
pkgdesc='Free Java environment based on OpenJDK 6.0 with IcedTea6 replacing binary plugs.'
backup=(etc/profile.d/openjdk6.sh)
depends=('gcc-libs' 'xdg-utils' 'hicolor-icon-theme' 'ca-certificates-java' 'libxtst' 'libxt' 'nss' 'libjpeg' 'freetype2' 'libxrender' 'libpng>=1.5.7')
makedepends=('alsa-lib' 'giflib' 'libxp' 'gtk2'
	     'nspr' 'zlib' 'libjpeg>=8' 'libx11' 'libcups' 'patch' 'libxslt'
	     'apache-ant' 'autoconf' 'unzip' 'rhino' 'mercurial' 'zip' 'cpio' 'openjdk6-old' 'inetutils' 'wget')
optdepends=('alsa-lib: for sound'
           'giflib: for gif format support')
install=openjdk6.install
options=('!emptydirs')
source=(http://icedtea.classpath.org/download/source/icedtea6-${_icedteaver}.tar.gz{,.sig}
	http://download.java.net/openjdk/jdk6/promoted/${_openjdk_version}/openjdk-6-src-${_openjdk_version}-${_openjdk_date}.tar.gz
	http://icedtea.classpath.org/download/drops/jaxp144_04.zip
	http://icedtea.classpath.org/download/drops/jdk6-jaxws2_1_6-2011_06_13.zip
	http://icedtea.classpath.org/download/drops/jdk6-jaf-b20.zip
	fix_jdk_cmds_path.diff
	fix_corba_cmds_path.diff
	fontconfig-paths.diff
	nonreparenting-wm.diff
	disable_Werror.diff
	openjdk6.profile
	openjdk6.profile.csh
	disable-openjdk-Werror.diff
	ecj-icedtea.patch)
noextract=(openjdk-6-src-${_openjdk_version}-${_openjdk_date}.tar.gz
	jaxp144_04.zip
	jdk6-jaxws2_1_6-2011_06_13.zip
	jdk6-jaf-b20.zip)
sha256sums=('db9dc14fa537fb22616fcd9e5b80758aa7baa66e0b6f8adfe3d5e80414574b4c'
            'a6cbeccc4f25f72a940b9ac0c3e05ece50edc16c1c13f7a1a82ee895563930e3'
            '044c3877b15940ff04f8aa817337f2878a00cc89674854557f1a02f15b1802a0'
            '490f696218c1fed9cb180680af883fe309b414fec232e9cec19645e12ad0b43c'
            '229040544e791f44906e8e7b6f6faf503c730a5d854275135f3925490d5c3be3'
            '78c7b5c9d6271e88ee46abadd018a61f1e9645f8936cc8df1617e5f4f5074012'
            'f5f59e121f7645ebc449bb13569fd924cbab3194e41db901f4fbe9dbd45720c5'
            '7b2db65bfb9d5014e1522178d65cabf05dfa85e0926cde5648b5a338db376479'
            '9ad943ceb3dbcdf45d72974fc3667886a7ed65c69ab9abc17be5412827551a7f'
            '9c3c55c30729ec44fab14c3f3f841c273730c7467d8908a72f018bc9e9f65bd9'
            'eb4c7f4cf50f5f74b683857f707bd21ec3847267e2e5e3173f42a6910a024f97'
            '26e2cd5a6034f08a685129c9412f487b9931fb0d556f1ccceab17bdb75a372cd'
            '0c2d9116d6e550021994d6713a93621a9df685d2182996be3249ad812712b007'
            '3e20fdcd17d4adee1cb2ddc3b15a39fe56b9a7837067487eedd40733adfea9c6'
            '77bafb45d67cbdac59ae27b0cc85e38d849dcf5c4c4005f5b28b33f4f5b734ab')

build() {

  unset CLASSPATH
  
    [ -z "${ANT_HOME}" ] && . /etc/profile.d/apache-ant.sh

  _javaver=6
  _jvmdir=/usr/lib/jvm/java-${_javaver}-openjdk

  cd ${srcdir}/icedtea6-${_icedteaver}

  ln -s ${srcdir}/openjdk-6-src-${_openjdk_version}-${_openjdk_date}.tar.gz .

  cp ${srcdir}/*.diff ${srcdir}/icedtea6-${_icedteaver}/patches/
  cp ${srcdir}/ecj-icedtea.patch ${srcdir}/icedtea6-${_icedteaver}/patches/ecj/icedtea.patch

  autoreconf -i

  export DISTRIBUTION_PATCHES="patches/fix_jdk_cmds_path.diff patches/fontconfig-paths.diff patches/fix_corba_cmds_path.diff patches/nonreparenting-wm.diff patches/disable_Werror.diff patches/disable-openjdk-Werror.diff"

  export ALT_PARALLEL_COMPILE_JOBS="${MAKEFLAGS/-j}"
  export HOTSPOT_BUILD_JOBS="${ALT_PARALLEL_COMPILE_JOBS}"
  unset MAKEFLAGS

  ./configure --with-parallel-jobs=${HOTSPOT_BUILD_JOBS} \
	--with-ant-home=/usr/share/java/apache-ant \
	--with-pkgversion=Parabola-${pkgver}-${pkgrel}-$CARCH \
	--with-jaxp-drop-zip=${srcdir}/jaxp144_04.zip \
  	--with-jaxws-drop-zip=${srcdir}/jdk6-jaxws2_1_6-2011_06_13.zip \
	--with-jaf-drop-zip=${srcdir}/jdk6-jaf-b20.zip \
	--with-abs-install-dir=${_jvmdir} \
	--with-jdk-home="$JAVA_HOME"

  # Java 7 compilers give more warnings.
  find . -name '*.gmk' -or -name 'Makefile' | xargs sed -i 's/-Werror//'

  LD_PRELOAD="" make 
}

package() {
  if [ "${CARCH}" = "x86_64" ]; then
    _arch=amd64
  else
    _arch=i586
  fi

  _javaver=6
  _jvmdir=/usr/lib/jvm/java-${_javaver}-openjdk

  cd ${srcdir}/icedtea6-${_icedteaver}
  install -m755 -d ${pkgdir}/${_jvmdir}/jre

  pushd ${srcdir}/icedtea6-${_icedteaver}/openjdk.build/j2sdk-image

   # Install main files.
  cp -a bin include lib ${pkgdir}/${_jvmdir}/ 
  cp -a jre/bin jre/lib ${pkgdir}/${_jvmdir}/jre/ 

  mv ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.Ubuntu.properties.src \
     ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.properties.src 
  mv ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.Ubuntu.bfc \
     ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.bfc 
  rm -f ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.*.bfc
  rm -f ${pkgdir}/${_jvmdir}/jre/lib/fontconfig.*.properties.src

  # set some variables
  install -m755 -d ${pkgdir}/etc/profile.d
  install -m755 ${srcdir}/openjdk6.profile ${pkgdir}/etc/profile.d/openjdk6.sh 
  install -m755 ${srcdir}/openjdk6.profile.csh ${pkgdir}/etc/profile.d/openjdk6.csh 
  
  # install license
  install -Dm644 ${srcdir}//icedtea6-${_icedteaver}/openjdk/LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE
}