3

GNU Make 4.3+

OS: Mac

With the following added to the .zshrc file, I am able to generate auto completions for make at the target level for aMakefile (or 'makefile') containing rules in that literal file.

zstyle ':completion:*:*:make:*' tag-order 'targets'
autoload -U compinit && compinit

However, when I group the commands into subfiles and include them via the include *.mk mechanic, zsh no longer generates the correct auto-completion statement. Only the targets defined in the top level makefile are output.


The exact file structure:

├── install-brew
├── install-oh-my-zsh
├── install-pathogen
├── makefile
├── mk
│   ├── get.mk
│   ├── notes.mk
│   ├── setup.mk
    ...

And makefile:

include mk/*.mk

foo:
  echo foo

bar:
  echo bar

> make [tab] produces:

> make foo
foo bar

And make get-brew:

if [ -z `command -v brew` ]; then ./install-brew; else echo "brew detected: `command -v brew`" >&2; fi

(so the makefile is working)


How does one configure zsh to generate the full user-defined target list from a makefile even when that make file includes supporting make files?

2
  • did you ever figure this out? Commented Sep 26, 2023 at 15:39
  • @KevinPauli I think it might be best to try and use the bash-completion utility (installed via brew) in zsh. Otherwise, I installed bash 4+ via brew. The people who've used only Mac prefer zsh, so I'll try and figure this out for a bit.
    – Chris
    Commented May 29 at 13:46

1 Answer 1

2
zstyle ':completion:*:make:*:targets' call-command true
zstyle ':completion:*:*:make:*' tag-order 'targets'

this worked for me, for 2 level makefile "include": just add to your .zshrc file. source: https://github.com/zsh-users/zsh-completions/issues/813#issuecomment-902592371

That causes the make completion to call make -nsp --no-print-directory --always-make if it detects make is GNU make to help determine the list of possible targets.

It used to be done unconditionally but that changed to be conditional to a zstyle setting in 2001 as calling make here could end-up being an expensive and potentially risky operation.

The description of that call-command style can be found with info zsh call-command:

call-command

This style is used in the function for commands such as make and ant where calling the command directly to generate matches suffers problems such as being slow or, as in the case of make can potentially cause actions in the makefile to be executed. If it is set to 'true' the command is called to generate matches. The default value of this style is 'false'.

2
  • On my Mac, using oh-my-zsh, it will auto-complete Make actions "included" via two levels of includes. Which OS are you using?
    – oba
    Commented Jun 6 at 11:36
  • 1
    I am using this solution on my mac today, so I'll delete my prior comment.
    – Chris
    Commented Jun 6 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .