Question

1) We have a need for Makefiles to build C++ on both z/OS USS and a Linux platform. Is it advisable to use gnu make on z/OS USS in order to keep our makefiles common ?

2) If the Makefiles are common, then some steps in the Makefiles, would still be conditional to the platform. Can we do that by steps that are similar to conditional compilation? If yes, can we please get help with the syntax?

3) Our z/OS USS Makefiles have shell scripts or groups of commands, as in example below, with the square brackets [] presenting the commands to the shell as a group, rather than one line at a time. It seems that using the GNU make, we had to modify these commands to become one line, which is messy, and the nested loop was a problem. Is there an easier way to group commands using gmake?

  [ 
  dirs=$(targets) 
  rc=0 
  for dir in $$dirs 
  do 
    cd $$dir/src 
    make -r 
    rc=$$? 
    if [ $$rc != 0 ]; then 
      echo "build failed for directory:" $$dir: 
      break; 
    fi 
    cd ../..
   done 
   echo "return code from make = " $$rc 
 ]
Was it helpful?

Solution

Disclaimers:

  1. I know nothing about z/OS USS,
  2. I know a lot about Make (and when you're holding a hammer, ...).

Advice:

  • Yes, I'd recommend using GNUMake on both platforms and keeping your Makefiles as common as possible.
  • There are a couple of ways to put conditionality in a Makefile.

    # Usually one defines a variable first.
    SYSTEM = $(shell uname)
    
    # Then one can define other variables conditionally
    
    SOMEFILE = $(SYSTEM)_file
    
    ifeq ($(SYSTEM), Linux)
    # Do some Linux things, define variables, whatever.
    else
    # Do some z/OS USS things.
    endif
    
    # In a block of commands, if the conditional DOESN'T start with a tab,
    # it's a Make statement and follows Make syntax.
    thing:
    ifeq($(SYSTEM), Linux)
        shell-command-do-something
    endif
    
    # If the conditional DOES follow a tab, Make expands the variables and passes
    # the whole thing to the shell, so the syntax is whatever the shell requires.
    otherthing:
        if($(SYSTEM)==ZOS) do_x ; otherwise do_y ; finish
    

    And there are other, more advanced tricks to try when you're bored with these.

  • I'm not sure what you mean when you say that you want the commands to be processed in groups, but I suspect you can get what you want by appending ;\ to each command in the group, so that they will be executed one by one in the same subshell (otherwise each command gets its own subshell).

  • OTHER TIPS

    If you have a need for portable Makefiles, by all means use GNU make. I've been running it under USS for years now without any problems. If you don't feel comfortable building it yourself, you can get a a copy from here

    I have built several applications on z/OS using Unix System Services (USS) and C/C++/HLASM. I have found it is well worth it to use gmake rather than make. Yes, you have to download gmake and set it up, but it's way easier to use, and way easier to make portable. In addition to gmake, you might want to get bash as well. It is going to be easier to have portable shell scripts between USS and other platforms using bash rather than forcing yourself to use sh. There are probably a few places you can get gmake and bash from, but I've used the Rocket site: http://www.rocketsoftware.com/product-categories/mainframe/bash-zos (it's free if you don't want support).

    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top