nmake inference rules question

A bit off topic, hopefully not so much.

I’m working on project which is built from several C files in multiple
directories. The standard build utility way i.e. build LIB in every
directory and link together doesn’t suit well because files are small and I
need to edit them all and build using DIRS and LIBS would be unnecessarily
slow (probably, I don’t plan trying). Also, the result isn’t a driver and I
don’t need DDK environment.

Instead, I tried to use nmake and found a problem using inference rules
(i.e. .c.obj:). What I want is to compile all obj files to one directory
(.\debug, .\release). So I write dependencies as $(TARGETPATH)\file.obj:
adir\file.c. To my surprise, inference rules without directories don’t work.
I had to write {adir}.c{$(TARGETPATH)}.obj: like rules instead. It is
stupid, error prone and what is the worst, batch rules aren’t invoked for
all files at once. Batch rules was the main reason why I started playing
with it because they speed up compiling significantly.

I can’t believe nmake is so limited. Any advice? (no, no, I don’t want to
use VS :wink:

To make things clear, the question is: how to write inference rule for
sources in multiple directories and the same destination directory. Thanks.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]

Do you need use nmake or just want something make-like?

nmake is joke. Try gnu make instead. This is the greatest make ever
written. Then, this done in trivial way (–directory option plus VPATH
variable)

Vladimir

----- Original Message -----
From: “Michal Vodicka”
To: “NT Developers Interest List”
Sent: Thursday, May 02, 2002 8:02 AM
Subject: [ntdev] nmake inference rules question

