#
# $Id: compressed.in,v 1.6 2003/02/03 23:09:34 jmmv Exp $
# Build compressed type distribution files.
#
# buildtool
# Copyright (c) 2002, Julio Merino.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

is_compressed() {
    case "$1" in
        tar.gz|tgz|tar.bz2|tbz|zip)
            return 0
            ;;
        *)
            return 1
            ;;
    esac
}

make_compressed() {
    local fmt="$1"
    local dirname="${BT_PKG_NAME}-${BT_PKG_VERSION}"
    local moved=""
    local curdir="`pwd`"
    local curbase="`basename $curdir`"

    echo "bt_dist: building compressed dist, type $fmt"
    cd ..
    if [ ! -d "$dirname" ]; then
        mv $curbase $dirname
        moved="yes"
    fi

    printf "${dirname}.${fmt}: "

    case "$fmt" in
        tar.gz|tgz)
            compress_tar_gz "$dirname" "$fmt"
            ;;
        tar.bz2|tbz)
            compress_tar_bz2 "$dirname" "$fmt"
            ;;
        zip)
            compress_zip "$dirname" "$fmt"
            ;;
    esac

    if [ -n "$moved" ]; then
        mv $dirname $curbase
    fi
    cd $curdir
    echo "done."
}

compress_tar_gz() {
    tar cf - $1 | gzip -c9 > "$1.$2"
}

compress_tar_bz2() {
    tar cf - $1 | bzip2 -c9 > "$1.$2"
}

compress_zip() {
    zip -r9 "$1.$2" $1 2>&1 > /dev/null
}

# Local Variables: ***
# mode: shell-script ***
# End: ***
#!/usr/local/bin/bash
# $Id: frontend.in,v 1.7 2003/01/31 11:19:32 jmmv Exp $
# bt_dist's frontend.
#
# buildtool
# Copyright (c) 2002, Julio Merino.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

Cmd_Lc="tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'"

if [ x"$__BUILDTOOL" != x"yes" ]; then
    echo "bt_dist: this program must be run through buildtool"
    exit 1
fi

if [ ! -f "./buildtool.d/defs" ]; then
    echo "bt_dist: cannot find buildtool.d/defs file"
    exit 1
fi

# Clean the source tree
if [ -f "./bt_config.mk" ]; then
    echo "bt_dist: cleaning tree (cleandir)"
    __BUILDTOOL="yes" /usr/local/libexec/buildtool-0/bt_make -m/usr/local/share/buildtool-0/mk BT_DIR_MODS=/usr/local/libexec/buildtool-0 cleandir
fi

# Validate package first
echo "bt_dist: validating package"
__BUILDTOOL="yes" /usr/local/bin/bash -c "/usr/local/libexec/buildtool-0/bt_lint"
if [ $? -eq 1 ]; then
    echo "bt_dist: cannot continue; fix FATAL errors and retry"
    exit 1
fi

. ./buildtool.d/defs

if [ -z "$BT_PKG_DISTFMTS" ]; then
    BT_PKG_DISTFMTS="tar.gz"
else
    BT_PKG_DISTFMTS="`echo $BT_PKG_DISTFMTS | $Cmd_Lc`"
fi

for fmt in $BT_PKG_DISTFMTS; do
    if is_compressed "$fmt"; then
        make_compressed "$fmt"
    else
        echo "bt_dist: unrecognized $fmt dist format"
    fi
done

exit 0

# Local Variables: ***
# mode: shell-script ***
# End: ***
