Search code examples
makefilemainframezos

Using conditionals in a z/OS makefile


I have been successfully using z/OS make to build my application. I have now come to point in my project where I move from a debug version of the application to a "release" version, a.k.a non-debug, so my compile options and link options change.

I have been trying to use conditionals in my makefile to mean I don't have to change multiple lines in the file in order to switch between the two build modes, but I cannot find ANY examples of conditionals in z/OS make, and the small amount of documentation in the manuals about them is not enough to actually discover how to make it work. I'm hoping someone on here has managed to make them work (no pun intended) and can enlighten me.

Here's what I would like to have (snippet from makefile):-

BuildType=DEBUG

.IF ($(BuildType)==DEBUG)
CompOpts= -c -W"c,debug,LP64,sscomm,dll" -D_DEBUG
.ELSE
CompOpts= -c -s -W"c,LP64,sscomm,compress,dll"
.END

Note that I understand there are many different ways to set BuildType. This snippet has it set in-line for simplicity of asking the question. The problem at hand is the syntax of the .IF statement. I cannot make the .IF statement work. That's what I am hoping for help, or working examples of.

I have managed to get something working where I only have to edit one character in the file to switch between the two modes, but it is not by any means ideal. N.B. ANYTHING is not set to any value in the makefile.

# In the .IF clause below, if you have != it will run the DEBUG build
# and if you have == it will run the RELEASE build
.IF ($(ANYTHING)==$(NULL))
CompOpts= -c -W"c,debug,LP64,sscomm,dll" -D_DEBUG
.ELSE
CompOpts= -c -s -W"c,LP64,sscomm,compress,dll"
.END

Solution

  • The following syntax should work with z/OS make:

    .IF $(BuildType) == DEBUG
    CompOpts= -c -W"c,debug,LP64,sscomm,dll" -D_DEBUG
    .ELSE
    CompOpts= -c -s -W"c,LP64,sscomm,compress,dll"
    .END
    

    When you invoke the make file with:

    make -DBuildType=DEBUG
    

    it will select the debug version of compiler options, otherwise it will select the production version.