How to build library from object files created in

i have a directory say dir1. I have three subdirectories under it say sdir1,
sdir2, sdir3.
I would like to build object files from .c files within each subdir sdir1,
sdir2, sdir3.
I have some .c files in dir also. I build object files from these as well.
Now I want to combine all these .os into a single library without use of
intermediate libraries?

Can you please please let me know what macros I should define in
dir1\sources file to acheive this to link all these
.o’s and build a single library.

I dont see MACROS to do the last step of specifying object files to link to
build a library?

Thanks,
-Praveen

> Now I want to combine all these .os into a single library without use of

intermediate libraries?

Either intermediate libraries, or #include “…/…/dir1/sdir2/myfile.c”, or
both.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Hi,

Thanks for the reply.

I tried creating intermediarly libraries.

For eg. directory structure is like:

dir -> sdir1
sdir2
sdir3
sdir4

I created sdir1.lib, sdir2.lib, sdir3.lib in sub-directories sdir1,
sdir2, sdir3 respectively by sepecifying TARGETTYPE=DRIVER_LIBRARY.

In sdir4, I build sdir4.lib and also try to link sdir1, sdir2, sdir3 by
specifying them in LINKLIBS/TARGETLIBS.
But sdir4.lib is getting built but is not getting linked with other three
libraries.
In sdir4\sources , I again set TARGETTYPE=DRIVER_LIBRARY only because I am
going to use sdir4.lib to build
a driver in another directory.

Is there a way I can do this?

Regards,
-Praveen

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> Now I want to combine all these .os into a single library without use of
>> intermediate libraries?
>
> Either intermediate libraries, or #include “…/…/dir1/sdir2/myfile.c”, or
> both.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

> For eg. directory structure is like:

dir -> sdir1
sdir2
sdir3
sdir4

I created sdir1.lib, sdir2.lib, sdir3.lib in sub-directories sdir1,
sdir2, sdir3 respectively by sepecifying TARGETTYPE=DRIVER_LIBRARY.

In sdir4, I build sdir4.lib and also try to link sdir1, sdir2, sdir3 by
specifying them in LINKLIBS/TARGETLIBS.

No. All dirs but the last one build the LIBs, the last one builds the real
binary with the LIBs specified in TARGETLIBS.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks again.

One last question.

I want to source files to compile conditionally like:

!if ()
SOURCES= a.c
!else
SOURCES= b.c
!endif.

Build utility is giving an error if I try this. The error i get is as
follows:
1>sources(21) : warning U1018: directive and/or expression part missing

I could not locate info on using conditions inside source file within DDK.
Can you let me know what is the problem here or how I can acheive this
conditional assignment?

Regards,
-Praveen

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> For eg. directory structure is like:
>>
>> dir -> sdir1
>> sdir2
>> sdir3
>> sdir4
>>
>> I created sdir1.lib, sdir2.lib, sdir3.lib in sub-directories sdir1,
>> sdir2, sdir3 respectively by sepecifying TARGETTYPE=DRIVER_LIBRARY.
>>
>> In sdir4, I build sdir4.lib and also try to link sdir1, sdir2, sdir3 by
>> specifying them in LINKLIBS/TARGETLIBS.
>
> No. All dirs but the last one build the LIBs, the last one builds the real
> binary with the LIBs specified in TARGETLIBS.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

Praveen Kumar Amritaluru wrote:

Thanks again.

One last question.

I want to source files to compile conditionally like:

!if ()
>SOURCES= a.c
>!else
>SOURCES= b.c
>!endif.
>
>Build utility is giving an error if I try this. The error i get is as
>follows:
>1>sources(21) : warning U1018: directive and/or expression part missing
>
>

Right. There can only be one line that says “SOURCES=”. That’s one of
the amusing little quirks of build, which is essentially a pre-processor
for nmake. Other than a few quirks, the rest of the sources file must
be nmake-compatible.

So, just make it:

SOURCES = <br> a1.c <br> a2.c <br>!if ()
a.c <br>!else
b.c <br>!endif
c.c


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> I want to source files to compile conditionally like:

!if ()
> SOURCES= a.c
> !else
> SOURCES= b.c
> !endif.
>
> Build utility is giving an error if I try this. The error i get is as

Yes, this is the IIRC only limitation on conditions in SOURCES file.

The SOURCES statement itself must not be inside a condition. Any other
statements, including the ones describing the target, can be under a condition.
For instance, I have a multi-directory user mode project. It can be built to
several DLLs and an EXE, or to a single EXE with everything in it, and these 2
modes are switched by un-commenting 1 variable in the master SOURCES.INC

