Tutorial: Develop an OK Linux Application
We are going to develop and deploy a simple application running on top of OK Linux.
Step 1: The Application
We will use this program :
# cat hello.c
int main(int ac, char *av[])
{
write (1, "Hello_World\n", 12);
return 0;
}With this Makefile:
# cat Makefile
all: hello
install:
install hello $(PREFIX)/bin
Step 2: Directory Structure
Our hello world program must go in linux/apps/[Application name]
# ls linux/apps/hello Makefile hello.c
Note: The folder's name is significant since we'll refer to it by this name in the build process.
Step 3: SCons
OKL4 uses SCons as its build system. Thus we will create a SConscript file to wrap our Makefile and link it to the whole building process.
#touch linux/apps/hello/Sconscript #ls linux/apps/hello/ Makefile SConscript hello.c
This SConscript will define the building and installation commands for our program. As with every SConscript, it is written with Python and includes the following steps:
- Environment variables importation.
- Build and install path definitions (respectively “build/linux/[App name]/”
- and “build/linux/install/”)
- Build and install commands definitions
- Install command return (which depends on the building command)
#cat linux/apps/hello/SConscript
Import("*")
import os
build_dir = Dir(env.builddir + "/hello").abspath
inst_dir = Dir(env.builddir + "/install").abspath
def b(file_name):
return os.path.join(build_dir, file_name)
def i(file_name):
return os.path.join(inst_dir, file_name)
env.scons_env["MAKE"] = "make"
hello = env.Command(b("hello"),
[] ,
"PREFIX=%s ZLIB=no $MAKE -j %d -C linux/apps/hello"
%(inst_dir, GetOption('num_jobs')))
hello_install = env.Command(i("bin/hello"),
hello,
"PREFIX=%s $MAKE -C linux/apps/hello install"
% (inst_dir))
Return("hello_install")
Step 4: Build
For our new program to be built we need to specify the command-line option linux_apps=[app name]. If, for example, we are building for a pc99 target we would use the following command:
# ./tools/build.py machine=ia32_pc99 project=iguana wombat=True linux_apps=hello
Note: the linux_apps parameter corresponds to the name of the folder containing the program (in this case hello)
Step 5: Run
# qemu -hda build/images/c.img -nographic [...] # hello Hello_World #
Step 6: Regeneration
When we modify our application we need to clean before rebuilding.
# rm -rf build
or
# ./tools/build.py -c machine=ia32_pc99 project=iguana wombat=True toolprefix=i686-unknown-linux-gnu- linux_apps=hello # ./tools/build.py machine=ia32_pc99 project=iguana wombat=True toolprefix=i686-unknown-linux-gnu- linux_apps=hello
Acknowledgment: Tutorial by Remy Gottschalk, via http://lists.okl4.org/pipermail/developer/2008-March/000831.html