Hi all,
For my version of
https://bitbucket.org/reiniero/lazupdater_baremetal/, I want to know whether an operating system is 32 bit or 64 bit, so I can let the user choose between 32 and 64 bit compilers/binutils - if possible.
For Windows, I found a function that does it, thanks to the German Lazarus forum:
http://wiki.lazarus.freepascal.org/Multiplatform_Programming_Guide#Detecting_bitness_at_runtimeHow can I detect if you're running on 32 or 64 bit Linux and OSX? (Bonus question: if not on x86 architecture, how can I detect which processor it's running on - but I think that's less pressing)
Something like uname -a might work, but I don't know if the output can be parsed for all Linux distros and OSX.
Linux:
Don't really know if all Linux
uname
s will give the same 64 bit indication...
On Linux, perhaps something in the /proc filesystem?
Found
http://www.velocityreviews.com/forums/t147757-how-to-detect-cpu-architecture-bitmode-32-bit-vs-64-bit-for-linux.html; paraphrased:
cat /proc/cpuinfo
You will see some parameters with their description
Under "flags" parameter various parameters?/names?, one of them:
1. "rm(real mode)": 16 bit processor
2. "tm(transparent mode)": 32 bit processor
3. "lm(long mode)": 64 bit processor
Would this also apply to non-X86 architectures? (And yes, the obvious next question is, how do I detect Linux on ARM etc)
OSX:
On OSX, I saw a post by Shebuka mentioning system_profiler:
http://www.lazarus.freepascal.org/index.php/topic,13109.msg71741.html#msg71741, but the questions are: what setting to query & is there a more elegant way of doing that?
Saw another site
http://osxdaily.com/2009/09/07/how-to-tell-if-youre-running-the-32-bit-or-64-bit-kernel-in-mac-os-x-snow-leopard/ that says:
uname -a
this returns a line ending with:
i386
or
x86_64
Any more elegant way?
Ok, for completeness' sake & my records: other unixes (FreeBSD, Solaris): any tips?
Thanks!