To bypass this, define a macro which will make the whole .C/.CPP file as empty,
and also a #pragma warning to switch off the “translation unit is empty”
warning.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

As others have pointed out, BUILD.EXE/SOURCES has some limitations on what
kind of SOURCES file you can have. If you want to conditionally include a
file in your project, just have a dummy.c file that has:

#if FOO
#include “a.c”
#else
#include “b.c”
#endif

and set FOO in your SOURCES file, depending on whatever conditions you
have.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Monday, April 17, 2006 9:24 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:How to build library from object files created in

Thanks again.

One last question.

I want to source files to compile conditionally like:

!if ()
SOURCES= a.c
!else
SOURCES= b.c
!endif.

Build utility is giving an error if I try this. The error i get is as
follows:
1>sources(21) : warning U1018: directive and/or expression part missing

I could not locate info on using conditions inside source file within DDK.
Can you let me know what is the problem here or how I can acheive this
conditional assignment?

Regards,
-Praveen

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> For eg. directory structure is like:
>>
>> dir -> sdir1
>> sdir2
>> sdir3
>> sdir4
>>
>> I created sdir1.lib, sdir2.lib, sdir3.lib in sub-directories sdir1,
>> sdir2, sdir3 respectively by sepecifying TARGETTYPE=DRIVER_LIBRARY.
>>
>> In sdir4, I build sdir4.lib and also try to link sdir1, sdir2, sdir3 by
>> specifying them in LINKLIBS/TARGETLIBS.
>
> No. All dirs but the last one build the LIBs, the last one builds the real
> binary with the LIBs specified in TARGETLIBS.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Thanks very much to all those who replied.

Now I changed to overcome this problem.

The way I have done now is:

!if $(NEW_API)
C_DEFINES=$(C_DEFINES) -DAPI
LINKLIBS= a.lib b.lib
RM_SOURCES=a.c b.c c.c
!else
C_DEFINES=$(C_DEFINES)
LINKLIBS=a.lib
RM_SOURCES=d.c e.c
!endif

SOURCES=$RM_SOURCES

The problem I face here is that:

If the env variable NEW_API is set to 0, it executes only else clause. But
if I set NEW_API to 1, it executes if-clause code
followed by else-clause code. So incase NEW_API==1, this undo’s whatever is
present in if-clause and SOURCES always ends up being d.c e.c

Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI NES
too wherein both if-caluse and else-clause
statements are executed?

Regards,
-Praveen

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Praveen Kumar Amritaluru wrote:
>
>>Thanks again.
>>
>>One last question.
>>
>> I want to source files to compile conditionally like:
>>
>>!if ()
>>SOURCES= a.c
>>!else
>>SOURCES= b.c
>>!endif.
>>
>>Build utility is giving an error if I try this. The error i get is as
>>follows:
>>1>sources(21) : warning U1018: directive and/or expression part missing
>>
>>
>
> Right. There can only be one line that says “SOURCES=”. That’s one of
> the amusing little quirks of build, which is essentially a pre-processor
> for nmake. Other than a few quirks, the rest of the sources file must
> be nmake-compatible.
>
> So, just make it:
>
> SOURCES = <br>> a1.c <br>> a2.c <br>> !if ()
> a.c <br>> !else
> b.c <br>> !endif
> c.c
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>

No you have some bug. Your sources file is interpreted as part of a
makefile and follows the rules documented in the nmake references. I
assume you meant SOURCES=$(RM_SOURCES) rather than SOURCES=$RM_SOURCES.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Thursday, April 20, 2006 9:38 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:How to build library from object files created in

Thanks very much to all those who replied.

Now I changed to overcome this problem.

The way I have done now is:

!if $(NEW_API)
C_DEFINES=$(C_DEFINES) -DAPI
LINKLIBS= a.lib b.lib
RM_SOURCES=a.c b.c c.c
!else
C_DEFINES=$(C_DEFINES)
LINKLIBS=a.lib
RM_SOURCES=d.c e.c
!endif

SOURCES=$RM_SOURCES

The problem I face here is that:

If the env variable NEW_API is set to 0, it executes only else clause.
But
if I set NEW_API to 1, it executes if-clause code
followed by else-clause code. So incase NEW_API==1, this undo’s
whatever is
present in if-clause and SOURCES always ends up being d.c e.c

Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI
NES
too wherein both if-caluse and else-clause
statements are executed?

