xref: /freebsd/release/packages/generate-ucl.sh (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
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	outname="$(echo ${outname} | tr '-' '_')"
35
36	case "${outname}" in
37		runtime)
38			outname="runtime"
39			uclfile="${uclfile}"
40			;;
41		runtime_manuals)
42			outname="${origname}"
43			pkgdeps="runtime"
44			;;
45		runtime_*)
46			outname="${origname}"
47			uclfile="${outname##*}${uclfile}"
48			pkgdeps="runtime"
49			_descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)"
50			;;
51		jail_*)
52			outname="${origname}"
53			uclfile="${outname##*}${uclfile}"
54			pkgdeps="runtime"
55			_descr="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESCR)"
56			;;
57		*_lib32_development)
58			outname="${outname%%_lib32_development}"
59			_descr="32-bit Libraries, Development Files"
60			pkgdeps="${outname}"
61			;;
62		*_lib32_debug)
63			outname="${outname%%_lib32_debug}"
64			_descr="32-bit Libraries, Debugging Symbols"
65			pkgdeps="${outname}"
66			;;
67		*_lib32_profile)
68			outname="${outname%%_lib32_profile}"
69			_descr="32-bit Libraries, Profiling"
70			pkgdeps="${outname}"
71			;;
72		*_lib32)
73			outname="${outname%%_lib32}"
74			_descr="32-bit Libraries"
75			pkgdeps="${outname}"
76			;;
77		*_development)
78			outname="${outname%%_development}"
79			_descr="Development Files"
80			pkgdeps="${outname}"
81			;;
82		*_profile)
83			outname="${outname%%_profile}"
84			_descr="Profiling Libraries"
85			pkgdeps="${outname}"
86			;;
87		*_debug)
88			outname="${outname%%_debug}"
89			_descr="Debugging Symbols"
90			pkgdeps="${outname}"
91			;;
92		${origname})
93			pkgdeps="runtime"
94			;;
95		*)
96			uclfile="${outname##*}${origname}"
97			outname="${outname##*}${origname}"
98			;;
99	esac
100
101	outname="${outname%%_*}"
102
103	desc="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_DESC)"
104	comment="$(make -C ${srctree}/release/packages -f Makefile.package -V ${outname}_COMMENT)"
105
106	uclsource="${srctree}/release/packages/${outname}.ucl"
107	if [ ! -e "${uclsource}" ]; then
108		uclsource="${srctree}/release/packages/template.ucl"
109	fi
110
111	if [ ! -z "${debug}" ]; then
112		echo ""
113		echo "==============================================================="
114		echo "DEBUG:"
115		echo "_descr=${_descr}"
116		echo "outname=${outname}"
117		echo "origname=${origname}"
118		echo "srctree=${srctree}"
119		echo "uclfile=${uclfile}"
120		echo "desc=${desc}"
121		echo "comment=${comment}"
122		echo "cp ${uclsource} -> ${uclfile}"
123		echo "==============================================================="
124		echo ""
125		echo ""
126		echo ""
127	fi
128
129	[ -z "${comment}" ] && comment="${outname} package"
130	[ ! -z "${_descr}" ] && comment="${comment} (${_descr})"
131	[ -z "${desc}" ] && desc="${outname} package"
132
133	cp "${uclsource}" "${uclfile}"
134	cap_arg="$(make -C ${srctree}/etc -VCAP_MKDB_ENDIAN)"
135	pwd_arg="$(make -C ${srctree}/etc -VPWD_MKDB_ENDIAN)"
136	sed -i '' -e "s/%VERSION%/${PKG_VERSION}/" \
137		-e "s/%PKGNAME%/${origname}/" \
138		-e "s/%COMMENT%/${comment}/" \
139		-e "s/%DESC%/${desc}/" \
140		-e "s/%CAP_MKDB_ENDIAN%/${cap_arg}/g" \
141		-e "s/%PWD_MKDB_ENDIAN%/${pwd_arg}/g" \
142		-e "s/%PKGDEPS%/${pkgdeps}/" \
143		${uclfile}
144	return 0
145}
146
147main "${@}"
148