How to use shell builtin function from a Makefile?

后端 未结 5 1491
一个人的身影
一个人的身影 2020-12-16 22:02

I just stumbled on this problem. I tried to write a very basic Makefile target:

core: myprogram
        ulimit -c 10000
        ./myprogram
             


        
5条回答
  •  青春惊慌失措
    2020-12-16 22:54

    The default shell for any Makefile is sh. If you have to use builtins of a specific shell, specify that shell in your Makefile:

    SHELL:=bash
    

    Note that this is bad practice, because the idea is that your Makefile should work on any machine, not only those with bash installed.

    If you want to support either variant (external vs. builtin), you can check for the availability of bash resp. ulimit via which, and set a variable containing the command to use (ulimit vs. bash -c "ulimit") depending on the outcome of that check.

    Edit: MadScientist is absolutely right about the "current shell only" aspect of ulimit. I'll keep this answer intact for documentation purposes, but it doesn't help with perror's specific problem.

提交回复
热议问题