�Editor's Note
�IT Purchases
�Linux, But Which One?
�Virtual LANs
�Free Software - II
�Database Components
�Windows Security - I
�CISN Archive
�Questionnaire
�Send Feedback


Computing & Information Services Newsletter
Development Tools for Free Software
     
 

In the previous issue of CISN, the topic I have dealt with was Free Software. In this issue, I would like to give information about developement tools for free software and I am going to perform a sample software project.

You can develop free software on many different platforms with various different tools. My intention in this article is to talk about tools such as automake, autoconf, cvs. I am not, however, going to give information about visual tools such as Klyx, Glade.

Using the following command strings while installing programs on Linux operating systems have been a simple routine for many of us:

$ ./configure
$ make
$ make install

Though it definitely depends on the program we are going to install, it is possible for us to configure our installation at ./configure step. I think an examplary configuration will better illustrate my point. Let's provide an example with one of the mostly widely written programs; namely "helloworld".

- helloworld.c
-------------------------------
#include <stdio.h>

int main(int argc, char **argv) {

  printf("hello world\n");
  return 0;
}
-------------------------------

You will need the following command to compile this program. What you get as an outcome of this command is an executable file named "helloworld".

$ gcc -o helloworld helloworld.c

With the configure command as referred above, you can render your program configurable, and with the make command you can render your program compilable. The environment to develop such a program requires you to install autoconf and automake programs. Let us define the functions of these programs:

Autoconf: Autoconf is a tool for producing shell scripts that automatically configure software source code packages to adapt to many kinds of UNIX-like systems. Autoconf lists the system features that the program needs and creates a configuration script from a template file that checks the presence of each feature.

Automake: Automake is a tool for automatically generating Makefile file that is useful for compiling the program.

Let's continue with our example. If you would like to print the version info of the "helloworld" program on the screen, you can either choose to write it in "helloworld.c" source code file, or you can prefer to develop a program with autoconf/automake tools which will obtain this info via the configuration files. At this stage, you must create the files that autoconf and automake will use as indicated in the following example:

- configure.in
-------------------------------
AC_INIT(Makefile.am)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(helloworld,0.1)
AM_CONFIG_HEADER(config.h)
AC_PROG_INSTALL
AC_SUBST(INCLUDES)
AC_SUBST(VERSION)
AC_OUTPUT(Makefile)
-------------------------------

This file indicates that it will use a file named Makefile.am, it will create a config.h header file etc. To this file, you can add any information required for program compiling and you can indicate here the information on how to control the options you would like to see during configuration.

- acconfig.h
-------------------------------
#ifndef VERSION
#undef VERSION
#endif
-------------------------------

acconfig.h file is required to create the config.h file that we have mentioned in "configure.in" file.

- Makefile.am
-------------------------------
bin_PROGRAMS: helloworld
helloworld_SOURCES: helloworld.c
-------------------------------

We are indicating here the information about which source code file will be used as we are compiling the program with Makefile and the executable file that will be created.

- helloworld.c
-------------------------------
#include <stdio.h>
#include <config.h>

int main(int argc, char **argv) {

  char *version = VERSION;
  printf("hello world!! my version: %s\n", version);
  return 0;
}
-------------------------------

Finally, we perform the essential alterations on our source code and we fix our program so that it obtains the version info from "config.h" file. At present, we have only 4 files. The commands that should be run and the outcome of these commands are as follows.

-------------------------------
$ ls
acconfig.h   configure.in   helloworld.c   Makefile.am

$ aclocal
$ ls
acconfig.h   aclocal.m4   configure.in   helloworld.c   Makefile.am

$ autoheader
$ ls
acconfig.h   aclocal.m4   config.h.in   configure.in   helloworld.c   Makefile.am

$ autoconf
$ ls
acconfig.h   config.h.in   configure.in   Makefile.am
aclocal.m4   configure     helloworld.c

