#!/usr/bin/env bash
set -e
main() {
setup
(
set -x
add-standard-files
add-test
add-test-000
add-dist-ini
)
[ -x tool/make-cpan ] && tool/make-cpan
make-doc
make-alias
if [ -e pkg/make-cpan ]; then
./pkg/make-cpan
fi
}
setup() {
: "${PERL:=$(which perl)}"
ZILD="$PERL -S zild"
rm -fr cpan
mkdir cpan
CP_RL='cp -rL'
if [[ "$OSTYPE" =~ ^darwin|^freebsd ]]; then
CP_RL='cp -r'
fi
}
add-test() {
if [ -d test ]; then
cp -r test cpan/t
else
mkdir cpan/t
fi
if [ -d cpan/t/extra ]; then
mv cpan/t/extra cpan/xt
elif [ -d cpan/t/devel ]; then
mv cpan/t/devel cpan/xt
fi
rm -fr cpan/t/misc cpan/t/fail
}
add-standard-files() {
cp Changes cpan
# XXX Maybe should be CONTRIBUTING.pod
[ -e Contributing ] && cp Contributing cpan/CONTRIBUTING
[ -e bin ] && cp -r bin cpan
[ -e eg ] && cp -r eg cpan/example
cp -r lib cpan
if [ -e share ]; then
$CP_RL share cpan
fi
}
add-test-000() {
if [ "$($ZILD meta =zild/test-000)" == require ]; then
$PERL -S zild-render-template \
test/000-require-modules.t \
cpan/t/000-require-modules.t
elif [ "$($ZILD meta =zild/test-000)" == none ]; then
true # Nothing
else
$PERL -S zild-render-template \
test/000-compile-modules.t \
cpan/t/000-compile-modules.t
fi
}
add-dist-ini() {
$PERL -S zild-render-template dist.ini cpan/dist.ini
}
make-doc() {
for swim in $(find doc -type f -name '*.swim'); do
pod="${swim/doc/cpan/lib}"
pod="${pod/.swim/.pod}"
mkdir -p "$(dirname "$pod")"
if grep -E '^=+$' "$swim" &> /dev/null; then
(
set -x
swim --to=pod --meta=Meta --pod-cpan "$swim" > "$pod"
)
else
(
set -x
swim --to=pod --meta=Meta --complete=1 --wrap=1 "$swim" > "$pod"
)
fi
done
}
make-alias() {
alias="$($PERL -S zild meta =zild/alias)"
if [ -n "$alias" ]; then
for a in "${alias[@]}"; do
$PERL -S zild-render-template
done
fi
}
[ "${BASH_SOURCE[0]}" == "$0" ] && main "$@"
true
# vim: set ft=sh sw=2 lisp: