freebsd-nq/release/packages/generate-ucl.sh
Glen Barber 5c52b2f5ca Rework the way <packagename>.ucl files are generated.
One of the major pain points with how this was implemented
is the requirement of in-tree, hard-coded <name>.ucl, as
well as <name>-<suffix>.ucl where <suffix> can be lib32,
profile, development, debug, or any combination of the four.

This created significant overhead when adding new packages
and any of the files in any of the combinations were missing.

Instead of test(1)-ing if the <packagename>.ucl file exists,
hand off to a script to figure out what the final ucl file
name should be before invoking pkg(8).

The default behavior is 'template.ucl' is used as a fallback.

This affects only the userland packages, as the kernel code
is already smart enough to handle these variations.

Sponsored by:	The FreeBSD Foundation
2016-02-04 15:32:03 +00:00

139 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
main() {
desc=
comment=
debug=
uclsource=
while getopts "do:s:u:" arg; do
case ${arg} in
d)
debug=1
;;
o)
outname="${OPTARG}"
origname="${OPTARG}"
;;
s)
srctree="${OPTARG}"
;;
u)
uclfile="${OPTARG}"
;;
*)
echo "Unknown argument"
;;
esac
done
shift $(( ${OPTIND} - 1 ))
outname="$(echo ${outname} | tr '-' '_')"
case "${outname}" in
*_lib32_development)
outname="${outname%%_lib32_development}"
_descr="32-bit Libraries, Development Files"
pkgdeps="${outname}"
;;
*_lib32_debug)
outname="${outname%%_lib32_debug}"
_descr="32-bit Libraries, Debugging Symbols"
pkgdeps="${outname}"
;;
*_lib32_profile)
outname="${outname%%_lib32_profile}"
_descr="32-bit Libraries, Profiling"
pkgdeps="${outname}"
;;
*_lib32)
outname="${outname%%_lib32}"
_descr="32-bit Libraries"
pkgdeps="${outname}"
;;
*_development)
outname="${outname%%_development}"
_descr="Development Files"
pkgdeps="${outname}"
;;
*_profile)
outname="${outname%%_profile}"
_descr="Profiling Libraries"
pkgdeps="${outname}"
;;
*_debug)
outname="${outname%%_debug}"
_descr="Debugging Symbols"
pkgdeps="${outname}"
;;
*_manuals)
outname="${origname}"
pkgdeps="runtime"
;;
runtime)
outname="runtime"
uclfile="${uclfile}"
;;
${origname})
pkgdeps="runtime"
;;
debug|development|lib32|profile)
uclfile="${outname##*}${uclfile}"
;;
*)
uclfile="${outname##*}${origname}"
outname="${outname##*}${origname}"
;;
esac
outname="${outname%%_*}"
desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)"
comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)"
uclsource="${srctree}/release/packages/${outname}.ucl"
if [ ! -e "${uclsource}" ]; then
uclsource="${srctree}/release/packages/template.ucl"
fi
if [ ! -z "${debug}" ]; then
echo ""
echo "==============================================================="
echo "DEBUG:"
echo "_descr=${_descr}"
echo "outname=${outname}"
echo "origname=${origname}"
echo "srctree=${srctree}"
echo "uclfile=${uclfile}"
echo "desc=${desc}"
echo "comment=${comment}"
echo "cp ${uclsource} -> ${uclfile}"
echo "==============================================================="
echo ""
echo ""
echo ""
fi
[ -z "${comment}" ] && comment="${outname} package"
[ ! -z "${_descr}" ] && comment="${comment} (${_descr})"
[ -z "${desc}" ] && desc="${outname} package"
cp "${uclsource}" "${uclfile}"
cap_arg="$(make -C ${srctree}/etc -VCAP_MKDB_ENDIAN)"
pwd_arg="$(make -C ${srctree}/etc -VPWD_MKDB_ENDIAN)"
sed -i '' -e "s/%VERSION%/${PKG_VERSION}/" \
-e "s/%PKGNAME%/${origname}/" \
-e "s/%COMMENT%/${comment}/" \
-e "s/%DESC%/${desc}/" \
-e "s/%CAP_MKDB_ENDIAN%/${cap_arg}/g" \
-e "s/%PWD_MKDB_ENDIAN%/${pwd_arg}/g" \
-e "s/%PKGDEPS%/${pkgdeps}/" \
${uclfile}
return 0
}
main "${@}"