windows linux mac下erlang nif或者port_driver通用编译脚本
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.

123 lines
5.0 KiB

5 years ago
5 years ago
5 years ago
  1. # Erlang nif port compiler
  2. windows linux mac下erlang nif或者port_driver通用编译脚本
  3. 改造自 erlang-native-compiler
  4. ## Usage
  5. default_env
  6. 1. Clone this repository
  7. 1. Run `make` in this directory
  8. 1. Copy `eNpc` to your project "c_src" dir and commit it
  9. 1. Add these (or similar) hooks to your rebar.config:
  10. ```erlang
  11. {pre_hooks, [{"", compile, "escript c_src/eNpc compile"}]}.
  12. {post_hooks, [{"", clean, "escript c_src/eNpc clean"}]}.
  13. ```
  14. After that eNpc should read your old rebar.config `port_specs` and `port_env` settings as expected (it is rebar2's port compiler after all...).
  15. ###
  16. ```
  17. Supported configuration variables:
  18. * port_specs - Erlang list of tuples of the forms
  19. {ArchRegex, TargetFile, Sources, Options}
  20. {ArchRegex, TargetFile, Sources}
  21. {TargetFile, Sources}
  22. Note that if you want to use any of the rebar3 variables
  23. below you must MUST use a ${}-style to get the expansion
  24. to work. e.g. to expand REBAR_DEPS_DIR, do something like:
  25. {port_specs, [{"priv/nif.so",
  26. ["c_src/nif.c",
  27. "${REBAR_DEPS_DIR}/foo/bar.c"]}]}.
  28. This is a _very_ good way to be able to use your code both
  29. as a top level app and a dependency.
  30. CAVEAT! Not using {} is broken for the moment.
  31. * port_env - Erlang list of key/value pairs which will control
  32. the environment when running the compiler and linker.
  33. Variables set in the surrounding system shell are taken
  34. into consideration when expanding port_env. Note that
  35. for ERL_LDFLAGS, -lerl_interface is used for only those
  36. Erlang/OTP versions where it exists (those prior to
  37. version 23.0).
  38. By default, the following variables are defined:
  39. CC - C compiler
  40. CXX - C++ compiler
  41. CFLAGS - C compiler
  42. CXXFLAGS - C++ compiler
  43. LDFLAGS - Link flags
  44. ERL_CFLAGS - default -I paths for erts and ei
  45. ERL_LDFLAGS - default -L and -lerl_interface -lei
  46. DRV_CFLAGS - flags that will be used for compiling
  47. DRV_LDFLAGS - flags that will be used for linking
  48. EXE_CFLAGS - flags that will be used for compiling
  49. EXE_LDFLAGS - flags that will be used for linking
  50. ERL_EI_LIBDIR - ei library directory
  51. DRV_CXX_TEMPLATE - C++ command template
  52. DRV_CC_TEMPLATE - C command template
  53. DRV_LINK_TEMPLATE - C Linker command template
  54. DRV_LINK_CXX_TEMPLATE - C++ Linker command template
  55. EXE_CXX_TEMPLATE - C++ command template
  56. EXE_CC_TEMPLATE - C command template
  57. EXE_LINK_TEMPLATE - C Linker command template
  58. EXE_LINK_CXX_TEMPLATE - C++ Linker command template
  59. Note that if you wish to extend (vs. replace) these variables,
  60. you MUST include a shell-style reference in your definition.
  61. e.g. to extend CFLAGS, do something like:
  62. {port_env, [{"CFLAGS", "$CFLAGS -MyOtherOptions"}]}
  63. It is also possible to specify platform specific options
  64. by specifying a triplet where the first string is a regex
  65. that is checked against Erlang's system architecture string.
  66. e.g. to specify a CFLAG that only applies to x86_64 on linux
  67. do:
  68. {port_env, [{"x86_64.*-linux", "CFLAGS",
  69. "$CFLAGS -X86Options"}]}
  70. Cross-arch environment variables to configure toolchain:
  71. GET_ARCH to set the tool chain name to use
  72. GET_ARCH_WORDSIZE (optional - to determine word size)"
  73. word size is 32
  74. GET_ARCH_VSN (optional - "
  75. l version of CC/CXX is requested),
  76. {port_specs, [
  77. {"priv/jiffy.so", [
  78. "c_src/*.c",
  79. "c_src/*.cc",
  80. "c_src/double-conversion/*.cc"
  81. ]}
  82. ]}.
  83. {port_env, [
  84. % Drop -lerl_interface
  85. {"ERL_LDFLAGS", " -L$ERL_EI_LIBDIR -lei"},
  86. {"win32", "ERL_LDFLAGS", " /LIBPATH:$ERL_EI_LIBDIR ei.lib"},
  87. {".*", "FLTO_FLAG", ""},
  88. {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)", "CFLAGS", "$CFLAGS -Ic_src/ -g -Wall $FLTO_FLAG -Werror -O3"},
  89. {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)", "CXXFLAGS", "$CXXFLAGS -Ic_src/ -g -Wall $FLTO_FLAG -Werror -O3"},
  90. {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)", "LDFLAGS", "$LDFLAGS $FLTO_FLAG -lstdc++"},
  91. %% OS X Leopard flags for 64-bit
  92. {"darwin9.*-64$", "CXXFLAGS", "-m64"},
  93. {"darwin9.*-64$", "LDFLAGS", "-arch x86_64"},
  94. %% OS X Snow Leopard flags for 32-bit
  95. {"darwin10.*-32$", "CXXFLAGS", "-m32"},
  96. {"darwin10.*-32$", "LDFLAGS", "-arch i386"},
  97. {"win32", "CXXFLAGS", "$CXXFLAGS /O2 /DNDEBUG"}
  98. ]}.
  99. ```