View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (c)  2002-2026, University of Amsterdam
    7                              SWI-Prolog Solutions b.v.
    8    All rights reserved.
    9
   10    Redistribution and use in source and binary forms, with or without
   11    modification, are permitted provided that the following conditions
   12    are met:
   13
   14    1. Redistributions of source code must retain the above copyright
   15       notice, this list of conditions and the following disclaimer.
   16
   17    2. Redistributions in binary form must reproduce the above copyright
   18       notice, this list of conditions and the following disclaimer in
   19       the documentation and/or other materials provided with the
   20       distribution.
   21
   22    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   23    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   24    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   25    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   26    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   27    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   28    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   29    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   30    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   31    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   32    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   33    POSSIBILITY OF SUCH DAMAGE.
   34*/
   35
   36:- module(license,
   37          [ license/1,                  % +LicenseId
   38            license/2,                  % +LicenseId, +ModuleId
   39            license/0,                  % Current situation
   40
   41            known_licenses/0
   42          ]).   43
   44:- dynamic
   45    licensed/2.                     % +Id, +Module
   46
   47:- multifile
   48    license/3.   49
   50/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   51License  definitions.  This  data  is   (still  incomplete)  taken  from
   52http://www.fsf.org/licenses/license-list.html. The first argument is the
   53license identifier. The second is the category: `gpl` and `lgpl` for the
   54licenses compatible with the GPL and LGPL, `copyleft` for licenses whose
   55copyleft is limited to the files of the component  (e.g., EPL and MPL),
   56`permissive` and `proprietary`.  The remainder is a  list of properties
   57that can be used with more high-level license-information tools.  The
   58property gpl_compatible(false) flags licenses that may not be combined
   59with GPL components.
   60- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
   61
   62license(gpl, gpl,
   63        [ comment('GNU General Public License'),
   64          url('http://www.fsf.org/copyleft/gpl.html')
   65        ]).
   66license(gplv2, gpl,
   67        [ comment('GNU General Public License, version 2'),
   68          url('http://www.fsf.org/copyleft/gpl.html')
   69        ]).
   70license('gplv2+', gpl,
   71        [ comment('GNU General Public License, version 2 or later'),
   72          url('http://www.fsf.org/copyleft/gpl.html')
   73        ]).
   74license(gplv3, gpl,
   75        [ comment('GNU General Public License, version 3'),
   76          url('http://www.fsf.org/copyleft/gpl.html')
   77        ]).
   78license(lgpl, lgpl,
   79        [ comment('GNU Lesser General Public License'),
   80          url('http://www.fsf.org/copyleft/lesser.html')
   81        ]).
   82license(lgplv2, lgpl,
   83        [ comment('GNU Lesser General Public License, version 2'),
   84          url('http://www.fsf.org/copyleft/lesser.html')
   85        ]).
   86license('lgplv2+', lgpl,
   87        [ comment('GNU Lesser General Public License, version 2 or later'),
   88          url('http://www.fsf.org/copyleft/lesser.html')
   89        ]).
   90license(lgplv3, lgpl,
   91        [ comment('GNU Lesser General Public License, version 3'),
   92          url('http://www.fsf.org/copyleft/lesser.html')
   93        ]).
   94license(gpl_swipl, lgpl,
   95        [ comment('SWI-Prolog Prolog Source License for versions up to 7.3.32'),
   96          url('http://www.swi-prolog.org/license-old.html')
   97        ]).
   98license(swipl, lgpl,
   99        [ comment('SWI-Prolog Prolog Source License for versions up to 7.3.32'),
  100          url('http://www.swi-prolog.org/license-old.html')
  101        ]).
  102
  103%       Other GPL/LGPL compatible licenses.
  104%       TBD: Check permissive status of these licenses
  105
  106license(guile, lgpl,
  107        [ comment('License for Guile'),
  108          url('https://www.gnu.org/software/guile/docs/docs-1.6/guile-ref/Guile-License.html')
  109        ]).
  110license(gnu_ada, lgpl,
  111        [ comment('The license of the run-time units of the GNU Ada compiler'),
  112          url('https://en.wikipedia.org/wiki/GNAT#License')
  113        ]).
  114license(x11, permissive,
  115        [ comment('The X11 license'),
  116          url('http://www.x.org/terms.htm')
  117        ]).
  118license(expat, permissive,
  119        [ comment('Expat license'),
  120          url('http://www.jclark.com/xml/copying.txt')
  121        ]).
  122license(sml, permissive,
  123        [ comment('Standard ML of New Jersey Copyright License'),
  124          url('http://cm.bell-labs.com/cm/cs/what/smlnj/license.html')
  125        ]).
  126license(public_domain, permissive,
  127        [ comment('Unrestricted Public domain')
  128        ]).
  129license(cryptix, permissive,
  130        [ comment('The Cryptix General License'),
  131          url('http://www.cryptix.org/docs/license.html')
  132        ]).
  133license(bsd, permissive,
  134        [ comment('The modified BSD license'),
  135          url('http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5')
  136        ]).
  137license(mit, permissive,
  138        [ comment('The MIT License'),
  139          url('https://en.wikipedia.org/wiki/MIT_License')
  140        ]).
  141license(zlib, permissive,
  142        [ comment('The license of ZLib'),
  143          url('http://www.gzip.org/zlib/zlib_license.html')
  144        ]).
  145license(sleepycat, gpl,
  146        [ comment('Sleepycat License (Berkeley DB up to 5.3)'),
  147          url('https://opensource.org/license/sleepycat')
  148        ]).
  149license(agpl, gpl,
  150        [ comment('Affero General Public License'),
  151          url('http://www.gnu.org/licenses/agpl-3.0.en.html')
  152        ]).
  153license(lgpl_compatible, lgpl,
  154        [ comment('Other LGPL compatible license')
  155        ]).
  156license(gpl_compatible, gpl,
  157        [ comment('Other GPL and not LGPL compatible license')
  158        ]).
  159license(permissive, permissive,
  160        [ comment('Other permissive license')
  161        ]).
  162license(asl2, permissive,
  163        [ comment('Apache License 2.0'),
  164          url('http://www.apache.org/licenses/LICENSE-2.0')
  165        ]).
  166license(epl, copyleft,
  167        [ comment('Eclipse Public License 1.0'),
  168          url('https://www.eclipse.org/legal/epl-v10.html'),
  169          gpl_compatible(false)
  170        ]).
  171license(eplv2, copyleft,
  172        [ comment('Eclipse Public License 2.0'),
  173          url('https://www.eclipse.org/legal/epl-2.0/')
  174        ]).
 license(+License) is det
 license(+License, +ModuleId) is det
