Tue Jan 2 22:40:32 2018 UTC ()
Added the guess-license target.

It compares the license file from the package with the available licenses
in licenses/ and shows the diff to the best match.

This will hopefully make it easier for package authors to include the
LICENSE variable in the package Makefile. This variable being missing is
one of the most frequent error messages from pkglint (4187 out of 20044).


(rillig)
diff -r1.80 -r1.81 pkgsrc/mk/license.mk

cvs diff -r1.80 -r1.81 pkgsrc/mk/license.mk (expand / switch to unified diff)

--- pkgsrc/mk/license.mk 2017/05/11 12:56:21 1.80
+++ pkgsrc/mk/license.mk 2018/01/02 22:40:32 1.81
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: license.mk,v 1.80 2017/05/11 12:56:21 jperkin Exp $ 1# $NetBSD: license.mk,v 1.81 2018/01/02 22:40:32 rillig Exp $
2# 2#
3# This file handles everything about the LICENSE variable. It is 3# This file handles everything about the LICENSE variable. It is
4# included automatically by bsd.pkg.mk. 4# included automatically by bsd.pkg.mk.
5# 5#
6# XXX There should be one place to set the default list and for users 6# XXX There should be one place to set the default list and for users
7# to set the ACCEPTABLE_LICENSES list, used by both source builds and 7# to set the ACCEPTABLE_LICENSES list, used by both source builds and
8# binary installs# 8# binary installs#
9# 9#
10# XXX: Some of this content arguably belongs in the pkgsrc guide 10# XXX: Some of this content arguably belongs in the pkgsrc guide
11# instead. 11# instead.
12# 12#
13# === User-settable variables === 13# === User-settable variables ===
14# 14#
@@ -87,30 +87,30 @@ @@ -87,30 +87,30 @@
87# DEFAULT_ACCEPTABLE_LICENSES list, and that should be updated 87# DEFAULT_ACCEPTABLE_LICENSES list, and that should be updated
88# to match the list here. See 88# to match the list here. See
89# pkgsrc/pkgtools/pkg_install/files/lib/license.c 89# pkgsrc/pkgtools/pkg_install/files/lib/license.c
90# 90#
91# === See also === 91# === See also ===
92# 92#
93# ../doc/TODO, section "Licenses of packages" 93# ../doc/TODO, section "Licenses of packages"
94# 94#
95# Keywords: licence license 95# Keywords: licence license
96# 96#
97 97
98# This list is not complete. Free and Open Source licenses should be 98# This list is not complete. Free and Open Source licenses should be
99# added to the list as they are added to pkgsrc. 99# added to the list as they are added to pkgsrc.
100 100#
101# The convention is that Free or Open Source licenses do not have a 101# The convention is that Free or Open Source licenses do not have a
102# -license suffix, and nonfree licenses end in -license. 102# -license suffix, and nonfree licenses end in -license.
103 103#
104DEFAULT_ACCEPTABLE_LICENSES= \ 104DEFAULT_ACCEPTABLE_LICENSES= \
105 apache-1.1 apache-2.0 \ 105 apache-1.1 apache-2.0 \
106 arphic-public \ 106 arphic-public \
107 artistic artistic-2.0 \ 107 artistic artistic-2.0 \
108 boost-license \ 108 boost-license \
109 cc-by-sa-v3.0 \ 109 cc-by-sa-v3.0 \
110 cc0-1.0-universal \ 110 cc0-1.0-universal \
111 cddl-1.0 \ 111 cddl-1.0 \
112 cecill-2.1 \ 112 cecill-2.1 \
113 cpl-1.0 \ 113 cpl-1.0 \
114 epl-v1.0 \ 114 epl-v1.0 \
115 eupl-v1.1 \ 115 eupl-v1.1 \
116 gfsl \ 116 gfsl \
@@ -226,13 +226,61 @@ PKG_FAIL_REASON+= "${PKGNAME} has an una @@ -226,13 +226,61 @@ PKG_FAIL_REASON+= "${PKGNAME} has an una
226 " ACCEPTABLE_LICENSES= foo" \ 226 " ACCEPTABLE_LICENSES= foo" \
227 "to ${_PKG_INSTALL_CONF}." 227 "to ${_PKG_INSTALL_CONF}."
228. endif 228. endif
229 229
230.elif ${_ACCEPTABLE_LICENSE} == "failure" 230.elif ${_ACCEPTABLE_LICENSE} == "failure"
231PKG_FAIL_REASON+= "License conditions for ${PKGNAME} could not be evaluated" 231PKG_FAIL_REASON+= "License conditions for ${PKGNAME} could not be evaluated"
232.elif ${_ACCEPTABLE_LICENSE} == "outdated" 232.elif ${_ACCEPTABLE_LICENSE} == "outdated"
233PKG_FAIL_REASON+= \ 233PKG_FAIL_REASON+= \
234 "Your pkg_install is too old to evaluate license conditions" \ 234 "Your pkg_install is too old to evaluate license conditions" \
235 "You can bypass this check by setting SKIP_LICENSE_CHECK=yes" 235 "You can bypass this check by setting SKIP_LICENSE_CHECK=yes"
236.endif 236.endif
237 237
238.endif 238.endif
 239
 240# guess-license:
 241# Extracts the current package and tries to guess its license.
 242# This is useful for package developers.
 243#
 244# Keywords: license
 245
 246guess-license:
 247 ${RUN} ${MAKE} extract
 248 ${RUN} \
 249 type wdiff > /dev/null 2>&1 || ${FAIL_MSG} "To guess the license, textproc/wdiff must be installed."; \
 250 \
 251 printf "%8s %s\n" "Wdiff" "License"; \
 252 bestsize=1000000; \
 253 bestlicense=; \
 254 for pkglicense in ${WRKSRC}/COPYING ${WRKSRC}/LICENSE; do \
 255 for license in ${PKGSRCDIR}/licenses/*; do \
 256 if [ -f "$$pkglicense" ] && [ -f "$$license" ]; then \
 257 size=`{ wdiff -3 "$$pkglicense" "$$license" || true; } | wc -c`; \
 258 if [ "$$size" -lt "$$bestsize" ]; then \
 259 printf "%8d %s\n" "$$size" "$${license##*/}"; \
 260 bestsize="$$size"; \
 261 bestlicense="$$license"; \
 262 fi \
 263 fi \
 264 done; \
 265 if [ "$$bestlicense" ]; then \
 266 break; \
 267 fi \
 268 done; \
 269 \
 270 if [ "$$bestlicense" ]; then \
 271 if [ "$$bestsize" -lt 3000 ]; then \
 272 echo ""; \
 273 echo "Line differences in license texts:"; \
 274 echo ""; \
 275 diff -wu "$$pkglicense" "$$bestlicense" || true; \
 276 echo ""; \
 277 echo "Word differences in license texts:"; \
 278 echo ""; \
 279 wdiff -3 "$$pkglicense" "$$bestlicense" || true; \
 280 else \
 281 echo ""; \
 282 echo "No similar enough license found."; \
 283 fi \
 284 else \
 285 echo "No license file found in ${WRKSRC}."; \
 286 fi