View source with raw comments or as raw
    1/*  Part of ClioPatria SeRQL and SPARQL server
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2017, University of Amsterdam,
    7		   VU University Amsterdam
    8
    9    This program is free software; you can redistribute it and/or
   10    modify it under the terms of the GNU General Public License
   11    as published by the Free Software Foundation; either version 2
   12    of the License, or (at your option) any later version.
   13
   14    This program is distributed in the hope that it will be useful,
   15    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17    GNU General Public License for more details.
   18
   19    You should have received a copy of the GNU General Public
   20    License along with this library; if not, write to the Free Software
   21    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22
   23    As a special exception, if you link this library with other files,
   24    compiled with a Free Software compiler, to produce an executable, this
   25    library does not by itself cause the resulting executable to be covered
   26    by the GNU General Public License. This exception does not however
   27    invalidate any other reasons why the executable file might be covered by
   28    the GNU General Public License.
   29*/
   30
   31:- module(cp_setup,
   32	  [ setup/0
   33	  ]).   34:- prolog_load_context(directory, Dir),
   35   directory_file_path(Dir, lib, LibDir),
   36   asserta(user:file_search_path(library, LibDir)).   37
   38user:message_hook(git(update_versions), informational, _).
   39
   40:- use_module(library(setup)).   41:- use_module(library(option)).   42:- use_module(library(lists)).   43:- use_module(library(apply)).   44:- use_module(library(filesex)).   45
   46:- multifile
   47	user:file_search_path/2.   48:- dynamic
   49	user:file_search_path/2.   50
   51:- prolog_load_context(directory, Dir),
   52   asserta(user:file_search_path(cliopatria, Dir)).   53
   54:- initialization(setup, main).
 setup
Setup ClioPatria. This installs files *.in from the ClioPatria after localization and creates config-enabled.
   61setup :-
   62	options(Options),
   63	setup(Options).
   64
   65setup(Options) :-
   66	cliopatria_dir(ClioDir),
   67	install_dir(Dir),
   68	(   option(help(true), Options)
   69	->  true
   70	;   setup_scripts(ClioDir, Dir)
   71	),
   72	directory_file_path(ClioDir, 'lib/APPCONF.txt.in', ReadmeIn),
   73	directory_file_path(ClioDir, 'config-available', ConfigAvail),
   74	directory_file_path(Dir,     'config-enabled', ConfigEnabled),
   75	setup_default_config(ConfigEnabled, ConfigAvail,
   76			     [ readme(ReadmeIn)
   77			     | Options
   78			     ]),
   79	setup_goodbye.
   80
   81cliopatria_dir(Dir) :-
   82	absolute_file_name(cliopatria(.),
   83			   Dir,
   84			   [ file_type(directory),
   85			     access(read)
   86			   ]).
   87
   88install_dir(Dir) :-
   89	current_prolog_flag(windows, true), !,
   90	working_directory(CWD, CWD),
   91	(   get(@(display), win_directory,
   92		'Create ClioPatria project in', CWD, Dir)
   93	->  true
   94	;   halt(1)
   95	).
   96install_dir(DIR) :-
   97	working_directory(DIR, DIR).
   98
   99
  100setup:substitutions([ 'SWIPL'=PL,		% Prolog executable (for #!...)
  101		      'CLIOPATRIA'=ClioDir,	% ClioPatria directory
  102		      'CWD'=CWD,		% This directory
  103		      'PARENTDIR'=Parent,	% Parent of CWD
  104		      'HASHBANG'=HashBang,	% #! (or not)
  105		      'LOADOPTIONS'=LoadOptions % -s (or not)
  106		    ]) :-
  107	cliopatria_dir(ClioDir),
  108	working_directory(CWD, CWD),
  109	file_directory_name(CWD, Parent),
  110	setup_prolog_executable(PL),
  111	hashbang(HashBang),
  112	load_options(LoadOptions).
  113
  114hashbang('%!') :- current_prolog_flag(windows, true), !.
  115hashbang('#!').
  116
  117load_options('').
 options(-Options) is det
Options is a list of (long) commandline options. This uses a simple generic conversion between command-line argument and option value, defined as follows:
--without-Xwithout(X)
--with-Xwith(X)
--Name=ValueName(Value)
--NameName(true)
  131options(Options) :-
  132	current_prolog_flag(argv, Argv),
  133	(   append(_, [--|AV], Argv)
  134	->  true
  135	;   AV = Argv
  136	),
  137	maplist(cmd_option, AV, Options).
  138
  139cmd_option(Text, Option) :-
  140	atom_concat('--without-', Module, Text), !,
  141	Option = without(Module).
  142cmd_option(Text, Option) :-
  143	atom_concat('--with-', Module, Text), !,
  144	Option = with(Module).
  145cmd_option(Text, Option) :-
  146	atom_concat(--, Rest, Text), !,
  147	(   sub_atom(Rest, B, _, A, =)
  148	->  sub_atom(Rest, 0, B, _, Name),
  149	    sub_atom(Rest, _, A, 0, OptVal),
  150	    canonical_value(OptVal, Value),
  151	    Option =.. [Name,Value]
  152	;   Option =.. [Rest,true]
  153	).
  154cmd_option(Text, Text).
  155
  156canonical_value(Text, Number) :-
  157	catch(atom_number(Text, Number), _, true), !.
  158canonical_value(Text, Text)