Register the current file under the given license restriction.
  182license(License) :-
  183    (   prolog_load_context(file, File)
  184    ->  true
  185    ;   File = '<unknown file>'
  186    ),
  187    license(License, File).
  188
  189license(License, File) :-
  190    warn_if_unknown(License),
  191    assertz(licensed(License, File)).
  192
  193warn_if_unknown(License) :-
  194    license(License, _, _),
  195    !.
  196warn_if_unknown(License) :-
  197    print_message(warning, unknown_license(License)).
 license is det
Report current license situation
  203license :-
  204    (setof(Module, gpled(Module), GPL)   -> true ; GPL  = []),
  205    (setof(Module, lgpled(Module), LGPL) -> true ; LGPL = []),
  206    findall(L-Modules,
  207            setof(Module, licensed(Module, copyleft, L), Modules),
  208            Copyleft),
  209    findall(L-Modules,
  210            setof(Module, licensed(Module, permissive, L), Modules),
  211            Permissive),
  212    findall(L-Modules,
  213            setof(Module, proprietary(Module, L), Modules),
  214            Proprietary),
  215    (   gpl_conflict
  216    ->  Conflict = true
  217    ;   Conflict = false
  218    ),
  219    print_message(informational,
  220                  license(GPL,LGPL,Copyleft,Conflict,Permissive,Proprietary)).
  221
  222gpled(Module) :-
  223    licensed(X, Module),
  224    license(X, gpl, _).
  225
  226lgpled(Module) :-
  227    licensed(X, Module),
  228    license(X, lgpl, _).
  229
  230licensed(Module, Category, L) :-
  231    licensed(L, Module),
  232    license(L, Category, _).
  233
  234proprietary(Module, L) :-
  235    licensed(L, Module),
  236    (   license(L, C, _)
  237    ->  \+ open_category(C)
  238    ;   true
  239    ).
  240
  241open_category(gpl).
  242open_category(lgpl).
  243open_category(copyleft).
  244open_category(permissive).
 gpl_conflict is semidet
