次の方法で共有


A Build Example (Compact 2013)

3/26/2014

To understand how Sources Macros work, it is helpful 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, as well as any dependencies. Thus, each leaf-node directory that contains a sources file also contains a makefile. The makefile is a dummy file that points to the master makefile, located in %_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.

Makefile include ordering

Example

The following example shows the sources file located at 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

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 and TARGETTYPE, you can see that the file creates SDBus.dll. The file also lists a module definition (sdbus.def), 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 these libraries 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.

See Also

Concepts

Compile and Link with the Build Tool
Sources Macros