git: ddd0e820c8eb - main - Mk/bsd.ports.mk: Add suppport for WWW in Makefiles

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Wed, 07 Sep 2022 19:41:12 UTC
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/ports/commit/?id=ddd0e820c8eb73acef94c72434c382982d0fa329

commit ddd0e820c8eb73acef94c72434c382982d0fa329
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2022-09-07 19:32:54 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2022-09-07 19:32:54 +0000

    Mk/bsd.ports.mk: Add suppport for WWW in Makefiles
    
    Expect the project website or other relevant URL of a port to be
    specified in a WWW macro in its Makefile.
    
    This information used to be available in WWW: lines at the end of
    each port's pkg-descr file. By moving it into the Makefile, this
    value is easier to access, verify, and maintain.
    
    A WWW: line is added to the "desc" element of package manifests
    based on the WWW macro value by the create-manifest.sh script.
    This restores the previous contents of this line in the manifest
    (as e.g. expected by the Freshports website).
    
    The ports-mgmt/portlint port has been updated in commit 9800743f0
    (version 2.19.13) to support the planned introduction of WWW in
    port Makefiles.
    
    Approved by:            portmgr (tcberner)
    Differential Revision:  https://reviews.freebsd.org/D36434
---
 Mk/Scripts/create-manifest.sh |  4 ++++
 Mk/bsd.port.mk                | 43 +++++++++++++++----------------------------
 2 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/Mk/Scripts/create-manifest.sh b/Mk/Scripts/create-manifest.sh
index 8619a6959cbe..252fcead9103 100644
--- a/Mk/Scripts/create-manifest.sh
+++ b/Mk/Scripts/create-manifest.sh
@@ -87,6 +87,10 @@ fi
 
 # Copy the pkg-descr file
 cp ${dp_DESCR} ${dp_METADIR}/+DESC
+if [ -n "${dp_WWW}" ] && ! grep -q '^WWW: ' ${dp_DESCR}; then
+	echo >> ${dp_METADIR}/+DESC
+	echo "WWW: ${dp_WWW}" >> ${dp_METADIR}/+DESC
+fi
 
 # Concatenate all the scripts
 output_files=
diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
index a68ace6f5fdb..e080b81a64d8 100644
--- a/Mk/bsd.port.mk
+++ b/Mk/bsd.port.mk
@@ -123,9 +123,13 @@ FreeBSD_MAINTAINER=	portmgr@FreeBSD.org
 #
 # (NOTE: by convention, the MAINTAINER entry (see above) should go here.)
 #
-# These variables are typically set in /etc/make.conf to indicate
-# the user's preferred location to fetch files from.  You should
-# rarely need to set these.
+# COMMENT		- A short description of the package (less than 70 characters)
+# WWW			- URL users can get more information on the provided package
+# 				  was previously part of pkg-descr
+#
+# The following variables are typically set in /etc/make.conf to indicate
+# the user's preferred location to fetch files from.  You should rarely
+# need to set these.
 #
 # MASTER_SITE_BACKUP
 #				- Backup location(s) for distribution files and patch
@@ -3595,12 +3599,11 @@ security-check: ${TMPPLIST}
 		! ${AWK} -v audit="$${PORTS_AUDIT}" -f ${SCRIPTSDIR}/security-check.awk \
 		  ${WRKDIR}/.PLIST.flattened ${WRKDIR}/.PLIST.readelf ${WRKDIR}/.PLIST.setuid ${WRKDIR}/.PLIST.writable; \
 	then \
-		www_site=$$(cd ${.CURDIR} && ${MAKE} www-site); \
-	    if [ ! -z "$${www_site}" ]; then \
+	    if [ ! -z "${_WWW}" ]; then \
 			${ECHO_MSG}; \
 			${ECHO_MSG} "      For more information, and contact details about the security"; \
 			${ECHO_MSG} "      status of this software, see the following webpage: "; \
-			${ECHO_MSG} "$${www_site}"; \
+			${ECHO_MSG} "${_WWW}"; \
 		fi; \
 	fi
 .      endif
@@ -3655,10 +3658,9 @@ ${stage}-${name}-script:
 
 .    if !target(pretty-print-www-site)
 pretty-print-www-site:
-	@www_site=$$(cd ${.CURDIR} && ${MAKE} www-site); \
-	if [ -n "$${www_site}" ]; then \
+	@if [ -n "${_WWW}" ]; then \
 		${ECHO_MSG} -n " and/or visit the "; \
-		${ECHO_MSG} -n "<a href=\"$${www_site}\">web site</a>"; \
+		${ECHO_MSG} -n "<a href=\"${_WWW}\">web site</a>"; \
 		${ECHO_MSG} " for further information"; \
 	fi
 .    endif
@@ -4285,7 +4287,7 @@ create-manifest:
 			dp_PORT_OPTIONS='${PORT_OPTIONS}'                     \
 			dp_PREFIX='${PREFIX}'                                 \
 			dp_USERS='${USERS:u:S/$/,/}'                          \
-			dp_WWW='${WWW}'                                       \
+			dp_WWW='${_WWW}'                                      \
 			${PKG_NOTES_ENV}                                      \
 			${SH} ${SCRIPTSDIR}/create-manifest.sh
 
@@ -4349,6 +4351,7 @@ _FETCH_DEPENDS=${FETCH_DEPENDS:C/^[^ :]+:([^ :@]+)(@[^ :]+)?(:[^ :]+)?/\1/:O:u:C
 _LIB_DEPENDS=${LIB_DEPENDS:C/^[^ :]+:([^ :@]+)(@[^ :]+)?(:[^ :]+)?/\1/:O:u:C,(^[^/]),${PORTSDIR}/\1,}
 _BUILD_DEPENDS=${BUILD_DEPENDS:C/^[^ :]+:([^ :@]+)(@[^ :]+)?(:[^ :]+)?/\1/:O:u:C,(^[^/]),${PORTSDIR}/\1,} ${_LIB_DEPENDS}
 _RUN_DEPENDS=${RUN_DEPENDS:C/^[^ :]+:([^ :@]+)(@[^ :]+)?(:[^ :]+)?/\1/:O:u:C,(^[^/]),${PORTSDIR}/\1,} ${_LIB_DEPENDS}
+_WWW=${WWW:U${MASTER_SITES:[1]}}
 .      if exists(${DESCR})
 _DESCR=${DESCR}
 .      else
@@ -4363,19 +4366,7 @@ INDEX_OUT=/dev/stdout
 
 .      if empty(FLAVORS) || defined(_DESCRIBE_WITH_FLAVOR)
 describe:
-	@(${ECHO_CMD} -n "${PKGNAME}|${.CURDIR}|${PREFIX}|"; \
-	${ECHO_CMD} -n ${COMMENT:Q}; \
-	${ECHO_CMD} -n "|${_DESCR}|${MAINTAINER}|${CATEGORIES}|${_EXTRACT_DEPENDS}|${_PATCH_DEPENDS}|${_FETCH_DEPENDS}|${_BUILD_DEPENDS:O:u}|${_RUN_DEPENDS:O:u}|"; \
-	while read one two discard; do \
-		case "$$one" in \
-		WWW:)   case "$$two" in \
-			https://*|http://*|ftp://*) ${ECHO_CMD} -n "$$two" ;; \
-			*) ${ECHO_CMD} -n "http://$$two" ;; \
-			esac; \
-			break; \
-			;; \
-		esac; \
-	done < ${DESCR}; ${ECHO_CMD}) >>${INDEX_OUT}
+	@(${ECHO_CMD} "${PKGNAME}|${.CURDIR}|${PREFIX}|${COMMENT:Q}|${_DESCR}|${MAINTAINER}|${CATEGORIES}|${_EXTRACT_DEPENDS}|${_PATCH_DEPENDS}|${_FETCH_DEPENDS}|${_BUILD_DEPENDS:O:u}|${_RUN_DEPENDS:O:u}|${_WWW}" >> ${INDEX_OUT})
 .      else # empty(FLAVORS)
 describe: ${FLAVORS:S/^/describe-/}
 .        for f in ${FLAVORS}
@@ -4386,11 +4377,7 @@ describe-${f}:
 .    endif
 
 www-site:
-.    if exists(${DESCR})
-	@${AWK} '$$1 ~ /^WWW:/ {print $$2}' ${DESCR} | ${HEAD} -1
-.    else
-	@${ECHO_CMD}
-.    endif
+	@${ECHO_CMD} ${_WWW}
 
 .    if !target(readmes)
 readmes:	readme