How to define global shell functions in a Makefile?

前端 未结 7 979
醉酒成梦
醉酒成梦 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 13:09

    This is really ghetto, but whatever. I use zsh, but I'm sure there are bash and sh equivalents.

    Makefile:

    export ZDOTDIR := ./
    
    SHELL := /usr/bin/env zsh
    
    default:
        f
    

    .zshenv, same directory as Makefile:

    f () { echo 'CHECK OUT THIS AWESOME FUNCTION!' }
    

    The ZDOTDIR variable makes zsh look in the current directory for dotfiles. Then you just stick what you want in .zshenv.

    $ make
    f
    CHECK OUT THIS AWESOME FUNCTION!
    

提交回复
热议问题