[okl4-developer] Linux hello_world howto

Abi Nourai anourai at ok-labs.com
Wed Mar 26 22:50:50 EST 2008


Great work Remy !

One of the things the gang here at OK is looking forward to doing  
(very soon) is starting and maintaining a technical FAQ for the  
mailing list.  What you put together would make a great candidate for  
that IMHO.

Thanks again,
Abi

On 26/03/2008, at 1:07 AM, Remy Gottschalk wrote:
> In my quest in understanding the OKL4 project I've done the following
> howto. Since it may be useful to some other people i am posting it. Of
> course it is mainly a rewrite of what was posted in the mailing list  
> but
> it may be a little more convenient this way. Of course fell free to
> correct or ameliorate this. (It worked for me so it shouldn't be so  
> wrong
> :) )
>
>
> -----------------
> Linux Hello world
> -----------------
>
> We are going to integrate a simple application running on to of the
> paravirtualized Linux to the OKL4 framework. We want to make it  
> built and
> put in the final image by SCons when we call build.py.
>
> 1 The program
>
> 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
>
> 2 The 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 pretty important since we'll use it when
> finally building.
>
> 3 SCons
>
> OKL4's framework use SCons as building environment. 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
>
>
> 4 SConscript
>
> This script will define the building and installation commands for our
> program. As every SCons script it is written with Python.
> It 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")
>
> 5 Building
>
> For our new program to be built we need to specify the option
> linux_apps=[app name]. When building for a pc99 target we have the
> following command :
>
> # ./tools/build.py machine=ia32_pc99 project=iguana wombat=True
> toolprefix=i686-unknown-linux-gnu- linux_apps=hello
>
> Note : linux_apps's parameter correspond in fact to the folder's name
> which contain out program (in this case hello)
>
> 6 Say hello
>
> # qemu -hda build/images/c.img -nographic
> [...]
> # hello
> Hello_World
> #
>
> 7 Regeneration
>
> Even when integrated this way we still got some problem for  
> regenerating
> the final image when our hello world is modified. Thus 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
> and then
> # ./tools/build.py machine=ia32_pc99 project=iguana wombat=True
> toolprefix=i686-unknown-linux-gnu- linux_apps=hello
>
>
> _______________________________________________
> Developer mailing list
> Developer at okl4.org
> https://lists.okl4.org/mailman/listinfo/developer
>




More information about the Developer mailing list