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