Introduction to Sun WorkShop HomeContentsPreviousNextIndex


Chapter 3

Building Programs

Sun WorkShop projects allow you to customize your builds, build your programs without having to write a makefile, or build a program using your own makefile. You can also build an application without a current project, run one build job or several build jobs concurrently, and fix build errors using the Building window and the Sun WorkShop editor of your choice.

For step-by-step instructions and more information, see the Building Programs section of the online help (you can access the online help through the Help menu in any Sun WorkShop window).

Working With Targets

When building in Sun WorkShop, two types of targets are involved:

Sun WorkShop Target

A Sun WorkShop target is an object derived from the build directory, the build command, the makefile, and the make target:

When a Sun WorkShop target is built, it is added to the picklist of Sun WorkShop targets in the Build menu and in the Build Edit Target command. When you begin a build, Sun WorkShop looks for the first target in the Sun WorkShop target list and builds it.

A project can contain multiple targets. For an executable, static library/archive, shared library, or Fortran application, your executable/library is one target, and a special Clean target is another (found in the Build menu picklist). The Clean target deletes all of your project's generated files (for example, the .o files), the source browsing database, the C++ templates database, the executable itself, and other build-related files.

For a complex project, you can have more targets, which are listed in the Build menu picklist. For example, your project can generate five libraries and an executable to link them together. Each library or executable is then a WorkShop target, and you can build each individual one by selecting it from the Build menu picklist.

User Makefile Target

A user makefile target is an object that make knows how to build from the directions (rules) contained in a particular makefile. Makefiles are generally designed so that the default target (the one you get when you do not specify a target) is the most commonly built target.

A makefile contains entries that describe how to bring a make target up to date with respect to those files on which it depends (called dependencies). Since each dependency is a make target, each dependency might have dependencies of its own. Targets and file dependencies and subdependencies form a tree structure that make traces when deciding whether or not to rebuild a make target.

For a user makefile project, each target listed in the Build menu picklist is a makefile or a makefile target to be built.

Using the Building Window

The Building window displays information on program compilation. You can open the window by choosing Build Show Building Window in the Sun WorkShop main window. FIGURE 3-1 shows the Building window.

From the Building window, you can:


FIGURE 3-1   Building Window

Building a Program

You can build your entire project or only one of your project targets. After you ask Sun WorkShop to build your project targets, Sun WorkShop:

  1. Creates a makefile from the project definitions you provided in the Create New Project wizard or the Edit Current Project Window.

  2. Launches the make utility.

  3. Opens the Building Window to show the results of the build.

For more information, see the following topics in the Building Programs section of the online help:

You can also specify build parameters using the Define New Target and Edit Target dialog boxes. You use the Define New Target dialog box to specify a new WorkShop target and the Edit Target dialog box to modify an existing WorkShop target (the Define New Target and Edit Target dialog boxes are identical). FIGURE 3-2 shows the Define New Target dialog box.


FIGURE 3-2   Define New Target Dialog Box

Building With Default Values

Sun WorkShop provides a default make target and a default make command (dmake), so you can begin a build without specifying a build command or a make target. You must still supply a makefile when you are building a user makefile project or when a project is not loaded (Sun WorkShop searches for a file named makefile or Makefile and allows make to figure out which one to use).

By using the project feature of Sun WorkShop, you can ask Sun WorkShop to create a makefile for you through the Create New Project wizard or the Edit Current Project window.

For more information, see "Building With Default Values" in the Building Programs section of the online help.

Specifying Your Own Build Values

If you have a makefile with a unique name, a certain make target, or a specific build command, you can define those build values in the Define New Target dialog box or Edit Target dialog box (this applies to a user makefile project or when a project is not loaded). For example, by specifying your own build command, you can filter out unnecessary warnings by passing make output through a filter. At a minimum, you must include a build directory. Sun WorkShop will then use the make command to find the makefile using make's search order. See the make(1S) man page.

For more information, see "Specifying Your Own Build Values" in the Building Programs section of the online help.

Specifying Build Options

You can specify build options in the Build Options dialog box. To open the Build Options dialog box, click Options in the Edit Target dialog box. For information about the options available, click Help in the Build Options dialog box. When you are finished selecting the options you want, click OK in the Build Options dialog box. Then click Build in the Edit Target dialog box.

Before running a distributed build for the first time, you must create a .dmakerc runtime configuration file that specifies which machines are to participate as dmake build servers. The file contains groups (lists) of build servers and the number of jobs distributed to each build server. The dmake utility searches for this file on the dmake host to know where to distribute jobs. Generally, this file is in your home directory. If dmake does not find a runtime configuration file, it distributes two jobs to the local host. For information on setting up a runtime configuration file, see "The .dmakerc File" in the Building Programs section of the online help and the dmake(1) man page. For more information about the dmake utility, see Appendix C and the dmake(1) man page.

To set up a machine to be used as a build server, you must create a configuration file called /etc/opt/SPROdmake/dmake.conf on the server's file system. Without this file, dmake refuses to distribute jobs to that machine. In the dmake.conf file, you specify the maximum number of jobs (from all users) that can run concurrently on that build server. See "The dmake.conf File" in the Building Programs section of the online help, Appendix C in this book, and the dmake(1) man page for more information.

Using Makefile Macros

You can specify makefile macros in the Make Macros dialog box (to open, click Macros in the Edit Target or Define New Target dialog box). Makefile macros let you refer conveniently to files or command options that appear in the description file. Through the Make Macros dialog box, you can add makefile macros to or delete them from the Persistent Build Macros list in your WorkShop target and then reassign values for makefile macros in the list. You can also add macros currently defined in the makefile to the list and override their values. For more information, click Help in the Make Macros dialog box, and see Appendix B for information about defining macros.

Using Environment Variables

You can specify environment variables for your build in the Environment Variables dialog box (to open, click Environment Variables in the Edit Target or Define New Target dialog box). Using the Environment Variables dialog box, you can add environment variables to or delete them from the Persistent Environment Variables list in your WorkShop target and reassign values for environment variables in the list. When you start the build, setenv commands for these environment variables are prepended to the build command. For more information, click Help in the Environment Variables dialog box.

Identifying Build Errors

When a build fails, the build errors display in the Build Output display pane of the Building window (see FIGURE 3-3). The location of the error is underlined and highlighted to denote a hypertext link to the location of the error in a source file. Each error gives the name of the file containing the error, the line number on which the error occurs, and the error message. Clicking on the underscored error in the Building window starts a text editor that displays the source file containing the error. For more information, see "Fixing Build Errors" in the Building Programs section of the online help.


Note – Only Sun compilers produce output that can be converted to hypertext links. If you use a build command that does not call Sun compilers, you will not have links to the source files from the build errors listed in the Building window.


FIGURE 3-3   Build Errors in the Build Output Display Pane of the Building Window

Error messages issued by the Fortran, C, and C++ compilers include an information icon ( ) in the build error message. Click on the icon to open a pop-up window displaying a definition of the associated error message (see FIGURE 3-4).


FIGURE 3-4   Build Error and Dialog Box With Associated Error Message Defined

Exiting Building

To kill the current build process and close all build windows, choose Build Exit Building in the Building window.

If you want to close the building windows without killing the current build process, choose Build Close.


Sun Microsystems, Inc.
Copyright information. All rights reserved.
Feedback
Library   |   Contents   |   Previous   |   Next   |   Index