Porting software
From WhitixDoc
This is a guide to porting software to Whitix. The process currently requires an UNIX-like operating system such as Linux or FreeBSD to compile the application. Whitix is able to run many POSIX programs, provided the application is built specifically for it. Note that currently many POSIX features (such as signals, passwords and many network functions) don't have a corresponding Whitix layer, so not all the functionality of a typical UNIX-like operating system can be provided at the moment.
Contents |
Before you start
Check that Whitix provides the functionality the program requires. For example, porting a Linux-specific application (such as hdparm) will reqiure a lot of work on the kernel side, and those features may not be high on the to-do list of developers.
This guide currently details how to port a C application to Whitix that is compiled with gcc and built with GNU make. Porting programs written in other languages, like C++ or Python, has not yet been attempted. You may also want to announce an port attempt at the user mailing list (users@whitix.org) or developer mailing list (developers@whitix.org). Other users or developers may want to contribute to the effort.
Download
Porting a program to Whitix requires the source code of the operating system. You can download the Whitix source from either the Subversion repository, at svn://www.whitix.org/svn/projects/Whitix or the project website (The current version's source code is often older than the code available in the Subversion repository, so you may miss out on new features).
Download and extract the application source to the user/[application name] directory of your Whitix source tree. (Other configurations are possible, but are often less portable and may not build in other people's source trees). Ensure the source has extracted correctly before moving on.
Makefiles
C compiling
Since compiling applications in Whitix is currently not possible (due to a lack of developments tools like make), several alterations must be made to any Makefiles that compile C code. The following steps are required for code compilation (this does not include linking):
- CFLAGS changes. Since Whitix should not include the default C headers (for example, in Linux,
gccsets/usr/includeas the default directory), the following options should be added to aCFLAGSvariable somewhere in the Makefile:CFLAGS+= -fno-builtin -nostdlib -ffreestanding -fno-stack-protectorThe-fno-builtinoption disables gcc's builtin functions, that are usually linked in libgcc1.a (which is not available in a freestanding implementation).-fno-stack-protectordisables GCC's new stack protector (this may not apply to older versions of GCC), which requires builtin functions from GCC. - Includes. There are several include directories that describe the interfaces of various libraries. The following options should be added:
CFLAGS+= -I../librtl -I../libc/include -I../posix/includefor the runtime library, C library and POSIX library respectively. The exact directory reference may have to be altered, depending on the location of the application's source directory and Makefile.
Linking
The following flags should be added to LDFLAGS: -L../librtl -lrtl -L../libc -lstdc -L../posix -lposix -lpthread. You may also need to add -lm (the C math library, built in user/libc). Undefined references will be listed, so you may need to create some stub functions (or indeed write them, it's up to you) in the libc and posix libraries. You will also need to add -Wl,-I/Linker ../libc/init/init.o, which sets the correct name of the dynamic linker (if ld is called to link the program, you won't need the -Wl prefix), adds the _start function.
Installing
Most project makefiles have an install option, which typically copies the program and its data to parts of the Linux filesystem. This needs to be altered; a typical install command will have this layout:
cp <app name> ../../CdRoot/Applications cp <data> ../../CdRoot/Applications/<app name> #Optional
(Moving <app name> into the applications folder is a temporary measure; future versions of the Whitix kernel will support symbolic links in filesystems, and so /Applications/Burn will contain a link to each command-line application). If you've got this far, you've ported the application of your choice to Whitix. Thanks for doing so, and remember to post on the developer mailing list so we can congratulate you accordingly.
What next?
You can submit your application's port to the Whitix ports directory. Just e-mail the webmaster, Matthew Whitworth, at webmaster@whitix.org, and he'll place the gziped source package in the ports section of the Whitix.org website.