[Liverpool] Runtime OS architecture detection
Dave Love
d.love at liverpool.ac.uk
Sat Dec 11 11:18:13 UTC 2010
Liam Devine <dmail00 at gmail.com> writes:
> Premake[1] is an Open Source cross platform 'configure' type library
> written in Lua which generates project files, solutions and make
> files. Currently I am trying to figure out the best and most universal
> method of detecting the host architecture for Linux distros at runtime
Do you mean GNU/Linux? Even if you don't think much of GNU autotools,
I'm pretty sure you won't do better for platform information than
config.sub/config.guess, and they're not specific to Linux-based
systems. The autotools have a lot of hard experience behind them, and I
guess such questions are best asked in an autoconf forum.
> for a couple of reasons: To let users call out to external
> executables depending on the arch [2]
I don't understand exactly what's required, but for building you don't
normally care about the hardware, just what the tools target -- what
width is a C long, not what's the addressing of the metal.
> To set the correct location to look for libraries [3]
I don't know why you want to, but you're on to a loser if you assume
libraries are necessarily somewhere like /usr/lib64, and especially if
you consider non-GNU/Linux systems. While you can, perhaps, locate
libraries with ldd and a sample binary, ask yourself why.
> My current thinking is the best method is to parse the output of
> 'uname -m' and this method has been confirmed to me that at least on
> one distro gives the value of a 32 bit id when a 32 bit distro is
> installed on a 64 bit system, which is what I am looking for.
(In the absence of details,) that's not necessarily what's relevant,
e.g.
$ /usr/share/misc/config.guess
x86_64-unknown-linux-gnu
$ linux32 /usr/share/misc/config.guess
i686-pc-linux-gnu
You can't, in general, determine the target parameters with build-time
tests; think cross-building a cross-compiler, and you may or may not
regard `gcc -m...' as cross-compiling.
> The current values that I have can be seen in [4]. Are there any
> others that are known to yourselves
Look at GCC for a start on architectures of current interest, but it
probably misses current ones.
More information about the Liverpool
mailing list