%define ant_home %{_datadir}/ant
%define gcj_support 0

Name:           ant
Summary:        Ant build tool for java
Summary(ja):    Java 用ビルドツール
Version:        1.8.1
Release:        1%{?_dist_release}

License:        ASL 2.0
URL:            http://ant.apache.org/
Group:          Development/Tools

# using binary for bootstrap
Source0:        http://www.apache.org/dist/ant/binaries/apache-ant-%{version}-bin.tar.bz2
Source1:        apache-ant-1.7.ant.conf

BuildRequires:  jpackage-utils >= 1.7.5
BuildRequires:  java-devel >= 1.5.0
#BuildRequires:  jaxp_transform_impl
#if %without bootstrap
#BuildRequires:  ant
#BuildRequires:  junit
#BuildRequires:  xml-commons-jaxp-1.3-apis
#BuildRequires:  xerces-j2
#endif

Requires:       jpackage-utils >= 1.7.5
Requires:       java-devel >= 1.5.0
#if %without bootstrap
Requires:       xerces-j2
Requires:       xml-commons-jaxp-1.3-apis
#endif

%if !%{gcj_support}
BuildArch:      noarch
%endif
BuildRoot:      %{_tmppath}/%{name}-%{version}-root
# RHUG
Obsoletes:      ant-devel < %{version}-%{release}
Provides:       ant-devel = %{version}-%{release}
# Mandriva
Conflicts:      j2sdk-ant
%if %{gcj_support}
BuildRequires:  java-gcj-compat-devel
Requires(post):   java-gcj-compat
Requires(postun): java-gcj-compat
%endif

Requires(post):   jpackage-utils >= 1.7.5
Requires(postun): jpackage-utils >= 1.7.5

%description
Ant is a platform-independent build tool for java. It's used by apache
jakarta and xml projects.

#'
# -----------------------------------------------------------------------------

%prep
%setup -q -n apache-ant-%{version}

# Fix file-not-utf8 rpmlint warning
iconv KEYS -f iso-8859-1 -t utf-8 -o KEYS.utf8
mv KEYS.utf8 KEYS
iconv LICENSE -f iso-8859-1 -t utf-8 -o LICENSE.utf8
mv LICENSE.utf8 LICENSE

# Provides: exclude perl(oata), perl(examples)
cat <<__EOF__ > %{name}-perl.prov
#!/bin/sh
/usr/lib/rpm/perl.prov \$* | grep -v '^perl(oata)$' | grep -v '^perl(examples)$'
__EOF__
%define __perl_provides %{_builddir}/apache-ant-%{version}/%{name}-perl.prov
chmod +x %{__perl_provides}


# Requires: exclude bogus perl(the)
cat <<__EOF__ > %{name}-perl.req
#!/bin/sh
/usr/lib/rpm/perl.req \$* | grep -v '^perl(the)$'
__EOF__
%define __perl_requires %{_builddir}/apache-ant-%{version}/%{name}-perl.req
chmod +x %{__perl_requires}

# -----------------------------------------------------------------------------

%build


# -----------------------------------------------------------------------------

%install
rm -rf $RPM_BUILD_ROOT

# ANT_HOME and subdirs
mkdir -p $RPM_BUILD_ROOT%{ant_home}/{lib,etc}

# jars
install -d -m 755 $RPM_BUILD_ROOT%{_javadir}
install -d -m 755 $RPM_BUILD_ROOT%{_javadir}/%{name}
install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/maven2/poms

pushd lib
for jars in *.jar; do
    suffix=`echo $jars | cut -f1 -d.`
    case "$suffix" in
	ant | ant-launcher)
	    install -m 644 $jars $RPM_BUILD_ROOT%{_javadir}/$suffix-%{version}.jar
	    ;;
	*)
	    install -m 644 $jars $RPM_BUILD_ROOT%{_javadir}/%{name}/$suffix-%{version}.jar
	    ;;
    esac
done

