makefile.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Language: Makefile
  3. Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
  4. Contributors: Joël Porquet <joel@porquet.org>
  5. Website: https://www.gnu.org/software/make/manual/html_node/Introduction.html
  6. Category: common
  7. */
  8. function makefile(hljs) {
  9. /* Variables: simple (eg $(var)) and special (eg $@) */
  10. const VARIABLE = {
  11. className: 'variable',
  12. variants: [
  13. {
  14. begin: '\\$\\(' + hljs.UNDERSCORE_IDENT_RE + '\\)',
  15. contains: [ hljs.BACKSLASH_ESCAPE ]
  16. },
  17. {
  18. begin: /\$[@%<?\^\+\*]/
  19. }
  20. ]
  21. };
  22. /* Quoted string with variables inside */
  23. const QUOTE_STRING = {
  24. className: 'string',
  25. begin: /"/,
  26. end: /"/,
  27. contains: [
  28. hljs.BACKSLASH_ESCAPE,
  29. VARIABLE
  30. ]
  31. };
  32. /* Function: $(func arg,...) */
  33. const FUNC = {
  34. className: 'variable',
  35. begin: /\$\([\w-]+\s/,
  36. end: /\)/,
  37. keywords: {
  38. built_in:
  39. 'subst patsubst strip findstring filter filter-out sort ' +
  40. 'word wordlist firstword lastword dir notdir suffix basename ' +
  41. 'addsuffix addprefix join wildcard realpath abspath error warning ' +
  42. 'shell origin flavor foreach if or and call eval file value'
  43. },
  44. contains: [ VARIABLE ]
  45. };
  46. /* Variable assignment */
  47. const ASSIGNMENT = {
  48. begin: '^' + hljs.UNDERSCORE_IDENT_RE + '\\s*(?=[:+?]?=)'
  49. };
  50. /* Meta targets (.PHONY) */
  51. const META = {
  52. className: 'meta',
  53. begin: /^\.PHONY:/,
  54. end: /$/,
  55. keywords: {
  56. $pattern: /[\.\w]+/,
  57. 'meta-keyword': '.PHONY'
  58. }
  59. };
  60. /* Targets */
  61. const TARGET = {
  62. className: 'section',
  63. begin: /^[^\s]+:/,
  64. end: /$/,
  65. contains: [ VARIABLE ]
  66. };
  67. return {
  68. name: 'Makefile',
  69. aliases: [
  70. 'mk',
  71. 'mak',
  72. 'make',
  73. ],
  74. keywords: {
  75. $pattern: /[\w-]+/,
  76. keyword: 'define endef undefine ifdef ifndef ifeq ifneq else endif ' +
  77. 'include -include sinclude override export unexport private vpath'
  78. },
  79. contains: [
  80. hljs.HASH_COMMENT_MODE,
  81. VARIABLE,
  82. QUOTE_STRING,
  83. FUNC,
  84. ASSIGNMENT,
  85. META,
  86. TARGET
  87. ]
  88. };
  89. }
  90. module.exports = makefile;