#!/bin/bash
# find-and-aot-compile

: ${1?"
find-and-aot-compile:  Recursively find jars in the current directory,
natively-compile them, and generate a .tar.gz to be exploded in the library
directory of the target.  This is intended to only be run within an RPM build
tree

  Usage: $0 NAME BUILD_OPTIONS
    NAME - the desired name for the .tar.gz
      (ex. eclipse)
    BUILD_OPTIONS - a list of gcj options to pass to aot-compile
      (outside of -findirect-dispatch, -shared, and -Wl,-Bsymbolic)
"}

name=$1
build_options=$2

for jarfile in $(find -name \*.jar); do
    # This is ugly.  What we want is to be able to natively-compile all the
    # jars within an RPM build tree as well as from an arbitrary location
    # in the filesystem.  Patches welcome :)
    so_dir="./$name/$(dirname $jarfile | \
      sed 's:^\.\+/::')";
    mkdir -p $so_dir;
    dest_so_name=$so_dir/lib`basename $jarfile`.so
    aot-compile $jarfile $dest_so_name "$build_options"
done

tar czf $name.tar.gz $name
