Set environment variable in makefile read by jom / nmake

Viewed 1127

I have a makefile, which is designed to work with nmake (in a ms visual studio command line prompt). The makefile itself sets an environment variable MY_SAY_SOMETHING needed for other tools like a batchfile test.bat. This works very fine with nmake.

However, I want to use Qt's jom instead to speed up my build process by usage of several processor cores with the option -J. The tool jomis considered to be a clone of nmake according to Qt it, so the makefile should be compatible.

The problem is: jom does not set environment variables on a windows machine! At least not in the way the nmake supports it.

So my question is: How do I set an environment variable with jom?


This is the shortest possible example showing my problem:

makefile:

!IF [set MY_SAY_SOMETHING="my super message"]
!ENDIF

all:
    @test.bat

test.bat:

@echo off
echo THIS IS MY SUPER MESSAGE "%MY_SAY_SOMETHING%"

Now I'm just calling the makefile with nmake (from the visual studio command line prompt). This looks like this:

D:\> nmake

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved.

THIS IS MY SUPER MESSAGE ""my super message""

When I'm calling jom (either from the visual studio command line prompt or a regular windows cmd.exe prompt), I just get this:

D:\> jom

jom 1.1.3 - empower your cores

THIS IS MY SUPER MESSAGE ""

I also called the -P option for nmake and jom to get more information about how the makefile is interpreted. However, my environment variable was printed with nmake, but not with jom. I also tried the option -E (override environment variable macros) with the same result.

Maybe it is just a bug in jom...

3 Answers

Edit: This is my first answer, exploring three ideas which do not work. See my second answer for an actual solution.


This is more of a comment than an answer, but it does suggest a work-around.

The output of the following makefile:

!IF [echo Test 1:] && [set MY_SAY_SOMETHING="my super message"] && [set MY]
!ENDIF

!IF [echo Test 2: && set MY_SAY_SOMETHING="my unsuper message" && set MY]
!ENDIF

WORK_AROUND = set MY_SAY_SOMETHING="this is a possible work-around"

all:
    @echo Test 3:
    @-call set MY
    @test.bat
    @echo Test 4:
    @$(WORK_AROUND)
    @call set MY
    @test.bat

is for nmake:

>nmake

Microsoft (R) Program Maintenance Utility Version 14.10.25019.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Test 1:
MY_SAY_SOMETHING="my super message"
Test 2:
MY_SAY_SOMETHING="my unsuper message"
Test 3:
MY_SAY_SOMETHING="my super message"
THIS IS MY SUPER MESSAGE ""my super message""
Test 4:
MY_SAY_SOMETHING="this is a possible work-around"
THIS IS MY SUPER MESSAGE ""this is a possible work-around""

and for jom:

>jom
Test 1:
Environment variable MY not defined
Test 2:
MY_SAY_SOMETHING="my unsuper message"

jom 1.1.3 - empower your cores

Test 3:
Environment variable MY not defined
THIS IS MY SUPER MESSAGE ""
Test 4:
MY_SAY_SOMETHING="this is a possible work-around"
THIS IS MY SUPER MESSAGE ""this is a possible work-around""

Note 1: For nmake, the output of Test 2 is what I would expect, but it doesn't "take". The set MY in Test 3 gives what was set in Test 1.

Note 2: For jom, Test 2 gives the desired output, but again it doesn't "take". And Test 1 fails.

Note 3: In the recipe, the call is needed for jom for set MY to work. It is optional for nmake.

The makefile:

all: .MY_ENVIRONMENT
    @test.bat

.MY_ENVIRONMENT:
    @set MY_SAY_SOMETHING="my super message"

will work with both nmake and jom:

>nmake -l
THIS IS MY SUPER MESSAGE ""my super message""

>jom -l
THIS IS MY SUPER MESSAGE ""my super message""

In the Makefile you can write:

!IF [call set MY_SAY_SOMETHING="my super message"]
!ENDIF

This should not break nmake, but fixes JOM.

Related