blob: 6fd46aaa545288a1c2725d70685009f24af3fe46 [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 Moolenaar0c5fa7d2012-10-05 22:26:30 +02005" Last Change: 2012 Oct 05
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" For version 5.x: Clear all syntax items
8" For version 6.x: Quit when a syntax file was already loaded
9if version < 600
10 syntax clear
11elseif exists("b:current_syntax")
12 finish
13endif
14
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020015let s:cpo_save = &cpo
16set cpo&vim
17
18
Bram Moolenaar071d4272004-06-13 20:20:40 +000019" some special characters
Bram Moolenaar8dff8182006-04-06 20:18:50 +000020syn match makeSpecial "^\s*[@+-]\+"
Bram Moolenaar071d4272004-06-13 20:20:40 +000021syn match makeNextLine "\\\n\s*"
22
23" some directives
Bram Moolenaar8dff8182006-04-06 20:18:50 +000024syn match makePreCondit "^ *\(ifeq\>\|else\>\|endif\>\|ifneq\>\|ifdef\>\|ifndef\>\)"
25syn match makeInclude "^ *[-s]\=include"
26syn match makeStatement "^ *vpath"
27syn match makeExport "^ *\(export\|unexport\)\>"
28syn match makeOverride "^ *override"
Bram Moolenaar071d4272004-06-13 20:20:40 +000029hi link makeOverride makeStatement
30hi link makeExport makeStatement
31
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020032" catch unmatched define/endef keywords. endef only matches it is by itself on a line, possibly followed by a commend
33syn region makeDefine start="^\s*define\s" end="^\s*endef\s*\(#.*\)\?$" contains=makeStatement,makeIdent,makePreCondit,makeDefine
Bram Moolenaar071d4272004-06-13 20:20:40 +000034
35" Microsoft Makefile specials
36syn case ignore
Bram Moolenaar8dff8182006-04-06 20:18:50 +000037syn match makeInclude "^! *include"
38syn 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 +000039syn case match
40
41" identifiers
42syn region makeIdent start="\$(" skip="\\)\|\\\\" end=")" contains=makeStatement,makeIdent,makeSString,makeDString
43syn region makeIdent start="\${" skip="\\}\|\\\\" end="}" contains=makeStatement,makeIdent,makeSString,makeDString
44syn match makeIdent "\$\$\w*"
45syn match makeIdent "\$[^({]"
Bram Moolenaar8dff8182006-04-06 20:18:50 +000046syn match makeIdent "^ *\a\w*\s*[:+?!*]="me=e-2
47syn match makeIdent "^ *\a\w*\s*="me=e-1
Bram Moolenaar071d4272004-06-13 20:20:40 +000048syn match makeIdent "%"
49
50" Makefile.in variables
51syn match makeConfig "@[A-Za-z0-9_]\+@"
52
53" make targets
54" 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 +000055syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:$"me=e-1 nextgroup=makeSource
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +020056syn match makeImplicit "^\.[A-Za-z0-9_./\t -]\+\s*:[^=]"me=e-2 nextgroup=makeSource
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
58syn 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 skipnl nextGroup=makeCommands
59syn match makeTarget "^[A-Za-z0-9_./$()%*@-][A-Za-z0-9_./\t $()%*@-]*::\=\s*$" contains=makeIdent,makeSpecTarget skipnl nextgroup=makeCommands,makeCommandError
60
Bram Moolenaar8dff8182006-04-06 20:18:50 +000061syn 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 skipnl nextGroup=makeCommands
62syn 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 skipnl nextgroup=makeCommands,makeCommandError
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
64syn match makeCommandError "^\s\+\S.*" contained
65syn 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
66syn match makeCmdNextLine "\\\n."he=e-1 contained
67
68
69" Statements / Functions (GNU make)
Bram Moolenaare37d50a2008-08-06 17:06:04 +000070syn 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 +000071
72" Comment
73if exists("make_microsoft")
Bram Moolenaar9964e462007-05-05 17:54:07 +000074 syn match makeComment "#.*" contains=@Spell,makeTodo
Bram Moolenaar8dff8182006-04-06 20:18:50 +000075elseif !exists("make_no_comments")
Bram Moolenaar9964e462007-05-05 17:54:07 +000076 syn region makeComment start="#" end="^$" end="[^\\]$" keepend contains=@Spell,makeTodo
77 syn match makeComment "#$" contains=@Spell
Bram Moolenaar071d4272004-06-13 20:20:40 +000078endif
79syn keyword makeTodo TODO FIXME XXX contained
80
81" match escaped quotes and any other escaped character
82" except for $, as a backslash in front of a $ does
83" not make it a standard character, but instead it will
84" still act as the beginning of a variable
85" The escaped char is not highlightet currently
86syn match makeEscapedChar "\\[^$]"
87
88
89syn region makeDString start=+\(\\\)\@<!"+ skip=+\\.+ end=+"+ contains=makeIdent
90syn region makeSString start=+\(\\\)\@<!'+ skip=+\\.+ end=+'+ contains=makeIdent
91syn region makeBString start=+\(\\\)\@<!`+ skip=+\\.+ end=+`+ contains=makeIdent,makeSString,makeDString,makeNextLine
92
93" Syncing
94syn sync minlines=20 maxlines=200
95
96" Sync on Make command block region: When searching backwards hits a line that
97" can't be a command or a comment, use makeCommands if it looks like a target,
98" NONE otherwise.
99syn sync match makeCommandSync groupthere NONE "^[^\t#]"
100syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}[^:=]"
101syn sync match makeCommandSync groupthere makeCommands "^[A-Za-z0-9_./$()%-][A-Za-z0-9_./\t $()%-]*:\{1,2}\s*$"
102
103" Define the default highlighting.
104" For version 5.7 and earlier: only when not done already
105" For version 5.8 and later: only when an item doesn't have highlighting yet
106if version >= 508 || !exists("did_make_syn_inits")
107 if version < 508
108 let did_make_syn_inits = 1
109 command -nargs=+ HiLink hi link <args>
110 else
111 command -nargs=+ HiLink hi def link <args>
112 endif
113
114 HiLink makeNextLine makeSpecial
115 HiLink makeCmdNextLine makeSpecial
116 HiLink makeSpecTarget Statement
117 if !exists("make_no_commands")
118 HiLink makeCommands Number
119 endif
120 HiLink makeImplicit Function
121 HiLink makeTarget Function
122 HiLink makeInclude Include
123 HiLink makePreCondit PreCondit
124 HiLink makeStatement Statement
125 HiLink makeIdent Identifier
126 HiLink makeSpecial Special
127 HiLink makeComment Comment
128 HiLink makeDString String
129 HiLink makeSString String
130 HiLink makeBString Function
131 HiLink makeError Error
132 HiLink makeTodo Todo
133 HiLink makeDefine Define
134 HiLink makeCommandError Error
135 HiLink makeConfig PreCondit
136 delcommand HiLink
137endif
138
139let b:current_syntax = "make"
140
Bram Moolenaar0c5fa7d2012-10-05 22:26:30 +0200141let &cpo = s:cpo_save
142unlet s:cpo_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143" vim: ts=8