Complete Contents
Introduction
Chapter 1 About Netscape Application Server Extensions
Chapter 2 About the Netscape Extension Builder
Chapter 3 Introduction to Netscape's Interface Definition Language
Chapter 4 Designing a Netscape Extension
Chapter 5 Generating Output Files
Chapter 6 Completing Method Stubs
Chapter 7 Using Template Streaming
Chapter 8 Managing State and Session Information
Chapter 9 Using Object Pools
Chapter 10 Compiling the Extension Source Code
Chapter 11 Deploying and Managing a Netscape Extension
Chapter 12 Example Extension: HelloWorld
Appendix A C++ Helper Functions
Appendix B Java Helper Static Methods
Appendix C Java Class Decorations
Appendix D Reserved Words
Appendix E The ConnManager.cpp File
Glossary
Previous Next Contents Index


Compiling the Extension Source Code

This chapter describes compiling, the repeated process that you perform after generating output files with Netscape Extension Builder. Extension code is compiled by running the make command.

The following topics are included in this chapter:


About Compiling the Source Code
When you run make the first time, the initial compilation produces a "boilerplate" extension—a valid extension containing no useful functionality. After you add functionality—by filling out method stubs and by completing other code—you must run make a second time.

As long as your extension uses only the source files automatically generated by Netscape Extension Builder, you can recompile simply by running make. However, in many cases your extension needs to encapsulate legacy code, and this requires you to link libraries or create source code by hand. If your extension uses components that were not automatically generated, then these components will not appear in the makefiles. You must add this information to the makefiles before you can successfully compile the extension code.


Introduction to Editing Makefiles
You may need to edit one or more files in the make harness under any of the following conditions:

When you modify the make harness, edit only the makefile in each affected directory. For example, suppose you created new .cpp files by hand in a service module directory named EmployeeServices. If so, you would edit that directory's makefile and re-run the make command from that directory.

If instead, you added source files to many directories, you would still edit each directory's makefile, but you might find it easier to re-run the make command just once, from the top-level directory.

The specific changes you add to a makefile depend on your computing platform (Solaris or Windows NT) and on the extension language (C++ or Java).


Editing Makefiles on Solaris
This section describes the following tasks:

Editing Makefiles for C++ Extensions
If you are building a C++ extension, you may need to edit the GNUmakefile.sun file in any of the following ways:

Adding New Source File Names
If you created new extension source files:

  1. Locate the section where SERVICE_SRCS is defined, and append the new file names. For example:
  2. SERVICE_SRCS = \

    CExtModule.cpp \

    CExtFirstClass.cpp \

    CExtSecondClass.cpp \

    CMyNewClass.cpp

  3. Locate the section where SERVICE_OBJS is defined, and append the name of the corresponding object files. For example:
  4. SERVICE_OBJS = \

    $(INTERMEDIATE_OUTDIR_NAME)/CExtModule.o \

    $(INTERMEDIATE_OUTDIR_NAME)/CExtFirstClass.o \

    $(INTERMEDIATE_OUTDIR_NAME)/CExtSecondClass.o \

    $(INTERMEDIATE_OUTDIR_NAME)/CMyNewClass.o

Linking Additional Libraries

  1. Locate the section where LIBS_KIVA is defined.
  2. Append your library names to the LIBS_KIVA definition. For example:
  3. LIBS_KIVA += -lMyExtension

If you extend the definition of LIBS_KIVA, check that the listed libraries reside in <NAS_ROOTDIR>/APPS/bin; otherwise, the Deployment Manager will not be able to deploy them.

Adding Flags

  1. For C++ compilation flags, edit the CFLAGS definition. For example, to add the DEBUG flag:
  2. CFLAGS += -DDEBUG

  3. For link flags, edit the LFLAGS_SERVICE definition. For example:
  4. LFLAGS_SERVICE += -L anotherLibDirectory

Adding Support for Non-Pic Objects
By default, the linker supports position-independent code (PIC) objects. On Solaris, you must edit makefiles if a C++ extension uses non-PIC objects. The edits you make will differ, depending on whether you can recompile the non-PIC objects.

