Most of the modules in your system use the same build options. However, you will occasionally need to modify the options for a single module. For example, if the code size is critical on most modules but one module needs to be optimized for speed, you can set your compiler options to optimize for space, which handles the predominant case. You can then modify the options for the module that you want to optimize for speed.
The example that follows shows how to customize your project to change the compiler options to optimize only COUNTCH.C for speed.
First, set the compiler options for the most general case. For COUNT in this example, the most general case is to optimize for space. (If you have been following the tutorial, you did this in the previous section.)
Once you have set the options for the general case, you have to customize the project to compile only COUNTCH.C with optimizations for time. To do this, you manually edit the instructions in the project makefile for compiling COUNTCH.C.
·To open COUNT.MAK for editing:
1.If the COUNT project is open, choose Close Project from the Project menu.
This step is important because you cannot edit a PWB makefile for a project that is currently open.
2.Choose the Open command from the File menu and open the COUNT.MAK file in the editor.
Find the rule for compiling COUNTCH.C:
COUNTCH.obj : COUNTCH.C
!IF $(DEBUG)
$(CC) /c $(CFLAGS_G) $(CFLAGS_D) /FoCOUNTCH.obj COUNTCH.C
!ELSE
$(CC) /c $(CFLAGS_G) $(CFLAGS_R) /FoCOUNTCH.obj COUNTCH.C
!ENDIF
This rule contains a conditional statement with two commands. The first command is for debug builds, and the second command is for release builds. You will edit the second (release) command. The release command uses the following macros defined earlier in the makefile:
Macro | Definition |
CC | The name of the C compiler |
CFLAGS_G | Global options for C compiles |
CFLAGS_R | Release options for C compiles |
To optimize only COUNTCH.C for time, place the /Ot compiler option after $(CFLAGS_R). The resulting command is:
$(CC) /c $(CFLAGS_G) $(CFLAGS_R) /Ot /FoCOUNTCH.obj COUNTCH.C
There is no way to predict if the C option macros contain the /Os option, which would turn off /Ot, or if they contain any other option. To handle this potential problem, the new option must be placed at the end because the option specified last takes precedence. The compiler options, such as /Ot, and NMAKE macros, such as CFLAGS_G, are case sensitive and must appear exactly as shown.
Warning:
After this modification, PWB can still understand this makefile as a PWB makefile. However, if you make changes beyond adding options to individual command lines, PWB may no longer recognize the file as a PWB makefile. If this happens, you can delete the makefile and re-create it, or you can use it as a non-PWB makefile. For more information on using non-PWB makefiles, see “Using a Non-PWB Makefile”.
Save your changes to the makefile by choosing Save from the File menu. You can now reopen the project and rebuild COUNT with the custom options.