True if a component under the GNU GPL is combined with a component whose license has the property gpl_compatible(false). Note that not all licenses in the gpl category are GNU licenses: e.g., the Sleepycat license only shares the copyleft over the program.
  253gpl_conflict :-
  254    licensed(G, _),
  255    gnu_gpl(G),
  256    licensed(L, _),
  257    license(L, _, Atts),
  258    memberchk(gpl_compatible(false), Atts),
  259    !.
  260
  261gnu_gpl(gpl).
  262gnu_gpl(gplv2).
  263gnu_gpl('gplv2+').
  264gnu_gpl(gplv3).
  265gnu_gpl(agpl).
 known_licenses
Print all known licenses.
  271known_licenses :-
  272    findall(license(Id,Compat,Atts),
  273            license(Id,Compat,Atts),
  274            Licenses),
  275    print_message(informational, known_licenses(Licenses)).
  276
  277
  278                 /*******************************
  279                 *             MESSAGES         *
  280                 *******************************/
  281
  282:- multifile
  283    prolog:message/3.  284
  285prolog:message(license(GPL,LGPL,Copyleft,Conflict,Permissive,Proprietary)) -->
  286    license_message(GPL,LGPL,Copyleft,Conflict,Permissive,Proprietary).
  287prolog:message(unknown_license(License)) -->
  288    [ 'The license "~w" is not known.  You can list the known '-[License], nl,
  289      'licenses using ?- known_licenses. or add information about this ',
  290      'license by extending license:license/3.'
  291    ].
  292prolog:message(known_licenses(Licenses)) -->
  293    [ 'The following license identifiers may be used in license/2 ',
  294      'and PL_license()'
  295    ],
  296    known_licenses(Licenses).
 license_message(+GPL, +LGPL, +Copyleft, +Conflict, +Permissive, +Proprietary)//
  301license_message(GPL, LGPL, Copyleft, Conflict, Permissive, Proprietary) -->
  302    license_message(GPL, LGPL, Copyleft, Permissive),
  303    copyleft_licenses(Copyleft),
  304    gpl_conflict(Conflict),
  305    proprietary_licenses(Proprietary).
  306
  307license_message([], [], [], Permissive) -->
  308    !,
  309    [ 'This program contains only components covered by permissive license', nl,
  310      'conditions. SWI-Prolog is covered by the Simplified BSD license:',
  311      nl, nl
  312    ],
  313    bsd2_license,
  314	permissive_licenses(Permissive).
  315license_message(GPL, _, _, _) -->
  316    { GPL \== [] },
  317    !,
  318    [ 'SWI-Prolog is covered by the Simplified BSD license:', nl, nl ],
  319    bsd2_license, [nl, nl],
  320    warn([ 'This program contains components covered by the GNU General', nl,
  321           'Public License, which therefore apply to the entire program.', nl,
  322           'These components are:', nl, nl
  323         ]),
  324    file_list(GPL).
  325license_message([], LGPL, _, _) -->
  326    { LGPL \== [] },
  327    !,
  328    [ 'SWI-Prolog is covered by the Simplified BSD license:', nl, nl ],
  329    bsd2_license, [nl, nl],
  330    warn([ 'This program contains components covered by the GNU Lesser', nl,
  331           'Public License.  Distribution of this program is subject to',  nl,
  332           'additional conditions.  These components are:', nl, nl
  333         ]),
  334    file_list(LGPL).
  335license_message([], [], _, Permissive) -->
  336    [ 'SWI-Prolog is covered by the Simplified BSD license:', nl, nl ],
  337    bsd2_license,
  338    permissive_licenses(Permissive).
  339
  340
  341bsd2_license -->
  342    [ 'Redistribution and use in source and binary forms, with or without', nl,
  343      'modification, are permitted provided that the following conditions', nl,
  344      'are met:', nl,
  345      nl,
  346      '1. Redistributions of source code must retain the above copyright', nl,
  347      '   notice, this list of conditions and the following disclaimer.', nl,
  348      nl,
  349      '2. Redistributions in binary form must reproduce the above copyright', nl,
  350      '   notice, this list of conditions and the following disclaimer in', nl,
  351      '   the documentation and/or other materials provided with the', nl,
  352      '   distribution.', nl,
  353      nl,
  354      'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS', nl,
  355      '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT', nl,
  356      'LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS', nl,
  357      'FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE', nl,
  358      'COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,', nl,
  359      'INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,', nl,
  360      'BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;', nl,
  361      'LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER', nl,
  362      'CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT', nl,
  363      'LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN', nl,
  364      'ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE', nl,
  365      'POSSIBILITY OF SUCH DAMAGE.'
  366    ].
  367
  368permissive_licenses([]) --> !.
  369permissive_licenses([LM| LMs]) -->
  370    [ nl, nl,
  371      'This program contains other components with permissive licenses:',
  372      nl, nl
  373    ],
  374    license_groups([LM| LMs]).
 license_groups(+Pairs:list(pair(atom,list)))//