If you can recompile the objects, then use the -KPIC option in the compile command. Using this option produces objects with position-independent code.

If you cannot recompile the objects, then override the LFLAGS_ZTEXT variable in the makefile. For example:

include $(GX_KETROOTDIR)/makefiles/GNUdefaults_sun.mak

LIB_TARGETS += $(LIB_INSTALL_DIR)/lib$(SERVICE_TARGET).so

LIBS_KIVA += FileWriterNOPIC.a -lketgxidl -lketutil \

-lSampleExt_ext

INCLUDE_PATH += -I$(KIVA_EXT_INCLUDE) -I$(INCLUDE_INSTALL_DIR)

# override the default LFLAGS_ZTEXT value

LFLAGS_ZTEXT =

The default value of LFLAGS_ZTEXT is "-z text". This value causes a fatal error whenever text relocations need to occur, and text relocations always occur when linking with a non-PIC object. By overriding the default value of LFLAGS_ZTEXT to nothing, the linker does not use the "-z text" flag. As a result, non-PIC objects can be successfully linked.

Editing Makefiles for Java Extensions
If you are building a Java extension, you edit the makefile only if you add new source files. No edits are needed to account for libraries, and no flags are used when compiling or linking Java. Any Java class files you want to import in your extension must reside in <NAS_ROOTDIR>/APPS/bin; otherwise, the Deployment Manager will not be able to deploy them.

If you created new Java source files, edit GNUmakefile.sun as follows.

  1. Locate the section where JAVA_SRCS is defined, and append the new file names. For example:
  2. JAVA_SRCS = \

    CExtModule.java \

    CExtFirstClass.java \

    CExtSecondClass.java \

    CMyNewClass.java

  3. Locate the section where JAVA_CLASSES is defined, and append the name of the corresponding Java class files. For example:
  4. JAVA_CLASSES = \

    $(JAVA_INSTALL_DIR)/$(JAVA_PACKAGEDIR)/CExtModule.class \

    $(JAVA_INSTALL_DIR)/$(JAVA_PACKAGEDIR)/ \

    CExtFirstClass.class \

    $(JAVA_INSTALL_DIR)/$(JAVA_PACKAGEDIR)/ \

    CExtSecondClass.class \

    $(JAVA_INSTALL_DIR)/$(JAVA_PACKAGEDIR)/CMyNewClass.class


Editing Makefiles On Windows NT
This section describes the following tasks:

Editing Makefiles for C++ Extensions
If you are building a C++ extension, you may need to edit the GNUmakefile.nt file in any of the following ways:

Adding New Source File Names
If you created new extension source files:

  1. Locate the section where SERVICE_SRCS is defined, and append the new file names. For example:
  2. SERVICE_SRCS = \

    CExtModule.cpp \

    CExtFirstClass.cpp \

    CExtSecondClass.cpp \

    CMyNewClass.cpp

  3. Locate the section where SERVICE_OBJS is defined, and append the name of the corresponding object files. For example:
  4. SERVICE_OBJS = \

    $(INTERMEDIATE_OUTDIR_NAME)\CExtModule.obj \

    $(INTERMEDIATE_OUTDIR_NAME)\CExtFirstClass.obj \

    $(INTERMEDIATE_OUTDIR_NAME)\CExtSecondClass.obj \

    $(INTERMEDIATE_OUTDIR_NAME)\CMyNewClass.obj

  5. Locate the section where INTERMEDIATE_OUTDIR_NAME is defined, and add similar entries for each of the new files. For example:
  6. $(INTERMEDIATE_OUTDIR_NAME)\CMyNewClass.obj: CMyNewClass.cpp

    $(CPP) $(CFLAGS) -Fo"$@" CMyNewClass.cpp

Linking Additional Libraries

  1. Locate the section where LIBS_KIVA is defined.
  2. Append your library names to the LIBS_KIVA definition. For example:
  3. LIBS_KIVA = $(LIBS_KIVA) ketgxidl.lib ketutil.lib MyExt.lib

  4. If the new libraries reside in directories other than those defined by LIB_PATH, append the directory paths to LIB_PATH. For example:
  5. LIB_PATH = $(LIB_PATH); C:\my_legacy_code\lib

