/usr/lib/swi-prolog/doc/Manual/compilation.html is in swi-prolog-nox 5.10.4-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>SWI-Prolog 5.11.18 Reference Manual: Section 2.10</TITLE><LINK REL=home HREF="index.html">
<LINK REL=contents HREF="Contents.html">
<LINK REL=index HREF="DocIndex.html">
<LINK REL=summary HREF="summary.html">
<LINK REL=previous HREF="debugoverview.html">
<LINK REL=next HREF="flags.html">
<STYLE type="text/css">
/* Style sheet for SWI-Prolog latex2html
*/
dd.defbody
{ margin-bottom: 1em;
}
dt.pubdef
{ background-color: #c5e1ff;
}
dt.multidef
{ background-color: #c8ffc7;
}
.bib dd
{ margin-bottom: 1em;
}
.bib dt
{ float: left;
margin-right: 1.3ex;
}
pre.code
{ margin-left: 1.5em;
margin-right: 1.5em;
border: 1px dotted;
padding-top: 5px;
padding-left: 5px;
padding-bottom: 5px;
background-color: #f8f8f8;
}
div.navigate
{ text-align: center;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
}
div.title
{ text-align: center;
padding-bottom: 1em;
font-size: 200%;
font-weight: bold;
}
div.author
{ text-align: center;
font-style: italic;
}
div.abstract
{ margin-top: 2em;
background-color: #f0f0f0;
border: 1px dotted;
padding: 5px;
margin-left: 10%; margin-right:10%;
}
div.abstract-title
{ text-align: center;
padding: 5px;
font-size: 120%;
font-weight: bold;
}
div.toc-h1
{ font-size: 200%;
font-weight: bold;
}
div.toc-h2
{ font-size: 120%;
font-weight: bold;
margin-left: 2em;
}
div.toc-h3
{ font-size: 100%;
font-weight: bold;
margin-left: 4em;
}
div.toc-h4
{ font-size: 100%;
margin-left: 6em;
}
span.sec-nr
{
}
span.sec-title
{
}
span.pred-ext
{ font-weight: bold;
}
span.pred-tag
{ float: right;
padding-top: 0.2em;
font-size: 80%;
font-style: italic;
color: #202020;
}
/* Footnotes */
sup.fn { color: blue; text-decoration: underline; }
span.fn-text { display: none; }
sup.fn span {display: none;}
sup:hover span
{ display: block !important;
position: absolute; top: auto; left: auto; width: 80%;
color: #000; background: white;
border: 2px solid;
padding: 5px; margin: 10px; z-index: 100;
font-size: smaller;
}
</STYLE>
</HEAD>
<BODY BGCOLOR="white">
<DIV class="navigate"><A class="nav" href="index.html"><IMG SRC="home.gif" BORDER=0 ALT="Home"></A>
<A class="nav" href="Contents.html"><IMG SRC="index.gif" BORDER=0 ALT="Contents"></A>
<A class="nav" href="DocIndex.html"><IMG SRC="yellow_pages.gif" BORDER=0 ALT="Index"></A>
<A class="nav" href="summary.html"><IMG SRC="info.gif" BORDER=0 ALT="Summary"></A>
<A class="nav" href="debugoverview.html"><IMG SRC="prev.gif" BORDER=0 ALT="Previous"></A>
<A class="nav" href="flags.html"><IMG SRC="next.gif" BORDER=0 ALT="Next"></A>
</DIV>
<H2><A NAME="sec:2.10"><SPAN class="sec-nr">2.10</SPAN> <SPAN class="sec-title">Compilation</SPAN></A></H2>
<A NAME="sec:compilation"></A>
<H3><A NAME="sec:2.10.1"><SPAN class="sec-nr">2.10.1</SPAN> <SPAN class="sec-title">During
program development</SPAN></A></H3>
<A NAME="sec:develcomp"></A>
<P>During program development, programs are normally loaded using
<A NAME="idx:consult1:104"></A><A class="pred" href="consulting.html#consult/1">consult/1</A>,
or the list abbreviation. It is common practice to organise a project as
a collection of source files and a <EM>load-file</EM>, a Prolog file
containing only <A NAME="idx:usemodule12:105"></A><A class="pred" href="import.html#use_module/1">use_module/[1,2]</A>
or <A NAME="idx:ensureloaded1:106"></A><A class="pred" href="consulting.html#ensure_loaded/1">ensure_loaded/1</A>
directives, possibly with a definition of the <EM>entry-point</EM> of
the program, the predicate that is normally used to start the program.
This file is often called <CODE>load.pl</CODE>. If the entry-point is
called
<EM>go</EM>, a typical session starts as:
<PRE class="code">
% swipl
<banner>
1 ?- [load].
<compilation messages>
Yes
2 ?- go.
<program interaction>
</PRE>
<P>When using Windows, the user may open <CODE>load.pl</CODE> from the
Windows explorer, which will cause <B>swipl-win.exe</B> to be started in
the directory holding <CODE>load.pl</CODE>. Prolog loads <CODE>load.pl</CODE>
before entering the top-level.
<H3><A NAME="sec:2.10.2"><SPAN class="sec-nr">2.10.2</SPAN> <SPAN class="sec-title">For
running the result</SPAN></A></H3>
<A NAME="sec:runcomp"></A>
<P>There are various options if you want to make your program ready for
real usage. The best choice depends on whether the program is to be used
only on machines holding the SWI-Prolog development system, the size of
the program and the operating system (Unix vs. Windows).
<H4><A NAME="sec:2.10.2.1"><SPAN class="sec-nr">2.10.2.1</SPAN> <SPAN class="sec-title">Using
PrologScript</SPAN></A></H4>
<A NAME="sec:plscript"></A>
<P>New in version 4.0.5 is the possibility to use a Prolog source file
directly as a Unix script-file. The same mechanism is useful to specify
additional parameters for running a Prolog file on Windows.
<P>If the first letter of a Prolog file is <CODE>#</CODE>, the first
line is treated as comment.<SUP class="fn">5<SPAN class="fn-text">The <TT>#</TT>-sign
can be the legal start of a normal Prolog clause. In the unlikely case
this is required, leave the first line blank or add a header-comment.</SPAN></SUP>
To create a Prolog script, make the first line start like this:
<BLOCKQUOTE>
<CODE>#!/path/to/pl</CODE> <<VAR>options</VAR>> <CODE>-s</CODE>
</BLOCKQUOTE>
<P>Prolog recognises this starting sequence and causes the interpreter
to receive the following argument-list:
<BLOCKQUOTE>
<CODE>/path/to/pl</CODE> <<VAR>options</VAR>> <CODE>-s</CODE> <<VAR>script</VAR>> <CODE>--</CODE> <<VAR>ScriptArguments</VAR>>
</BLOCKQUOTE>
<P>Instead of <STRONG>-s</STRONG>, the user may use <STRONG>-f</STRONG>
to stop Prolog from looking for a personal initialisation file.
<P>Here is a simple script doing expression evaluation:
<PRE class="code">
#!/usr/bin/pl -q -t main -f
eval :-
current_prolog_flag(argv, Argv),
append(_, [--|Args], Argv),
concat_atom(Args, ' ', SingleArg),
term_to_atom(Term, SingleArg),
Val is Term,
format('~w~n', [Val]).
main :-
catch(eval, E, (print_message(error, E), fail)),
halt.
main :-
halt(1).
</PRE>
<P>And here are two example runs:
<PRE class="code">
% eval 1+2
3
% eval foo
ERROR: Arithmetic: `foo/0' is not a function
%
</PRE>
<P><B>The Windows version</B> supports the <CODE>#!</CODE> construct
too, but here it serves a rather different role. The Windows shell
already allows the user to start Prolog source files directly through
the Windows file-type association. Windows however makes it rather
complicated to provide additional parameters, such as the required
stack-size for an individual Prolog file. The <CODE>#!</CODE> line
provides for this, providing a more flexible approach than changing the
global defaults. The following starts Prolog with unlimited stack-size
on the given source file:
<PRE class="code">
#!/usr/bin/pl -L0 -T0 -G0 -s
....
</PRE>
<P>Note the use of <CODE>/usr/bin/pl</CODE>, which specifies the
interpreter. This argument is ignored in the Windows version, but
required to ensure best cross-platform compatibility.
<H4><A NAME="sec:2.10.2.2"><SPAN class="sec-nr">2.10.2.2</SPAN> <SPAN class="sec-title">Creating
a shell-script</SPAN></A></H4>
<A NAME="sec:shellscript"></A>
<P>With the introduction of <EM>PrologScript</EM> (see <A class="sec" href="compilation.html">section
2.10.2.1</A>), using shell-scripts as explained in this section has
become redundant for most applications.
<P>Especially on Unix systems and not-too-large applications, writing a
shell-script that simply loads your application and calls the
entry-point is often a good choice. A skeleton for the script is given
below, followed by the Prolog code to obtain the program arguments.
<PRE class="code">
#!/bin/sh
base=<absolute-path-to-source>
PL=pl
exec $PL -f none -g "load_files(['$base/load'],[silent(true)])" \
-t go -- $*
</PRE>
<PRE class="code">
go :-
current_prolog_flag(argv, Arguments),
append(_SytemArgs, [--|Args], Arguments), !,
go(Args).
go(Args) :-
...
</PRE>
<P>On Windows systems, similar behaviour can be achieved by creating a
shortcut to Prolog, passing the proper options or writing a <CODE>.bat</CODE>
file.
<H4><A NAME="sec:2.10.2.3"><SPAN class="sec-nr">2.10.2.3</SPAN> <SPAN class="sec-title">Creating
a saved-state</SPAN></A></H4>
<A NAME="sec:makestate"></A>
<P>For larger programs, as well as for programs that are required to run
on systems that do not have the SWI-Prolog development system installed,
creating a saved state is the best solution. A saved state is created
using <A NAME="idx:qsaveprogram12:107"></A><A class="pred" href="runtime.html#qsave_program/1">qsave_program/[1,2]</A>
or using the linker swipl-ld(1). A saved state is a file containing
machine-independent intermediate code in a format dedicated for fast
loading. Optionally, the emulator may be integrated in the saved state,
creating a single-file, but machine-dependent, executable. This process
is described in <A class="sec" href="runtime.html">chapter 10</A>.
<H4><A NAME="sec:2.10.2.4"><SPAN class="sec-nr">2.10.2.4</SPAN> <SPAN class="sec-title">Compilation
using the -c command-line option</SPAN></A></H4>
<A NAME="sec:cmdlinecomp"></A>
<P>This mechanism loads a series of Prolog source files and then creates
a saved-state as <A NAME="idx:qsaveprogram2:108"></A><A class="pred" href="runtime.html#qsave_program/2">qsave_program/2</A>
does. The command syntax is:
<PRE class="code">
% swipl [option ...] [-o output] -c file ...
</PRE>
<P>The <VAR>options</VAR> argument are options to <A NAME="idx:qsaveprogram2:109"></A><A class="pred" href="runtime.html#qsave_program/2">qsave_program/2</A>
written in the format below. The option-names and their values are
described with
<A NAME="idx:qsaveprogram2:110"></A><A class="pred" href="runtime.html#qsave_program/2">qsave_program/2</A>.
<BLOCKQUOTE>
<CODE>--</CODE><EM>option-name</EM><CODE>=</CODE><EM>option-value
</EM></BLOCKQUOTE>
<P>For example, to create a stand-alone executable that starts by
executing main/0 and for which the source is loaded through
<CODE>load.pl</CODE>, use the command
<PRE class="code">
% swipl --goal=main --stand_alone=true -o myprog -c load.pl
</PRE>
<P>This performs exactly the same as executing
<PRE class="code">
% swipl
<banner>
?- [load].
?- qsave_program(myprog,
[ goal(main),
stand_alone(true)
]).
?- halt.
</PRE>
<P></BODY></HTML>
|