| Version 77 (modified by Ben, 2 years ago) (diff) |
|---|
Developing your own applications
This guide is aimed at the complete beginner who would like to know how to develop their own applications for SHR. Taking the usual Hello World program as an example, it will use Vala as the programming language which should be familiar to Java developers.
It is assumed that the reader has already successfully built SHR using the instructions at Building SHR.
1. Creating a source folder
$ cd /path/to/shr/build $ mkdir myfirstapp $ cd myfirstapp
2. Writing Hello World in Vala
Create and enter a sub folder for the source:
$ mkdir src $ cd src
Create a file called myfirstapp.vala and insert the following text:
class Demo.HelloWorld : GLib.Object
{
public static int main(string[] args)
{
stdout.printf("Hello, World\n");
return 0;
}
}
More information about Vala can be found here: http://live.gnome.org/Vala/Tutorial
3. Set up autotools
Create a file called Makefile.am and insert the following text:
bin_PROGRAMS = myfirstapp AM_CFLAGS = $(DEPS_CFLAGS) AM_LIBS = $(DEPS_LIBS) $(DEPS_LIBS) AM_VALAFLAGS = --pkg "gio-2.0" --pkg "glib-2.0" myfirstapp_SOURCES = myfirstapp.vala myfirstapp_LDADD = $(INTI_LIBS) myfirstapp_LDFLAGS = $(AM_LIBS) clean: rm -f *.c *.o *.stamp
Go back to the previous folder:
$ cd ..
Create a file called Makefile.am and insert the following text:
SUBDIRS = src
Create a file called configure.ac and insert the following text:
AC_INIT([my_first_app],0.1) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/myfirstapp.vala]) AC_PROG_CC m4_pattern_allow AM_PROG_VALAC PKG_CHECK_MODULES([DEPS], [glib-2.0 gio-2.0]) AC_OUTPUT([Makefile src/Makefile])
Run the following commands:
$ aclocal $ autoconf $ touch AUTHORS NEWS README ChangeLog $ automake --add-missing
4. Add a bitbake recipe
Enter the third party recipes folder:
$ cd /path/to/shr/build/shr-unstable/openembedded/recipes/openmoko-3rdparty
Create a file called myfirstapp_0.1.bb and insert the following text:
DESCRIPTION = "A hello world program written in Vala"
PR = "r0"
S = "${WORKDIR}/myfirstapp"
SRC_URI = "file:///path/to/shr/build/myfirstapp"
inherit autotools vala
5. Build a package
$ cd /path/to/shr/build/shr-unstable $ . setup-env $ bitbake myfirstapp
You should find that you now have an ipk package like this: /path/to/shr/build/shr-unstable/tmp/deploy/ipk/armv4t/myfirstapp_0.1-r0.6_armv4t.ipk
In order to test your program, simply install this package on your phone and run "/usr/bin/myfirstapp".
