Sun Studio 12: C++ User's Guide

2.7 Simplifying Commands

You can simplify complicated compiler commands by defining special shell aliases, using the CCFLAGS environment variable, or by using make.

2.7.1 Using Aliases Within the C Shell

The following example defines an alias for a command with frequently used options.

example% alias CCfx "CC -fast -xnolibmil"

The next example uses the alias CCfx.

example% CCfx any.C

The command CCfx is now the same as:

example% CC -fast -xnolibmil any.C

2.7.2 Using CCFLAGS to Specify Compile Options

You can specify options by setting the CCFLAGS variable.

The CCFLAGS variable can be used explicitly in the command line. The following example shows how to set CCFLAGS (C Shell):

 example% setenv CCFLAGS ’-xO2 -xsb’

The next example uses CCFLAGS explicitly.

 example% CC $CCFLAGS

When you use make, if the CCFLAGS variable is set as in the preceding example and the makefile’s compilation rules are implicit, then invoking make will result in a compilation equivalent to:

CC -xO2 -xsb files...

2.7.3 Using make

The make utility is a very powerful program development tool that you can easily use with all Sun compilers. See the make(1S) man page for additional information. Using CCFLAGS Within make

When you are using the implicit compilation rules of the makefile (that is, there is no C++ compile line), the make program uses CCFLAGS automatically. Adding a Suffix to Your Makefile

You can incorporate different file suffixes into C++ by adding them to your makefile. The following example adds .cpp as a valid suffix for C++ files. Add the SUFFIXES macro to your makefile:

SUFFIXES: .cpp .cpp~

(This line can be located anywhere in the makefile.)

Add the following lines to your makefile. Indented lines must start with a tab.

    $( -o $@ $< $(LDLIBS)
    $(GET) $(GFLAGS) -p $< > $*.cpp
    $( -o $@ $*.cpp $(LDLIBS)
    $( $(OUTPUT_OPTION) $<
    $(GET) $(GFLAGS) -p $< > $*.cpp
    $( $(OUTPUT_OPTION) $<
    $( -o $% $<
    $( -xar $@ $%
    $(RM) $%
    $(GET) $(GFLAGS) -p $< > $*.cpp
    $( -o $% $<
    $( -xar $@ $%
    $(RM) $% Using make With Standard Library Header Files

The standard library file names do not have .h suffixes. Instead, they are named istream, fstream, and so forth. In addition, the template source files are named,, and so forth.