for poms in *.pom; do
    case "$poms" in
	ant.pom | ant-launcher.pom)
	    install -m 644 $poms $RPM_BUILD_ROOT%{_datadir}/maven2/poms/JPP-$poms
	    ;;
	*)
	    install -m 644 $poms $RPM_BUILD_ROOT%{_datadir}/maven2/poms/JPP.%{name}-$poms
	    ;;
    esac
done
ln -sf %{name}-apache-bcel.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/%{name}-jakarta-bcel.jar
ln -sf %{name}-apache-log4j.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/%{name}-jakarta-log4j.jar
ln -sf %{name}-apache-oro.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/%{name}-jakarta-oro.jar
ln -sf %{name}-apache-regexp.jar $RPM_BUILD_ROOT%{_javadir}/%{name}/%{name}-jakarta-regexp.jar
popd

# jar aliases
(cd $RPM_BUILD_ROOT%{_javadir} && for jar in *-%{version}.jar; do ln -sf ${jar} `echo $jar| sed "s|-%{version}||g"`; done)
(cd $RPM_BUILD_ROOT%{_javadir}/%{name} && for jar in *-%{version}.jar; do ln -sf ${jar} `echo $jar| sed "s|-%{version}||g"`; done)

# XSLs
cp -p etc/*.xsl $RPM_BUILD_ROOT%{ant_home}/etc

# install everything else
mkdir -p $RPM_BUILD_ROOT%{_bindir}
cp -p bin/ant{,Run} $RPM_BUILD_ROOT%{_bindir}

# default ant.conf
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}
cp -p %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.conf

# OPT_JAR_LIST fragments
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d
echo "ant/ant-jmf" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/jmf
echo "ant/ant-nodeps" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/nodeps
echo "ant/ant-swing" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/swing
echo "jaxp_transform_impl ant/ant-trax xalan-j2-serializer" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/trax
echo "antlr ant/ant-antlr" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/antlr
echo "bsf ant/ant-apache-bsf" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-bsf
echo "xml-commons-resolver12 ant/ant-apache-resolver" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-resolver
echo "jakarta-commons-logging ant/ant-commons-logging" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/commons-logging
echo "jakarta-commons-net ant/ant-commons-net" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/commons-net
#echo "jai ant/ant-jai" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/jai
echo "bcel ant/ant-apache-bcel" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-bcel
echo "log4j ant/ant-apache-log4j" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-log4j
echo "oro ant/ant-apache-oro" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-oro
echo "regexp ant/ant-apache-regexp" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/apache-regexp
echo "javamail jaf ant/ant-javamail" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/javamail
echo "jdepend ant/ant-jdepend" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/jdepend
echo "jsch ant/ant-jsch" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/jsch
echo "junit ant/ant-junit" > $RPM_BUILD_ROOT%{_sysconfdir}/%{name}.d/junit

# -----------------------------------------------------------------------------

%if %{gcj_support}
rm -rf aot-compile-rpm
%{_bindir}/aot-compile-rpm
%endif

%if %{gcj_support}
%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
%endif

%clean
rm -rf $RPM_BUILD_ROOT

# -----------------------------------------------------------------------------

%files
%defattr(0644,root,root,0755)
%doc KEYS LICENSE NOTICE README WHATSNEW
%config(noreplace) %{_sysconfdir}/%{name}.conf
%dir %{_sysconfdir}/%{name}.d
%{_sysconfdir}/%{name}.d/*
%attr(0755,root,root) %{_bindir}/ant
%attr(0755,root,root) %{_bindir}/antRun
%{_javadir}/*.jar
%dir %{_javadir}/%{name}
%{_javadir}/%{name}/*.jar
%dir %{ant_home}
%dir %{ant_home}/etc
%{ant_home}/etc/*.xsl
%{_datadir}/maven2/poms/*
%if %{gcj_support}
%attr(-,root,root) %{_libdir}/gcj/%{name}/*
%endif

# -----------------------------------------------------------------------------

%changelog
* Sat Aug 28 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.8.1-1
- Initial build for Vine Linux
- this release is based on binary distribution
