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