OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Andreas Schnellbacher on October 20, 2021, 01:09:32 pm

Title: Passing env vars to an nmake process
Post by: Andreas Schnellbacher 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.
Title: Re: Passing env vars to an nmake process
Post by: Andreas Schnellbacher 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?
Title: Re: Passing env vars to an nmake process
Post by: Andi B. 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.
Title: Re: Passing env vars to an nmake process
Post by: Andreas Schnellbacher 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 (http://trac.netlabs.org/nepmd/changeset/4764) to implement the temp. file technique. Related are changesets 4757 (http://trac.netlabs.org/nepmd/changeset/4757) and 4758 (http://trac.netlabs.org/nepmd/changeset/4758).