View source with formatted 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)  2014-2018, VU University Amsterdam
    7                              CWI, Amsterdam
    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(prolog_install,
   37          [ qcompile_libraries/0,
   38            cmake_qcompile/0,
   39            cmake_qcompile/2,                   % +File, +Deps
   40            cmake_save_man_index/0
   41          ]).   42:- autoload(library(apply),[maplist/3]).   43:- autoload(library(dialect),[exists_source/1]).   44:- autoload(library(lists),[append/3,member/2,subtract/3]).   45:- autoload(library(make),[make/0]).   46
   47
   48/** <module> Installation support predicates
   49
   50This module provides helper predicates for build and install steps.
   51*/
   52
   53%!  qcompile_libraries
   54%
   55%   Quick-load compilation of the Prolog libraries.
   56
   57qcompile_libraries :-
   58    make,                           % update library index
   59    qcompile_xpce.
   60
   61qcompile_xpce :-                        % no XPCE around
   62    \+ absolute_file_name(swi(xpce),
   63                          [ access(exist),
   64                            file_type(directory),
   65                            file_errors(fail)
   66                          ], _),
   67    !,
   68    print_message(informational, qcompile(no(xpce))).
   69qcompile_xpce :-
   70    (   absolute_file_name(swi('swipl-win.rc'), _,
   71                           [ access(read),
   72                             file_errors(fail)
   73                           ])
   74    ->  use_module(swi('swipl-win.rc'))
   75    ;   true
   76    ),
   77    qcompile_libs.
   78
   79
   80                 /*******************************
   81                 *       PRECOMPILED PARTS      *
   82                 *******************************/
   83
   84qmodule(pce, library(pce)).
   85qmodule(lib, library(pce_manual)).
   86qmodule(lib, library(pcedraw)).
   87qmodule(lib, library('emacs/emacs')).
   88qmodule(lib, library('dialog/dialog')).
   89qmodule(lib, library('trace/trace')).
   90qmodule(lib, library('cql/cql')).
   91
   92qcompile_libs :-
   93    forall(qmodule(_Type, Module),
   94           (   exists_source(Module)
   95           ->  print_message(informational, qcompile(Module)),
   96               qcompile(Module)
   97           ;   print_message(informational, qcompile(no(Module)))
   98           )).
   99
  100		 /*******************************
  101		 *   QLF COMPILATION FOR BUILD	*
  102		 *******************************/
  103
  104%!  cmake_qcompile(+File, +Deps) is det.
  105%
  106%   Qcompile on behalf of CMAKE installation.  File   is  the file to be
  107%   qcompiled. Deps is the dependencies as   CMAKE  believes to be true.
  108%   Reports on inconsistent dependencies
  109
  110cmake_qcompile :-
  111    current_prolog_flag(argv, ['--compile', File, '--qlfdeps' | Rest]),
  112    (   append(Deps, ['--preload'|Preload], Rest)
  113    ->  true
  114    ;   Deps = Rest,
  115        Preload = []
  116    ),
  117    forall(member(X, Preload), preload(X)),
  118    cmake_qcompile(File, Deps).
  119
  120preload(X) :-
  121    atom_concat('lib:', File, X),
  122    !,
  123    use_module(user:library(File)).
  124preload(X) :-
  125    use_module(user:X).
  126
  127
  128cmake_qcompile(File, Deps) :-
  129    qcompile(File),
  130    file_name_extension(File, qlf, QlfFile),
  131    '$qlf_sources'(QlfFile, Files),
  132    maplist(absolute_file_name, Deps, Canonical),
  133    subtract(Files, Canonical, Missing),
  134    subtract(Canonical, Files, Extra),
  135    (   Missing == []
  136    ->  true
  137    ;   print_message(warning, qcompile(missing, File, Missing))
  138    ),
  139    (   Extra == []
  140    ->  true
  141    ;   print_message(warning, qcompile(extra, File, Extra))
  142    ).
  143
  144		 /*******************************
  145		 *        MANUAL SUPPORT	*
  146		 *******************************/
  147
  148%!  cmake_save_man_index
  149%
  150%   Create swi('doc/manindex.db') during the build process.
  151
  152cmake_save_man_index :-
  153    use_module(library(pldoc/man_index)),
  154    save_man_index.
  155
  156
  157                 /*******************************
  158                 *            MESSAGES          *
  159                 *******************************/
  160
  161:- multifile prolog:message//1.  162
  163prolog:message(qcompile(no(What))) -->
  164    [ 'Cannot find ~w'-[What] ].
  165prolog:message(qcompile(library(Lib))) -->
  166    [ nl, '~*c'-[64, 0'*], nl ],
  167    [ 'Qcompile library ~q'-[Lib], nl ],
  168    [ '~*c'-[64, 0'*] ].
  169prolog:message(qcompile(missing, File, Dependencies)) -->
  170    [ 'The following dependencies for ~p are not listed'-[File] ],
  171    deps(Dependencies).
  172prolog:message(qcompile(extra, File, Dependencies)) -->
  173    [ 'The following dependencies for ~p are not needed'-[File] ],
  174    deps(Dependencies).
  175
  176deps([]) -->
  177    [].
  178deps([H|T]) -->
  179    [ nl, '  ~p'-[H] ],
  180    deps(T)