Print the components for each license in Pairs.
  380license_groups([]) --> [].
  381license_groups([License-Modules|T]) -->
  382    license_title(License),
  383    license_url(License),
  384    [nl],
  385    file_list(Modules),
  386    (   {T==[]}
  387    ->  []
  388    ;   [nl],
  389        license_groups(T)
  390    ).
  391
  392copyleft_licenses([]) --> !.
  393copyleft_licenses(List) -->
  394    warn([ nl, nl,
  395           'This program contains components covered by a copyleft license', nl,
  396           'that applies to these components only.  Distributing this', nl,
  397           'program in binary form requires making the source of these', nl,
  398           'components available.  Modifications to them must be published', nl,
  399           'under the same license.  These components are:', nl, nl
  400         ]),
  401    license_groups(List).
  402
  403gpl_conflict(false) --> [].
  404gpl_conflict(true) -->
  405    warn([ nl, nl,
  406           'The license of some of the copyleft components above is not', nl,
  407           'compatible with the GNU General Public License.  This program', nl,
  408           'may therefore not be distributed.'
  409         ]).
  410
  411proprietary_licenses([]) --> !.
  412proprietary_licenses(List) -->
  413    warn([ nl,
  414           'This program contains components with proprietary licenses:',
  415           nl, nl
  416         ]),
  417    license_groups(List).
  418
  419license_title(License) -->
  420    {   license(License, _, Att),
  421        memberchk(comment(C), Att)
  422    ->  true
  423    ;   C = License
  424    },
  425    [ '  The following components are covered by the "~w" license'-[C] ].
  426
  427license_url(License) -->
  428    { license(License, _, Att),
  429      memberchk(url(URL), Att)
  430    },
  431    !,
  432    [ nl, '    (see ~w)'-[URL] ].
  433license_url(_) --> [].
  434
  435file_list([]) -->
  436    [].
  437file_list([H|T]) -->
  438    [ '    ~w'-[H], nl ],
  439    file_list(T).
  440
  441known_licenses([]) --> [].
  442known_licenses([H|T]) --> [nl,nl], known_license(H), known_licenses(T).
  443
  444known_license(license(ID, Compat, Atts)) -->
  445    { memberchk(comment(Comment), Atts) },
  446    !,
  447    [ '  ~w (category ~w): ~w'-[ID, Compat, Comment] ],
  448    license_url(ID).
  449known_license(license(ID, Compat, _)) -->
  450    [ '  ~w (category ~w)'-[ID, Compat] ],
  451    license_url(ID).
  452
  453warn([]) --> [].
  454warn([H|T]) --> warn1(H), warn(T).
  455
  456warn1(nl) --> !, [nl].
  457warn1(Line) --> [ansi([fg(red)], Line, [])].
  458warn1(Line-Args) --> [ansi([fg(red)], Line, Args)]