What is it that makes a GNU program a GNU program? What makes GNU software “better” than other (free or non-free) software? The most obvious difference is the GNU General Public License (GPL), which describes the distribution terms for GNU software. But this is usually not the reason you hear people saying “Get the GNU version of xyz, it's much better.” GNU software is usually more robust, and performs better, than standard Unix versions. We're going to look at some of the reasons why, and at the document that describes the principles of GNU software design.
The GNU Coding Standards describe how to write software for the GNU project. It covers a range of topics. As of this writing, related chapters are not grouped together, so we'll look at the chapters by topics, not in the order they appear.
You can find the GNU Coding Standards in the Autoconf distribution, currently autoconf-2.3.tar.gz, from your nearest GNU mirror site. An ASCII copy (standards.txt) should also be available as a standalone file from your nearest GNU mirror site, as well.
The first issue discussed has to do with intellectual ownership. If you're GOING to write a GNU program that re-implements a Unix utility, don't look at the Unix source code! (Source code licenses are harder and harder to get these days, so this is less of a problem than it was 10 years ago.) The other issue has to do with copyright assignment. If you're going to write or work on a GNU program, you have to either declare your work to be in the public domain, or assign the copyright in it to the FSF. (Small changes don't have to do this, so don't be scared off by this if you want to submit a bug fix. On the other hand, if you enhance GNU [cw]find[ecw] so that it can read cpio archive tapes, you probably would have to do paperwork. Even this is usually painless.)
You can, of course, write a program from scratch, release it under the GPL, and keep the copyright. You may also generate your own changes to a program for which the FSF owns the copyright, and distribute your version separately from the FSF's version, under the GPL. Assigning copyright to the FSF is only a necessity when you want your changes to be folded back into the main distribution of a GNU program.
A number of chapters provide general advice about program design. The four main issues are compatibility (with standards and Unix), what language to write in, whether to rely on non-standard features of other programs (in a word, “don't”), and what “portability” means.
Compatibility with ANSI, POSIX, and Berkeley Unix is an important goal. But it's not an overriding one. The general idea is to provide all necessary functionality, with command line switches to provide a strict ANSI or POSIX mode.
C is the preferred language for writing GNU software, since it is the most commonly available language. In the Unix world, ANSI C is only now becoming common (sad but true), so K&R C is still the most widely portable dialect. This is changing rapidly though, with C++ becoming more commonplace. One widely used GNU package written in C++ is groff (GNU troff). With GCC supporting C++, it has been my experience that installing groff is not difficult.
The standards state that portability is a bit of red herring. GNU utilities are ultimately intended to run on the GNU kernel with the GNU C library. But since the kernel isn't finished yet, and users are using GNU tools on non-GNU systems, portability is desirable, just not paramount. The standard recommends using Autoconf (about which I one day hope to write a column) for achieving portability among different Unix systems.
The next group of chapters provides general advice about program behavior. We will return to look at one of these chapters in detail, below. These chapters focuses on how to design your program, how error messages should be formatted, how to write libraries (make them reentrant), and standards for the command line interface.
Error message formatting is important, since several tools, notably Emacs, use the error messages to help you go straight to the point in the source file or data file where an error occurred.
GNU utilities should use a function named getopt_long for processing the command line. This function provides command line option parsing for both traditional Unix style options (gawk -F: ...) and GNU style long options (gawk --field-separator=: ...). All programs should provide --help and --version options, and when a long name is used in one program, it should be used the same way in other GNU programs. To this end, there is a rather exhaustive list of long options used by current GNU programs.
|Privacy Is Personal||Jul 02, 2015|
|July 2015 Issue of Linux Journal: Mobile||Jul 01, 2015|
|July 2015 Video Preview||Jul 01, 2015|
|PHP for Non-Developers||Jun 30, 2015|
|A Code Boot Camp for Underprivileged Kids||Jun 30, 2015|
|Comprehensive Identity Management and Audit for Red Hat Enterprise Linux||Jun 29, 2015|
- July 2015 Issue of Linux Journal: Mobile
- Privacy Is Personal
- PHP for Non-Developers
- Secure Server Deployments in Hostile Territory
- Linux Kernel 4.1 Released
- A Code Boot Camp for Underprivileged Kids
- Django Templates
- Comprehensive Identity Management and Audit for Red Hat Enterprise Linux
- Attack of the Drones
- Practical Books for the Most Technical People on the Planet