A Build Example (Compact 7)
3/12/2014
To understand how sources macros work, you need to examine the build system in more depth. While it is true that build.exe is responsible for compiling and linking code, it actually calls nmake.exe to do the real compilation and linking. Nmake.exe uses makefiles that specify what to compile and link and what the dependencies are. Thus, each leaf-node directory that contains a sources file also contains a makefile. In Microsoft’s implementation, the makefile is a dummy makefile that points to the master makefile, %_WINCEROOT%\public\common\oak\misc\makefile.def.
Makefile.def is a large file that is ultimately responsible for providing the correct information to nmake.exe. Nmake.exe interprets the sources macros, creating a set of flags to pass to the compiler and linker. Makefile.def provides details about how particular source macros work. In addition to the sources file, it includes several other files, which are shown in the following figure.
Example
The following example shows a slightly more complex sources file (Public\Common\Oak\Drivers\Sdcard\Sdbus_dll\Sources).
Note
The syntax $(<env_name>)
denotes the value of the environment variable whose name is <env_name>
.
TARGETNAME=SDBus
TARGETTYPE=DYNLINK
RELEASETYPE=OAK
DLLENTRY=_DllEntryCRTStartup
DEFFILE=..\sdbus\sdbus.def
SOURCES=
TARGETLIBS= \
$(_COREDLL) \
$(_CEDDK)
SOURCELIBS= \
$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\SDBus_LIB.lib \
$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\defbuslib.lib \
$(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\sdcardlib.lib
By looking at TARGETNAME, TARGETTYPE, and DLLENTRY, you can see that the file creates SDBus.dll, and its entry point is _DllEntryCRTStartup. It has a module definition file, located in ..\sdbus, which typically describes its function exports. In this case, the code is not compiled, but coredll.lib and ceddk.lib are linked with several libraries specific to this driver that have already been built. It is important to use SOURCELIBS for these libraries in order to include their object code so that the function exports in sdbus.def are valid. If all of these are set to TARGETLIBS, the result is a DLL with nothing in it, because there is no source code that requires their symbols for resolution.
Finally, the RELEASETYPE for SDBus.dll is OAK. If you look in makefile.def, you can see that this causes Public\Common\Oak\Misc\Sources.ReleaseType_OAK to be included, which sets the output directory to $(__PROJROOT)\Oak\Target\$(__CPUDIR). For more information about how to interpret these environment variables, see Build from the Top Down.