IBM
Contents Index Previous Next



Creating a New Library


Caution!

If you create new versions of the library, make sure that the library and the generated code are compiled with the same compilation switches. If not, you might experience any type of strange behavior in the generated application!

This section describes how to generate a new library. The following topics are covered:

Directory Structure

The structure of files and directories used for the Cadvanced/Cbasic SDL to C Compiler libraries is shown in Figure 561 The directory sdtdir is in the installation:

<installation directory>/sdt/sdtdir/<machine 
dependent dir>

where <machine dependent dir> is for example sunos5sdtdir on SunOS 5 and wini386 in Windows. (In Windows, / should be replaced by \ in the path above.)

This directory is here called sdtdir and is in UNIX normally referred to by the environment variable sdtdir.

Figure 561 : Directory structure

"sctdir" is a reference to an object library and is usually setup as a parameter in the call to make. It can also be an environment variable.

In the sdtdir directory three important files are found:

  1. predef.sdl contains the definition of the predefined sorts in SDL.
  2. sdtsct.knl contains a list of the available libraries that can be used together with code generated by the Cadvanced/Cbasic SDL to C Compiler.
  3. help_sct.hlp contains the help information that can be obtained using the monitor command help.

The file predef.sdl is read by the SDL Analyzer during analysis, while the file sdtsct.knl is used to present the available libraries in the Make dialog in the Organizer (see Make).

In the INCLUDE directory, there are two important groups of files:

  1. The source code files for the runtime library:
    scttypes.h, sctlocal.h, sctsdl.c, sctutil.c, sctpost.c, sctpred.h, sctpred.c, sctmon.c, sctos.c and sctenv.c
  2. The files necessary to include communication with other SCT applications: post.h, post.o (post64.o for solaris 64-bit, post.lib in Windows), sdt.h, itex.h.

In parallel with the INCLUDE directory there are a number of directories for libraries in object form. The SCTDEBCOM directory in Figure 561 is an example of such a directory. Each of these directories will contain three files: comp.opt, makeoptions (make.opt in Windows).

The comp.opt file determines the contents of the generated makefile and how make is called. For more details see below.

The makeoptions (make.opt) file describes the properties of the library, such as the compiler used, compiler options, linker options, and so on.

To guarantee the consistency of, for example, compilation flags between the SDL system and the kernel, the makeoptions (make.opt) file is used both by the make file compiling the library (Makefile) and by the generated make files used to compile the generated SDL system. Non-consistency in this sense between the library and the SDL system will make the result unpredictable.

File sdtsct.knl

The sdtsct.knl file describes which libraries that are available. This is presented by the Organizer in the Make dialog see Make). The sdtsct.knl file has the following structure. Each available library is described on a line of its own. Such a line should first contain the name of the library (the name presented in the dialog), then the path to the directory containing the library, and last a comment up to end of line.

The path to the library can either be the complete path or a relative path. A relative path is relative to the environment variable sdtdir (on UNIX) or SDTDIR (in Windows), if that variable is defined. Otherwise it is relative to the SDL Suite installation.

Example 516

Simulation          SCTDEBCOM
RealTimeSimulation  SCTDEBCLCOM
Application         SCTAPPLCLENV
ApplicationDebug    /util/sct/SCTDEBCLENVCOM

ApplicationDebug    x:\sdt\sdtdir\dbclecom
MyTestLibrary       ..\testlib\dbcom

Not that the two last lines is examples for Windows, while the fourth line is for UNIX.

The Organizer will look for an sdtsct.knl file first in the directory the SDL Suite is started from, then in the home directory for the user, and then in the directory referenced by the environment variable sdtdir (SDTDIR) if it is defined, and in the directory where the SDL Suite was installed.

File Makefile

In each directory that contains a library version there is a Makefile that can "make" the library. To create a new library after an update of the source code, change directory to the directory for the library and execute the Makefile. The Makefile uses the makeoptions (make.opt) file in the directory to get the correct compilation switches and other relevant information.

Caution!

Do not generate and test libraries in the installation directory structure. Create an appropriate copy.

Note:

The environment variables (if used) sdtdir (SDTDIR) and sctdir (SCTDIR) need not necessarily refer to directories in the installation directory. Any directory containing the relevant files may be used.

File comp.opt

This file determines the details of the generated make files, and the command issued to execute the makefile. A comp.opt file contains zero, one or more initial lines starting with a #. These lines are treated as comments. After that it contains five lines of essential data.

On each of these lines % codes can be used to insert specific information.

On all five lines:

%n : newline
%t : tab
%d : target directory
%s : source directory
%k : kernel directory
%f : base name of generated executable (no path, no
     file extension). NOT on line 2 or 5.

On line 2, the compile script:

%c : c file in compile script
%C : c file in compile script, without extension
%o : resulting object file in compile script

On line 3, the link script:

%o : list of all object files in link script
%O : list of all object files in link script, with
\ followed by newline between files
%e : executable file in link script

On line 4, the make command:

%m : name of generated makefile

On line 5, the archive command:

%o : list of object files, i.e. $(sctCODER_OBJS).
%a : the archive file, i.e.
     libstcoder$(sctLIBEXTENSION)

Example 517 : comp.opt file for UNIX

# makefile for unix make
include $(sctdir)/makeoptions
%t$(sctCC) $(sctCPPFLAGS) $(sctCCFLAGS) $(sctIFDEF) %c -o %o
%t$(sctLD) $(sctLDFLAGS) %o -o %e
make -f %m sctdir=%k
%t$(sctAR) $(sctARFLAGS) %a %o

File makeoptions / make.opt

This file has the following structure:

Example on UNIX:

# #
sctLIBNAME     = Simulation
sctIFDEF       = -DSCTDEBCOM
sctEXTENSION   = _smd.sct
sctOEXTENSION  = _smd.o
sctLIBEXTENSION=  _smd.a
sctKERNEL      = $(sctdir)/../INCLUDE
sctCODERDIR    = $(sctdir)/../coder

#Compiling, linking
sctCC          = cc
sctCODERFLAGS  = -I$(sctCODERDIR)
sctCPPFLAGS    = -I. -I$(sctKERNEL) $(sctCODERFLAGS)
 $(sctCOMPFLAGS) $(sctUSERDEFS)
sctCCFLAGS     = -c -Xc
sctLD          = cc
sctLDFLAGS     =
sctAR          = ar
sctARFLAGS     = rcu

all : default

# below this point there are a large number of
# compilation rules for compiling the Master Library
# and the Coder library (used for encoding/decoding)
# The following name of any importance are defined:

sctLINKKERNEL  = 
sctLINKKERNELDEP = 
sctLINKCODERLIB = 
sctLINKCODERLIBDEP = 

The information to the right of the equal signs should be seen as an example. These environment variables set in the makeoptions (make.opt) file should specify:

Generated Make Files

The generated make files for an SDL system will as first action include the makeoptions (make.opt) file in the directory referenced by the environment variable sctdir. It will then use the variables sctIFDEF, sctLINKKERNEL, sctCC, sctCPPFLAGS, sctCCFLAGS, sctLD, and sctLDFLAGS to compile and link the SDL system with the selected library.

The make file is generated and executed by the Cadvanced/Cbasic SDL to C Compiler.

Example 518

Below, a UNIX make file generated for the SDL system example is shown.

# makefile for System: example

sctAUTOCFGDEP =
sctCOMPFLAGS = -DXUSE_GENERIC_FUNC

include $(sctdir)/makeoptions

default: example$(sctEXTENSION)

example$(sctEXTENSION): \
  example$(sctOEXTENSION) \
  $(sctLINKKERNELDEP)
	 $(sctLD) $(sctLDFLAGS) \
  example$(sctOEXTENSION) $(sctLINKKERNEL) \
  -o example$(sctEXTENSION)

example$(sctOEXTENSION): \
  example.c
	 $(sctCC) $(sctCPPFLAGS) $(sctCCFLAGS) \
  $(sctIFDEF) example.c -o example$(sctOEXTENSION)


http://www.ibm.com/rational
Contents Index Previous Next