2

I am doing something like this:

all: 
    @SET /p filecontent= < somefile.txt
    @echo %filecontent%

However the filecontent variable does not seem to hold the contents of the file somefile.txt.

Community
  • 1
  • 1
Vitaly P
  • 1,121
  • 3
  • 11
  • 21

3 Answers3

2

It is possible to read a file that is not a valid nmake file using !INCLUDE. For examle if we have a version file version that contains a single line of text we can do that:

//version file
1.2.4

//makefile
VERSION= \
!INCLUDE <version>

It is not working if the file contains more than one line.

Taavi Valjaots
  • 111
  • 1
  • 4
1

Simply ensure somefile.txt is in acceptable nmake syntax, and then !include it. Thus:

c:>type somefile.txt
PASSWORD=secret
c:>type makefile
!INCLUDE somefile.txt
!MESSAGE Password is [$(PASSWORD)]
c:>nmake -nologo
Password is [secret]
bobbogo
  • 14,989
  • 3
  • 48
  • 57
0

You could try something like this:

# ---- vitaly.mak ----

target1:
# create and invoke a temporary cmd file
@<<mygetpassword.cmd
 @echo off
 setlocal
 @SET /p filecontent= < secret.txt
 @echo %filecontent%
 endlocal
<<

#--- END ---

I think a cmd/bat file run within nmake.exe cannot affect the environment of nmake. So you must use the password that you grabbed from the secret.txt within the temporary cmd file.

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713
  • Just undone the misguided downvote here. :) The example in the question itself was confused (doesn't show what OP *really* wanted to achieve), and in the strict context of what is *actually* shown there, i.e. the command block of a rule, your answer is correct: *there* (or "at that time") you really can't change the NMAKE macros any more, AFAIK. – Sz. Aug 20 '19 at 23:58