6 Licenses_Include_MAINTAINER= portmgr@FreeBSD.org
9 # bsd.licenses.mk - License auditing framework.
11 # Created by: Alejandro Pulver <alepulver@FreeBSD.org>
13 # Please view me with 4 column tabs!
17 # - Bring back save and checksum with new dialog interface (only offers to do
18 # so if ran by root, otherwise silently remove the options). Also only allow
19 # saving per-port options (known or unknown), and only when accepted.
20 # - Add custom restriction targets for better integration (now some files are
21 # removed from FTP if restricted for CDROM for example, as the old
24 # The following cases are not considered:
26 # - Redistribution of modified distfiles, because is never done.
27 # - Creating binaries from modified sources, because packages almost always
28 # contain modifications to the source, can not be autodetected (i.e.
29 # patch-* in ${FILESDIR}, post-* targets, etc), and these licenses tend to
30 # have more restrictions anyways.
33 # Integration with target sequences
35 # _SANITY_SEQ+= check-license (after check-vulnerable)
36 # _PATCH_SEQ+= ask-license (before any other targets)
37 # _INSTALL_SUSEQ+= install-license (after install-desktop-entries)
39 # The 'check-license' target will determine if the license was accepted,
40 # rejected or has to be asked later to the user in 'ask-license' (by then
41 # licenses should be extracted). The 'install-license' target installs the
42 # applications' licenses, a general package license mentioning them, and a
43 # restriction report (to be used by ports, scripts and similar tools).
45 # Variables provided to the ports system and users in general, to modify the
46 # behavior of the framework
48 # DISABLE_LICENSES - Disable license auditing framework completely.
49 # NO_LICENSES_INSTALL - Do not install catalog, report and licenses.
50 # NO_LICENSES_DIALOGS - Disable interactive menus for asking licenses.
52 #NO_LICENSES_INSTALL= yes
53 #NO_LICENSES_DIALOGS= yes
55 # Variables provided to users (can be passed to make or set in /etc/make.conf)
57 # LICENSES_ACCEPTED - Accepted licenses.
58 # LICENSES_REJECTED - Rejected licenses.
59 # LICENSES_GROUPS_ACCEPTED - Accepted license groups.
60 # LICENSES_GROUPS_REJECTED - Rejected license groups.
61 # LICENSES_ASK - Require explicit user approval for all licenses not
62 # present in previous variables (for example, stock
63 # accepted licenses will ask confirmation).
66 # Variables provided to ports
68 # LICENSE - Code of license (short name).
69 # LICENSE_PERMS - Permissions; use "none" if empty.
70 # LICENSE_GROUPS - Groups the license belongs.
71 # LICENSE_NAME - Full license name (for the reports).
72 # LICENSE_FILE - Full path to license (or use LICENSE_TEXT).
73 # LICENSE_TEXT - Text to use as a license, useful when referencing to
74 # another place if it's not in the distfile.
75 # LICENSE_DISTFILES - Name of licensed files (defaults to ${_DISTFILES}).
76 # LICENSE_COMB - Set to "dual" or "multi", for OR/AND behavior
77 # (defaults to "single" if undefined, the common case)
79 # The following cases are supported after defining LICENSE:
81 # Case 1: license defined in the framework (aka "known").
83 # In this case the only allowed variables to set are LICENSE_FILE and
84 # LICENSE_DISTFILES. The rest are managed by the framework and are not allowed
87 # Case 2: license only known by the port (aka "unknown").
89 # In this case LICENSE_{PERMS,NAME} are mandatory, in addition to
90 # either LICENSE_FILE or LICENSE_TEXT. Optional variables are
91 # LICENSE_{GROUPS,NOTES}.
93 # Available components for LICENSE_PERMS:
94 # dist-mirror - No free redistribution of distfile (like FTP mirroring; RESTRICTED).
95 # dist-sell - No selling of distfile (like in CD-ROM; NO_CDROM).
96 # pkg-mirror - No free redistribution of package (like FTP upload; NO_PACKAGE).
97 # pkg-sell - No selling of package (like in CD-ROM; NO_CDROM).
98 # auto-accept - If license is accepted by default, without presented
99 # agreement, unless the user defines LICENSES_ASK.
101 # Notes about permissions:
102 # - Permissions use a default-deny policy.
103 # - Components can be negated by prefixing them with "no-" (like
105 # - In case a component is present and also excluded (i.e. no-dist-sell and
106 # dist-sell together in LICENSE_PERMS), it will be excluded.
107 # - XXX Currently there is no point in "no-" prefixes, as permissions are not
108 # inherited from groups. Maybe it looks more clear that way than leaving the
111 # Dual/multiple licenses:
113 # If LICENSE_COMB is set to "dual", then LICENSE can (must, actually) have
114 # more than one component. After that each license "lic" in LICENSE falls in
115 # previous cases (known or unknown), but their variables are prefixed by
116 # _LICENSE_ and suffixed by _lic. The main license name, perms and groups will
117 # be set automatically (following appropiate logic). The idea is that any
118 # license from LICENSE can be chosen to use the package.
120 # The case when LICENSE_COMB is set to "multi" is similar. But the idea is
121 # that all of the licenses in LICENSE must be agreed to use the package.
124 .if defined(_POSTMKINCLUDED) && !defined(BEFOREPORTMK)
128 # Include known licenses from database
130 .include "${PORTSDIR}/Mk/bsd.licenses.db.mk"
132 # Lists of variables and valid components
134 # _LICENSE_LIST_PERMS - Valid permission components
135 # _LICENSE_LIST_PORT_VARS - License variables defined by the port
137 _LICENSE_LIST_PERMS= dist-mirror dist-sell pkg-mirror pkg-sell auto-accept none
138 _LICENSE_LIST_PORT_VARS= PERMS NAME GROUPS
142 # _LICENSE_DIR - Directory to install licenses
143 # _LICENSE_DIR_REL - Same as above, without ${PREFIX}
144 # _LICENSE_STORE - Store for known license files
145 # _LICENSE_CATALOG - License catalog (make include file) to be created (dst)
146 # _LICENSE_CATALOG_TMP - Same as above, but in WRKDIR (src)
147 # _LICENSE_REPORT - License summary, shows licenses and how they are combined (dst)
148 # _LICENSE_REPORT_TMP - Same as above, but in WRKDIR (src)
149 # _LICENSE_COOKIE - Set when license is accepted, it is not present in
150 # bsd.port.mk to avoid creating LICENSE_{REQ,SEQ} for a
151 # few more targets only.
153 _LICENSE_DIR?= ${PREFIX}/share/licenses/${PKGNAME}
154 _LICENSE_DIR_REL?= share/licenses/${PKGNAME}
155 _LICENSE_STORE?= ${PORTSDIR}/Templates/Licenses
156 _LICENSE_CATALOG?= ${_LICENSE_DIR}/catalog.mk
157 _LICENSE_CATALOG_TMP?= ${WRKDIR}/.license-catalog.mk
158 _LICENSE_REPORT?= ${_LICENSE_DIR}/LICENSE
159 _LICENSE_REPORT_TMP?= ${WRKDIR}/.license-report
160 _LICENSE_COOKIE?= ${WRKDIR}/.license_done.${PORTNAME}.${PREFIX:S/\//_/g}
162 # Defaults (never overriden for now)
164 # _LICENSE - Copy of LICENSE (for now)
165 # _LICENSE_COMB - Copy of LICENSE_COMB (but "single" instead of empty)
167 _LICENSE?= ${LICENSE}
168 .if !defined(LICENSE_COMB)
169 _LICENSE_COMB= single
171 _LICENSE_COMB= ${LICENSE_COMB}
174 # Check if single or dual/multiple license
176 # Make sure LICENSE_COMB is only used with more than one license.
178 .if ${_LICENSE_COMB} != "single" && ${_LICENSE_COMB} != "dual" && ${_LICENSE_COMB} != "multi"
179 _LICENSE_ERROR?= invalid value for LICENSE_COMB: "${_LICENSE_COMB}" (should be "single", "dual" or "multi")
182 .for lic in ${_LICENSE}
183 . if defined(_LICENSE_DEFINED)
184 . if ${_LICENSE_COMB} == "single"
185 _LICENSE_ERROR?= multiple licenses in LICENSE, but LICENSE_COMB is set to "single" (or undefined)
190 _LICENSE_DEFINED= yes
193 .if ${_LICENSE_COMB} != "single" && !defined(_LICENSE_MULTI)
194 _LICENSE_ERROR?= single license in LICENSE, but LICENSE_COMB is set to "${_LICENSE_COMB}" (requires more than one)
196 .if !defined(_LICENSE_DEFINED)
197 _LICENSE_ERROR?= no licenses present in LICENSE (empty string)
199 .undef _LICENSE_DEFINED
200 .undef _LICENSE_MULTI
202 # Evaluate port license groups and permissions
204 # Available values for _LICENSE_TYPE:
206 # Case 1: "known" (license info taken from internal database)
207 # Case 2: "unknown" (LICENSE is not known, and info taken from port)
209 # Make sure required variables are defined, and remove conflicting (positive
210 # and negative) duplicated components.
212 .if ${_LICENSE_COMB} == "single"
216 . for lic in ${_LICENSE}
217 . if ${_LICENSE_LIST:M${lic}} != ""
218 # Case 1: license defined in the framework.
220 . for var in ${_LICENSE_LIST_PORT_VARS}
221 . if defined(LICENSE_${var})
222 _LICENSE_ERROR?= redefining LICENSE_${var} is not allowed for known licenses, to define a custom license try another LICENSE name like ${_LICENSE}-variant
224 . if !defined(_LICENSE_${var}_${lic})
225 _LICENSE_ERROR?= ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
227 _LICENSE_${var}= ${_LICENSE_${var}_${lic}}
230 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
231 . if !defined(LICENSE_FILE)
232 . if !defined(LICENSE_TEXT)
233 . if exists(${_LICENSE_STORE}/${lic})
234 _LICENSE_FILE= ${_LICENSE_STORE}/${lic}
236 # No license file in /usr/ports/Templates/Licenses
237 _LICENSE_TEXT= The license: ${_LICENSE} (${_LICENSE_NAME}) is standard, please read from the web.
238 _LICENSE_FILE= ${WRKDIR}/${lic}
241 _LICENSE_ERROR?= defining LICENSE_TEXT is not allowed for known licenses
244 _LICENSE_FILE= ${LICENSE_FILE}
248 # Case 2: license only known by the port.
249 _LICENSE_TYPE= unknown
250 . for var in ${_LICENSE_LIST_PORT_VARS}
251 . if defined(LICENSE_${var})
252 _LICENSE_${var}= ${LICENSE_${var}}
253 . elif !defined(_LICENSE_${var})
254 _LICENSE_ERROR?= for unknown licenses, defining LICENSE_${var} is mandatory (otherwise use a known LICENSE)
257 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
259 . for comp in ${_LICENSE_PERMS}
260 . if ${_LICENSE_LIST_PERMS:M${comp:C/^no-//}} == ""
261 _LICENSE_ERROR?= invalid LICENSE_PERMS component "${comp}"
262 . elif ${__LICENSE_PERMS:M${comp}} == "" && \
263 ${_LICENSE_PERMS:Mno-${comp:C/^no-//}} == ""
264 __LICENSE_PERMS+= ${comp}
267 _LICENSE_PERMS:= ${__LICENSE_PERMS}
268 . undef __LICENSE_PERMS
269 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
270 . if !defined(LICENSE_FILE)
271 . if !defined(LICENSE_TEXT)
272 _LICENSE_ERROR?= either LICENSE_FILE or LICENSE_TEXT must be defined
274 _LICENSE_TEXT= ${LICENSE_TEXT}
275 _LICENSE_FILE= ${WRKDIR}/${lic}
278 _LICENSE_FILE= ${LICENSE_FILE}
282 # Only one is allowed
283 . if defined(LICENSE_FILE) && defined(LICENSE_TEXT)
284 _LICENSE_ERROR?= defining both LICENSE_FILE and LICENSE_TEXT is not allowed
287 . if !defined(LICENSE_DISTFILES)
288 _LICENSE_DISTFILES= ${_DISTFILES}
290 _LICENSE_DISTFILES= ${LICENSE_DISTFILES}
295 . for lic in ${_LICENSE}
297 _LICENSE_GROUPS_${lic}?=#
298 . if ${_LICENSE_LIST:M${lic}} != ""
299 # Case 1: license defined in the framework.
300 _LICENSE_TYPE_${lic}= known
301 . for var in ${_LICENSE_LIST_PORT_VARS}
302 . if defined(LICENSE_${var}_${lic})
303 _LICENSE_ERROR?= redefining LICENSE_${var}_${lic} is not allowed for known licenses, to define a custom license try another LICENSE name for ${lic} like ${lic}-variant
305 . if !defined(_LICENSE_${var}_${lic})
306 _LICENSE_ERROR?= ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
309 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
310 . if !defined(LICENSE_FILE_${lic})
311 . if !defined(LICENSE_TEXT_${lic})
312 . if exists(${_LICENSE_STORE}/${lic})
313 _LICENSE_FILE_${lic}= ${_LICENSE_STORE}/${lic}
315 # No license file in /usr/ports/Templates/Licenses
316 _LICENSE_TEXT_${lic}= The license: ${lic} (${_LICENSE_NAME_${lic}}) is standard, please read from the web.
317 _LICENSE_FILE_${lic}= ${WRKDIR}/${lic}
320 _LICENSE_ERROR?= defining LICENSE_TEXT_${lic} is not allowed for known licenses
323 _LICENSE_FILE_${lic}= ${LICENSE_FILE_${lic}}
327 # Case 2: license only known by the port.
328 _LICENSE_TYPE_${lic}= unknown
329 . for var in ${_LICENSE_LIST_PORT_VARS}
330 . if defined(LICENSE_${var}_${lic})
331 _LICENSE_${var}_${lic}= ${LICENSE_${var}_${lic}}
332 . elif !defined(_LICENSE_${var}_${lic})
333 _LICENSE_ERROR?= for unknown licenses, defining LICENSE_${var}_${lic} is mandatory (otherwise use a known LICENSE)
336 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
338 . for comp in ${_LICENSE_PERMS_${lic}}
339 . if ${_LICENSE_LIST_PERMS:M${comp:C/^no-//}} == ""
340 _LICENSE_ERROR?= invalid LICENSE_PERMS_${var} component "${comp}"
341 . elif ${__LICENSE_PERMS:M${comp}} == "" && \
342 ${_LICENSE_PERMS_${lic}:Mno-${comp:C/^no-//}} == ""
343 __LICENSE_PERMS+= ${comp}
346 _LICENSE_PERMS_${lic}:= ${__LICENSE_PERMS}
347 . undef __LICENSE_PERMS
348 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
349 . if !defined(LICENSE_FILE_${lic})
350 . if !defined(LICENSE_TEXT_${lic})
351 _LICENSE_ERROR?= either LICENSE_FILE_${lic} or LICENSE_TEXT_${lic} must be defined
353 _LICENSE_TEXT_${lic}= ${LICENSE_TEXT_${lic}}
354 _LICENSE_FILE_${lic}= ${WRKDIR}/${lic}
357 _LICENSE_FILE_${lic}= ${LICENSE_FILE_${lic}}
361 # Only one is allowed
362 . if defined(LICENSE_FILE_${lic}) && defined(LICENSE_TEXT_${lic})
363 _LICENSE_ERROR?= defining both LICENSE_FILE_${lic} and LICENSE_TEXT_${lic}is not allowed
366 . if !defined(LICENSE_DISTFILES_${lic})
367 _LICENSE_DISTFILES_${lic}= ${_DISTFILES}
369 _LICENSE_DISTFILES_${lic}= ${LICENSE_DISTFILES_${lic}}
374 # Check if the user agrees with the license
376 # Make sure these are defined
378 LICENSES_ACCEPTED?= #
379 LICENSES_REJECTED?= #
380 LICENSES_GROUPS_ACCEPTED?= #
381 LICENSES_GROUPS_REJECTED?= #
383 # Evaluate per-license status
385 .if ${_LICENSE_COMB} == "single"
386 . for lic in ${_LICENSE}
387 . if ${LICENSES_REJECTED:M${lic}} != ""
388 _LICENSE_STATUS?= rejected
390 . for group in ${_LICENSE_GROUPS}
391 . if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
392 _LICENSE_STATUS?= rejected
394 . if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
395 _LICENSE_STATUS?= accepted
398 . if ${LICENSES_ACCEPTED:M${lic}} != ""
399 _LICENSE_STATUS?= accepted
401 . if ${_LICENSE_PERMS:Mauto-accept} != "" && !defined(LICENSES_ASK)
402 _LICENSE_STATUS?= accepted
404 _LICENSE_STATUS?= ask
408 . for lic in ${_LICENSE}
409 . if ${LICENSES_REJECTED:M${lic}} != ""
410 _LICENSE_STATUS_${lic}?= rejected
412 . for group in ${_LICENSE_GROUPS_${lic}}
413 . if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
414 _LICENSE_STATUS_${lic}?= rejected
416 . if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
417 _LICENSE_STATUS_${lic}?= accepted
420 . if ${LICENSES_ACCEPTED:M${lic}} != ""
421 _LICENSE_STATUS_${lic}?= accepted
423 . if ${_LICENSE_PERMS_${lic}:Mauto-accept} != "" && !defined(LICENSES_ASK)
424 _LICENSE_STATUS_${lic}?= accepted
426 _LICENSE_STATUS_${lic}?= ask
430 # Evaluate general status
432 .if ${_LICENSE_COMB} == "dual"
433 . for lic in ${_LICENSE}
434 . if ${_LICENSE_STATUS_${lic}} == "accepted"
435 _LICENSE_STATUS= accepted
436 . elif ${_LICENSE_STATUS_${lic}} == "ask"
437 _LICENSE_STATUS?= ask
438 _LICENSE_TO_ASK+= ${lic}
440 _LICENSE_STATUS?= rejected
443 .elif ${_LICENSE_COMB} == "multi"
444 . for lic in ${_LICENSE}
445 . if ${_LICENSE_STATUS_${lic}} == "rejected"
446 _LICENSE_STATUS= rejected
447 . elif ${_LICENSE_STATUS_${lic}} == "ask"
448 _LICENSE_STATUS?= ask
449 _LICENSE_TO_ASK+= ${lic}
452 _LICENSE_STATUS?= accepted
455 # For dual/multi licenses, after processing all sub-licenses, the following
456 # must be determined: _LICENSE_NAME, _LICENSE_PERMS and _LICENSE_GROUPS.
458 .if ${_LICENSE_COMB} == "dual"
459 _LICENSE_NAME= Dual (any of): ${_LICENSE}
460 # Calculate least restrictive permissions (union)
462 . for lic in ${_LICENSE}
463 . for comp in ${_LICENSE_LIST_PERMS}
464 . if ${_LICENSE_PERMS_${lic}:M${comp}} != "" && \
465 ${_LICENSE_PERMS:M${comp}} == ""
466 _LICENSE_PERMS+= ${comp}
470 # Calculate least restrictive groups (union)
472 . for lic in ${_LICENSE}
473 . for comp in ${_LICENSE_LIST_GROUPS}
474 . if ${_LICENSE_GROUPS_${lic}:M${comp}} != "" && \
475 ${_LICENSE_GROUPS:M${comp}} == ""
476 _LICENSE_GROUPS+= ${comp}
481 .elif ${_LICENSE_COMB} == "multi"
482 _LICENSE_NAME= Multiple (all of): ${_LICENSE}
483 # Calculate most restrictive permissions (intersection)
484 _LICENSE_PERMS:= ${_LICENSE_LIST_PERMS}
485 . for lic in ${_LICENSE}
486 . for comp in ${_LICENSE_LIST_PERMS}
487 . if ${_LICENSE_PERMS_${lic}:M${comp}} == ""
488 _LICENSE_PERMS:= ${_LICENSE_PERMS:N${comp}}
492 # Calculate most restrictive groups (intersection)
493 _LICENSE_GROUPS:= ${_LICENSE_LIST_GROUPS}
494 . for lic in ${_LICENSE}
495 . for comp in ${_LICENSE_LIST_GROUPS}
496 . if ${_LICENSE_GROUPS_${lic}:M${comp}} == ""
497 _LICENSE_GROUPS:= ${_LICENSE_GROUPS:N${comp}}
503 # Prepare information for asking license to the user
505 .if ${_LICENSE_STATUS} == "ask" && ${_LICENSE_COMB} != "single"
506 _LICENSE_ASK_DATA!= mktemp -ut portslicense
509 # Calculate restrictions and set RESTRICTED_FILES when
510 # appropiate, together with cleaning targets.
512 # XXX For multiple licenses restricted distfiles are always removed from both
513 # CDROM and FTP, but the current framework supports separating them (would
514 # require better/new delete-package and delete-distfiles targets)
516 .if ${_LICENSE_PERMS:Mpkg-mirror} == ""
517 _LICENSE_RESTRICTED+= delete-package
518 .elif ${_LICENSE_PERMS:Mpkg-sell} == ""
519 _LICENSE_CDROM+= delete-package
522 .if ${_LICENSE_COMB} == "multi"
523 . for lic in ${_LICENSE}
524 . if ${_LICENSE_PERMS_${lic}:Mdist-mirror} == "" || ${_LICENSE_PERMS_${lic}:Mdist-sell} == ""
525 RESTRICTED_FILES+= ${_LICENSE_DISTFILES_${lic}}
528 . if defined(RESTRICTED_FILES)
529 RESTRICTED_FILES+= ${_PATCHFILES}
530 _LICENSE_RESTRICTED+= delete-distfiles
531 _LICENSE_CDROM+= delete-distfiles
534 . if ${_LICENSE_PERMS:Mdist-mirror} == ""
535 _LICENSE_RESTRICTED+= delete-distfiles
536 RESTRICTED_FILES= ${_PATCHFILES} ${_DISTFILES}
537 . elif ${_LICENSE_PERMS:Mdist-sell} == ""
538 _LICENSE_CDROM+= delete-distfiles
539 RESTRICTED_FILES= ${_PATCHFILES} ${_DISTFILES}
543 .if defined(_LICENSE_RESTRICTED)
544 clean-restricted: ${_LICENSE_RESTRICTED}
545 clean-restricted-list: ${_LICENSE_RESTRICTED:C/$/-list/}
548 clean-restricted-list:
551 .if defined(_LICENSE_CDROM)
552 clean-for-cdrom: ${_LICENSE_CDROM}
553 clean-for-cdrom-list: ${_LICENSE_CDROM:C/$/-list/}
556 clean-for-cdrom-list:
559 # Check variables are correctly defined and print status up to here
561 .if ${_LICENSE_STATUS} == "ask" && defined(BATCH)
562 IGNORE= License ${_LICENSE} needs confirmation, but BATCH is defined
566 .if defined(_LICENSE_ERROR)
567 @${ECHO_MSG} "===> License not correctly defined: ${_LICENSE_ERROR}"
570 .if ${_LICENSE_STATUS} == "rejected"
571 @${ECHO_MSG} "===> License ${_LICENSE} rejected by the user"
573 @${ECHO_MSG} "If you want to install this port make sure the following license(s) are not present in LICENSES_REJECTED, either in make arguments or /etc/make.conf: ${_LICENSE}. Also check LICENSES_GROUPS_REJECTED in case they contain a group this license(s) belong to." | ${FMT}
576 .elif ${_LICENSE_STATUS} == "accepted"
577 @${ECHO_MSG} "===> License ${_LICENSE} accepted by the user"
578 .elif ${_LICENSE_STATUS} == "ask"
579 @${ECHO_MSG} "===> License ${_LICENSE} needs confirmation, will ask later"
582 # Display, ask and save preference if requested
584 ask-license: ${_LICENSE_COOKIE}
587 # Make sure all required license files exist
588 .if ${_LICENSE_COMB} == "single"
589 . if !defined(LICENSE_FILE) && defined(_LICENSE_TEXT)
590 @test -f ${_LICENSE_FILE} || ${ECHO_CMD} "${_LICENSE_TEXT}" | ${FMT} > ${_LICENSE_FILE}
592 @test -f ${_LICENSE_FILE} || \
593 (${ECHO_MSG} "===> Missing license file for ${_LICENSE} in ${_LICENSE_FILE}"; exit 1)
595 . for lic in ${_LICENSE}
596 . if !defined(LICENSE_FILE_${lic}) && defined(_LICENSE_TEXT_${lic})
597 @test -f ${_LICENSE_FILE_${lic}} || ${ECHO_CMD} "${_LICENSE_TEXT_${lic}}" | ${FMT} > ${_LICENSE_FILE_${lic}}
599 @test -f ${_LICENSE_FILE_${lic}} || \
600 (${ECHO_MSG} "===> Missing license file for ${lic} in ${_LICENSE_FILE_${lic}}"; exit 1)
604 .if ${_LICENSE_STATUS} == "ask"
605 . if !defined(NO_LICENSES_DIALOGS)
607 . if ${_LICENSE_COMB} == "single"
608 @trap '${RM} -f $$tmpfile' EXIT INT TERM; \
609 tmpfile=$$(mktemp -t portlicenses); \
611 ${DIALOG} --menu "License for ${PKGNAME} (${_LICENSE})" 21 70 15 accept "Accept license" reject "Reject license" view "View license" 2>"$${tmpfile}"; \
612 result=`${CAT} $${tmpfile}`; \
616 view) ${DIALOG} --textbox "${_LICENSE_FILE}" 21 75 ;; \
620 . elif ${_LICENSE_COMB} == "dual"
621 @${RM} -f ${_LICENSE_ASK_DATA}
622 . for lic in ${_LICENSE_TO_ASK}
623 @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
625 @menu_cmd="${DIALOG} --hline \"This port requires you to accept at least one license\" --menu \"License for ${PKGNAME} (dual)\" 21 70 15"; \
626 trap '${RM} -f $$tmpfile' EXIT INT TERM; \
627 tmpfile=$$(mktemp -t portlicenses); \
628 for lic in ${_LICENSE_TO_ASK}; do \
629 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\" USE_$${lic} \"Accept the license $${lic}\""; \
631 menu_cmd="$${menu_cmd} REJECT \"Reject the licenses (all)\""; \
633 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
634 result=$$(${CAT} "$${tmpfile}"); \
637 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
638 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
639 ${DIALOG} --textbox "$${file}" 21 75 ;; \
640 USE_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^USE_//'); \
641 ${ECHO_CMD} $${name} > ${_LICENSE_COOKIE}; \
646 . elif ${_LICENSE_COMB} == "multi"
647 @${RM} -f ${_LICENSE_ASK_DATA}
648 . for lic in ${_LICENSE_TO_ASK}
649 @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
651 @menu_cmd="${DIALOG} --hline \"This port requires you to accept all mentioned licenses\" --menu \"License for ${PKGNAME} (multi)\" 21 70 15"; \
652 trap '${RM} -f $$tmpfile' EXIT INT TERM; \
653 tmpfile=$$(mktemp -t portlicenses); \
654 for lic in ${_LICENSE_TO_ASK}; do \
655 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\""; \
657 menu_cmd="$${menu_cmd} ACCEPT \"Accept the licenses (all)\" REJECT \"Reject the licenses (all)\""; \
659 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
660 result=$$(${CAT} "$${tmpfile}"); \
664 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
665 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
666 ${DIALOG} --textbox "$${file}" 21 75 ;; \
674 . if ${_LICENSE_COMB} == "single"
675 @${ECHO_MSG} "To install the port you must agree to the license: ${_LICENSE} (${_LICENSE_NAME})." | ${FMT}
677 @${ECHO_MSG} "You can view the license at ${_LICENSE_FILE:S/${WRKDIR}\//${WRKDIR:T}\//}."
678 . elif ${_LICENSE_COMB} == "dual"
679 @${ECHO_MSG} "To install the port you must agree to any of the following licenses:"
680 . elif ${_LICENSE_COMB} == "multi"
681 @${ECHO_MSG} "To install the port you must agree to all of the following licenses:"
684 . if ${_LICENSE_COMB} != "single"
685 . for lic in ${_LICENSE_TO_ASK}
686 @${ECHO_MSG} "- ${lic} (${_LICENSE_NAME_${lic}}), available at ${_LICENSE_FILE_${lic}:S/${WRKDIR}\//${WRKDIR:T}\//}"
690 @${ECHO_MSG} "If you agree with the corresponding license(s), add them to LICENSES_ACCEPTED either in make arguments or /etc/make.conf." | ${FMT}
694 @${RM} -f ${_LICENSE_ASK_DATA}
697 # Create report and catalog
698 .if !defined(NO_LICENSES_INSTALL)
699 @${RM} -f ${_LICENSE_CATALOG_TMP} ${_LICENSE_REPORT_TMP}
700 . if ${_LICENSE_COMB} == "single"
702 . for var in _LICENSE _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS _LICENSE_DISTFILES
703 @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
706 @${ECHO_CMD} "This package has a single license: ${_LICENSE} (${_LICENSE_NAME})." > ${_LICENSE_REPORT_TMP}
709 . for var in _LICENSE _LICENSE_COMB _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS
710 @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
712 . if ${_LICENSE_COMB} == "dual" && ${_LICENSE_STATUS} == "ask"
713 @${SED} -e 's/^/_LICENSE_SELECTED=/' ${_LICENSE_COOKIE} >> ${_LICENSE_CATALOG_TMP}
715 . for lic in ${_LICENSE}
716 . for var in NAME PERMS GROUPS DISTFILES
717 @${ECHO_CMD} "_LICENSE_${var}_${lic}=${_LICENSE_${var}_${lic}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
721 . if ${_LICENSE_COMB} == "dual"
722 @${ECHO_CMD} "This package has dual licenses (any of):" >> ${_LICENSE_REPORT_TMP}
723 . elif ${_LICENSE_COMB} == "multi"
724 @${ECHO_CMD} "This package has multiple licenses (all of):" >> ${_LICENSE_REPORT_TMP}
726 . for lic in ${_LICENSE}
727 @${ECHO_CMD} "- ${lic} (${_LICENSE_NAME_${lic}})" >> ${_LICENSE_REPORT_TMP}
733 @${TOUCH} ${_LICENSE_COOKIE}
735 # Package list entries, and installation
737 .if !defined(NO_LICENSES_INSTALL)
738 PLIST_FILES+= ${_LICENSE_DIR_REL}/${_LICENSE_CATALOG:T} \
739 ${_LICENSE_DIR_REL}/${_LICENSE_REPORT:T}
741 .if ${_LICENSE_COMB} == "single"
742 PLIST_FILES+= ${_LICENSE_DIR_REL}/${_LICENSE}
744 . for lic in ${_LICENSE}
745 . if defined(_LICENSE_FILE_${lic})
746 PLIST_FILES+= ${_LICENSE_DIR_REL}/${lic}
752 @${MKDIR} ${STAGEDIR}${_LICENSE_DIR}
753 @${INSTALL_DATA} ${_LICENSE_CATALOG_TMP} ${STAGEDIR}${_LICENSE_CATALOG}
754 @${INSTALL_DATA} ${_LICENSE_REPORT_TMP} ${STAGEDIR}${_LICENSE_REPORT}
755 .if ${_LICENSE_COMB} == "single"
756 @${INSTALL_DATA} ${_LICENSE_FILE} ${STAGEDIR}${_LICENSE_DIR}/${_LICENSE}
758 . for lic in ${_LICENSE}
759 @${INSTALL_DATA} ${_LICENSE_FILE_${lic}} ${STAGEDIR}${_LICENSE_DIR}/${lic}
762 # XXX @dirrmtry entry must be here (no way to do with PLIST_* vars)
763 @${ECHO_CMD} "@owner root" >> ${TMPPLIST}
764 @${ECHO_CMD} "@group wheel" >> ${TMPPLIST}
765 @${ECHO_CMD} "@cwd ${PREFIX}" >> ${TMPPLIST}
766 @${ECHO_CMD} "@dirrm ${_LICENSE_DIR_REL}" >> ${TMPPLIST}
767 @${ECHO_CMD} "@unexec rmdir %D/share/licenses 2>/dev/null || true" >> ${TMPPLIST}
774 . if defined(LICENSE_VERBOSE)
775 @${ECHO_MSG} "===> License check disabled, port has not defined LICENSE"