> A bit off topic, hopefully not so much.
>
> I’m working on project which is built from several C files in multiple
> directories. The standard build utility way i.e. build LIB in every
> directory and link together doesn’t suit well because files are small and
I
> need to edit them all and build using DIRS and LIBS would be unnecessarily
> slow (probably, I don’t plan trying). Also, the result isn’t a driver and
I
> don’t need DDK environment.
>
> Instead, I tried to use nmake and found a problem using inference rules
> (i.e. .c.obj:). What I want is to compile all obj files to one directory
> (.\debug, .\release). So I write dependencies as $(TARGETPATH)\file.obj:
> adir\file.c. To my surprise, inference rules without directories don’t
work.
> I had to write {adir}.c{$(TARGETPATH)}.obj: like rules instead. It is
> stupid, error prone and what is the worst, batch rules aren’t invoked for
> all files at once. Batch rules was the main reason why I started playing
> with it because they speed up compiling significantly.
>
> I can’t believe nmake is so limited. Any advice? (no, no, I don’t want to
> use VS :wink:
>
> To make things clear, the question is: how to write inference rule for
> sources in multiple directories and the same destination directory.
Thanks.
>
> Best regards,
>
> Michal Vodicka
> STMicroelectronics Design and Application s.r.o.
> [michal.vodicka@st.com, http:://www.st.com]
>
>
> —
> You are currently subscribed to ntdev as: 100xcd@100xcd.com
> To unsubscribe send a blank email to %%email.unsub%%
>

Probably ud like to have a look at sun’s jdk build makefile which uses gnu
make … its a wonderful example which addresses a similar situation like
yours ( a nested make ) … and even much more sophisticated ones … I means
mutiple common destinations dirs …

–Arup

-----Original Message-----
From: Vladimir Ignatov [mailto:100xcd@100xCD.com]
Sent: Thursday, May 02, 2002 10:54 AM
To: NT Developers Interest List
Subject: [ntdev] Re: nmake inference rules question

Do you need use nmake or just want something make-like?

nmake is joke. Try gnu make instead. This is the greatest make ever
written. Then, this done in trivial way (–directory option plus VPATH
variable)

Vladimir

----- Original Message -----
From: “Michal Vodicka”
> To: “NT Developers Interest List”
> Sent: Thursday, May 02, 2002 8:02 AM
> Subject: [ntdev] nmake inference rules question
>
>
> > A bit off topic, hopefully not so much.
> >
> > I’m working on project which is built from several C files
> in multiple
> > directories. The standard build utility way i.e. build LIB in every
> > directory and link together doesn’t suit well because files
> are small and
> I
> > need to edit them all and build using DIRS and LIBS would
> be unnecessarily
> > slow (probably, I don’t plan trying). Also, the result
> isn’t a driver and
> I
> > don’t need DDK environment.
> >
> > Instead, I tried to use nmake and found a problem using
> inference rules
> > (i.e. .c.obj:). What I want is to compile all obj files to
> one directory
> > (.\debug, .\release). So I write dependencies as
> $(TARGETPATH)\file.obj:
> > adir\file.c. To my surprise, inference rules without
> directories don’t
> work.
> > I had to write {adir}.c{$(TARGETPATH)}.obj: like rules
> instead. It is
> > stupid, error prone and what is the worst, batch rules
> aren’t invoked for
> > all files at once. Batch rules was the main reason why I
> started playing
> > with it because they speed up compiling significantly.
> >
> > I can’t believe nmake is so limited. Any advice? (no, no, I
> don’t want to
> > use VS :wink:
> >
> > To make things clear, the question is: how to write
> inference rule for
> > sources in multiple directories and the same destination directory.
> Thanks.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> >
> > —
> > You are currently subscribed to ntdev as: 100xcd@100xcd.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@quark.co.in
> To unsubscribe send a blank email to %%email.unsub%%
>

Once in my life I wrote a make program, so I’m interested: Vlad,
what features of the gnu make you find important that are not
available in nmake ?

Alberto.

================

On 2 May 2002, at 9:23, Vladimir Ignatov wrote:

Do you need use nmake or just want something make-like?

nmake is joke. Try gnu make instead. This is the greatest make ever
written. Then, this done in trivial way (–directory option plus VPATH
variable)

Vladimir

----- Original Message -----
From: “Michal Vodicka”
> To: “NT Developers Interest List”
> Sent: Thursday, May 02, 2002 8:02 AM
> Subject: [ntdev] nmake inference rules question
>
>
> > A bit off topic, hopefully not so much.
> >
> > I’m working on project which is built from several C files in multiple
> > directories. The standard build utility way i.e. build LIB in every
> > directory and link together doesn’t suit well because files are small and
> I
> > need to edit them all and build using DIRS and LIBS would be unnecessarily
> > slow (probably, I don’t plan trying). Also, the result isn’t a driver and
> I
> > don’t need DDK environment.
> >
> > Instead, I tried to use nmake and found a problem using inference rules
> > (i.e. .c.obj:). What I want is to compile all obj files to one directory
> > (.\debug, .\release). So I write dependencies as $(TARGETPATH)\file.obj:
> > adir\file.c. To my surprise, inference rules without directories don’t
> work.
> > I had to write {adir}.c{$(TARGETPATH)}.obj: like rules instead. It is
> > stupid, error prone and what is the worst, batch rules aren’t invoked for
> > all files at once. Batch rules was the main reason why I started playing
> > with it because they speed up compiling significantly.
> >
> > I can’t believe nmake is so limited. Any advice? (no, no, I don’t want to
> > use VS :wink:
> >
> > To make things clear, the question is: how to write inference rule for
> > sources in multiple directories and the same destination directory.
> Thanks.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> >
> > —
> > You are currently subscribed to ntdev as: 100xcd@100xcd.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to %%email.unsub%%
>

> Once in my life I wrote a make program, so I’m interested: Vlad,

what features of the gnu make you find important that are not
available in nmake ?

This is an examle from my article about using gnu make. Directory tree look
like:

/project
makefile
/source

/bin
/release
/debug

“gmake debug” build executable file iEdit.exe (with apropriate settings) in
“/bin/debug” and “gmake release” build executable in “/bin/release”
subdirectory. Source files list builded automatically (all .cpp files from
“/source” directory).

Can you do it with nmake?

Vladimir

----------------------------------------------------------------------------
----------------------
#
# example_7-auto-find/project/Makefile
#
# Example 7. Automatically find source files
#
# (C) Vladimir Ignatov, 2000-2001
#

program_name := iEdit
include_dirs = .

release: CFLAGS := -O3 -fomit-frame-pointer
debug: CFLAGS := -O0 -g

# —

.PHONY: all release debug <br> clean_release clean_debug clean <br> rebuild rebuild_release rebuild_debug

export CFLAGS

root_dir := $(shell cd … ; pwd)
project_dir := $(root_dir)/project
source_dir := $(root_dir)/source
release_dir := $(root_dir)/bin/release
debug_dir := $(root_dir)/bin/debug

source_files := $(shell find $(source_dir) -path .cpp)

all: release debug

release:
@-mkdir -p $(release_dir)
@$(MAKE) -C $(release_dir) -f $(project_dir)/Makefile $(program_name)
root_dir=$(root_dir)

debug:
@-mkdir -p $(debug_dir)
@$(MAKE) -C $(debug_dir) -f $(project_dir)/Makefile $(program_name)
root_dir=$(root_dir)

$(program_name): $(notdir $(patsubst %.cpp,%.o,$(source_files)))
gcc -pipe $(LDFLAGS) $^ -o $@

vpath %.cpp $(sort $(dir $(source_files) ))

%.o: %.cpp
gcc -pipe -c -MD $(CFLAGS) $(addprefix -I$(source_dir)/,$(include_dirs))
$<

-include .d

clean_release:
-rm $(release_dir)/
.o $(release_dir)/
.d
$(release_dir)/$(program_name).exe

clean_debug:
-rm $(debug_dir)/
.o $(debug_dir)/*.d $(debug_dir)/$(program_name).exe

clean: clean_release clean_debug

rebuild: clean all
rebuild_release: clean_release release
rebuild_debug: clean_debug debug

.SUFFIXES:

Thanks to all who replied. So general conclusion is nmake is too stupid to
do something like this?

Actually, we already use GNU make for our night builds. The reason why I
tried to use nmake was batch rules, I don’t know how to do something like
this using GNU make.

I mean following:

.c.obj::
$(CC) $(PARAMS) $<

It calls compiler only once for all C files which need to recompile. With VC
it really speeds up compilation. Is it possible using GNU make?

Thanks.

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: 100xcd@100xCD.com[SMTP:100xcd@100xCD.com]
Reply To: xxxxx@lists.osr.com
Sent: Thursday, May 02, 2002 7:23 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: nmake inference rules question

Do you need use nmake or just want something make-like?

nmake is joke. Try gnu make instead. This is the greatest make ever
written. Then, this done in trivial way (–directory option plus VPATH
variable)

Vladimir

----- Original Message -----
From: “Michal Vodicka”
> To: “NT Developers Interest List”
> Sent: Thursday, May 02, 2002 8:02 AM
> Subject: [ntdev] nmake inference rules question
>
>
> > A bit off topic, hopefully not so much.
> >
> > I’m working on project which is built from several C files in multiple
> > directories. The standard build utility way i.e. build LIB in every
> > directory and link together doesn’t suit well because files are small
> and
> I
> > need to edit them all and build using DIRS and LIBS would be
> unnecessarily
> > slow (probably, I don’t plan trying). Also, the result isn’t a driver
> and
> I
> > don’t need DDK environment.
> >
> > Instead, I tried to use nmake and found a problem using inference rules
> > (i.e. .c.obj:). What I want is to compile all obj files to one directory
> > (.\debug, .\release). So I write dependencies as $(TARGETPATH)\file.obj:
> > adir\file.c. To my surprise, inference rules without directories don’t
> work.
> > I had to write {adir}.c{$(TARGETPATH)}.obj: like rules instead. It is
> > stupid, error prone and what is the worst, batch rules aren’t invoked
> for
> > all files at once. Batch rules was the main reason why I started playing
> > with it because they speed up compiling significantly.
> >
> > I can’t believe nmake is so limited. Any advice? (no, no, I don’t want
> to
> > use VS :wink:
> >
> > To make things clear, the question is: how to write inference rule for
> > sources in multiple directories and the same destination directory.
> Thanks.
> >
> > Best regards,
> >
> > Michal Vodicka
> > STMicroelectronics Design and Application s.r.o.
> > [michal.vodicka@st.com, http:://www.st.com]
> >
> >
> > —
> > You are currently subscribed to ntdev as: 100xcd@100xcd.com
> > To unsubscribe send a blank email to %%email.unsub%%
> >
>
>
> —
> You are currently subscribed to ntdev as: michal.vodicka@st.com
> To unsubscribe send a blank email to %%email.unsub%%
>

> Actually, we already use GNU make for our night builds. The reason why I

tried to use nmake was batch rules, I don’t know how to do something like
this using GNU make.

I mean following:

.c.obj::
$(CC) $(PARAMS) $<

It calls compiler only once for all C files which need to recompile. With
VC
it really speeds up compilation. Is it possible using GNU make?

You can ask your question in gnu make’s mailing list. I am not an expert,
but in my opinion - this is impossible. gmake have very clear and
intuitive set of rules. nmake’s “batch rules” does not fits well in
traditional make model.

Vladimir

At 19.45 02/05/2002, you wrote:

I mean following:

.c.obj::
$(CC) $(PARAMS) $<

It calls compiler only once for all C files which need to recompile. With
VC it really speeds up compilation. Is it possible using GNU make?

it does something equivalent, but, IIRC, with a different syntax

> >I mean following:

>
>.c.obj::
> $(CC) $(PARAMS) $<
>
>It calls compiler only once for all C files which need to recompile. With
>VC it really speeds up compilation. Is it possible using GNU make?

it does something equivalent, but, IIRC, with a different syntax

Can you be more specific? Once I translate the whole gnu make manual (about
280 pages) to russian. I don’t remember anything similar to “batch rules”.
Do you mean “$?” automatic variable? Yes, it exist but

%.obj: %.cpp
cl /c $?

will not work like batch rule.

Vladimir

What prevents you from having “debug:” and “release:” being two
different targets in your makefile ? And then you invoke nmake
recursively from inside your master makefile ?

Alberto.

On 2 May 2002, at 17:22, Vladimir Ignatov wrote:

> Once in my life I wrote a make program, so I’m interested: Vlad,
> what features of the gnu make you find important that are not
> available in nmake ?

This is an examle from my article about using gnu make. Directory tree look
like:

/project
makefile
/source

> /bin
> /release
> /debug
>
> “gmake debug” build executable file iEdit.exe (with apropriate settings) in
> “/bin/debug” and “gmake release” build executable in “/bin/release”
> subdirectory. Source files list builded automatically (all .cpp files from
> “/source” directory).
>
> Can you do it with nmake?
>
> Vladimir
>
> ----------------------------------------------------------------------------
> ----------------------
> #
> # example_7-auto-find/project/Makefile
> #
> # Example 7. Automatically find source files
> #
> # (C) Vladimir Ignatov, 2000-2001
> #
>
> program_name := iEdit
> include_dirs = .
>
> release: CFLAGS := -O3 -fomit-frame-pointer
> debug: CFLAGS := -O0 -g
>
> # —
>
> .PHONY: all release debug <br>> clean_release clean_debug clean <br>> rebuild rebuild_release rebuild_debug
>
> export CFLAGS
>
> root_dir := $(shell cd … ; pwd)
> project_dir := $(root_dir)/project
> source_dir := $(root_dir)/source
> release_dir := $(root_dir)/bin/release
> debug_dir := $(root_dir)/bin/debug
>
> source_files := $(shell find $(source_dir) -path .cpp)
>
> all: release debug
>
> release:
> @-mkdir -p $(release_dir)
> @$(MAKE) -C $(release_dir) -f $(project_dir)/Makefile $(program_name)
> root_dir=$(root_dir)
>
> debug:
> @-mkdir -p $(debug_dir)
> @$(MAKE) -C $(debug_dir) -f $(project_dir)/Makefile $(program_name)
> root_dir=$(root_dir)
>
> $(program_name): $(notdir $(patsubst %.cpp,%.o,$(source_files)))
> gcc -pipe $(LDFLAGS) $^ -o $@
>
> vpath %.cpp $(sort $(dir $(source_files) ))
>
> %.o: %.cpp
> gcc -pipe -c -MD $(CFLAGS) $(addprefix -I$(source_dir)/,$(include_dirs))
> $<
>
> -include .d
>
> clean_release:
> -rm $(release_dir)/
.o $(release_dir)/
.d
> $(release_dir)/$(program_name).exe
>
> clean_debug:
> -rm $(debug_dir)/
.o $(debug_dir)/*.d $(debug_dir)/$(program_name).exe
>
> clean: clean_release clean_debug
>
> rebuild: clean all
> rebuild_release: clean_release release
> rebuild_debug: clean_debug debug
>
> .SUFFIXES:
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to %%email.unsub%%
>

If anybody is interested, I finally did it with nmake. It was necessary to
add one level of indirection i.e reference files which contain full pathname
of original file. For every directory with sources I added a rule:

{apath}.c{$(TARGETPATH)}.crf:
truename $< > $@

and added .crf to .SUFFIXES. For every file one line had to be added:

$(TARGETPATH)\afile.obj: $(*R).crf $(HEADERS)

and original line changed:

$(TARGETPATH)\afile.crf: d:\apath\afile$(*B).c

now batch rule looks like:

{$(TARGETPATH)}.crf{$(TARGETPATH)}.obj::
type $< > files.tmp
$(CC_LINE) @files.tmp

Surprisingly, it works and is still faster than to invoke compiler for every
file. The price is really nasty makefile :wink:

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From: 100xcd@100xCD.com[SMTP:100xcd@100xCD.com]
Reply To: xxxxx@lists.osr.com
Sent: Friday, May 03, 2002 8:49 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: nmake inference rules question

> >I mean following:
> >
> >.c.obj::
> > $(CC) $(PARAMS) $<
> >
> >It calls compiler only once for all C files which need to recompile.
With
> >VC it really speeds up compilation. Is it possible using GNU make?
>
> it does something equivalent, but, IIRC, with a different syntax

Can you be more specific? Once I translate the whole gnu make manual
(about
280 pages) to russian. I don’t remember anything similar to “batch rules”.
Do you mean “$?” automatic variable? Yes, it exist but

%.obj: %.cpp
cl /c $?

will not work like batch rule.

Vladimir


You are currently subscribed to ntdev as: michal.vodicka@st.com
To unsubscribe send a blank email to %%email.unsub%%

It is even easier, obj -> crf dependency can be made using one line:

$(OBJECTS): $(OBJECTS:.obj=.crf) $(HEADERS)

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From:
xxxxx@veridicom.cz.nospam[SMTP:xxxxx@veridicom.cz.nospam]
Reply To: xxxxx@lists.osr.com
Sent: Saturday, May 04, 2002 5:09 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Re: nmake inference rules question

If anybody is interested, I finally did it with nmake. It was necessary to
add one level of indirection i.e reference files which contain full
pathname
of original file. For every directory with sources I added a rule:

{apath}.c{$(TARGETPATH)}.crf:
truename $< > $@

and added .crf to .SUFFIXES. For every file one line had to be added:

$(TARGETPATH)\afile.obj: $(*R).crf $(HEADERS)

and original line changed:

$(TARGETPATH)\afile.crf: d:\apath\afile$(*B).c

now batch rule looks like:

{$(TARGETPATH)}.crf{$(TARGETPATH)}.obj::
type $< > files.tmp
$(CC_LINE) @files.tmp

Surprisingly, it works and is still faster than to invoke compiler for
every
file. The price is really nasty makefile :wink:

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]

> ----------
> From: 100xcd@100xCD.com[SMTP:100xcd@100xCD.com]
> Reply To: xxxxx@lists.osr.com
> Sent: Friday, May 03, 2002 8:49 AM
> To: xxxxx@lists.osr.com
> Subject: [ntdev] Re: nmake inference rules question
>
> > >I mean following:
> > >
> > >.c.obj::
> > > $(CC) $(PARAMS) $<
> > >
> > >It calls compiler only once for all C files which need to recompile.
> With
> > >VC it really speeds up compilation. Is it possible using GNU make?
> >
> > it does something equivalent, but, IIRC, with a different syntax
>
> Can you be more specific? Once I translate the whole gnu make manual
> (about
> 280 pages) to russian. I don’t remember anything similar to “batch
rules”.
> Do you mean “$?” automatic variable? Yes, it exist but
>
> %.obj: %.cpp
> cl /c $?
>
> will not work like batch rule.
>
> Vladimir
>
>
> —
> You are currently subscribed to ntdev as: michal.vodicka@st.com
> To unsubscribe send a blank email to %%email.unsub%%
>


You are currently subscribed to ntdev as: michal.vodicka@st.com
To unsubscribe send a blank email to %%email.unsub%%