xref: /freebsd/release/packages/generate-ucl.sh (revision 656d68a711952ac2b92ed258502978c5ba1dbc73)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6main() {
7	desc=
8	comment=
9	debug=
10	uclsource=
11	while getopts "do:s:u:" arg; do
12		case ${arg} in
13		d)
14			debug=1
15			;;
16		o)
17			outname="${OPTARG}"
18			origname="${OPTARG}"
19			;;
20		s)
21			srctree="${OPTARG}"
22			;;
23		u)
24			uclfile="${OPTARG}"
25			;;
26		*)
27			echo "Unknown argument"
28			;;
29		esac
30	done
31
32	shift $(( ${OPTIND} - 1 ))
33
34	vital="false"
35
36	case "${outname}" in
37		bootloader)
38			pkgdeps=""
39			;;
40		clibs)
41			vital="true"
42			# clibs should not have any dependencies or anything
43			# else imposed on it.
44			;;
45		caroot)
46			pkgdeps="openssl"
47			;;
48		utilities)
49			uclfile="${uclfile}"
50			;;
51		runtime)
52			outname="runtime"
53			_descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)"
54			vital="true"
55			;;
56		*-lib32_dev)
57			outname="${outname%%-lib32_dev}"
58			_descr="32-bit Libraries, Development Files"
59			pkgdeps="${outname}"
60			;;
61		*-lib32_dbg)
62			outname="${outname%%-lib32_dbg}"
63			_descr="32-bit Libraries, Debugging Symbols"
64			pkgdeps="${outname}"
65			;;
66		*-lib32)
67			outname="${outname%%-lib32}"
68			_descr="32-bit Libraries"
69			pkgdeps="${outname}"
70			;;
71		*-dev)
72			outname="${outname%%-dev}"
73			_descr="Development Files"
74			pkgdeps="${outname}"
75			;;
76		*-dbg)
77			outname="${outname%%-dbg}"
78			_descr="Debugging Symbols"
79			pkgdeps="${outname}"
80			;;
81		*-man)
82			outname="${outname%%-man}"
83			_descr="Manual Pages"
84			pkgdeps="${outname}"
85			;;
86		${origname})
87			pkgdeps="runtime"
88			;;
89		*)
90			uclfile="${outname##*}${origname}"
91			outname="${outname##*}${origname}"
92			;;
93	esac
94
95	desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)"
96	comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)"
97
98	uclsource="${srctree}/release/packages/${outname}.ucl"
99	if [ ! -e "${uclsource}" ]; then
100		uclsource="${srctree}/release/packages/template.ucl"
101	fi
102
103	if [ ! -z "${debug}" ]; then
104		echo ""
105		echo "==============================================================="
106		echo "DEBUG:"
107		echo "_descr=${_descr}"
108		echo "outname=${outname}"
109		echo "origname=${origname}"
110		echo "srctree=${srctree}"
111		echo "uclfile=${uclfile}"
112		echo "desc=${desc}"
113		echo "comment=${comment}"
114		echo "vital=${vital}"
115		echo "cp ${uclsource} -> ${uclfile}"
116		echo "==============================================================="
117		echo ""
118		echo ""
119		echo ""
120	fi
121
122	[ -z "${comment}" ] && comment="${outname} package"
123	[ ! -z "${_descr}" ] && comment="${comment} (${_descr})"
124	[ -z "${desc}" ] && desc="${outname} package"
125
126	cp "${uclsource}" "${uclfile}"
127	if [ ! -z "${pkgdeps}" ]; then
128		cat <<EOF >> ${uclfile}
129deps: {
130	FreeBSD-${pkgdeps}: {
131		origin: "base",
132		version: "${PKG_VERSION}"
133	}
134}
135EOF
136	fi
137	cap_arg="$( make -f ${srctree}/share/mk/bsd.endian.mk -VCAP_MKDB_ENDIAN )"
138	sed -i '' -e "s/%VERSION%/${PKG_VERSION}/" \
139		-e "s/%PKGNAME%/${origname}/" \
140		-e "s/%COMMENT%/${comment}/" \
141		-e "s/%DESC%/${desc}/" \
142		-e "s/%VITAL%/${vital}/" \
143		-e "s/%CAP_MKDB_ENDIAN%/${cap_arg}/g" \
144		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
145		-e "s|%PKG_WWW%|${PKG_WWW}|" \
146		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
147		${uclfile}
148	return 0
149}
150
151main "${@}"
152