$ automake
automake: configure.in: required file `./install-sh' not found
automake: configure.in: required file `./mkinstalldirs' not found
automake: configure.in: required file `./missing' not found
automake: configure.in: required file `./config.guess' not found
automake: configure.in: required file `./config.sub' not found
automake: Makefile.am: required file `./INSTALL' not found
automake: Makefile.am: required file `./NEWS' not found
automake: Makefile.am: required file `./README' not found
automake: Makefile.am: required file `./COPYING' not found
automake: Makefile.am: required file `./AUTHORS' not found
automake: Makefile.am: required file `./ChangeLog' not found
$ ls
acconfig.h   config.h.in   configure.in   Makefile.am   stamp-h.in
aclocal.m4   configure     helloworld.c   Makefile.in

$ automake --add-missing
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'
automake: configure.in: installing `./config.guess'
automake: configure.in: installing `./config.sub'
automake: Makefile.am: installing `./INSTALL'
automake: Makefile.am: required file `./NEWS' not found
automake: Makefile.am: required file `./README' not found
automake: Makefile.am: installing `./COPYING'
automake: Makefile.am: required file `./AUTHORS' not found
automake: Makefile.am: required file `./ChangeLog' not found
$ ls
acconfig.h     config.h.in   configure.in   INSTALL       Makefile.in    stamp-h.in
aclocal.m4     config.sub    COPYING        install-sh    missing
config.guess   configure     helloworld.c   Makefile.am   mkinstalldirs
-------------------------------

The files such as "NEWS", "README", "AUTHORS" and "ChangeLog" that should be available in every software package must be prepared by the developer of the package.

If we configure our program with the following commands and then run the program,

$ ./configure
$ make

the following statements will be displayed:

$ ./helloworld
hello world!! my version: 0.1

In the normal course of developing new versions, the developer may need to restore the previous state of the files in the project. If you have recorded the different source code histories of your project under different directories, you may end up in a mess and may not easily find what you are looking for. However, restoring the state poses no difficulty if the history is kept under CVS.

CVS: CVS is a version control system. With the help of CVS, you can keep the record of previous states/history of your source codes. CVS keeps the different versions of the files in one file much the same way as in the differences maintained in the output of diff command; therefore it uses very little disc space. CVS server can either be on the computer where the software is developed or it can be on another computer.

-------------------------------
$ cvs -d:pserve
r:user@cvs_server:/cvs/cvsroot login
Logging in to :pserver:user@cvs_server:2401/cvs/cvsroot
CVS password:
$
-------------------------------

After logging on to the CVS server, we can send our files to CVS server.

-------------------------------
$ cvs import -m "helloworld project" helloworld yoyo start
L helloworld/install-sh
L helloworld/mkinstalldirs
L helloworld/missing
L helloworld/config.guess
L helloworld/config.sub
L helloworld/INSTALL
L helloworld/COPYING
N helloworld/aclocal.m4
N helloworld/helloworld.c
N helloworld/configure.in
N helloworld/acconfig.h
N helloworld/Makefile.am
N helloworld/configure
N helloworld/config.h.in
N helloworld/stamp-h.in
N helloworld/Makefile.in

No conflicts created by this import
$
-------------------------------

The process of sending the files in our project to CVS server is completed. If you would like to call back the files from CVS server in order to work on them, you need to do the following:

-------------------------------
$ cvs checkout helloworld
cvs server: Updating hel
loworld
U helloworld/Makefile.am
U helloworld/Makefile.in
U helloworld/acconfig.h
U helloworld/aclocal.m4
U helloworld/config.h.in
U helloworld/configure
U helloworld/configure.in
U helloworld/helloworld.c
U helloworld/stamp-h.in
-------------------------------

Let's continue to work on our example to see how we will incorporate an argument into our program during configuration with the "configure" command. If we want our program to print on the screen whether our program is compiled with "debug" option, we should change our files as in the following case:

- configure.in
-------------------------------
AC_INIT(Makefile.am)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(helloworld,0.2)
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
AC_PROG_INSTALL

debuger=no
AC_ARG_ENABLE(debug,
  [--enable-debug, enable debug data generation],
  debuger="$enableval")
if test x"$debuger" = x"yes"; then
  AC_DEFINE(DEBUG)
if

AC_SUBST(INCLUDES)
AC_SUBST(VERSION)
AC_OUTPUT(Makefile)
-------------------------------

- acconfig.h
-------------------------------
#ifndef VERSION
#un
def VERSION
#endif
#ifndef DEBUG
#undef DEBUG
#endif
-------------------------------

- helloworld.c
-------------------------------
#include
#include

int main(int argc, char **argv) {

  char *version = VERSION;
  #ifdef DEBUG
  printf("hello world - debug enabled!! my version: %s\n", version);
  #else
  printf("hello world!! my version: %s\n", version);
  #endif

  return 0;
}
-------------------------------

To render the changes workable/runnable, the commands aclocal, autoheader, autoconf, automake should be run as told above. Then we can compile our program.

-------------------------------
$ ./configure --enable-debug
$ make
$ ./helloworld
hello world - debug enabled!! my version: 0.2
$ ./configure
$ make
$ ./helloworld
hello world!! my version: 0.2
-------------------------------

As you may see, our program has obtained an option during the configuration which comes before compilation. This will be our version 0.2. You should perform the following commands, if you would like to keep this version under CVS repository:

-------------------------------
$ cvs commit helloworld.c
Checking in helloworld.c;
/cvs/cvsroot/helloworld/helloworld.c,v <-- helloworld.c
new revision: 1.2; previous revision: 1.1
done
$ cvs commit configure.in acconfig.h
Checking in configure.in;
/cvs/cvsroot/helloworld/configure.in,v <-- configure.in
new revision: 1.2; previous revision: 1.1
done
Checking in acconfig.h;
/cvs/cvsroot/helloworld/acconfig.h,v <-- acconfig.h
new revision: 1.2; previous revision: 1.1
done
-------------------------------

Now we are able to access to 1.1 or 1.2 versions of our files whenever we want.

As you are performing these processes, a text editor, which lets you to write down your comments and notes explaining the nature of your changes, will be displayed on the screen. These notes will be very helpful for future changes on these files.

Lastly, I would like to talk about a program called cvs2cl. cvs2cl, which is actaully a Perl shell script, automatically creates ChangeLog file that are available in releases. As it creates ChangeLog file, it uses the comments and notes about the changes on files as referred above.

-------------------------------
$ cvs2cl.pl -P
cvs server: Logging .
$ cat ChangeLog
2002-11-17 18:06 user

* acconfig.h, configure.in: necessary changes for debug option

2002-11-17 18:05 user

* helloworld.c: debug option enabled

2002-11-17 16:51 user

* Makefile.am, Makefile.in, acconfig.h, aclocal.m4, config.h.in,
configure, configure.in, helloworld.c, stamp-h.in: Initial revision

2002-11-17 16:51 user

* Makefile.am, Makefile.in, acconfig.h, aclocal.m4, config.h.in,
configure, configure.in, helloworld.c, stamp-h.in: helloworld
project
-------------------------------

My intention above was to make you acquainted with the free software development environment by providing a brief example. For those who are planning a software project; if you would like to develop and distribute according to the free software principles, I strongly recommend you to visit the site of Sourceforge and study the means made available there for free software developers.

Links:

http://www.sourceforge.net
http://www.gnu.org
http://www.freshmeat.net

Share and Enjoy!

Ahmet Öztürk

 
     
  - TOP -  
© 2002 METU CC
Design: CC - INFO