| Version 67 (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. Using the familiar Hello World program as an example, it will use Vala as the programming language as this should be familiar and easy to understand for people with Java experience.
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
Go back to the previous folder:
$ cd ..
Create a file called Makefile.am and insert the following text:
SUBDIRS = src
Now go to the source folder once again:
$ cd src
Create another 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 top level folder:
$ cd ..
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
Create a file called myfirstapp.bb and insert the following text:
DESCRIPTION = "A hello world program written in Vala"
SRCREV_pn-${PN} = "${AUTOREV}"
PV = "0.1"
PR = "r0"
S = "${WORKDIR}/myfirstapp"
SRC_URI = "file:///path/to/shr/build/myfirstapp"
inherit autotools vala
5. Build a package
$ cd shr-unstable $ . setup-env $ bitbake -b /path/to/shr/build/myfirstapp/myfirstapp.bb
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 you program, simply install this package on your phone and run "/usr/bin/myfirstapp".
