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