jw-pkg/scripts/create-mkspec.sh
2019-01-30 16:23:40 +00:00

143 lines
3.1 KiB
Bash

#!/bin/bash
_cat()
{
sed 's/^ *|//'
}
cfg_section()
{
ini_section "$inifile" $@
}
cfg_value()
{
ini_value "$inifile" $@
}
cfg_escape()
{
sed 's/\\/\\\\/g; s/\$/\\$/g; s/`/\\`/g'
}
# unneeded but kept, because it might come in handy in the future
have_pkg()
{
echo "$subpackages" | grep -q "\(^[ ]*\|[ ]\+\)$1\([ ]\+\|$\)"
return $?
}
subpackage_description()
{
case $1 in
run)
echo "Runtime files"
;;
devel)
echo "Development files"
;;
esac
}
# -- here we go
echo "== running $0" "$@" >&2
export LANG=POSIX
dir=`dirname $0`
inifile="$1"
. $dir/ini-tools.sh
subpackages=`cfg_value global.subpackages`
license=`cfg_value global.license`
[ "$license" ] || license="janware GmbH proprietary license"
vendor=`cfg_value global.vendor`
[ "$vendor" ] || vendor="janware GmbH"
url=`cfg_value global.url`
[ "$url" ] || url="https://janware.com"
_cat <<- EOT
|echo "%define debug_package %{nil}"
|# ---------------------------------------
|echo "Name: \$NAME"
|echo "Summary: `cfg_value summary`"
|echo "Version: \$VERSION"
|echo "Release: \$RELEASE"
|echo "License: $license"
|echo "Group: System/Libraries"
|[ -n "\$SOURCE" ] && echo "Source: \$SOURCE"
|echo "Vendor: $vendor"
|echo "URL: $url"
|echo "BuildRoot: /var/tmp/%{name}-buildroot"
|echo "Distribution: jw / openSUSE Tumbleweed"
|echo ""
|echo "%description"
|echo "`cfg_value description`"
|echo ""
|# ---------------------------------------
|echo "%prep -n \$NAME-run"
|echo "%setup -q -n \$NAME-\$V"
|echo ""
|echo "%build"
|echo 'pwd'
|echo 'make config'
|echo 'make'
|echo ""
|echo "%install"
|echo 'rm -rf \$RPM_BUILD_ROOT'
|echo "export ENV_PREFIX=\\\$RPM_BUILD_ROOT"
|echo "export INSTALL_LOG=\$INSTALL_LOG"
|echo "mkdir -p \`dirname \$INSTALL_LOG\`"
|echo "> \$INSTALL_LOG"
|echo "make install"
|echo "export PATH=$MOD_SCRIPT_DIR:\\\$PATH"
|echo "/bin/bash pkg.sh milk-install-log -p \\\$ENV_PREFIX -n \$NAME -t rpm -s \\"$subpackages\\" \$INSTALL_LOG \`dirname \$INSTALL_LOG\`"
|echo "exit 0" # <- Cut short CentOS magic appended to install scriptlet, which would generate .pyo files and other cruft.
EOT
for p in $subpackages; do
P=${p^^}
_cat <<- EOT
|echo ""
|echo "# --------------------------------------- subpackage $p"
|echo ""
|echo "%package -n \$NAME-$p"
|echo "Summary: `cfg_value summary`"
|echo "Group: `cfg_value global.group`"
|[ "\$REQUIRES_$P" ] && echo "Requires: \$REQUIRES_$P"
|[ "\$CONFLICTS_$P" ] && echo "Conflicts: \$CONFLICTS_$P"
|[ "\$PROVIDES_$P" ] && echo "Provides: \$PROVIDES_$P"
|echo ""
EOT
descr=`subpackage_description $p`
if [ "$descr" ]; then
_cat <<- EOT
|echo ""
|echo "%description -n \$NAME-$p"
|echo "$descr"
EOT
fi
for stage in pre preun post postun; do
echo "== processing stage $stage: cfg_section pkg.$p.$stage" >&2
cfg_section pkg.$p.$stage >&2
cfg_section pkg.$p.$stage | grep -q . && {
_cat <<- EOT
|echo ""
|echo "%$stage -n \$NAME-$p"
EOT
echo "cat << EOT"
cfg_section pkg.$p.$stage | cfg_escape
echo "EOT"
}
done
_cat <<- EOT
|echo ""
|echo "%files -n \$NAME-$p -f \$INSTALL_LOG.\$NAME-$p"
|echo '%defattr (-, root, root)'
EOT
done