
| Sample Code |
Introduction
If there is an application that needs to work on both mobile and non-mobile platforms, besides adding appropriate pre-processor symbols around platform-specific code, the compiling process should be different for different platforms. This document gives an overview of GNU Autotools and specifies the process of using GNU Autotools to enable the compiling switch among different platforms. The document also describes how to check the build architecture to automatically compile properly, when creating debian packages.
This document assumes that the reader is familiar with the following:
This document contains two main sections:
Introduction to Makefile
When a software project becomes larger and more complicated, it is
almost impossible to compile source code and install binaries by manually
inputing single commands, one-by-one. The GNU make utility is introduced
to control the compilation of the project, automatically determine which
pieces of a large program need to be recompiled, and issue the commands
to recompile them[1].
To prepare to use make, you must write a file called the Makefile to tell make how to compile and link a program. It describes the relationships among files in your program and provides commands for updating each file[1].
The content of a Makefile can become very complex considering the complexity of the project. Detailed information on how to write a Makefile and run make can be found at http://www.gnu.org/software/make/manual/make.html.
Using GNU Autotools
Although Makefiles are very powerful (especially when using pkg-config),
they run against limitations in the following situations
The GNU Autotools (Automake, Autoconf, etc.) provide a powerful configuration and compilation system to avoid the limitations brought by the above situations.
Two main tools of GNU Autotools are Autoconf and Automake.
The general procedure for outfitting your source code and generating Makefiles with the GNU Autotools is as follows.
Here is the flow diagram of the above procedure.

Compiling Switch among Platforms
Modifying configure.ac and Makefile.am
To enable the application to work on both mobile and non-mobile platforms, the user needs to add the appropriate pre-processor symbols around platform specific code, besides, Makefile needs to be modified (such as compiling rules, installing rules, etc.) before building the application on the target platform. The changes to Makefile can be made automatically by modifying configure.ac & Makefile.am when using GNU Autotools to generate Makefile.
Before following this example, you need to configure the development environment. We recommend that you develop in the target device's build-environment, which can be created using Moblin Image Creator. This SDK includes guides on installing and using Moblin Image Creator.
You can download a our sample
hello world application from
here. We will use this to describe the process. By supporting Hildon for Moblin platform and GTK+
for desktop platform in the code, this application can run on both
platforms.
# Enables '--enable-hildon' argument.
AC_ARG_ENABLE(hildon,
[AC_HELP_STRING([--enable-hildon],
[compile with Hildon-based internet tablet user interface (default: enabled)])],
enable_hildon="$enableval",
enable_hildon="yes")
Here is the related code in configure.ac,
# Checks for hildon libraries.
HILDON_REQUIRED=1.0.5
if test "x$enable_hildon" = "xyes"; then
# Check hildon libraries
PKG_CHECK_MODULES(HILDON,
[
hildon-1 >= $HILDON_REQUIRED
libosso
])
# Define USE_HILDON
AC_DEFINE(USE_HILDON, 1, [Define if we're using hildon])
# Add hildon specific preprocessor, compile & link flags
CFLAGS="$CFLAGS $HILDON_CFLAGS"
LIBS="$LIBS $HILDON_LIBS"
# Define a conditional USE_HILDON for the use in Makefile.am
AM_CONDITIONAL(USE_HILDON, [test "x$enable_hildon" = "xyes"])
Here, USE_HILDON is the conditonal name which will be used in Makefile.am.
if USE_HILDON
# Generate the service file and set its install path
servicedir = $(datadir)/dbus-1/services
service_in_files = org.moblin.helloworld.service.in
service_DATA = $(service_in_files:.service.in=.service)
# Rules to generate the service file
org.moblin.helloworld.service: org.moblin.helloworld.service.in Makefile
@sed -e "s|\@bindir\@|$(bindir)|" $< > $@
BUILT_SOURCES = org.moblin.helloworld.service
endif
...
if USE_HILDON
# Add the additional clean rule of the generated service file
CLEANFILES = $(BUILT_SOURCES)
endif
if USE_HILDON
# Set the desktop file install path
desktopdir = $(datadir)/applications
desktop_DATA = hello-world.desktop
endif
if USE_HILDON
# Set the icon file install path
icondir = $(datadir)/icons/hicolor/16x16/apps
icon_DATA = hello-world.png
endif
Checking Build Architecture when Creating Debian Packages
When creating debian packages of applications, for example, hello-world, you can check the build architecture of the application first, so that you can automatically decide whether to use the argument --enable-hildon of the configure script or not.
One way to check the build architecture is to add similar judgment, as follows, into the file debian/rules of hello-world:
Thus, if running dpkg-buildpackage to create the debian package of hello-world on Moblin platform, whose architecture is lpia (Low Power Intel Architecture), it will use the argument --enable-hildon when running the configure script, and finally generate a Hildon-based application binary hello-world. Else, the argument --disable-hildon will be used, and a GTK+-based hello-world will be built.
Reference Documents
The following documents are used as references in the writing of this document. Please refer to these documents for further details.
Intel is a trademark of Intel Corporation in the U.S. and other countries.
Linux is a registered trademark of Linus Torvalds.
* Other names and brands may be claimed as the property of others