Can you make valid Makefiles without tab characters?

前端 未结 10 2583
孤城傲影
孤城傲影 2020-12-02 07:17
target: dependencies
    command1
    command2

On my system (Mac OS X), make seems to require that that Makefiles have a tab character

相关标签:
10条回答
  • 2020-12-02 07:46

    In the time since this question was originally asked, a version of GNU Make has been released that allows you to use something other than Tab as the prefix character. From the mailing list announcement:

    New special variable: .RECIPEPREFIX allows you to reset the recipe introduction character from the default (TAB) to something else. The first character of this variable value is the new recipe introduction character. If the variable is set to the empty string, TAB is used again. It can be set and reset at will; recipes will use the value active when they were first parsed. To detect this feature check the value of $(.RECIPEPREFIX).

    This feature was added in GNU Make 3.82, released in July 2010 (six months after this question's original ask date). Since it has in turn been three years and change since that, it's likely that other Make flavors have followed GNU Make.

    0 讨论(0)
  • 2020-12-02 07:49

    There is a convoluted way of have a valid makefile without tabs.

    If you change your makefile to read:

    target: dependencies; command1; command2
    

    If will work. If you want it on more than one line, then you can do:

    target: dependencies; \
    command1; \
    command2
    

    Messy, but it works.

    0 讨论(0)
  • 2020-12-02 07:55

    If you have a vimrc in your profile you can add this line to prevent vim from changing to spaces:

    autocmd FileType make setlocal noexpandtab
    

    I too was struggling with this, and this fixed it for me. Spread the good word!

    0 讨论(0)
  • 2020-12-02 07:57

    This does it for me if you would like to use spaces

    .RECIPEPREFIX +=
    

    Example

    0 讨论(0)
提交回复
热议问题