Regards,
-Praveen

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Praveen Kumar Amritaluru wrote:
>
>>Thanks again.
>>
>>One last question.
>>
>> I want to source files to compile conditionally like:
>>
>>!if ()
>>SOURCES= a.c
>>!else
>>SOURCES= b.c
>>!endif.
>>
>>Build utility is giving an error if I try this. The error i get is as
>>follows:
>>1>sources(21) : warning U1018: directive and/or expression part
missing
>>
>>
>
> Right. There can only be one line that says “SOURCES=”. That’s one
of
> the amusing little quirks of build, which is essentially a
pre-processor
> for nmake. Other than a few quirks, the rest of the sources file must
> be nmake-compatible.
>
> So, just make it:
>
> SOURCES = <br>> a1.c <br>> a2.c <br>> !if ()
> a.c <br>> !else
> b.c <br>> !endif
> c.c
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

You are right. I meant SOURCES=$(RM_SOURCES)

But any idea why both if-part and else-part are getting executed incase
if(condition) is true.

Regds,
-Praveen

“Roddy, Mark” wrote in message news:xxxxx@ntdev…
No you have some bug. Your sources file is interpreted as part of a
makefile and follows the rules documented in the nmake references. I
assume you meant SOURCES=$(RM_SOURCES) rather than SOURCES=$RM_SOURCES.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Thursday, April 20, 2006 9:38 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:How to build library from object files created in

Thanks very much to all those who replied.

Now I changed to overcome this problem.

The way I have done now is:

!if $(NEW_API)
C_DEFINES=$(C_DEFINES) -DAPI
LINKLIBS= a.lib b.lib
RM_SOURCES=a.c b.c c.c
!else
C_DEFINES=$(C_DEFINES)
LINKLIBS=a.lib
RM_SOURCES=d.c e.c
!endif

SOURCES=$RM_SOURCES

The problem I face here is that:

If the env variable NEW_API is set to 0, it executes only else clause.
But
if I set NEW_API to 1, it executes if-clause code
followed by else-clause code. So incase NEW_API==1, this undo’s
whatever is
present in if-clause and SOURCES always ends up being d.c e.c

Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI
NES
too wherein both if-caluse and else-clause
statements are executed?

Regards,
-Praveen

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Praveen Kumar Amritaluru wrote:
>
>>Thanks again.
>>
>>One last question.
>>
>> I want to source files to compile conditionally like:
>>
>>!if ()
>>SOURCES= a.c
>>!else
>>SOURCES= b.c
>>!endif.
>>
>>Build utility is giving an error if I try this. The error i get is as
>>follows:
>>1>sources(21) : warning U1018: directive and/or expression part
missing
>>
>>
>
> Right. There can only be one line that says “SOURCES=”. That’s one
of
> the amusing little quirks of build, which is essentially a
pre-processor
> for nmake. Other than a few quirks, the rest of the sources file must
> be nmake-compatible.
>
> So, just make it:
>
> SOURCES = <br>> a1.c <br>> a2.c <br>> !if ()
> a.c <br>> !else
> b.c <br>> !endif
> c.c
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

> Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI NES

too wherein both if-caluse and else-clause
statements are executed?

Try using !IFDEF instead.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

So you have some other problem. I took you example and put it into a
functional sources file, and added a !message line:

!if $(NEW_API)
RM_SOURCES=a.c
!message IF ENTERED
!else
RM_SOURCES=d.c
!message ELSE ENTERED
!endif

And this works just as expected. If NEW_API is ‘1’ “IF ENTERED” is in
the logfile and “ELSE ENTERED” is not. If NEW_API is ‘0’ “IF ENTERED” is
not in the logfile and “ELSE ENTERED” is.

The problem is not what you think it is. The nmake preprocessor works as
documented. The problem is the way build works.

I would suggest that you reorganize your sources. In a simplified
example with an a.c and a d.c as separate sources and common source
file, call it event.c, I would create two separate subdirectories,
buildA and buildB. In BuildA my sources file would look like this:

TARGETNAME=event
TARGETTYPE=DRIVER

INCLUDES=$(INCLUDES) …\

SOURCES=…\event.c \
…\a.c \
…\event.rc

In BuildB my sources file looks like this:

TARGETNAME=event
TARGETTYPE=DRIVER

INCLUDES=$(INCLUDES) …\

SOURCES=…\event.c \
…\d.c \
…\event.rc

This works, even though the support for including source files ‘up one
level’ is undocumented.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Thursday, April 20, 2006 12:24 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:How to build library from object files created in

You are right. I meant SOURCES=$(RM_SOURCES)

But any idea why both if-part and else-part are getting executed incase
if(condition) is true.

