slitaz-doc-wiki-data view pages/en/handbook/development.txt @ rev 7

Add pages/en folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Feb 26 12:17:18 2011 +0000 (2011-02-26)
parents
children 7f77649ceb97
line source
1 ====== Development ======
3 ===== About Development =====
5 SliTaz provides development tools for web design, editing scripts and source code. On the website, the Development page will give you general information about the developers and opportunities for involvement.
7 ===== SHell scripts =====
9 Writing SHell scripts is the easiest way to start coding, they can provide quick results and the only prerequisites are being able to open a terminal and using a text editor such as Nano, Leafpad or Geany. SHell scripts can do many things on a GNU/Linux system - initialize the system, make backups, perform repetitive tasks, display system information, create or modify files and so on. In a SHell script you can use variables, functions or calls to include a file. Note that you can name your script as you see fit and the .sh extension is widely used.
11 === Create a SHell script ===
13 Before starting a new SHell script, you must pay attention to the interpreter used. Most SHell scripts use ///bin/sh//, because it's more portable, but there are scripts that rely on ///bin/bash// and this must be installed on the system. For a SHell script to function it must be made executable by changing permissions on the command line using the chmod tool. To create a script.sh and make it executable:
15 <code> $ touch script.sh
16 $ chmod +x script.sh
17 </code>
19 Now that you have a new executable file, you can edit it. You can continue to stay in the terminal and use the Nano editor (Ctrl + x to save & exit) or IDE Geany to edit:
21 <code>
22 $ nano script.sh
23 Or :
24 $ geany script.sh &
25 </code>
27 Here's a script that contains a variable NAME and displays the value with the echo command:
29 <file>
30 #!/bin/sh
32 NAME="kayam"
34 echo "$NAME is nice."
35 </file>
37 Once you have created/modified your script.sh, you can execute it to see the result:
39 <code> $ ./script.sh </code>
41 So much for this brief introduction to SHell scripts. The Web is full of information if you wish to explore further.
43 ===== Dialog =====
45 Dialog can create GUI-based consoles such as the SliTaz 'installer'. The configuration files are ///etc/dialogrc// and/or //~/dialogrc// for each user. Here's a simple example of using dialog via a console or terminal:
47 <code> $ dialog --title "Hello $USER" \
48 --msgbox "Message made by dialog." 5 54 </code>
50 You can find plenty of example scripts in the ///sample// directory inside the source code of dialog which can be downloaded from: http://invisible-island.net/dialog/dialog.html. Download sources and decompress:
52 <code> $ wget ftp://invisible-island.net/dialog/dialog.tar.gz
53 $ tar xzf dialog.tar.gz
54 </code>
56 ===== Geany IDE =====
58 Geany is an IDE or Integrated Development Environment. Geany is simple, quick and light, offering colored syntax, tabs and auto completion. Geany was used to create this page and most of the website documentation (with a little bit of Nano as well).
60 === Launch Geany ===
62 You will find Geany in the //menu --> Development --> Geany//. Once launched for the first time, you can adjust your preferences via Edit --> Preferences. You can also launch Geany via a terminal:
64 <code> $ geany & </code>
66 Note when compiling the source code, the ./configure script offers the option: //-enable-the-force//... Which you can use if you ever feel the need to become Luke Skywalker!
68 ===== Perl or Microperl - Code/use Perl scripts =====
70 On SliTaz you can use the powerful scripting language Perl via the perl or microperl binary. Microperl is a streamlined version of perl compiled from official sources, Perl scripts running Microperl are compatible with the complete version of Perl. One of Perl's strengths is its portability, it can be used on any system and it's an interpreted language, which means that the code doesn't need to be compiled and can be used directly. On SliTaz, Perl and Microperl are not installed by default on the LiveCD: you can either rebuild your ISO or install through the package manager. Note: Microperl is only 1 MB and provides no modules:
72 <code>
73 # tazpkg install perl
74 Or :
75 # tazpkg install microperl
76 </code>
78 === Hello world! ===
80 The purpose of this script is to display Hello World. You can start by creating the file and making it executable on the command line and then editing with IDE Geany. Note the script is called hello.pl, but you can name it as you see fit, with or without the .pl extension:
82 <code>
83 $ touch hello.pl
84 $ chmod +x hello.pl
85 $ geany hello.pl &
86 </code>
88 The first line of a Perl script begins by defining the path to the Perl interpreter, usually ///usr/bin/perl// and to display text, just use the print command. It should be noted that Perl is case sensitive and a line of code should always end with a semicolon. Example code (you can copy and paste):
90 <file>
91 #!/usr/bin/perl
92 #
94 print "Hello World!\n";
96 </file>
97 To execute and test the script:
99 <code> $ ./hello.pl </code>
101 === CGI Scripts and Perl ===
103 CGI scripts are designed to display dynamically generated web pages. The Perl language associated with the LightTPD web server allows you to use CGI scripts through your public space or via virtual hosts. Perl is quite adapted to Web 2.0 and can generate xHTML pages. On SliTaz you must have Perl or Microperl installed and the LightTPD server configured before you can use CGI scripts coded in Perl. Note that by default SHell scripts (.sh) can be placed in /cgi-bin/.
105 Once the server is properly configured, you can put your CGI in your //$HOME/Public/cgi-bin// using the //.pl// or //.cgi// extension and view them either locally or remotely. Example of using a Perl CGI script:
107 <file>
108 #!/usr/bin/perl
109 #
110 print "content-type : text/html\n\n";
112 print "Hello World!\n";
113 </file>
115 ===== Python =====
117 The Python programming language is available as an installable package. Once installed, you can create your own scripts/programs and use CGI applications with the LightTPD web server, taking care to configure the server properly. The official SliTaz Mercurial repositories are provided by a CGI/Python web interface - a solution suited to a product that's reliable and robust. To install the python package with tazpkg:
119 <code> # tazpkg get-install python </code>
121 ===== Ruby =====
123 The Ruby programming language is available as an installable package. Ruby is (to quote the official website):- "A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write". Ruby handles exceptions, supports Object-Orientated Programming (OOP), automatic memory management and is highly portable. To install the ruby package with tazpkg:
125 <code> # tazpkg get-install ruby </code>
127 ===== Toolchain - Libraries, C compiler and tools =====
129 To compile software from sources or your own code, you need at least the basic toolchain, comprising of Binutils, Glibc, C compiler, Kernel headers and the Make utility. Note that the toolchain is used by the SliTaz developers to compile the entire system from source. To install the meta package and all dependencies:
131 <code> # tazpkg get-install slitaz-toolchain </code>
133 The installation of the toolchain can now compile basic applications in console mode without a problem using the Busybox Ash SHell, but some other packages will not compile without Bash. GNU Bash is available as a package along with various other development tools such as Flex, M4, Bison or Pkg-config. If you are looking for pkg-config for example:
135 <code> $ tazpkg search pkg-config </code>
137 If you would like to compile applications utilizing the Ncurses library, you must install the ncurses-dev package. Note the ncurses package also provides a variety of small programs such as tic or tac:
139 <code> $ tazpkg search ncurses </code>