Import devel/fpc-fpmkunit version 2.6.4
[dports.git] / Mk / bsd.licenses.mk
1 #-*- tab-width: 4; -*-
2 # ex:ts=4
3 #
4 # $FreeBSD$
5
6 # ** Please run changes to this file by eadler@ first **
7
8 Licenses_Include_MAINTAINER=         portmgr@FreeBSD.org
9
10 #
11 # bsd.licenses.mk - License auditing framework.
12 #
13 # Created by: Alejandro Pulver <alepulver@FreeBSD.org>
14 #
15 # Please view me with 4 column tabs!
16 #
17
18 # TODO:
19 # - Bring back save and checksum with new dialog interface (only offers to do
20 #   so if ran by root, otherwise silently remove the options). Also only allow
21 #   saving per-port options (known or unknown), and only when accepted.
22 # - Add custom restriction targets for better integration (now some files are
23 #   removed from FTP if restricted for CDROM for example, as the old
24 #   behavior).
25
26 # The following cases are not considered:
27 #
28 # - Redistribution of modified distfiles, because is never done.
29 # - Creating binaries from modified sources, because packages almost always
30 #   contain modifications to the source, can not be autodetected (i.e.
31 #   patch-* in ${FILESDIR}, post-* targets, etc), and these licenses tend to
32 #   have more restrictions anyways.
33 #
34
35 # Integration with target sequences
36 #
37 # _SANITY_SEQ+=         check-license (after check-vulnerable)
38 # _PATCH_SEQ+=          ask-license (before any other targets)
39 # _INSTALL_SUSEQ+=      install-license (after install-desktop-entries)
40 #
41 # The 'check-license' target will determine if the license was accepted,
42 # rejected or has to be asked later to the user in 'ask-license' (by then
43 # licenses should be extracted).  The 'install-license' target installs the
44 # applications' licenses, a general package license mentioning them, and a
45 # restriction report (to be used by ports, scripts and similar tools).
46
47 # Variables provided to the ports system and users in general, to modify the
48 # behavior of the framework
49 #
50 # DISABLE_LICENSES                      - Disable license auditing framework completely.
51 # NO_LICENSES_INSTALL           - Do not install catalog, report and licenses.
52 # NO_LICENSES_DIALOGS           - Disable interactive menus for asking licenses.
53
54 #NO_LICENSES_INSTALL=           yes
55 #NO_LICENSES_DIALOGS=           yes
56
57 # Variables provided to users (can be passed to make or set in /etc/make.conf)
58 #
59 # LICENSES_ACCEPTED     - Accepted licenses.
60 # LICENSES_REJECTED     - Rejected licenses.
61 # LICENSES_GROUPS_ACCEPTED      - Accepted license groups.
62 # LICENSES_GROUPS_REJECTED      - Rejected license groups.
63 # LICENSES_ASK          - Require explicit user approval for all licenses not
64 #                                         present in previous variables (for example, stock
65 #                                         accepted licenses will ask confirmation).
66 #
67
68 # Variables provided to ports
69 #
70 # LICENSE                       - Code of license (short name).
71 # LICENSE_PERMS         - Permissions; use "none" if empty.
72 # LICENSE_GROUPS        - Groups the license belongs.
73 # LICENSE_NAME          - Full license name (for the reports).
74 # LICENSE_FILE          - Full path to license (or use LICENSE_TEXT).
75 # LICENSE_TEXT          - Text to use as a license, useful when referencing to
76 #                                         another place if it's not in the distfile.
77 # LICENSE_DISTFILES     - Name of licensed files (defaults to ${_DISTFILES}).
78 # LICENSE_COMB          - Set to "dual" or "multi", for OR/AND behavior
79 #                                         (defaults to "single" if undefined, the common case)
80 #
81 # The following cases are supported after defining LICENSE:
82 #
83 # Case 1: license defined in the framework (aka "known").
84 #
85 # In this case the only allowed variables to set are LICENSE_FILE and
86 # LICENSE_DISTFILES. The rest are managed by the framework and are not allowed
87 # to change.
88 #
89 # Case 2: license only known by the port (aka "unknown").
90 #
91 # In this case LICENSE_{PERMS,NAME} are mandatory, in addition to
92 # either LICENSE_FILE or LICENSE_TEXT. Optional variable is
93 # LICENSE_GROUPS.
94 #
95 # Available components for LICENSE_PERMS:
96 # dist-mirror   - Redistribution of distfile is permitted
97 #                                 (like FTP mirroring; port is not RESTRICTED).
98 # dist-sell             - Selling of distfile, e.g. on CD-ROM is permitted
99 #                                 (port does not need to set NO_CDROM).
100 # pkg-mirror    - Free redistribution of package is permitted
101 #                                 (like FTP upload; port does not set NO_PACKAGE).
102 # pkg-sell              - Selling of package is permitted, e.g. on CD-ROM.
103 # auto-accept   - License is accepted by default, without presented
104 #                                 agreement, unless the user defines LICENSES_ASK.
105 #
106 # Notes about permissions:
107 # - Permissions use a default-deny policy (e.g. not setting "dist-mirror"
108 #   means it is automatically excluded).
109 # - Components can be negated by prefixing them with "no-" (like
110 #   "no-pkg-sell").
111 # - In case a component is present and also excluded (i.e. no-dist-sell and
112 #   dist-sell together in LICENSE_PERMS), it will be excluded.
113 # - XXX Currently there is no point in "no-" prefixes, as permissions are not
114 #   inherited from groups. Maybe it looks more clear that way than leaving the
115 #   variable empty?
116 #
117 # Dual/multiple licenses:
118 #
119 # If LICENSE_COMB is set to "dual", then LICENSE can (must, actually) have
120 # more than one component. After that each license "lic" in LICENSE falls in
121 # previous cases (known or unknown), but their variables are prefixed by
122 # _LICENSE_ and suffixed by _lic. The main license name, perms and groups will
123 # be set automatically (following appropiate logic). The idea is that any
124 # license from LICENSE can be chosen to use the package.
125 #
126 # The case when LICENSE_COMB is set to "multi" is similar. But the idea is
127 # that all of the licenses in LICENSE must be agreed to use the package.
128 #
129
130 .if defined(_POSTMKINCLUDED) && !defined(BEFOREPORTMK)
131
132 .if defined(LICENSE)
133
134 # Include known licenses from database
135
136 .include "${PORTSDIR}/Mk/bsd.licenses.db.mk"
137
138 # Lists of variables and valid components
139 #
140 # _LICENSE_LIST_PERMS           - Valid permission components
141 # _LICENSE_LIST_PORT_VARS       - License variables defined by the port
142
143 _LICENSE_LIST_PERMS=            dist-mirror dist-sell pkg-mirror pkg-sell auto-accept none
144 _LICENSE_LIST_PORT_VARS=        PERMS NAME GROUPS
145
146 # Path variables
147 #
148 # _LICENSE_DIR          - Directory to install licenses
149 # _LICENSE_STORE        - Store for known license files
150 # _LICENSE_CATALOG      - License catalog (make include file) to be created (dst)
151 # _LICENSE_CATALOG_TMP  - Same as above, but in WRKDIR (src)
152 # _LICENSE_REPORT       - License summary, shows licenses and how they are combined (dst)
153 # _LICENSE_REPORT_TMP   - Same as above, but in WRKDIR (src)
154 # _LICENSE_COOKIE       - Set when license is accepted, it is not present in
155 #                                         bsd.port.mk to avoid creating LICENSE_{REQ,SEQ} for a
156 #                                         few more targets only.
157
158 _LICENSE_DIR?=          ${PREFIX}/share/licenses/${PKGNAME}
159 _LICENSE_STORE?=        ${PORTSDIR}/Templates/Licenses
160 _LICENSE_CATALOG?=      ${_LICENSE_DIR}/catalog.mk
161 _LICENSE_CATALOG_TMP?=  ${WRKDIR}/.license-catalog.mk
162 _LICENSE_REPORT?=       ${_LICENSE_DIR}/LICENSE
163 _LICENSE_REPORT_TMP?=   ${WRKDIR}/.license-report
164 _LICENSE_COOKIE?=       ${WRKDIR}/.license_done.${PORTNAME}.${PREFIX:S/\//_/g}
165
166 # Defaults (never overriden for now)
167 #
168 # _LICENSE                      - Copy of LICENSE (for now)
169 # _LICENSE_COMB         - Copy of LICENSE_COMB (but "single" instead of empty)
170
171 _LICENSE?=                      ${LICENSE}
172 .if !defined(LICENSE_COMB)
173 _LICENSE_COMB=          single
174 .else
175 _LICENSE_COMB=          ${LICENSE_COMB}
176 .endif
177
178 # Check if single or dual/multiple license
179 #
180 # Make sure LICENSE_COMB is only used with more than one license.
181
182 .if ${_LICENSE_COMB} != "single" && ${_LICENSE_COMB} != "dual" && ${_LICENSE_COMB} != "multi"
183 _LICENSE_ERROR?=        invalid value for LICENSE_COMB: "${_LICENSE_COMB}" (should be "single", "dual" or "multi")
184 .endif
185
186 .for lic in ${_LICENSE}
187 .       if defined(_LICENSE_DEFINED)
188 .               if ${_LICENSE_COMB} == "single"
189 _LICENSE_ERROR?=        multiple licenses in LICENSE, but LICENSE_COMB is set to "single" (or undefined)
190 .               else
191 _LICENSE_MULTI=         yes
192 .               endif
193 .       else
194 _LICENSE_DEFINED=       yes
195 .       endif
196 .endfor
197 .if ${_LICENSE_COMB} != "single" && !defined(_LICENSE_MULTI)
198 _LICENSE_ERROR?=        single license in LICENSE, but LICENSE_COMB is set to "${_LICENSE_COMB}" (requires more than one)
199 .endif
200 .if !defined(_LICENSE_DEFINED)
201 _LICENSE_ERROR?=        no licenses present in LICENSE (empty string)
202 .endif
203 .undef _LICENSE_DEFINED
204 .undef _LICENSE_MULTI
205
206 # Evaluate port license groups and permissions
207 #
208 # Available values for _LICENSE_TYPE:
209 #
210 # Case 1: "known" (license info taken from internal database)
211 # Case 2: "unknown" (LICENSE is not known, and info taken from port)
212 #
213 # Make sure required variables are defined, and remove conflicting (positive
214 # and negative) duplicated components.
215
216 .if ${_LICENSE_COMB} == "single"
217 # Defaults to empty
218 _LICENSE_GROUPS?=       #
219 # Start
220 .       for lic in ${_LICENSE}
221 .               if ${_LICENSE_LIST:M${lic}} != ""
222 # Case 1: license defined in the framework.
223 _LICENSE_TYPE=          known
224 .                       for var in ${_LICENSE_LIST_PORT_VARS}
225 .                               if defined(LICENSE_${var})
226 _LICENSE_ERROR?=        redefining LICENSE_${var} is not allowed for known licenses, to define a custom license try another LICENSE name like ${_LICENSE}-variant
227 .                               endif
228 .                               if !defined(_LICENSE_${var}_${lic})
229 _LICENSE_ERROR?=        ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
230 .                               else
231 _LICENSE_${var}=        ${_LICENSE_${var}_${lic}}
232 .                               endif
233 .                       endfor
234 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
235 .                       if !defined(LICENSE_FILE)
236 .                               if !defined(LICENSE_TEXT)
237 .                                       if exists(${_LICENSE_STORE}/${lic})
238 _LICENSE_FILE=          ${_LICENSE_STORE}/${lic}
239 .                                       else
240 # No license file in /usr/ports/Templates/Licenses
241 _LICENSE_TEXT=          The license: ${_LICENSE} (${_LICENSE_NAME}) is standard, please read from the web.
242 _LICENSE_FILE=          ${WRKDIR}/${lic}
243 .                                       endif
244 .                               else
245 _LICENSE_ERROR?=        defining LICENSE_TEXT is not allowed for known licenses
246 .                               endif
247 .                       else
248 _LICENSE_FILE=          ${LICENSE_FILE}
249 .                       endif
250
251 .               else
252 # Case 2: license only known by the port.
253 _LICENSE_TYPE=          unknown
254 .                       for var in ${_LICENSE_LIST_PORT_VARS}
255 .                               if defined(LICENSE_${var})
256 _LICENSE_${var}=        ${LICENSE_${var}}
257 .                               elif !defined(_LICENSE_${var})
258 _LICENSE_ERROR?=        for unknown licenses, defining LICENSE_${var} is mandatory (otherwise use a known LICENSE)
259 .                               endif
260 .                       endfor
261 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
262 __LICENSE_PERMS:=       #
263 .                       for comp in ${_LICENSE_PERMS}
264 .                               if ${_LICENSE_LIST_PERMS:M${comp:C/^no-//}} == ""
265 _LICENSE_ERROR?=        invalid LICENSE_PERMS component "${comp}"
266 .                               elif ${__LICENSE_PERMS:M${comp}} == "" && \
267                                          ${_LICENSE_PERMS:Mno-${comp:C/^no-//}} == ""
268 __LICENSE_PERMS+=       ${comp}
269 .                               endif
270 .                       endfor
271 _LICENSE_PERMS:=        ${__LICENSE_PERMS}
272 .                       undef __LICENSE_PERMS
273 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
274 .                       if !defined(LICENSE_FILE)
275 .                               if !defined(LICENSE_TEXT)
276 _LICENSE_ERROR?=        either LICENSE_FILE or LICENSE_TEXT must be defined
277 .                               else
278 _LICENSE_TEXT=          ${LICENSE_TEXT}
279 _LICENSE_FILE=          ${WRKDIR}/${lic}
280 .                               endif
281 .                       else
282 _LICENSE_FILE=          ${LICENSE_FILE}
283 .                       endif
284 .               endif
285
286 # Only one is allowed
287 .               if defined(LICENSE_FILE) && defined(LICENSE_TEXT)
288 _LICENSE_ERROR?=        defining both LICENSE_FILE and LICENSE_TEXT is not allowed
289 .               endif
290 # Distfiles
291 .               if !defined(LICENSE_DISTFILES)
292 _LICENSE_DISTFILES=     ${_DISTFILES}
293 .               else
294 _LICENSE_DISTFILES=     ${LICENSE_DISTFILES}
295 .               endif
296 .       endfor
297
298 .else
299 .       for lic in ${_LICENSE}
300 # Defaults to empty
301 _LICENSE_GROUPS_${lic}?=#
302 .               if ${_LICENSE_LIST:M${lic}} != ""
303 # Case 1: license defined in the framework.
304 _LICENSE_TYPE_${lic}=   known
305 .                       for var in ${_LICENSE_LIST_PORT_VARS}
306 .                               if defined(LICENSE_${var}_${lic})
307 _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
308 .                               endif
309 .                               if !defined(_LICENSE_${var}_${lic})
310 _LICENSE_ERROR?=        ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
311 .                               endif
312 .                       endfor
313 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
314 .                       if !defined(LICENSE_FILE_${lic})
315 .                               if !defined(LICENSE_TEXT_${lic})
316 .                                       if exists(${_LICENSE_STORE}/${lic})
317 _LICENSE_FILE_${lic}=           ${_LICENSE_STORE}/${lic}
318 .                                       else
319 #  No license file in /usr/ports/Templates/Licenses
320 _LICENSE_TEXT_${lic}=   The license: ${lic} (${_LICENSE_NAME_${lic}}) is standard, please read from the web.
321 _LICENSE_FILE_${lic}=   ${WRKDIR}/${lic}
322 .                                       endif
323 .                               else
324 _LICENSE_ERROR?=        defining LICENSE_TEXT_${lic} is not allowed for known licenses
325 .                               endif
326 .                       else
327 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
328 .                       endif
329
330 .               else
331 # Case 2: license only known by the port.
332 _LICENSE_TYPE_${lic}=   unknown
333 .                       for var in ${_LICENSE_LIST_PORT_VARS}
334 .                               if defined(LICENSE_${var}_${lic})
335 _LICENSE_${var}_${lic}= ${LICENSE_${var}_${lic}}
336 .                               elif !defined(_LICENSE_${var}_${lic})
337 _LICENSE_ERROR?=        for unknown licenses, defining LICENSE_${var}_${lic} is mandatory (otherwise use a known LICENSE)
338 .                               endif
339 .                       endfor
340 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
341 __LICENSE_PERMS:=       #
342 .                       for comp in ${_LICENSE_PERMS_${lic}}
343 .                               if ${_LICENSE_LIST_PERMS:M${comp:C/^no-//}} == ""
344 _LICENSE_ERROR?=                invalid LICENSE_PERMS_${var} component "${comp}"
345 .                               elif ${__LICENSE_PERMS:M${comp}} == "" && \
346                                          ${_LICENSE_PERMS_${lic}:Mno-${comp:C/^no-//}} == ""
347 __LICENSE_PERMS+=               ${comp}
348 .                               endif
349 .                       endfor
350 _LICENSE_PERMS_${lic}:= ${__LICENSE_PERMS}
351 .                       undef __LICENSE_PERMS
352 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
353 .                       if !defined(LICENSE_FILE_${lic})
354 .                               if !defined(LICENSE_TEXT_${lic})
355 _LICENSE_ERROR?=                either LICENSE_FILE_${lic} or LICENSE_TEXT_${lic} must be defined
356 .                               else
357 _LICENSE_TEXT_${lic}=   ${LICENSE_TEXT_${lic}}
358 _LICENSE_FILE_${lic}=   ${WRKDIR}/${lic}
359 .                               endif
360 .                       else
361 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
362 .                       endif
363 .               endif
364
365 # Only one is allowed
366 .               if defined(LICENSE_FILE_${lic}) && defined(LICENSE_TEXT_${lic})
367 _LICENSE_ERROR?=                defining both LICENSE_FILE_${lic} and LICENSE_TEXT_${lic}is not allowed
368 .               endif
369 # Distfiles
370 .               if !defined(LICENSE_DISTFILES_${lic})
371 _LICENSE_DISTFILES_${lic}=      ${_DISTFILES}
372 .               else
373 _LICENSE_DISTFILES_${lic}=      ${LICENSE_DISTFILES_${lic}}
374 .               endif
375 .       endfor
376 .endif
377
378 # Check if the user agrees with the license
379
380 # Make sure these are defined
381
382 LICENSES_ACCEPTED?=                     #
383 LICENSES_REJECTED?=                     #
384 LICENSES_GROUPS_ACCEPTED?=      #
385 LICENSES_GROUPS_REJECTED?=      #
386
387 # Evaluate per-license status
388
389 .if ${_LICENSE_COMB} == "single"
390 .       for lic in ${_LICENSE}
391 .               if ${LICENSES_REJECTED:M${lic}} != ""
392 _LICENSE_STATUS?=       rejected
393 .               endif
394 .               for group in ${_LICENSE_GROUPS}
395 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
396 _LICENSE_STATUS?=       rejected
397 .                       endif
398 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
399 _LICENSE_STATUS?=       accepted
400 .                       endif
401 .               endfor
402 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
403 _LICENSE_STATUS?=       accepted
404 .               endif
405 .               if ${_LICENSE_PERMS:Mauto-accept} != "" && !defined(LICENSES_ASK)
406 _LICENSE_STATUS?=       accepted
407 .               endif
408 _LICENSE_STATUS?=       ask
409 .       endfor
410
411 .else
412 .       for lic in ${_LICENSE}
413 .               if ${LICENSES_REJECTED:M${lic}} != ""
414 _LICENSE_STATUS_${lic}?=        rejected
415 .               endif
416 .               for group in ${_LICENSE_GROUPS_${lic}}
417 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
418 _LICENSE_STATUS_${lic}?=        rejected
419 .                       endif
420 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
421 _LICENSE_STATUS_${lic}?=        accepted
422 .                       endif
423 .               endfor
424 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
425 _LICENSE_STATUS_${lic}?=        accepted
426 .               endif
427 .               if ${_LICENSE_PERMS_${lic}:Mauto-accept} != "" && !defined(LICENSES_ASK)
428 _LICENSE_STATUS_${lic}?=        accepted
429 .               endif
430 _LICENSE_STATUS_${lic}?=        ask
431 .       endfor
432 .endif
433
434 # Evaluate general status
435
436 .if ${_LICENSE_COMB} == "dual"
437 .       for lic in ${_LICENSE}
438 .               if ${_LICENSE_STATUS_${lic}} == "accepted"
439 _LICENSE_STATUS=        accepted
440 .               elif ${_LICENSE_STATUS_${lic}} == "ask"
441 _LICENSE_STATUS?=       ask
442 _LICENSE_TO_ASK+=       ${lic}
443 .               endif
444 _LICENSE_STATUS?=       rejected
445 .       endfor
446
447 .elif ${_LICENSE_COMB} == "multi"
448 .       for lic in ${_LICENSE}
449 .               if ${_LICENSE_STATUS_${lic}} == "rejected"
450 _LICENSE_STATUS=        rejected
451 .               elif ${_LICENSE_STATUS_${lic}} == "ask"
452 _LICENSE_STATUS?=       ask
453 _LICENSE_TO_ASK+=       ${lic}
454 .               endif
455 .       endfor
456 _LICENSE_STATUS?=       accepted
457 .endif
458
459 # For dual/multi licenses, after processing all sub-licenses, the following
460 # must be determined: _LICENSE_NAME, _LICENSE_PERMS and _LICENSE_GROUPS.
461
462 .if ${_LICENSE_COMB} == "dual"
463 _LICENSE_NAME=          Dual (any of): ${_LICENSE}
464 # Calculate least restrictive permissions (union)
465 _LICENSE_PERMS:=        #
466 .       for lic in ${_LICENSE}
467 .               for comp in ${_LICENSE_LIST_PERMS}
468 .                       if ${_LICENSE_PERMS_${lic}:M${comp}} != "" && \
469                            ${_LICENSE_PERMS:M${comp}} == ""
470 _LICENSE_PERMS+=        ${comp}
471 .                       endif
472 .               endfor
473 .       endfor
474 # Calculate least restrictive groups (union)
475 _LICENSE_GROUPS:=       #
476 .       for lic in ${_LICENSE}
477 .               for comp in ${_LICENSE_LIST_GROUPS}
478 .                       if ${_LICENSE_GROUPS_${lic}:M${comp}} != "" && \
479                            ${_LICENSE_GROUPS:M${comp}} == ""
480 _LICENSE_GROUPS+=       ${comp}
481 .                       endif
482 .               endfor
483 .       endfor
484
485 .elif ${_LICENSE_COMB} == "multi"
486 _LICENSE_NAME=          Multiple (all of): ${_LICENSE}
487 # Calculate most restrictive permissions (intersection)
488 _LICENSE_PERMS:=        ${_LICENSE_LIST_PERMS}
489 .       for lic in ${_LICENSE}
490 .               for comp in ${_LICENSE_LIST_PERMS}
491 .                       if ${_LICENSE_PERMS_${lic}:M${comp}} == ""
492 _LICENSE_PERMS:=        ${_LICENSE_PERMS:N${comp}}
493 .                       endif
494 .               endfor
495 .       endfor
496 # Calculate most restrictive groups (intersection)
497 _LICENSE_GROUPS:=       ${_LICENSE_LIST_GROUPS}
498 .       for lic in ${_LICENSE}
499 .               for comp in ${_LICENSE_LIST_GROUPS}
500 .                       if ${_LICENSE_GROUPS_${lic}:M${comp}} == ""
501 _LICENSE_GROUPS:=       ${_LICENSE_GROUPS:N${comp}}
502 .                       endif
503 .               endfor
504 .       endfor
505 .endif
506
507 # Prepare information for asking license to the user
508
509 .if ${_LICENSE_STATUS} == "ask" && ${_LICENSE_COMB} != "single"
510 _LICENSE_ASK_DATA!=     mktemp -ut portslicense
511 .endif
512
513 # Calculate restrictions and set RESTRICTED_FILES when
514 # appropiate, together with cleaning targets.
515 #
516 # XXX For multiple licenses restricted distfiles are always removed from both
517 # CDROM and FTP, but the current framework supports separating them (would
518 # require better/new delete-package and delete-distfiles targets)
519
520 .if ${_LICENSE_PERMS:Mpkg-mirror} == ""
521 _LICENSE_RESTRICTED+=   delete-package
522 .elif ${_LICENSE_PERMS:Mpkg-sell} == ""
523 _LICENSE_CDROM+=                delete-package
524 .endif
525
526 .if ${_LICENSE_COMB} == "multi"
527 .       for lic in ${_LICENSE}
528 .               if ${_LICENSE_PERMS_${lic}:Mdist-mirror} == "" || ${_LICENSE_PERMS_${lic}:Mdist-sell} == ""
529 RESTRICTED_FILES+=              ${_LICENSE_DISTFILES_${lic}}
530 .               endif
531 .       endfor
532 .       if defined(RESTRICTED_FILES)
533 RESTRICTED_FILES+=              ${_PATCHFILES}
534 _LICENSE_RESTRICTED+=   delete-distfiles
535 _LICENSE_CDROM+=                delete-distfiles
536 .       endif
537 .else
538 .       if ${_LICENSE_PERMS:Mdist-mirror} == ""
539 _LICENSE_RESTRICTED+=   delete-distfiles
540 RESTRICTED_FILES=               ${_PATCHFILES} ${_DISTFILES}
541 .       elif ${_LICENSE_PERMS:Mdist-sell} == ""
542 _LICENSE_CDROM+=                delete-distfiles
543 RESTRICTED_FILES=               ${_PATCHFILES} ${_DISTFILES}
544 .       endif
545 .endif
546
547 .if defined(_LICENSE_RESTRICTED)
548 # _LICENSE_RESTRICTED contains 'delete-distfiles' and 'delete-package' if
549 # needed with RESTRICTED_FILES filled from above.
550 clean-restricted:       ${_LICENSE_RESTRICTED}
551 clean-restricted-list: ${_LICENSE_RESTRICTED:C/$/-list/}
552 .else
553 clean-restricted:
554 clean-restricted-list:
555 .endif
556
557 .if defined(_LICENSE_CDROM)
558 clean-for-cdrom:        ${_LICENSE_CDROM}
559 clean-for-cdrom-list: ${_LICENSE_CDROM:C/$/-list/}
560 .else
561 clean-for-cdrom:
562 clean-for-cdrom-list:
563 .endif
564
565 # Check variables are correctly defined and print status up to here
566
567 .if ${_LICENSE_STATUS} == "ask" && defined(BATCH)
568 IGNORE=         License ${_LICENSE} needs confirmation, but BATCH is defined
569 .endif
570
571 check-license:
572 .if defined(_LICENSE_ERROR)
573                 @${ECHO_MSG} "===>  License not correctly defined: ${_LICENSE_ERROR}"
574                 @exit 1
575 .endif
576 .if ${_LICENSE_STATUS} == "rejected"
577                 @${ECHO_MSG} "===>  License ${_LICENSE} rejected by the user"
578                 @${ECHO_MSG}
579                 @${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}
580                 @${ECHO_MSG}
581                 @exit 1
582 .elif ${_LICENSE_STATUS} == "accepted"
583                 @${ECHO_MSG} "===>  License ${_LICENSE} accepted by the user"
584 .elif ${_LICENSE_STATUS} == "ask"
585                 @${ECHO_MSG} "===>  License ${_LICENSE} needs confirmation, will ask later"
586 .endif
587
588 # Display, ask and save preference if requested
589
590 ask-license: ${_LICENSE_COOKIE}
591
592 ${_LICENSE_COOKIE}:
593 # Make sure all required license files exist
594 .if ${_LICENSE_COMB} == "single"
595 .       if !defined(LICENSE_FILE) && defined(_LICENSE_TEXT)
596         @test -f ${_LICENSE_FILE} || ${ECHO_CMD} "${_LICENSE_TEXT}" | ${FMT} > ${_LICENSE_FILE}
597 .       endif
598         @test -f ${_LICENSE_FILE} || \
599                 (${ECHO_MSG} "===>  Missing license file for ${_LICENSE} in ${_LICENSE_FILE}"; exit 1)
600 .else
601 .       for lic in ${_LICENSE}
602 .               if !defined(LICENSE_FILE_${lic}) && defined(_LICENSE_TEXT_${lic})
603         @test -f ${_LICENSE_FILE_${lic}} || ${ECHO_CMD} "${_LICENSE_TEXT_${lic}}" | ${FMT} > ${_LICENSE_FILE_${lic}}
604 .               endif
605         @test -f ${_LICENSE_FILE_${lic}} || \
606                 (${ECHO_MSG} "===>  Missing license file for ${lic} in ${_LICENSE_FILE_${lic}}"; exit 1)
607 .       endfor
608 .endif
609
610 .if ${_LICENSE_STATUS} == "ask"
611 .       if !defined(NO_LICENSES_DIALOGS)
612 # Dialog interface
613 .               if ${_LICENSE_COMB} == "single"
614         @trap '${RM} -f $$tmpfile' EXIT INT TERM; \
615         tmpfile=$$(mktemp -t portlicenses); \
616         while true; do \
617                 ${DIALOG} --menu "License for ${PKGNAME} (${_LICENSE})" 21 70 15 accept "Accept license" reject "Reject license" view "View license" 2>"$${tmpfile}"; \
618                 result=`${CAT} $${tmpfile}`; \
619                 case $${result} in \
620                 accept) break ;; \
621                 reject) exit 1;; \
622                 view)   ${DIALOG} --textbox "${_LICENSE_FILE}" 21 75 ;; \
623                 esac; \
624         done
625
626 .               elif ${_LICENSE_COMB} == "dual"
627         @${RM} -f ${_LICENSE_ASK_DATA}
628 .                       for lic in ${_LICENSE_TO_ASK}
629         @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
630 .                       endfor
631         @menu_cmd="${DIALOG} --hline \"This port requires you to accept at least one license\" --menu \"License for ${PKGNAME} (dual)\" 21 70 15"; \
632         trap '${RM} -f $$tmpfile' EXIT INT TERM; \
633         tmpfile=$$(mktemp -t portlicenses); \
634         for lic in ${_LICENSE_TO_ASK}; do \
635                 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\" USE_$${lic} \"Accept the license $${lic}\""; \
636         done; \
637         menu_cmd="$${menu_cmd} REJECT \"Reject the licenses (all)\""; \
638         while true; do \
639                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
640                 result=$$(${CAT} "$${tmpfile}"); \
641                 case $${result} in \
642                 REJECT) exit 1;; \
643                 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
644                                 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
645                                 ${DIALOG} --textbox "$${file}" 21 75 ;; \
646                 USE_*)  name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^USE_//'); \
647                                 ${ECHO_CMD} $${name} > ${_LICENSE_COOKIE}; \
648                                 break ;; \
649                 esac; \
650         done
651
652 .               elif ${_LICENSE_COMB} == "multi"
653         @${RM} -f ${_LICENSE_ASK_DATA}
654 .                       for lic in ${_LICENSE_TO_ASK}
655         @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
656 .                       endfor
657         @menu_cmd="${DIALOG} --hline \"This port requires you to accept all mentioned licenses\" --menu \"License for ${PKGNAME} (multi)\" 21 70 15"; \
658         trap '${RM} -f $$tmpfile' EXIT INT TERM; \
659         tmpfile=$$(mktemp -t portlicenses); \
660         for lic in ${_LICENSE_TO_ASK}; do \
661                 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\""; \
662         done; \
663         menu_cmd="$${menu_cmd} ACCEPT \"Accept the licenses (all)\" REJECT \"Reject the licenses (all)\""; \
664         while true; do \
665                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
666                 result=$$(${CAT} "$${tmpfile}"); \
667                 case $${result} in \
668                 ACCEPT) break ;; \
669                 REJECT) exit 1 ;; \
670                 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
671                                 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
672                                 ${DIALOG} --textbox "$${file}" 21 75 ;; \
673                 esac; \
674         done
675 .               endif
676
677 .       else
678 # Text interface
679         @${ECHO_MSG}
680 .               if ${_LICENSE_COMB} == "single"
681         @${ECHO_MSG} "To install the port you must agree to the license: ${_LICENSE} (${_LICENSE_NAME})." | ${FMT}
682         @${ECHO_MSG}
683         @${ECHO_MSG} "You can view the license at ${_LICENSE_FILE:S/${WRKDIR}\//${WRKDIR:T}\//}."
684 .               elif ${_LICENSE_COMB} == "dual"
685         @${ECHO_MSG} "To install the port you must agree to any of the following licenses:"
686 .               elif ${_LICENSE_COMB} == "multi"
687         @${ECHO_MSG} "To install the port you must agree to all of the following licenses:"
688 .               endif
689         @${ECHO_MSG}
690 .               if ${_LICENSE_COMB} != "single"
691 .                       for lic in ${_LICENSE_TO_ASK}
692 .                               if defined(WRKDIRPREFIX)
693         @${ECHO_MSG} "- ${lic} (${_LICENSE_NAME_${lic}}), available at ${_LICENSE_FILE_${lic}}"
694 .                               else
695         @${ECHO_MSG} "- ${lic} (${_LICENSE_NAME_${lic}}), available at ${_LICENSE_FILE_${lic}:S/${WRKDIR}\//${WRKDIR:T}\//}"
696 .                               endif
697 .                       endfor
698         @${ECHO_MSG}
699 .               endif
700         @${ECHO_MSG} "If you agree with the corresponding license(s), add them to LICENSES_ACCEPTED either in make arguments or /etc/make.conf." | ${FMT}
701         @${ECHO_MSG}
702         @exit 1
703 .       endif
704         @${RM} -f ${_LICENSE_ASK_DATA}
705 .endif
706
707 # Create report and catalog
708 .if !defined(NO_LICENSES_INSTALL)
709         @${RM} -f ${_LICENSE_CATALOG_TMP} ${_LICENSE_REPORT_TMP}
710 .       if ${_LICENSE_COMB} == "single"
711 # Catalog
712 .               for var in _LICENSE _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS _LICENSE_DISTFILES
713         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
714 .               endfor
715 # Report
716         @${ECHO_CMD} "This package has a single license: ${_LICENSE} (${_LICENSE_NAME})." > ${_LICENSE_REPORT_TMP}
717 .       else
718 # Catalog
719 .               for var in _LICENSE _LICENSE_COMB _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS
720         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
721 .               endfor
722 .               if ${_LICENSE_COMB} == "dual" && ${_LICENSE_STATUS} == "ask"
723         @${SED} -e 's/^/_LICENSE_SELECTED=/' ${_LICENSE_COOKIE} >> ${_LICENSE_CATALOG_TMP}
724 .               endif
725 .               for lic in ${_LICENSE}
726 .                       for var in NAME PERMS GROUPS DISTFILES
727         @${ECHO_CMD} "_LICENSE_${var}_${lic}=${_LICENSE_${var}_${lic}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
728 .                       endfor
729 .               endfor
730 # Report
731 .               if ${_LICENSE_COMB} == "dual"
732         @${ECHO_CMD} "This package has dual licenses (any of):"  >> ${_LICENSE_REPORT_TMP}
733 .               elif ${_LICENSE_COMB} == "multi"
734         @${ECHO_CMD} "This package has multiple licenses (all of):"  >> ${_LICENSE_REPORT_TMP}
735 .               endif
736 .               for lic in ${_LICENSE}
737         @${ECHO_CMD} "- ${lic} (${_LICENSE_NAME_${lic}})"  >> ${_LICENSE_REPORT_TMP}
738 .               endfor
739 .       endif
740 .endif
741
742 # Cookie (done here)
743         @${TOUCH} ${_LICENSE_COOKIE}
744
745 # Package list entries, and installation
746
747 .if !defined(NO_LICENSES_INSTALL)
748 PLIST_FILES+=   ${_LICENSE_CATALOG} \
749                                 ${_LICENSE_REPORT}
750
751 .if ${_LICENSE_COMB} == "single"
752 PLIST_FILES+=   ${_LICENSE_DIR}/${_LICENSE}
753 .else
754 .       for lic in ${_LICENSE}
755 .               if defined(_LICENSE_FILE_${lic})
756 PLIST_FILES+=   ${_LICENSE_DIR}/${lic}
757 .               endif
758 .       endfor
759 .endif
760
761 install-license:
762         @${MKDIR} ${STAGEDIR}${_LICENSE_DIR}
763         @${INSTALL_DATA} ${_LICENSE_CATALOG_TMP} ${STAGEDIR}${_LICENSE_CATALOG}
764         @${INSTALL_DATA} ${_LICENSE_REPORT_TMP} ${STAGEDIR}${_LICENSE_REPORT}
765 .if ${_LICENSE_COMB} == "single"
766         @${INSTALL_DATA} ${_LICENSE_FILE} ${STAGEDIR}${_LICENSE_DIR}/${_LICENSE}
767 .else
768 .       for lic in ${_LICENSE}
769         @${INSTALL_DATA} ${_LICENSE_FILE_${lic}} ${STAGEDIR}${_LICENSE_DIR}/${lic}
770 .       endfor
771 .endif
772 .endif
773
774 .else   # !LICENSE
775
776 check-license:
777 .       if defined(LICENSE_VERBOSE)
778         @${ECHO_MSG} "===>  License check disabled, port has not defined LICENSE"
779 .       endif
780
781 .endif  # LICENSE
782
783 .endif