<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE TIP SYSTEM "http://www.tcl.tk/cgi-bin/tct/tip/tipxml.dtd">
<!-- Converted at Sat May 18 16:38:13 GMT 2013 -->
<!-- TIP AutoGenerator - written by Donal K. Fellows -->

<TIP number='291'>
<header><title>Add the &apos;platform&apos; Package to Tcl</title><author address="mailto:steve@DigitalSmarties.com">Steve Landers</author><author address="mailto:andreask@activestate.com">Andreas Kupries</author><status type='project' state='final' tclversion="8.5" vote='after'>$Revision: 1.9 $</status><history></history><created day='26' month='oct' year='2006' /><keyword>Tcl Critcl TEApot</keyword></header>
<abstract>This TIP proposes adding the <emph style="bold">platform</emph> package to the Tcl core sources and to install it automatically, similar to what is currently done with the <emph style="bold">tcltest</emph> package.</abstract>
<body><section title="Rationale">
<para>It has been shown by the current users of the <emph style="bold">platform</emph> package - the <emph style="bold">Critcl</emph> (C Runtime in Tcl) and the <emph style="bold">TEApot</emph> repository system - that it is useful to not only be able to identify the architecture of a machine running Tcl, but to condense this information into a single identifier, standardized across platforms.</para>
<para>Whilst Tcl provides the <emph style="italic">tcl_platform</emph> array for identifying the current architecture (in particular, the platform and machine elements) this is not always sufficient. This is because (on Unix machines) <emph style="italic">tcl_platform</emph> reflects the values returned by the <emph style="bold">uname</emph> command and these aren&apos;t standardized across platforms and architectures. In addition, on at least one platform (AIX) the <emph style="italic">tcl_platform(machine)</emph> contains the CPU serial number.</para>
<para>Consequently, individual applications need to manipulate the values in <emph style="italic">tcl_platform</emph> (along with the output of system specific utilities) - which is both inconvenient for developers, and introduces the potential for inconsistencies in identifying architectures and in naming conventions.</para>
<para>Placing the <emph style="bold">platform</emph> package into the core in the same manner as <emph style="bold">tcltest</emph> will prevent such fragmentation - i.e., it will establish a standard naming convention for architectures running Tcl - and will make it more convenient for developers to identify the current architecture a Tcl program is running on.</para>
</section>
<section title="Specification of the proposed Change">

<subsection title="Tcl Level API">
<para>Two new packages, <emph style="bold">platform</emph> and <emph style="bold">platform::shell</emph> are made available, and can be loaded into Tcl via <emph style="bold">package require</emph>.</para>
<para>The package <emph style="bold">platform</emph> provides three commands:</para>
<enumerate><item.e index='1'><para><emph style="bold">::platform::identify</emph></para><para>This command returns an identifier describing the platform the Tcl core is running on.</para></item.e><item.e index='2'><para><emph style="bold">::platform::generic</emph></para><para>This command returns a simplified identifier, leaving out details like kernel version, libc version, etc.</para></item.e><item.e index='3'><para><emph style="bold">::platform::patterns</emph> <emph style="italic">id</emph></para><para>This command takes an identifier as returned by <emph style="bold">::platform::identify</emph> and returns a list of identifiers for compatible architectures.</para></item.e></enumerate>
<para>All identifiers have the general format <emph style="italic">OS</emph>-<emph style="italic">CPU</emph>. The CPU part will not contain dashes anymore, whereas the OS part may contain dashes.</para>
<para>The package <emph style="bold">platform::shell</emph> provides three commands as well, two of which are wrappers around commands provided by <emph style="bold">platform</emph>.</para>
<enumerate><item.e index='1'><para><emph style="bold">::platform::shell::generic</emph> <emph style="italic">shell</emph></para><para>This command returns the generic identification of the specified <emph style="italic">shell</emph>. The shell has to be executable on the host machine, but does not have to have the package <emph style="bold">platform</emph> itself. This is supplied by the caller.</para></item.e><item.e index='2'><para><emph style="bold">::platform::shell::identify</emph> <emph style="italic">shell</emph></para><para>This command returns the exact identification of the specified <emph style="italic">shell</emph>. The shell has to be executable on the host machine, but does not have to have the package <emph style="bold">platform</emph> itself. This is supplied by the caller.</para></item.e><item.e index='3'><para><emph style="bold">::platform::shell::platform</emph> <emph style="italic">shell</emph></para><para>This command returns the contents of <emph style="italic">tcl_platform(platform)</emph> for the specified <emph style="italic">shell</emph>. The shell has to be executable on the host machine.</para></item.e></enumerate>
</subsection>
<subsection title="Public C API">
<para>One deficiency in the current implementation of the package <emph style="italic">platform</emph> is the difficulty of distinguishing 64bit and 32bit systems. To remove this deficiency the variable <emph style="italic">tcl_platform</emph> of the Tcl core is extended to contain an entry <emph style="italic">pointerSize</emph>. The value associated with this entry is the number of bytes needed by the machine to store a <emph style="italic">void *</emph> pointer.</para>
</subsection>
</section>
<section title="Discussion">
<para>When choosing the format for platform identifiers we had two contenders, i.e. <emph style="italic">OS</emph>-<emph style="italic">CPU</emph> vs. <emph style="italic">CPU</emph>-<emph style="italic">OS</emph>, the second of which is used by GCC. However for developers using a scripting language like Tcl the OS is of more importance than the CPU architecture. Because of this the first form was chosen.</para>
</section>
<section title="Reference Implementation">
<para>This is available on SourceForge [<url ref="http://sourceforge.net/support/tracker.php?aid=1600701"/>].</para>
</section>
<section title="Copyright">
<para>This document has been placed in the public domain.</para>
<para>Please note that any correspondence to the author concerning this TIP is considered in the public domain unless otherwise specifically requested by the individual(s) authoring said correspondence. This is to allow information about the TIP to be placed in a public forum for discussion.</para>
</section>
</body></TIP>
