Go is an amazing, awesome programming language. But it has in many ways too much, and in other ways, too little. This is an attempt to balance it.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .PHONY: all build clean
  2. COM_COLOR = \033[0;34m
  3. OBJ_COLOR = \033[0;36m
  4. MAGENTA_COLOR = \033[0;35m
  5. CYAN_COLOR = \033[0;36m
  6. OK_COLOR = \033[0;32m
  7. ERROR_COLOR = \033[0;31m
  8. WARN_COLOR = \033[0;33m
  9. NO_COLOR = \033[m
  10. OK_STRING = [OK]
  11. ERROR_STRING = [ERROR]
  12. WARN_STRING = [WARNING]
  13. COM_STRING = [Compiling]
  14. define title
  15. printf "%b" "\n$(CYAN_COLOR)=> $(WARN_COLOR)$(1)$(NO_COLOR)\n";
  16. endef
  17. define section_title
  18. printf "%b" "$(MAGENTA_COLOR)-> $(OK_COLOR)$(1)$(NO_COLOR)\n";
  19. endef
  20. define run_and_test
  21. printf "%b" "- $(OBJ_COLOR)$(2)$(NO_COLOR)\r"; \
  22. $(1) 2> $@.log; \
  23. RESULT=$$?; \
  24. if [ $$RESULT -ne 0 ]; then \
  25. printf '%-60b%b' '- $(OBJ_COLOR)$(2)' '$(ERROR_COLOR)$(ERROR_STRING)$(NO_COLOR)\n'; \
  26. elif [ -s $@.log ]; then \
  27. printf '%-60b%b' '- $(OBJ_COLOR)$(2)' '$(WARNING_COLOR)$(WARNING_STRING)$(NO_COLOR)\n'; \
  28. else \
  29. printf '%-60b%b' '- $(OBJ_COLOR)$(2)' '$(OK_COLOR)$(OK_STRING)$(NO_COLOR)\n'; \
  30. fi; \
  31. cat $@.log; \
  32. rm -f $@.log; \
  33. exit $$RESULT
  34. endef
  35. SRC_PATH=lib/
  36. SRC=$(wildcard $(SRC_PATH)og/*.og $(SRC_PATH)translator/*.og $(SRC_PATH)ast/*.og $(SRC_PATH)ast/walker/*.og $(SRC_PATH)ast/common/*.og)
  37. RES=$(SRC:.og=.go)
  38. EXE=og
  39. CC=og
  40. all: grammar build
  41. grammar: parser/*.go
  42. parser/*.go: parser/Og.g4
  43. @$(call section_title,Grammar)
  44. @$(call run_and_test,go generate,Generating parser from $<)
  45. build:
  46. @$(call title,Building from `$(CC) -v`)
  47. @$(CC) lib
  48. @make test -s --no-print-directory
  49. $(EXE): $(SRC) $(RES)
  50. @make test --no-print-directory
  51. # @$(call section_title,Building Binary)
  52. # @go build
  53. re:
  54. @$(call title,Full Re-Bootstrap)
  55. @make re_ --no-print-directory
  56. re_: grammar
  57. @make clean build --no-print-directory
  58. @make CC='./og' clean new --no-print-directory
  59. new:
  60. @make CC='./og' all --no-print-directory
  61. test:
  62. @$(call section_title,Testing)
  63. @go test ./tests
  64. doc:
  65. @docsify serve ./docs
  66. clean:
  67. @$(call section_title,Cleaning src folder)
  68. @rm -f $(RES)
  69. @rm -f tests/exemples/*.go
  70. # lib/%.go: src/%.og
  71. # @$(call run_and_test,$(CC) -o lib $?,Compiling $<)