Configuring the Application Development Environment
Embedding Python
To use Python in an embedded
project, you must build the Python virtual machine for the target. That virtual
machine is built with a cross-compiler. To build Python, you need a
cross-compiler built as explained in the previous chapter with the glibc
library, but you can’t use the uClibc C library to build the Python virtual
machine. First, obtain and download the source code:
$ wget http://www.python.org/ftp/python/<version>/Python-<version>.tgz
$ tar xzf Python-<version>.tgz
You can find the list of current
Python releases at http://www.python.org/download/releases/.
The latest version of Python is
3.2.1. The 3.0 line of Python contains enough new features that some older code
written for Python 2.x won’t compile or run, and this has stopped users from
switching. Because the 2.x line of Python is more popular, version 2.6.2 is
used as the example version. After unpacking the code, change directories into
the source directory and use the configure command to set up the build
environment:
$ cd ./Python-<version>
$ CC=<compiler> ./configure –prefix=<board-rfs>
$ make
$ make install
Change <board-rfs> to the
directory containing the board’s root file system, because this is a
directory on the development host
before it’s readied for deployment on the board. The build process chugs along
and produces a working Python virtual machine.
Embedding TCL
You can obtain the software for
TCL at http://www.tcl.tk/software/tcltk/download.html.
Download the source, and perform
a cross-build using these steps:
$ tar xzf tcl<version>-src.tar.gz
$ cd tcl<version>/unix
$ export tcl_cv_strtod_buggy=1
$ export ac_cv_func_strtod=yes
$ CC=<cross-compiler> ./configure –prefix=<board-rfs>
$ make
$ make install
This compiles TCL with the
cross-compiler and puts the resulting code in the board’s root file system.
These two commands
$ export tcl_cv_strtod_buggy=1
$ export ac_cv_func_strtod=yes
To run this code, save it in a
file such as aprogram.tcl and do the following:
$ tcl<version> aprogram.tcl
Generally, you’ll put the
following at the top of a TCL script and mark the file as executable:
#!/usr/bin/tclsh Use this command
to make the file executable:
$ chmod +x aprogram.tcl
When the file is marked as
executable, Linux examines this first line, \ runs the program following the #!
(called hash bang), and then changes the standard input of the following
program to the rest of the current file. That means you can execute the program
by running it from the command line like a binary:
$ ./aprogram
PHP
PHP is a good language for
embedded development for the same reasons it’s popular for web
development: it’s a stable,
feature-rich environment that’s very easy to use. PHP has mix of object
oriented and procedural idioms, and you’re free to pick a mix of what’s best
for your project and your personal preferences. PHP has an extensive list of
built-in functions, and these are a prime reason to use the language. The standard
library for PHP contains functions for networking, handling arrays, and parsing
regular expressions and also has great support for MySQL and PostgreSQL. This
makes it an ideal tool for applications that interact with a database. PHP is a
well-supported language with a large and growing number of extensions.
To experiment with PHP from the
command line, install the PHP command-line client by
doing the following:
$ sudo apt-get install php5-cli
Use this if your system is RPM
based:
$ sudo yum install php5-cli
This installs a program on the
system that you can use to run PHP scripts in the following fashion:
php hello.php
The PHP script can also begin
with a #!/usr/bin/php so you can run the program directly from the command-line.
For example, this code.
#!/usr/bin/php
<?php
function info($something='') {
print $something;
}
print "Hello there";
?>
can be executed by doing the
following to make the file executable
$ chmod +x ./test.php
and then running it from the
command line:
$ ./test.php
Embedding PHP
You can cross-compile PHP by
obtaining the source code from http://www.php.net/downloads.php. This page
contains a list of mirrors to pick from; use the mirror closest to your location:
$ wget ftp://xmlsoft.org/libxml2/libxml2-2.6.30.tar.gz
$ tar xzf libxml2-2.6.30.tar.gz
$ CC=powerpc-405-linux-gnu-gcc ./configure --host=powerpc-linux-gnu--disable-all
--enable-cli
Mpatrol
Mpatrol is a lightweight
memory-leak detection tool that’s been around for nearly ten years. It works
the same way as dmalloc: the malloc and free functions are overridden, and the
system tracks what’s been requested versus what’s been relinquished. Mpatrol
supported on x86 and some PowerPC platforms. The lack of support for ARM means
that many embedded engineers can’t use mpatrol. To obtain mpatrol, visit this
site, download the source tar file, unpack it, and do the following:
$ cd mpatrol/pkg/auto
$ ./setup
$ export ac_cv_func_setvbuf_reversed='no'
$ CC=powerpc-405-linux-gnu-gcc ./configure --build=powerpc-linux-gnu –
prefix=/tmp/board-dev
$ make
$ make install
The mpatrol library is installed
into the /tmp/board-dev directory. To compile a program with
mpatrol support, you need to add
some additional libraries to the command line. These libraries are part of a
glibc installation:
$(CC) -I/usr/local/include -L/tmp/board-dev/lib -lmpatrol -lbfd-liberty
-lintl
No comments:
Post a Comment