Back to TOC Unix


Motif Programming with the LessTif Freeware Library

Cameron Laird and Kathryn Soraiz

Here's a way to get your feet wet with Motif without taking a bath.


Would you like to become a Motif developer? No problem. You can have the power of the industry's leading Unix graphical user interface (GUI) toolkit today, and you can have it for free. If you're a Unix programmer, Motif's ability to build GUIs will help on that application you're working on. Motif is built for people who want a lot of control over their applications. It allows precise control of colors and fonts. Using Motif lets you mix foreign language characters in your displays. It provides flexible and accurate drawing primitives. It's powerful, reliable, and offers you a lot of choices.

Even given the above, many Unix programmers still shy away from Motif, and there are a couple of good reasons: first, there is confusion among developers about what Motif is and does. We cover that below. Second, many find Motif's licensing fee prohibitive. We show how to jump that hurdle, too. So if you have an aversion to Motif and you'd like to get rid of it, read on.

Origin of Motif

Motif was developed by The Boston-based Open Software Foundation (OSF) in 1989. Since then, it has become the standard, and most often identified, GUI toolkit for Unix. Motif is not the only GUI toolkit for Unix. There are over a dozen other toolkits available, including XView, Tk, Visual Tcl, and Qt. Each of these has survived to this day by virtue of its unique strengths. But none of these toolkits matches the popularity of Motif.

In 1989 the OSF released the Motif Style Guide, a set of user interface guidelines. The Style Guide included a library of widgets, called the Motif Toolkit, which implement the guideline's "look and feel."

Most Unix vendors now bundle Motif with their products, in the form of a library called Xm. Vendors pass on the OSF's fee in the price of their operating system. Motif is not available directly from the OSF. It must be purchased bundled from a hardware company or from one of several independent software vendors (ISVs).

ISVs sell and support some fine implementations of Motif, including releases for free operating systems such as Linux and FreeBSD. This sometimes puzzles newcomers to the free software world, so it's important to make a distinction: Linux is available at no charge; however, some of the software it runs, including the Motif user interface toolkit, can be obtained legally only via purchase.

Motif: Confusions and Clarifications

The different uses of the trademark "Motif" confuse many Unix users. Sometimes speakers are referring to the guidelines, or a particular licensed library which implements those guidelines. Perhaps they mean User Interface Language (UIL), a higher-level specification language used in Motif development. Often, someone asks, "Are you running Motif?" or "Is Motif up?" when the intended question is, "Do you rely on a window manager called mwm which OSF includes as part of a licensed Motif distribution?"

For the purpose of this article, "Motif" refers to the Xm library.

It is also important to make a distinction between Motif and the X Window System. X, as it's usually abbreviated, is a display standard first commercially released in 1986. Motif is built atop the Xt and Xlib libraries which are part of X. Most freeware Unixes, including FreeBSD and Linux, come with X. X and Motif are distinct. Many Unix users make the mistake of referring to one when they mean the other.

Remember: OSF licenses Motif for a fee. X is freely available from the X Consortium. Motif uses X.

(Visit the website listed at Table 1, Motif FAQs, for a wealth of FAQ-style Motif information. You can read more on Motif at the website listed in Table 1 under General Motif Info.)

The LessTif Alternative

While Motif still costs, it's now possible to obtain a library that substitutes for it in many situations and costs absolutely nothing. The library is called LessTif. Distributions are available from mirror sites and CD-ROM publishers in both North America and Europe.

LessTif was begun as a communal project in 1995 by a group known as Hungry Programmers (www.hungry.com). Hungry Programmers' aim for LessTif is to clone Motif version 1.2. They have constructed slots in the source code for member contributions that provide functionality from Motif 2.0 or Common Desktop Environment (CDE). Although they have packaged minor releases every month or two during the last year, as of November 1997 Hungry Programmers have yet to incorporate the first routines specific to 2.0 or CDE. Hungry Programmers distribute LessTif under a GNU Library General Public License "copyleft" [1].

There are two sources of documentation for LessTif. The first is a manual provided by Hungry Programmers (Table 1, LessTif Manual). This manual is produced in a style called "Lessdox Document." The second source of information is in a work by Harald Albrecht entitled Inside LessTif (Table 1, Inside LessTif), a technical discussion of Synthetic Resources, Geometry Management, and other advanced topics. His current release is over a hundred PostScript-formatted pages.

Getting and Installing LessTif

Binary versions of the LessTif libraries are available for Linux, OS/2, and FreeBSD. Ftp sites are listed at the top of Table 1.

