Bitness of the system on Vala - 32bit-64bit

As for the Vala language cross-platform to know the bitness of the system?

sizeof(void*) will be 8 for 64-bit systems and 4 for 32 bit systems. Also, 2 for 16 bit systems, but I don't even know that glib will work there.

The whole point of GLib is to avoid having to do platform specific code.
However according to you comment you want to do something like download platform specific packages.
First of all it would be better to use a system or user package manager to do that, since they already know how to achieve that (DRY principle).
If you absolutely must, you can also use tools like lsb-release -a or the more general uname -a (for the kernel and arch) or some other arguments to those tools.
You can invoke them with GLibs process spawning facilities.
See also:
How to determine whether a given Linux is 32 bit or 64 bit?
And a related problem is OS detection:
Is OS detection possible with GLib?
Also since Vala is a compiled language, you could use your favorite build system to pass something like -DPlatformx64 or -DPlatformx86 to the Vala compiler (see the above link on OS detection for an example on how to use the preprocessor in Vala code).

Related

Decompile a RISC system/6000 executable file

we have a old AIX server and it has an executable file and we want to rewrite the same logic of the executable file on linux server, so we are trying to read it but could not find a way to do that.could you please let us know if there is a way to decipher this file
$ file execfile
execfile: executable (RISC System/6000) or object module
The IBM RS/6000 has a POWER architecture CPU, possibly a PowerPC 603 or PowerPC 604, or possibly one of the newer models like POWER1, POWER2, POWER3, etc. The most recent (current) systems use POWER7 or POWER8.
Anyway, if the system has the compiler and toolchain installed on it then there should be a decent symbolic debugger included, and you should be able to use that to disassemble any executable. Depending on exactly which version of the OS it was compiled on, and which compiler was used, you might even be able to use PowerPC tools on some other OS, such as MacOS, or even potentially a cross-compiler toolchain on any type of system, to disassemble the program. For example GDB built for PowerPC may be able to disassemble the program.
However if the executable has been stripped of symbols (as was typically the case on AIX systems, IIRC), and especially if it had been run through the most powerful optimizing stage of the compiler, then you'll be pretty much lost and what you are trying to do will be impractical and require many man hours to decipher -- indeed many thousands of man hours for any significantly sized program, even if you're able to hire someone to help who is familiar with the code generation patterns of the particular compiler which was used.
You might be better off trying to hire an archeologist to help you dig through the specific landfill where you might hope to find listings or backup tapes or CDs or disks containing the original source code, or specification documents, etc., for this program. Seriously.
Or try to find and (re-)hire the original author(s).

are compiler and shell internal part of Unix?

I had this question on my exam, now in diagrams I saw, we have : hardware, kernel, system call interface to the kernel, then (compilers, shells, sys.libs) and on top some applications. Does OS scope include only kernel, and everything else is just some additional functions we choose to install , or does a Unix OS include everything from the list I gave above?
OS have more or less 2 definitions :
academic : OS is soft for doing a abstraction layer between
hardware and software
pragmatic : OS is soft that come with hardware when we buy it.
Compiler and shell don't enter in definition 1. It can be enter in definition 2.
And usually, users that are interesting by a compiler or a shell prefer to consider OS as asbtraction layer (academic definition).
Simple answer, No. They are not an internal part of Unix but additional functionality to help make the Operating System more usable.
The OS scope applies primarily to the kernel only.
Whilst you need a compiler to build the kernel, you don't necessarily require one for the general day to day use of the system. Most operating systems don't ship the compiler by default and instead, the kernel and applications is built on one machine and then the resulting binarys are packaged and distributed either with the computer directly (Windows/Unix) or via the internet for others to download and install (Linux/BSD)
Likewise with the shell. Although all operating systems ship with a default one (sh/bash/dash on Linux|Unix systems, Command Prompt/Powershell on Windows), most general users can go their entire lives without using it.
Having said that, if you were to delete the shell, you'll almost certainly find your system won't boot up. This is because a lot of core start-up scripts rely on the shell to stop / start the services presenting interfaces between the user and the kernel.
In summary:
You need a compiler to build the kernel and applications but not for running the OS.
You need a shell to execute applications (which also includes the compiler)

Installing software on Solaris

I'd like to install several unix utilities (incl. xmlstarlet, wget) on a solaris 10 machine which I don't have root access to (obviously, I have a user account). I'm not that experienced with solaris and am wondering if I can simply get hold of an uber binary for each utility I need and just place this in my home directory? Is this feasible?
Many thanks
wget is installed by default on Solaris 10 in /usr/sfw/bin/wget.
xmlstarlet requires four libraries that aren't included in Solaris 10 so it's going to be trickier but of course, you can build them and then xmlstarlet from their respective source code.
Have a look there for information about what is needed: http://www.opencsw.org/packages/xmlstarlet
If you really don't want to compile the binaries, there is certainly a way to manually install the files stored on these Solaris packages elsewhere and patch/fix them to make the whole work. I did that already.
Finally, don't underestimate the willingness of the system administrator to help.
As long as the binary doesn't try to do something that requires superuser privileges and the binary is compiled for your platform, you should be ok.

Conditional sections in AIX Makefiles

How do I make a makefile that works on AIX, Linux and SunOS and has the ability to provide different compiler options for each environment?
I have access to an environment variable which describes the OS, but the AIX make utility does not like ifeq, so I can't do something like:
ifeq($(OS), AIX)
CFLAGS = $(CFLAGS) <IBM compiler options>
endif
You can use a construct like this:
CFLAGS_AIX = AIX flags
CFLAGS_Linux = Linux flags
CFLAGS_SunOS = SunOS flags
CFLAGS = $(CFLAGS_$(OS))
The portability of a Makefile is not directly related to the operating system, but to the implementation of make on the platform in question. (So there is an indirect relationship in that the implementation of make may be guessed (but NOT accurately) from the OS.) In general, this is a difficult problem for which many solutions have been proposed. You might want to look into automake, which will generate portable makefiles for you. However, automake's solution to the problem of setting flags for different unixen may not appeal to you as the solution is (basically) "don't do it". Rather than setting options based on the platform, the philosophy is to determine what flags are needed based on the functionality provided by the host or by the user at configure time. One convenient autoconf/automake based solution for the problem of assigning flags based on platform is to have a distinct file for each of your platforms which assigns CFLAGS at configure time, and have the file be specified in the CONFIG_SITE environment variable of the user running configure. You can assign CONFIG_SITE in the login script of the user based on the platform. (ie, push the problem away from configure/make and into the login setup) This makes the assignment transparent to the user building the software. (transparent but easily overridden).

Detecting CPU architecture (32bit / 64bit ) in scons?

Are there any 'standard' plugins for detecting the CPU architecture in scons?
BTW, this question was asked already here in a more general form... just wondering if anyone has already taken the time to incorporate this information into scons.
Using i386 is rather compiler dependant, and won't detect non x86 32 bits archs. Assuming the python interpreter used by scons runs on the CPU you are interested in (not always the case - think cross compilation), you can just use python itself.
import platform
print platform.machine()
print platform.architecture()
If you need something more sophisticated, then maybe you will have to write your own configure function - but it may be better to deal with it in your code directly.
Something like this?
env = Environment()
conf = Configure(env)
if conf.CheckDeclaration("__i386__"):
conf.Define("MY_ARCH", "blahblablah")
env = conf.Finish()

Resources