Makefiles that are not written by PWB often contain utility targets that are not used in the process of building the project itself. These targets are used to clean up intermediate files, perform backups, process documentation, or automate other tasks related to the project. You can extend a PWB makefile to perform these kinds of tasks by adding new rules. These additional rules must be placed in a special section of the project makefile.
In the following example you will add a section that creates a file with information about the project. This file has the same base name as the project and the extension .LST. It lists the files in the project and the major options used for the build. This example section can be used with any PWB project.
Use the COUNT project to see how to add a custom section. If you have been following the tutorial, this project is already open in PWB.
·To add a custom section to the PWB makefile:
1.From the Project menu, choose Close Project.
This step is crucial because PWB disables modification of the project makefile until the project is closed or a different project is opened. (This restriction does not apply to non-PWB project makefiles.)
2.From the File menu, choose the Open command and open the COUNT.MAK file in the editor.
3.Press CTRL+END to move the cursor to the end of the makefile.
4.Type this comment line exactly as shown:
# << User_supplied_information >>
You must put the number sign (#) in column one and type the contents of the line exactly as shown, including capitalization. Failing to type this line accurately will make the project unrecognizable to PWB or allow PWB to change your custom build information in unexpected ways.
NMAKE requires space between rules. Therefore, you should separate this line from the lines above it by one blank line. Similarly, you should leave at least one line between the separator and your custom build rules. For more information about NMAKE and the syntax of makefiles, see Chapter 18, “Managing Projects with NMAKE.”
This comment line is used by PWB as a separator. Anything above this comment is regarded as belonging to PWB, and you should not edit the information there. The exception is to add options to individual command lines, as described in “Changing Options for Individual Modules”. Anything in the makefile after the separator is your information, and PWB ignores it. NMAKE, however, processes the entire file.
Now that you have a separator to show PWB where your custom information starts, you can add the custom information. The separator and custom section is included in the following text:
# << User_supplied_information >>
# Example 'user section' for PWB project makefiles,
# used in the PWB Tutorial.
#
# NOTE: This is not a standalone makefile.
# Append this file to makefiles created by PWB.
#
# This user section adds a new target to build a project
# listing that shows the build type, options, and a list
# of files in the project.
#
!IFNDEF PROJ
!ERROR Not a standalone makefile.
!ENDIF
!IF $(DEBUG)
BUILD_TYPE = debug
!ELSE
BUILD_TYPE = release
!ENDIF
# Project files and information-list target
#
$(PROJ).lst : $(PROJFILE)
@echo < Project Name: $(PROJ)
Build Type: $(BUILD_TYPE)
Program Arguments: $(RUNFLAGS)
Project Files
$(FILES: =^
)
C Compiler Options
Global: $(CFLAGS_G)
Debug: $(CFLAGS_D)
Release: $(CFLAGS_R)
Link Options
Global: $(LFLAGS_G)
Debug: $(LFLAGS_D)
Release: $(LFLAGS_R)
Debug Libraries: $(LLIBS_D)
Release Libraries: $(LLIBS_R)
<<KEEP
The custom section of a PWB makefile can use any of the information defined by PWB. This example takes advantage of many macros defined by PWB. For example, the PROJFILE macro, which contains the name of the project makefile, is used as the dependent of the listing file so that the listing is rebuilt whenever the project makefile changes.
In addition, this custom section uses many features of NMAKE including macros, macro substitution, preprocessing directives, and inline files. For more information about NMAKE and makefiles, see Chapter 18, “Managing Projects with NMAKE.”
·To rebuild using the custom options:
1.Choose Open Project from the Project menu and reopen the COUNT project.
2.From the Project menu, choose Build Target.
3.Type the name of the new target COUNT.LST in the Target text box, and then choose OK.
PWB informs you that the build options have changed and asks if you want to rebuild everything.
4.Choose Yes to confirm that you want to rebuild everything.
The project information file that is created shows the project name, indicates whether the build is a debug or release build, lists the files in the project, and lists the compiler and linker options used for the build.