blob: a6d8ad47e39709109fd878897fbe8586c74b824a [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Makefile
Bram Moolenaarade0d392020-01-21 22:33:58 +01003" Maintainer: Roland Hieber <rohieb+vim-iR0jGdkV@rohieb.name>, <https://github.com/rohieb>
Bram Moolenaar4c92e752019-02-17 21:18:32 +01004" Previous Maintainer: Claudio Fleiner <claudio@fleiner.com>
Bram Moolenaarade0d392020-01-21 22:33:58 +01005" URL: https://github.com/vim/vim/blob/master/runtime/syntax/make.vim
Bram Moolenaar76db9e02022-11-09 21:21:04 +00006" Last Change: 2022 Nov 06
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +02007" 2025 Apr 15 by Vim project: rework Make flavor detection (#17089)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02009" quit when a syntax file was already loaded
10if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000011 finish
12endif
13
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020014let s:cpo_save = &cpo
15set cpo&vim
16
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020017" enable GNU extension when b:make_flavor is not set—detection failed or Makefile is POSIX-compliant
18let s:make_flavor = 'gnu'
19
Bram Moolenaar071d4272004-06-13 20:20:40 +000020" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000021syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000022syn match makeNextLine "\\\n\s*"
23
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020024" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
Bram Moolenaarb17893a2020-03-14 08:19:51 +010025syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$"
26 \ contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000027
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020028if get(b:, 'make_flavor', s:make_flavor) == 'microsoft'
29 " Microsoft Makefile specials
30 syn case ignore
31 syn match makeInclude "^!\s*include\s.*$"
32 syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s*if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
33 syn case match
34endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000035
36" identifiers
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020037if get(b:, 'make_flavor', s:make_flavor) == 'microsoft'
Ken Takataeb4b9032024-07-25 21:07:13 +020038 syn region makeIdent start="\$(" end=")" contains=makeStatement,makeIdent
39 syn region makeIdent start="\${" end="}" contains=makeStatement,makeIdent
40else
41 syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
42 syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
43endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000044syn match makeIdent "\$\$\w*"
45syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010046syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
Bram Moolenaarade0d392020-01-21 22:33:58 +010047syn match makeIdent "^ *[^:#= \t]*\s*::="me=e-3
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010048syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000049syn match makeIdent "%"
50
51" Makefile.in variables
52syn match makeConfig "@[A-Za-z0-9_]\+@"
53
54" make targets
Bram Moolenaar9834b962019-12-04 20:43:03 +010055syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1
56syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaarb17893a2020-03-14 08:19:51 +010058syn region makeTarget transparent matchgroup=makeTarget
Bram Moolenaar76db9e02022-11-09 21:21:04 +000059 \ start="^[~A-Za-z0-9_./$(){}%-][A-Za-z0-9_./\t ${}()%-]*&\?:\?:\{1,2}[^:=]"rs=e-1
Bram Moolenaarb529cfb2022-07-25 15:42:07 +010060 \ end="[^\\]$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010061 \ keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment,makeDString
62 \ skipnl nextGroup=makeCommands
Bram Moolenaar76db9e02022-11-09 21:21:04 +000063syn match makeTarget "^[~A-Za-z0-9_./$(){}%*@-][A-Za-z0-9_./\t $(){}%*@-]*&\?::\=\s*$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010064 \ contains=makeIdent,makeSpecTarget,makeComment
65 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000066
Bram Moolenaarb17893a2020-03-14 08:19:51 +010067syn region makeSpecTarget transparent matchgroup=makeSpecTarget
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020068 \ start="^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|NOTPARALLEL\|POSIX\)\>\s*:\{1,2}[^:=]"rs=e-1
Bram Moolenaarb17893a2020-03-14 08:19:51 +010069 \ end="[^\\]$" keepend
70 \ contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020071syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|NOTPARALLEL\|POSIX\)\>\s*::\=\s*$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +010072 \ contains=makeIdent,makeComment
73 \ skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000074
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +020075if get(b:, 'make_flavor', s:make_flavor) == 'bsd'
76 syn region makeSpecTarget transparent matchgroup=makeSpecTarget
77 \ start="^\.DELETE_ON_ERROR\>\s*:\{1,2}[^:=]"rs=e-1
78 \ end="[^\\]$" keepend
79 \ contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands
80 syn match makeSpecTarget "^\.DELETE_ON_ERROR\>\s*::\=\s*$"
81 \ contains=makeIdent,makeComment
82 \ skipnl nextgroup=makeCommands,makeCommandError
83elseif get(b:, 'make_flavor', s:make_flavor) == 'gnu'
84 syn region makeSpecTarget transparent matchgroup=makeSpecTarget
85 \ start="^\.\(EXPORT_ALL_VARIABLES\|DELETE_ON_ERROR\|INTERMEDIATE\|KEEP_STATE\|LIBPATTERNS\|ONESHELL\|SECONDARY\)\>\s*:\{1,2}[^:=]"rs=e-1
86 \ end="[^\\]$" keepend
87 \ contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands
88 syn match makeSpecTarget "^\.\(EXPORT_ALL_VARIABLES\|DELETE_ON_ERROR\|INTERMEDIATE\|KEEP_STATE\|LIBPATTERNS\|ONESHELL\|SECONDARY\)\>\s*::\=\s*$"
89 \ contains=makeIdent,makeComment
90 \ skipnl nextgroup=makeCommands,makeCommandError
91endif
92
Bram Moolenaar071d4272004-06-13 20:20:40 +000093syn match makeCommandError "^\s\+\S.*" contained
Bram Moolenaarb17893a2020-03-14 08:19:51 +010094syn region makeCommands contained start=";"hs=s+1 start="^\t"
95 \ end="^[^\t#]"me=e-1,re=e-1 end="^$"
96 \ contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString
97 \ nextgroup=makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000098syn match makeCmdNextLine "\\\n."he=e-1 contained
99
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100100" some directives
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100101syn match makeInclude "^ *[-s]\=include\s.*$"
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100102syn match makeExport "^ *\(export\|unexport\)\>"
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +0200103if get(b:, 'make_flavor', s:make_flavor) == 'gnu'
104 " Statements / Functions (GNU make)
105 syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)"
106 syn match makeStatement "^ *vpath\>"
107 syn match makeOverride "^ *override\>"
108 syn match makeStatement contained "[({]\(abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|file\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|guile\|if\|info\|intcmp\|join\|lastword\|let\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|subst\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1
109endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110
111" Comment
Ken Takataeb4b9032024-07-25 21:07:13 +0200112if !exists("make_no_comments")
Eisuke Kawashimaf35bd762025-04-15 19:20:06 +0200113 if get(b:, 'make_flavor', s:make_flavor) == 'microsoft'
Ken Takataeb4b9032024-07-25 21:07:13 +0200114 syn match makeComment "#.*" contains=@Spell,makeTodo
115 else
116 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
117 syn match makeComment "#$" contains=@Spell
118 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119endif
120syn keyword makeTodo TODO FIXME XXX contained
121
122" match escaped quotes and any other escaped character
123" except for $, as a backslash in front of a $ does
124" not make it a standard character, but instead it will
125" still act as the beginning of a variable
126" The escaped char is not highlightet currently
127syn match makeEscapedChar "\\[^$]"
128
129
Bram Moolenaar9834b962019-12-04 20:43:03 +0100130syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent
131syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
133
134" Syncing
135syn sync minlines=20 maxlines=200
136
137" Sync on Make command block region: When searching backwards hits a line that
138" can't be a command or a comment, use makeCommands if it looks like a target,
139" NONE otherwise.
140syn sync match makeCommandSync groupthere NONE "^[^\t#]"
141syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
142syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
143
144" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200145" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000146
Bram Moolenaar723dd942019-04-04 13:11:03 +0200147hi def link makeNextLine makeSpecial
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200148hi def link makeCmdNextLine makeSpecial
Bram Moolenaarb17893a2020-03-14 08:19:51 +0100149hi link makeOverride makeStatement
150hi link makeExport makeStatement
151
Bram Moolenaar723dd942019-04-04 13:11:03 +0200152hi def link makeSpecTarget Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200153if !exists("make_no_commands")
Bram Moolenaar723dd942019-04-04 13:11:03 +0200154hi def link makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155endif
Bram Moolenaar723dd942019-04-04 13:11:03 +0200156hi def link makeImplicit Function
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200157hi def link makeTarget Function
158hi def link makeInclude Include
Bram Moolenaar723dd942019-04-04 13:11:03 +0200159hi def link makePreCondit PreCondit
160hi def link makeStatement Statement
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200161hi def link makeIdent Identifier
162hi def link makeSpecial Special
163hi def link makeComment Comment
164hi def link makeDString String
165hi def link makeSString String
166hi def link makeBString Function
167hi def link makeError Error
168hi def link makeTodo Todo
169hi def link makeDefine Define
170hi def link makeCommandError Error
171hi def link makeConfig PreCondit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000172
173let b:current_syntax = "make"
174
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200175let &cpo = s:cpo_save
176unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177" vim: ts=8