#!/bin/bash
## src2pkg script for:  tpkg
## Auto-generated by src2pkg-2.6
## src2pkg - Copyright 2005-2011 Gilbert Ashley <[email protected]>

#SOURCE_NAME='tpkg-1.3.tar.bz2'
#NAME='tpkg'   # Use ALT_NAME to override guessed value
#VERSION='1.0'   # Use ALT_VERSION to override guessed value

SOURCE_NAME='tar-1.13.tar.bz2'
ALT_NAME='tpkg'
ALT_VERSION='1.3'

# ARCH=''
# BUILD='1'
# PRE_FIX='usr'
# Any extra options go here:
EXTRA_CONFIGS='--disable-nls --with-ncursesw --enable-widec'
# STD_FLAGS='-O2 -march=i586 -mtune=i686'
PATCHLIST='tpkg-patches/01B-tar-1.13-save-dir-metadata.diff
tpkg-patches/02B-tar-1.13-bz2.diff
tpkg-patches/03B-tar-1.13-lzma.diff
tpkg-patches/04B-tar-1.13-autodetect.diff
tpkg-patches/05B-tar-1.13-pet.diff
tpkg-patches/06B-tar-1.13-xz.diff
tpkg-patches/07B-tar-1.13-no-automake.diff
tpkg-patches/08B-tar-1.13-update-config-guess.diff
tpkg-patches/09B-tar-1.13-update-config-sub.diff
tpkg-patches/010B-tar-1.13-mktime.diff
tpkg-patches/011B-tar-1.13-remove-bitrotted-rmt.diff
tpkg-patches/012B-tar-1.13-more-gcc4-madness.diff
tpkg-patches/013B-tar-1.13-tpkg.diff'

ADM_DIR=var/lib/tpkg
AUTO_DOT_NEW=NO
ADD_REQS=xz

# Optional function replaces configure_source, compile_source, fake_install
# To use, uncomment and write/paste CODE between the {} brackets.
# build() { CODE }

# Get the functions and configs
/usr/libexec/src2pkg/FUNCTIONS ;

# Execute the named packaging steps:
pre_process
find_source
make_dirs
unpack_source
fix_source_perms
configure_source #
# compile_source   # If used, the 'build' function replaces these 3
# fake_install     #

cd $SRC_DIR
echo -n $BLUE"Building tar-1.13 - "$NORMAL
# avert autotools-goes-wacko whatever happened to automake-1.4?? madness
touch *
(cd lib && make &> /dev/null )
(cd src && make &> /dev/null )
if [[ $? -eq 0 ]] ; then
       mkdir -p $PKG_DIR/bin
       cp -f src/tar $PKG_DIR/bin/tar-1.13
       chmod 755 $PKG_DIR/bin/tar-1.13
       echo $GREEN"OK"$NORMAL
else
       echo $RED"Failed! "$NORMAL
       exit
fi

for DIR in manifests packages postinst postrm \
       preinst prerm removed required setup/tmp transactions ; do
       mkdir -p $PKG_DIR/$ADM_DIR/$DIR
done

cd $SRC_DIR && tar -xaf $CWD/tpkg-$VERSION.tar.bz2

mkdir -p $PKG_DIR/sbin $PKG_DIR/usr/bin

( cd $SRC_DIR/tpkg-$VERSION && \
       {       cp tpkg-install tpkg-remove tpkg-upgrade $PKG_DIR/sbin
               cp tpkg-deps tpkg-explode tpkg-orphans tpkg-reqs tpkg-make xwm-config $PKG_DIR/usr/bin
               chown root:root $PKG_DIR/sbin/* $PKG_DIR/usr/bin/*
               chmod 755 $PKG_DIR/sbin/* $PKG_DIR/usr/bin/*
               for FILE in setup.* ; do
                       cp -a $FILE $PKG_DIR/$ADM_DIR/setup
               done
               chown root:root $PKG_DIR/$ADM_DIR/setup/setup.*
               chmod 755 $PKG_DIR/$ADM_DIR/setup/*
               # setup/tmp is a private dir
               chmod 700 $PKG_DIR/$ADM_DIR/setup/tmp
       }
)

( cd $PKG_DIR/sbin && ln -sf tpkg-install tpkg-i )
( cd $PKG_DIR/sbin && ln -sf tpkg-remove tpkg-r )
( cd $PKG_DIR/sbin && ln -sf tpkg-upgrade tpkg-u )

( cd $PKG_DIR/usr/bin && ln -sf tpkg-make tpkg-m )
( cd $PKG_DIR/usr/bin && ln -sf tpkg-explode tpkg-e )

mkdir -p $MAN_DIR/man8
cp $SRC_DIR/tpkg-$VERSION/*.8 $MAN_DIR/man8

mkdir -p $PKG_DIR/etc
cp $SRC_DIR/tpkg-$VERSION/tpkg.conf.new $PKG_DIR/etc

fix_pkg_perms
strip_bins
create_docs
compress_man_pages
make_description
make_doinst
make_package
post_process

## See the documentation for more help and examples. Below are some of
# the most common Extras and Options for easy cut-and-paste use.
# DOCLIST='' PATCHLIST='' INSTALL_TYPE=''
# CONFIG_COMMAND='' MAKE_COMMAND='' INSTALL_LINE=''
# When editing src2pkg scripts to add custom code, use these variables
# to refer to the current directory, the sources or the package tree:
# $CWD (current directory), $SRC_DIR (sources), $PKG_DIR (package tree)
# Other commonly-used directories include: $DOC_DIR (document directory)
# $MAN_DIR (man-page directory) $DATA_DIR (shared-data directory)