Author Topic: Passing env vars to an nmake process  (Read 3717 times)

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Passing env vars to an nmake process
« on: October 20, 2021, 01:09:32 pm »
I'm using IBM nmake. During processing of the main makefile, I would like to import values set by an external .cmd, let's name it queryvar.cmd. These vars should be used in pathnames to call e.g. an OS/2 copy command.

Code: [Select]
ALL:
#  queryvar.cmd should set DIR1
   @queryvar.cmd
   copy $(DIR1)\sub1\file.1 G:\

How can a value be passed from queryvar.cmd to the running nmake, so that it can be used as $(DIR1) in the example above?

It works well when setting env vars before calling nmake. But in this case nmake is already started. It won't matter for me if queryvar.cmd really sets env vars or just returns the value of one env var only.

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: Passing env vars to an nmake process
« Reply #1 on: October 20, 2021, 10:23:59 pm »
Found a solution with a temporary file:

queryvar.cmd was changed to write DIR1=Value to STDOUT. Then I call

Code: [Select]
queryvar.cmd > tmpfile

tmpfile is then included within a pseudo target.

Because !include is expanded by the preprocessor, tmpfile must exist when the preprocessor runs the !include line. That is achieved by using

Code: [Select]
!if [queryvar.cmd > tmpfile]
!endif

All together:

Code: [Select]
ALL:
!ifndef DIR1
! if [queryvar.cmd > tmpfile]
! endif
! include tmpfile
!endif
   @echo DIR1 is defined after including tmpfile as: $(DIR1)

(It's heavily simplified compared to my original, hopefully I didn't break it.)

Any more ideas?
« Last Edit: October 20, 2021, 10:36:06 pm by Andreas Schnellbacher »

Andi B.

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +11/-2
    • View Profile
Re: Passing env vars to an nmake process
« Reply #2 on: October 21, 2021, 07:34:00 am »
I'm sure I stumbled over the same problem a few times in the last > 20 years. Sorry I've no solution offhand. But please keep posting your results.

Guess you checked the wpstoolkit, xworkplace, xwlan ... makefiles before.

Andreas Schnellbacher

  • Hero Member
  • *****
  • Posts: 827
  • Karma: +14/-0
    • View Profile
Re: Passing env vars to an nmake process
« Reply #3 on: October 21, 2021, 09:53:18 am »
Thanks. Yes, these nmake projects (by Christian and Ulrich) are usually my source. All specials of xwlan are included in nepmd, too. This is (after much reading and trying) my first notable change of a makefile.

I've added changeset 4764 to implement the temp. file technique. Related are changesets 4757 and 4758.