Debian Codegraph @

embedded/www/files/critcl_package.html

raw
1 <!DOCTYPE html><html><head>
2 <meta charset="UTF-8">
3 <meta name="viewport" content="width=device-width, initial-scale=1">
4 <title>critcl_package - C Runtime In Tcl (CriTcl)</title>
5 <style type="text/css"><!--
6 HTML {
7 background: #FFFFFF;
8 color: black;
9 }
10 BODY {
11 background: #FFFFFF;
12 color: black;
13 }
14 DIV.doctools {
15 margin-left: 10%;
16 margin-right: 10%;
17 }
18 DIV.doctools H1,DIV.doctools H2 {
19 margin-left: -5%;
20 }
21 H1, H2, H3, H4 {
22 margin-top: 1em;
23 font-family: sans-serif;
24 font-size: large;
25 color: #005A9C;
26 background: transparent;
27 text-align: left;
28 }
29 H1.doctools_title {
30 text-align: center;
31 }
32 UL,OL {
33 margin-right: 0em;
34 margin-top: 3pt;
35 margin-bottom: 3pt;
36 }
37 UL LI {
38 list-style: disc;
39 }
40 OL LI {
41 list-style: decimal;
42 }
43 DT {
44 padding-top: 1ex;
45 }
46 UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
47 font: normal 12pt/14pt sans-serif;
48 list-style: none;
49 }
50 LI.doctools_section, LI.doctools_subsection {
51 list-style: none;
52 margin-left: 0em;
53 text-indent: 0em;
54 padding: 0em;
55 }
56 PRE {
57 display: block;
58 font-family: monospace;
59 white-space: pre;
60 margin: 0%;
61 padding-top: 0.5ex;
62 padding-bottom: 0.5ex;
63 padding-left: 1ex;
64 padding-right: 1ex;
65 width: 100%;
66 }
67 PRE.doctools_example {
68 color: black;
69 background: #f5dcb3;
70 border: 1px solid black;
71 }
72 UL.doctools_requirements LI, UL.doctools_syntax LI {
73 list-style: none;
74 margin-left: 0em;
75 text-indent: 0em;
76 padding: 0em;
77 }
78 DIV.doctools_synopsis {
79 color: black;
80 background: #80ffff;
81 border: 1px solid black;
82 font-family: serif;
83 margin-top: 1em;
84 margin-bottom: 1em;
85 }
86 UL.doctools_syntax {
87 margin-top: 1em;
88 border-top: 1px solid black;
89 }
90 UL.doctools_requirements {
91 margin-bottom: 1em;
92 border-bottom: 1px solid black;
93 }
94 --></style>
95 </head>
96 <!-- Generated from file 'critcl_package.man' by tcllib/doctools with format 'html'
97 -->
98 <!-- Copyright &amp;copy; Jean-Claude Wippler -- Copyright &amp;copy; Steve Landers -- Copyright &amp;copy; 2011-2024 Andreas Kupries
99 -->
100 <!-- critcl_package.n
101 -->
102 <body><hr> [
103 <a href="../toc.html">Table Of Contents</a>
104 &#124; <a href="../index.html">Keyword Index</a>
105 ] <hr>
106 <div class="doctools">
107 <h1 class="doctools_title">critcl_package(n) 3.3.1 doc &quot;C Runtime In Tcl (CriTcl)&quot;</h1>
108 <div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
109 <p>critcl_package - CriTcl Package Reference</p>
110 </div>
111 <div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
112 <ul class="doctools_toc">
113 <li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
114 <li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
115 <li class="doctools_section"><a href="#section1">Description</a></li>
116 <li class="doctools_section"><a href="#section2">API</a>
117 <ul>
118 <li class="doctools_subsection"><a href="#subsection1">Embedded C Code</a></li>
119 <li class="doctools_subsection"><a href="#subsection2">Stubs Table Management</a></li>
120 <li class="doctools_subsection"><a href="#subsection3">Package Meta Data</a></li>
121 <li class="doctools_subsection"><a href="#subsection4">Control &amp; Interface</a></li>
122 <li class="doctools_subsection"><a href="#subsection5">Introspection</a></li>
123 <li class="doctools_subsection"><a href="#subsection6">Build Management</a></li>
124 <li class="doctools_subsection"><a href="#subsection7">Result Cache Management</a></li>
125 <li class="doctools_subsection"><a href="#subsection8">Build Configuration</a></li>
126 <li class="doctools_subsection"><a href="#subsection9">Tool API</a></li>
127 <li class="doctools_subsection"><a href="#subsection10">Advanced: Embedded C Code</a></li>
128 <li class="doctools_subsection"><a href="#subsection11">Custom Build Configuration</a></li>
129 <li class="doctools_subsection"><a href="#subsection12">Advanced: Location management</a></li>
130 <li class="doctools_subsection"><a href="#subsection13">Advanced: Diversions</a></li>
131 <li class="doctools_subsection"><a href="#subsection14">Advanced: File Generation</a></li>
132 </ul>
133 </li>
134 <li class="doctools_section"><a href="#section3">Concepts</a>
135 <ul>
136 <li class="doctools_subsection"><a href="#subsection15">Modes Of Operation/Use</a></li>
137 <li class="doctools_subsection"><a href="#subsection16">Runtime Behaviour</a></li>
138 <li class="doctools_subsection"><a href="#subsection17">File Mapping</a></li>
139 <li class="doctools_subsection"><a href="#subsection18">Result Cache</a></li>
140 <li class="doctools_subsection"><a href="#subsection19">Preloading functionality</a></li>
141 <li class="doctools_subsection"><a href="#subsection20">Configuration Internals</a></li>
142 <li class="doctools_subsection"><a href="#subsection21">Stubs Tables</a></li>
143 </ul>
144 </li>
145 <li class="doctools_section"><a href="#section4">Examples</a></li>
146 <li class="doctools_section"><a href="#section5">Authors</a></li>
147 <li class="doctools_section"><a href="#section6">Bugs, Ideas, Feedback</a></li>
148 <li class="doctools_section"><a href="#keywords">Keywords</a></li>
149 <li class="doctools_section"><a href="#category">Category</a></li>
150 <li class="doctools_section"><a href="#copyright">Copyright</a></li>
151 </ul>
152 </div>
153 <div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
154 <div class="doctools_synopsis">
155 <ul class="doctools_requirements">
156 <li>package require <b class="pkgname">Tcl 8.6</b></li>
157 <li>package require <b class="pkgname">critcl <span class="opt">?3.3.1?</span></b></li>
158 <li>package require <b class="pkgname">platform <span class="opt">?1.0.2?</span></b></li>
159 <li>package require <b class="pkgname">md5 <span class="opt">?2?</span></b></li>
160 </ul>
161 <ul class="doctools_syntax">
162 <li><a href="#1"><b class="cmd">::critcl::ccode</b> <i class="arg">fragment</i></a></li>
163 <li><a href="#2"><b class="cmd">::critcl::ccommand</b> <i class="arg">tclname</i> <i class="arg">cname</i></a></li>
164 <li><a href="#3"><b class="cmd">::critcl::ccommand</b> <i class="arg">tclname</i> <i class="arg">arguments</i> <i class="arg">body</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i>...?</span></a></li>
165 <li><a href="#4"><b class="cmd">::critcl::cdata</b> <i class="arg">tclname</i> <i class="arg">data</i></a></li>
166 <li><a href="#5"><b class="cmd">::critcl::cconst</b> <i class="arg">tclname</i> <i class="arg">resulttype</i> <i class="arg">value</i></a></li>
167 <li><a href="#6"><b class="cmd">::critcl::cdefines</b> <i class="arg">list of glob patterns</i> <span class="opt">?<i class="arg">namespace</i>?</span></a></li>
168 <li><a href="#7"><b class="cmd">::critcl::cproc</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">resulttype</i> <i class="arg">body</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i>...?</span></a></li>
169 <li><a href="#8"><b class="cmd">::critcl::cproc</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">resulttype</i></a></li>
170 <li><a href="#9"><b class="cmd">::critcl::cinit</b> <i class="arg">text</i> <i class="arg">externals</i></a></li>
171 <li><a href="#10"><b class="cmd">::critcl::include</b> <i class="arg">path</i></a></li>
172 <li><a href="#11"><b class="cmd">::critcl::api</b> <b class="method">import</b> <i class="arg">name</i> <i class="arg">version</i></a></li>
173 <li><a href="#12"><b class="cmd">::critcl::api</b> <b class="method">function</b> <i class="arg">resulttype</i> <i class="arg">name</i> <i class="arg">arguments</i></a></li>
174 <li><a href="#13"><b class="cmd">::critcl::api</b> <b class="method">header</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></li>
175 <li><a href="#14"><b class="cmd">::critcl::api</b> <b class="method">extheader</b> <span class="opt">?<i class="arg">file</i>...?</span></a></li>
176 <li><a href="#15"><b class="cmd">::critcl::license</b> <i class="arg">author</i> <span class="opt">?<i class="arg">text</i>...?</span></a></li>
177 <li><a href="#16"><b class="cmd">::critcl::summary</b> <i class="arg">text</i></a></li>
178 <li><a href="#17"><b class="cmd">::critcl::description</b> <i class="arg">text</i></a></li>
179 <li><a href="#18"><b class="cmd">::critcl::subject</b> <span class="opt">?<i class="arg">key</i>...?</span></a></li>
180 <li><a href="#19"><b class="cmd">::critcl::meta</b> <i class="arg">key</i> <span class="opt">?<i class="arg">word</i>...?</span></a></li>
181 <li><a href="#20"><b class="cmd">::critcl::meta?</b> <i class="arg">key</i></a></li>
182 <li><a href="#21"><b class="cmd">::critcl::buildrequirement</b> <i class="arg">script</i></a></li>
183 <li><a href="#22"><b class="cmd">::critcl::cheaders</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></li>
184 <li><a href="#23"><b class="cmd">::critcl::csources</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></li>
185 <li><a href="#24"><b class="cmd">::critcl::clibraries</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></li>
186 <li><a href="#25"><b class="cmd">::critcl::source</b> <i class="arg">glob pattern</i></a></li>
187 <li><a href="#26"><b class="cmd">::critcl::tsources</b> <i class="arg">glob pattern</i>...</a></li>
188 <li><a href="#27"><b class="cmd">::critcl::owns</b> <i class="arg">glob pattern</i>...</a></li>
189 <li><a href="#28"><b class="cmd">::critcl::cflags</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></li>
190 <li><a href="#29"><b class="cmd">::critcl::ldflags</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></li>
191 <li><a href="#30"><b class="cmd">::critcl::framework</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></li>
192 <li><a href="#31"><b class="cmd">::critcl::tcl</b> <i class="arg">version</i></a></li>
193 <li><a href="#32"><b class="cmd">::critcl::tk</b></a></li>
194 <li><a href="#33"><b class="cmd">::critcl::preload</b> <i class="arg">lib</i>...</a></li>
195 <li><a href="#34"><b class="cmd">::critcl::debug</b> <i class="arg">area</i>...</a></li>
196 <li><a href="#35"><b class="cmd">::critcl::check</b> <span class="opt">?<i class="arg">label</i>?</span> <i class="arg">text</i></a></li>
197 <li><a href="#36"><b class="cmd">::critcl::checklink</b> <span class="opt">?<i class="arg">label</i>?</span> <i class="arg">text</i></a></li>
198 <li><a href="#37"><b class="cmd">::critcl::msg</b> <span class="opt">?<b class="option">-nonewline</b>?</span> <i class="arg">msg</i></a></li>
199 <li><a href="#38"><b class="cmd">::critcl::print</b> <span class="opt">?<b class="option">-nonewline</b>?</span> <span class="opt">?<i class="arg">chan</i>?</span> <i class="arg">msg</i></a></li>
200 <li><a href="#39"><b class="cmd">::critcl::compiled</b></a></li>
201 <li><a href="#40"><b class="cmd">::critcl::compiling</b></a></li>
202 <li><a href="#41"><b class="cmd">::critcl::done</b></a></li>
203 <li><a href="#42"><b class="cmd">::critcl::failed</b></a></li>
204 <li><a href="#43"><b class="cmd">::critcl::load</b></a></li>
205 <li><a href="#44"><b class="cmd">::critcl::config</b> <i class="arg">option</i> <span class="opt">?<i class="arg">val</i>?</span></a></li>
206 <li><a href="#45"><b class="cmd">::critcl::cache</b> <span class="opt">?path?</span></a></li>
207 <li><a href="#46"><b class="cmd">::critcl::clean_cache</b> <span class="opt">?<i class="arg">pattern</i>...?</span></a></li>
208 <li><a href="#47"><b class="cmd">::critcl::readconfig</b> <i class="arg">path</i></a></li>
209 <li><a href="#48"><b class="cmd">::critcl::showconfig</b> <span class="opt">?<i class="arg">chan</i>?</span></a></li>
210 <li><a href="#49"><b class="cmd">::critcl::showallconfig</b> <span class="opt">?<i class="arg">chan</i>?</span></a></li>
211 <li><a href="#50"><b class="cmd">::critcl::chooseconfig</b> <i class="arg">target</i> <span class="opt">?<i class="arg">nomatcherr</i>?</span></a></li>
212 <li><a href="#51"><b class="cmd">::critcl::setconfig</b> <i class="arg">target</i></a></li>
213 <li><a href="#52"><b class="cmd">::critcl::actualtarget</b></a></li>
214 <li><a href="#53"><b class="cmd">::critcl::buildforpackage</b> <span class="opt">?<i class="arg">flag</i>?</span></a></li>
215 <li><a href="#54"><b class="cmd">::critcl::cnothingtodo</b> <i class="arg">file</i></a></li>
216 <li><a href="#55"><b class="cmd">::critcl::cresults</b> <span class="opt">?<i class="arg">file</i>?</span></a></li>
217 <li><a href="#56"><b class="cmd">::critcl::crosscheck</b></a></li>
218 <li><a href="#57"><b class="cmd">::critcl::error</b> <i class="arg">msg</i></a></li>
219 <li><a href="#58"><b class="cmd">::critcl::knowntargets</b></a></li>
220 <li><a href="#59"><b class="cmd">::critcl::sharedlibext</b></a></li>
221 <li><a href="#60"><b class="cmd">::critcl::targetconfig</b></a></li>
222 <li><a href="#61"><b class="cmd">::critcl::buildplatform</b></a></li>
223 <li><a href="#62"><b class="cmd">::critcl::targetplatform</b></a></li>
224 <li><a href="#63"><b class="cmd">::critcl::cobjects</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></li>
225 <li><a href="#64"><b class="cmd">::critcl::scan</b> <i class="arg">path</i></a></li>
226 <li><a href="#65"><b class="cmd">::critcl::name2c</b> <i class="arg">name</i></a></li>
227 <li><a href="#66"><b class="cmd">::critcl::argnames</b> <i class="arg">arguments</i></a></li>
228 <li><a href="#67"><b class="cmd">::critcl::argcnames</b> <i class="arg">arguments</i></a></li>
229 <li><a href="#68"><b class="cmd">::critcl::argcsignature</b> <i class="arg">arguments</i></a></li>
230 <li><a href="#69"><b class="cmd">::critcl::argvardecls</b> <i class="arg">arguments</i></a></li>
231 <li><a href="#70"><b class="cmd">::critcl::argconversion</b> <i class="arg">arguments</i> <span class="opt">?<i class="arg">n</i>?</span></a></li>
232 <li><a href="#71"><b class="cmd">::critcl::argoptional</b> <i class="arg">arguments</i></a></li>
233 <li><a href="#72"><b class="cmd">::critcl::argdefaults</b> <i class="arg">arguments</i></a></li>
234 <li><a href="#73"><b class="cmd">::critcl::argsupport</b> <i class="arg">arguments</i></a></li>
235 <li><a href="#74"><b class="cmd">::critcl::userconfig</b> <b class="method">define</b> <i class="arg">name</i> <i class="arg">description</i> <i class="arg">type</i> <span class="opt">?<i class="arg">default</i>?</span></a></li>
236 <li><a href="#75"><b class="cmd">::critcl::userconfig</b> <b class="method">query</b> <i class="arg">name</i></a></li>
237 <li><a href="#76"><b class="cmd">::critcl::userconfig</b> <b class="method">set</b> <i class="arg">name</i> <i class="arg">value</i></a></li>
238 <li><a href="#77"><b class="cmd">::critcl::at::caller</b></a></li>
239 <li><a href="#78"><b class="cmd">::critcl::at::caller</b> <i class="arg">offset</i></a></li>
240 <li><a href="#79"><b class="cmd">::critcl::at::caller</b> <i class="arg">offset</i> <i class="arg">level</i></a></li>
241 <li><a href="#80"><b class="cmd">::critcl::at::here</b></a></li>
242 <li><a href="#81"><b class="cmd">::critcl::at::get*</b></a></li>
243 <li><a href="#82"><b class="cmd">::critcl::at::get</b></a></li>
244 <li><a href="#83"><b class="cmd">::critcl::at::=</b> <i class="arg">file</i> <i class="arg">line</i></a></li>
245 <li><a href="#84"><b class="cmd">::critcl::at::incr</b> <i class="arg">n</i>...</a></li>
246 <li><a href="#85"><b class="cmd">::critcl::at::incrt</b> <i class="arg">str</i>...</a></li>
247 <li><a href="#86"><b class="cmd">::critcl::at::caller!</b></a></li>
248 <li><a href="#87"><b class="cmd">::critcl::at::caller!</b> <i class="arg">offset</i></a></li>
249 <li><a href="#88"><b class="cmd">::critcl::at::caller!</b> <i class="arg">offset</i> <i class="arg">level</i></a></li>
250 <li><a href="#89"><b class="cmd">::critcl::at::here!</b></a></li>
251 <li><a href="#90"><b class="cmd">::critcl::collect_begin</b></a></li>
252 <li><a href="#91"><b class="cmd">::critcl::collect_end</b></a></li>
253 <li><a href="#92"><b class="cmd">::critcl::collect</b> <i class="arg">script</i></a></li>
254 <li><a href="#93"><b class="cmd">::critcl::make</b> <i class="arg">path</i> <i class="arg">contents</i></a></li>
255 <li><a href="#94"><b class="cmd">::preload</b> <i class="arg">library</i></a></li>
256 </ul>
257 </div>
258 </div>
259 <div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
260 <p>Be welcome to the <i class="term">C Runtime In Tcl</i> (short: <i class="term"><a href="critcl.html">CriTcl</a></i>), a system for embedding and using C
261 code from within <a href="http://core.tcl-lang.org/tcl">Tcl</a> scripts.</p>
262 <p>The <b class="package"><a href="critcl.html">critcl</a></b> package is the core of the system. For an overview of the
263 complete system, see <i class="term"><a href="critcl.html">Introduction To CriTcl</a></i>. For the usage of the
264 standalone <b class="cmd"><a href="critcl.html">critcl</a></b> program, see <i class="term">CriTcl Application</i>.
265 This core package maybe be used to embed C code into Tcl scripts. It also
266 provides access to the internals that other parts of the core use and which
267 are of interest to those wishing to understand the internal workings of the
268 core and of the API it provides to the <i class="term">CriTcl Application</i>. These
269 advanced sections are marked as such so that those simply wishing to use the
270 package can skip them.</p>
271 <p>This package resides in the Core Package Layer of CriTcl.</p>
272 <p><img alt="arch_core" src="../image/arch_core.png"></p>
273 </div>
274 <div id="section2" class="doctools_section"><h2><a name="section2">API</a></h2>
275 <p>A short note ahead of the documentation: Instead of repeatedly talking
276 about
277 &quot;a Tcl script with embbedded C code&quot;, or
278 &quot;a Tcl script containing CriTcl commands&quot;,
279 we call such a script a <i class="term">CriTcl script</i>. A file containing a
280 <i class="term">CriTcl script</i> usually has the extension <b class="const">.tcl</b> or
281 <b class="const">.critcl</b>.</p>
282 <div id="subsection1" class="doctools_subsection"><h3><a name="subsection1">Embedded C Code</a></h3>
283 <p>The following commands append C code fragments to the current module. Fragments
284 appear in the module in the order they are appended, so the earlier fragments
285 (variables, functions, macros, etc.) are visible to later fragments.</p>
286 <dl class="doctools_definitions">
287 <dt><a name="1"><b class="cmd">::critcl::ccode</b> <i class="arg">fragment</i></a></dt>
288 <dd><p>Appends the C code in <i class="arg">fragment</i> to the current module and returns the
289 empty string.
290 See <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span>.</p></dd>
291 <dt><a name="2"><b class="cmd">::critcl::ccommand</b> <i class="arg">tclname</i> <i class="arg">cname</i></a></dt>
292 <dd><p>As documented below, except that <i class="arg">cname</i> is the name of a C function
293 that already exists.</p></dd>
294 <dt><a name="3"><b class="cmd">::critcl::ccommand</b> <i class="arg">tclname</i> <i class="arg">arguments</i> <i class="arg">body</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i>...?</span></a></dt>
295 <dd><p>Appends the code to create a Tcl command named <i class="arg">tclname</i> and a
296 corresponding C function whose body is <i class="arg">body</i> and which behaves as
297 documented for Tcl's own
298 <a href="https://www.tcl-lang.org/man/tcl/TclLib/CrtObjCmd.htm">Tcl_CreateObjCommand</a>.</p>
299 <p><i class="arg">aguments</i> is a list of zero to four names for the standard arguments
300 <b class="const">clientdata</b>, <b class="const">interp</b>, <b class="const">objc</b>, and <b class="const">objv</b>. The
301 standard default names are used in place of any missing names.
302 This is a more low-level way than <b class="cmd">critcl::cproc</b> to define a command, as
303 processing of the items in <b class="const">objv</b> is left to the author, affording
304 complete control over the handling of the arguments to the command.
305 See section <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span>.</p>
306 <p>Returns the empty string.</p>
307 <p>Each <i class="arg">option</i> may be one of:</p>
308 <dl class="doctools_options">
309 <dt><b class="option">-clientdata</b> <i class="arg">c-expression</i></dt>
310 <dd><p>Provides the client data for the new command. <b class="const">NULL</b> by default.</p></dd>
311 <dt><b class="option">-delproc</b> <i class="arg">c-expression</i></dt>
312 <dd><p>Provides a function pointer of type <a href="https://www.tcl-lang.org/man/tcl/TclLib/CrtObjCmd.htm">Tcl_CmdDeleteProc</a> as the deletion function for the new command. <b class="const">NULL</b> by default.</p></dd>
313 <dt><b class="option">-cname</b> <i class="arg">boolean</i></dt>
314 <dd><p>If <b class="const">false</b> (the default), a name for the corresponding C function is
315 automatically derived from the fully-qualified <i class="arg">tclname</i>. Otherwise, name
316 of the C function is the last component of <i class="arg">tclname</i>.</p></dd>
317 </dl></dd>
318 <dt><a name="4"><b class="cmd">::critcl::cdata</b> <i class="arg">tclname</i> <i class="arg">data</i></a></dt>
319 <dd><p>Appends the code to create a new Tcl command named <i class="arg">tclname</i> which returns
320 <i class="arg">data</i> as a <b class="const">ByteArray</b> result.</p>
321 <p>Returns the empty string.</p></dd>
322 <dt><a name="5"><b class="cmd">::critcl::cconst</b> <i class="arg">tclname</i> <i class="arg">resulttype</i> <i class="arg">value</i></a></dt>
323 <dd><p>Appends the code to create a new Tcl command named <i class="arg">tclname</i> which returns
324 the constant <i class="arg">value</i> having the Tcl type <i class="arg">resulttype</i>. <i class="arg">value</i> can
325 be a C macro or a function <em>call</em> (including the parentheses) to any
326 visible C function that does not take arguments.
327 Unlike <b class="cmd">critcl::cdata</b>, <i class="arg">resulttype</i> can be any type known to
328 <b class="cmd">critcl::cproc</b>.
329 Its semantics are equivalent to:</p>
330 <pre class="doctools_example">
331 cproc $tclname {} $resulttype &quot;return $value ;&quot;
332 </pre>
333 <p>This is more efficient than <b class="cmd">critcl::cproc</b> since there is no
334 C function generated.</p>
335 <p>Returns the empty string.</p></dd>
336 <dt><a name="6"><b class="cmd">::critcl::cdefines</b> <i class="arg">list of glob patterns</i> <span class="opt">?<i class="arg">namespace</i>?</span></a></dt>
337 <dd><p>Arranges for <i class="term">C enum</i> and <i class="term">#define</i> values that match one of the
338 patterns in <i class="term">glob patterns</i> to be created in the namespace
339 <i class="arg">namespace</i>, each variable having the same as the corresponding C item.
340 The default namespace is the global namespace. A pattern that matches nothing
341 is ignored.</p>
342 <p>The Tcl variables are created when the module is compiled, using the
343 preprocessor in order to properly find all matching C definitions.</p>
344 <p>Produces no C code. The desired C definitions must already exist.</p></dd>
345 <dt><a name="7"><b class="cmd">::critcl::cproc</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">resulttype</i> <i class="arg">body</i> <span class="opt">?<i class="arg">option</i> <i class="arg">value</i>...?</span></a></dt>
346 <dd><p>Appends a function having <i class="arg">body</i> as its body, another shim function to
347 perform the needed conversions, and the code to create a corresponding Tcl
348 command named <i class="arg">tclname</i>. Unlike <b class="cmd">critcl::ccommand</b> the arguments and
349 result are typed, and CriTcl generates the code to convert between Tcl_Obj
350 values and C data types.
351 See also <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span>.</p>
352 <p>Returns the empty string.</p>
353 <dl class="doctools_arguments">
354 <dt>string <i class="arg">option</i></dt>
355 <dd><p>Each may be one of:</p>
356 <dl class="doctools_options">
357 <dt><b class="option">-cname</b> <i class="arg">boolean</i></dt>
358 <dd><p>If <b class="const">false</b> (the default), a name for the corresponding C function is
359 automatically derived from the fully-qualified <i class="arg">tclname</i>. Otherwise, name
360 of the C function is the last component of <i class="arg">tclname</i>.</p></dd>
361 <dt><b class="option">-pass-cdata</b> <i class="arg">boolean</i></dt>
362 <dd><p>If <b class="const">false</b> (the default), the shim function performing the conversion to
363 and from Tcl level does not pass the ClientData as the first argument to
364 the function.</p></dd>
365 <dt><b class="option">-arg-offset</b> <i class="arg">int</i></dt>
366 <dd><p>A non-negative integer, <b class="const">0</b> by default, indicating the number of hidden
367 arguments preceding the actual procedure arguments. Used by higher-order code
368 generators where there are prefix arguments which are not directly seen by the
369 function but which influence argument counting and extraction.</p></dd>
370 </dl></dd>
371 <dt>string <i class="arg">resulttype</i></dt>
372 <dd><p>May be a predefined or a custom type.
373 See <i class="term"><a href="critcl_cproc.html">CriTcl cproc Type Reference</a></i> for the full list of predefined types and how to
374 extend them.
375 Unless otherwise noted, the Tcl return code is always <b class="const">TCL_OK</b>.</p></dd>
376 <dt>list <i class="arg">arguments</i></dt>
377 <dd><p>Is a multi-dictionary where each key is an
378 argument type and its value is the argument name.
379 For example:</p>
380 <pre class="doctools_example"> int x int y </pre>
381 <p>Each argument name must be a valid C identifier.</p>
382 <p>If the name is a list containing two items, the first item is the name
383 and the second item is the default value. A limited form of variadic arguments
384 can be accomplished using such default values.
385 For example:</p>
386 <pre class="doctools_example"> int {x 1} </pre>
387 <p>Here <i class="arg">x</i> is an optional argument of type <b class="type">int</b> with a default
388 value of <b class="const">1</b>.</p>
389 <p>Argument conversion is completely bypassed when the argument is not
390 provided, so a custom converter doing validation does not get the chance to
391 validate the default value. In this case, the value should be checked in the
392 body of the function.</p>
393 <p>Each argument type may be a predefined or custom type.
394 See <i class="term"><a href="critcl_cproc.html">CriTcl cproc Type Reference</a></i> for the full list of predefined types and how to
395 extend them.</p></dd>
396 </dl></dd>
397 <dt><a name="8"><b class="cmd">::critcl::cproc</b> <i class="arg">name</i> <i class="arg">arguments</i> <i class="arg">resulttype</i></a></dt>
398 <dd><p>As documented below, but used when the C function named <i class="arg">name</i> already
399 exists.</p></dd>
400 <dt><a name="9"><b class="cmd">::critcl::cinit</b> <i class="arg">text</i> <i class="arg">externals</i></a></dt>
401 <dd><p>Appends the C code in <i class="arg">text</i> and <i class="arg">externals</i>, but only after all the
402 other fragments appended by the previously-listed commands regardless of their
403 placement in the <i class="term">CriTcl script</i> relative to this command. Thus, all
404 their content is visible. See also <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span>.</p>
405 <p>The C code in <i class="arg">text</i> is placed into the body of the initialization
406 function of the shared library backing the <i class="term">CriTcl script</i>, and is
407 executed when this library is loaded into the interpreter. It has access to
408 the variable <b class="variable">Tcl_Interp* interp</b> referencing the Tcl interpreter currently
409 being initialized.</p>
410 <p><i class="arg">externals</i> is placed outside and just before the initialization
411 function, making it a good place for any external symbols required by
412 initialization function, but which should not be accessible by any other parts
413 of the C code.</p>
414 <p>Calls to this command are cumulative.</p>
415 <p>Returns the empty string.</p></dd>
416 <dt><a name="10"><b class="cmd">::critcl::include</b> <i class="arg">path</i></a></dt>
417 <dd><p>This command is a convenient shorthand for</p>
418 <pre class="doctools_example">
419 critcl::code {
420 #include &lt;${path}&gt;
421 }
422 </pre>
423 </dd>
424 </dl>
425 </div>
426 <div id="subsection2" class="doctools_subsection"><h3><a name="subsection2">Stubs Table Management</a></h3>
427 <p>CriTcl versions 3 and later provide <b class="cmd">critcl::api</b> to create and manipulate
428 stubs tables, Tcl's dynamic linking mechanism handling the resolution of
429 symbols between C extensions.
430 See <a href="http://wiki.tcl-lang.org/285">http://wiki.tcl-lang.org/285</a>
431 for an introduction, and section <span class="sectref"><a href="#subsection21">Stubs Tables</a></span>
432 for the details of CriTcl's particular variant.</p>
433 <p>Importing stubs tables, i.e. APIs, from another extension:</p>
434 <dl class="doctools_definitions">
435 <dt><a name="11"><b class="cmd">::critcl::api</b> <b class="method">import</b> <i class="arg">name</i> <i class="arg">version</i></a></dt>
436 <dd><p>Adds the following include directives into the <i class="term">CriTcl script</i>
437 <em>and</em> each of its companion &quot;<b class="file">.c</b>&quot; files:</p>
438 <ol class="doctools_enumerated">
439 <li><p>#include &lt;<b class="variable">name</b>/<b class="variable">name</b>Decls.h&gt;</p></li>
440 <li><p>#include &lt;<b class="variable">name</b>/<b class="variable">name</b>StubLib.h&gt;</p></li>
441 </ol>
442 <p>Returns an error if &quot;<b class="file"><b class="variable">name</b></b>&quot; isn't in the search path for the
443 compiler. See <b class="cmd">critcl::cheaders</b> and the critcl application's <b class="option">-I</b>
444 and <b class="option">-includedir</b> options.</p>
445 <p><em>Important:</em> If <b class="variable">name</b> is a fully-qualified name in a
446 non-global namespace, e.g.
447 &quot;c::stack&quot;, the namespace separators &quot;::&quot; are converted into underscores
448 (&quot;_&quot;) in path names, C code, etc.</p>
449 <p><b class="variable">name</b>/<b class="variable">name</b>Decls.h contains the stubs table type declarations,
450 mapping macros, etc., and may include package-specific headers. See
451 <b class="cmd">critcl::api header</b>, below. An <i class="term">#include</i> directive is added at
452 the beginning of the generated code for <i class="term">CriTcl script</i> and at the
453 beginning of each of its companion &quot;<b class="file">.c</b>&quot; files.</p>
454 <p><b class="variable">name</b>/<b class="variable">name</b>StubLib.h contains the stubs table variable
455 definition and the function to initialize it. An <i class="term">#include</i> directive
456 for it is added to the initialization code for the <i class="term">CriTcl script</i> ,
457 along with a call to the initializer function.</p>
458 <p>If &quot;<b class="file"><b class="variable">name</b>/<b class="variable">name</b>.decls</b>&quot; accompanies
459 <b class="variable">name</b>/<b class="variable">name</b>Decls.h, it should contain the external representation of
460 the stubs table used to generate the headers. The file is read and the internal
461 representation of the stubs table returned for use by the importing package.
462 Otherwise, the empy string is returned.</p>
463 <p>One possible use would be the automatic generation of C code
464 calling on the functions listed in the imported API.</p>
465 <p>When generating a TEA package the names of the imported APIs
466 are used to declare <b class="syscmd">configure</b> options with which the user can
467 declare a non-standard directory for the headers of the API. Any API
468 <b class="variable">name</b> is translated into a single configure option
469 <b class="option">--with-<b class="variable">name</b>-include</b>.</p></dd>
470 </dl>
471 <p>Declaration and export of a stubs table, i.e. API, for
472 the <i class="term">CriTcl script</i>:</p>
473 <dl class="doctools_definitions">
474 <dt><a name="12"><b class="cmd">::critcl::api</b> <b class="method">function</b> <i class="arg">resulttype</i> <i class="arg">name</i> <i class="arg">arguments</i></a></dt>
475 <dd><p>Adds to the public API of the <i class="term">CriTcl script</i> the signature
476 for the function named <i class="arg">name</i> and having the signature specified by
477 <i class="arg">arguments</i> and <i class="arg">resulttype</i>. Code is generated for a &quot;<b class="file">.decls</b>&quot;
478 file, the corresponding public headers, and a stubs table usable by
479 <b class="cmd">critcl::api import</b>.</p>
480 <p><i class="arg">arguments</i> is a multidict where each key is an argument type and its
481 value is the argument name, and <i class="arg">resulttype</i> is a C type.</p></dd>
482 <dt><a name="13"><b class="cmd">::critcl::api</b> <b class="method">header</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></dt>
483 <dd><p>Each file matching a <i class="arg">glob pattern</i> is copied into the directory
484 containing the generated headers, and an <i class="term">#include</i> directive for it is
485 added to &quot;<b class="file">Decls.h</b>&quot; for the <i class="term">CriTcl script</i>.
486 Returns an error if a <i class="arg">glob pattern</i> matches nothing.</p>
487 <p>A pattern for a relative path is resolved relative to the directory
488 containing the <i class="term">CriTcl script</i>.</p></dd>
489 <dt><a name="14"><b class="cmd">::critcl::api</b> <b class="method">extheader</b> <span class="opt">?<i class="arg">file</i>...?</span></a></dt>
490 <dd><p>Like <b class="cmd">::critcl::api header</b>, but each <i class="arg">file</i> should exist in the
491 external development environment. An <i class="term">#include</i> directive is added to
492 &quot;<b class="file"><b class="variable">foo</b>Decls.h</b>&quot;, but <i class="arg">file</i> is not copied to the package header
493 directory. <i class="arg">file</i> is not a glob pattern as CriTcl has no context,
494 i.e directory, in which to expand such patterns.</p></dd>
495 </dl>
496 <p>As with the headers for an imported API, an <i class="term">#include</i> directive is
497 added to the generated code for the <i class="term">CriTcl script</i> and to
498 each companion &quot;<b class="file">.c</b>&quot; file.</p>
499 <p>In &quot;compile &amp; run&quot; mode the generated header files and any companion
500 headers are placed in the <span class="sectref"><a href="#subsection18">Result Cache</a></span> subdirectory for the
501 <i class="term">CriTcl script</i>. This directory is added to the include search path of
502 any other package importing this API and and building in mode &quot;compile &amp; run&quot;.</p>
503 <p>In &quot;generate package&quot; mode <b class="option">-includedir</b> specifies the
504 subdirectory in the package to place the generated headers in. This
505 directory is added to the search paths for header files, ensuring that a
506 package importing an API finds it if the package exporting that API used the
507 same setting for <b class="option">-includedir</b>.</p>
508 <p>In &quot;generate TEA&quot; mode the static scanner recognizes
509 <b class="cmd">critcl::api header</b> as a source of companion files.
510 It also uses data from calls to <b class="cmd">critcl::api import</b> to
511 add support for <b class="option">--with-<b class="variable">foo</b>-include</b> options into the
512 generated &quot;<b class="file">configure(.in)</b>&quot; so that a user may specify custom
513 locations for the headers of any imported API.</p>
514 </div>
515 <div id="subsection3" class="doctools_subsection"><h3><a name="subsection3">Package Meta Data</a></h3>
516 <p>CriTcl versions 3 and later can create TEApot meta-data to be placed into
517 &quot;<b class="file">teapot.txt</b>&quot; in a format suitable for use by the
518 <a href="http://docs.activestate.com/activetcl/8.5/tpm/toc.html">TEApot tools</a>.</p>
519 <p>In version 2, some meta data support was already present through
520 <b class="cmd">::critcl::license</b>, but this was only used to generate &quot;<b class="file">license.txt</b>&quot;.</p>
521 <dl class="doctools_definitions">
522 <dt><a name="15"><b class="cmd">::critcl::license</b> <i class="arg">author</i> <span class="opt">?<i class="arg">text</i>...?</span></a></dt>
523 <dd><p>Ignored in &quot;compile &amp; run&quot; mode.</p>
524 <p>In &quot;generate package&quot; mode provides information about the author of the
525 package and the license for the package.</p>
526 <p><i class="arg">text</i> arguments are concatenated to form the text of the license, which is
527 written to &quot;<b class="file">license.terms</b>&quot; in the same directory as &quot;<b class="file">pkgIndex.tcl</b>&quot;.
528 If no <i class="arg">text</i> is provided the license is read from &quot;<b class="file">license.terms</b>&quot;
529 in the same directory as the <i class="term">CriTcl script</i>.</p>
530 <p>This information takes precedence over any information specified through
531 the generic API <b class="cmd">::critcl::meta</b>. It is additionally placed
532 into the meta data file &quot;<b class="file">teapot.txt</b>&quot; under the keys <i class="term">as::author</i> and
533 <i class="term">license</i>.</p></dd>
534 <dt><a name="16"><b class="cmd">::critcl::summary</b> <i class="arg">text</i></a></dt>
535 <dd><p>Ignored in &quot;compile &amp; run&quot; mode.</p>
536 <p>In &quot;generate package&quot; mode places a short, preferably one-line description of
537 the package into the meta data file &quot;<b class="file">teapot.txt</b>&quot; under the key
538 <i class="term">summary</i>. This information takes precedence over information specified
539 through the generic API <b class="cmd">::critcl::meta</b>.</p></dd>
540 <dt><a name="17"><b class="cmd">::critcl::description</b> <i class="arg">text</i></a></dt>
541 <dd><p>Ignored in &quot;compile &amp; run&quot; mode.</p>
542 <p>In &quot;generate package&quot; mode places a longer description of the package into the
543 meta data file &quot;<b class="file">teapot.txt</b>&quot;, under the key <i class="term">description</i>. The data
544 specified by this command takes precedence over any information specified
545 through the generic API <b class="cmd">::critcl::meta</b>.</p></dd>
546 <dt><a name="18"><b class="cmd">::critcl::subject</b> <span class="opt">?<i class="arg">key</i>...?</span></a></dt>
547 <dd><p>Ignored in &quot;compile &amp; run&quot; mode.</p>
548 <p>In &quot;generate package&quot; mode places each <i class="arg">key</i> into the meta data file
549 &quot;<b class="file">teapot.txt</b>&quot;, under the key <i class="term">subject</i>. This information takes
550 precedence over any information specified through the generic API
551 <b class="cmd">::critcl::meta</b>.</p>
552 <p>Calls to this command are cumulative.</p></dd>
553 <dt><a name="19"><b class="cmd">::critcl::meta</b> <i class="arg">key</i> <span class="opt">?<i class="arg">word</i>...?</span></a></dt>
554 <dd><p>Provides arbitrary meta data outside of the following reserved keys:
555 <i class="term">as::author</i>,
556 <i class="term">as::build::date</i>,
557 <i class="term">description</i>,
558 <i class="term">license</i>,
559 <i class="term">name</i>,
560 <i class="term">platform</i>,
561 <i class="term">require</i>
562 <i class="term">subject</i>,
563 <i class="term">summary</i>, and
564 <i class="term">version</i>,
565 Its behaviour is like <b class="cmd">::critcl::subject</b> in that it treats all
566 keys as list of words, with each call providing one or more words for
567 the key, and multiple calls extending the data for an existing key, if
568 not reserved.</p>
569 <p>While it is possible to declare information for one of the
570 reserved keys with this command such data is ignored when the final
571 meta data is assembled and written.</p>
572 <p>Use the commands
573 <b class="cmd">::critcl::license</b>,
574 <b class="cmd">::critcl::summary</b>,
575 <b class="cmd">::critcl::description</b>
576 <b class="cmd">::critcl::subject</b>,
577 <b class="cmd">package require</b>, and
578 <b class="cmd">package provide</b>
579 to declare data for the reserved keys.</p>
580 <p>The information for the reserved keys
581 <i class="term">as::build::date</i> and
582 <i class="term">platform</i>
583 is automatically generated by <b class="package"><a href="critcl.html">critcl</a></b> itself.</p></dd>
584 <dt><a name="20"><b class="cmd">::critcl::meta?</b> <i class="arg">key</i></a></dt>
585 <dd><p>Returns the value in the metadata associated with <i class="arg">key</i>.</p>
586 <p>Used primarily to retrieve the name of the package
587 from within utility packages having to adapt C code templates to their
588 environment. For example, <b class="package"><a href="critcl_class.html">critcl::class</a></b> uses does this.</p></dd>
589 <dt><a name="21"><b class="cmd">::critcl::buildrequirement</b> <i class="arg">script</i></a></dt>
590 <dd><p>Provides control over the capturing of dependencies declared via
591 <b class="cmd">package require</b>. <i class="arg">script</i> is evaluated and any dependencies
592 declared within are ignored, i.e. not recorded in the meta data.</p></dd>
593 </dl>
594 </div>
595 <div id="subsection4" class="doctools_subsection"><h3><a name="subsection4">Control &amp; Interface</a></h3>
596 <p>These commands control the details of compilation and linking a
597 <i class="term">CriTcl script</i>. The information is used only to compile/link the
598 object for the <i class="term">CriTcl script</i>. For example, information for
599 &quot;<b class="file">FOO.tcl</b>&quot; is kept separate from information for &quot;<b class="file">BAR.tcl</b>&quot;.</p>
600 <dl class="doctools_definitions">
601 <dt><a name="22"><b class="cmd">::critcl::cheaders</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></dt>
602 <dd><p>Provides additional header locations.</p>
603 <p>Each argument is a glob pattern. If an argument begins with <b class="const">-</b>
604 it is an argument to the compiler. Otherwise the parent directory of each
605 matching path is a directory to be searched for header files. Returns an
606 error if a pattern matches no files.
607 A pattern for a relative path is resolved relative to the directory
608 containing the <i class="term">CriTcl script</i>.</p>
609 <p><b class="const">#include</b> lines are not automatically generated for matching
610 header files. Use <b class="cmd">critcl::include</b> or <b class="cmd">critcl::ccode</b> as necessary to
611 add them.</p>
612 <p>Calls to this command are cumulative.</p></dd>
613 <dt><a name="23"><b class="cmd">::critcl::csources</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></dt>
614 <dd><p>Matching paths become inputs to the compilation of the current object
615 along with the sources for the current <i class="term">CriTcl script</i>. Returns an
616 error if no paths match a pattern.
617 A pattern for a relative path is resolved relative to the directory
618 containing the <i class="term">CriTcl script</i>.</p>
619 <p>Calls to this command are cumulative.</p></dd>
620 <dt><a name="24"><b class="cmd">::critcl::clibraries</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></dt>
621 <dd><p>provides the link step with additional libraries and library locations.
622 A <i class="arg">glob pattern</i> that begins with <b class="const">-</b> is added as an argument to
623 the linker. Otherwise matching files are linked into the shared library.
624 Returns an error if no paths match a pattern.
625 A pattern for a relative path is resolved relative to the directory
626 containing the <i class="term">CriTcl script</i>.</p>
627 <p>Calls to this command are cumulative.</p></dd>
628 <dt><a name="25"><b class="cmd">::critcl::source</b> <i class="arg">glob pattern</i></a></dt>
629 <dd><p>Evaluates as scripts the files matching each <i class="arg">glob pattern</i>. Returns an
630 error if there are no matching files.
631 A pattern for a relative path is resolved relative to the directory
632 containing the <i class="term">CriTcl script</i>.</p></dd>
633 <dt><a name="26"><b class="cmd">::critcl::tsources</b> <i class="arg">glob pattern</i>...</a></dt>
634 <dd><p>Provides the information about additional Tcl script files to source when the
635 shared library is loaded.</p>
636 <p>Matching paths are made available to the generated shared library when
637 it is loaded for the current <i class="term">CriTcl script</i>. Returns an error if a
638 pattern matches no files.
639 A pattern for a relative path is resolved relative to the directory
640 containing the <i class="term">CriTcl script</i>.</p>
641 <p>Calls to this command are cumulative.</p>
642 <p>After the shared library has been loaded, the declared files are sourced
643 in the same order that they were provided as arguments.</p></dd>
644 <dt><a name="27"><b class="cmd">::critcl::owns</b> <i class="arg">glob pattern</i>...</a></dt>
645 <dd><p>Ignored in &quot;compile and run&quot; and &quot;generate package&quot; modes.
646 In &quot;generate TEA&quot; mode each file matching a <i class="arg">glob pattern</i> is a file to
647 be included in the TEA extension but that could not be ascertained as such from
648 previous commands like <b class="cmd">critcl::csources</b> and <b class="cmd">critcl::tsources</b>,
649 either because of they were specified dynamically or because they were directly
650 sourced.</p></dd>
651 <dt><a name="28"><b class="cmd">::critcl::cflags</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></dt>
652 <dd><p>Each <i class="arg">arg</i> is an argument to the compiler.</p>
653 <p>Calls to this command are cumulative.</p></dd>
654 <dt><a name="29"><b class="cmd">::critcl::ldflags</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></dt>
655 <dd><p>Each <i class="arg">arg</i> is an argument to the linker.</p>
656 <p>Calls to this command are cumulative.</p></dd>
657 <dt><a name="30"><b class="cmd">::critcl::framework</b> <span class="opt">?<i class="arg">arg</i>...?</span></a></dt>
658 <dd><p>Each <i class="arg">arg</i> is the name of a framework to link on MacOS X. This command is
659 ignored if OS X is not the target so that frameworks can be specified
660 unconditionally.</p>
661 <p>Calls to this command are cumulative.</p></dd>
662 <dt><a name="31"><b class="cmd">::critcl::tcl</b> <i class="arg">version</i></a></dt>
663 <dd><p>Specifies the minimum version of the Tcl runtime
664 to compile and link the package for. The default is <b class="const">8.4</b>.</p></dd>
665 <dt><a name="32"><b class="cmd">::critcl::tk</b></a></dt>
666 <dd><p>Arranges to include the Tk headers and link to the Tk stubs.</p></dd>
667 <dt><a name="33"><b class="cmd">::critcl::preload</b> <i class="arg">lib</i>...</a></dt>
668 <dd><p>Arranges for the external shared library <i class="arg">lib</i> to be loaded
669 before the shared library for the <i class="term">CriTcl script</i> is loaded.</p>
670 <p>Calls to this command are cumulative.</p>
671 <p>Each library <i class="arg">FOO</i> is searched for in the directories listed below, in the order
672 listed. The search stops at the first existing path.
673 Additional notes:</p>
674 <ul class="doctools_itemized">
675 <li><p><b class="variable">platform</b> is the placeholder for the target platform of the package.</p></li>
676 <li><p>The extension &quot;<b class="file">.so</b>&quot; is the placeholder for whatever actual extension is used by the target platform for its shared libraries.</p></li>
677 <li><p>The search is relative to the current working directory.</p></li>
678 </ul>
679 <p>And now the paths, depending on the exact form of the library name:</p>
680 <dl class="doctools_definitions">
681 <dt>FOO</dt>
682 <dd><ol class="doctools_enumerated">
683 <li><p>FOO.so</p></li>
684 <li><p>FOO/FOO.so</p></li>
685 <li><p>FOO/<b class="variable">platform</b>/FOO.so</p></li>
686 </ol></dd>
687 <dt>PATH/FOO</dt>
688 <dd><p>The exact set searched depends on the existence of
689 directory &quot;<b class="file">PATH/FOO</b>&quot;. If it exists, critcl searches</p>
690 <ol class="doctools_enumerated">
691 <li><p>FOO.so</p></li>
692 <li><p>PATH/FOO/FOO.so</p></li>
693 <li><p>PATH/FOO/<b class="variable">platform</b>/FOO.so</p></li>
694 </ol>
695 <p>Otherwise it searches</p>
696 <ol class="doctools_enumerated">
697 <li><p>FOO.so</p></li>
698 <li><p>PATH/FOO.so</p></li>
699 <li><p>PATH/<b class="variable">platform</b>/FOO.so</p></li>
700 </ol>
701 <p>instead.</p></dd>
702 <dt>/PATH/FOO</dt>
703 <dd><p>Even when specifying FOO with an absolute path the first path searched
704 is relative to the current working directory.</p>
705 <ol class="doctools_enumerated">
706 <li><p>FOO.so</p></li>
707 <li><p>/PATH/FOO.so</p></li>
708 <li><p>/PATH/<b class="variable">platform</b>/FOO.so</p></li>
709 </ol></dd>
710 </dl>
711 <p>For developers who want to understand or modify the internals of the
712 <b class="package"><a href="critcl.html">critcl</a></b> package, <span class="sectref"><a href="#subsection19">Preloading functionality</a></span> explains how
713 preloading is implemented.</p></dd>
714 <dt><a name="34"><b class="cmd">::critcl::debug</b> <i class="arg">area</i>...</a></dt>
715 <dd><p>Specifies what debugging features to activate. Internally each area is translated into
716 area-specific flags for the compiler which are then handed over to
717 <b class="cmd">critcl::cflags</b>.</p>
718 <dl class="doctools_definitions">
719 <dt><b class="const">memory</b></dt>
720 <dd><p>Specifies Tcl memory debugging.</p></dd>
721 <dt><b class="const">symbols</b></dt>
722 <dd><p>Specifies compilation and linking with debugging symbols for use by a debugger
723 or other tool.</p></dd>
724 <dt><b class="const">all</b></dt>
725 <dd><p>Specifies all available debugging.</p></dd>
726 </dl></dd>
727 </dl>
728 </div>
729 <div id="subsection5" class="doctools_subsection"><h3><a name="subsection5">Introspection</a></h3>
730 <p>The following commands control compilation and linking.</p>
731 <dl class="doctools_definitions">
732 <dt><a name="35"><b class="cmd">::critcl::check</b> <span class="opt">?<i class="arg">label</i>?</span> <i class="arg">text</i></a></dt>
733 <dd><p>Returns a <b class="const">true</b> if the C code in <i class="arg">text</i> compiles sucessfully, and
734 <b class="const">false</b> otherwise. Used to check for availability of features in the
735 build environment.
736 If provided, <i class="arg">label</i> is used to uniquely mark the results in the generated
737 log.</p></dd>
738 <dt><a name="36"><b class="cmd">::critcl::checklink</b> <span class="opt">?<i class="arg">label</i>?</span> <i class="arg">text</i></a></dt>
739 <dd><p>Like <b class="cmd">critcl::check</b> but also links the compiled objects, returning
740 <b class="const">true</b> if the link is successful and <b class="const">false</b> otherwise.
741 If specified, <i class="arg">label</i> is used to uniquely mark the results in the generated
742 log.</p></dd>
743 <dt><a name="37"><b class="cmd">::critcl::msg</b> <span class="opt">?<b class="option">-nonewline</b>?</span> <i class="arg">msg</i></a></dt>
744 <dd><p>Scripts using <b class="cmd">critcl::check</b> and <b class="cmd">critcl::checklink</b> can use this
745 command to report results. Does nothing in <i class="term"><a href="../index.html#compile_run">compile &amp; run</a></i> mode. Tools
746 like the <i class="term">CriTcl Aplication</i> may redefine this command to implement
747 their own message reporting. For example, <b class="package">critcl::app</b> and any
748 packages built on it print messages to <i class="term">stdout</i>.</p></dd>
749 <dt><a name="38"><b class="cmd">::critcl::print</b> <span class="opt">?<b class="option">-nonewline</b>?</span> <span class="opt">?<i class="arg">chan</i>?</span> <i class="arg">msg</i></a></dt>
750 <dd><p>Used by the CriTcl internals to report activity. By default, effectively the
751 same thing as <b class="cmd">::puts</b>. Tools directly using either the CriTcl package or
752 the CriTcl application package may redefine this procedure to implement their
753 own output functionality.</p>
754 <p>For example, the newest revisions of
755 <a href="https://chiselapp.com/user/andreas_kupries/repository/Kettle/index">Kettle</a>
756 use this to highlight build warnings.</p></dd>
757 <dt><a name="39"><b class="cmd">::critcl::compiled</b></a></dt>
758 <dd><p>Returns <b class="const">true</b> if the current <i class="term">CriTcl script</i> is already compiled
759 and <b class="const">false</b> otherwise.</p>
760 <p>Enables a <i class="term">CriTcl script</i> used as its own Tcl companion file (see
761 <b class="cmd">critcl::tsources</b>) to distinguish between being sourced for compilation in
762 <i class="term"><a href="../index.html#compile_run">compile &amp; run</a></i> mode and being sourced from either the result of
763 <i class="term"><a href="../index.html#generate_package">generate package</a></i> mode or during the load phase of
764 <i class="term"><a href="../index.html#compile_run">compile &amp; run</a></i> mode.
765 The result is <b class="const">false</b> in the first case and <b class="const">true</b> in the later two
766 cases.</p></dd>
767 <dt><a name="40"><b class="cmd">::critcl::compiling</b></a></dt>
768 <dd><p>Returns <b class="const">true</b> if a working C compiler is available and <b class="const">false</b>
769 otherwise.</p></dd>
770 <dt><a name="41"><b class="cmd">::critcl::done</b></a></dt>
771 <dd><p>Returns <b class="const">true</b> when <i class="term">CriTcl script</i> has been built and
772 <b class="const">false</b> otherwise. Only useful from within a <i class="term">CriTcl script</i>.
773 Enables the Tcl parts of a <i class="term">CriTcl script</i> to distinguish between
774 <i class="term">prebuilt package</i> mode and <i class="term"><a href="../index.html#compile_run">compile &amp; run</a></i> mode.</p>
775 <p>See also <span class="sectref"><a href="#subsection15">Modes Of Operation/Use</a></span>.</p></dd>
776 <dt><a name="42"><b class="cmd">::critcl::failed</b></a></dt>
777 <dd><p>Returns <b class="const">true</b> if the <i class="term">CriTcl script</i> could not be built, and
778 <b class="const">false</b> otherwise. Forces the building of the package if it hasn't
779 already been done, but not its loading. Thus, a <i class="term">CriTcl script</i> can
780 check itself for availability of the compiled components. Only useful from
781 within a <i class="term">CriTcl script</i>.</p></dd>
782 <dt><a name="43"><b class="cmd">::critcl::load</b></a></dt>
783 <dd><p>Like <b class="cmd">critcl::failed</b> except that it also forces the loading of the
784 generated shared library, and that it returns <b class="const">true</b> on success and
785 <b class="const">false</b> on failure. Thus, a <i class="term">CriTcl script</i> can check itself for
786 availability of the compiled components. Only useful from within a
787 <i class="term">CriTcl script</i>.</p></dd>
788 </dl>
789 </div>
790 <div id="subsection6" class="doctools_subsection"><h3><a name="subsection6">Build Management</a></h3>
791 <p>The following command manages global settings, i.e. configuration options which
792 are independent of any <i class="term">CriTcl script</i>.</p>
793 <p>This command should not be needed to write a <i class="term">CriTcl script</i>. It is
794 a management command which is only useful to the <i class="term">CriTcl Application</i>
795 or similar tools.</p>
796 <dl class="doctools_definitions">
797 <dt><a name="44"><b class="cmd">::critcl::config</b> <i class="arg">option</i> <span class="opt">?<i class="arg">val</i>?</span></a></dt>
798 <dd><p>Sets and returns the following global configuration options:</p>
799 <dl class="doctools_options">
800 <dt><b class="option">force</b> bool</dt>
801 <dd><p>When <b class="const">false</b> (the default), the C files are not built if there is a
802 cached shared library.</p></dd>
803 <dt><b class="option">lines</b> bool</dt>
804 <dd><p>When <b class="const">true</b> (the default), #line directives are embedded into the
805 generated C code.</p>
806 <p>This facility requires the use of a tclsh that provides
807 <b class="cmd">info frame</b>. Otherwise, no <i class="term">#line</i> directives are emitted. The
808 command is supported by Tcl 8.5 and higher. It is also supported by
809 Tcl 8.4 provided that it was compiled with the define
810 <b class="option">-DTCL_TIP280</b>. An example of such is ActiveState's ActiveTcl.</p>
811 <p>Developers of higher-level packages generating their own C
812 code, either directly or indirectly through critcl, should
813 also read section <span class="sectref"><a href="#subsection12">Advanced: Location management</a></span> to see how
814 critcl helps them in generating their directives.
815 Examples of such packages come with critcl itself. See
816 <b class="package"><a href="critcl_iassoc.html">critcl::iassoc</a></b> and <b class="package"><a href="critcl_class.html">critcl::class</a></b>.</p></dd>
817 <dt><b class="option">trace</b> bool</dt>
818 <dd><p>When <b class="const">false</b> (the default), no code tracing the entry and exit of
819 CriTcl-backed commands in the <i class="term">CriTcl script</i> is inserted. Insertion of
820 such code implicitly activates the tracing facility in general. See
821 <b class="package"><a href="critcl_cutil.html">critcl::cutil</a></b>.</p></dd>
822 <dt><b class="option">I</b> path</dt>
823 <dd><p>A single global include path to use for all files. Not set by default.</p></dd>
824 <dt><b class="option">combine</b> enum</dt>
825 <dd><dl class="doctools_definitions">
826 <dt><b class="const">dynamic</b> (the default)</dt>
827 <dd><p>Object files have the suffix <b class="const">_pic</b>.</p></dd>
828 <dt><b class="const">static</b></dt>
829 <dd><p>Object files have the suffix <b class="const">_stub</b>.</p></dd>
830 <dt><b class="const">standalone</b></dt>
831 <dd><p>Object files have no suffix, and the generated C files are compiled
832 without using Tcl/Tk stubs. The result are object files usable for
833 static linking into a <i class="term">big shell</i>.</p></dd>
834 </dl></dd>
835 <dt><b class="option">language</b> string</dt>
836 <dd></dd>
837 <dt><b class="option">keepsrc</b> bool</dt>
838 <dd><p>When <b class="const">false</b> (the default), the generated &quot;<b class="file">.c</b>&quot;
839 files are deleted after the &quot;<b class="file">.o</b>&quot; files have been built.</p></dd>
840 <dt><b class="option">outdir</b> directory</dt>
841 <dd><p>The directory where to place a generated shared library. By default, it is
842 placed into the <span class="sectref"><a href="#subsection18">Result Cache</a></span>.</p></dd>
843 </dl></dd>
844 </dl>
845 </div>
846 <div id="subsection7" class="doctools_subsection"><h3><a name="subsection7">Result Cache Management</a></h3>
847 <p>The following commands control the <span class="sectref"><a href="#subsection18">Result Cache</a></span>.
848 These commands are not needed to simply write a <i class="term">CriTcl script</i>.</p>
849 <dl class="doctools_definitions">
850 <dt><a name="45"><b class="cmd">::critcl::cache</b> <span class="opt">?path?</span></a></dt>
851 <dd><p>Sets and returns the path to the directory for the package's result cache.</p>
852 <p>The default location is
853 &quot;<b class="file">~/.critcl/[platform::generic]</b>&quot; and usually does not
854 require any changes.</p></dd>
855 <dt><a name="46"><b class="cmd">::critcl::clean_cache</b> <span class="opt">?<i class="arg">pattern</i>...?</span></a></dt>
856 <dd><p>Cleans the result cache, i.e. removes any and all files
857 and directories in it. If one or more patterns are specified then only
858 the files and directories matching them are removed.</p></dd>
859 </dl>
860 </div>
861 <div id="subsection8" class="doctools_subsection"><h3><a name="subsection8">Build Configuration</a></h3>
862 <p>The following commands manage the build configuration, i.e. the per-platform
863 information about compilers, linkers, and their commandline options.
864 These commands are not needed to simply write a <i class="term">CriTcl script</i>.</p>
865 <dl class="doctools_definitions">
866 <dt><a name="47"><b class="cmd">::critcl::readconfig</b> <i class="arg">path</i></a></dt>
867 <dd><p>Reads the build configuration file at <i class="arg">path</i> and configures the package
868 using the information for the target platform.</p></dd>
869 <dt><a name="48"><b class="cmd">::critcl::showconfig</b> <span class="opt">?<i class="arg">chan</i>?</span></a></dt>
870 <dd><p>Converts the active build configuration into a human-readable string and
871 returns it, or if <i class="arg">chan</i> is provided prints the result to that channel.</p></dd>
872 <dt><a name="49"><b class="cmd">::critcl::showallconfig</b> <span class="opt">?<i class="arg">chan</i>?</span></a></dt>
873 <dd><p>Converts the set of all known build configurations from the currently active
874 build configuration file last set with <b class="cmd">critcl::readconfig</b> into a string
875 and returns it, or if <i class="arg">chan</i> is provided, prints it to that channel.</p></dd>
876 <dt><a name="50"><b class="cmd">::critcl::chooseconfig</b> <i class="arg">target</i> <span class="opt">?<i class="arg">nomatcherr</i>?</span></a></dt>
877 <dd><p>Matches <i class="arg">target</i> against all known targets, returning a list containing
878 all the matching ones. This search is first done on an exact basis, and then
879 via glob matching. If no known target matches the argument the default is to
880 return an empty list. However, if the boolean <i class="arg">nomatcherr</i> is specified and
881 set an error is thrown using <b class="cmd">critcl::error</b> instead.</p></dd>
882 <dt><a name="51"><b class="cmd">::critcl::setconfig</b> <i class="arg">target</i></a></dt>
883 <dd><p>Configures the package to use the settings of <i class="arg">target</i>.</p></dd>
884 </dl>
885 </div>
886 <div id="subsection9" class="doctools_subsection"><h3><a name="subsection9">Tool API</a></h3>
887 <p>The following commands provide tools like
888 <i class="term">CriTcl Application</i> or similar with
889 deeper access to the package's internals.
890 These commands are not needed to simply write a <i class="term">CriTcl script</i>.</p>
891 <dl class="doctools_definitions">
892 <dt><a name="52"><b class="cmd">::critcl::actualtarget</b></a></dt>
893 <dd><p>Returns the platform identifier for the target platform, i.e. the platform to
894 build for. Unlike <b class="cmd">::critcl::targetplatform</b> this is the true target, with
895 any cross-compilation information resolved.</p></dd>
896 <dt><a name="53"><b class="cmd">::critcl::buildforpackage</b> <span class="opt">?<i class="arg">flag</i>?</span></a></dt>
897 <dd><p>Signals whether the next file is to be built for inclusion into a package. If
898 not specified the <i class="arg">flag</i> defaults to <b class="const">true</b>, i.e. building for a
899 package. This disables a number of things in the backend, namely the linking of
900 that file into a shared library and the loading of that library. It is expected
901 that the build results are later wrapped into a larger collection.</p></dd>
902 <dt><a name="54"><b class="cmd">::critcl::cnothingtodo</b> <i class="arg">file</i></a></dt>
903 <dd><p>Checks whether there is anything to build for <i class="arg">file</i>.</p></dd>
904 <dt><a name="55"><b class="cmd">::critcl::cresults</b> <span class="opt">?<i class="arg">file</i>?</span></a></dt>
905 <dd><p>Returns information about building <i class="arg">file</i>, or <b class="cmd">info script</b> If
906 <i class="arg">file</i> is not provided.
907 The result in question is a dictionary containing the following items:</p>
908 <dl class="doctools_definitions">
909 <dt><b class="const">clibraries</b></dt>
910 <dd><p>A list of external shared libraries and/or directories needed to link
911 <i class="arg">file</i>.</p></dd>
912 <dt><b class="const">ldflags</b></dt>
913 <dd><p>A list of linker flags needed to link <i class="arg">file</i>.</p></dd>
914 <dt><b class="const">license</b></dt>
915 <dd><p>The text of the license for the package <i class="arg">file</i> is located in.</p></dd>
916 <dt><b class="const">mintcl</b></dt>
917 <dd><p>The minimum version of Tcl required by the package <i class="arg">file</i>
918 is in to run successfully. A proper Tcl version number.</p></dd>
919 <dt><b class="const">objects</b></dt>
920 <dd><p>A list of object files to link into <i class="arg">file</i>.</p></dd>
921 <dt><b class="const">preload</b></dt>
922 <dd><p>A list of libraries to be preloaded in order to sucessfully load and use
923 <i class="arg">file</i>.</p></dd>
924 <dt><b class="const">tk</b></dt>
925 <dd><p><b class="const">true</b> if <i class="arg">file</i> requires Tk and <b class="const">false</b> otherwise.</p></dd>
926 <dt><b class="const">tsources</b></dt>
927 <dd><p>A list of companion &quot;<b class="file">.tcl</b>&quot; files to source in order to load and use the
928 <i class="term">CriTcl script</i> <i class="arg">file</i>.</p></dd>
929 <dt><b class="const">log</b></dt>
930 <dd><p>The full build log generated by the compiler/linker, including command
931 line data from critcl, and other things.</p></dd>
932 <dt><b class="const">exl</b></dt>
933 <dd><p>The raw build log generated by the compiler/linker. Contains the output
934 generated by the invoked applications.</p></dd>
935 </dl></dd>
936 <dt><a name="56"><b class="cmd">::critcl::crosscheck</b></a></dt>
937 <dd><p>Determines whether the package is configured for cross-compilation and prints a
938 message to the standard error channel if so.</p></dd>
939 <dt><a name="57"><b class="cmd">::critcl::error</b> <i class="arg">msg</i></a></dt>
940 <dd><p>Used to report internal errors. The default implementation simply returns the
941 error. Tools like the <i class="term">CriTcl Application</i> are allowed to redefine
942 this procedure to perform their own way of error reporting. There is
943 one constraint they are not allowed to change: The procedure must
944 <em>not return</em> to the caller.</p></dd>
945 <dt><a name="58"><b class="cmd">::critcl::knowntargets</b></a></dt>
946 <dd><p>Returns a list of the identifiers of all targets
947 found during the last invocation of <b class="cmd">critcl::readconfig</b>.</p></dd>
948 <dt><a name="59"><b class="cmd">::critcl::sharedlibext</b></a></dt>
949 <dd><p>Returns the file extension for shared libraries on the target platform.</p></dd>
950 <dt><a name="60"><b class="cmd">::critcl::targetconfig</b></a></dt>
951 <dd><p>Returns the identifier of the target to build for, as specified by either the
952 user or the system.</p></dd>
953 <dt><a name="61"><b class="cmd">::critcl::buildplatform</b></a></dt>
954 <dd><p>Returns the identifier of the build platform, i.e. where the package is running
955 on.</p></dd>
956 <dt><a name="62"><b class="cmd">::critcl::targetplatform</b></a></dt>
957 <dd><p>Returns the identifier of the target platform,
958 i.e. the platform to compile for. In contrast to
959 <b class="cmd">::critcl::actualtarget</b> this may be the name of a
960 cross-compilation target.</p></dd>
961 <dt><a name="63"><b class="cmd">::critcl::cobjects</b> <span class="opt">?<i class="arg">glob pattern</i>...?</span></a></dt>
962 <dd><p>Like <b class="cmd">::critcl::clibraries</b>, but instead of matching libraries, each
963 <i class="arg">glob pattern</i> matches object files to be linked into the
964 shared object (at compile time, not runtime). If a <i class="arg">glob pattern</i> matches
965 nothing an error is returned.
966 Not listed in <span class="sectref"><a href="#subsection4">Control &amp; Interface</a></span> because it is of no use to
967 package writers. Only tools like the <i class="term">CriTcl Application</i> need it.</p>
968 <p>A pattern for a relative path is resolved relative to the directory
969 containing the <i class="term">CriTcl script</i>.</p>
970 <p>Calls to this command are cumulative.</p></dd>
971 <dt><a name="64"><b class="cmd">::critcl::scan</b> <i class="arg">path</i></a></dt>
972 <dd><p>The main entry point to CriTcl's static code scanner. Used by tools to
973 implement processing modes like the assembly of a directory hierarchy
974 containing a TEA-lookalike buildystem, etc.</p>
975 <p>Scans <i class="arg">path</i> and returns a dictionary containing the following items:</p>
976 <dl class="doctools_definitions">
977 <dt>version</dt>
978 <dd><p>Package version.</p></dd>
979 <dt>org</dt>
980 <dd><p>Author(ing organization).</p></dd>
981 <dt>files</dt>
982 <dd><p>List of the companion files, relative to the directory of the input
983 file.</p></dd>
984 </dl></dd>
985 <dt><a name="65"><b class="cmd">::critcl::name2c</b> <i class="arg">name</i></a></dt>
986 <dd><p>Given the Tcl-level identifier <i class="arg">name</i>, returns a list containing the
987 following details of its conversion to C:</p>
988 <ul class="doctools_itemized">
989 <li><p>Tcl namespace prefix</p></li>
990 <li><p>C namespace prefix</p></li>
991 <li><p>Tcl base name</p></li>
992 <li><p>C base name</p></li>
993 </ul>
994 <p>For use by utilities that provide Tcl commands without going through
995 standard commands like <b class="cmd">critcl::ccommand</b> or <b class="cmd">critcl::cproc</b>.
996 <b class="package"><a href="critcl_class.html">critcl::class</a></b> does this.</p></dd>
997 </dl>
998 </div>
999 <div id="subsection10" class="doctools_subsection"><h3><a name="subsection10">Advanced: Embedded C Code</a></h3>
1000 <p>For advanced use, the following commands used by <b class="cmd">critcl::cproc</b> itself are
1001 exposed.</p>
1002 <dl class="doctools_definitions">
1003 <dt><a name="66"><b class="cmd">::critcl::argnames</b> <i class="arg">arguments</i></a></dt>
1004 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of the corresponding user-visible names.</p></dd>
1005 <dt><a name="67"><b class="cmd">::critcl::argcnames</b> <i class="arg">arguments</i></a></dt>
1006 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of the corresponding C variable names for the
1007 user-visible names. The names returned here match the names used in the
1008 declarations and code returned by <b class="cmd">::critcl::argvardecls</b> and
1009 <b class="cmd">::critcl::argconversion</b>.</p></dd>
1010 <dt><a name="68"><b class="cmd">::critcl::argcsignature</b> <i class="arg">arguments</i></a></dt>
1011 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of the corresponding C parameter declarations.</p></dd>
1012 <dt><a name="69"><b class="cmd">::critcl::argvardecls</b> <i class="arg">arguments</i></a></dt>
1013 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of the corresponding C variable declarations.
1014 The names used in these declarations match the names returned by
1015 <b class="cmd">::critcl::argcnames</b>.</p></dd>
1016 <dt><a name="70"><b class="cmd">::critcl::argconversion</b> <i class="arg">arguments</i> <span class="opt">?<i class="arg">n</i>?</span></a></dt>
1017 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of C code fragments converting the user visible
1018 arguments found in the declaration from Tcl_Obj* to C types. The names used in
1019 these statements match the names returned by <b class="cmd">::critcl::argcnames</b>.</p>
1020 <p>The generated code assumes that the procedure arguments start
1021 at index <i class="arg">n</i> of the <b class="variable">objv</b> array. The default is <b class="const">1</b>.</p></dd>
1022 <dt><a name="71"><b class="cmd">::critcl::argoptional</b> <i class="arg">arguments</i></a></dt>
1023 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of boolean values indicating which arguments
1024 are optional (<b class="const">true</b>), and which are not (<b class="const">false</b>).</p></dd>
1025 <dt><a name="72"><b class="cmd">::critcl::argdefaults</b> <i class="arg">arguments</i></a></dt>
1026 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list containing the default values for all optional
1027 arguments.</p></dd>
1028 <dt><a name="73"><b class="cmd">::critcl::argsupport</b> <i class="arg">arguments</i></a></dt>
1029 <dd><p>Given an argument declaration as documented for <b class="cmd">critcl::cproc</b>, returns a list of C code fragments needed to define the
1030 necessary supporting types.</p></dd>
1031 </dl>
1032 </div>
1033 <div id="subsection11" class="doctools_subsection"><h3><a name="subsection11">Custom Build Configuration</a></h3>
1034 <p>This package provides one command for the management of
1035 package-specific, i.e. developer-specified custom build configuration
1036 options.</p>
1037 <dl class="doctools_definitions">
1038 <dt><a name="74"><b class="cmd">::critcl::userconfig</b> <b class="method">define</b> <i class="arg">name</i> <i class="arg">description</i> <i class="arg">type</i> <span class="opt">?<i class="arg">default</i>?</span></a></dt>
1039 <dd><p>This command defines custom build configuration option, with
1040 <i class="arg">description</i>, <i class="arg">type</i> and optional <i class="arg">default</i> value.</p>
1041 <p>The type can be either <b class="const">bool</b>, or a list of values.</p>
1042 <ol class="doctools_enumerated">
1043 <li><p>For <b class="const">bool</b> the default value, if specified, must be a
1044 boolean. If it is not specified it defaults to <b class="const">true</b>.</p></li>
1045 <li><p>For a list of values the default value, if specified, must be a
1046 value found in this list. If it is not specified it defaults to the
1047 first value of the list.</p></li>
1048 </ol>
1049 <p>The <i class="arg">description</i> serves as in-code documentation of the
1050 meaning of the option and is otherwise ignored. When generating a TEA
1051 wrapper the description is used for the <b class="syscmd">configure</b> option
1052 derived from the option declared by the command.</p>
1053 <p>A boolean option <b class="variable">FOO</b> are translated into a pair of
1054 configure options, <b class="option">--enable-<b class="variable">FOO</b></b> and
1055 <b class="option">--disable-<b class="variable">FOO</b></b>, whereas an option whose <i class="arg">type</i> is a
1056 list of values is translated into a single configure option
1057 <b class="option">--with-<b class="variable">FOO</b></b>.</p></dd>
1058 <dt><a name="75"><b class="cmd">::critcl::userconfig</b> <b class="method">query</b> <i class="arg">name</i></a></dt>
1059 <dd><p>This command queries the database of custom build configuration option
1060 for the current &quot;<b class="file">.critcl</b>&quot; file and returns the chosen value.
1061 This may be the default if no value was set via
1062 <b class="cmd">::critcl::userconfig set</b>.</p>
1063 <p>It is at this point that definitions and set values are brought
1064 together, with the latter validated against the definition.</p></dd>
1065 <dt><a name="76"><b class="cmd">::critcl::userconfig</b> <b class="method">set</b> <i class="arg">name</i> <i class="arg">value</i></a></dt>
1066 <dd><p>This command is for use by a tool, like the <b class="syscmd"><a href="critcl.html">critcl</a></b> application,
1067 to specify values for custom build configuration options.</p>
1068 <p>At the time this command is used only the association between
1069 option name and value is recorded, and nothing else is done. This
1070 behaviour is necessary as the system may not know if an option of the
1071 specified name exists when the command is invoked, nor its type.</p>
1072 <p>Any and all validation is defered to when the value of an
1073 option is asked for via <b class="cmd">::critcl::userconfig query</b>.</p>
1074 <p>This means that it is possible to set values for any option we
1075 like, and the value will take effect only if such an option is both
1076 defined and used later on.</p></dd>
1077 </dl>
1078 </div>
1079 <div id="subsection12" class="doctools_subsection"><h3><a name="subsection12">Advanced: Location management</a></h3>
1080 <p>First a small introduction for whose asking themselves
1081 'what is location management' ?</p>
1082 <p>By default critcl embeds <i class="term">#line</i> directives into the
1083 generated C code so that any errors, warnings and notes found by the C
1084 compiler during compilation will refer to the &quot;<b class="file">.critcl</b>&quot; file the
1085 faulty code comes from, instead of the generated &quot;<b class="file">.c</b>&quot; file.</p>
1086 <p>This facility requires the use of a tclsh that provides
1087 <b class="cmd">info frame</b>. Otherwise, no <i class="term">#line</i> directives are emitted. The
1088 command is supported by Tcl 8.5 and higher. It is also supported by
1089 Tcl 8.4 provided that it was compiled with the define
1090 <b class="option">-DTCL_TIP280</b>. An example of such is ActiveState's ActiveTcl.</p>
1091 <p>Most users will not care about this feature beyond simply
1092 wanting it to work and getting proper code references when reading
1093 compiler output.</p>
1094 <p>Developers of higher-level packages generating their own C code
1095 however should care about this, to ensure that their generated code
1096 contains proper references as well. Especially as this is key to
1097 separating bugs concerning code generated by the package itself and
1098 bug in the user's code going into the package, if any.</p>
1099 <p>Examples of such packages come with critcl itself, see the
1100 implementation of packages <b class="package"><a href="critcl_iassoc.html">critcl::iassoc</a></b> and
1101 <b class="package"><a href="critcl_class.html">critcl::class</a></b>.</p>
1102 <p>To help such developers eight commands are provided to manage
1103 such <i class="term">location</i> information. These are listed below.</p>
1104 <p>A main concept is that they all operate on a single
1105 <i class="term">stored location</i>, setting, returning and clearing it.
1106 Note that this location information is completely independent of the
1107 generation of <i class="term">#line</i> directives within critcl itself.</p>
1108 <dl class="doctools_definitions">
1109 <dt><a name="77"><b class="cmd">::critcl::at::caller</b></a></dt>
1110 <dd><p>This command stores the location of the caller of the current
1111 procedure as a tuple of file name and linenumber. Any previously
1112 stored location is overwritten.
1113 The result of the command is the empty string.</p></dd>
1114 <dt><a name="78"><b class="cmd">::critcl::at::caller</b> <i class="arg">offset</i></a></dt>
1115 <dd><p>As above, the stored line number is modified by the specified
1116 offset. In essence an implicit call of <b class="cmd">critcl::at::incr</b>.</p></dd>
1117 <dt><a name="79"><b class="cmd">::critcl::at::caller</b> <i class="arg">offset</i> <i class="arg">level</i></a></dt>
1118 <dd><p>As above, but the level the location information is taken from is
1119 modified as well. Level <b class="const">0</b> is the caller, <b class="const">-1</b> its
1120 caller, etc.</p></dd>
1121 <dt><a name="80"><b class="cmd">::critcl::at::here</b></a></dt>
1122 <dd><p>This command stores the current location in the current procedure as a
1123 tuple of file name and linenumber. Any previously stored location is
1124 overwritten.
1125 The result of the command is the empty string.</p>
1126 <p>In terms of <b class="cmd">::critcl::at::caller</b> this is equivalent to</p>
1127 <pre class="doctools_example">
1128 critcl::at::caller 0 1
1129 </pre>
1130 </dd>
1131 <dt><a name="81"><b class="cmd">::critcl::at::get*</b></a></dt>
1132 <dd><p>This command takes the stored location and returns a formatted
1133 <i class="term">#line</i> directive ready for embedding into some C code. The
1134 stored location is left untouched.
1135 Note that the directive contains its own closing newline.</p>
1136 <p>For proper nesting and use it is recommended that such
1137 directives are always added to the beginning of a code fragment. This
1138 way, should deeper layers add their own directives these will come
1139 before ours and thus be inactive. End result is that the outermost
1140 layer generating a directive will 'win', i.e. have its directive
1141 used. As it should be.</p></dd>
1142 <dt><a name="82"><b class="cmd">::critcl::at::get</b></a></dt>
1143 <dd><p>This command is like the above, except that it also clears the stored
1144 location.</p></dd>
1145 <dt><a name="83"><b class="cmd">::critcl::at::=</b> <i class="arg">file</i> <i class="arg">line</i></a></dt>
1146 <dd><p>This command allows the caller to set the stored location to anything
1147 they want, outside of critcl's control.
1148 The result of the command is the empty string.</p></dd>
1149 <dt><a name="84"><b class="cmd">::critcl::at::incr</b> <i class="arg">n</i>...</a></dt>
1150 <dd></dd>
1151 <dt><a name="85"><b class="cmd">::critcl::at::incrt</b> <i class="arg">str</i>...</a></dt>
1152 <dd><p>These commands allow the user to modify the line number of the stored
1153 location, changing it incrementally. The increment is specified as
1154 either a series of integer numbers (<b class="cmd">incr</b>), or a series of
1155 strings to consider (<b class="cmd">incrt</b>). In case of the latter the delta is
1156 the number of lines endings found in the strings.</p></dd>
1157 <dt><a name="86"><b class="cmd">::critcl::at::caller!</b></a></dt>
1158 <dd></dd>
1159 <dt><a name="87"><b class="cmd">::critcl::at::caller!</b> <i class="arg">offset</i></a></dt>
1160 <dd></dd>
1161 <dt><a name="88"><b class="cmd">::critcl::at::caller!</b> <i class="arg">offset</i> <i class="arg">level</i></a></dt>
1162 <dd></dd>
1163 <dt><a name="89"><b class="cmd">::critcl::at::here!</b></a></dt>
1164 <dd><p>These are convenience commands combining <b class="cmd">caller</b> and <b class="cmd">here</b>
1165 with <b class="cmd">get</b>. I.e. they store the location and immediately return it
1166 formatted as proper <i class="term">#line</i> directive. Also note that after their
1167 use the stored location is cleared.</p></dd>
1168 </dl>
1169 </div>
1170 <div id="subsection13" class="doctools_subsection"><h3><a name="subsection13">Advanced: Diversions</a></h3>
1171 <p>Diversions are for higher-level packages generating their own C code,
1172 to make their use of critcl's commands generating
1173 <span class="sectref"><a href="#subsection1">Embedded C Code</a></span> easier.</p>
1174 <p>These commands normally generate all of their C code for the
1175 current &quot;<b class="file">.critcl</b>&quot; file, which may not be what is wanted by a
1176 higher-level package.</p>
1177 <p>With a diversion the generator output can be redirected into
1178 memory and from there on then handled and processed as the caller
1179 desires before it is committed to an actual &quot;<b class="file">.c</b>&quot; file.</p>
1180 <p>An example of such a package comes with critcl itself, see the
1181 implementation of package <b class="package"><a href="critcl_class.html">critcl::class</a></b>.</p>
1182 <p>To help such developers three commands are provided to manage
1183 diversions and the collection of C code in memory. These are:</p>
1184 <dl class="doctools_definitions">
1185 <dt><a name="90"><b class="cmd">::critcl::collect_begin</b></a></dt>
1186 <dd><p>This command starts the diversion of C code collection into memory.</p>
1187 <p>The result of the command is the empty string.</p>
1188 <p>Multiple calls are allowed, with each call opening a new
1189 nesting level of diversion.</p></dd>
1190 <dt><a name="91"><b class="cmd">::critcl::collect_end</b></a></dt>
1191 <dd><p>This command end the diversion of C code collection into memory and
1192 returns the collected C code.</p>
1193 <p>If multiple levels of diversion are open the call only closes
1194 and returns the data from the last level.</p>
1195 <p>The command will throw an error if no diversion is active,
1196 indicating a mismatch in the pairing of <b class="cmd">collect_begin</b> and
1197 <b class="cmd">collect_end</b>.</p></dd>
1198 <dt><a name="92"><b class="cmd">::critcl::collect</b> <i class="arg">script</i></a></dt>
1199 <dd><p>This is a convenience command which runs the <i class="arg">script</i> under
1200 diversion and returns the collected C code, ensuring the correct
1201 pairing of <b class="cmd">collect_begin</b> and <b class="cmd">collect_end</b>.</p></dd>
1202 </dl>
1203 </div>
1204 <div id="subsection14" class="doctools_subsection"><h3><a name="subsection14">Advanced: File Generation</a></h3>
1205 <p>While file generation is related to the diversions explained in the
1206 previous section they are not the same.
1207 Even so, like diversions this feature is for higher-level packages
1208 generating their own C code.</p>
1209 <p>Three examples of utility packages using this facility comes
1210 with critcl itself.
1211 See the implementations of packages <b class="package"><a href="critcl_literals.html">critcl::literals</a></b>,
1212 <b class="package"><a href="critcl_bitmap.html">critcl::bitmap</a></b>, and <b class="package"><a href="critcl_enum.html">critcl::enum</a></b>.</p>
1213 <p>When splitting a package implementation into pieces it is often
1214 sensible to have a number of pure C companion files containing
1215 low-level code, yet these files may require information about the code
1216 in the main &quot;<b class="file">.critcl</b>&quot; file. Such declarations are normally not
1217 exportable and using the stub table support does not make sense, as
1218 this is completely internal to the package.</p>
1219 <p>With the file generation command below the main &quot;<b class="file">.critcl</b>&quot;
1220 file can generate any number of header files for the C companions to
1221 pick up.</p>
1222 <dl class="doctools_definitions">
1223 <dt><a name="93"><b class="cmd">::critcl::make</b> <i class="arg">path</i> <i class="arg">contents</i></a></dt>
1224 <dd><p>This command creates the file <i class="arg">path</i> in a location where the C
1225 companion files of the package are able to pick it up by simple
1226 inclusion of <i class="arg">path</i> during their compilation, without interfering
1227 with the outer system at all.</p>
1228 <p>The generated file will contain the specified <i class="arg">contents</i>.</p></dd>
1229 </dl>
1230 </div>
1231 </div>
1232 <div id="section3" class="doctools_section"><h2><a name="section3">Concepts</a></h2>
1233 <div id="subsection15" class="doctools_subsection"><h3><a name="subsection15">Modes Of Operation/Use</a></h3>
1234 <p>CriTcl can be used in three different modes of operation, called</p>
1235 <ol class="doctools_enumerated">
1236 <li><p><i class="term"><a href="../index.html#compile_run">Compile &amp; Run</a></i>, and</p></li>
1237 <li><p><i class="term"><a href="../index.html#generate_package">Generate Package</a></i></p></li>
1238 <li><p><i class="term">Generate TEA Package</i></p></li>
1239 </ol>
1240 <p><i class="term"><a href="../index.html#compile_run">Compile &amp; Run</a></i> was the original mode and is the default for
1241 <i class="term">critcl_pkg</i>. Collects the C fragments from the
1242 <i class="term">CriTcl script</i>, builds them as needed, and caches the results to
1243 improve load times later.</p>
1244 <p>The second mode, <i class="term"><a href="../index.html#generate_package">Generate Package</a></i>, was introduced to enable
1245 the creation of (prebuilt) deliverable packages which do not depend on
1246 the existence of a build system, i.e. C compiler, on the target
1247 machine.
1248 This was originally done through the experimental <b class="cmd">Critbind</b> tool,
1249 and is now handled by the <i class="term">CriTcl Application</i>, also named
1250 <b class="cmd"><a href="critcl.html">critcl</a></b>.</p>
1251 <p>Newly introduced with CriTcl version 3 is
1252 <i class="term">Generate TEA Package</i>. This mode constructs a directory
1253 hierarchy from the package which can later be built like a regular TEA
1254 package, i.e. using</p>
1255 <pre class="doctools_example">
1256 .../configure --prefix ...
1257 make all isntall
1258 </pre>
1259 <p>Regarding the caching of results please read the section about
1260 the <span class="sectref"><a href="#subsection18">Result Cache</a></span> fore more details.</p>
1261 </div>
1262 <div id="subsection16" class="doctools_subsection"><h3><a name="subsection16">Runtime Behaviour</a></h3>
1263 <p>The default behaviour of critcl, the package is to defer the
1264 compilation, linking, and loading of any C code as much as possible,
1265 given that this is an expensive operation, mainly in the time
1266 required.
1267 In other words, the C code embedded into a &quot;<b class="file">.critcl</b>&quot; file is
1268 built only when the first C command or procedure it provides is
1269 invoked.
1270 This part of the system uses standard functionality built into the Tcl
1271 core, i.e. the <b class="variable">auto_index</b> variable to map from commands to
1272 scripts providing them and the <b class="cmd">unknown</b> command using this
1273 information when the command is needed.</p>
1274 <p>A <em>limitation</em> of this behaviour is that it is not
1275 possible to just use <b class="cmd">info commands</b> check for the existence of
1276 a critcl defined command. It is also necessary to search in the
1277 <b class="variable">auto_index</b> array, in case it has not been build yet.</p>
1278 <p>This behaviour can be changed by using the control command
1279 <b class="cmd">critcl::load</b>. When invoked, the building, including loading of
1280 the result, is forced. After this command has been invoked for a
1281 &quot;<b class="file">.critcl</b>&quot; file further definition of C code in this file is not
1282 allowed any longer.</p>
1283 </div>
1284 <div id="subsection17" class="doctools_subsection"><h3><a name="subsection17">File Mapping</a></h3>
1285 <p>Each &quot;<b class="file">.critcl</b>&quot; file is backed by a single private &quot;<b class="file">.c</b>&quot; file
1286 containing that code, plus the boilerplate necessary for its
1287 compilation and linking as a single shared library.</p>
1288 <p>The <span class="sectref"><a href="#subsection10">Embedded C Code</a></span>
1289 fragments appear in that file in the exact same order they were
1290 defined in the &quot;<b class="file">.critcl</b>&quot; file, with one exception. The C code
1291 provided via <b class="cmd">critcl::cinit</b> is put after all other fragments.
1292 In other words all fragments have access to the symbols defined by
1293 earlier fragments, and the <b class="cmd">critcl::cinit</b> fragment has access to
1294 all, regardless of its placement in the &quot;<b class="file">.critcl</b>&quot; file.</p>
1295 <p>Note: A <em>limitation</em> of the current system is the near
1296 impossibility of C level access between different critcl-based
1297 packages. The issue is not the necessity of writing and sharing the
1298 proper <b class="syscmd">extern</b> statements, but that the management (export and
1299 import) of package-specific stubs-tables is not supported. This means
1300 that dependent parts have to be forcibly loaded before their user,
1301 with all that entails. See section <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span> for
1302 the relevant critcl limitation, and remember that many older platforms
1303 do not support the necessary resolution of symbols, the reason why
1304 stubs were invented for Tcl in the first place.</p>
1305 </div>
1306 <div id="subsection18" class="doctools_subsection"><h3><a name="subsection18">Result Cache</a></h3>
1307 <p>The compilation of C code is time-consuming <b class="package"><a href="critcl.html">critcl</a></b> not only
1308 defers it as much as possible, as described in section
1309 <span class="sectref"><a href="#subsection16">Runtime Behaviour</a></span>, but also caches the results.</p>
1310 <p>This means that on the first use of a &quot;<b class="file">.critcl</b>&quot; file
1311 &quot;<b class="file">FOO.tcl</b>&quot; the resulting object file and shared library are saved
1312 into the cache, and on future uses of the same file reused,
1313 i.e. loaded directly without requiring compilation, provided that the
1314 contents of &quot;<b class="file">FOO.tcl</b>&quot; did not change.</p>
1315 <p>The change detection is based MD5 hashes. A single hash is
1316 computed for each &quot;<b class="file">.critcl</b>&quot; file, based on hashes for all C code
1317 fragments and configuration options, i.e. everything which affects the
1318 resulting binary.</p>
1319 <p>As long as the input file doesn't change as per the hash a
1320 previously built shared library found in the cache is reused,
1321 bypassing the compilation and link stages.</p>
1322 <p>The command to manage the cache are found in section
1323 <span class="sectref"><a href="#subsection7">Result Cache Management</a></span>.
1324 Note however that they are useful only to tools based on the package,
1325 like the <i class="term">CriTcl Application</i>. Package writers have no need
1326 of them.</p>
1327 <p>As a last note, the default directory for the cache is chosen
1328 based on the chosen build target. This means that the cache can be put
1329 on a shared (network) filesystem without having to fear interference
1330 between machines of different architectures.</p>
1331 </div>
1332 <div id="subsection19" class="doctools_subsection"><h3><a name="subsection19">Preloading functionality</a></h3>
1333 <p>The audience of this section are developers wishing to understand
1334 and possibly modify the internals of critcl package and application.
1335 Package writers can skip this section.</p>
1336 <p>It explains how the preloading of external libraries is realized.</p>
1337 <p>Whenever a package declares libraries for preloading critcl will build
1338 a supporting shared library providing a Tcl package named &quot;preload&quot;.
1339 This package is not distributed separately, but as part of the package
1340 requiring the preload functionality.
1341 This support package exports a single Tcl command</p>
1342 <dl class="doctools_definitions">
1343 <dt><a name="94"><b class="cmd">::preload</b> <i class="arg">library</i></a></dt>
1344 <dd><p>which is invoked once per libraries to preload, with the absolute path
1345 of that <i class="arg">library</i>. The command then loads the <i class="arg">library</i>.</p>
1346 <p>On windows the command will further use the Tcl command
1347 <b class="cmd">::critcl::runtime::precopy</b> to copy the <i class="arg">library</i> to the
1348 disk, should its path be in a virtual filesystem which doesn't
1349 directly support the loading of a shared library from it.</p></dd>
1350 </dl>
1351 <p>The command <b class="cmd">::critcl::runtime::precopy</b> is provided by the file
1352 &quot;<b class="file">critcl-rt.tcl</b>&quot; in the generated package, as is the command
1353 <b class="cmd">::critcl::runtime::loadlib</b> which generates the
1354 <i class="term">ifneeded script</i> expected by Tcl's package management. This
1355 generated ifneeded script contains the invocations of <b class="cmd">::preload</b>.</p>
1356 <p>The C code for the supporting library is found in the file
1357 &quot;<b class="file">critcl_c/preload.c</b>&quot;, which is part of the <b class="package"><a href="critcl.html">critcl</a></b>
1358 package.</p>
1359 <p>The Tcl code for the supporting runtime &quot;<b class="file">critcl-rt.tcl</b>&quot; is found
1360 in the file &quot;<b class="file">runtime.tcl</b>&quot;, which is part of the
1361 <b class="package">critcl::app</b> package.</p>
1362 </div>
1363 <div id="subsection20" class="doctools_subsection"><h3><a name="subsection20">Configuration Internals</a></h3>
1364 <p>The audience of this section are developers wishing to understand
1365 and possibly modify the internals of critcl package and application.
1366 Package writers can skip this section.</p>
1367 <p>It explains the syntax of configuration files and the configuration
1368 keys used by <b class="package"><a href="critcl.html">critcl</a></b> to configure its build backend, i.e. how
1369 this part of the system accesses compiler, linker, etc.</p>
1370 <p>It is recommended to open the file containing the standard
1371 configurations (&quot;<b class="file">path/to/critcl/Config</b>&quot;) in the editor of your
1372 choice when reading this section of the documentation, using it as an
1373 extended set of examples going beyond the simple defaults shown here.</p>
1374 <p>First, the keys and the meaning of their values, plus examples drawn
1375 from the standard configurations distributed with the package.
1376 Note that when writing a custom configuration it is not necessary to
1377 specify all the keys listed below, but only those whose default values
1378 are wrong or insufficient for the platform in question.</p>
1379 <dl class="doctools_definitions">
1380 <dt>version</dt>
1381 <dd><p>The command to print the compiler version number.
1382 Defaults to</p>
1383 <pre class="doctools_example"> gcc -v </pre>
1384 </dd>
1385 <dt>compile</dt>
1386 <dd><p>The command to compile a single C source file to an object file.
1387 Defaults to</p>
1388 <pre class="doctools_example"> gcc -c -fPIC </pre>
1389 </dd>
1390 <dt>debug_memory</dt>
1391 <dd><p>The list of flags for the compiler to enable memory debugging in
1392 Tcl.
1393 Defaults to</p>
1394 <pre class="doctools_example"> -DTCL_MEM_DEBUG </pre>
1395 </dd>
1396 <dt>debug_symbols</dt>
1397 <dd><p>The list of flags for the compiler to add symbols to the object files
1398 and the resulting library.
1399 Defaults to</p>
1400 <pre class="doctools_example"> -g </pre>
1401 </dd>
1402 <dt>include</dt>
1403 <dd><p>The compiler flag to add an include directory.
1404 Defaults to</p>
1405 <pre class="doctools_example"> -I </pre>
1406 </dd>
1407 <dt>tclstubs</dt>
1408 <dd><p>The compiler flag to set USE_TCL_STUBS.
1409 Defaults to</p>
1410 <pre class="doctools_example"> -DUSE_TCL_STUBS </pre>
1411 </dd>
1412 <dt>tkstubs</dt>
1413 <dd><p>The compiler flag to set USE_TK_STUBS.
1414 Defaults to</p>
1415 <pre class="doctools_example"> -DUSE_TK_STUBS </pre>
1416 </dd>
1417 <dt>threadflags</dt>
1418 <dd><p>The list of compiler flags to enable a threaded build.
1419 Defaults to</p>
1420 <pre class="doctools_example">
1421 -DUSE_THREAD_ALLOC=1 -D_REENTRANT=1 -D_THREAD_SAFE=1
1422 -DHAVE_PTHREAD_ATTR_SETSTACKSIZE=1 -DHAVE_READDIR_R=1
1423 -DTCL_THREADS=1
1424 </pre>
1425 <p>.</p></dd>
1426 <dt>noassert</dt>
1427 <dd><p>The compiler flag to turn off assertions in Tcl code.
1428 Defaults to</p>
1429 <pre class="doctools_example"> -DNDEBUG </pre>
1430 </dd>
1431 <dt>optimize</dt>
1432 <dd><p>The compiler flag to specify optimization level.
1433 Defaults to</p>
1434 <pre class="doctools_example"> -O2 </pre>
1435 </dd>
1436 <dt>output</dt>
1437 <dd><p>The compiler flags to set the output file of a compilation.
1438 Defaults to</p>
1439 <pre class="doctools_example"> -o [list $outfile] </pre>
1440 <p><em>NOTE</em> the use of Tcl commands and variables here. At the
1441 time <b class="package"><a href="critcl.html">critcl</a></b> uses the value of this key the value of the
1442 referenced variable is substituted into it. The named variable is the
1443 only variable whose value is defined for this substitution.</p></dd>
1444 <dt>object</dt>
1445 <dd><p>The file extension for object files on the platform.
1446 Defaults to</p>
1447 <pre class="doctools_example"> .o </pre>
1448 </dd>
1449 <dt>preproc_define</dt>
1450 <dd><p>The command to preprocess a C source file without compiling it, but
1451 leaving #define's in the output. Defaults to</p>
1452 <pre class="doctools_example"> gcc -E -dM </pre>
1453 </dd>
1454 <dt>preproc_enum</dt>
1455 <dd><p>See <b class="const">preproc_define</b>, except that #define's are not left in the
1456 output. Defaults to</p>
1457 <pre class="doctools_example"> gcc -E </pre>
1458 </dd>
1459 <dt>link</dt>
1460 <dd><p>The command to link one or more object files and create a shared
1461 library. Defaults to</p>
1462 <pre class="doctools_example"> gcc -shared </pre>
1463 </dd>
1464 <dt>link_preload</dt>
1465 <dd><p>The list of linker flags to use when dependent libraries are
1466 pre-loaded. Defaults to</p>
1467 <pre class="doctools_example"> --unresolved-symbols=ignore-in-shared-libs </pre>
1468 </dd>
1469 <dt>strip</dt>
1470 <dd><p>The flag to tell the linker to strip symbols from the shared library.
1471 Defaults to</p>
1472 <pre class="doctools_example"> -Wl,-s </pre>
1473 </dd>
1474 <dt>ldoutput</dt>
1475 <dd><p>Like <b class="const">output</b>, but for the linker.
1476 Defaults to the value of <b class="const">output</b>.</p></dd>
1477 <dt>link_debug</dt>
1478 <dd><p>The list of linker flags needed to build a shared library with
1479 symbols. Defaults to the empty string.
1480 One platform requiring this are all variants of Windows, which uses</p>
1481 <pre class="doctools_example"> -debug:full -debugtype:cv </pre>
1482 </dd>
1483 <dt>link_release</dt>
1484 <dd><p>The list of linker flags needed to build a shared library without
1485 symbols, i.e. a regular build. Defaults to the empty string.
1486 One platform requiring this are all variants of Windows, which uses</p>
1487 <pre class="doctools_example"> -release -opt:ref -opt:icf,3 -ws:aggressive </pre>
1488 </dd>
1489 <dt>sharedlibext</dt>
1490 <dd><p>The file extension for shared library files on the platform.
1491 Defaults to</p>
1492 <pre class="doctools_example"> [info sharedlibextension] </pre>
1493 </dd>
1494 <dt>platform</dt>
1495 <dd><p>The identifier of the platform used in generated packages.
1496 Defaults to</p>
1497 <pre class="doctools_example"> [platform::generic] </pre>
1498 </dd>
1499 <dt>target</dt>
1500 <dd><p>The presence of this key marks the configuration as a
1501 cross-compilation target and the value is the actual platform
1502 identifier of the target. No default.</p></dd>
1503 </dl>
1504 <p>The syntax expected from configuration files is governed by the rules below.
1505 Again, it is recommended to open the file containing the standard
1506 configurations (&quot;<b class="file">path/to/critcl/Config</b>&quot;) in the editor of your
1507 choice when reading this section of the documentation, using it as an
1508 extended set of examples for the syntax&gt;</p>
1509 <ol class="doctools_enumerated">
1510 <li><p>Each logical line of the configuration file consists of one or
1511 more physical lines. In case of the latter the physical lines have to
1512 follow each other and all but the first must be marked by a trailing
1513 backslash. This is the same marker for <i class="term">continuation lines</i> as
1514 used by Tcl itself.</p></li>
1515 <li><p>A (logical) line starting with the character &quot;#&quot; (modulo
1516 whitespace) is a comment which runs until the end of the line, and is
1517 otherwise ignored.</p></li>
1518 <li><p>A (logical) line starting with the word &quot;if&quot; (modulo
1519 whitespace) is interpreted as Tcl's <b class="cmd">if</b> command and executed as
1520 such. I.e. this command has to follow Tcl's syntax for the command,
1521 which may stretch across multiple logical lines. The command will be
1522 run in a save interpreter.</p></li>
1523 <li><p>A (logical) line starting with the word &quot;set&quot; (modulo
1524 whitespace) is interpreted as Tcl's <b class="cmd">set</b> command and executed as
1525 such. I.e. this command has to follow Tcl's syntax for the command,
1526 which may stretch across multiple logical lines. The command will be
1527 run in a save interpreter.</p></li>
1528 <li><p>A line of the form &quot;<i class="arg">platform</i> <b class="variable">variable</b> <i class="arg">value</i>&quot;
1529 defines a platform specific configuration variable and value.
1530 The <b class="variable">variable</b> has to be the name of one of the configuration keys
1531 listed earlier in this section, and the <i class="arg">platform</i> string
1532 identifies the platform the setting is for. All settings with the same
1533 identification string form the <i class="term">configuration block</i> for this
1534 platform.</p></li>
1535 <li><p>A line of the special form
1536 &quot;<i class="arg">platform</i> <b class="const">when</b> <i class="arg">expression</i>&quot;
1537 marks the <i class="arg">platform</i> and all the settings in its
1538 <i class="term">configuration block</i> as conditional on the <i class="arg">expression</i>.</p>
1539 <p>If the build platform is not a prefix of <i class="arg">platform</i>,
1540 nor vice versa the whole block is ignored.
1541 Otherwise the <i class="arg">expression</i> is evaluated via <b class="cmd">expr</b>, in the
1542 same safe interpreter used to run any <b class="cmd">set</b> and <b class="cmd">if</b> commands
1543 found in the configuration file (see above).</p>
1544 <p>If the expression evaluates to <b class="const">true</b> this configuration block
1545 is considered to be the build platform fo the host and chosen as the
1546 default configuration.
1547 An large example of of this feature is the handling of OS X found in
1548 the standard configuration file, where it selects the architectures to
1549 build based on the version of the operating system, the available SDK,
1550 etc. I.e. it chooses whether the output is universal or not, and
1551 whether it is old-style (ix86 + ppc) versus new-style (ix86 32+64) of
1552 universality.</p></li>
1553 <li><p>A line of the special form
1554 &quot;<i class="arg">platform</i> <b class="const">copy</b> <i class="arg">sourceplatform</i>&quot;
1555 copies the configuration variables and values currently defined in the
1556 <i class="term">configuration block</i> for <i class="arg">sourceplatform</i> to that of
1557 <i class="arg">platform</i>, overwriting existing values, and creating missing
1558 ones. Variables of <i class="arg">platform</i> not defined by by <i class="arg">sourceplatform</i>
1559 are not touched.</p>
1560 <p>The copied values can be overridden later in the configuration
1561 file. Multiple <b class="const">copy</b> lines may exist for a platform and be
1562 intermixed with normal configuration definitions. Only the last definition of a
1563 variable is used.</p></li>
1564 <li><p>At last, a line of the form &quot;<b class="variable">variable</b> <i class="arg">value</i>&quot;
1565 defines a default configuration variable and value.</p></li>
1566 </ol>
1567 </div>
1568 <div id="subsection21" class="doctools_subsection"><h3><a name="subsection21">Stubs Tables</a></h3>
1569 <p>This section is for developers of extensions not based on critcl, yet
1570 also wishing to interface with stubs as they are understood and used
1571 by critcl, either by exporting their own stubs table to a
1572 critcl-based extension, or importing a stubs table of a critcl-based
1573 extension into their own.</p>
1574 <p>To this end we describe the stubs table information of a
1575 package <b class="package">foo</b>.</p>
1576 <ol class="doctools_enumerated">
1577 <li><p>Note that the differences in the capitalization of &quot;foo&quot;,
1578 &quot;Foo&quot;, &quot;FOO&quot;, etc. below demonstrate how to capitalize the actual
1579 package name in each context.</p></li>
1580 <li><p>All relevant files must be available in a sub-directory
1581 &quot;<b class="file">foo</b>&quot; which can be found on the include search paths.</p></li>
1582 <li><p>The above directory may contain a file &quot;<b class="file">foo.decls</b>&quot;. If
1583 present it is assumed to contain the external representation
1584 of the stubs table the headers mentioned in the following
1585 items are based on.</p>
1586 <p>critcl is able to use such a file to give the importing package
1587 programmatic access to the imported API, for automatic code
1588 generation and the like.</p></li>
1589 <li><p>The above directory must contain a header file
1590 &quot;<b class="file">fooDecls.h</b>&quot;. This file <em>declares</em> the exported API.
1591 It is used by both exporting and importing packages. It is usually
1592 generated and must contain (in the order specified):</p>
1593 <ol class="doctools_enumerated">
1594 <li><p>the declarations of the exported, i.e. public, functions of
1595 <b class="package">foo</b>,</p></li>
1596 <li><p>the declaration of structure &quot;FooStubs&quot; for the stub table,</p></li>
1597 <li><p>the C preprocessor macros which route the invocations of the
1598 public functions through the stubs table.</p>
1599 <p>These macros must be defined if, and only if, the C preprocessor
1600 macro USE_FOO_STUBS is defined. Package <b class="package">foo</b> does not
1601 define this macro, as it is allowed to use the exported
1602 functions directly. All importing packages however must define
1603 this macro, to ensure that they do <em>not</em> use any of the
1604 exported functions directly, but only through the stubs table.</p></li>
1605 <li><p>If the exported functions need additional types for their proper
1606 declaration then these types should be put into a separate
1607 header file (of arbitrary name) and &quot;<b class="file">fooDecls.h</b>&quot; should
1608 contain an #include directive to this header at the top.</p></li>
1609 </ol>
1610 <p>A very reduced, yet also complete example, from a package for
1611 low-level random number generator functions can be found at the end of
1612 this section.</p></li>
1613 <li><p>The above directory must contain a header file
1614 &quot;<b class="file">fooStubLib.h</b>&quot;. This file <em>defines</em> everything needed to use
1615 the API of <b class="package">foo</b>. Consequently it is used only by importing
1616 packages. It is usually generated and must contain (in the order
1617 specified):</p>
1618 <ol class="doctools_enumerated">
1619 <li><p>An #include directive for &quot;<b class="file">tcl.h</b>&quot;, with USE_TCL_STUBS
1620 surely defined.</p></li>
1621 <li><p>An #include directive for &quot;<b class="file">fooDecls.h</b>&quot;, with USE_FOO_STUBS
1622 surely defined.</p></li>
1623 <li><p>A <em>definition</em> of the stubs table variable, i.e.</p>
1624 <pre class="doctools_example">const FooStubs* fooStubsPtr;</pre>
1625 </li>
1626 <li><p>A <em>definition</em> of the stubs initializer function, like</p>
1627 <pre class="doctools_example">char *
1628 Foo_InitStubs(Tcl_Interp *interp, CONST char *version, int exact)
1629 {
1630 /*
1631 * Boiler plate C code initalizing the stubs table variable,
1632 * i.e. &quot;fooStubsPtr&quot;.
1633 */
1634 CONST char *actualVersion;
1635 actualVersion = Tcl_PkgRequireEx(interp, &quot;foo&quot;, version,
1636 exact, (ClientData *) &amp;fooStubsPtr);
1637 if (!actualVersion) {
1638 return NULL;
1639 }
1640 if (!fooStubsPtr) {
1641 Tcl_SetResult(interp,
1642 &quot;This implementation of Foo does not support stubs&quot;,
1643 TCL_STATIC);
1644 return NULL;
1645 }
1646 return (char*) actualVersion;
1647 }</pre>
1648 </li>
1649 </ol>
1650 <p>This header file must be included by an importing package
1651 <em>exactly once</em>, so that it contains only one definition of both
1652 stubs table and stubs initializer function.</p>
1653 <p>The importing package's initialization function must further
1654 contain a statement like</p>
1655 <pre class="doctools_example">if (!Foo_InitStubs (ip, &quot;1&quot;, 0)) {
1656 return TCL_ERROR;
1657 }</pre>
1658 <p>which invokes <b class="package">foo</b>'s stubs initializer function to set the
1659 local stub table up.</p>
1660 <p>For a complete example of such a header file see below, at the
1661 end of this section.</p></li>
1662 <li><p>The last item above, about &quot;<b class="file">fooStubLib.h</b>&quot; <em>differs</em>
1663 from the regular stub stable system used by Tcl. The regular
1664 system assumes that a static library &quot;<b class="file">libfoostub.a</b>&quot; was
1665 installed by package <b class="package">foo</b>, and links it.</p>
1666 <p>IMVHO critcl's approach is simpler, using <em>only</em> header
1667 files found in a single location, vs. header files and static
1668 library found in multiple, different locations.</p>
1669 <p>A second simplification is that we avoid having to extend
1670 critcl's compiler backend with settings for the creation of
1671 static libraries.</p></li>
1672 </ol>
1673 <p>Below is a complete set of example header files, reduced, yet still
1674 complete, from a package for low-level random number generator
1675 functions:</p>
1676 <dl class="doctools_definitions">
1677 <dt>&quot;<b class="file">rngDecls.h</b>&quot;:</dt>
1678 <dd>
1679 <pre class="doctools_example">
1680 #ifndef rng_DECLS_H
1681 #define rng_DECLS_H
1682 #include &lt;tcl.h&gt;
1683 /*
1684 * Exported function declarations:
1685 */
1686 /* 0 */
1687 EXTERN void rng_bernoulli(double p, int*v);
1688 typedef struct RngStubs {
1689 int magic;
1690 const struct RngStubHooks *hooks;
1691 void (*rng_bernoulli) (double p, int*v); /* 0 */
1692 } RngStubs;
1693 #ifdef __cplusplus
1694 extern &quot;C&quot; {
1695 #endif
1696 extern const RngStubs *rngStubsPtr;
1697 #ifdef __cplusplus
1698 }
1699 #endif
1700 #if defined(USE_RNG_STUBS)
1701 /*
1702 * Inline function declarations:
1703 */
1704 #define rng_bernoulli (rngStubsPtr-&gt;rng_bernoulli) /* 0 */
1705 #endif /* defined(USE_RNG_STUBS) */
1706 #endif /* rng_DECLS_H */
1707 </pre>
1708 </dd>
1709 <dt>&quot;<b class="file">rngStubLib.h</b>&quot;:</dt>
1710 <dd>
1711 <pre class="doctools_example">
1712 /*
1713 * rngStubLib.c --
1714 *
1715 * Stub object that will be statically linked into extensions that wish
1716 * to access rng.
1717 */
1718 #ifndef USE_TCL_STUBS
1719 #define USE_TCL_STUBS
1720 #endif
1721 #undef USE_TCL_STUB_PROCS
1722 #include &lt;tcl.h&gt;
1723 #ifndef USE_RNG_STUBS
1724 #define USE_RNG_STUBS
1725 #endif
1726 #undef USE_RNG_STUB_PROCS
1727 #include &quot;rngDecls.h&quot;
1728 /*
1729 * Ensure that Rng_InitStubs is built as an exported symbol. The other stub
1730 * functions should be built as non-exported symbols.
1731 */
1732 #undef TCL_STORAGE_CLASS
1733 #define TCL_STORAGE_CLASS DLLEXPORT
1734 const RngStubs* rngStubsPtr;
1735
1736 /*
1737 *----------------------------------------------------------------------
1738 *
1739 * Rng_InitStubs --
1740 *
1741 * Checks that the correct version of Rng is loaded and that it
1742 * supports stubs. It then initialises the stub table pointers.
1743 *
1744 * Results:
1745 * The actual version of Rng that satisfies the request, or
1746 * NULL to indicate that an error occurred.
1747 *
1748 * Side effects:
1749 * Sets the stub table pointers.
1750 *
1751 *----------------------------------------------------------------------
1752 */
1753 #ifdef Rng_InitStubs
1754 #undef Rng_InitStubs
1755 #endif
1756 char *
1757 Rng_InitStubs(Tcl_Interp *interp, CONST char *version, int exact)
1758 {
1759 CONST char *actualVersion;
1760 actualVersion = Tcl_PkgRequireEx(interp, &quot;rng&quot;, version,
1761 exact, (ClientData *) &amp;rngStubsPtr);
1762 if (!actualVersion) {
1763 return NULL;
1764 }
1765 if (!rngStubsPtr) {
1766 Tcl_SetResult(interp,
1767 &quot;This implementation of Rng does not support stubs&quot;,
1768 TCL_STATIC);
1769 return NULL;
1770 }
1771 return (char*) actualVersion;
1772 }
1773 </pre>
1774 </dd>
1775 </dl>
1776 </div>
1777 </div>
1778 <div id="section4" class="doctools_section"><h2><a name="section4">Examples</a></h2>
1779 <p>See section &quot;Embedding C&quot; in <i class="term">Using CriTcl</i>.</p>
1780 </div>
1781 <div id="section5" class="doctools_section"><h2><a name="section5">Authors</a></h2>
1782 <p>Jean Claude Wippler, Steve Landers, Andreas Kupries</p>
1783 </div>
1784 <div id="section6" class="doctools_section"><h2><a name="section6">Bugs, Ideas, Feedback</a></h2>
1785 <p>This document, and the package it describes, will undoubtedly contain
1786 bugs and other problems.
1787 Please report them at <a href="https://github.com/andreas-kupries/critcl/issues">https://github.com/andreas-kupries/critcl/issues</a>.
1788 Ideas for enhancements you may have for either package, application,
1789 and/or the documentation are also very welcome and should be reported
1790 at <a href="https://github.com/andreas-kupries/critcl/issues">https://github.com/andreas-kupries/critcl/issues</a> as well.</p>
1791 </div>
1792 <div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
1793 <p><a href="../index.html#c_code">C code</a>, <a href="../index.html#embedded_c_code">Embedded C Code</a>, <a href="../index.html#calling_c_code_from_tcl">calling C code from Tcl</a>, <a href="../index.html#code_generator">code generator</a>, <a href="../index.html#compile_run">compile &amp; run</a>, <a href="../index.html#compiler">compiler</a>, <a href="../index.html#dynamic_code_generation">dynamic code generation</a>, <a href="../index.html#dynamic_compilation">dynamic compilation</a>, <a href="../index.html#generate_package">generate package</a>, <a href="../index.html#linker">linker</a>, <a href="../index.html#on_demand_compilation">on demand compilation</a>, <a href="../index.html#on_the_fly_compilation">on-the-fly compilation</a></p>
1794 </div>
1795 <div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
1796 <p>Glueing/Embedded C code</p>
1797 </div>
1798 <div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
1799 <p>Copyright &copy; Jean-Claude Wippler<br>
1800 Copyright &copy; Steve Landers<br>
1801 Copyright &copy; 2011-2024 Andreas Kupries</p>
1802 </div>
1803 </div></body></html>