# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../apache-ant/apache-ant.conf
# Copyright (C) 2007 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# Check if a java development kit was installed.
if [ -z $JAVA_HOME ]; then
	abort "JDK required for building $pkg"
fi

# We want Ant to be installed in its own directory.
prefix=$prefix/apache-ant
export ANT_HOME=$root/$prefix
set_confopt

# Custom package building and installation.
ant_postmake() {
	# The next command will start the build and when finished
	# it will automatically install the new build in ANT_HOME
	./build.sh install
	if [ $? -ne 0 ]; then
		# Something went wrong.
		abort "Building $pkg failed."
	fi

	# Now the ant commands need to be made available. This can
	# be done is two ways. Add the bin directory to PATH or have
	# links to the ant commands somewhere in the existing PATH.
	# Here we choose the last option to prevent PATH becoming to
	# large. We will place the links in the default java/bin
	# directory.
	bin_path=$(pkgprefix bindir java-dirtree)
	for ant_command in $(find $ANT_HOME/bin -perm +o=x -type f); do
		# Create a link for the current ant command.
		ln -sf $ant_command $bin_path/$(basename $ant_command)
	done

        # Prepare necessary environment variables.
	cat <<-EOF > $root/etc/profile.d/ant
	ANT_HOME=/$prefix
	export ANT_HOME
	EOF
}

hook_add postmake 5 ant_postmake