plugin_escript.mk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Escript plugin.
  2. ESCRIPT_TARGETS = $(call list_targets,escript)
  3. .PHONY: escript $(ESCRIPT_TARGETS)
  4. escript: $(ESCRIPT_TARGETS)
  5. escript-build: build clean
  6. $i "Bootstrap a new OTP library named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  10. $i "Generate a module containing a function main/1"
  11. $t printf "%s\n" \
  12. "-module($(APP))." \
  13. "-export([main/1])." \
  14. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  15. $i "Build the escript"
  16. $t $(MAKE) -C $(APP) escript $v
  17. $i "Check that the escript exists"
  18. $t test -f $(APP)/$(APP)
  19. $i "Check that the escript runs"
  20. $t $(APP)/$(APP) | grep -q good
  21. $i "Distclean the application"
  22. $t $(MAKE) -C $(APP) distclean $v
  23. $i "Check that the escript was removed"
  24. $t test ! -e $(APP)/$(APP)
  25. escript-build-deps: build clean
  26. $i "Bootstrap a new OTP library named $(APP)"
  27. $t mkdir $(APP)/
  28. $t cp ../erlang.mk $(APP)/
  29. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  30. $i "Add Ranch to the list of dependencies"
  31. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = ranch\n"}' $(APP)/Makefile
  32. $i "Add lfe.mk to the list of build dependencies"
  33. $t perl -ni.bak -e 'print;if ($$.==1) {print "BUILD_DEPS = lfe.mk\ndep_lfe.mk = git https://github.com/ninenines/lfe.mk master\n"}' $(APP)/Makefile
  34. $i "Generate a module containing a function main/1"
  35. $t printf "%s\n" \
  36. "-module($(APP))." \
  37. "-export([main/1])." \
  38. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  39. $i "Build the escript"
  40. $t $(MAKE) -C $(APP) escript $v
  41. $i "Check that the build dependency was fetched"
  42. $t test -d $(APP)/deps/lfe.mk
  43. $i "Check that the escript runs"
  44. $t $(APP)/$(APP) | grep -q good
  45. $i "Check that the escript does not contain the build dependency"
  46. $t ! zipinfo $(APP)/$(APP) 2> /dev/null | grep -q lfe
  47. escript-deps: build clean
  48. $i "Bootstrap a new OTP library named $(APP)"
  49. $t mkdir $(APP)/
  50. $t cp ../erlang.mk $(APP)/
  51. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  52. $i "Add Ranch to the list of dependencies"
  53. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = ranch\n"}' $(APP)/Makefile
  54. $i "Generate a module containing a function main/1"
  55. $t printf "%s\n" \
  56. "-module($(APP))." \
  57. "-export([main/1])." \
  58. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  59. $i "Build the escript"
  60. $t $(MAKE) -C $(APP) escript $v
  61. $i "Check that the escript runs"
  62. $t $(APP)/$(APP) | grep -q good
  63. $i "Check that the escript contains the dependency"
  64. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q ranch
  65. escript-distclean: 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 "Use a non-standard name for the escript"
  71. $t perl -ni.bak -e 'print;if ($$.==1) {print "ESCRIPT_FILE = real-escript\n"}' $(APP)/Makefile
  72. $i "Generate a module containing a function main/1"
  73. $t printf "%s\n" \
  74. "-module($(APP))." \
  75. "-export([main/1])." \
  76. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  77. $i "Build the escript"
  78. $t $(MAKE) -C $(APP) escript $v
  79. $i "Check that the escript runs"
  80. $t test ! -f $(APP)/$(APP)
  81. $t $(APP)/real-escript | grep -q good
  82. $i "Check that make distclean removes the generated escript"
  83. $t $(MAKE) -C $(APP) distclean $v
  84. $t test ! -f $(APP)/$(APP)
  85. $t test ! -f $(APP)/real-escript
  86. escript-extra: build clean
  87. $i "Bootstrap a new OTP library named $(APP)"
  88. $t mkdir $(APP)/
  89. $t cp ../erlang.mk $(APP)/
  90. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  91. $i "Instruct Erlang.mk to add extra files to the escript"
  92. $t printf "%s\n" \
  93. "escript-zip::" \
  94. ' $$(verbose) $$(ESCRIPT_ZIP) $$(ESCRIPT_ZIP_FILE) Makefile erlang.mk' >> $(APP)/Makefile
  95. $i "Generate a module containing a function main/1"
  96. $t printf "%s\n" \
  97. "-module($(APP))." \
  98. "-export([main/1])." \
  99. 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl
  100. $i "Build the escript"
  101. $t $(MAKE) -C $(APP) escript $v
  102. $i "Check that the escript runs"
  103. $t $(APP)/$(APP) | grep -q good
  104. $i "Check that the escript contains the extra files"
  105. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q Makefile
  106. $t zipinfo $(APP)/$(APP) 2> /dev/null | grep -q erlang.mk