blob: f022a4e9ac2273082dde84b457bc4fe2fb53120f [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
2" Language: Makefile
3" Maintainer: Claudio Fleiner <claudio@fleiner.com>
4" URL: http://www.fleiner.com/vim/syntax/make.vim
Bram Moolenaar2b8388b2015-02-28 13:11:45 +01005" Last Change: 2015 Feb 28
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
Bram Moolenaar89bcfda2016-08-30 23:26:57 +02007" quit when a syntax file was already loaded
8if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00009 finish
10endif
11
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020012let s:cpo_save = &cpo
13set cpo&vim
14
15
Bram Moolenaar071d4272004-06-13 20:20:40 +000016" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000017syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000018syn match makeNextLine "\\\n\s*"
19
20" some directives
Bram Moolenaar8dff8182006-04-06 20:18:50 +000021syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)"
22syn match makeInclude "^ *[-s]\=include"
23syn match makeStatement "^ *vpath"
24syn match makeExport "^ *\(export\|unexport\)\>"
25syn match makeOverride "^ *override"
Bram Moolenaar071d4272004-06-13 20:20:40 +000026hi link makeOverride makeStatement
27hi link makeExport makeStatement
28
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020029" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
30syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000031
32" Microsoft Makefile specials
33syn case ignore
Bram Moolenaar8dff8182006-04-06 20:18:50 +000034syn match makeInclude "^! *include"
35syn match makePreCondit "! *\(cmdswitches\|error\|message\|include\|if\|ifdef\|ifndef\|else\|elseif\|else if\|else\s*ifdef\|else\s*ifndef\|endif\|undef\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000036syn case match
37
38" identifiers
39syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString
40syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString
41syn match makeIdent "\$\$\w*"
42syn match makeIdent "\$[^({]"
Bram Moolenaar2b8388b2015-02-28 13:11:45 +010043syn match makeIdent "^ *[^:#= \t]*\s*[:+?!*]="me=e-2
44syn match makeIdent "^ *[^:#= \t]*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000045syn match makeIdent "%"
46
47" Makefile.in variables
48syn match makeConfig "@[A-Za-z0-9_]\+@"
49
50" make targets
51" syn match makeSpecTarget "^\.\(SUFFIXES\|PHONY\|DEFAULT\|PRECIOUS\|IGNORE\|SILENT\|EXPORT_ALL_VARIABLES\|KEEP_STATE\|LIBPATTERNS\|NOTPARALLEL\|DELETE_ON_ERROR\|INTERMEDIATE\|POSIX\|SECONDARY\)\>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000052syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020053syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource
Bram Moolenaar071d4272004-06-13 20:20:40 +000054
Bram Moolenaar2b8388b2015-02-28 13:11:45 +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 skipnl nextGroup=makeCommands
56syn 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 Moolenaare37d50a2008-08-06 17:06:04 +000067syn match makeStatement contained "(\(subst\|abspath\|addprefix\|addsuffix\|and\|basename\|call\|dir\|error\|eval\|filter-out\|filter\|findstring\|firstword\|flavor\|foreach\|if\|info\|join\|lastword\|notdir\|or\|origin\|patsubst\|realpath\|shell\|sort\|strip\|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
86syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent
87syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent
88syn 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
102command -nargs=+ HiLink hi def link <args>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200104HiLink makeNextLine makeSpecial
105HiLink makeCmdNextLine makeSpecial
106HiLink makeSpecTarget Statement
107if !exists("make_no_commands")
108HiLink makeCommands Number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109endif
Bram Moolenaar89bcfda2016-08-30 23:26:57 +0200110HiLink makeImplicit Function
111HiLink makeTarget Function
112HiLink makeInclude Include
113HiLink makePreCondit PreCondit
114HiLink makeStatement Statement
115HiLink makeIdent Identifier
116HiLink makeSpecial Special
117HiLink makeComment Comment
118HiLink makeDString String
119HiLink makeSString String
120HiLink makeBString Function
121HiLink makeError Error
122HiLink makeTodo Todo
123HiLink makeDefine Define
124HiLink makeCommandError Error
125HiLink makeConfig PreCondit
126delcommand HiLink
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
128let b:current_syntax = "make"
129
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200130let &cpo = s:cpo_save
131unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000132" vim: ts=8