| Version 89 (modified by Ben, 2 years ago) (diff) |
|---|
Creating a Hello World application
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. Setting 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 another file called Makefile.am and insert the following text:
SUBDIRS = src
Create a file called configure.ac and insert the following text:
AC_INIT([myfirstapp],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. Adding 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
Note: For building from local sources you can also use "inherit srctree" as it's used in conf/local-builds.conf
5. Building 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".
Graphical User Interface
Once you have successfully completed the steps above, you may wish to know how to add a Graphical User Interface (GUI). This section will show you how to do this using the Elementary widget set, which is utilised by the core SHR phone applications.
1. Creating a source folder
$ cd /path/to/shr/build $ mkdir myfirstgui $ cd myfirstgui
2. Writing a Hello World GUI in Vala and Elementary
Create and enter a sub folder for the source:
$ mkdir src $ cd src
Create a file called myfirstgui.vala and insert the following text:
using Elm;
private void win_del()
{
Elm.exit();
}
class Demo.HelloWorldGui : GLib.Object
{
public static int main(string[] args)
{
Elm.init(args);
Win win = new Win(null, "hello", WinType.BASIC);
win.title_set("Hello");
win.smart_callback_add("delete-request", win_del);
Bg bg = new Bg(win);
bg.size_hint_weight_set(1.0, 1.0);
win.resize_object_add(bg);
bg.show();
Label lb = new Label(win);
lb.label_set("Hello World!");
lb.size_hint_weight_set(1.0, 1.0);
win.resize_object_add(lb);
lb.show();
win.show();
Elm.run();
Elm.shutdown();
return 0;
}
}
More information about Elementary can be found here: http://trac.enlightenment.org/e/wiki/Elementary
