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)  2018-2023, VU University Amsterdam
    7			      CWI, Amsterdam
    8                              SWI-Prolog Solutions b.v.
    9    All rights reserved.
   10
   11    Redistribution and use in source and binary forms, with or without
   12    modification, are permitted provided that the following conditions
   13    are met:
   14
   15    1. Redistributions of source code must retain the above copyright
   16       notice, this list of conditions and the following disclaimer.
   17
   18    2. Redistributions in binary form must reproduce the above copyright
   19       notice, this list of conditions and the following disclaimer in
   20       the documentation and/or other materials provided with the
   21       distribution.
   22
   23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   24    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   25    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   26    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   27    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   28    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   29    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   30    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   31    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   32    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   33    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   34    POSSIBILITY OF SUCH DAMAGE.
   35*/
   36
   37:- module(prolog_config,
   38	  [ prolog_dump_runtime_variables/0,
   39            prolog_config/2
   40	  ]).

Provide configuration information

This module provides information about the configuration to facilitate linking against Prolog, embedding Prolog or calling Prolog. */

   48:- multifile
   49    prolog:runtime_config/2.
 prolog_dump_runtime_variables
Dump the current configuration in shell format. This predicate is called when Prolog is started using the commandline option `--dump-runtime-variables`
   57prolog_dump_runtime_variables :-
   58    (   '$cmd_option_val'(config, Format),
   59	Format \== ''
   60    ->  prolog_dump_runtime_variables(Format)
   61    ;   prolog_dump_runtime_variables(sh)
   62    ).
   63
   64prolog_dump_runtime_variables(Format) :-
   65    print_flag(home,                      'PLBASE',          Format),
   66    print_flag(pack_path,                 'SWIPL_PACK_PATH', Format),
   67    print_flag(arch,                      'PLARCH',          Format),
   68    print_flag(address_bits,              'PLBITS',          Format),
   69    print_flag(version,                   'PLVERSION',       Format),
   70    print_flag(shared_object_extension,   'PLSOEXT',         Format),
   71    print_flag(shared_object_search_path, 'PLSOPATH',        Format),
   72    print_flag(c_libdir,                  'PLLIBDIR',        Format),
   73    print_flag(c_lib,                     'PLLIB',           Format),
   74    print_flag(libswipl,                  'PLLIBSWIPL',      Format),
   75    print_flag(open_shared_object,        'PLSHARED',        Format),
   76    print_flag(threads,                   'PLTHREADS',       Format).
   77
   78print_flag(Flag, Var, Format) :-
   79    (   prolog:runtime_config(Flag, Value)
   80    ->  print_config(Format, Var, Value)
   81    ;   prolog_config(Flag, Value)
   82    ->  print_config(Format, Var, Value)
   83    ;   true
   84    ).
 prolog_config(+Config, -Value) is semidet
Get information on the configuration of the current Prolog system. Mostly used to support scripting.
   91prolog_config(Flag, Value) :-
   92    boolean_flag(Flag),
   93    (   current_prolog_flag(Flag, true)
   94    ->  Value = yes
   95    ;   Value = no
   96    ).
   97prolog_config(c_libdir, Value) :-
   98    current_prolog_flag(home, Home),
   99    (   current_prolog_flag(c_libdir, Rel)
  100    ->  atomic_list_concat([Home, Rel], /, Value)
  101    ;   current_prolog_flag(msys2, true)
  102    ->  current_prolog_flag(arch, Arch),
  103        atomic_list_concat([Home, bin, Arch], /, Value)
  104    ;   current_prolog_flag(windows, true)
  105    ->  atomic_list_concat([Home, bin], /, Value)
  106    ;   apple_bundle_libdir(LibDir)
  107    ->  Value = LibDir
  108    ;   current_prolog_flag(arch, Arch)
  109    ->  atomic_list_concat([Home, lib, Arch], /, Value)
  110    ).
  111prolog_config(apple_bundle_libdir, LibDir) :-
  112    apple_bundle_libdir(LibDir).
  113prolog_config(c_lib, '-lswipl').
  114prolog_config(pack_path, Value) :-
  115    findall(Dir, absolute_file_name(pack(.), Dir,
  116                                    [ file_errors(fail),
  117                                      solutions(all)
  118                                    ]),
  119            Dirs),
  120    maplist(prolog_to_os_filename, Dirs, OSDirs),
  121    current_prolog_flag(path_sep, Sep),
  122    atomic_list_concat(OSDirs, Sep, Value).
  123prolog_config(Flag, Value) :-
  124    current_prolog_flag(Flag, Value).
 apple_bundle_libdir(-LibDir)
If we are part of a MacOS bundle the C libraries are in the bundle Frameworks directory and the executable is in the bundle MacOS directory.
  132apple_bundle_libdir(LibDir) :-
  133    current_prolog_flag(apple, true),
  134    current_prolog_flag(executable, Exe),
  135    file_directory_name(Exe, ExeDir),
  136    file_base_name(ExeDir, 'MacOS'),
  137    file_directory_name(ExeDir, ContentsDir),
  138    file_base_name(ContentsDir, 'Contents'),
  139    atomic_list_concat([ContentsDir, 'Frameworks'], /, LibDir),
  140    exists_directory(LibDir).
  141
  142boolean_flag(threads).
  143boolean_flag(open_shared_object).
  144
  145print_config(sh, Var, Value) :-
  146    format('~w=\"~w\";~n', [Var, Value]).
  147print_config(cmd, Var, Value) :-
  148    (   file_var(Var)
  149    ->  prolog_to_os_filename(Value, OSValue),
  150	format('SET ~w=~w~n', [Var, OSValue])
  151    ;   format('SET ~w=~w~n', [Var, Value])
  152    ).
  153
  154file_var('PLBASE')