forked from ClioPatria/ClioPatria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.pl
125 lines (107 loc) · 3.11 KB
/
setup.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
:- module(cp_setup,
[ setup/0
]).
:- prolog_load_context(directory, Dir),
directory_file_path(Dir, lib, LibDir),
asserta(user:file_search_path(library, LibDir)).
:- load_files(library(setup), [silent(true)]).
:- multifile
user:file_search_path/2.
:- dynamic
user:file_search_path/2.
:- prolog_load_context(directory, Dir),
asserta(user:file_search_path(cliopatria, Dir)).
:- initialization
set_prolog_flag(verbose, normal),
setup.
%% setup
%
% Setup ClioPatria. This installs files *.in from the ClioPatria
% after localization and creates config-enabled.
setup :-
options(Options),
setup(Options).
setup(Options) :-
cliopatria_dir(ClioDir),
install_dir(Dir),
( option(help(true), Options)
-> true
; setup_scripts(ClioDir, Dir)
),
directory_file_path(ClioDir, 'lib/APPCONF.txt.in', ReadmeIn),
directory_file_path(ClioDir, 'config-available', ConfigAvail),
directory_file_path(Dir, 'config-enabled', ConfigEnabled),
setup_default_config(ConfigEnabled, ConfigAvail,
[ readme(ReadmeIn)
| Options
]),
setup_goodbye.
cliopatria_dir(Dir) :-
absolute_file_name(cliopatria(.),
Dir,
[ file_type(directory),
access(read)
]).
install_dir(Dir) :-
current_prolog_flag(windows, true), !,
working_directory(CWD, CWD),
( get(@(display), win_directory,
'Create ClioPatria project in', CWD, Dir)
-> true
; halt(1)
).
install_dir(DIR) :-
working_directory(DIR, DIR).
setup:substitutions([ 'SWIPL'=PL, % Prolog executable (for #!...)
'CLIOPATRIA'=ClioDir, % ClioPatria directory
'CWD'=CWD, % This directory
'PARENTDIR'=Parent, % Parent of CWD
'HASHBANG'=HashBang, % #! (or not)
'LOADOPTIONS'=LoadOptions % -s (or not)
]) :-
cliopatria_dir(ClioDir),
working_directory(CWD, CWD),
file_directory_name(CWD, Parent),
setup_prolog_executable(PL),
hashbang(HashBang),
load_options(LoadOptions).
hashbang('%!') :- current_prolog_flag(windows, true), !.
hashbang('#!').
load_options('') :- current_prolog_flag(os_argv, _), !.
load_options('-s').
%% 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-X | without(X) |
% | --with-X | with(X) |
% | --Name=Value | Name(Value) |
% | --Name | Name(true) |
options(Options) :-
current_prolog_flag(argv, Argv),
( append(_, [--|AV], Argv)
-> true
; AV = Argv
),
maplist(cmd_option, AV, Options).
cmd_option(Text, Option) :-
atom_concat('--without-', Module, Text), !,
Option = without(Module).
cmd_option(Text, Option) :-
atom_concat('--with-', Module, Text), !,
Option = with(Module).
cmd_option(Text, Option) :-
atom_concat(--, Rest, Text), !,
( sub_atom(Rest, B, _, A, =)
-> sub_atom(Rest, 0, B, _, Name),
sub_atom(Rest, _, A, 0, OptVal),
canonical_value(OptVal, Value),
Option =.. [Name,Value]
; Option =.. [Rest,true]
).
cmd_option(Text, Text).
canonical_value(Text, Number) :-
catch(atom_number(Text, Number), _, true), !.
canonical_value(Text, Text).