|
HOWTO: write programs
Page update November 18, 2010
Puppy Linux is a tiny distribution, but there is a wide choice of
programming languages.
The default live-CD is not setup for compiling programs, however there is an add-on 'devx' file that turns
Puppy into a complete compiling environment. The add-on file also provides Python. Without the add-on, Puppy already has
Ash/Bash and Perl scripting languages. This page has a summary of
the programming options in Puppy...
Ash/Bash scripts
A language that is all ready for action in Puppy is command-shell
scripting. Unix and Linux shell command-scripting has been around for
ages and is going to be around for a long time to come. What I mean by the
"command shell" is the user interface that you use when at the commandline.
When you are running X, the commandline will be in a terminal window, but
you can also exit from X and be back at a commandline.
The actual program that is running and doing the interacting with you is
known as the command-shell, and for Linux it is usually what is known as the
Bash shell. In Puppy, you have a choice of two shells, Bash or Ash.
Note that when a terminal window is opened in X, Bash is running. If
you exit from X to the commandline, Ash is running. You can explicitly
choose either Bash or Ash in a script by placing "#!/bin/bash" or
"#!/bin/sh" (or "#!/bin/ash") on the first line.
A shell script is an executable program, except that it is a text file and
does not have to be compiled. Shell scripts can be very sophisticated, and
there are lots of them in Puppy.
This page is not a tutorial on how to program with Ash/Bash scripts --there
are plenty of books on the subject and also on the Internet. There are a
couple of Bash scripting HOWTOs to be found here:
"Advanced Bash-Scripting Guide": http://www.tldp.org/LDP/abs/html/index.html
"Bash Programming - Introduction HOWTO": http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
To write a Ash/Bash script, all you need is a text editor, and Puppy has two
console editors, e3 and MP, and two GUI editors, Geany
and NicoEdit. Geany, NicoEdit and MP have
color syntax highlighting for Bash/Ash scripts.
Have fun, write a script for Puppy!
Here is an overview of tools to aid with scripting, with links to online docs:
e3, mp, NicoEdit,
Geany
|
Text editors
|
Ash , Bash
|
Command shells used in Puppy
|
BusyBox
|
A
suite of basic Unix/Linux console applications, can be used in scripts.
Puppy uses many of these, although in many cases the "full" program is
used as the Busybox applet lacks the required functionality.
|
Xdialog
|
A GTK GUI frontend for scripts
|
xmessage
|
A very basic X11 GUI dialog frontend for scripts
|
xclip
|
A console application for cut-to and paste-from the
clipboard or X-selections (primary or secondary). Can be used in scripts.
|
gtkdialog3
|
This is yet another alternative to xmessage
and Xdialog. Gtkdialog is a GTK2 application and reads an XML file
that describes the dialog format and user interaction, allowing
incredible sophisticated GUIs. I think that gtkdialog is the pick of the bunch!
Note that Puppy currently has two versions of gtkdialog, named
gtkdialog2 and gtkdialog3 -- it is preferred that you use the latter as
this will eventually be the only one in Puppy -- in other words, always
execute the binary "gtkdialog3".
Note, the user manual for gtkdialog3 is rudimentary, but the 'devx'
module has many example programs at /usr/share/doc/gtkdialog3/examples in Puppy.
Forum member 'zigbert' has a nice tutorial with tips on how to use gtkdialog: GtkDialog tips.
|
yaf-splash
|
A more powerful alternative to xmessage. There are two flavours, the original yaf-splash and our re-written enhanced yaf-splash. Note that they have the same filename but the original is always to be found at /usr/X11R7/bin.
|
Here are some scripts used in Puppy:
/usr/sbin/pmount
/usr/sbin/timezone-set
C/C++ programming
All of the tools for compiling C/C++ applications are to be found in an add-on file named *devx*.sfs (* denotes optional extra text used to describe release version ec.). This is what we call an SFS file, and you can read an overview of these online in this page: http://puppylinux.com/development/package-management.htm
To use this file is very simple. Download it from the Internet (it is
about 90MB) and save to /mnt/home (the same place as the "pupsave.2fs" file, that is, your saved session).
Or, if you have installed Puppy to hard drive with what we call a
"full" installation (Puppy occupying his own partition, no
ramdisk), then download the *devx*.sfs file ...then some manual steps are required, see here: http://www.puppylinux.com/hard-puppy.htm.
After downloading *devx*.sfs and placing it in the right place, reboot Puppy, and that's it, you're ready to go.
All of the normal compiling tools work, such as "configure" and "make".
Note, it is necessary that the PC have either a Linux swap partition and/or a lot
of RAM. C/C++ compiling needs a lot of temporary space.
It is also recommended that you place the source package (that you want to compile) in a mounted
Linux partition, not in /root. This is in the case of running from a
live-CD or a frugal install, in which '/' is actually a layered
filesystem. A layered filesystem sometimes causes problems with
compiling, so it is recommended to mount a hard drive partition for the
purpose -- a Linux partition, not a DOS/Windows partition!
If you compile a package and would like to make it available for others
to use, it is very easy to create a PET package -- read this: http://www.puppylinux.com/development/createpet.htm
If you want to write GTK applications, the 'devx' file also has
'glade-3'. This is a visual GUI-builder. Find out more about Glade
here: http://glade.gnome.org/
The 'glade-3' program generates an XML file, and Puppy has 'libglade',
a library that an application uses to read the XML file and generate
the GUI.
Note, gtkdialog3 is also able to load a Glade XML file. See the
gtkdialog3 examples at /usr/share/doc/gtkdialog/examples, provided by
the 'devx' file. So, even a Bash script can utilise Glade.
Vala/Genie programming
This is the future. Vala and Genie are languages
in every respect superior to C/C++. Vala has a C#-like syntax, Genie
has a Python-like syntax. It is actually the same compiler, it just
accepts two alternative syntaxes.
Vala/Genie is a true compiler environment and generates extremely
efficient executables. They are particularly nice for writing GTK
applications. I have placed the Vala/Genie compiler, with documentation
and the ValaIDE, in the 'devx' SFS file.
Online documentation on Vala/Genie is here:
http://bkhome.org/genie/index.html
The ValaIDE is an Integrated Development Environment, with a text
editor that has colour syntax highlghting for both Vala and Genie. If
the 'devx' SFS file is loaded, you will find an entry for ValaIDE in
the 'Utility' menu.
Note that the NicoEdit text editor also has syntax highlighting for
Vala and Genie. The Geany text editor has syntax highlighting for Vala
but not Genie.
Also if the 'devx' sfs file is loaded you will find the Vala Reference Manual at /usr/share/devhelp/books/vala/index.html.
You can find
some exciting new applications on the Puppy forum, that are gradually
finding their way into the official Puppy live-CD.
Nicholas's NicoEdit text editor is one example, a GTK application
written in
Genie. It doesn't stop there, Mark has written PuppyBrowser,
EmbeddedBookmarks and Pictureviewer in Genie.
BaCon programming
BaCon is a structured-BASIC compiler ....what! ...why are we promoting
a 1970's programming language? Sometimes older and simpler is actually better.
BaCon is very easy to learn and get productive in a very short time. It
is also one of the easiest ways to write GTK GUI applications, using
HUG (Highlevel Universal GUI).
The main reason that you would write a program in a compilable language
is due to very much faster execution speed compared with a shell
script. It also gives you ready access to all the shared libraries,
which you can't really call from a script.
I have created an introductory page, with links to everything you need to know:
http://bkhome.org/bacon/
The author of BaCon is Peter van Eerten, and this is his project home:
http://www.basic-converter.org/
When you have the 'devx' SFS file loaded, you will find documentation and .bac include files in /usr/share/BaCon.
© Copyright Barry Kauler 2010 bkhome.org All rights reserved
See FAQ for legal statement.
|