1) 我们需要 Makefiles 在 z/OS USS 和 Linux 平台上构建 C++。为了保持我们的 makefile 的通用性,是否建议在 z/OS USS 上使用 gnu make?

2) 如果 Makefile 是通用的,那么 Makefile 中的某些步骤仍然会以平台为条件。我们可以通过类似于条件编译的步骤来做到这一点吗?如果是,我们可以获得语法方面的帮助吗?

3) 我们的 z/OS USS Makefile 具有 shell 脚本或命令组,如下例所示,其中方括号 [] 将命令作为一组而不是一次一行呈现给 shell。看来使用GNU make,我们得把这些命令修改成一行,比较乱,而且嵌套循环也是个问题。有没有更简单的方法使用 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 
 ]
有帮助吗?

解决方案

免责声明:

  1. 我对 z/OS USS 一无所知,
  2. 我对 Make 了解很多(当你拿着锤子时,......)。

建议:

  • 是的,我建议在两个平台上使用 GNUMake 并让您的 Makefile 尽可能通用。
  • 有几种方法可以将条件放入 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
    

    当您对这些感到厌倦时,还有其他更高级的技巧可以尝试。

  • 当您说希望按组处理命令时,我不确定您的意思,但我怀疑您可以通过将 ;\ 附加到组中的每个命令来获得您想要的内容,以便它们将被执行一个在同一个子 shell 中(否则每个命令都有自己的子 shell)。

  • 许可以下: CC-BY-SA归因
    不隶属于 StackOverflow
    scroll top