Could you please tell me what is the reason for such different behavior when inheriting variables (macros)?
Example #1 (the simplest one).
The contents of the makefile "calling.mak":
# variable inheritance checking
TEST_VARIABLE1 = 30
!IF [set TEST_VARIABLE1=30]
!ENDIF
!IF [$(MAKE) /l /e /f called.mak task1]
!ENDIF
!MESSAGE
!MESSAGE *****
!MESSAGE value TEST_VARIABLE1 on calling makefile is -- $(TEST_VARIABLE1) --
!MESSAGE env-var TEST_VARIABLE1 output by the command `set TEST_VARIABLE1` in calling makefile:
!IF [set TEST_VARIABLE1]
!ENDIF
!MESSAGE value TEST_VARIABLE2 on calling makefile is -- $(TEST_VARIABLE2) --
!MESSAGE env-var TEST_VARIABLE2 output by the command `set TEST_VARIABLE2` in calling makefile:
!IF [set TEST_VARIABLE2]
!ENDIF
# Which is kind of understandable.
# The nmake.exe program inherits those environment variables that were defined before it was called.
!MESSAGE *****
!MESSAGE
The contents of the makefile "callied.mak":
# variable inheritance checking
TEST_VARIABLE1 = 40
task1 : task2
@ echo:
@ echo( #####
@ echo value TEST_VARIABLE1 in task1 on called makefile -- $(TEST_VARIABLE1) --
@ echo env-var TEST_VARIABLE1 in task1 on called makefile -- %%TEST_VARIABLE1%% --
@ echo env-var TEST_VARIABLE1 output by `set TEST_VARIABLE1` in task1
@ set TEST_VARIABLE1
# Setup env-var TEST_VERIABLE2 from TEST_VARIABLE1
@ set TEST_VARIABLE2=%%TEST_VARIABLE1%%
@ echo value TEST_VARIABLE2 in task1 on called makefile -- $(TEST_VARIABLE2) --
@ echo env-var TEST_VARIABLE2 in task1 on called -- %%TEST_VARIABLE2%% --
@ echo env-var TEST_VARIABLE2 output by `set TEST_VARIABLE2` in task1
@ set TEST_VARIABLE2
@ echo:
@ echo( #####
task2 :
@ echo:
@ echo( #####
@ echo value TEST_VARIABLE1 in task2 on called makefile -- $(TEST_VARIABLE1) --
@ echo env-var TEST_VARIABLE1 in task2 on called makefile -- %%TEST_VARIABLE1%% --
@ echo env-var TEST_VARIABLE1 output by `set TEST_VARIABLE1` in task2
@ set TEST_VARIABLE1
@ echo value TEST_VARIABLE2 in task2 on called makefile -- $(TEST_VARIABLE2) --
# @ echo env-var TEST_VARIABLE2 in task2 on called -- %%TEST_VARIABLE2%% --
# @ echo env-var TEST_VARIABLE2 output by `set TEST_VARIABLE2` in task2
# @ set TEST_VARIABLE2
# If you uncomment the lines above, it will fail. Which is kind of understandable.
# Target "task1" will be executed after target "task2" is processed.
@ echo:
@ echo( #####
Let's set the environment variable TEST_VARIABLE1:
set "TEST_VARIABLE1=10"
Let's check its value:
set TEST_VARIABLE1
TEST_VARIABLE1=10
Now run the nmake.exe program with this command:
nmake.exe /elf calling.mak
Otputs:
#####
value TEST_VARIABLE1 in task2 on called makefile -- 30 --
env-var TEST_VARIABLE1 in task2 on called makefile -- 30 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task2
TEST_VARIABLE1=30
value TEST_VARIABLE2 in task2 on called makefile -- --
##########
value TEST_VARIABLE1 in task1 on called makefile -- 30 --
env-var TEST_VARIABLE1 in task1 on called makefile -- 30 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task1
TEST_VARIABLE1=30
value TEST_VARIABLE2 in task1 on called makefile -- --
env-var TEST_VARIABLE2 in task1 on called -- 30 --
env-var TEST_VARIABLE2 output byset TEST_VARIABLE2in task1
TEST_VARIABLE2=30
#####*****
value TEST_VARIABLE1 on calling makefile is -- 10 --
env-var TEST_VARIABLE1 output by the commandset TEST_VARIABLE1in calling make file:
TEST_VARIABLE1=30
value TEST_VARIABLE2 on calling makefile is -- --
env-var TEST_VARIABLE2 output by the commandset TEST_VARIABLE2in calling make file:
Environment variable TEST_VARIABLE2 not defined
*****
Now let's change the line in the make-file from this one !IF [set TEST_VARIABLE1=30] to this one !IF [set "TEST_VARIABLE1=30"]
Run the nmake.exe program with this command:
nmake.exe /elf calling.mak
Otputs:
#####
value TEST_VARIABLE1 in task2 on called makefile -- 10 --
env-var TEST_VARIABLE1 in task2 on called makefile -- 10 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task2
TEST_VARIABLE1=10
value TEST_VARIABLE2 in task2 on called makefile -- --
##########
value TEST_VARIABLE1 in task1 on called makefile -- 10 --
env-var TEST_VARIABLE1 in task1 on called makefile -- 10 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task1
TEST_VARIABLE1=10
value TEST_VARIABLE2 in task1 on called makefile -- --
env-var TEST_VARIABLE2 in task1 on called -- 10 --
env-var TEST_VARIABLE2 output byset TEST_VARIABLE2in task1
TEST_VARIABLE2=10
#####*****
value TEST_VARIABLE1 on calling makefile is -- 10 --
env-var TEST_VARIABLE1 output by the commandset TEST_VARIABLE1in calling make file:
TEST_VARIABLE1=10
value TEST_VARIABLE2 on calling makefile is -- --
env-var TEST_VARIABLE2 output by the commandset TEST_VARIABLE2in calling make file:
Environment variable TEST_VARIABLE2 not defined
*****
Now let's change the line in the make-file from this one !IF [set TEST_VARIABLE1=30] to this one !IF [set TEST_VARIABLE1=30 & set TEST_VARIABLE3=70]. And add lines to the "calling.mak" and "called.mak" files to check the result.
nmake.exe /elf calling.mak
Otputs:
#####
value TEST_VARIABLE1 in task2 on called makefile -- 30
env-var TEST_VARIABLE1 in task2 on called makefile -- 30
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task2
TEST_VARIABLE1=30 & set TEST_VARIABLE3=70
value TEST_VARIABLE2 in task2 on called makefile -- --
value TEST_VARIABLE3 in task2 on called makefile -- --
env-var TEST_VARIABLE3 in task2 on called -- %TEST_VARIABLE3% --
env-var TEST_VARIABLE3 output byset TEST_VARIABLE3in task2
Environment variable TEST_VARIABLE3 not defined
NMAKE : fatal error U1077: 'set' : return code '0x1'
Stop.*****
value TEST_VARIABLE1 on calling makefile is -- 10 --
env-var TEST_VARIABLE1 output by the commandset TEST_VARIABLE1in calling make file:
TEST_VARIABLE1=30 & set TEST_VARIABLE3=70
value TEST_VARIABLE1 on calling makefile is -- --
env-var TEST_VARIABLE2 output by the commandset TEST_VARIABLE2in calling make file:
Environment variable TEST_VARIABLE2 not defined
value TEST_VARIABLE3 on calling makefile is -- --
env-var TEST_VARIABLE3 output by the commandset TEST_VARIABLE3in calling make file:
Environment variable TEST_VARIABLE3 not defined
*****
Now let's change the line in the make-file from this one !IF [set TEST_VARIABLE1=30] to this one !IF [set TEST_VARIABLE1=30] && [set TEST_VARIABLE3=70].
nmake.exe /elf calling.mak
Otputs:
#####
value TEST_VARIABLE1 in task2 on called makefile -- 30 --
env-var TEST_VARIABLE1 in task2 on called makefile -- 30 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task2
TEST_VARIABLE1=30
value TEST_VARIABLE2 in task2 on called makefile -- --
value TEST_VARIABLE3 in task2 on called makefile -- 70 --
env-var TEST_VARIABLE3 in task2 on called -- 70 --
env-var TEST_VARIABLE3 output byset TEST_VARIABLE3in task2
TEST_VARIABLE3=70
##########
value TEST_VARIABLE1 in task1 on called makefile -- 30 --
env-var TEST_VARIABLE1 in task1 on called makefile -- 30 --
env-var TEST_VARIABLE1 output byset TEST_VARIABLE1in task1
TEST_VARIABLE1=30
value TEST_VARIABLE2 in task1 on called makefile -- --
env-var TEST_VARIABLE2 in task1 on called -- 30 --
env-var TEST_VARIABLE2 output byset TEST_VARIABLE2in task1
TEST_VARIABLE2=30
value TEST_VARIABLE3 in task1 on called makefile -- 70 --
env-var TEST_VARIABLE3 in task1 on called -- 70 --
env-var TEST_VARIABLE3 output byset TEST_VARIABLE3in task1
TEST_VARIABLE3=70
#####*****
value TEST_VARIABLE1 on calling makefile is -- 10 --
env-var TEST_VARIABLE1 output by the commandset TEST_VARIABLE1in calling make file:
TEST_VARIABLE1=30
value TEST_VARIABLE2 on calling makefile is -- --
env-var TEST_VARIABLE2 output by the commandset TEST_VARIABLE2in calling make file:
Environment variable TEST_VARIABLE2 not defined
value TEST_VARIABLE3 on calling makefile is -- --
env-var TEST_VARIABLE3 output by the commandset TEST_VARIABLE3in calling make file:
TEST_VARIABLE3=70
*****
What is the reason for this behavior? How can I ensure that nmake inherits variables and macros normally?
Actually, it is required to transfer macros from one makefile to another when they are connected via a directive !INCLUDE in the third makefile.
Previously, as I remember in version 1.5, there was such a wonderful command line key as "/V". But, apparently, he got lost somewhere along the way.