plugin_c_src.mk 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # C source plugin.
  2. C_SRC_CASES = cpp custom dir env nif port
  3. C_SRC_TARGETS = $(addprefix c-src-,$(C_SRC_CASES))
  4. C_SRC_CLEAN_TARGETS = $(addprefix clean-,$(C_SRC_TARGETS))
  5. .PHONY: c-src $(C_SRC_TARGETS) clean-c-src $(C_SRC_CLEAN_TARGETS)
  6. clean-c-src: $(C_SRC_CLEAN_TARGETS)
  7. clean-c_src: clean-c-src
  8. $(C_SRC_CLEAN_TARGETS):
  9. $t rm -rf $(APP_TO_CLEAN)
  10. c-src: $(C_SRC_TARGETS)
  11. c_src: c-src
  12. c-src-nif: build clean-c-src-nif
  13. $i "Bootstrap a new OTP library named $(APP)"
  14. $t mkdir $(APP)/
  15. $t cp ../erlang.mk $(APP)/
  16. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  17. $i "Generate a NIF from templates"
  18. $t $(MAKE) -C $(APP) new-nif n=$(APP) $v
  19. $i "Build the application"
  20. $t $(MAKE) -C $(APP) $v
  21. $i "Check that all compiled files exist"
  22. $t test -f $(APP)/$(APP).d
  23. $t test -f $(APP)/c_src/$(APP).o
  24. $t test -f $(APP)/c_src/env.mk
  25. $t test -f $(APP)/ebin/$(APP).app
  26. $t test -f $(APP)/ebin/$(APP).beam
  27. ifeq ($(PLATFORM),msys2)
  28. $t test -f $(APP)/priv/$(APP).dll
  29. else
  30. $t test -f $(APP)/priv/$(APP).so
  31. endif
  32. $i "Check that the application was compiled correctly"
  33. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  34. ok = application:start($(APP)), \
  35. {ok, [$(APP)]} = application:get_key($(APP), modules), \
  36. {module, $(APP)} = code:load_file($(APP)), \
  37. {hello, joe} = $(APP):hello(joe), \
  38. {hello, mike} = $(APP):hello(mike), \
  39. {hello, robert} = $(APP):hello(robert), \
  40. halt()"
  41. $i "Re-build the application"
  42. $t $(MAKE) -C $(APP) $v
  43. $i "Check that all compiled files exist"
  44. $t test -f $(APP)/$(APP).d
  45. $t test -f $(APP)/c_src/$(APP).o
  46. $t test -f $(APP)/c_src/env.mk
  47. $t test -f $(APP)/ebin/$(APP).app
  48. $t test -f $(APP)/ebin/$(APP).beam
  49. ifeq ($(PLATFORM),msys2)
  50. $t test -f $(APP)/priv/$(APP).dll
  51. else
  52. $t test -f $(APP)/priv/$(APP).so
  53. endif
  54. $i "Check that the application was compiled correctly"
  55. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  56. ok = application:start($(APP)), \
  57. {ok, [$(APP)]} = application:get_key($(APP), modules), \
  58. {module, $(APP)} = code:load_file($(APP)), \
  59. {hello, joe} = $(APP):hello(joe), \
  60. {hello, mike} = $(APP):hello(mike), \
  61. {hello, robert} = $(APP):hello(robert), \
  62. halt()"
  63. $i "Clean the application"
  64. $t $(MAKE) -C $(APP) clean $v
  65. $i "Check that all intermediate files were removed"
  66. $t test ! -e $(APP)/$(APP).d
  67. $t test ! -e $(APP)/c_src/$(APP).o
  68. $t test ! -e $(APP)/ebin/$(APP).app
  69. $t test ! -e $(APP)/ebin/$(APP).beam
  70. ifeq ($(PLATFORM),msys2)
  71. $t test ! -e $(APP)/priv/$(APP).dll
  72. else
  73. $t test ! -e $(APP)/priv/$(APP).so
  74. endif
  75. $i "Distclean the application"
  76. $t $(MAKE) -C $(APP) distclean $v
  77. $i "Check that all files were removed"
  78. $t test ! -e $(APP)/c_src/env.mk