1#!/bin/sh
2
3set -o pipefail
4
5if [ -z "${FAKE_DESTDIR}" -o -z "${PREFIX}" -o -z "${LOCALBASE}" ]; then
6	echo "FAKE_DESTDIR, PREFIX, LOCALBASE required in environment." >&2
7	exit 1
8fi
9
10[ -n "${DEBUG_MK_SCRIPTS}" -o -n "${DEBUG_MK_SCRIPTS_QA}" ] && set -x
11
12LF=$(printf '\nX')
13LF=${LF%X}
14
15notice() {
16	echo "Notice: $*" >&2
17}
18
19warn() {
20	echo "Warning: $*" >&2
21}
22
23err() {
24	echo "Error: $*" >&2
25}
26
27list_stagedir_elfs() {
28	cd ${FAKE_DESTDIR} && find -s . -type f \( -perm +111 -o -name '*.so*' \) "$@"
29}
30
31shebangonefile() {
32	local f interp interparg badinterp rc
33
34	f="$*"
35	rc=0
36
37	# whitelist some files
38	case "${f}" in
39	*.pm|*.pod|*.txt|${FAKE_DESTDIR}${LINUXBASE}/*)
40		return 0
41		;;
42	esac
43
44	interp=$(sed -n -e '1s/^#![[:space:]]*\([^[:space:]]*\).*/\1/p;2q' "${f}")
45	badinterp=""
46	case "${interp}" in
47	"") ;;
48	/bin/rc)
49		# whitelist some interpreters
50		;;
51	${LOCALBASE}/bin/python|${PREFIX}/bin/python|${LOCALBASE}/bin/python2|${PREFIX}/bin/python2|${LOCALBASE}/bin/python3|${PREFIX}/bin/python3)
52		badinterp="${interp}"
53		;;
54	${LINUXBASE}/*) ;;
55	${LOCALBASE}/bin/perl5.* | ${PREFIX}/bin/perl5.*)
56		# lang/perl5* are allowed to have these shebangs.
57		if ! expr ${PKGORIGIN} : '^lang/perl5.*' > /dev/null; then
58			err "'${interp}' is an invalid shebang for '${f#${FAKE_DESTDIR}${PREFIX}/}' you must use ${LOCALBASE}/bin/perl."
59			err "Either pass \${PERL} to the build or use USES=shebangfix"
60			rc=1
61		fi
62		;;
63	${LOCALBASE}/*) ;;
64	${PREFIX}/*) ;;
65	/bin/csh) ;;
66	/bin/ksh) ;;
67	/bin/mksh) ;;
68	/bin/sh) ;;
69	/bin/tcsh) ;;
70	/usr/bin/awk) ;;
71	/usr/bin/env)
72		interparg=$(sed -n -e '1s/^#![[:space:]]*[^[:space:]]*[[:space:]]*\([^[:space:]]*\).*/\1/p;2q' "${f}")
73		case "${interparg}" in
74		python|python2|python3)
75			badinterp="${interp} ${interparg}"
76			;;
77		esac
78		;;
79	/usr/bin/nawk) ;;
80	/usr/bin/sed) ;;
81	/usr/sbin/dtrace) ;;
82	/usr/bin/make) ;;
83	/usr/libexec/atf-sh) ;;
84	*)
85		badinterp="${interp}"
86		;;
87	esac
88
89	if [ -n "${badinterp}" ]; then
90		err "'${badinterp}' is an invalid shebang you need USES=shebangfix for '${f#${FAKE_DESTDIR}${PREFIX}/}'"
91		rc=1
92	fi
93
94	return ${rc}
95}
96
97shebang() {
98	local f l link rc
99
100	rc=0
101
102	while read -r f; do
103		# No results presents a blank line from heredoc.
104		[ -z "${f}" ] && continue
105		shebangonefile "${f}" || rc=1
106	# Use heredoc to avoid losing rc from find|while subshell
107	done <<-EOF
108	$(find ${FAKE_DESTDIR}${PREFIX} \
109	    -type f -perm +111 2>/dev/null)
110	EOF
111
112	return ${rc}
113}
114
115baselibs() {
116	local rc
117	local found_openssl
118	local file
119	while read -r f; do
120		case ${f} in
121		File:\ .*)
122			file=${f#File: .}
123			;;
124		*NEEDED*\[libarchive.so.[56]])
125			err "Bad linking on ${f##* } for ${file} please add USES=libarchive"
126			rc=1
127			;;
128		*NEEDED*\[libedit.so.7])
129			err "Bad linking on ${f##* } for ${file} please add USES=libedit"
130			rc=1
131			;;
132		*NEEDED*\[libcrypto.so.*]|*NEEDED*\[libssl.so.*])
133			found_openssl=1
134			;;
135		esac
136	done <<-EOF
137	$(list_stagedir_elfs -exec readelf -d {} + 2>/dev/null)
138	EOF
139
140	if ! list_stagedir_elfs | egrep -q 'lib(crypto|ssl).so*'; then
141		if [ -z "${USESSSL}" -a -n "${found_openssl}" ]; then
142			warn "you need USES=ssl"
143		elif [ -n "${USESSSL}" -a -z "${found_openssl}" ]; then
144			warn "you may not need USES=ssl"
145		fi
146	fi
147	return ${rc}
148}
149
150symlinks() {
151	local rc
152
153	rc=0
154
155	# Split stat(1) result into 2 lines and read each line separately to
156	# retain spaces in filenames.
157	while read -r l; do
158		# No results presents a blank line from heredoc.
159		[ -z "${l}" ] && continue
160		read -r link
161		case "${link}" in
162			${FAKE_DESTDIR}*)
163				warn "Bad symlink '${l#${FAKE_DESTDIR}${PREFIX}/}' pointing inside the stage directory"
164				;;
165			/*)
166				# Only warn for symlinks within the package.
167				if [ -e "${FAKE_DESTDIR}${link}" ]; then
168					warn "Bad symlink '${l#${FAKE_DESTDIR}}' pointing to an absolute pathname '${link}'"
169				fi
170				# Also warn if the symlink exists nowhere.
171				if [ ! -e "${FAKE_DESTDIR}${link}" -a ! -e "${link}" ]; then
172					warn "Symlink '${l#${FAKE_DESTDIR}}' pointing to '${link}' which does not exist in the stage directory or in localbase"
173				fi
174				;;
175		esac
176	# Use heredoc to avoid losing rc from find|while subshell.
177	done <<-EOF
178	$(find ${FAKE_DESTDIR} -type l -exec stat -f "%N${LF}%Y" {} +)
179	EOF
180
181	return ${rc}
182}
183
184paths() {
185	local rc
186
187	rc=0
188
189	while read -r f; do
190		# No results presents a blank line from heredoc.
191		[ -z "${f}" ] && continue
192		# Ignore false-positive/harmless files
193		case "${f}" in
194			*/lib/ruby/gems/*) continue ;;
195			*/share/texmf-var/web2c/*/*.fmt) continue ;;
196			*/share/texmf-var/web2c/*/*.log) continue ;;
197		esac
198		err "'${f#${FAKE_DESTDIR}${PREFIX}/}' is referring to ${FAKE_DESTDIR}"
199		rc=1
200	# Use heredoc to avoid losing rc from find|while subshell
201	done <<-EOF
202	$(find ${TMPPLIST} ${FAKE_DESTDIR} -type f -exec grep -l "${FAKE_DESTDIR}" {} +)
203	EOF
204
205	return ${rc}
206}
207
208# For now do not raise an error, just warnings
209stripped() {
210	[ -x /usr/bin/file ] || return # this is fatal
211	[ -n "${STRIP}" ] || return 0
212	# Split file and result into 2 lines and read separately to ensure
213	# files with spaces are kept intact.
214	# Using readelf -h ... /ELF Header:/ will match on all ELF files.
215	find ${FAKE_DESTDIR} -type f ! -name '*.a' ! -name '*.o' \
216	    -exec sh -c 'readelf -S -- /dev/null "$0" "$@" || :' -- {} + 2>/dev/null | awk '
217	    /File:/ {sub(/File: /, "", $0); file=$0}
218	    /[[:space:]]\.debug_info[[:space:]]*PROGBITS/ {print file}' |
219	    while read -r f; do
220		warn "'${f#${FAKE_DESTDIR}${PREFIX}/}' is not stripped consider trying INSTALL_TARGET=install-strip or using \${STRIP_CMD}"
221	done
222}
223
224desktopfileutils() {
225	if [ -z "${USESDESKTOPFILEUTILS}" ]; then
226		grep -q MimeType= ${FAKE_DESTDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null &&
227		warn "you need USES=desktop-file-utils"
228	else
229		grep -q MimeType= ${FAKE_DESTDIR}${PREFIX}/share/applications/*.desktop 2>/dev/null ||
230		warn "you may not need USES=desktop-file-utils"
231	fi
232	return 0
233}
234
235sharedmimeinfo() {
236	local f found
237
238	found=0
239	for f in ${FAKE_DESTDIR}${PREFIX}/share/mime/packages/*.xml; do
240		[ "${f}" = "${FAKE_DESTDIR}${PREFIX}/share/mime/packages/*.xml" ] && break #no matches
241		[ "${f}" = "${FAKE_DESTDIR}${PREFIX}/share/mime/packages/freedesktop.org.xml" ] && continue
242		found=1
243		break
244	done
245	if [ -z "${USESSHAREDMIMEINFO}" -a ${found} -eq 1 ]; then
246		warn "you need USES=shared-mime-info"
247	elif [ -n "${USESSHAREDMIMEINFO}" -a ${found} -eq 0 ]; then
248		warn "you may not need USES=shared-mime-info"
249	fi
250	return 0
251}
252
253suidfiles() {
254	local filelist
255
256	filelist=$(find ${FAKE_DESTDIR} -type f \
257		\( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
258		\( -perm -u+s -or -perm -g+s \))
259	if [ -n "${filelist}" ]; then
260		warn "setuid files in the stage directory (are these necessary?):"
261		ls -liTd ${filelist}
262	fi
263	return 0
264}
265
266libtool() {
267	if [ -z "${USESLIBTOOL}" ]; then
268		find ${FAKE_DESTDIR} -name '*.la' | while read -r f; do
269			if grep -q 'libtool library' "${f}"; then
270				err ".la libraries found, port needs USES=libtool"
271				return 1
272			fi
273		done
274		# The return above continues here.
275	fi
276}
277
278libperl() {
279	local has_some_libperl_so files found
280	if [ -n "${SITE_ARCH_REL}" -a -d "${FAKE_DESTDIR}${PREFIX}/${SITE_ARCH_REL}" ]; then
281		has_some_libperl_so=0
282		files=0
283		while read -r f; do
284			# No results presents a blank line from heredoc.
285			[ -z "${f}" ] && continue
286			files=$((files+1))
287			found=$(readelf -d ${f} | awk "BEGIN {libperl=1}
288				/NEEDED.*${LIBPERL}/  { libperl = 0 }
289				END {print libperl}
290				")
291			case "${found}" in
292				1)
293					warn "${f} is not linked with ${LIBPERL}, not respecting lddlflags?"
294					;;
295				0)
296					has_some_libperl_so=1
297					;;
298			esac
299		# Use heredoc to avoid losing rc from find|while subshell
300		done <<-EOT
301		$(find ${FAKE_DESTDIR}${PREFIX}/${SITE_ARCH_REL} -name '*.so')
302		EOT
303
304		if [ ${files} -gt 0 -a ${has_some_libperl_so} -eq 0 ]; then
305			err "None of the ${files} .so in ${FAKE_DESTDIR}${PREFIX}/${SITE_ARCH_REL} are linked with ${LIBPERL}, see above for the full list."
306			return 1
307		else
308			return 0
309		fi
310	fi
311}
312
313prefixvar() {
314	if [ ${PREFIX} != ${LINUXBASE} -a -d ${FAKE_DESTDIR}${PREFIX}/var ]; then
315		warn "port uses ${PREFIX}/var instead of /var"
316	fi
317}
318
319terminfo() {
320	local f found
321
322	for f in ${FAKE_DESTDIR}${PREFIX}/share/misc/*.terminfo; do
323		[ "${f}" = "${FAKE_DESTDIR}${PREFIX}/share/misc/*.terminfo" ] && break #no matches
324		found=1
325		break
326	done
327	for f in ${FAKE_DESTDIR}${PREFIX}/share/misc/terminfo.db*; do
328		[ "${f}" = "${FAKE_DESTDIR}${PREFIX}/share/misc/terminfo.db*" ] && break #no matches
329		found=1
330		break
331	done
332	if [ -z "${USESTERMINFO}" -a -n "${found}" ]; then
333		warn "you need USES=terminfo"
334	elif [ -n "${USESTERMINFO}" -a -z "${found}" ]; then
335		warn "you may not need USES=terminfo"
336	fi
337	return 0
338}
339
340listcontains() {
341	local str lst elt
342	str=$1
343	lst=$2
344
345	for elt in ${lst} ; do
346		if [ ${elt} = ${str} ]; then
347			return 0
348		fi
349	done
350	return 1
351}
352
353proxydeps_suggest_uses() {
354	local pkg=$1
355	local lib_file=$2
356
357	# miscellaneous USE clauses
358	if [ ${pkg} = 'devel/gettext-runtime' ]; then
359		warn "you need USES+=gettext-runtime"
360	elif [ ${pkg} = 'databases/sqlite3' ]; then
361		warn "you need USES+=sqlite"
362	elif [ ${pkg} = 'databases/sqlite2' ]; then
363		warn "you need USES+=sqlite:2"
364	# Gnome -> same as port
365	# grep LIB_DEPENDS= Mk/extensions/gnome.mk |sed -e 's|\(.*\)_LIB_DEPENDS.*:\(.*\)\/\(.*\)|[ "\1" = "\3" ] \&\& echo "\\${pkg} = \\\"\2/\3\\\" -o \\\\"|'|sort|sh
366	elif [ ${pkg} = "accessibility/atk" -o \
367		${pkg} = "accessibility/atkmm" -o \
368		${pkg} = "graphics/cairo" -o \
369		${pkg} = "graphics/cairomm" -o \
370		${pkg} = "devel/dconf" -o \
371		${pkg} = "devel/gconf2" -o \
372		${pkg} = "devel/glib20" -o \
373		${pkg} = "devel/glibmm" -o \
374		${pkg} = "audio/gsound" -o \
375		${pkg} = "x11-toolkits/gtk20" -o \
376		${pkg} = "x11-toolkits/gtk30" -o \
377		${pkg} = "www/gtkhtml4" -o \
378		${pkg} = "x11-toolkits/gtkmm20" -o \
379		${pkg} = "x11-toolkits/gtkmm24" -o \
380		${pkg} = "x11-toolkits/gtkmm30" -o \
381		${pkg} = "x11-toolkits/gtksourceview2" -o \
382		${pkg} = "x11-toolkits/gtksourceview3" -o \
383		${pkg} = "x11-toolkits/gtksourceviewmm3" -o \
384		${pkg} = "databases/libgda5" -o \
385		${pkg} = "databases/libgda5-ui" -o \
386		${pkg} = "devel/libglade2" -o \
387		${pkg} = "graphics/libgnomecanvas" -o \
388		${pkg} = "x11/libgnomekbd" -o \
389		${pkg} = "devel/libgsf" -o \
390		${pkg} = "graphics/librsvg2" -o \
391		${pkg} = "devel/libsigc++12" -o \
392		${pkg} = "devel/libsigc++20" -o \
393		${pkg} = "x11-toolkits/libwnck" -o \
394		${pkg} = "x11-toolkits/libwnck3" -o \
395		${pkg} = "textproc/libxml++26" -o \
396		${pkg} = "textproc/libxml2" -o \
397		${pkg} = "textproc/libxslt" -o \
398		${pkg} = "x11-toolkits/pango" -o \
399		${pkg} = "x11-toolkits/pangomm" -o \
400		${pkg} = "x11-toolkits/pangox-compat" -o \
401		${pkg} = "x11-toolkits/vte" -o \
402		${pkg} = "x11-toolkits/vte3" ]; then
403		warn "you need USE_GNOME+=${pkg#*/}"
404	# Gnome different as port
405	# grep LIB_DEPENDS= Mk/extensions/gnome.mk |sed -e 's|\(.*\)_LIB_DEPENDS.*:\(.*\)\/\(.*\)|[ "\1" = "\3" ] \|\| echo "elif [ \\${pkg} = \\\"\2/\3\\\" ]; then; warn \\\"you need USE_GNOME+=\1\\\""|'|sort|sh
406	elif [ ${pkg} = "databases/evolution-data-server" ]; then warn "you need USE_GNOME+=evolutiondataserver3"
407	elif [ ${pkg} = "graphics/gdk-pixbuf" ]; then warn "you need USE_GNOME+=gdkpixbuf"
408	elif [ ${pkg} = "graphics/gdk-pixbuf2" ]; then warn "you need USE_GNOME+=gdkpixbuf"
409	elif [ ${pkg} = "x11/gnome-desktop" ]; then warn "you need USE_GNOME+=gnomedesktop3"
410	elif [ ${pkg} = "devel/gobject-introspection" ]; then warn "you need USE_GNOME+=introspection"
411	elif [ ${pkg} = "graphics/libart_lgpl" ]; then warn "you need USE_GNOME+=libartlgpl2"
412	elif [ ${pkg} = "devel/libIDL" ]; then warn "you need USE_GNOME+=libidl"
413	elif [ ${pkg} = "x11-fm/nautilus" ]; then warn "you need USE_GNOME+=nautilus4"
414	elif [ ${pkg} = "graphics/librsvg2-rust" ]; then warn "you need USE_GNOME+=librsvg2"
415	# mate
416	# grep LIB_DEPENDS= Mk/extensions/mate.mk |sed -e 's|\(.*\)_LIB_DEPENDS.*:\(.*\)\/\(.*\)|elif [ ${pkg} = "\2/\3" ]; then warn "you need USE_MATE+=\1"|'
417	elif [ ${pkg} = "x11-fm/caja" ]; then warn "you need USE_MATE+=caja"
418	elif [ ${pkg} = "sysutils/mate-control-center" ]; then warn "you need USE_MATE+=controlcenter"
419	elif [ ${pkg} = "x11/mate-desktop" ]; then warn "you need USE_MATE+=desktop"
420	elif [ ${pkg} = "x11/libmatekbd" ]; then warn "you need USE_MATE+=libmatekbd"
421	elif [ ${pkg} = "net/libmateweather" ]; then warn "you need USE_MATE+=libmateweather"
422	elif [ ${pkg} = "x11-wm/marco" ]; then warn "you need USE_MATE+=marco"
423	elif [ ${pkg} = "x11/mate-menus" ]; then warn "you need USE_MATE+=menus"
424	elif [ ${pkg} = "x11/mate-panel" ]; then warn "you need USE_MATE+=panel"
425	elif [ ${pkg} = "sysutils/mate-polkit" ]; then warn "you need USE_MATE+=polkit"
426	# KDE
427	# grep -B1 _LIB= Mk/extensions/kde.mk | grep _PORT=|sed -e 's/^kde-\(.*\)_PORT=[[:space:]]*\([^[:space:]]*\).*/elif [ ${pkg} = "\2" ]; then warn "you need to use USE_KDE+=\1"/'
428	# KDE Applications
429	elif [ ${pkg} = "net/akonadi-contacts" ]; then warn "you need to use USE_KDE+=akonadicontacts"
430	elif [ ${pkg} = "deskutils/akonadi-import-wizard" ]; then warn "you need to use USE_KDE+=akonadiimportwizard"
431	elif [ ${pkg} = "net/akonadi-mime" ]; then warn "you need to use USE_KDE+=akonadimime"
432	elif [ ${pkg} = "net/akonadi-notes" ]; then warn "you need to use USE_KDE+=akonadinotes"
433	elif [ ${pkg} = "net/akonadi-calendar" ]; then warn "you need to use USE_KDE+=akonadicalendar"
434	elif [ ${pkg} = "net/akonadi-search" ]; then warn "you need to use USE_KDE+=akonadisearch"
435	elif [ ${pkg} = "net/calendarsupport" ]; then warn "you need to use USE_KDE+=calendarsupport"
436	elif [ ${pkg} = "net/kcalcore" ]; then warn "you need to use USE_KDE+=calendarcore"
437	elif [ ${pkg} = "net/kcalutils" ]; then warn "you need to use USE_KDE+=calendarutils"
438	elif [ ${pkg} = "net/kcontacts" ]; then warn "you need to use USE_KDE+=contacts"
439	elif [ ${pkg} = "net/eventviews" ]; then warn "you need to use USE_KDE+=eventviews"
440	elif [ ${pkg} = "net/libkgapi" ]; then warn "you need to use USE_KDE+=gapi"
441	elif [ ${pkg} = "deskutils/grantleetheme" ]; then warn "you need to use USE_KDE+=grantleetheme"
442	elif [ ${pkg} = "net/libgravatar" ]; then warn "you need to use USE_KDE+=gravatar"
443	elif [ ${pkg} = "net/kidentitymanagement" ]; then warn "you need to use USE_KDE+=identitymanagement"
444	elif [ ${pkg} = "net/kimap" ]; then warn "you need to use USE_KDE+=imap"
445	elif [ ${pkg} = "net/incidenceeditor" ]; then warn "you need to use USE_KDE+=incidenceeditor"
446	elif [ ${pkg} = "deskutils/kdepim-apps-libs" ]; then warn "you need to use USE_KDE+=kdepim-apps-libs"
447	elif [ ${pkg} = "net/kitinerary" ]; then warn "you need to use USE_KDE+=kitinerary"
448	elif [ ${pkg} = "net/kontactinterface" ]; then warn "you need to use USE_KDE+=kontactinterface"
449	elif [ ${pkg} = "net/kf5-kdav" ]; then warn "you need to use USE_KDE+=kdav"
450	elif [ ${pkg} = "security/kpkpass" ]; then warn "you need to use USE_KDE+=kpkpass"
451	elif [ ${pkg} = "net/ksmtp" ]; then warn "you need to use USE_KDE+=ksmtp"
452	elif [ ${pkg} = "net/kldap" ]; then warn "you need to use USE_KDE+=ldap"
453	elif [ ${pkg} = "deskutils/libkdepim" ]; then warn "you need to use USE_KDE+=libkdepim"
454	elif [ ${pkg} = "security/libkleo" ]; then warn "you need to use USE_KDE+=libkleo"
455	elif [ ${pkg} = "net/libksieve" ]; then warn "you need to use USE_KDE+=libksieve"
456	elif [ ${pkg} = "net/mailcommon" ]; then warn "you need to use USE_KDE+=mailcommon"
457	elif [ ${pkg} = "net/mailimporter" ]; then warn "you need to use USE_KDE+=mailimporter"
458	elif [ ${pkg} = "net/kmailtransport" ]; then warn "you need to use USE_KDE+=mailtransport"
459	elif [ ${pkg} = "net/kmbox" ]; then warn "you need to use USE_KDE+=mbox"
460	elif [ ${pkg} = "net/messagelib" ]; then warn "you need to use USE_KDE+=messagelib"
461	elif [ ${pkg} = "net/kmime" ]; then warn "you need to use USE_KDE+=mime"
462	elif [ ${pkg} = "net/pimcommon" ]; then warn "you need to use USE_KDE+=pimcommon"
463	elif [ ${pkg} = "net/kpimtextedit" ]; then warn "you need to use USE_KDE+=pimtextedit"
464	elif [ ${pkg} = "net/ktnef" ]; then warn "you need to use USE_KDE+=tnef"
465	elif [ ${pkg} = "databases/akonadi" ]; then warn "you need to use USE_KDE+=akonadi"
466	elif [ ${pkg} = "sysutils/baloo-widgets" ]; then warn "you need to use USE_KDE+=baloo-widgets"
467	elif [ ${pkg} = "audio/libkcddb" ]; then warn "you need to use USE_KDE+=libkcddb"
468	elif [ ${pkg} = "audio/libkcompactdisc" ]; then warn "you need to use USE_KDE+=libkcompactdisc"
469	elif [ ${pkg} = "graphics/libkdcraw" ]; then warn "you need to use USE_KDE+=libkdcraw"
470	elif [ ${pkg} = "games/libkdegames" ]; then warn "you need to use USE_KDE+=libkdegames"
471	elif [ ${pkg} = "misc/libkeduvocdocument" ]; then warn "you need to use USE_KDE+=libkeduvocdocument"
472	elif [ ${pkg} = "graphics/libkexiv2" ]; then warn "you need to use USE_KDE+=libkexiv2"
473	elif [ ${pkg} = "graphics/libksane" ]; then warn "you need to use USE_KDE+=libksane"
474	elif [ ${pkg} = "astro/marble" ]; then warn "you need to use USE_KDE+=marble"
475	elif [ ${pkg} = "graphics/okular" ]; then warn "you need to use USE_KDE+=okular"
476	# KDE Plasma
477	elif [ ${pkg} = "x11/plasma5-kactivitymanagerd" ]; then warn "you need to use USE_KDE+=activitymanagerd"
478	elif [ ${pkg} = "x11-wm/plasma5-kdecoration" ]; then warn "you need to use USE_KDE+=decoration"
479	elif [ ${pkg} = "devel/plasma5-khotkeys" ]; then warn "you need to use USE_KDE+=hotkeys"
480	elif [ ${pkg} = "sysutils/plasma5-kmenuedit" ]; then warn "you need to use USE_KDE+=kmenuedit"
481	elif [ ${pkg} = "security/plasma5-kscreenlocker" ]; then warn "you need to use USE_KDE+=kscreenlocker"
482	elif [ ${pkg} = "x11/plasma5-libkscreen" ]; then warn "you need to use USE_KDE+=libkscreen"
483	elif [ ${pkg} = "sysutils/plasma5-libksysguard" ]; then warn "you need to use USE_KDE+=libksysguard"
484	elif [ ${pkg} = "deskutils/plasma5-milou" ]; then warn "you need to use USE_KDE+=milou"
485	elif [ ${pkg} = "x11-themes/plasma5-oxygen" ]; then warn "you need to use USE_KDE+=oxygen"
486	elif [ ${pkg} = "x11/plasma5-plasma-workspace" ]; then warn "you need to use USE_KDE+=plasma-workspace"
487	elif [ ${pkg} = "sysutils/plasma5-powerdevil" ]; then warn "you need to use USE_KDE+=powerdevil"
488	# KDE Frameworks
489	elif [ ${pkg} = "x11-toolkits/kf5-attica" ]; then warn "you need to use USE_KDE+=attica"
490	elif [ ${pkg} = "sysutils/kf5-baloo" ]; then warn "you need to use USE_KDE+=baloo"
491	elif [ ${pkg} = "x11/kf5-frameworkintegration" ]; then warn "you need to use USE_KDE+=frameworkintegration"
492	elif [ ${pkg} = "devel/kf5-kcmutils" ]; then warn "you need to use USE_KDE+=kcmutils"
493	elif [ ${pkg} = "devel/kf5-kdeclarative" ]; then warn "you need to use USE_KDE+=kdeclarative"
494	elif [ ${pkg} = "x11/kf5-kded" ]; then warn "you need to use USE_KDE+=kded"
495	elif [ ${pkg} = "x11/kf5-kdelibs4support" ]; then warn "you need to use USE_KDE+=kdelibs4support"
496	elif [ ${pkg} = "security/kf5-kdesu" ]; then warn "you need to use USE_KDE+=kdesu"
497	elif [ ${pkg} = "www/kf5-khtml" ]; then warn "you need to use USE_KDE+=khtml"
498	elif [ ${pkg} = "devel/kf5-kio" ]; then warn "you need to use USE_KDE+=kio"
499	elif [ ${pkg} = "lang/kf5-kross" ]; then warn "you need to use USE_KDE+=kross"
500	elif [ ${pkg} = "x11/kf5-plasma-framework" ]; then warn "you need to use USE_KDE+=plasma-framework"
501	elif [ ${pkg} = "graphics/kf5-prison" ]; then warn "you need to use USE_KDE+=prison"
502	elif [ ${pkg} = "misc/kf5-purpose" ]; then warn "you need to use USE_KDE+=purpose"
503	elif [ ${pkg} = "devel/kf5-solid" ]; then warn "you need to use USE_KDE+=solid"
504	elif [ ${pkg} = "textproc/kf5-sonnet" ]; then warn "you need to use USE_KDE+=sonnet"
505	elif [ ${pkg} = "net/kf5-syndication" ]; then warn "you need to use USE_KDE+=syndication"
506	elif [ ${pkg} = "textproc/kf5-syntax-highlighting" ]; then warn "you need to use USE_KDE+=syntaxhighlighting"
507	elif [ ${pkg} = "devel/kf5-threadweaver" ]; then warn "you need to use USE_KDE+=threadweaver"
508	elif expr ${pkg} : '.*/kf5-.*' > /dev/null; then
509		warn "you need USE_KDE+=$(echo ${pkg} | sed -E 's|.*/kf5-k||')"
510	# GStreamer 0.10
511	elif [ ${pkg} = "multimedia/gstreamer" ]; then warn "you need to use USE_GSTREAMER+=yes"
512	elif [ ${pkg} = "multimedia/gstreamer-plugins" ]; then warn "you need to use USE_GSTREAMER+=yes"
513	elif [ ${pkg} = "multimedia/gstreamer-plugins-bad" ]; then warn "you need to use USE_GSTREAMER+=bad"
514	# GStreamer 1
515	elif [ ${pkg} = "multimedia/gstreamer1" ]; then warn "you need to use USE_GSTREAMER1+=yes"
516	elif [ ${pkg} = "multimedia/gstreamer1-plugins" ]; then warn "you need to use USE_GSTREAMER1+=yes"
517	elif [ ${pkg} = "multimedia/gstreamer1-plugins-bad" ]; then warn "you need to use USE_GSTREAMER1+=bad"
518	# boost related
519	elif [ ${pkg} = "devel/boost-python-libs" ]; then warn "you need to add LIB_DEPENDS+=\${PY_BOOST} and maybe USES+=python"
520	# sdl-related
521	elif [ ${pkg} = 'devel/sdl12' ]; then
522		warn "you need USE_SDL+=sdl"
523	elif echo ${pkg} | grep -E '/sdl_(console|gfx|image|mixer|mm|net|pango|sound|ttf)$' > /dev/null; then
524		warn "you need USE_SDL+=$(echo ${pkg} | sed -E 's|.*/sdl_||')"
525	elif [ ${pkg} = 'devel/sdl20' ]; then
526		warn "you need USE_SDL+=sdl2"
527	elif echo ${pkg} | grep -E '/sdl2_(gfx|image|mixer|net|ttf)$' > /dev/null; then
528		warn "you need USE_SDL+=$(echo ${pkg} | sed -E 's|.*/sdl2_||')2"
529	# gl-related
530	elif expr ${lib_file} : "${LOCALBASE}/lib/libGL.so.*$" > /dev/null; then
531		warn "you need USE_GL+=gl"
532	elif expr ${lib_file} : "${LOCALBASE}/lib/libGLX.so.*$" > /dev/null; then
533		warn "you need USE_GL+=gl"
534	elif expr ${lib_file} : "${LOCALBASE}/lib/libgbm.so.*$" > /dev/null; then
535		warn "you need USE_GL+=gbm"
536	elif expr ${lib_file} : "${LOCALBASE}/lib/libGLESv2.so.*$" > /dev/null; then
537		warn "you need USE_GL+=glesv2"
538	elif expr ${lib_file} : "${LOCALBASE}/lib/libEGL.so.*$" > /dev/null; then
539		warn "you need USE_GL+=egl"
540	elif expr ${lib_file} : "${LOCALBASE}/lib/libOpenGL.so.*$" > /dev/null; then
541		warn "you need USE_GL+=opengl"
542	elif [ ${pkg} = 'graphics/glew' ]; then
543		warn "you need USE_GL+=glew"
544	elif [ ${pkg} = 'graphics/libGLU' ]; then
545		warn "you need USE_GL+=glu"
546	elif [ ${pkg} = 'graphics/libGLw' ]; then
547		warn "you need USE_GL+=glw"
548	elif [ ${pkg} = 'graphics/freeglut' ]; then
549		warn "you need USE_GL+=glut"
550	# Xorg-libraries: this should be by XORG_MODULES @ bsd.xorg.mk
551	elif echo ${pkg} | grep -E '/lib(X11|Xau|Xdmcp|Xext|SM|ICE|Xfixes|Xft|Xdamage|Xcomposite|Xcursor|Xinerama|Xmu|Xmuu|Xpm|Xt|Xtst|Xi|Xrandr|Xrender|Xres|XScrnSaver|Xv|Xxf86vm|Xxf86dga|Xxf86misc|xcb)$' > /dev/null; then
552		warn "you need USE_XORG+=$(echo ${pkg} | sed -E 's|.*/lib||' | tr '[:upper:]' '[:lower:]')"
553	elif [ ${pkg} = 'x11/pixman' ]; then
554		warn "you need USE_XORG+=pixman"
555	# Qt5
556	elif expr ${pkg} : '.*/qt5-.*' > /dev/null; then
557		warn "you need USES=qt:5 and USE_QT+=$(echo ${pkg} | sed -E 's|.*/qt5-||')"
558	# Qt6
559	elif expr ${pkg} : '.*/qt6-.*' > /dev/null; then
560		warn "you need USES=qt:6 and USE_QT+=$(echo ${pkg} | sed -E 's|.*/qt6-||')"
561	# MySQL
562	elif expr ${lib_file} : "${LOCALBASE}/lib/mysql/[^/]*$" > /dev/null; then
563		warn "you need USES+=mysql"
564	# postgresql
565	elif expr ${pkg} : "^databases/postgresql.*-client" > /dev/null; then
566		warn "you need USES+=pgsql"
567	# bdb
568	elif expr ${pkg} : "^databases/db[456]" > /dev/null; then
569		warn "you need USES+=bdb"
570	# fam/gamin
571	elif [ ${pkg} = "devel/fam" -o ${pkg} = "devel/gamin" ]; then
572		warn "you need USES+=fam"
573	# firebird
574	elif [ ${pkg} = "databases/firebird25-client" ]; then
575		warn "you need USES+=firebird"
576	# fuse
577	elif [ ${pkg} = "filesystems/fusefs-libs" ]; then
578		warn "you need USES+=fuse"
579	# gnustep
580	elif [ ${pkg} = "lang/gnustep-base" ]; then
581		warn "you need USES+=gnustep and USE_GNUSTEP+=base"
582	elif [ ${pkg} = "x11-toolkits/gnustep-gui" ]; then
583		warn "you need USES+=gnustep and USE_GNUSTEP+=gui"
584	# iconv
585	elif [ ${pkg} = "converters/libiconv" ]; then
586		warn "you need USES+=iconv, USES+=iconv:wchar_t, or USES+=iconv:translit depending on needs"
587	# jpeg
588	elif [ ${pkg} = "graphics/jpeg-turbo" ]; then
589		warn "you need USES+=jpeg"
590	# libarchive
591	elif [ ${pkg} = "archivers/libarchive" ]; then
592		warn "you need USES+=libarchive"
593	elif [ ${pkg} = "devel/libedit" ]; then
594		warn "you need USES+=libedit"
595	# lua
596	elif expr ${pkg} : "^lang/lua" > /dev/null; then
597		warn "you need USES+=lua"
598	# magick
599	elif [ ${pkg} = "graphics/ImageMagick6" ] ; then
600		warn "you need USES=magick:6"
601	elif [ ${pkg} = "graphics/ImageMagick6-nox11" ] ; then
602		warn "you need USES=magick:6,nox11"
603	elif [ ${pkg} = "graphics/ImageMagick7" ] ; then
604		warn "you need USES=magick:7"
605	elif [ ${pkg} = "graphics/ImageMagick7-nox11" ] ; then
606		warn "you need USES=magick:7,nox11"
607	# motif
608	elif [ ${pkg} = "x11-toolkits/lesstif" -o ${pkg} = "x11-toolkits/open-motif" ]; then
609		warn "you need USES+=motif"
610	# ncurses
611	elif [ ${pkg} = "devel/ncurses" ]; then
612		warn "you need USES+=ncurses"
613	# objc
614	elif [ ${pkg} = "lang/libobjc2" ]; then
615		warn "you need USES+=objc"
616	# openal
617	elif [ ${pkg} = "audio/openal" -o ${pkg} = "audio/openal-soft" -o ${pkg} = "audio/freealut" ]; then
618		warn "you need USES+=openal"
619	# readline
620	elif [ ${pkg} = "devel/readline" ]; then
621		warn "you need USES+=readline"
622	# ssl
623	# When updating this, please also update the versions list in
624	# default-versions.mk and ssl.mk!
625	elif [ ${pkg} = "security/openssl" -o ${pkg} = "security/openssl111" \
626	  -o ${pkg} = "security/openssl31" -o ${pkg} = "security/openssl32" \
627	  -o ${pkg} = "security/openssl33" \
628	  -o ${pkg} = "security/libressl" -o ${pkg} = "security/libressl-devel" \
629	  ]; then
630		warn "you need USES=ssl"
631	# Tcl
632	elif expr ${pkg} : "^lang/tcl" > /dev/null; then
633		warn "you need USES+=tcl"
634	# Tk
635	elif expr ${pkg} : "^x11-toolkits/tk" > /dev/null; then
636		warn "you need USES+=tk"
637	# Xfce
638	# grep LIB_DEPENDS= Mk/Uses/xfce.mk |sed -e 's|\(.*\)_LIB_DEPENDS.*:\(.*\)\/\(.*\)|elif [ ${pkg} = "\2/\3" ]; then warn "you need USE_XFCE+=\1"|'
639	elif [ ${pkg} = "sysutils/garcon" ]; then warn "you need USE_XFCE+=garcon"
640	elif [ ${pkg} = "x11/libexo" ]; then warn "you need USE_XFCE+=libexo"
641	elif [ ${pkg} = "x11-toolkits/libxfce4gui" ]; then warn "you need USE_XFCE+=libgui"
642	elif [ ${pkg} = "x11/libxfce4menu" ]; then warn "you need USE_XFCE+=libmenu"
643	elif [ ${pkg} = "x11/libxfce4util" ]; then warn "you need USE_XFCE+=libutil"
644	elif [ ${pkg} = "x11-wm/xfce4-panel" ]; then warn "you need USE_XFCE+=panel"
645	elif [ ${pkg} = "x11-fm/thunar" ]; then warn "you need USE_XFCE+=thunar"
646	elif [ ${pkg} = "x11/xfce4-conf" ]; then warn "you need USE_XFCE+=xfconf"
647	# default
648	elif expr ${lib_file} : "${LOCALBASE}/lib/[^/]*$" > /dev/null; then
649		lib_file=${lib_file#${LOCALBASE}/lib/}
650		lib_file=${lib_file%.so*}.so
651		warn "you need LIB_DEPENDS+=${lib_file}:${pkg}"
652	fi
653}
654
655proxydeps() {
656	local file dep_file dep_file_pkg already rc dep_lib_file dep_lib_files
657
658	rc=0
659
660	# Check all dynamically linked ELF files
661	# Some .so are not executable, but we want to check them too.
662	while read -r file; do
663		# No results presents a blank line from heredoc.
664		[ -z "${file}" ] && continue
665		while read -r dep_file; do
666			# No results presents a blank line from heredoc.
667			[ -z "${dep_file}" ] && continue
668			# Skip files we already checked.
669			if listcontains ${dep_file} "${already}"; then
670				continue
671			fi
672			if mport which -q ${dep_file} > /dev/null 2>&1; then
673				dep_file_pkg=$(mport which -qo ${dep_file})
674
675				# Check that the .so we need has a SONAME
676				if [ "${dep_file_pkg}" != "${PKGORIGIN}" ]; then
677					# When grep -q finds a match it will close the pipe immediately.
678					# This may cause the test to fail when pipefail is turned on.
679					set +o pipefail
680					if ! readelf -d "${dep_file}" | grep SONAME > /dev/null; then
681						err "${file} is linked to ${dep_file} which does not have a SONAME.  ${dep_file_pkg} needs to be fixed."
682					fi
683					set -o pipefail
684				fi
685
686				# If we don't already depend on it, and we don't provide it
687				if ! listcontains ${dep_file_pkg} "${LIB_RUN_DEPENDS} ${PKGORIGIN}"; then
688					# If the package has a flavor, check that the dependency is not on that particular flavor.
689					flavor=$(mport annotate -q -S "$(mport which -q "${dep_file}")" flavor)
690					if [ -n "${flavor}" ]; then
691						if listcontains ${dep_file_pkg}@${flavor} "${LIB_RUN_DEPENDS} ${PKGORIGIN}"; then
692							continue
693						fi
694					fi
695					err "${file} is linked to ${dep_file} from ${dep_file_pkg} but it is not declared as a dependency"
696					proxydeps_suggest_uses ${dep_file_pkg} ${dep_file}
697					rc=1
698				fi
699			else
700				err "${file} is linked to ${dep_file} that does not belong to any package"
701				rc=1
702			fi
703			already="${already} ${dep_file}"
704			dep_lib_file=$(basename ${dep_file})
705			dep_lib_files="${dep_lib_files} ${dep_lib_file%%.so*}.so"
706		done <<-EOT
707		$(env LD_LIBMAP_DISABLE=1 ldd -a "${FAKE_DESTDIR}${file}" | \
708			awk '
709			BEGIN {section=0}
710			/^\// {section++}
711			!/^\// && section<=1 && ($3 ~ "^'${PREFIX}'" || $3 ~ "^'${LOCALBASE}'") {print $3}')
712		EOT
713	done <<-EOT
714	$(list_stagedir_elfs | \
715		file -F $'\1' -f - | \
716		grep -a 'ELF.*FreeBSD.*dynamically linked' | \
717		cut -f 1 -d $'\1'| \
718		sed -e 's/^\.//')
719	EOT
720
721	# Check whether all files in LIB_DPEENDS are actually linked against
722	for _library in ${WANTED_LIBRARIES} ; do
723		if ! listcontains ${_library%%.so*}.so "${dep_lib_files}" ; then
724			warn "you might not need LIB_DEPENDS on ${_library}"
725		fi
726	done
727
728	[ -z "${PROXYDEPS_FATAL}" ] && return 0
729
730	return ${rc}
731}
732
733sonames() {
734	[ ! -d ${FAKE_DESTDIR}${PREFIX}/lib -o -n "${BUNDLE_LIBS}" ] && return 0
735	while read -r f; do
736		# No results presents a blank line from heredoc.
737		[ -z "${f}" ] && continue
738		# Ignore symlinks
739		[ -f "${f}" -a ! -L "${f}" ] || continue
740		# Ignore .debug files
741		[ "${f}" == "${f%.debug}" ] || continue
742		if ! readelf -d ${f} | grep SONAME > /dev/null; then
743			warn "${f} doesn't have a SONAME."
744			warn "mport(8) will not register it as being provided by the port."
745			warn "If another port depend on it, mport will not be able to know where it comes from."
746			case "${f}" in
747				${FAKE_DESTDIR}${PREFIX}/lib/*/*)
748					warn "It is in a subdirectory, it may not be used in another port."
749					;;
750				*)
751					warn "It is directly in ${PREFIX}/lib, it is probably used by other ports."
752					;;
753			esac
754		fi
755	# Use heredoc to avoid losing rc from find|while subshell
756	done <<-EOT
757	$(find ${FAKE_DESTDIR}${PREFIX}/lib -name '*.so.*')
758	EOT
759}
760
761perlcore_port_module_mapping() {
762	case "$1" in
763		Net)
764			echo "Net::Config"
765			;;
766		libwww)
767			echo "LWP"
768			;;
769		*)
770			echo "$1" | sed -e 's/-/::/g'
771			;;
772	esac
773}
774
775perlcore() {
776	local portname version module gotsome
777	[ -x "${LOCALBASE}/bin/corelist" ] || return 0
778	for dep in ${UNIFIED_DEPENDS}; do
779		portname=$(expr "${dep}" : ".*/p5-\(.*\)")
780		if [ -n "${portname}" ]; then
781			gotsome=1
782			module=$(perlcore_port_module_mapping "${portname}")
783			version=$(expr "${dep}" : ".*>=*\([^:<]*\)")
784
785			while read -r l; do
786				case "${l}" in
787					*was\ not\ in\ CORE*)
788						# This never was with Perl
789						# CORE, so nothing to do here
790						;;
791					*and\ removed*)
792						# This was in Perl CORE but has
793						# been removed since.
794						warn "${dep##*:} was in Perl CORE.  Check with \`corelist ${module} ${version}\` and \`corelist -a ${module}\` if it should be conditionally added depending on PERL_LEVEL"
795						;;
796					*deprecated*in*)
797						# This is in Perl CORE but is
798						# deprecated.
799						warn "${dep##*:} is in Perl CORE but deprecated.  Check with \`corelist ${module} ${version}\` and \`corelist -a ${module}\` if the dependency is really needed or if it should be conditionally added depending on PERL_LEVEL"
800						;;
801					*was\ first\ released*)
802						# This is in Perl CORE and is
803						# maybe not needed.
804						warn "${dep##*:} is present in Perl CORE.  Check with \`corelist ${module} ${version}\` and \`corelist -a ${module}\` if the dependency is really needed or if it should be conditionally added depending on PERL_LEVEL"
805						;;
806					*)
807						err "This line is not handled: \"${l}\""
808				esac
809			done <<-EOT
810			$(${LOCALBASE}/bin/corelist "${module}"|tail -1)
811			EOT
812		fi
813	done
814	if [ -n "${gotsome}" ] && ! mport info p5-Module-CoreList; then
815		notice "You have some Perl modules as dependencies but you do not have devel/p5-Module-CoreList installed, the perlcore QA check gets better results when using it, especially with older Perl versions."
816	fi
817}
818
819no_arch() {
820	[ -z "$NO_ARCH" ] && return
821	rc=0
822	while read -r f; do
823		[ -z "$f" ] && continue
824		if [ -n "$NO_ARCH_IGNORE" ]; then
825			skip=
826			for blacklist in $NO_ARCH_IGNORE; do
827				case $f in
828					*$blacklist) skip=1; break;;
829				esac
830			done
831			[ "$skip" ] && continue
832		fi
833		err "'${f#.}' is a architecture specific binary file and you have set NO_ARCH.  Either remove NO_ARCH or add '$(basename $f)' to NO_ARCH_IGNORE."
834		rc=1
835	done <<-EOF
836	$(list_stagedir_elfs  \
837		| file -F $'\1' -f - -N \
838		| grep -aE 'ELF .* [LM]SB .*, .*, version [0-9]+ \(FreeBSD\)' \
839		| cut -f 1 -d $'\1')
840	EOF
841	return $rc
842}
843
844gemdeps()
845{
846	rc=0
847	if [ "${PKGBASE%%-*}" = "rubygem" ]; then
848		# shellcheck disable=SC2153
849		# In the heredoc, ${PORTNAME} comes from the environment, not
850		# to be confused with ${portname}
851		while read -r l; do
852			if [ -n "${l}" ]; then
853				name=${l%% *}
854				vers=${l#* }
855				while read -r v; do
856					if ! while read -r p; do
857						${LOCALBASE}/bin/ruby -e "puts 'OK' if Gem::Dependency.new('${name}','${v}').match?('${name}','${p}')"
858					done | grep -qFx OK; then
859						err RubyGem dependency ${name} ${v} is not satisfied.
860						rc=1
861					fi <<-EOF
862					$(${LOCALBASE}/bin/gem list -e "${name}" \
863						| sed "s|.*(\(.*\))|\1|" \
864						| tr -d ' ' \
865						| tr , '\n')
866					EOF
867				done <<-EOF
868				$(while echo "${vers}" | grep -q '"'; do
869					echo "${vers}" | cut -d '"' -f2
870					vers=$(echo "${vers}"|cut -d '"' -f3-)
871				done)
872				EOF
873			fi
874		done <<-EOF
875		$(grep -a 's.add_runtime_dependency' ${FAKE_DESTDIR}${PREFIX}/lib/ruby/gems/*/specifications/${PORTNAME}-*.gemspec \
876			| sed 's|.*<\(.*\)>.*\[\(.*\)\])|\1 \2|' \
877			| sort -u)
878		EOF
879	fi
880	return $rc
881}
882
883# If an non rubygem-port has a 'Gemfile' file
884# it is checked with bundle to be sure
885# all dependencies are satisfied.
886# Without the check missing/wrong dependencies
887# are just found when executing the application
888gemfiledeps()
889{
890	# skip check if port does not use ruby at all
891	if [ -z "$USE_RUBY" ]; then
892		return 0
893	fi
894
895	# skip check if port is a rubygem-* one; they have no Gemfiles
896	if [ "${PKGBASE%%-*}" = "rubygem" ]; then
897		return 0
898	fi
899
900	# advise install of bundler if its not present for check
901	if ! type bundle > /dev/null 2>&1; then
902		notice "Please install sysutils/rubygem-bundler for additional Gemfile-checks"
903		return 0
904	fi
905
906	# locate the Gemfile(s)
907	while read -r f; do
908
909		# no results presents a blank line from heredoc
910		[ -z "$f" ] && continue
911
912		# if there is no Gemfile everything is fine - stop here
913		[ ! -f "$f" ] && return 0;
914
915		# use bundle to check if Gemfile is satisfied
916		# if bundle returns 1 the Gemfile is not satisfied
917		# and so stage-qa isn't also
918		if ! bundle check --dry-run --gemfile $f > /dev/null 2>&1; then
919			warn "Dependencies defined in ${f} are not satisfied"
920		fi
921
922	done <<-EOF
923		$(find ${FAKE_DESTDIR} -name Gemfile)
924		EOF
925	return 0
926}
927
928flavors()
929{
930	local rc pkgnames uniques
931	rc=0
932	if [ -n "${FLAVOR}" ]; then
933		pkgnames=$(make -C "${CURDIR}" flavors-package-names|sort)
934		uniques=$(echo "${pkgnames}"|uniq)
935		if [ "$pkgnames" != "${uniques}" ]; then
936			err "Package names are not unique with flavors:"
937			make -C "${CURDIR}" pretty-flavors-package-names >&2
938			err "maybe use <flavor>_PKGNAMEPREFIX/SUFFIX".
939			rc=1
940		fi
941	fi
942	return ${rc}
943}
944
945license()
946{
947	local lic autoaccept pkgmirror #distsell distmirror pkgsell
948
949	if [ -n "$DISABLE_LICENSES" ]; then
950		warn "You have disabled the licenses framework with DISABLE_LICENSES, unable to run checks"
951	elif [ -n "$LICENSE" ]; then
952		for lic in $LICENSE_PERMS; do
953			case "$lic" in
954				auto-accept) autoaccept=1 ;;
955				#dist-mirror) distmirror=1 ;;
956				#dist-sell)   distsell=1   ;;
957				pkg-mirror)  pkgmirror=1  ;;
958				#pkg-sell)    pkgsell=1    ;;
959			esac
960		done
961
962		if [ -z "$autoaccept" ]; then
963			warn "License is not auto-accepted, packages will not be built, ports depending on this one will be ignored."
964		fi
965		if [ -z "$pkgmirror" ]; then
966			warn "License does not allow package to be distributed, ports depending on this one will be ignored"
967		fi
968	fi
969
970	return 0
971}
972
973# This is to prevent adding dependencies to meta ports that are only there to
974# improve the end user experience.
975depends_blacklist()
976{
977	local dep rc instead
978
979	rc=0
980
981	for dep in ${UNIFIED_DEPENDS}; do
982		origin=$(expr "${dep}" : ".*:\([^@]*\)")
983		instead=""
984
985		case "$origin" in
986			lang/python|lang/python2|lang/python3)
987				# lang/python depends on lang/pythonX, but it's
988				# ok, it is also in the blacklist.
989				if [ ${PKGORIGIN} != lang/python ]; then
990					instead="USES=python:xy with a specific version"
991				fi
992				;;
993			lang/gcc)
994				instead="USE_GCC"
995				;;
996			lang/go)
997				instead="USES=go"
998				;;
999#			lang/mono)
1000#				instead="USES=mono"
1001#				;;
1002			devel/llvm)
1003				instead="USES=llvm"
1004				;;
1005		esac
1006
1007		if [ -n "${instead}" ]; then
1008			err "$origin should not be depended upon. Instead, use $instead."
1009			rc=1
1010		fi
1011	done
1012
1013	return $rc
1014}
1015
1016pkgmessage()
1017{
1018	for message in ${PKGMESSAGES}; do
1019		if [ -f "${message}" ]; then
1020			if ! head -1 "${message}" | grep -q '^\['; then
1021				warn "${message} not in UCL format, will be shown on initial install only."
1022				warn "See https://github.com/MidnightBSD/src/wiki/mports-porting-guide"
1023			fi
1024		fi
1025	done
1026
1027	return 0
1028}
1029
1030reinplace()
1031{
1032	if [ -f ${REWARNFILE} ]; then
1033		warn "Possible REINPLACE_CMD issues:"
1034		cat ${REWARNFILE}
1035	fi
1036}
1037
1038prefixman() {
1039	return 0
1040# todo: BSD.local.dist mtree needs work
1041	if [ -d "${FAKE_DESTDIR}${PREFIX}/man" ]; then
1042		warn "Installing man files in ${PREFIX}/man is no longer supported. Consider installing these files in ${PREFIX}/share/man instead."
1043		ls -liTd ${FAKE_DESTDIR}${PREFIX}/man
1044	fi
1045	return 0
1046}
1047
1048checks="shebang symlinks paths stripped desktopfileutils sharedmimeinfo"
1049checks="$checks suidfiles libtool libperl prefixvar baselibs terminfo"
1050checks="$checks proxydeps sonames perlcore no_arch gemdeps gemfiledeps flavors"
1051checks="$checks license depends_blacklist pkgmessage reinplace prefixman"
1052
1053ret=0
1054cd ${FAKE_DESTDIR} || exit 1
1055for check in ${checks}; do
1056	eval check_test="\$IGNORE_QA_$check"
1057	if [ -z "${check_test}" ]; then
1058		${check} || ret=1
1059	else
1060		warn "Ignoring $check QA test"
1061	fi
1062done
1063
1064exit ${ret}
1065