If any of the files you appended to LIBS_KIVA are .dll files, check that they reside in <NAS_ROOTDIR>\APPS\bin; otherwise, the Deployment Manager will not be able to deploy them. It is recommended, though not required, that .lib files reside in <NAS_ROOTDIR>\APPS\bin as well.

Adding Flags

  1. For C++ compilation flags, edit the CFLAGS definition. For example, to add the DEBUG flag:
  2. CFLAGS = $(CFLAGS) -DDEBUG

  3. For link flags, edit the LFLAGS_SERVICE definition. For example:
  4. LFLAGS_SERVICE = $(LFLAGS_SERVICE) -nologo

Editing Makefiles for Java Extensions
If you are building a Java extension, you edit the makefile only if you add new source files. No edits are needed to account for libraries, and no flags are used when compiling or linking Java. Any Java class files you want to import in your extension must reside in <NAS_ROOTDIR>\APPS\bin; otherwise, the Deployment Manager will not be able to deploy them.

If you created new Java source files, edit GNUmakefile.nt as follows.

  1. Locate the section where JAVA_SRCS is defined, and append the new file names. For example:
  2. JAVA_SRCS = \

    CExtModule.java \

    CExtFirstClass.java \

    CExtSecondClass.java \

    CMyNewClass.java

  3. Locate the section where JAVA_CLASSES is defined, and append the name of the corresponding Java class files. For example:
  4. JAVA_CLASSES = \

    $(JAVA_INSTALL_DIR)\$(JAVA_PACKAGEDIR)\CExtModule.class \

    $(JAVA_INSTALL_DIR)\$(JAVA_PACKAGEDIR)\ \

    CExtFirstClass.class \

    $(JAVA_INSTALL_DIR)\$(JAVA_PACKAGEDIR)\ \

    CExtSecondClass.class \

    $(JAVA_INSTALL_DIR)\$(JAVA_PACKAGEDIR)\CMyNewClass.class

  5. Locate the section where JAVA_INSTALL_DIR is defined, and add similar entries for each of the new files. For example:
  6. $(JAVA_INSTALL_DIR)\$(JAVA_PACKAGEDIR)\CMyNewClass.class :

    CMyNewClass.java

    $(JAVAC) $(JAVAC_FLAGS) CMyNewClass.java

Configuring the make Harness
You may need to configure Netscape Extension Builder so that the make harness can locate your C++ development environment. You do this by setting several variables in the env.mak file. This file resides in the <NEB_ROOTDIR>\makefiles directory.

For example, to set your C++ development environment, you might define variables as shown in this sample env.mak file:

# GNUenv_nt.mak

# Contains machine-specific directories.

# Where the MSDEV environment is.

# Make sure you keep the double quotes if the

# paths you specify here include spaces.

# For example, "c:\Program Files\DevStudio"

#

WIN_SDK = "c:\msdev"

CPP = "c:\msdev\bin\cl.exe"

LINK = "c:\msdev\bin\link.exe"

WIN_SDK_INCLUDE = "c:\msdev\include"

WIN_SDK_LIB = "c:\msdev\lib"

The installer attempts to set these variables to their correct values. Check the env.mak file and edit these values as needed.


The make Harness
After Netscape Extension Builder Designer generates IDL files and a make harness, you run the gmake command from the top-level directory. Running this command performs the following main tasks:

In particular, the top-level makefile recursively calls the makefiles in the idl subdirectory and in the source code subdirectories (cpp, java, or both).

Inside the IDL Directory
The gmake command in the idl directory performs the following tasks:

Inside the cpp Directory
The cpp directory is created if you are building a C++ extension. The gmake command in the cpp directory performs the following tasks:

Inside the Java Directory
The java directory is created if you are building a Java extension or a C++ extension with a Java Access Layer. The gmake command in the java directory traverses down multiple directories, recursively running make until it reaches the <package> directory. For example, if the Java package is named com.mycompany.Hello, then the make command is run from the <extension>\com\mycompany\Hello directory.

The gmake command in the <package> directory performs the following tasks:

 

Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.