makefile.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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, build-system
  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. { begin: /\$[@%<?\^\+\*]/ }
  18. ]
  19. };
  20. /* Quoted string with variables inside */
  21. const QUOTE_STRING = {
  22. className: 'string',
  23. begin: /"/,
  24. end: /"/,
  25. contains: [
  26. hljs.BACKSLASH_ESCAPE,
  27. VARIABLE
  28. ]
  29. };
  30. /* Function: $(func arg,...) */
  31. const FUNC = {
  32. className: 'variable',
  33. begin: /\$\([\w-]+\s/,
  34. end: /\)/,
  35. keywords: { built_in:
  36. 'subst patsubst strip findstring filter filter-out sort '
  37. + 'word wordlist firstword lastword dir notdir suffix basename '
  38. + 'addsuffix addprefix join wildcard realpath abspath error warning '
  39. + 'shell origin flavor foreach if or and call eval file value' },
  40. contains: [ VARIABLE ]
  41. };
  42. /* Variable assignment */
  43. const ASSIGNMENT = { begin: '^' + hljs.UNDERSCORE_IDENT_RE + '\\s*(?=[:+?]?=)' };
  44. /* Meta targets (.PHONY) */
  45. const META = {
  46. className: 'meta',
  47. begin: /^\.PHONY:/,
  48. end: /$/,
  49. keywords: {
  50. $pattern: /[\.\w]+/,
  51. keyword: '.PHONY'
  52. }
  53. };
  54. /* Targets */
  55. const TARGET = {
  56. className: 'section',
  57. begin: /^[^\s]+:/,
  58. end: /$/,
  59. contains: [ VARIABLE ]
  60. };
  61. return {
  62. name: 'Makefile',
  63. aliases: [
  64. 'mk',
  65. 'mak',
  66. 'make',
  67. ],
  68. keywords: {
  69. $pattern: /[\w-]+/,
  70. keyword: 'define endef undefine ifdef ifndef ifeq ifneq else endif '
  71. + 'include -include sinclude override export unexport private vpath'
  72. },
  73. contains: [
  74. hljs.HASH_COMMENT_MODE,
  75. VARIABLE,
  76. QUOTE_STRING,
  77. FUNC,
  78. ASSIGNMENT,
  79. META,
  80. TARGET
  81. ]
  82. };
  83. }
  84. export { makefile as default };