Regds,
-Praveen

“Roddy, Mark” wrote in message
news:xxxxx@ntdev…
No you have some bug. Your sources file is interpreted as part of a
makefile and follows the rules documented in the nmake references. I
assume you meant SOURCES=$(RM_SOURCES) rather than SOURCES=$RM_SOURCES.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Thursday, April 20, 2006 9:38 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:How to build library from object files created in

Thanks very much to all those who replied.

Now I changed to overcome this problem.

The way I have done now is:

!if $(NEW_API)
C_DEFINES=$(C_DEFINES) -DAPI
LINKLIBS= a.lib b.lib
RM_SOURCES=a.c b.c c.c
!else
C_DEFINES=$(C_DEFINES)
LINKLIBS=a.lib
RM_SOURCES=d.c e.c
!endif

SOURCES=$RM_SOURCES

The problem I face here is that:

If the env variable NEW_API is set to 0, it executes only else clause.
But
if I set NEW_API to 1, it executes if-clause code
followed by else-clause code. So incase NEW_API==1, this undo’s
whatever is
present in if-clause and SOURCES always ends up being d.c e.c

Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI
NES
too wherein both if-caluse and else-clause
statements are executed?

Regards,
-Praveen

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Praveen Kumar Amritaluru wrote:
>
>>Thanks again.
>>
>>One last question.
>>
>> I want to source files to compile conditionally like:
>>
>>!if ()
>>SOURCES= a.c
>>!else
>>SOURCES= b.c
>>!endif.
>>
>>Build utility is giving an error if I try this. The error i get is as
>>follows:
>>1>sources(21) : warning U1018: directive and/or expression part
missing
>>
>>
>
> Right. There can only be one line that says “SOURCES=”. That’s one
of
> the amusing little quirks of build, which is essentially a
pre-processor
> for nmake. Other than a few quirks, the rest of the sources file must
> be nmake-compatible.
>
> So, just make it:
>
> SOURCES = <br>> a1.c <br>> a2.c <br>> !if ()
> a.c <br>> !else
> b.c <br>> !endif
> c.c
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Praveen Kumar Amritaluru wrote:

You are right. I meant SOURCES=$(RM_SOURCES)

But any idea why both if-part and else-part are getting executed incase
if(condition) is true.

They aren’t. I guarantee it. You have some other bug. Post the ENTIRE
sources file, and we can try to figure it out.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> ----------

From: xxxxx@lists.osr.com[SMTP:xxxxx@lists.osr.com] on behalf of Roddy, Mark[SMTP:xxxxx@stratus.com]
Reply To: Windows System Software Devs Interest List
Sent: Thursday, April 20, 2006 7:37 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Re:How to build library from object files created in

This works, even though the support for including source files ‘up one
level’ is undocumented.

It is used by some DDK samples so I’d take it as documented. There is yet another interesting technique in some samples:

!include …\sources.inc

TARGETNAME=vadac3

SOURCES=\
$(SOURCES) \
mintopo.cpp \
minwave.cpp

Common SOURCES are defined in …\sources.inc and target specific can be added above way.

BTW (for OP), including common sources file part using !INCLUDE is next common way how to organize build.

Best regards,

Michal Vodicka
UPEK, Inc.
[xxxxx@upek.com, http://www.upek.com]

My apologies if someone has already cleared this up and I just missed
it. Assuming no one has yet…

SOURCES (the entry, not the file, but that’s another story) are
special(1). Build.exe parses for it outside of any makefile processing
so both will get evaluated when building _objects.mac. As a
consequence, the second one is always winning. (The OP was mistaken in
believing things were working in the ‘else’ case… they just looked
like they were working.)

–Scott
(1) And, IIRC, so are a couple of other entries, though I forget which
ones.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Thursday, April 20, 2006 10:38 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Re:How to build library from object
files created in

Praveen Kumar Amritaluru wrote:

>You are right. I meant SOURCES=$(RM_SOURCES)
>
>But any idea why both if-part and else-part are getting
executed incase
>if(condition) is true.
>
>

They aren’t. I guarantee it. You have some other bug. Post
the ENTIRE sources file, and we can try to figure it out.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi,

!ifdef did not work. It gave the same results as !if.

Currently I have overcome by using different sources file and selecting the
source file from the build script.

Regds,
-Praveen

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> Is this there any restriction similar to SOURCES on LINKLIBS or C_DEFI
>> NES
>> too wherein both if-caluse and else-clause
>> statements are executed?
>
> Try using !IFDEF instead.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>