Version 7 of Generating a generic platform name

Updated 2003-03-06 10:49:58

This page was prompted by a discussion started by Bob Techentin and Joe English on comp.lang.tcl [L1 ]. -jcw

The problem: how to generate a simple name which can be used as directory name when storing multiple shared library builds for different platforms next to each other. This has uses in Critcl and in Starkits.

The problem is hard, because it's not well specified. One could do "[join [array get tcl_platform] { }]", and end up with a name which is definitely unique, but huge. The trouble is that for shared libraries, this approach is in fact wrong - there are many details in tcl_platform which differ between machines, yet are irrelevant w.r.t. binary compatibility. An example from Joe English's post: IRIX has numerous variations with intricate compatibility issues, while Linux does not really care - all shared libs will load anywhere regardless of kernel version.

So, let's try to come up with some logic, and extend / perfect it along the way. Here's a start:

    proc platform {} {
        global tcl_platform
        set plat [lindex $tcl_platform(os) 0]
        set mach $tcl_platform(machine)
        switch -glob -- $mach {
            sun4* { set mach sparc }
            intel -
            i*86* { set mach x86 }
            "Power Macintosh" { set mach ppc }
        }
        set mach [regsub -all {[ /]} $mach "-"]
        return "$plat-$mach"
    }

Some output:

   Linux-x86
   Darwin-ppc   (Mac OSX)
   Windows-x86
   SunOS-sparc

The goal is to come up with a unique identifier which can be used as directory name (no slashes or colons, please), for each context which requires a different binary. For contexts which are compatible, the goal is to end up with the same identifier each time.

Failures are not necessarily show-stoppers. If a specific shared library needs more differentiation than the identifier provides, one can always add add-hoc logic for it (example: a high-performance bianry which is built different for Pentium vs. Athlon cpu's). If it turns out that two different identifiers are produced for what is determined to be compatible after all (IRIX comes to mind), then one can either store copies, or post-process the output from the [platform] command.


Anyway, the idea for this page is to tweak the above [platform] command, so we can use it as "easy shared-lib discriminator" on more and more platforms. Here's a modified version with Bob's HPUX changes added:

    proc platform {} {
        global tcl_platform
        set plat [lindex $tcl_platform(os) 0]
        set mach $tcl_platform(machine)
        switch -glob -- $mach {
            sun4* { set mach sparc }
            intel -
            i*86* { set mach x86 }
            "Power Macintosh" { set mach ppc }
            9000* {set mach 9000}
        }
        set mach [regsub -all {[ /]} $mach "-"]
        return "$plat-$mach"
    }

Please feel free to alter the above (carefully, so it doesn't break). The history of this page (warning: it only gets updated once per day) can be used to see all previous versions if you need to go back and check things out:

    http://mini.net/tclhist/8522~   (annotated per line)
    http://mini.net/tclhist/8522*   (list of all versions)

LV Any reason to not pattern the names after autoconf's config.guess ? For instance, platform, above, says on my sparc solaris 2.6 machine:

 SunOS-sparc

while config.guess says

 sparc-sun-solaris2.6

Without OS version, you run into basic runtime incompatibilities (like between major releases of Linux and Solaris at least - maybe other platforms as well). config.guess when possible.

stevel Yes - there's a reason - this was done to facilitate loading platform specific shared libraries when, in most instances, the OS version is irrelevant (and can be obtained if you need it).


Another reason for generating generic platform names is to make tcl_platform(machine)consistent across platforms. For For example, Power PC should be "ppc" on both AIX and MacOSX. At the moment on MacOSX it is "Power Macintosh" whereas on Linux it is "ppc". Note that CriTcl tries to do this as far as is possible (e.g. ppc, x86, sparc, etc) - stevel

Category Porting