I was looking over my original post about sources files (Platform Builder: Sources Files) today and it occurred to me that there is room to improve. That post provided basic information to create a sources file that will build a driver.  The following are other things that you can do within a sources file:
Set CFLAGS and AFLAGS
CFLAGS and AFLAGS cannot be set in a sources file. Instead, you will need to set CDEFINES and ADEFINES to set compiler and assembler command line flags.
Set CDEFINES, LDEFINES and ADEFINES
These variables are used to change the command line parameters to the compiler (CDEFINES), assembler (ADEFINES) and linker (LDEFINES). 
As with all variables in a sources file the way to set the variable is <VAR NAME>=<DATA>. So, using CDEFINES for an example:
CDEFINES=-DMY_MACRO –DOTHER_MACRO=5
Which causes the compiler command line to define MY_MACRO and to define OTHER_MACRO=5. The –D is the compiler command line flag to define a macro. But wait, setting CDEFINES this way will cause any previous settings to be lost. This is exactly why we cannot use CFLAGS and AFLAGS, it is set this way in makefile.def. So a better way to set a variable is:
CDEFINES=$(CDEFINES) -DMY_MACRO –DOTHER_MACRO=5
By doing so, we are setting CDEFINES equal to the current value in CDEFINES plus defining MY_MACRO and OTHER_MACRO=5.
Skip Building
You can skip building a directory in the build tree by checking the component environment variable and setting SKIPBUILD. SKIPBUILD tells build to skip building the directory.
!if "$(BSP_NOTHISDRIVER)" == "1"
SKIPBUILD=1
!endif
This checks to see if the environment variable BSP_NOTHISDRIVER is set to “1”. If it is then sets SKIPBUILD=1. For those of us that don’t like variable with “NO” in them, you can use:
!if "$( BSP_THISDRIVER)" == ""
SKIPBUILD=1
!endif
This checks to see if BSP_THISDRIVER is not set. If it is not then sets SKIPBUILD=1.
Build Something Before or After Building the Directory
WINCETARGETFILE0 can be used to tell the build system to build a target before building the current directory. WINCETARGFILES tells the build system to build a target after building the current directory.    I have given an example of using WINCETARGETFILES in Windows CE Platform Builder: Automatically putting files in the SDK during build so let’s look at WINCETARGETFILE0.
In this example, I have a DLL that is built in a different directory tree and want to extend the DLL by adding some new functions. The original DLL is built in two directories, one that creates a LIB file and the other that links the LIB to create a DLL.  In this directory there is source code that adds some functions and a def file that exports the functions. For maintainability, I want to use the def file from the original DLL folder, but extend it to add new definitions. To do this, use WINCETARGETFILE0 set equal to DEFFILE:
WINCETARGETFILE0=$(DEFFILE)
Create or edit makefile.inc in the same folder as the sources file. Add a target to makefile.inc and build instructions. In this case the target is $(DEFFILE) and the instructions will copy the original def file to this directory and append the contents of Custome.def to it:
$(DEFFILE): Custom.def                               
xcopy ..\Original\BuildDll\Original.def .
                type Custom.def >> Original.def
So the new def file will be created before building this directory and the def file will be available when the DLL is linked.
Tell the Solution Explorer about files to Display
The Solutions Explorer window uses sources files to determine which files to display and how to display them.
 
SOURCES not only tells build.exe which files should be built in the directory, but tells the Solutions Explorer which files to list in the “Source files” folder. The following will cause serial.cpp to display in the Source Files folder:
SOURCES=serial.cpp
FILE_VIEW_ROOT_FOLDER tells the Solutions Explorer window to which files to show in the root folder of the directory. The following will cause sources and makefile to display in the root folder:
FILE_VIEW_ROOT_FOLDER=Sources Makefile
FILE_VIEW_RESOURCE_FOLDER tells the Solutions Explorer window which files to display in the “Resource files” folder.
FILE_VIEW_RESOURCE_FOLDER=serial.rc
FILE_VIEW_INCLUDES_FOLDER tells the Solutions Explorer windows which files to display in the “Include files” folder.
FILE_VIEW_INCLUDES_FOLDER=serial.h
FILE_VIEW_PARAMETER_FOLDER tells the Solutions Explorer window which files to display in the “Paramter files” folder.
FILE_VIEW_PARAMETER_FOLDER=serial.bib serial.reg
 
 
 
Copyright © 2008 – Bruce Eitman
All Rights Reserved