How to define global shell functions in a Makefile?

前端 未结 7 994
醉酒成梦
醉酒成梦 2021-02-12 12:18

I want to define a shell function

#!/bin/sh

test ()
{
  do_some_complicated_tests $1 $2;
  if something; then
    build_thisway $1 $2;
  else
    build_otherway         


        
7条回答
  •  暖寄归人
    2021-02-12 12:56

    Something tells me you'd be better off filtering the output of make -n, but what you ask is possible:

    define test
      @echo do some tests with $(1) and $(2); \
      SOMETHING=$(1)_3 ; \
      if [ $$SOMETHING == foo_3 ]; then \
        echo build this way $(1) $(2); \
      else \
        echo build another way $(1) $(2) ; \
      fi
    endef
    
    someTarget:
        $(call test,foo,bar)
    
    someOtherTarget:
        $(call test,baz,quartz)
    

提交回复
热议问题