There is a document (Table 1, Compatibility) that tabulates the compatibility correspondences between available versions of LessTif, operating system, compiler, and X installation. If your configuration is not listed there, it's possible to "roll your own" on almost all Unix hosts, as well as OS/2. (Documentation on generating LessTif accompanies this article's source code on the CUJ ftp site. See p.3 for downloading instructions.)

Once you've obtained a release of LessTif, unpack the archive by decompressing ("gzip -d ARCHIVE.tar.gz") and un-tarring ("tar xvf ARCHIVE.tar"). (Procedures vary slightly for OS/2 users. All our examples are for Unix.)

LessTif is a well-behaved package. That is, it installs cleanly and quietly, and doesn't interfere with other products. LessTif can be generated and installed with your choice of directory location, library type, makefile flavor, and so on. Please note: the current version at the time of this writing (October 1997) was 0.81. By the time you read this, LessTif should have advanced through at least three more minor releases.

Using LessTif

To warm up to LessTif, we start with a minimal application. Source file pushb.c (Listing 1) defines a program with a single Motif-style pushbutton. Pushing the button prints a simple acknowledgement, and exits the program.

Generate the application with a makefile like the one shown in Listing 2. This makefile is rather overdone for an application as simple as this one. We made it more elaborate because the makefile generalizes well and thus can serve as a template when you work with more complicated configurations of source code.

Once the build has finished successfully, launch your application by invoking "pushb." You've done it! You're a LessTif programmer.

More Complicated Examples

The pushb application is instructive and it makes an excellent place to start learning how to program Motif-style applications. Some of this article's readers may have a different focus, though. They may just want to use canned applications built with Motif, such as the Mosaic Web browser, Xmcd CD player, and PhaserChess game. If you're in this category, you can drop in LessTif as a substitute for Motif. We show how to do this next.

The nedit word processor is another Motif application with many Unix fans. See Table 1 for an ftp site providing nedit 4.0.3. This distribution is bundled by major Unix vendors with their operating systems.

Modifying nedit 4.0.3 to work with LessTif isn't difficult. On FreeBSD, for example, it involves the following:

1. Download the nedit archive.

2. Uncompress and untar it.

3. Create two new files, source/Makefile.freebsd and util/Makefile.freebsd, with the contents shown in Listing 3.

4. Obtain Makefile and util/Makefile.common from the CUJ ftp site.

5. Run make.

In a few seconds, you'll have source/nedit, which we found to work as well as the versions made with Motif.

Hungry Programmers maintains a list of applications known to work with LessTif (Table 1, Known Applications).

The test programs distributed with LessTif in the test subdirectory give another direction you can explore. These are generally small applications that exercise or verify only a few aspects of the Motif interface. They're well written; you can study them for ideas on what you can do with LessTif.

Pros and Cons of LessTif

LessTif has a lot going for it:

LessTif also has a fair number of drawbacks:

Recommendations

We have mixed feelings about LessTif. As a technical achievement, it's a qualified success. The volunteers who comprise Hungry Programmers have come a long way toward attaining their goal. It's impressive to see how closely LessTif replicates Motif. It's a shame Hungry Programmers doesn't expose the bug list it maintains. We personally have very warm feelings toward products which do this and it seems like a natural step for Hungry Programmers to take. We'll definitely rely on LessTif to support development and maintenance efforts for several of our clients who presently use Motif.

We hesitate, though, to encourage beginners to tackle Motif. Most of our new developments use the Tk toolkit. We've found it better fits our projects. For a comparison of Motif and Tk, see the URL cited in Table 1, Motif & Tk Comparison.

If you know you need Motif, either for compatibility with your clients, or because of its precision in management of fonts, layout, and colors — all of which are strengths of Motif — then you should seriously consider experimenting with LessTif. We predict you'll find it meets most of your needs.

However, if you're looking for an effective GUI toolkit to serve as the front end to your C and C++ programs — especially if you have an interest in solutions that are portable between Unix, Windows, MacOS, and even OpenVMS — then consider Tk. You'll save yourself a lot of the overhead and complexity that comes with Motif work. o

Reference

[1] See "Linux — the Low Cost Unix," by Rick Roberts, C/C++ Users Journal, January 1995, p.45, for a description of the GNU copyleft.

Cameron Laird and Kathryn Soraiz manage their software consultancy, Network Engineered Solutions, from just outside Houston, Texas. Cameron also co-authored the chapter on Motif programming for the second edition of Unix Unleashed. For other publications, see http://starbase.neosoft.com/~claird/misc.writing/ publications.html.