blob: 62a591a8211e197940d19170d714f2153d3c61d8 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Makefile
Bram Moolenaar4c92e752019-02-17 21:18:32 +01003" Maintainer: Roland Hieber <rohieb+vim-iR0jGdkV@rohieb.name>
4" Previous Maintainer: Claudio Fleiner <claudio@fleiner.com>
5" URL: https://github.com/vim/vim/syntax/make.vim
Bram Moolenaar9834b962019-12-04 20:43:03 +01006" Last Change: 2019 Dec 04
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02008" quit when a syntax file was already loaded
9if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +000010 finish
11endif
12
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020013let s:cpo_save = &cpo
14set cpo&vim
15
16
Bram Moolenaar071d4272004-06-13 20:20:40 +000017" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000018syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000019syn match makeNextLine "\\\n\s*"
20
21" some directives
Bram Moolenaar723dd942019-04-04 13:11:03 +020022syn match makePreCondit "^ *\(ifn\=\(eq\|def\)\>\|else\(\s\+ifn\=\(eq\|def\)\)\=\>\|endif\>\)"
Bram Moolenaar9834b962019-12-04 20:43:03 +010023syn match makeInclude "^ *[-s]\=include\s.*$"
Bram Moolenaar8dff8182006-04-06 20:18:50 +000024syn match makeStatement "^ *vpath"
25syn match makeExport "^ *\(export\|unexport\)\>"
26syn match makeOverride "^ *override"
Bram Moolenaar071d4272004-06-13 20:20:40 +000027hi link makeOverride makeStatement
28hi link makeExport makeStatement
29
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020030" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
31syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33" Microsoft Makefile specials
34syn case ignore
Bram Moolenaar9834b962019-12-04 20:43:03 +010035syn match makeInclude "^!\s*include\s.*$"
Bram Moolenaar723dd942019-04-04 13:11:03 +020036syn match makePreCondit "^!\s*\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|else\s*if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000037syn case match
38
39" identifiers
Bram Moolenaar9834b962019-12-04 20:43:03 +010040syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent
41syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +000042syn match makeIdent "\$\$\w*"
43syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010044syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
45syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000046syn match makeIdent "%"
47
48" Makefile.in variables
49syn match makeConfig "@[A-Za-z0-9_]\+@"
50
51" make targets
Bram Moolenaar9834b962019-12-04 20:43:03 +010052syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1
53syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
Bram Moolenaar9834b962019-12-04 20:43:03 +010055syn region makeTarget transparent matchgroup=makeTarget start="^[~A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"rs=e-1 end=";"re=e-1,me=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment,makeDString skipnl nextGroup=makeCommands
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010056syn match makeTarget "^[~A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget,makeComment skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010058syn region makeSpecTarget transparent matchgroup=makeSpecTarget start="^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*:\{1,2}[^:=]"rs=e-1 end="[^\\]$" keepend contains=makeIdent,makeSpecTarget,makeNextLine,makeComment skipnl nextGroup=makeCommands
59syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>\s*::\=\s*$" contains=makeIdent,makeComment skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000060
61syn match makeCommandError "^\s\+\S.*" contained
62syn region makeCommands start=";"hs=s+1 start="^\t" end="^[^\t#]"me=e-1,re=e-1 end="^$" contained contains=makeCmdNextLine,makeSpecial,makeComment,makeIdent,makePreCondit,makeDefine,makeDString,makeSString nextgroup=makeCommandError
63syn match makeCmdNextLine "\\\n."he=e-1 contained
64
65
66" Statements / Functions (GNU make)
Bram Moolenaar4c92e752019-02-17 21:18:32 +010067syn match makeStatement contained "(\(abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|file\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|guile\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|subst\|suffix\|value\|warning\|wildcard\|word\|wordlist\|words\)\>"ms=s+1
Bram Moolenaar071d4272004-06-13 20:20:40 +000068
69" Comment
70if exists("make_microsoft")
Bram Moolenaar9964e462007-05-05 17:54:07 +000071 syn match makeComment "#.*" contains=@Spell,makeTodo
Bram Moolenaar8dff8182006-04-06 20:18:50 +000072elseif !exists("make_no_comments")
Bram Moolenaar9964e462007-05-05 17:54:07 +000073 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
74 syn match makeComment "#$" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000075endif
76syn keyword makeTodo TODO FIXME XXX contained
77
78" match escaped quotes and any other escaped character
79" except for $, as a backslash in front of a $ does
80" not make it a standard character, but instead it will
81" still act as the beginning of a variable
82" The escaped char is not highlightet currently
83syn match makeEscapedChar "\\[^$]"
84
85
Bram Moolenaar9834b962019-12-04 20:43:03 +010086syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contained contains=makeIdent
87syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contained contains=makeIdent
Bram Moolenaar071d4272004-06-13 20:20:40 +000088syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
89
90" Syncing
91syn sync minlines=20 maxlines=200
92
93" Sync on Make command block region: When searching backwards hits a line that
94" can't be a command or a comment, use makeCommands if it looks like a target,
95" NONE otherwise.
96syn sync match makeCommandSync groupthere NONE "^[^\t#]"
97syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
98syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
99
100" Define the default highlighting.
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200101" Only when an item doesn't have highlighting yet
Bram Moolenaar071d4272004-06-13 20:20:40 +0000102
Bram Moolenaar723dd942019-04-04 13:11:03 +0200103hi def link makeNextLine makeSpecial
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200104hi def link makeCmdNextLine makeSpecial
Bram Moolenaar723dd942019-04-04 13:11:03 +0200105hi def link makeSpecTarget Statement
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200106if !exists("make_no_commands")
Bram Moolenaar723dd942019-04-04 13:11:03 +0200107hi def link makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108endif
Bram Moolenaar723dd942019-04-04 13:11:03 +0200109hi def link makeImplicit Function
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200110hi def link makeTarget Function
111hi def link makeInclude Include
Bram Moolenaar723dd942019-04-04 13:11:03 +0200112hi def link makePreCondit PreCondit
113hi def link makeStatement Statement
Bram Moolenaarf37506f2016-08-31 22:22:10 +0200114hi def link makeIdent Identifier
115hi def link makeSpecial Special
116hi def link makeComment Comment
117hi def link makeDString String
118hi def link makeSString String
119hi def link makeBString Function
120hi def link makeError Error
121hi def link makeTodo Todo
122hi def link makeDefine Define
123hi def link makeCommandError Error
124hi def link makeConfig PreCondit
Bram Moolenaar071d4272004-06-13 20:20:40 +0000125
126let b:current_syntax = "make"
127
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200128let &cpo = s:cpo_save
129unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130" vim: ts=8