The Mer Wiki now uses your Mer user account and password (create account on https://bugs.merproject.org/)
Platform SDK and SB2
(→Vivaldi) |
|||
Line 161: | Line 161: | ||
=== Plasma Active === | === Plasma Active === | ||
+ | |||
+ | Plasma Active rootfs can be found here (built 25 March 2012) - https://img.merproject.org/images/web/vgrade/6-20120325-173308/plasmaactive-armv7l-c71-devel-rootfs.tar.bz2 | ||
=== Nemo Mobile === | === Nemo Mobile === |
Revision as of 18:02, 25 March 2012
The most straightforward way to use Scratchbox2 is within the Mer Platform SDK. This page will go through the steps of using SB2 to compile a simple program.
Contents |
Prerequisites
- A properly setup SDK
- Scratchbox2 pre-installed (see SB2 Installation if not)
- Your home directory is in /home/<username> (otherwise see directory mappings)
Create a simple C program
We'll use ~/src/hello.c as the location of our code.
mkdir ~/src cat <<EOF >~/src/hello.c #include <stdio.h> int main(int argc, char **argv) { printf("Hello World\n"); return 0; } EOF
And now to compile it:
sb2 gcc ~/src/hello.c -o ~/src/hello
This gets:
sb2: Error: Invalid target specified, aborting.
When sb2 runs it needs to know where to get header files and libraries and what architecture and cross-compiler to use. This is called a 'target'. SB2 can be configured to run against multiple named targets.
SB2 Setup
Target Preparation
A target is a rootfs that contains development files like headers, libraries and possibly programs. Notably it does *not* need to contain compilers, linkers etc.
Still running in the sdk we'll create a target in the recommended /srv/mer/targets/ area.
sudo mkdir -p /parentroot/srv/mer/targets sudo chown -R $USER /parentroot/srv/mer/targets
Now we need a kickstart file and then we can use mic to create the target
cd /tmp curl -O http://releases.merproject.org/releases/0.20120315.1/kickstarts/mer-core-armv7hl-xorg-basic-qmlviewer.ks sudo mic create fs mer-core-armv7hl-xorg-basic-qmlviewer.ks -o /parentroot/srv/mer/targets --pkgmgr=yum --arch armv7hl
(Note: if you use a kickstart with @BUILD_ID@ and use the --release= option to mic then mic creates a slightly different structure and your rootfs will end up in /parentroot/srv/mer/targets/<release>/images/<name> and you'll have to move it)
The final step is to make sure the rootfs is all owned by the user. SB2 uses fakeroot when needed and won't work if the target has root-owned files.
sudo chown -R $USER /parentroot/srv/mer/targets/*
This target could be any suitable rootfs such as a Nemo or PA rootfs.
Target Setup
To tell SB2 about the target we use sb2-init.
IMPORTANT : You must change directory to the target rootfs before running sb2-init.
cd /parentroot/srv/mer/targets/mer-core-armv7hl-xorg-basic-qmlviewer sb2-init -d -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / mer-core /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
We now need to work around bug #238:
echo -n "armv7hl-meego-linux" > etc/rpm/platform
And prepare the target for installation (all these steps will eventually be handled by a target preparation script or similar):
sb2 -t mer-core -m sdk-install -R rpm --rebuilddb sb2 -t mer-core -m sdk-install -R zypper ref --force
The target is now ready to be used by sb2.
Compile the simple C program
Again run:
sb2 gcc ~/src/hello.c -o ~/src/hello
This time:
~/src/hello.c:1:19: fatal error: stdio.h: No such file or directory
This is because the target has no development header files in it.
We need to be at the target root (this is bug #239) and then we can install some basic header files: Note the important use of the "-m sdk-install" and the "-R". The -m tells sb2 to use a mapping mode that permit the updating of the target and -R tells sb2 to run as fake root.
cd /parentroot/srv/mer/targets/mer-core-armv7hl-xorg-basic-qmlviewer sb2 -m sdk-install -R zypper in glibc-devel
You'll need to do this for any build requirements of your code.
SB2 Detailed setup information
The sb2-init options mean:
-d : make this the default target -L : linker options -C : compiler options -c : which qemu to use -m : which mapping to use by default -n : don't build libtool -N : don't do localisation for the target -t : the location of the build tools mer-core : The name of the target /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc : the cross-compiler to use
Alternate targets
N950 Nemo
To setup cross compiling for N950 (armv7hl) do the following inside the sdk chroot
Setup target
Extract the Nemo N950 rootfs as a target and set file permissions:
mkdir -p /srv/mer/targets/n950rootfs cd /srv/mer/targets/n950rootfs sudo tar xjvf /path/to/nemo-n950-image.tar.bz2 sudo chown -R $USER .
Initialize scratchbox2
cd /srv/mer/targets/n950rootfs sb2-init -L "--sysroot=/" -C "--sysroot=/" -c /usr/bin/qemu-arm-dynamic -m sdk-build -n -N -t / nemo-n950 /opt/cross/bin/armv7hl-meego-linux-gnueabi-gcc
The compiler should now work but you are still missing libraries to compile against. Install what you need into the n950 rootfs by
sb2 -m sdk-install -R zypper ref sb2 -m sdk-install -R zypper install ... (eg qt-devel)
If the installation fails due to permission errors give your user write permissions to the places the packages are being installed and retry. After this you can compile for example a c hello world by
cd cat << "EOF" > hello.c #include <stdio.h> int main(int argc, char **argv) { printf("Hello\n"); return 0; } EOF
To run a simple compile, tell sb2 what target to use (ie the name used in the sb2-init):
sb2 -t nemo-n950 gcc hello.c -o hello
Verify that the compilation worked
$ file hello hello: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.25, not stripped $ sb2 ./hello Hello
More typically you'll use
sb2 -t nemo-n950 make
Vivaldi
Place here any Vivaldi specific instructions for Plasma Active or Nemo development
Plasma Active
Plasma Active rootfs can be found here (built 25 March 2012) - https://img.merproject.org/images/web/vgrade/6-20120325-173308/plasmaactive-armv7l-c71-devel-rootfs.tar.bz2
Nemo Mobile
Additional Notes
Installation
If your SDK did not have the SB2 tools installed then you can do:
sudo zypper ar http://releases.merproject.org/releases/latest/builds/i486/cross mer-cross-tools sudo zypper ref sudo zypper in sdk-sb2-config qemu-usermode mpc cross-armv6l-gcc cross-armv6l-binutils cross-armv7l-gcc cross-armv7l-binutils cross-mipsel-gcc cross-mipsel-binutils cross-armv7hl-gcc cross-armv7hl-binutils
Directory Mappings
SB2 uses a sophisticated file mapping system to access the right tools and the right source code. The definitions are stored in /usr/share/scratchbox2/modes/sdk-build/fs_rules.lua
The current SDK definitions recognises a few filesystems:
/home /mer /maemo /everything
Additional entries can be made if your source lives elsewhere (eg /media or /data etc).