Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the output of a command when using Microsoft nmake?

Tags:

makefile

nmake

With make on linux, we can do things like:

foo=$(shell /bin/bar)

which runs the command bar and assigns the output to foo. This can later be used in the makefile by referencing $(foo).

But now I have a Microsoft project on my hands that is compiled and linked with the Microsoft nmake.exe. Is there an equivalent thing for nmake that would allow me to run a command and assign the output to a variable?

like image 414
Stéphane Avatar asked Feb 03 '11 06:02

Stéphane


2 Answers

Although this is an old question, there is a method of doing what is asked; its just convoluted, like everything in batch files!

One has to use the combined mechanisms of the fact that make imports environmental variables and that the preprocessor can invoke commands, and then call the Makefile recursively. It assume the Makefile is called Makefile (with no extension, which is the default).

!IFNDEF MAKE
MAKE=NMAKE
!ENDIF
!IFNDEF SHELLVALUE
!   IF [echo off && FOR /F "usebackq" %i IN (`hostname`) DO  SET SHELLVALUE=%i && $(MAKE)  /$(MAKEFLAGS) /nologo /f $(MAKEDIR)\Makefile && exit /b  ] == 0
!     MESSAGE Make completed
!   ELSE
!     ERROR Error in nmake
!   ENDIF
!ELSE
# $(SHELLVALUE) now contains the string returned from the command USERNAME
!MESSAGE Shellvalue is $(SHELLVALUE)
#      Put the parts of the makefile that depend on SHELLVALUE here
!ENDIF
#
# To be a valid makefile it must have some rules to perform
all:
     @echo;$(SHELLVALUE)

Yes, I know its horrible, but it does demonstrate how to do the technique, which can be done with any shell command and not just hostname.

like image 103
Brian Tompsett - 汤莱恩 Avatar answered Nov 19 '22 18:11

Brian Tompsett - 汤莱恩


I think the answer is "no." There is no equivalent.

I'd recommend that you convert to MSBuild if possible.

like image 35
Cheeso Avatar answered Nov 19 '22 17:11

Cheeso