Platform Builder: Fmerge Tips and Tricks

Platform Builder: Fmerge Tips and Tricks
Fmerge is a file merge utility that runs when you run makeimg. Fmerge is used to concatenate and process bib, reg, dat, db and nls files. Each file type is handled in a different way.
Tip1, check the makeimg output. The makeimg output includes the fmerge command line for each file type. This can be valuable for understanding which file is included when, and the name of the output file that is created. I will leave it to you to review the command line to check the order of processing files. The following table shows the output file names:
File Type
Output File
Reg
Reginit.ini
Bib
Ce.bib
Db
InitObj.db
Dat
InitObj.dat
Nls
nlssrc.txt
 
Tip 2, Including files – You don’t need to include all of your registry entries in the files that fmerge has listed on the command line, you can include one reg file from another. The syntax is very similar to including header file in C/C++, #include “file.reg”. The quotes actually turn out to be optional.
Example include
#include “$(_TARGETPLATROOT)/Src/Drivers/MyDriver/MyDriver.reg”
 That was simple enough, this says include MyDriver.reg from the Src/Drivers/MyDriver in the BSP directory. 
On the surface that doesn’t seem to be all that significant, but it really is quite powerful. First, changes to MyDriver.reg will be merged when makeimg is run without needing to first copy the file to the _FLATRELEASEDIR first.   More important though, this means that you can use the same driver in multiple projects through the power of version control and maintain the registry settings in one place.
Tip 3 – using conditional expressions - Fmerge supports conditional expressions, or as it these are documented in Platform Builder Help, “Decision Statements and Operators”.
Fmerge support a couple of different conditional expressions:

1.  The most basic conditional expression is the IF <environmentvariable> statement that you may see in many of the sample BSPs. The syntax is:

IF <EnvironmentVariable> [!]
… some settings…
ENDIF
Where EnvironmentVariable is a an environment variable set on your development system and the ‘!’ is the not character. This conditional allows you to check to see if an environment variable is defined, or not defined.

This explains why setting an environment variable equal to zero (0) is not the same thing as clearing the variable. If you set the variable to zero, it is still defined. If you clear the variable, it is no longer defined and can be checked by this conditional. So:

 

Set BSP_MYVAR=

Is not the same as

Set BSP_MYVAR=0

 

Example:

 

IF BSP_DRIVERSUPPORT

IF BSP_MYDRIVER

[HKEY_LOCAL_MACHINE/Drivers/Builtin/MyDriver]

                “dll”=”MyDriver.dll”

                “Index”=dword:1

ENDIF

ENDIF

 

Which includes the registry settings for MyDriver when BSP_DRIVERSUPPORT and BSP_MYDRIVER are defined.

2. Fmerge was enhanced in Windows CE 4.0 to support new conditional expressions which are much more powerful. The enhanced conditional expressions add support for value comparison and else statements.  The new syntax is:

#if ExpressionList
#elif ExpressionList

#else

#endif

 

Where ExpressionList can include “==”, “!=”, “||” and “&&” operators. So now we can simplify the previous example:

#if defined BSP_DRIVERSUPPORT && defined BSP_MYDRIVER

[HKEY_LOCAL_MACHINE/Drivers/Builtin/MyDriver]

                “dll”=”MyDriver.dll”

                “Index”=dword:1

#endif

 

Note the use of defined to check to see if a variable is defined.

 

This conditional also allows us to check for a value of variable, which allows us to do things like only include a registry setting if we are building a debug build of the OS:

#if “$(WINCEDEBUG)”==”debug”

[HKEY_LOCAL_MACHINE/Drivers/Builtin/MyDriver]

                “dll”=”MyDriver.dll”

                “Index”=dword:1

#endif

 
Tip 4 setting variables - We can also define variables in the REG file using #define, and undefined variables using #undef. This can be valuable for setting values in the registry:
 
#if !defined USB_VENDOR_ID
#define USB_VENDOR_ID 1234
#endif
 
[HKEY_LOCAL_MACHINE/Drivers/USB/FunctionDrivers/Serial_Class]
; idVendor must be changed. 045E belongs to Microsoft and is only to be used for
; prototype devices in your labs. Visit http://www.usb.org to obtain a vendor id.
 "idVendor"=dword:$(USB_VENDOR_ID)
 
Go to Summary of Building Windows CE
You may also want to look at my Summary of BIB File Posts
You may also want to look at Summary of Registry Posts
 
Tags: Makeimg, FMerge, BIB File, REG Files
 
 
Copyright © 2008 – Bruce Eitman
All Rights Reserved

Friday, June 20, 2008 3:00 PM

你可能感兴趣的:(Platform Builder: Fmerge Tips and Tricks)