|
|
Customizing the Windows CE build system using DIRS, SOURCES, and CECs [MSDN]
2002-01-03
Last month we provided an overview of the typical steps used to build an image of Microsoft Windows CE .NET, and took a look at how the operating system is built under the covers. The build system is extensible at a number of levels, providing a means for adding your own drivers, technologies, and applications to a platform.
These can either be in pre-build binary form, or in source code form. In this article, we will take a look at how to customize the build system through 'catalog feature files' (previously known as CE component files, or simply CEC files -- we will call these CEC files for the rest of the article) and DIRS and SOURCES. DIRS and SOURCES We touched on DIRS in last month's article; let's review how and when these are used. A typical Board Support Package (BSP) contains multiple folders, most of which will be 'touched' during the platform build process. BSPs are normally located in the C:\WINCE400\PLATFORM\folder, assuming Platform Builder is installed into the default folders. Let's examine the folder structure of the EMULATOR platform, which is located in C:\WINCE400\PLATFORM\EMULATOR. Below is shown a directory listing. You will notice a number of interesting looking folders?Drivers, GWE, KERNEL, and so on. Each of these folders may contain source files that need to be assembled, compiled, and linked during a platform build process. How does the build system know which files/folders to build? ![]() Notice the dirs file; let's examine its contents. (Note that I've stripped comments out of the file to make is easier to read.)
So, this is how we determine the folders that need to be built for the Emulator Platform. We will build gwe, then kernel, then drivers. Now let's take a look into one of the folders: Drivers. (Note that the same build mechanism is used in the other emulator folders, and in fact in other BSP folders. ![]() Again, we have a number of folders, including Display, Keyboard/Mouse, and so on. We also have another "dirs" file. Let's examine its contents. !if 0 We can see that we again have a list of folders that will be included in the build process. To add your own driver to the list, you would simply append the name of your driver folder into the DIRS file, like so: !if 0 Let's now examine the display folder; this again contains a DIRS file that lists a single folder, VGAFLAT. The C:\WINCE400\PLATFORM\EMULATOR\DRIVERS\DISPLAY\VGAFLAT folder doesn't contain a DIRS file, but does contain two files that are also used in the build process. These are SOURCES and MAKEFILE, which we will examine shortly. That's as hard as it gets for DIRS files; DIRS files simply contain a list of folders that will be included in the build process. Each of these folders may contain a DIRS file, which points at additional folders to include in the build process. SOURCES Using DIRS files to map out the folders included in the build process is all well and good, but at some point we actually need to build something. This is where SOURCES and MAKEFILE are used. The SOURCES file contains information that determines how folder contents will be built, and what the output will be from the build process (EXE, DLL, LIB). Build invokes make/nmake under the hood, so a makefile is needed. In the same directory as a SOURCES file, there is a makefile that #includes makefile.def (the "master" makefile). The purpose of that file is essentially to set environment variables, but it also handles precompiled headers, cleans old build targets, gets include paths right, and sets the correct library list for linking a particular component. It also contains the compiler and linker invocation command lines. MAKEFILE is deceptively simple. Here are the contents of the file: !INCLUDE $(_MAKEENVROOT)\makefile.def The _MAKEENVROOT macro (when expanded) equates to: _MAKEENVROOT=C:\WINCE400\public\common\oak\misc
C:\WINCE400\public\common\oak\misc\makefile.def The build process uses macro definitions in the DIRS and SOURCES files to build the source code for a platform. These macro definitions use the following syntax: Macroname= value You can include white space to the left of the macro name and to the right of the equals sign. There can be no white space between the macro name and the equal sign. If the value has a backslash (\) as the last character on a line, the macro definition continues to the next line. Given these rules, the following macro definitions are equivalent. SOURCES= MyProj1.c MyProj1.h Macro names are not case sensitive. Both Nmake.exe and Build.exe expand macro definitions. For example, Build.exe tries to expand the BBB macro in the following line: AAA= $(BBB)\Myproj If BBB is not defined as a macro or environment variable, Build.exe defines the AAA macro as \Myproj. A number of macros are commonly used in SOURCES files. Take a look at the following SOURCES example from the Emulator/Display/VGAFLAT folder. We will then examine some of the common macros. (A number of other macros can be used in SOURCES files. Take a look at the Platform Builder online help for a complete listing.) !if 0 Module Name: sources. Abstract: This file specifies the target component being built and the list of sources files needed to build that component. It also specifies optional compiler switches and libraries that are unique for the component being built. !ENDIF Each macros is described here:
To build the Sources or DIRS file, you can add it directly into the workspace by right clicking on the workspace icon at the root of the tree in the Feature View, and then select Insert User Feature. The insert dialog will appear. You will need to select the file type for DIRS and SOURCES to add it. However, if more then one developer will use the code, it's better to create a CEC file to allow developers to add it into a build with a simple click from the catalog. CEC files are a bit more complicated in version 4.0, as there is more functionality provided in the IDE. The good news is that Windows CE .NET includes a CEC file editor. (Which coincidentally has many features and ideas included in a tool published by one of the authors of these articles? Hmmmm, wonder where they got those ideas!) We'll stay away from the syntax, as it isn't much different from previous versions (it's documented, and there is a GUI editor for it). Instead we'll focus on the concepts of what it's for and how to apply the various elements properly. You'll see how CEC files are useful for much more than just building some code; they are actually the major control point for the build in the IDE. Now, a little bit about GUIDS? Globally Unique Identifiers (GUIDS) are 128-bit values represented in text in the form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}, where each X is a hexadecimal digit. The CEC editor will generate GUIDS automatically for you, and you can also generate new ones for a component. The GUIDGEN tool is also useful for those editing the CEC file as text. The following UML Diagram describes the elements of a CEC file. Don't worry if you aren't familiar with the UML notation. (Though learning it at some point is strongly recommended!) The CEC File has one CECInfo block. This block assigns a unique ID for the CEC file, and specifies a name and description for the file, as well as the version of the CEC file structure. The original CEC file structure from Platform Builder V2.12 did not include this block. Version 3.0 added this block primarily to include the version number. For Windows CE .NET, the version number is 4.00. The ComponentType block is directly related to a Feature in the catalog or feature view. It is represented in the IDE by the collection of three cylinders (2 green on blue) icon. The component type is much like a class in object-oriented programming. It is an abstraction only, and requires an implementation before it is useful. The ComponentType block may contain one or more implementations. Each implementation provides information specific to a particular feature item you want to include. By way of example, let's look at the display drivers component type. The Display Component Type has several implementations for various types of display cards. You can have implementations that are CPU-specific as well. It is important to know that every ComponentType has a GUID. BSP files no longer exist in Windows CE .NET. That functionality is now in the CEC file for the BSP. There is a special component type called, informatively enough, "BSPs," with a GUID of {3CABD6DA-B577-4A87-9490-9432E80DC2F1}. To add your own BSP into the catalog, you must include an implementation of this type in the CEC file. In your BSP implementation, you will include a DefaultDrivers attribute that specifies the drivers (by GUID) that the IDE will include in any new platforms created from the wizard based on your BSP. If your BSP supports multiple drivers of a particular type (such as a few variations on a display driver in the CEPC BSP), then you can specify the display component type GUID, and the end user will then resolve to a specific implementation before performing a build. The BIB Info block is a great addition to CEC files in Windows CE .NET. This element allows you to specify BIB file settings to be automatically included whenever the user selects the feature from the catalog. If you simply used a DIRS/SOURCES file, then the user would still need to add the BIB entries manually. Implementations contain one or more build methods, each associated with a particular step in the build process. Each Build Step should be applied as described:
Build Methods contain a set of actions to perform during the appropriate stage of the build process, as described in the following table:
![]() There are a few attributes of the various elements of a CEC file that provide important information to the IDE. Understanding these will help you appreciate the various ways in which the IDE tries to make your life easier.
Vendors providing drivers for Windows CE should also use CEC files for your drivers. It is an easy task to export a driver feature from the catalog (and any related files), and generate an installer for it. Microsoft has added this as a feature of the catalog, so that it will be easy to create installations for various features in the catalog from your existing ones. I would seriously question the quality or stability of any driver from a third party that does not provide this, since it is so easy for them to do, and it saves the end user so much time. About the authors: Mike Hall is a Product Manager in the Microsoft Embedded and Appliance Platform Group (EAPG). Mike has been working with Windows CE since 1996 -- in developer support, Embedded System Engineering, and the Embedded product group. When not at the office, Mike can be found with his family, working on Skunk projects, or riding a Honda ST1100. Steve Maillet is the Founder and Senior Consultant for Entelechy Consulting. Steve has provided training and has developed Windows CE solutions for clients since 1997, when CE was first introduced. Steve is a frequent contributor to the Microsoft Windows CE development newsgroups. When he's not at his computer burning up the keys, Steve can be found jumping out of airplanes at the nearest drop zone. Copyright (c) 2002 Microsoft Corporation. All rights reserved. Reproduced by WindowsForDevices.com under license.
|