#!/bin/sh

BIGGIE="tools/biggie/biggie"
HOMEWORLDSDL_BIG_DIR="HomeworldSDL_big"
HOMEWORLDSDL_BIG_FILE="HomeworldSDL.big"

if [ ! -e $PWD/$HOMEWORLDSDL_BIG_DIR ]; then
    echo -e "Sorry to be a pain but in order to make it easier to use this script"
    echo -e "I'm going to force you to run it from the root directory to ensure"
    echo -e "things are in a known location. Try cd'ing up a directory."
    echo -e "(Yes, I'm aware of the irony of this.)"
    exit;
fi

if [ ! -e $BIGGIE ]; then
    echo -e "It doesn't look like $BIGGIE exists. Please compile it first."
    exit;
fi

# Having ascertained we're in the right place and ready to go - let's change
# directory... This is so biggie sees relative paths as we want them in the
# .big file itself.

cd $HOMEWORLDSDL_BIG_DIR

# traverse the HomeworldSDL_big directory with `find`, searching for files of:
# - type [f]ile
# - which don't reside in a dot-directory
# - are not themselves a dot-file
# and then clean up the path so that paths don't start with "./". Also, strip
# out this script and accompanying README file. Finally pass this as a file
# list to biggie with the [f]ast-create flag and create .big file in the working
# copy's root directory "above" us.

../$BIGGIE -f ../$HOMEWORLDSDL_BIG_FILE `find . -type f -not -path '*/.*' -not -name '.*' \
    | grep -v "./README.txt" \
    | grep -v "./convert_directory_to_big_file" \
    | cut -f2- -d'/'`
