Tweak devel/racer version 2.1.31
[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, cannot 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
300 .       if defined(LICENSE_FILE)
301 .               for lic in ${_LICENSE}
302 LICENSE_FILE_${lic}?=   ${LICENSE_FILE}
303 .               endfor
304 .       endif
305
306 .       for lic in ${_LICENSE}
307 # Defaults to empty
308 _LICENSE_GROUPS_${lic}?=#
309 .               if ${_LICENSE_LIST:M${lic}} != ""
310 # Case 1: license defined in the framework.
311 _LICENSE_TYPE_${lic}=   known
312 .                       for var in ${_LICENSE_LIST_PORT_VARS}
313 .                               if defined(LICENSE_${var}_${lic})
314 _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
315 .                               endif
316 .                               if !defined(_LICENSE_${var}_${lic})
317 _LICENSE_ERROR?=        ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
318 .                               endif
319 .                       endfor
320 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
321 .                       if !defined(LICENSE_FILE_${lic})
322 .                               if !defined(LICENSE_TEXT_${lic})
323 .                                       if exists(${_LICENSE_STORE}/${lic})
324 _LICENSE_FILE_${lic}=           ${_LICENSE_STORE}/${lic}
325 .                                       else
326 #  No license file in /usr/ports/Templates/Licenses
327 _LICENSE_TEXT_${lic}=   The license: ${lic} (${_LICENSE_NAME_${lic}}) is standard, please read from the web.
328 _LICENSE_FILE_${lic}=   ${WRKDIR}/${lic}
329 .                                       endif
330 .                               else
331 _LICENSE_ERROR?=        defining LICENSE_TEXT_${lic} is not allowed for known licenses
332 .                               endif
333 .                       else
334 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
335 .                       endif
336
337 .               else
338 # Case 2: license only known by the port.
339 _LICENSE_TYPE_${lic}=   unknown
340 .                       for var in ${_LICENSE_LIST_PORT_VARS}
341 .                               if defined(LICENSE_${var}_${lic})
342 _LICENSE_${var}_${lic}= ${LICENSE_${var}_${lic}}
343 .                               elif !defined(_LICENSE_${var}_${lic})
344 _LICENSE_ERROR?=        for unknown licenses, defining LICENSE_${var}_${lic} is mandatory (otherwise use a known LICENSE)
345 .                               endif
346 .                       endfor
347 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
348 __LICENSE_PERMS:=       #
349 .                       for comp in ${_LICENSE_PERMS_${lic}}
350 .                               if ${_LICENSE_LIST_PERMS:M${comp:C/^no-//}} == ""
351 _LICENSE_ERROR?=                invalid LICENSE_PERMS_${var} component "${comp}"
352 .                               elif ${__LICENSE_PERMS:M${comp}} == "" && \
353                                          ${_LICENSE_PERMS_${lic}:Mno-${comp:C/^no-//}} == ""
354 __LICENSE_PERMS+=               ${comp}
355 .                               endif
356 .                       endfor
357 _LICENSE_PERMS_${lic}:= ${__LICENSE_PERMS}
358 .                       undef __LICENSE_PERMS
359 # Check for LICENSE_FILE or at least LICENSE_TEXT (which simulates it)
360 .                       if !defined(LICENSE_FILE_${lic})
361 .                               if !defined(LICENSE_TEXT_${lic})
362 _LICENSE_ERROR?=                either LICENSE_FILE_${lic} or LICENSE_TEXT_${lic} must be defined
363 .                               else
364 _LICENSE_TEXT_${lic}=   ${LICENSE_TEXT_${lic}}
365 _LICENSE_FILE_${lic}=   ${WRKDIR}/${lic}
366 .                               endif
367 .                       else
368 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
369 .                       endif
370 .               endif
371
372 # Only one is allowed
373 .               if defined(LICENSE_FILE_${lic}) && defined(LICENSE_TEXT_${lic})
374 _LICENSE_ERROR?=                defining both LICENSE_FILE_${lic} and LICENSE_TEXT_${lic}is not allowed
375 .               endif
376 # Distfiles
377 .               if !defined(LICENSE_DISTFILES_${lic})
378 _LICENSE_DISTFILES_${lic}=      ${_DISTFILES}
379 .               else
380 _LICENSE_DISTFILES_${lic}=      ${LICENSE_DISTFILES_${lic}}
381 .               endif
382 .       endfor
383 .endif
384
385 # Check if the user agrees with the license
386
387 # Make sure these are defined
388
389 LICENSES_ACCEPTED?=                     #
390 LICENSES_REJECTED?=                     #
391 LICENSES_GROUPS_ACCEPTED?=      #
392 LICENSES_GROUPS_REJECTED?=      #
393
394 # Evaluate per-license status
395
396 .if ${_LICENSE_COMB} == "single"
397 .       for lic in ${_LICENSE}
398 .               if ${LICENSES_REJECTED:M${lic}} != ""
399 _LICENSE_STATUS?=       rejected
400 .               endif
401 .               for group in ${_LICENSE_GROUPS}
402 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
403 _LICENSE_STATUS?=       rejected
404 .                       endif
405 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
406 _LICENSE_STATUS?=       accepted
407 .                       endif
408 .               endfor
409 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
410 _LICENSE_STATUS?=       accepted
411 .               endif
412 .               if ${_LICENSE_PERMS:Mauto-accept} != "" && !defined(LICENSES_ASK)
413 _LICENSE_STATUS?=       accepted
414 .               endif
415 _LICENSE_STATUS?=       ask
416 .       endfor
417
418 .else
419 .       for lic in ${_LICENSE}
420 .               if ${LICENSES_REJECTED:M${lic}} != ""
421 _LICENSE_STATUS_${lic}?=        rejected
422 .               endif
423 .               for group in ${_LICENSE_GROUPS_${lic}}
424 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
425 _LICENSE_STATUS_${lic}?=        rejected
426 .                       endif
427 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
428 _LICENSE_STATUS_${lic}?=        accepted
429 .                       endif
430 .               endfor
431 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
432 _LICENSE_STATUS_${lic}?=        accepted
433 .               endif
434 .               if ${_LICENSE_PERMS_${lic}:Mauto-accept} != "" && !defined(LICENSES_ASK)
435 _LICENSE_STATUS_${lic}?=        accepted
436 .               endif
437 _LICENSE_STATUS_${lic}?=        ask
438 .       endfor
439 .endif
440
441 # Evaluate general status
442
443 .if ${_LICENSE_COMB} == "dual"
444 .       for lic in ${_LICENSE}
445 .               if ${_LICENSE_STATUS_${lic}} == "accepted"
446 _LICENSE_STATUS=        accepted
447 .               elif ${_LICENSE_STATUS_${lic}} == "ask"
448 _LICENSE_STATUS?=       ask
449 _LICENSE_TO_ASK+=       ${lic}
450 .               endif
451 _LICENSE_STATUS?=       rejected
452 .       endfor
453
454 .elif ${_LICENSE_COMB} == "multi"
455 .       for lic in ${_LICENSE}
456 .               if ${_LICENSE_STATUS_${lic}} == "rejected"
457 _LICENSE_STATUS=        rejected
458 .               elif ${_LICENSE_STATUS_${lic}} == "ask"
459 _LICENSE_STATUS?=       ask
460 _LICENSE_TO_ASK+=       ${lic}
461 .               endif
462 .       endfor
463 _LICENSE_STATUS?=       accepted
464 .endif
465
466 # For dual/multi licenses, after processing all sub-licenses, the following
467 # must be determined: _LICENSE_NAME, _LICENSE_PERMS and _LICENSE_GROUPS.
468
469 .if ${_LICENSE_COMB} == "dual"
470 _LICENSE_NAME=          Dual (any of): ${_LICENSE}
471 # Calculate least restrictive permissions (union)
472 _LICENSE_PERMS:=        #
473 .       for lic in ${_LICENSE}
474 .               for comp in ${_LICENSE_LIST_PERMS}
475 .                       if ${_LICENSE_PERMS_${lic}:M${comp}} != "" && \
476                            ${_LICENSE_PERMS:M${comp}} == ""
477 _LICENSE_PERMS+=        ${comp}
478 .                       endif
479 .               endfor
480 .       endfor
481 # Calculate least restrictive groups (union)
482 _LICENSE_GROUPS:=       #
483 .       for lic in ${_LICENSE}
484 .               for comp in ${_LICENSE_LIST_GROUPS}
485 .                       if ${_LICENSE_GROUPS_${lic}:M${comp}} != "" && \
486                            ${_LICENSE_GROUPS:M${comp}} == ""
487 _LICENSE_GROUPS+=       ${comp}
488 .                       endif
489 .               endfor
490 .       endfor
491
492 .elif ${_LICENSE_COMB} == "multi"
493 _LICENSE_NAME=          Multiple (all of): ${_LICENSE}
494 # Calculate most restrictive permissions (intersection)
495 _LICENSE_PERMS:=        ${_LICENSE_LIST_PERMS}
496 .       for lic in ${_LICENSE}
497 .               for comp in ${_LICENSE_LIST_PERMS}
498 .                       if ${_LICENSE_PERMS_${lic}:M${comp}} == ""
499 _LICENSE_PERMS:=        ${_LICENSE_PERMS:N${comp}}
500 .                       endif
501 .               endfor
502 .       endfor
503 # Calculate most restrictive groups (intersection)
504 _LICENSE_GROUPS:=       ${_LICENSE_LIST_GROUPS}
505 .       for lic in ${_LICENSE}
506 .               for comp in ${_LICENSE_LIST_GROUPS}
507 .                       if ${_LICENSE_GROUPS_${lic}:M${comp}} == ""
508 _LICENSE_GROUPS:=       ${_LICENSE_GROUPS:N${comp}}
509 .                       endif
510 .               endfor
511 .       endfor
512 .endif
513
514 # Prepare information for asking license to the user
515
516 .if ${_LICENSE_STATUS} == "ask" && ${_LICENSE_COMB} != "single"
517 _LICENSE_ASK_DATA!=     mktemp -ut portslicense
518 .endif
519
520 # Calculate restrictions and set RESTRICTED_FILES when
521 # appropiate, together with cleaning targets.
522 #
523 # XXX For multiple licenses restricted distfiles are always removed from both
524 # CDROM and FTP, but the current framework supports separating them (would
525 # require better/new delete-package and delete-distfiles targets)
526
527 .if ${_LICENSE_PERMS:Mpkg-mirror} == ""
528 _LICENSE_RESTRICTED+=   delete-package
529 .elif ${_LICENSE_PERMS:Mpkg-sell} == ""
530 _LICENSE_CDROM+=                delete-package
531 .endif
532
533 .if ${_LICENSE_COMB} == "multi"
534 .       for lic in ${_LICENSE}
535 .               if ${_LICENSE_PERMS_${lic}:Mdist-mirror} == "" || ${_LICENSE_PERMS_${lic}:Mdist-sell} == ""
536 RESTRICTED_FILES+=              ${_LICENSE_DISTFILES_${lic}}
537 .               endif
538 .       endfor
539 .       if defined(RESTRICTED_FILES)
540 RESTRICTED_FILES+=              ${_PATCHFILES}
541 _LICENSE_RESTRICTED+=   delete-distfiles
542 _LICENSE_CDROM+=                delete-distfiles
543 .       endif
544 .else
545 .       if ${_LICENSE_PERMS:Mdist-mirror} == ""
546 _LICENSE_RESTRICTED+=   delete-distfiles
547 RESTRICTED_FILES=               ${_PATCHFILES} ${_DISTFILES}
548 .       elif ${_LICENSE_PERMS:Mdist-sell} == ""
549 _LICENSE_CDROM+=                delete-distfiles
550 RESTRICTED_FILES=               ${_PATCHFILES} ${_DISTFILES}
551 .       endif
552 .endif
553
554 .if defined(_LICENSE_RESTRICTED)
555 # _LICENSE_RESTRICTED contains 'delete-distfiles' and 'delete-package' if
556 # needed with RESTRICTED_FILES filled from above.
557 clean-restricted:       ${_LICENSE_RESTRICTED}
558 clean-restricted-list: ${_LICENSE_RESTRICTED:C/$/-list/}
559 .else
560 clean-restricted:
561 clean-restricted-list:
562 .endif
563
564 .if defined(_LICENSE_CDROM)
565 clean-for-cdrom:        ${_LICENSE_CDROM}
566 clean-for-cdrom-list: ${_LICENSE_CDROM:C/$/-list/}
567 .else
568 clean-for-cdrom:
569 clean-for-cdrom-list:
570 .endif
571
572 # Check variables are correctly defined and print status up to here
573
574 .if ${_LICENSE_STATUS} == "ask" && defined(BATCH)
575 IGNORE=         License ${_LICENSE} needs confirmation, but BATCH is defined
576 .endif
577
578 # This should probably be incrementally done while parsing all the license
579 # possibilities.
580 debug-license: check-license
581 .if ${_LICENSE_PERMS:Mdist-mirror}
582         @${ECHO_MSG} "===>  License allows mirroring distribution files"
583 .else
584         @${ECHO_MSG} "===>  License does not allow mirroring distribution files"
585 .endif
586 .if ${_LICENSE_PERMS:Mdist-sell}
587         @${ECHO_MSG} "===>  License allows selling distribution files"
588 .else
589         @${ECHO_MSG} "===>  License does not allow selling distribution files"
590 .endif
591 .if ${_LICENSE_PERMS:Mpkg-mirror}
592         @${ECHO_MSG} "===>  License allows mirroring pre-built packages"
593 .else
594         @${ECHO_MSG} "===>  License does not allow mirroring pre-build packages"
595 .endif
596 .if ${_LICENSE_PERMS:Mpkg-sell}
597         @${ECHO_MSG} "===>  License allows selling pre-build packages"
598 .else
599         @${ECHO_MSG} "===>  License does not allow selling pre-build packages"
600 .endif
601 .if ${_LICENSE_PERMS:Mauto-accept}
602         @${ECHO_MSG} "===>  License allows being auto-accepted"
603 .else
604         @${ECHO_MSG} "===>  License requires manual intervention by the user to accept its terms"
605 .endif
606
607
608 check-license:
609 .if defined(_LICENSE_ERROR)
610                 @${ECHO_MSG} "===>  License not correctly defined: ${_LICENSE_ERROR}"
611                 @exit 1
612 .endif
613 .if ${_LICENSE_STATUS} == "rejected"
614                 @${ECHO_MSG} "===>  License ${_LICENSE} rejected by the user"
615                 @${ECHO_MSG}
616                 @${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}
617                 @${ECHO_MSG}
618                 @exit 1
619 .elif ${_LICENSE_STATUS} == "accepted"
620                 @${ECHO_MSG} "===>  License ${_LICENSE} accepted by the user"
621 .elif ${_LICENSE_STATUS} == "ask"
622                 @${ECHO_MSG} "===>  License ${_LICENSE} needs confirmation, will ask later"
623 .endif
624
625 # Display, ask and save preference if requested
626
627 ask-license: ${_LICENSE_COOKIE}
628
629 ${_LICENSE_COOKIE}:
630 # Make sure all required license files exist
631 .if ${_LICENSE_COMB} == "single"
632 .       if !defined(LICENSE_FILE) && defined(_LICENSE_TEXT)
633         @test -f ${_LICENSE_FILE} || ${ECHO_CMD} "${_LICENSE_TEXT}" | ${FMT} > ${_LICENSE_FILE}
634 .       endif
635         @test -f ${_LICENSE_FILE} || \
636                 (${ECHO_MSG} "===>  Missing license file for ${_LICENSE} in ${_LICENSE_FILE}"; exit 1)
637 .else
638 .       for lic in ${_LICENSE}
639 .               if !defined(LICENSE_FILE_${lic}) && defined(_LICENSE_TEXT_${lic})
640         @test -f ${_LICENSE_FILE_${lic}} || ${ECHO_CMD} "${_LICENSE_TEXT_${lic}}" | ${FMT} > ${_LICENSE_FILE_${lic}}
641 .               endif
642         @test -f ${_LICENSE_FILE_${lic}} || \
643                 (${ECHO_MSG} "===>  Missing license file for ${lic} in ${_LICENSE_FILE_${lic}}"; exit 1)
644 .       endfor
645 .endif
646
647 .if ${_LICENSE_STATUS} == "ask"
648 .       if !defined(NO_LICENSES_DIALOGS)
649 # Dialog interface
650 .               if ${_LICENSE_COMB} == "single"
651         @${DIALOG} --title "License for ${PKGNAME} (${_LICENSE})" \
652                 --yes-label Accept --no-label Reject --yesno \
653                 "$$(${CAT} ${_LICENSE_FILE})" 21 76
654
655 .               elif ${_LICENSE_COMB} == "dual"
656         @${RM} ${_LICENSE_ASK_DATA}
657 .                       for lic in ${_LICENSE_TO_ASK}
658         @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
659 .                       endfor
660         @menu_cmd="${DIALOG} --hline \"This port requires you to accept at least one license\" --menu \"License for ${PKGNAME} (dual)\" 21 70 15"; \
661         trap '${RM} $$tmpfile' EXIT INT TERM; \
662         tmpfile=$$(mktemp -t portlicenses); \
663         for lic in ${_LICENSE_TO_ASK}; do \
664                 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\" USE_$${lic} \"Accept the license $${lic}\""; \
665         done; \
666         menu_cmd="$${menu_cmd} REJECT \"Reject the licenses (all)\""; \
667         while true; do \
668                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
669                 result=$$(${CAT} "$${tmpfile}"); \
670                 case $${result} in \
671                 REJECT) exit 1;; \
672                 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
673                                 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
674                                 ${DIALOG} --textbox "$${file}" 21 75 ;; \
675                 USE_*)  name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^USE_//'); \
676                                 ${ECHO_CMD} $${name} > ${_LICENSE_COOKIE}; \
677                                 break ;; \
678                 esac; \
679         done
680
681 .               elif ${_LICENSE_COMB} == "multi"
682         @${RM} ${_LICENSE_ASK_DATA}
683 .                       for lic in ${_LICENSE_TO_ASK}
684         @${ECHO_CMD} "${lic}:${_LICENSE_FILE_${lic}}" >> ${_LICENSE_ASK_DATA}
685 .                       endfor
686         @menu_cmd="${DIALOG} --hline \"This port requires you to accept all mentioned licenses\" --menu \"License for ${PKGNAME} (multi)\" 21 70 15"; \
687         trap '${RM} $$tmpfile' EXIT INT TERM; \
688         tmpfile=$$(mktemp -t portlicenses); \
689         for lic in ${_LICENSE_TO_ASK}; do \
690                 menu_cmd="$${menu_cmd} VIEW_$${lic} \"View the license $${lic}\""; \
691         done; \
692         menu_cmd="$${menu_cmd} ACCEPT \"Accept the licenses (all)\" REJECT \"Reject the licenses (all)\""; \
693         while true; do \
694                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
695                 result=$$(${CAT} "$${tmpfile}"); \
696                 case $${result} in \
697                 ACCEPT) break ;; \
698                 REJECT) exit 1 ;; \
699                 VIEW_*) name=$$(${ECHO_CMD} $${result} | ${SED} -e 's/^VIEW_//'); \
700                                 file=$$(${GREP} "^$${name}:" ${_LICENSE_ASK_DATA} | ${CUT} -d : -f 2); \
701                                 ${DIALOG} --textbox "$${file}" 21 75 ;; \
702                 esac; \
703         done
704 .               endif
705
706 .       else
707 # Text interface
708         @${ECHO_MSG}
709 .               if ${_LICENSE_COMB} == "single"
710         @${ECHO_MSG} "To install the port you must agree to the license: ${_LICENSE} (${_LICENSE_NAME})." | ${FMT}
711         @${ECHO_MSG}
712         @${ECHO_MSG} "You can view the license at ${_LICENSE_FILE:S/${WRKDIR}\//${WRKDIR:T}\//}."
713 .               elif ${_LICENSE_COMB} == "dual"
714         @${ECHO_MSG} "To install the port you must agree to any of the following licenses:"
715 .               elif ${_LICENSE_COMB} == "multi"
716         @${ECHO_MSG} "To install the port you must agree to all of the following licenses:"
717 .               endif
718         @${ECHO_MSG}
719 .               if ${_LICENSE_COMB} != "single"
720 .                       for lic in ${_LICENSE_TO_ASK}
721 .                               if defined(WRKDIRPREFIX)
722         @${ECHO_MSG} "- ${lic} (${_LICENSE_NAME_${lic}}), available at ${_LICENSE_FILE_${lic}}"
723 .                               else
724         @${ECHO_MSG} "- ${lic} (${_LICENSE_NAME_${lic}}), available at ${_LICENSE_FILE_${lic}:S/${WRKDIR}\//${WRKDIR:T}\//}"
725 .                               endif
726 .                       endfor
727         @${ECHO_MSG}
728 .               endif
729         @${ECHO_MSG} "If you agree with the corresponding license(s), add them to LICENSES_ACCEPTED either in make arguments or /etc/make.conf." | ${FMT}
730         @${ECHO_MSG}
731         @exit 1
732 .       endif
733         @${RM} ${_LICENSE_ASK_DATA}
734 .endif
735
736 # Create report and catalog
737 .if !defined(NO_LICENSES_INSTALL)
738         @${RM} ${_LICENSE_CATALOG_TMP} ${_LICENSE_REPORT_TMP}
739 .       if ${_LICENSE_COMB} == "single"
740 # Catalog
741 .               for var in _LICENSE _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS _LICENSE_DISTFILES
742         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
743 .               endfor
744 # Report
745         @${ECHO_CMD} "This package has a single license: ${_LICENSE} (${_LICENSE_NAME})." > ${_LICENSE_REPORT_TMP}
746 .       else
747 # Catalog
748 .               for var in _LICENSE _LICENSE_COMB _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS
749         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
750 .               endfor
751 .               if ${_LICENSE_COMB} == "dual" && ${_LICENSE_STATUS} == "ask"
752         @${SED} -e 's/^/_LICENSE_SELECTED=/' ${_LICENSE_COOKIE} >> ${_LICENSE_CATALOG_TMP}
753 .               endif
754 .               for lic in ${_LICENSE}
755 .                       for var in NAME PERMS GROUPS DISTFILES
756         @${ECHO_CMD} "_LICENSE_${var}_${lic} =${_LICENSE_${var}_${lic}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
757 .                       endfor
758 .               endfor
759 # Report
760 .               if ${_LICENSE_COMB} == "dual"
761         @${ECHO_CMD} "This package has dual licenses (any of):"  >> ${_LICENSE_REPORT_TMP}
762 .               elif ${_LICENSE_COMB} == "multi"
763         @${ECHO_CMD} "This package has multiple licenses (all of):"  >> ${_LICENSE_REPORT_TMP}
764 .               endif
765 .               for lic in ${_LICENSE}
766         @${ECHO_CMD} "- ${lic} (${_LICENSE_NAME_${lic}})"  >> ${_LICENSE_REPORT_TMP}
767 .               endfor
768 .       endif
769 .endif
770
771 # Cookie (done here)
772         @${TOUCH} ${_LICENSE_COOKIE}
773
774 # Package list entries, and installation
775
776 .if !defined(NO_LICENSES_INSTALL)
777 PLIST_FILES+=   ${_LICENSE_CATALOG} \
778                                 ${_LICENSE_REPORT}
779
780 .if ${_LICENSE_COMB} == "single"
781 PLIST_FILES+=   ${_LICENSE_DIR}/${_LICENSE}
782 .else
783 .       for lic in ${_LICENSE}
784 .               if defined(_LICENSE_FILE_${lic})
785 PLIST_FILES+=   ${_LICENSE_DIR}/${lic}
786 .               endif
787 .       endfor
788 .endif
789
790 install-license:
791         @${MKDIR} ${STAGEDIR}${_LICENSE_DIR}
792         @${INSTALL_DATA} ${_LICENSE_CATALOG_TMP} ${STAGEDIR}${_LICENSE_CATALOG}
793         @${INSTALL_DATA} ${_LICENSE_REPORT_TMP} ${STAGEDIR}${_LICENSE_REPORT}
794 .if ${_LICENSE_COMB} == "single"
795         @${INSTALL_DATA} ${_LICENSE_FILE} ${STAGEDIR}${_LICENSE_DIR}/${_LICENSE}
796 .else
797 .       for lic in ${_LICENSE}
798         @${INSTALL_DATA} ${_LICENSE_FILE_${lic}} ${STAGEDIR}${_LICENSE_DIR}/${lic}
799 .       endfor
800 .endif
801 .endif
802
803 .else   # !LICENSE
804
805 debug-license:
806 .       if defined(LICENSE_VERBOSE)
807         @${ECHO_MSG} "===>  License debug empty, port has not defined LICENSE"
808 .       endif
809
810 check-license:
811 .       if defined(LICENSE_VERBOSE)
812         @${ECHO_MSG} "===>  License check disabled, port has not defined LICENSE"
813 .       endif
814
815 .endif  # LICENSE
816
817 .endif