plugin_c_src.mk 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # C source plugin.
  2. C_SRC_TARGETS = $(call list_targets,c-src)
  3. .PHONY: c-src $(C_SRC_TARGETS)
  4. c-src: $(C_SRC_TARGETS)
  5. c_src: c-src
  6. ifeq ($(PLATFORM),msys2)
  7. C_SRC_OUTPUT_EXECUTABLE_EXTENSION = .dll
  8. else
  9. C_SRC_OUTPUT_EXECUTABLE_EXTENSION = .so
  10. endif
  11. c-src-makefile-change: init
  12. $i "Bootstrap a new OTP library named $(APP)"
  13. $t mkdir $(APP)/
  14. $t cp ../erlang.mk $(APP)/
  15. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  16. $i "Generate a NIF from templates"
  17. $t $(MAKE) -C $(APP) new-nif n=$(APP) $v
  18. $i "Build the application"
  19. $t $(MAKE) -C $(APP) $v
  20. $i "Touch the Makefile; check that all files get rebuilt"
  21. $t printf "%s\n" \
  22. $(APP)/$(APP).d \
  23. $(APP)/c_src/$(APP).o \
  24. $(APP)/ebin/$(APP).app \
  25. $(APP)/ebin/$(APP).beam \
  26. $(APP)/priv/$(APP)$(C_SRC_OUTPUT_EXECUTABLE_EXTENSION) \
  27. $(APP)/src/$(APP).erl | sort > $(APP)/EXPECT
  28. $t $(SLEEP)
  29. $t touch $(APP)/Makefile
  30. $t $(SLEEP)
  31. $t $(MAKE) -C $(APP) $v
  32. $t find $(APP) -type f -newer $(APP)/Makefile -not -path "$(APP)/.erlang.mk/*" | sort | diff $(APP)/EXPECT -
  33. $t rm $(APP)/EXPECT
  34. c-src-nif: init
  35. $i "Bootstrap a new OTP library named $(APP)"
  36. $t mkdir $(APP)/
  37. $t cp ../erlang.mk $(APP)/
  38. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  39. $i "Generate a NIF from templates"
  40. $t $(MAKE) -C $(APP) new-nif n=$(APP) $v
  41. $i "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. $t test -f $(APP)/priv/$(APP)$(C_SRC_OUTPUT_EXECUTABLE_EXTENSION)
  50. $i "Check that the application was compiled correctly"
  51. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  52. ok = application:start($(APP)), \
  53. {ok, [$(APP)]} = application:get_key($(APP), modules), \
  54. {module, $(APP)} = code:load_file($(APP)), \
  55. {hello, joe} = $(APP):hello(joe), \
  56. {hello, mike} = $(APP):hello(mike), \
  57. {hello, robert} = $(APP):hello(robert), \
  58. halt()"
  59. $i "Re-build the application"
  60. $t $(MAKE) -C $(APP) $v
  61. $i "Check that all compiled files exist"
  62. $t test -f $(APP)/$(APP).d
  63. $t test -f $(APP)/c_src/$(APP).o
  64. $t test -f $(APP)/c_src/env.mk
  65. $t test -f $(APP)/ebin/$(APP).app
  66. $t test -f $(APP)/ebin/$(APP).beam
  67. $t test -f $(APP)/priv/$(APP)$(C_SRC_OUTPUT_EXECUTABLE_EXTENSION)
  68. $i "Check that the application was compiled correctly"
  69. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  70. ok = application:start($(APP)), \
  71. {ok, [$(APP)]} = application:get_key($(APP), modules), \
  72. {module, $(APP)} = code:load_file($(APP)), \
  73. {hello, joe} = $(APP):hello(joe), \
  74. {hello, mike} = $(APP):hello(mike), \
  75. {hello, robert} = $(APP):hello(robert), \
  76. halt()"
  77. $i "Clean the application"
  78. $t $(MAKE) -C $(APP) clean $v
  79. $i "Check that all intermediate files were removed"
  80. $t test ! -e $(APP)/$(APP).d
  81. $t test ! -e $(APP)/c_src/$(APP).o
  82. $t test ! -e $(APP)/ebin/$(APP).app
  83. $t test ! -e $(APP)/ebin/$(APP).beam
  84. $t test ! -e $(APP)/priv/$(APP)$(C_SRC_OUTPUT_EXECUTABLE_EXTENSION)
  85. $i "Distclean the application"
  86. $t $(MAKE) -C $(APP) distclean $v
  87. $i "Check that all files were removed"
  88. $t test ! -e $(APP)/c_src/env.mk
  89. c-src-nif-missing-name: init
  90. $i "Bootstrap a new OTP library named $(APP)"
  91. $t mkdir $(APP)/
  92. $t cp ../erlang.mk $(APP)/
  93. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  94. $i "Try to generate a NIF without giving it a name"
  95. $t ! $(MAKE) -C $(APP) new-nif $v