2024-01-16 21:26:16 +08:00
|
|
|
/*
|
|
|
|
Language: Makefile
|
|
|
|
Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
|
|
|
|
Contributors: Joël Porquet <joel@porquet.org>
|
|
|
|
Website: https://www.gnu.org/software/make/manual/html_node/Introduction.html
|
|
|
|
Category: common
|
|
|
|
*/
|
|
|
|
|
|
|
|
function makefile(hljs) {
|
2023-12-18 13:12:25 +08:00
|
|
|
/* Variables: simple (eg $(var)) and special (eg $@) */
|
2024-01-16 21:26:16 +08:00
|
|
|
const VARIABLE = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'variable',
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
begin: '\\$\\(' + hljs.UNDERSCORE_IDENT_RE + '\\)',
|
2024-01-16 21:26:16 +08:00
|
|
|
contains: [ hljs.BACKSLASH_ESCAPE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
begin: /\$[@%<?\^\+\*]/
|
2024-01-16 21:26:16 +08:00
|
|
|
}
|
2023-12-18 13:12:25 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
/* Quoted string with variables inside */
|
2024-01-16 21:26:16 +08:00
|
|
|
const QUOTE_STRING = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'string',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /"/,
|
|
|
|
end: /"/,
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
|
|
|
hljs.BACKSLASH_ESCAPE,
|
2024-01-16 21:26:16 +08:00
|
|
|
VARIABLE
|
2023-12-18 13:12:25 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
/* Function: $(func arg,...) */
|
2024-01-16 21:26:16 +08:00
|
|
|
const FUNC = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'variable',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /\$\([\w-]+\s/,
|
|
|
|
end: /\)/,
|
2023-12-18 13:12:25 +08:00
|
|
|
keywords: {
|
|
|
|
built_in:
|
|
|
|
'subst patsubst strip findstring filter filter-out sort ' +
|
|
|
|
'word wordlist firstword lastword dir notdir suffix basename ' +
|
|
|
|
'addsuffix addprefix join wildcard realpath abspath error warning ' +
|
2024-01-16 21:26:16 +08:00
|
|
|
'shell origin flavor foreach if or and call eval file value'
|
2023-12-18 13:12:25 +08:00
|
|
|
},
|
2024-01-16 21:26:16 +08:00
|
|
|
contains: [ VARIABLE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
};
|
|
|
|
/* Variable assignment */
|
2024-01-16 21:26:16 +08:00
|
|
|
const ASSIGNMENT = {
|
|
|
|
begin: '^' + hljs.UNDERSCORE_IDENT_RE + '\\s*(?=[:+?]?=)'
|
2023-12-18 13:12:25 +08:00
|
|
|
};
|
|
|
|
/* Meta targets (.PHONY) */
|
2024-01-16 21:26:16 +08:00
|
|
|
const META = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'meta',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /^\.PHONY:/,
|
|
|
|
end: /$/,
|
|
|
|
keywords: {
|
|
|
|
$pattern: /[\.\w]+/,
|
|
|
|
'meta-keyword': '.PHONY'
|
|
|
|
}
|
2023-12-18 13:12:25 +08:00
|
|
|
};
|
|
|
|
/* Targets */
|
2024-01-16 21:26:16 +08:00
|
|
|
const TARGET = {
|
2023-12-18 13:12:25 +08:00
|
|
|
className: 'section',
|
2024-01-16 21:26:16 +08:00
|
|
|
begin: /^[^\s]+:/,
|
|
|
|
end: /$/,
|
|
|
|
contains: [ VARIABLE ]
|
2023-12-18 13:12:25 +08:00
|
|
|
};
|
|
|
|
return {
|
2024-01-16 21:26:16 +08:00
|
|
|
name: 'Makefile',
|
|
|
|
aliases: [
|
|
|
|
'mk',
|
|
|
|
'mak',
|
|
|
|
'make',
|
|
|
|
],
|
|
|
|
keywords: {
|
|
|
|
$pattern: /[\w-]+/,
|
|
|
|
keyword: 'define endef undefine ifdef ifndef ifeq ifneq else endif ' +
|
|
|
|
'include -include sinclude override export unexport private vpath'
|
|
|
|
},
|
2023-12-18 13:12:25 +08:00
|
|
|
contains: [
|
|
|
|
hljs.HASH_COMMENT_MODE,
|
|
|
|
VARIABLE,
|
|
|
|
QUOTE_STRING,
|
|
|
|
FUNC,
|
2024-01-16 21:26:16 +08:00
|
|
|
ASSIGNMENT,
|
2023-12-18 13:12:25 +08:00
|
|
|
META,
|
2024-01-16 21:26:16 +08:00
|
|
|
TARGET
|
2023-12-18 13:12:25 +08:00
|
|
|
]
|
|
|
|
};
|
2024-01-16 21:26:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = makefile;
|