conditional expressions in sources file

I am building scsiport and storport drivers out of the same directory,
conditionally depending on the build environment.

What is the correct way to determine the build environment in the
sources file? I thought the following would work:

!IF “$(DDK_TARGET_OS)” == “Win2K” || “$(DDK_TARGET_OS)” == “WinXP”
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
SOURCES=xenvbd.rc xenvbd_scsiport.c
!ELSE
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\storport.lib
SOURCES=xenvbd.rc xenvbd_storport.c
!ENDIF

But the expression always evaluates to false and builds the storport
version instead.

Thanks

James

You cannot use conditional expressions in macros that build.exe itself interprets (notable, SOURCES=). This is because build.exe doesn’t understand nmake conditionals.

There are a variety of ways to work around this limitation (from the simple #include’ing of source files, to creating subdirectories and referencing common source files one level up ("…" is, IIRC, one of the few exceptions to the rule that you can’t make cross directory references in SOURCES=), with specific sources files in referenced from “.”. [You should be able to use !include from within sources, if I am remembering right - but they must be unconditional.]

This topic has, for what it’s worth, been discussed many times on the list previously, so you can probably find some additional advice on dealing with it through a little bit of searching.

  • S

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of James Harper
Sent: Thursday, January 27, 2011 12:00 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] conditional expressions in sources file

I am building scsiport and storport drivers out of the same directory, conditionally depending on the build environment.

What is the correct way to determine the build environment in the sources file? I thought the following would work:

!IF “$(DDK_TARGET_OS)” == “Win2K” || “$(DDK_TARGET_OS)” == “WinXP”
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib SOURCES=xenvbd.rc xenvbd_scsiport.c !ELSE
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\storport.lib SOURCES=xenvbd.rc xenvbd_storport.c !ENDIF

But the expression always evaluates to false and builds the storport version instead.

Thanks

James


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Why not have 2 subdirs, one for each port model. Scsiport\sources !include’s …\sources.inc and then appends scsiport.lib to the TARGETLIBS directory, storport\sources does the same for storport.lib. then you can just use _NT_TARGET_VERESION or something similar to indicate the minimum target OS

d

>

You cannot use conditional expressions in macros that build.exe itself
interprets (notable, SOURCES=). This is because build.exe doesn’t
understand
nmake conditionals.

There are a variety of ways to work around this limitation (from the
simple
#include’ing of source files, to creating subdirectories and
referencing
common source files one level up ("…" is, IIRC, one of the few
exceptions to
the rule that you can’t make cross directory references in SOURCES=),
with
specific sources files in referenced from “.”. [You should be able to
use
!include from within sources, if I am remembering right - but they
must be
unconditional.]

This topic has, for what it’s worth, been discussed many times on the
list
previously, so you can probably find some additional advice on dealing
with it
through a little bit of searching.

Thanks. That explains it.

James

>

Why not have 2 subdirs, one for each port model. Scsiport\sources
!include’s
…\sources.inc and then appends scsiport.lib to the TARGETLIBS
directory,
storport\sources does the same for storport.lib. then you can just
use
_NT_TARGET_VERESION or something similar to indicate the minimum
target OS

I have a ‘makedist.bat’ script that builds drivers for all OS flavours
for each bit width (as supported per OS) (selecting 6100 DDK for W2K
build), zips up the pdb files for debugging previous versions, signs the
binaries, then finally calls the WiX installer build. My reason for
going for a single driver binary even though it might be scsiport on one
OS and storport on another is to keep the build as simple as possible (a
good theory… didn’t work out though did it :slight_smile:

I have changed my sources file to this:

!IF “$(DDK_TARGET_OS)” == “Win2K” || “$(DDK_TARGET_OS)” == “WinXP”
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\scsiport.lib
C_DEFINES=$(C_DEFINES) -D_GPLPV_SCSIPORT
!ELSE
TARGETLIBS=$(TARGETLIBS) $(DDK_LIB_PATH)\storport.lib
C_DEFINES=$(C_DEFINES) -D_GPLPV_STORPORT
!ENDIF
SOURCES=xenvbd.rc xenvbd.c

And then xenvbd.c is:

#ifdef _GPLPV_SCSIPORT
#include “xenvbd_scsiport.c”
#else
#include “xenvbd_storport.c”
#endif

I could probably have done the #if stuff with NTDDI_ defines instead but
this way it is always synced to whatever is in the sources file.

Thanks

James