plugin_escript.mk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Escript plugin.
  2. ESCRIPT_CASES = build deps distclean extra
  3. ESCRIPT_TARGETS = $(addprefix escript-,$(ESCRIPT_CASES))
  4. .PHONY: escript $(ESCRIPT_TARGETS)
  5. escript: $(ESCRIPT_TARGETS)
  6. escript-build: build clean
  7. $i "Bootstrap a new OTP library named $(APP)"
  8. $t mkdir $(APP)/
  9. $t cp ../erlang.mk $(APP)/
  10. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  11. $i "Generate a module containing a function main/1"
  12. $t printf "%s\n" \
  13. "-module($(APP))." \
  14. "-export([main/1])." \
  15. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  16. $i "Build the escript"
  17. $t $(MAKE) -C $(APP) escript $v
  18. $i "Check that the escript exists"
  19. $t test -f $(APP)/$(APP)
  20. $i "Check that the escript runs"
  21. $t $(APP)/$(APP) | grep -q good
  22. $i "Distclean the application"
  23. $t $(MAKE) -C $(APP) distclean $v
  24. $i "Check that the escript was removed"
  25. $t test ! -e $(APP)/$(APP)
  26. escript-deps: build clean
  27. $i "Bootstrap a new OTP library named $(APP)"
  28. $t mkdir $(APP)/
  29. $t cp ../erlang.mk $(APP)/
  30. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  31. $i "Add Ranch to the list of dependencies"
  32. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = ranch\n"}' $(APP)/Makefile
  33. $i "Generate a module containing a function main/1"
  34. $t printf "%s\n" \
  35. "-module($(APP))." \
  36. "-export([main/1])." \
  37. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  38. $i "Build the escript"
  39. $t $(MAKE) -C $(APP) escript $v
  40. $i "Check that the escript runs"
  41. $t $(APP)/$(APP) | grep -q good
  42. $i "Check that the escript contains the dependency"
  43. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q ranch
  44. escript-distclean: build clean
  45. $i "Bootstrap a new OTP library named $(APP)"
  46. $t mkdir $(APP)/
  47. $t cp ../erlang.mk $(APP)/
  48. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  49. $i "Use a non-standard name for the escript"
  50. $t perl -ni.bak -e 'print;if ($$.==1) {print "ESCRIPT_FILE = real-escript\n"}' $(APP)/Makefile
  51. $i "Generate a module containing a function main/1"
  52. $t printf "%s\n" \
  53. "-module($(APP))." \
  54. "-export([main/1])." \
  55. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  56. $i "Build the escript"
  57. $t $(MAKE) -C $(APP) escript $v
  58. $i "Check that the escript runs"
  59. $t test ! -f $(APP)/$(APP)
  60. $t $(APP)/real-escript | grep -q good
  61. $i "Check that make distclean removes the generated escript"
  62. $t $(MAKE) -C $(APP) distclean $v
  63. $t test ! -f $(APP)/$(APP)
  64. $t test ! -f $(APP)/real-escript
  65. escript-extra: build clean
  66. $i "Bootstrap a new OTP library named $(APP)"
  67. $t mkdir $(APP)/
  68. $t cp ../erlang.mk $(APP)/
  69. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  70. $i "Instruct Erlang.mk to add extra files to the escript"
  71. $t printf "%s\n" \
  72. "escript-zip::" \
  73. ' $$(verbose) $$(ESCRIPT_ZIP) $$(ESCRIPT_ZIP_FILE) Makefile erlang.mk' >> $(APP)/Makefile
  74. $i "Generate a module containing a function main/1"
  75. $t printf "%s\n" \
  76. "-module($(APP))." \
  77. "-export([main/1])." \
  78. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  79. $i "Build the escript"
  80. $t $(MAKE) -C $(APP) escript $v
  81. $i "Check that the escript runs"
  82. $t $(APP)/$(APP) | grep -q good
  83. $i "Check that the escript contains the extra files"
  84. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q Makefile
  85. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q erlang.mk