Earlier I posted about dirs files and stated that dirs files are the direction signs for build.exe. Sources files are the destinations. When build.exe finds a sources file, it stops and runs nmake to build the source code in the directory. Sources files set environment variables that are then used by nmake when interpreting the makefile. Of course if you have looked at the makefiles, you see that they typically only include the makefile.def in Public\Common\Oak\Misc.
 
Setting variables in a sources file is simple, it is just variable equals value; example TARGETNAME=DrivverShell. You can also dereference variables using the same syntax as in the bib files and reg files, wrap the variable in $(); example $( _COMMONSDKROOT).
Sources files use the same syntax as makefiles, so a # starts a comment which extends to the end of the line.
 
Let’s examine the simple sources file in my Driver Shell post:
 
#This is a sources comment
TARGETNAME=DriverShell
RELEASETYPE=PLATFORM
TARGETTYPE=DYNLINK
 
TARGETLIBS= \
    $(_COMMONSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib
 
DEFFILE=DriverShell.def
DLLENTRY=DllEntry
 
SOURCES=DriverShell.c

 

Hint: To fully understand what the variables in a sources file do, refer to Makefile.def in Public\Common\Oak\Misc
This sources file tells nmake to build in Platform\<BSP>\Target\<CPU Independent Path>\DriverShell.dll, link with coredll.lib, use DriverShell.def to define the exported symbols, that the entry point of the dll is DllEntry and that the source code to compile is DriverShell.c.
That was a lot, so let’s take it one step at a time:
  • TARTGETNAME defines the base name of the output file, this is defined by the developer of the sources file
  • RELEASETYPE defines where to put the output file, the choices are: DEFAULT, SDK, OAK, DDK, MANAGED, PLATFORM, LOCAL, CETK, CUSTOM. I could easily tell you where the output file ends up in each case, but it would be better for you to go look yourself. The output file in each case is defined in Public\Common\Oak\Misc\sources.Releasetype_%RELEASETYPE% or in makefile.def itself for versions prior to CE 5.0.
  • TARGETTYPE defines the type of output file that is being build. The options are:
  • DYNLINK – creates a dynamically linked library, MUI or control panel applet. If MUI is set to 1, the file extension is changed from dll to mui.  If CPL is set to 1, the file extension is changed from dll to cpl.
  • PROGRAM – creates an native exe
  • LIBRARY – creates a static linked library
  • MANAGED_EXE – creates a managed exe from
  • MANAGED_WINEXE – creates a managed exe of target winexe, quite frankly, I don’t know what this means.
  • MANAGED_MODULE – and again, I don’t know what this means
  • MANAGED_DLL – creates a managed dll
  • EXPLIB – creates an exp file
  • NOTARGET - cause nmake to skip over linking a target
  • TARGETLIBS lists the .lib files to link with.
  • SOURCELIBS (not shown) lists .lib files to link with.
  • DEFFILE sets the name of the DEF file to link with. If this is not defined, $(TARGENAME).def will be used
  • DLLENTRY sets the entry point function name
  • SOURCE sets the source code files to build, which also sets that the obj files are linked
NOTES on TARGETLIBS and SOURCELIBS:
  • If TARGETTYPE is LIBRARY TARGETLIBS is ignored
  • If TARGETTYPE is PROGRAM TARGETLIBS is linked before SOURCELIBS
  • If TARGETTYPE is DYNLINK, SOURCLIBS is linked before TARGETLIBS
Those are the basic variables set in a sources file. There are many more available, some documented and some not. The best documentation is the makefile.def file, but to read and understand it well you will need to understand makefiles. Makefile.def is a very sophisticated makefile, so be prepared that you may not fully understand it on the first pass. You may need to refer to makefile documentation, over and over until all of the details of makefile.def become clear.
Build.exe does not support conditional expressions in sources files. You may find examples of conditional expressions in sources files, but officially they are not supported, which means that if you use them they could break in the future. A known problem with conditional expressions is that since build.exe doesn’t use them, and build.exe processes dependencies, conditional expressions cause problems for the dependency checking.
For more on sources files take a look at: Platform Builder: Sources Files 2 
 
 
Copyright © 2008 – Bruce Eitman
All Rights Reserved