Chapter 1. Developing With Motif 2.1

At the start of the Motif 2.1 project, Silicon Graphics made the decision to support multiple (major) releases of the IRIX Interactive Desktop development environment installed on the system at the same time. Using the framework that was added as part of IRIX 6.5, it is now possible to develop both Motif 1.2 and 2.1 versions of an application side by side (subject of course to application build requirements). This allows you to move to Motif 2.1 at the rate that is most suited to your own needs.

The framework takes all version-specific files out of /usr/include, /usr/bin/X11, /usr/lib32, and /usr/lib64 and places them under /usr/Motif-1.2 or /usr/Motif-2.1, as appropriate.

Default Build Environment

To allow for normal (default) compilation, there are symbolic links that point from the locations used prior to IRIX 6.5 to the correct version of the installed Motif development environment.


Note: The version-stamped DSOs have not been moved and still reside in /usr/lib32 and /usr/lib64).

During the installation process, a shell script (/usr/Motif-1.2/lib/mksymlinks) is executed that sets the default build environment. The default environment is Motif 1.2 and will remain so until the next major release of IRIX.

If you need to change the default environment to 2.1, enter (as root) the following command:

# /usr/Motif-2.1/lib/mksymlinks 

To return the default environment to 1.2, enter:

# /usr/Motif-1.2/lib/mksymlinks 

To check which version is the default, use the following command:

ls -ld /usr/include/Xm 

This command prints out a directory listing that shows to which file /usr/include/Xm is linked:

lrwxr-xr-x /usr/include/Xm -> ../Motif-1.2/include/Xm

In the case above, anything compiled on this machine (using the default build environment) will use the Motif 1.2 API.

Caution for Using the Default Build Environment

The main problem with relying on the default build environment is one of reproducibility; anyone (as root) can change the environment (even during a build), and you will not know until you start getting random crashes.

For this reason Silicon Graphics does not recommend that the default build environment be used for production builds, or in environments where there may be some doubt as to a machine's state (large multi-user build machines, for example).

It cannot be stressed enough how important it is to ensure that you do not mix code (either individual .o files or even whole libraries) that uses both 1.2 and 2.1. If you do successfully get it to build you will see random crashes for which it is very difficult to determine the cause. It is up to the developers to ensure that they have a consistent environment throughout all stages of the project build.

Explicit Build Environment

An explicit build environment is one where it can be predicted in advance which set of libraries and header files will be used. This is done by making use of the structure under /usr/Motif-1.2 or /usr/Motif-2.1. For example, if you want to ensure that you are building a Motif 1.2 application, you should add the following to the compile/link line (assuming that you are building an n32 binary):

-I/usr/Motif-1.2/include -L/usr/Motif-1.2/lib32

This must appear on the command line before /usr/include and /usr/lib32. If your build process uses make to build its Makefiles, Silicon Graphics has configured mmkmf to generate the correct arguments. Do not use xmkmf. It is not part of the Motif Software Development Kit and could not be modified. It will generate Makefiles using the default environment.

Imake Tips

To build an application that uses the Motif 1.2 SDK, run /usr/Motif-1.2/bin/mmkmf. For Motif 2.1, use /usr/Motif-2.1/bin/mmkmf.

To check which version of Motif an Imake generated Makefiles will use, you can page through the Makefile, or try the following:

grep XmVersion Makefile

This returns a line like the following:

# ** XmVersion ** Motif 2.1 Generated Makefile *********************

Make Tips

If you use plain Makefiles for building, you will have to devise your own mechanism, but if you use smake, you can use the following method:

  1. Create a new Makefile (Example 1-1).

  2. Include the code in Example 1-2 in every Makefile.

 

Example 1-1. Sample Makefile (src/motifVer)


## This file will append the correct include/lib settings to the various LC*
## variables. 
 
## This line sets the default build to be 1.2. To build against 2.1
## all a Makefile has to do is set MOTIFVERSION to 2.1 *before* this file gets
## included (this could also be done on the command line with 
## make MOTIFVERSION=2.1 <target>
 
MOTIFVERSION ?=1.2
 
# The rest is automatic....
 
MOTIFDIR=/usr/Motif-$(MOTIFVERSION)
MOTIFROOTDIR = $(ROOT)$(MOTIFDIR)
 
LCINCS += -I$(MOTIFROOTDIR)/include
LC++INCS += -I$(MOTIFROOTDIR)/include
LCXXINCS += -I$(MOTIFROOTDIR)/include




Example 1-2. Sample Makefile Code (src/Makefile)


#!smake
#
# $Id: ch1.sgm,v 1.5 1998/09/29 23:58:09 cmiqueo Exp $
# This is an example Makefile to illustrate how one might construct
# a plain Make(not Imake) based build system that can be switched
# to use either version of Motif.
 
include /usr/include/make/commondefs
 
TARGETS=buildDemo
 
include motifVer
 
LLDLIBS = -lXm -lXt -lX11
 
$(TARGETS): vertical-writing.o
 
demo.o: vertical-writing.c

This example is for an or-based build, where you need to be able to build both 1.2 and 2.1 versions, but not during the same build. An and-based build (where both versions are needed concurrently) will probably create two new subdirectories (say obj and obj21), with a Makefile in each (each setting the MOTIFVERSION as appropriate). And rather than linking the source files, simply refer to them using “../”.