Compiling with scratchbox

From NAS-4220

Jump to: navigation, search

This is a translation by SilverstarX from the german tutorial by Hessijames


We start with a Debian GNU/Linux system.

As user root, we use the following command to make the scratchbox repository available:

 delta:~# echo 'deb http://scratchbox.org/debian/ stable main' >>/etc/apt/sources.list

In the next step we update the local packet list and install scratchbox:

 delta:~# apt-get update && apt-get install scratchbox-core scratchbox-devkit-debian scratchbox-libs scratchbox-devkit-cputransp scratchbox-toolchain-arm-linux-ct401-2.3

Answer the security question, if the packages should be installed without verification, with yes. Also, affirm the question if the scratchbox-group should be created, but negate the question if a user should be choosen for scratchbox.

Set up a user (here: pr) for the using of scratchbox:

 delta:~# /scratchbox/sbin/sbox_adduser pr

and get the output:

Add user pr to group 'sbox'? [yes/no] (yes): yes
Adding user `pr' to group `sbox' ...
Adding user pr to group sbox
Done.
Scratchbox user account for user pr added

Now log in as the new user and use the following command:

 pr@delta:~$ /scratchbox/login

Now you are welcomed with the life-story of scrathbox and a new promt:

  You dont have active target in scratchbox chroot.
  Please create one by running "sb-menu" before continuing
  
  
  Welcome to Scratchbox, the cross-compilation toolkit!
  
  Use 'sb-menu' to change your compilation target.
  See /scratchbox/doc/ for documentation.
  
  sb-conf: No current target
  [sbox-: ~] >

Now set up some settings:

  [sbox-: ~] > sb-menu

Choose Setup, NEW and type a name for your new target (target in scratchbox means a array of settings, like a profile). Your are now asked to choose some settings, the compiler arm-linux-ct401-2.3 and the devkit cputransp, then DONE. This is useful later, cause it enables you to run the compiled programs on your development system, although the architecture of the binaries (arm) aren't compatible with the hosts one (ix86). It's important, cause some bigger packages use the GNU autotools, which are checking, if a binary was created and can be run.

Answer the following question about the CPU-transparency method with qemu-arm-0.8.2-sb2. At the rootstrap-dialog choose no, but yes and OK when asked after installation of files. Now select the created target with yes

Your promt will now show this way (NAS is the name of your target, which you have specified before):

 [sbox-NAS: ~] >

Now it's time to compile your first program for the NAS. Start a editor:

 [sbox-NAS: ~] > nano hellonas.c

and add the following lines of programming art:

 #include <stdio.h>
 main()
 {
     printf ("Hello NAS!\n");
 }

Use Ctrl-X, yes and enter to save and quit the editor.

You compile the source by typing

 [sbox-NAS: ~] > cc hellonas.c -o hellonas

and check with

 [sbox-NAS: ~] > ./hellonas

if the CPU-transparency is working. You get the expected output:

 Hello NAS!

The created binary could be copied to and run on the NAS. In this case, it will happen by scp and ssh, which requires the ssh-server-packges on the NAS:

 [sbox-NAS: ~] > scp hellonas root@nas1:~
 root@nas1's password:
 hellonas                                      100% 7122     7.0KB/s   00:00
 [sbox-NAS: ~] > ssh root@nas1
 root@nas1's password:
 
 
 BusyBox v1.00-rc3 (2007.08.08-11:22+0000) Built-in shell (ash)
 Enter 'help' for a list of built-in commands.
 
 nas1> ./hellonas
 Hello NAS!
 nas1>

I wish you every success building new packages!

Personal tools
In other languages