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