Mk/Uses/iconv: support iconv+
[dports.git] / Mk / bsd.licenses.mk
1 #-*- tab-width: 4; -*-
2 # ex:ts=4
3 #
4 # $FreeBSD: ports/Mk/bsd.licenses.mk,v 1.14 2012/11/17 05:54:17 svnexp Exp $
5
6 Licenses_Include_MAINTAINER=         portmgr@FreeBSD.org
7
8 #
9 # bsd.licenses.mk - License auditing framework.
10 #
11 # Created by: Alejandro Pulver <alepulver@FreeBSD.org>
12 #
13 # Please view me with 4 column tabs!
14 #
15
16 # TODO:
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
22 #   behavior).
23
24 # The following cases are not considered:
25 #
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.
31 #
32
33 # Integration with target sequences
34 #
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)
38 #
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).
44
45 # Variables provided to the ports system and users in general, to modify the
46 # behavior of the framework
47 #
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.
51
52 #NO_LICENSES_INSTALL=           yes
53 #NO_LICENSES_DIALOGS=           yes
54
55 # Variables provided to users (can be passed to make or set in /etc/make.conf)
56 #
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).
64 #
65
66 # Variables provided to ports
67 #
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)
78 #
79 # The following cases are supported after defining LICENSE:
80 #
81 # Case 1: license defined in the framework (aka "known").
82 #
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
85 # to change.
86 #
87 # Case 2: license only known by the port (aka "unknown").
88 #
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}.
92 #
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.
100 #
101 # Notes about permissions:
102 # - Permissions use a default-deny policy.
103 # - Components can be negated by prefixing them with "no-" (like
104 #   "no-pkg-sell").
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
109 #   variable empty?
110 #
111 # Dual/multiple licenses:
112 #
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.
119 #
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.
122 #
123
124 .if defined(_POSTMKINCLUDED) && !defined(BEFOREPORTMK)
125
126 .if defined(LICENSE)
127
128 # Include known licenses from database
129
130 .include "${PORTSDIR}/Mk/bsd.licenses.db.mk"
131
132 # Lists of variables and valid components
133 #
134 # _LICENSE_LIST_PERMS           - Valid permission components
135 # _LICENSE_LIST_PORT_VARS       - License variables defined by the port
136
137 _LICENSE_LIST_PERMS=            dist-mirror dist-sell pkg-mirror pkg-sell auto-accept none
138 _LICENSE_LIST_PORT_VARS=        PERMS NAME GROUPS
139
140 # Path variables
141 #
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.
152
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}
161
162 # Defaults (never overriden for now)
163 #
164 # _LICENSE                      - Copy of LICENSE (for now)
165 # _LICENSE_COMB         - Copy of LICENSE_COMB (but "single" instead of empty)
166
167 _LICENSE?=                      ${LICENSE}
168 .if !defined(LICENSE_COMB)
169 _LICENSE_COMB=          single
170 .else
171 _LICENSE_COMB=          ${LICENSE_COMB}
172 .endif
173
174 # Check if single or dual/multiple license
175 #
176 # Make sure LICENSE_COMB is only used with more than one license.
177
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")
180 .endif
181
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)
186 .               else
187 _LICENSE_MULTI=         yes
188 .               endif
189 .       else
190 _LICENSE_DEFINED=       yes
191 .       endif
192 .endfor
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)
195 .endif
196 .if !defined(_LICENSE_DEFINED)
197 _LICENSE_ERROR?=        no licenses present in LICENSE (empty string)
198 .endif
199 .undef _LICENSE_DEFINED
200 .undef _LICENSE_MULTI
201
202 # Evaluate port license groups and permissions
203 #
204 # Available values for _LICENSE_TYPE:
205 #
206 # Case 1: "known" (license info taken from internal database)
207 # Case 2: "unknown" (LICENSE is not known, and info taken from port)
208 #
209 # Make sure required variables are defined, and remove conflicting (positive
210 # and negative) duplicated components.
211
212 .if ${_LICENSE_COMB} == "single"
213 # Defaults to empty
214 _LICENSE_GROUPS?=       #
215 # Start
216 .       for lic in ${_LICENSE}
217 .               if ${_LICENSE_LIST:M${lic}} != ""
218 # Case 1: license defined in the framework.
219 _LICENSE_TYPE=          known
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
223 .                               endif
224 .                               if !defined(_LICENSE_${var}_${lic})
225 _LICENSE_ERROR?=        ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
226 .                               else
227 _LICENSE_${var}=        ${_LICENSE_${var}_${lic}}
228 .                               endif
229 .                       endfor
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}
235 .                                       else
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}
239 .                                       endif
240 .                               else
241 _LICENSE_ERROR?=        defining LICENSE_TEXT is not allowed for known licenses
242 .                               endif
243 .                       else
244 _LICENSE_FILE=          ${LICENSE_FILE}
245 .                       endif
246
247 .               else
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)
255 .                               endif
256 .                       endfor
257 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
258 __LICENSE_PERMS:=       #
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}
265 .                               endif
266 .                       endfor
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
273 .                               else
274 _LICENSE_TEXT=          ${LICENSE_TEXT}
275 _LICENSE_FILE=          ${WRKDIR}/${lic}
276 .                               endif
277 .                       else
278 _LICENSE_FILE=          ${LICENSE_FILE}
279 .                       endif
280 .               endif
281
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
285 .               endif
286 # Distfiles
287 .               if !defined(LICENSE_DISTFILES)
288 _LICENSE_DISTFILES=     ${_DISTFILES}
289 .               else
290 _LICENSE_DISTFILES=     ${LICENSE_DISTFILES}
291 .               endif
292 .       endfor
293
294 .else
295 .       for lic in ${_LICENSE}
296 # Defaults to empty
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
304 .                               endif
305 .                               if !defined(_LICENSE_${var}_${lic})
306 _LICENSE_ERROR?=        ERROR: missing _LICENSE_${var}_${lic} in bsd.licenses.db.mk
307 .                               endif
308 .                       endfor
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}
314 .                                       else
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}
318 .                                       endif
319 .                               else
320 _LICENSE_ERROR?=        defining LICENSE_TEXT_${lic} is not allowed for known licenses
321 .                               endif
322 .                       else
323 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
324 .                       endif
325
326 .               else
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)
334 .                               endif
335 .                       endfor
336 # Check LICENSE_PERMS for invalid, ambiguous and duplicate components
337 __LICENSE_PERMS:=       #
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}
344 .                               endif
345 .                       endfor
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
352 .                               else
353 _LICENSE_TEXT_${lic}=   ${LICENSE_TEXT_${lic}}
354 _LICENSE_FILE_${lic}=   ${WRKDIR}/${lic}
355 .                               endif
356 .                       else
357 _LICENSE_FILE_${lic}=   ${LICENSE_FILE_${lic}}
358 .                       endif
359 .               endif
360
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
364 .               endif
365 # Distfiles
366 .               if !defined(LICENSE_DISTFILES_${lic})
367 _LICENSE_DISTFILES_${lic}=      ${_DISTFILES}
368 .               else
369 _LICENSE_DISTFILES_${lic}=      ${LICENSE_DISTFILES_${lic}}
370 .               endif
371 .       endfor
372 .endif
373
374 # Check if the user agrees with the license
375
376 # Make sure these are defined
377
378 LICENSES_ACCEPTED?=                     #
379 LICENSES_REJECTED?=                     #
380 LICENSES_GROUPS_ACCEPTED?=      #
381 LICENSES_GROUPS_REJECTED?=      #
382
383 # Evaluate per-license status
384
385 .if ${_LICENSE_COMB} == "single"
386 .       for lic in ${_LICENSE}
387 .               if ${LICENSES_REJECTED:M${lic}} != ""
388 _LICENSE_STATUS?=       rejected
389 .               endif
390 .               for group in ${_LICENSE_GROUPS}
391 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
392 _LICENSE_STATUS?=       rejected
393 .                       endif
394 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
395 _LICENSE_STATUS?=       accepted
396 .                       endif
397 .               endfor
398 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
399 _LICENSE_STATUS?=       accepted
400 .               endif
401 .               if ${_LICENSE_PERMS:Mauto-accept} != "" && !defined(LICENSES_ASK)
402 _LICENSE_STATUS?=       accepted
403 .               endif
404 _LICENSE_STATUS?=       ask
405 .       endfor
406
407 .else
408 .       for lic in ${_LICENSE}
409 .               if ${LICENSES_REJECTED:M${lic}} != ""
410 _LICENSE_STATUS_${lic}?=        rejected
411 .               endif
412 .               for group in ${_LICENSE_GROUPS_${lic}}
413 .                       if ${LICENSES_GROUPS_REJECTED:M${group}} != ""
414 _LICENSE_STATUS_${lic}?=        rejected
415 .                       endif
416 .                       if ${LICENSES_GROUPS_ACCEPTED:M${group}} != ""
417 _LICENSE_STATUS_${lic}?=        accepted
418 .                       endif
419 .               endfor
420 .               if ${LICENSES_ACCEPTED:M${lic}} != ""
421 _LICENSE_STATUS_${lic}?=        accepted
422 .               endif
423 .               if ${_LICENSE_PERMS_${lic}:Mauto-accept} != "" && !defined(LICENSES_ASK)
424 _LICENSE_STATUS_${lic}?=        accepted
425 .               endif
426 _LICENSE_STATUS_${lic}?=        ask
427 .       endfor
428 .endif
429
430 # Evaluate general status
431
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}
439 .               endif
440 _LICENSE_STATUS?=       rejected
441 .       endfor
442
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}
450 .               endif
451 .       endfor
452 _LICENSE_STATUS?=       accepted
453 .endif
454
455 # For dual/multi licenses, after processing all sub-licenses, the following
456 # must be determined: _LICENSE_NAME, _LICENSE_PERMS and _LICENSE_GROUPS.
457
458 .if ${_LICENSE_COMB} == "dual"
459 _LICENSE_NAME=          Dual (any of): ${_LICENSE}
460 # Calculate least restrictive permissions (union)
461 _LICENSE_PERMS:=        #
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}
467 .                       endif
468 .               endfor
469 .       endfor
470 # Calculate least restrictive groups (union)
471 _LICENSE_GROUPS:=       #
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}
477 .                       endif
478 .               endfor
479 .       endfor
480
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}}
489 .                       endif
490 .               endfor
491 .       endfor
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}}
498 .                       endif
499 .               endfor
500 .       endfor
501 .endif
502
503 # Prepare information for asking license to the user
504
505 .if ${_LICENSE_STATUS} == "ask" && ${_LICENSE_COMB} != "single"
506 _LICENSE_ASK_DATA!=     mktemp -ut portslicense
507 .endif
508
509 # Calculate restrictions and set RESTRICTED_FILES when
510 # appropiate, together with cleaning targets.
511 #
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)
515
516 .if ${_LICENSE_PERMS:Mpkg-mirror} == ""
517 _LICENSE_RESTRICTED+=   delete-package
518 .elif ${_LICENSE_PERMS:Mpkg-sell} == ""
519 _LICENSE_CDROM+=                delete-package
520 .endif
521
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}}
526 .               endif
527 .       endfor
528 .       if defined(RESTRICTED_FILES)
529 RESTRICTED_FILES+=              ${_PATCHFILES}
530 _LICENSE_RESTRICTED+=   delete-distfiles
531 _LICENSE_CDROM+=                delete-distfiles
532 .       endif
533 .else
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}
540 .       endif
541 .endif
542
543 .if defined(_LICENSE_RESTRICTED)
544 clean-restricted:       ${_LICENSE_RESTRICTED}
545 clean-restricted-list: ${_LICENSE_RESTRICTED:C/$/-list/}
546 .else
547 clean-restricted:
548 clean-restricted-list:
549 .endif
550
551 .if defined(_LICENSE_CDROM)
552 clean-for-cdrom:        ${_LICENSE_CDROM}
553 clean-for-cdrom-list: ${_LICENSE_CDROM:C/$/-list/}
554 .else
555 clean-for-cdrom:
556 clean-for-cdrom-list:
557 .endif
558
559 # Check variables are correctly defined and print status up to here
560
561 .if ${_LICENSE_STATUS} == "ask" && defined(BATCH)
562 IGNORE=         License ${_LICENSE} needs confirmation, but BATCH is defined
563 .endif
564
565 check-license:
566 .if defined(_LICENSE_ERROR)
567                 @${ECHO_MSG} "===>  License not correctly defined: ${_LICENSE_ERROR}"
568                 @exit 1
569 .endif
570 .if ${_LICENSE_STATUS} == "rejected"
571                 @${ECHO_MSG} "===>  License ${_LICENSE} rejected by the user"
572                 @${ECHO_MSG}
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}
574                 @${ECHO_MSG}
575                 @exit 1
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"
580 .endif
581
582 # Display, ask and save preference if requested
583
584 ask-license: ${_LICENSE_COOKIE}
585
586 ${_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}
591 .       endif
592         @test -f ${_LICENSE_FILE} || \
593                 (${ECHO_MSG} "===>  Missing license file for ${_LICENSE} in ${_LICENSE_FILE}"; exit 1)
594 .else
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}}
598 .               endif
599         @test -f ${_LICENSE_FILE_${lic}} || \
600                 (${ECHO_MSG} "===>  Missing license file for ${lic} in ${_LICENSE_FILE_${lic}}"; exit 1)
601 .       endfor
602 .endif
603
604 .if ${_LICENSE_STATUS} == "ask"
605 .       if !defined(NO_LICENSES_DIALOGS)
606 # Dialog interface
607 .               if ${_LICENSE_COMB} == "single"
608         @trap '${RM} -f $$tmpfile' EXIT INT TERM; \
609         tmpfile=$$(mktemp -t portlicenses); \
610         while true; do \
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}`; \
613                 case $${result} in \
614                 accept) break ;; \
615                 reject) exit 1;; \
616                 view)   ${DIALOG} --textbox "${_LICENSE_FILE}" 21 75 ;; \
617                 esac; \
618         done
619
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}
624 .                       endfor
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}\""; \
630         done; \
631         menu_cmd="$${menu_cmd} REJECT \"Reject the licenses (all)\""; \
632         while true; do \
633                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
634                 result=$$(${CAT} "$${tmpfile}"); \
635                 case $${result} in \
636                 REJECT) exit 1;; \
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}; \
642                                 break ;; \
643                 esac; \
644         done
645
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}
650 .                       endfor
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}\""; \
656         done; \
657         menu_cmd="$${menu_cmd} ACCEPT \"Accept the licenses (all)\" REJECT \"Reject the licenses (all)\""; \
658         while true; do \
659                 ${SH} -c "$${menu_cmd} 2>\"$${tmpfile}\""; \
660                 result=$$(${CAT} "$${tmpfile}"); \
661                 case $${result} in \
662                 ACCEPT) break ;; \
663                 REJECT) exit 1 ;; \
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 ;; \
667                 esac; \
668         done
669 .               endif
670
671 .       else
672 # Text interface
673         @${ECHO_MSG}
674 .               if ${_LICENSE_COMB} == "single"
675         @${ECHO_MSG} "To install the port you must agree to the license: ${_LICENSE} (${_LICENSE_NAME})." | ${FMT}
676         @${ECHO_MSG}
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:"
682 .               endif
683         @${ECHO_MSG}
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}\//}"
687 .                       endfor
688         @${ECHO_MSG}
689 .               endif
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}
691         @${ECHO_MSG}
692         @exit 1
693 .       endif
694         @${RM} -f ${_LICENSE_ASK_DATA}
695 .endif
696
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"
701 # Catalog
702 .               for var in _LICENSE _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS _LICENSE_DISTFILES
703         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
704 .               endfor
705 # Report
706         @${ECHO_CMD} "This package has a single license: ${_LICENSE} (${_LICENSE_NAME})." > ${_LICENSE_REPORT_TMP}
707 .       else
708 # Catalog
709 .               for var in _LICENSE _LICENSE_COMB _LICENSE_NAME _LICENSE_PERMS _LICENSE_GROUPS
710         @${ECHO_CMD} "${var}=${${var}:C/^[[:blank:]]*//}" >> ${_LICENSE_CATALOG_TMP}
711 .               endfor
712 .               if ${_LICENSE_COMB} == "dual" && ${_LICENSE_STATUS} == "ask"
713         @${SED} -e 's/^/_LICENSE_SELECTED=/' ${_LICENSE_COOKIE} >> ${_LICENSE_CATALOG_TMP}
714 .               endif
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}
718 .                       endfor
719 .               endfor
720 # Report
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}
725 .               endif
726 .               for lic in ${_LICENSE}
727         @${ECHO_CMD} "- ${lic} (${_LICENSE_NAME_${lic}})"  >> ${_LICENSE_REPORT_TMP}
728 .               endfor
729 .       endif
730 .endif
731
732 # Cookie (done here)
733         @${TOUCH} ${_LICENSE_COOKIE}
734
735 # Package list entries, and installation
736
737 .if !defined(NO_LICENSES_INSTALL)
738 PLIST_FILES+=   ${_LICENSE_DIR_REL}/${_LICENSE_CATALOG:T} \
739                                 ${_LICENSE_DIR_REL}/${_LICENSE_REPORT:T}
740
741 .if ${_LICENSE_COMB} == "single"
742 PLIST_FILES+=   ${_LICENSE_DIR_REL}/${_LICENSE}
743 .else
744 .       for lic in ${_LICENSE}
745 .               if defined(_LICENSE_FILE_${lic})
746 PLIST_FILES+=   ${_LICENSE_DIR_REL}/${lic}
747 .               endif
748 .       endfor
749 .endif
750
751 install-license:
752         @${MKDIR} ${_LICENSE_DIR}
753         @${INSTALL_DATA} ${_LICENSE_CATALOG_TMP} ${_LICENSE_CATALOG}
754         @${INSTALL_DATA} ${_LICENSE_REPORT_TMP} ${_LICENSE_REPORT}
755 .if ${_LICENSE_COMB} == "single"
756         @${INSTALL_DATA} ${_LICENSE_FILE} ${_LICENSE_DIR}/${_LICENSE}
757 .else
758 .       for lic in ${_LICENSE}
759         @${INSTALL_DATA} ${_LICENSE_FILE_${lic}} ${_LICENSE_DIR}/${lic}
760 .       endfor
761 .endif
762 # XXX @dirrmtry entry must be here (no way to do with PLIST_* vars)
763 # XXX Important, keep the whitespace behind "@cwd "!
764         @${ECHO_CMD} "@cwd " >> ${TMPPLIST}
765         @${ECHO_CMD} "@dirrm ${_LICENSE_DIR_REL}" >> ${TMPPLIST}
766         @${ECHO_CMD} "@unexec rmdir %D/share/licenses 2>/dev/null || true" >> ${TMPPLIST}
767
768 .else
769 install-license:
770         @${DO_NADA}
771
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