35
36:- module(cp_setup,
37 [ setup/0
38 ]). 39:- prolog_load_context(directory, Dir),
40 directory_file_path(Dir, lib, LibDir),
41 asserta(user:file_search_path(library, LibDir)). 42
43user:message_hook(git(update_versions), informational, _).
44
45:- use_module(library(setup)). 46:- use_module(library(option)). 47:- use_module(library(lists)). 48:- use_module(library(apply)). 49:- use_module(library(filesex)). 50
51:- multifile
52 user:file_search_path/2. 53:- dynamic
54 user:file_search_path/2. 55
56:- prolog_load_context(directory, Dir),
57 asserta(user:file_search_path(cliopatria, Dir)). 58
59:- initialization(setup, main).
66setup :-
67 options(Options),
68 setup(Options).
69
70setup(Options) :-
71 cliopatria_dir(ClioDir),
72 install_dir(Dir),
73 ( option(help(true), Options)
74 -> true
75 ; setup_scripts(ClioDir, Dir)
76 ),
77 directory_file_path(ClioDir, 'lib/APPCONF.txt.in', ReadmeIn),
78 directory_file_path(ClioDir, 'config-available', ConfigAvail),
79 directory_file_path(Dir, 'config-enabled', ConfigEnabled),
80 setup_default_config(ConfigEnabled, ConfigAvail,
81 [ readme(ReadmeIn)
82 | Options
83 ]),
84 setup_goodbye.
85
86cliopatria_dir(Dir) :-
87 absolute_file_name(cliopatria(.),
88 Dir,
89 [ file_type(directory),
90 access(read)
91 ]).
92
93install_dir(Dir) :-
94 current_prolog_flag(windows, true),
95 !,
96 working_directory(CWD, CWD),
97 ( get(@(display), win_directory,
98 'Create ClioPatria project in', CWD, Dir)
99 -> true
100 ; halt(1)
101 ).
102install_dir(DIR) :-
103 working_directory(DIR, DIR).
104
105
106setup:substitutions([ 'SWIPL'=PL, 107 'CLIOPATRIA'=ClioDir, 108 'CWD'=CWD, 109 'PARENTDIR'=Parent, 110 'HASHBANG'=HashBang, 111 'LOADOPTIONS'=LoadOptions 112 ]) :-
113 cliopatria_dir(ClioDir),
114 working_directory(CWD, CWD),
115 file_directory_name(CWD, Parent),
116 setup_prolog_executable(PL),
117 hashbang(HashBang),
118 load_options(LoadOptions).
119
120hashbang('%!') :- current_prolog_flag(windows, true), !.
121hashbang('#!').
122
123load_options('').
137options(Options) :-
138 current_prolog_flag(argv, Argv),
139 ( append(_, [--|AV], Argv)
140 -> true
141 ; AV = Argv
142 ),
143 maplist(cmd_option, AV, Options).
144
145cmd_option(Text, Option) :-
146 atom_concat('--without-', Module, Text),
147 !,
148 Option = without(Module).
149cmd_option(Text, Option) :-
150 atom_concat('--with-', Module, Text),
151 !,
152 Option = with(Module).
153cmd_option(Text, Option) :-
154 atom_concat(--, Rest, Text),
155 !,
156 ( sub_atom(Rest, B, _, A, =)
157 -> sub_atom(Rest, 0, B, _, Name),
158 sub_atom(Rest, _, A, 0, OptVal),
159 canonical_value(OptVal, Value),
160 Option =.. [Name,Value]
161 ; Option =.. [Rest,true]
162 ).
163cmd_option(Text, Text).
164
165canonical_value(Text, Number) :-
166 catch(atom_number(Text, Number), _, true),
167 !.
168canonical_value(Text, Text)