xref: /freebsd/release/packages/generate-ucl.sh (revision 657729a89dd578d8cfc70d6616f5c65a48a8b33a)
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
49		# -dev packages that have no corresponding non-dev package
50		# as a dependency.
51		liby-dev)
52			outname=${outname%%-dev}
53			_descr="Development Files"
54			;;
55		liby-lib32_dev)
56			outname=${outname%%-lib32_dev}
57			_descr="32-bit Libraries, Development Files"
58			;;
59
60		utilities)
61			uclfile="${uclfile}"
62			;;
63		runtime)
64			outname="runtime"
65			_descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)"
66			vital="true"
67			;;
68		*-lib32_dev)
69			outname="${outname%%-lib32_dev}"
70			_descr="32-bit Libraries, Development Files"
71			pkgdeps="${outname}"
72			;;
73		*-lib32_dbg)
74			outname="${outname%%-lib32_dbg}"
75			_descr="32-bit Libraries, Debugging Symbols"
76			pkgdeps="${outname}"
77			;;
78		*-lib32)
79			outname="${outname%%-lib32}"
80			_descr="32-bit Libraries"
81			pkgdeps="${outname}"
82			;;
83		*-dev)
84			outname="${outname%%-dev}"
85			_descr="Development Files"
86			pkgdeps="${outname}"
87			;;
88		*-dbg)
89			outname="${outname%%-dbg}"
90			_descr="Debugging Symbols"
91			pkgdeps="${outname}"
92			;;
93		*-man)
94			outname="${outname%%-man}"
95			_descr="Manual Pages"
96			pkgdeps="${outname}"
97			;;
98		${origname})
99			pkgdeps="runtime"
100			;;
101		*)
102			uclfile="${outname##*}${origname}"
103			outname="${outname##*}${origname}"
104			;;
105	esac
106
107	desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)"
108	comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)"
109
110	uclsource="${srctree}/release/packages/${outname}.ucl"
111	if [ ! -e "${uclsource}" ]; then
112		uclsource="${srctree}/release/packages/template.ucl"
113	fi
114
115	if [ ! -z "${debug}" ]; then
116		echo ""
117		echo "==============================================================="
118		echo "DEBUG:"
119		echo "_descr=${_descr}"
120		echo "outname=${outname}"
121		echo "origname=${origname}"
122		echo "srctree=${srctree}"
123		echo "uclfile=${uclfile}"
124		echo "desc=${desc}"
125		echo "comment=${comment}"
126		echo "vital=${vital}"
127		echo "cp ${uclsource} -> ${uclfile}"
128		echo "==============================================================="
129		echo ""
130		echo ""
131		echo ""
132	fi
133
134	[ -z "${comment}" ] && comment="${outname} package"
135	[ ! -z "${_descr}" ] && comment="${comment} (${_descr})"
136	[ -z "${desc}" ] && desc="${outname} package"
137
138	cp "${uclsource}" "${uclfile}"
139	if [ ! -z "${pkgdeps}" ]; then
140		cat <<EOF >> ${uclfile}
141deps: {
142	FreeBSD-${pkgdeps}: {
143		origin: "base",
144		version: "${PKG_VERSION}"
145	}
146}
147EOF
148	fi
149	cap_arg="$( make -f ${srctree}/share/mk/bsd.endian.mk -VCAP_MKDB_ENDIAN )"
150	sed -i '' -e "s/%VERSION%/${PKG_VERSION}/" \
151		-e "s/%PKGNAME%/${origname}/" \
152		-e "s/%COMMENT%/${comment}/" \
153		-e "s/%DESC%/${desc}/" \
154		-e "s/%VITAL%/${vital}/" \
155		-e "s/%CAP_MKDB_ENDIAN%/${cap_arg}/g" \
156		-e "s/%PKG_NAME_PREFIX%/${PKG_NAME_PREFIX}/" \
157		-e "s|%PKG_WWW%|${PKG_WWW}|" \
158		-e "s/%PKG_MAINTAINER%/${PKG_MAINTAINER}/" \
159		${uclfile}
160	return 0
161}
162
163main "${@}"
164