nodejs.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. ################################################################################
  2. #
  3. # nodejs
  4. #
  5. ################################################################################
  6. NODEJS_VERSION = 12.18.0
  7. NODEJS_SOURCE = node-v$(NODEJS_VERSION).tar.xz
  8. NODEJS_SITE = http://nodejs.org/dist/v$(NODEJS_VERSION)
  9. NODEJS_DEPENDENCIES = host-python host-nodejs c-ares \
  10. libuv zlib nghttp2 \
  11. $(call qstrip,$(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL_DEPS))
  12. HOST_NODEJS_DEPENDENCIES = host-libopenssl host-python host-zlib
  13. NODEJS_LICENSE = MIT (core code); MIT, Apache and BSD family licenses (Bundled components)
  14. NODEJS_LICENSE_FILES = LICENSE
  15. NODEJS_CONF_OPTS = \
  16. --without-snapshot \
  17. --shared-zlib \
  18. --shared-cares \
  19. --shared-libuv \
  20. --shared-nghttp2 \
  21. --without-dtrace \
  22. --without-etw \
  23. --cross-compiling \
  24. --dest-os=linux
  25. ifeq ($(BR2_PACKAGE_OPENSSL),y)
  26. NODEJS_DEPENDENCIES += openssl
  27. NODEJS_CONF_OPTS += --shared-openssl
  28. else
  29. NODEJS_CONF_OPTS += --without-ssl
  30. endif
  31. ifeq ($(BR2_PACKAGE_ICU),y)
  32. NODEJS_DEPENDENCIES += icu
  33. NODEJS_CONF_OPTS += --with-intl=system-icu
  34. else
  35. NODEJS_CONF_OPTS += --with-intl=none
  36. endif
  37. ifneq ($(BR2_PACKAGE_NODEJS_NPM),y)
  38. NODEJS_CONF_OPTS += --without-npm
  39. endif
  40. # nodejs build system is based on python, but only support python-2.6 or
  41. # python-2.7. So, we have to enforce PYTHON interpreter to be python2.
  42. define HOST_NODEJS_CONFIGURE_CMDS
  43. # The build system directly calls python. Work around this by forcing python2
  44. # into PATH. See https://github.com/nodejs/node/issues/2735
  45. mkdir -p $(@D)/bin
  46. ln -sf $(HOST_DIR)/bin/python2 $(@D)/bin/python
  47. (cd $(@D); \
  48. $(HOST_CONFIGURE_OPTS) \
  49. PATH=$(@D)/bin:$(BR_PATH) \
  50. PYTHON=$(HOST_DIR)/bin/python2 \
  51. $(HOST_DIR)/bin/python2 ./configure \
  52. --prefix=$(HOST_DIR) \
  53. --without-snapshot \
  54. --without-dtrace \
  55. --without-etw \
  56. --shared-openssl \
  57. --shared-openssl-includes=$(HOST_DIR)/include/openssl \
  58. --shared-openssl-libpath=$(HOST_DIR)/lib \
  59. --shared-zlib \
  60. --no-cross-compiling \
  61. --with-intl=small-icu \
  62. )
  63. endef
  64. NODEJS_HOST_TOOLS_V8 = \
  65. torque \
  66. gen-regexp-special-case \
  67. bytecode_builtins_list_generator
  68. NODEJS_HOST_TOOLS_NODE = mkcodecache
  69. NODEJS_HOST_TOOLS = $(NODEJS_HOST_TOOLS_V8) $(NODEJS_HOST_TOOLS_NODE)
  70. define HOST_NODEJS_BUILD_CMDS
  71. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python2 \
  72. $(MAKE) -C $(@D) \
  73. $(HOST_CONFIGURE_OPTS) \
  74. LDFLAGS.host="$(HOST_LDFLAGS)" \
  75. NO_LOAD=cctest.target.mk \
  76. PATH=$(@D)/bin:$(BR_PATH)
  77. endef
  78. define HOST_NODEJS_INSTALL_CMDS
  79. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python2 \
  80. $(MAKE) -C $(@D) install \
  81. $(HOST_CONFIGURE_OPTS) \
  82. LDFLAGS.host="$(HOST_LDFLAGS)" \
  83. NO_LOAD=cctest.target.mk \
  84. PATH=$(@D)/bin:$(BR_PATH)
  85. $(foreach f,$(NODEJS_HOST_TOOLS), \
  86. $(INSTALL) -m755 -D $(@D)/out/Release/$(f) $(HOST_DIR)/bin/$(f)
  87. )
  88. endef
  89. ifeq ($(BR2_i386),y)
  90. NODEJS_CPU = ia32
  91. else ifeq ($(BR2_x86_64),y)
  92. NODEJS_CPU = x64
  93. else ifeq ($(BR2_mips),y)
  94. NODEJS_CPU = mips
  95. else ifeq ($(BR2_mipsel),y)
  96. NODEJS_CPU = mipsel
  97. else ifeq ($(BR2_arm),y)
  98. NODEJS_CPU = arm
  99. # V8 needs to know what floating point ABI the target is using.
  100. NODEJS_ARM_FP = $(GCC_TARGET_FLOAT_ABI)
  101. # it also wants to know which FPU to use, but only has support for
  102. # vfp, vfpv3, vfpv3-d16 and neon.
  103. ifeq ($(BR2_ARM_FPU_VFPV2),y)
  104. NODEJS_ARM_FPU = vfp
  105. # vfpv4 is a superset of vfpv3
  106. else ifeq ($(BR2_ARM_FPU_VFPV3)$(BR2_ARM_FPU_VFPV4),y)
  107. NODEJS_ARM_FPU = vfpv3
  108. # vfpv4-d16 is a superset of vfpv3-d16
  109. else ifeq ($(BR2_ARM_FPU_VFPV3D16)$(BR2_ARM_FPU_VFPV4D16),y)
  110. NODEJS_ARM_FPU = vfpv3-d16
  111. else ifeq ($(BR2_ARM_FPU_NEON),y)
  112. NODEJS_ARM_FPU = neon
  113. endif
  114. else ifeq ($(BR2_aarch64),y)
  115. NODEJS_CPU = arm64
  116. endif
  117. # MIPS architecture specific options
  118. ifeq ($(BR2_mips)$(BR2_mipsel),y)
  119. ifeq ($(BR2_MIPS_CPU_MIPS32R6),y)
  120. NODEJS_MIPS_ARCH_VARIANT = r6
  121. NODEJS_MIPS_FPU_MODE = fp64
  122. else ifeq ($(BR2_MIPS_CPU_MIPS32R2),y)
  123. NODEJS_MIPS_ARCH_VARIANT = r2
  124. else ifeq ($(BR2_MIPS_CPU_MIPS32),y)
  125. NODEJS_MIPS_ARCH_VARIANT = r1
  126. endif
  127. endif
  128. NODEJS_LDFLAGS = $(TARGET_LDFLAGS)
  129. ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
  130. NODEJS_LDFLAGS += -latomic
  131. endif
  132. define NODEJS_CONFIGURE_CMDS
  133. mkdir -p $(@D)/bin
  134. ln -sf $(HOST_DIR)/bin/python2 $(@D)/bin/python
  135. (cd $(@D); \
  136. $(TARGET_CONFIGURE_OPTS) \
  137. PATH=$(@D)/bin:$(BR_PATH) \
  138. LDFLAGS="$(NODEJS_LDFLAGS)" \
  139. LD="$(TARGET_CXX)" \
  140. PYTHON=$(HOST_DIR)/bin/python2 \
  141. $(HOST_DIR)/bin/python2 ./configure \
  142. --prefix=/usr \
  143. --dest-cpu=$(NODEJS_CPU) \
  144. $(if $(NODEJS_ARM_FP),--with-arm-float-abi=$(NODEJS_ARM_FP)) \
  145. $(if $(NODEJS_ARM_FPU),--with-arm-fpu=$(NODEJS_ARM_FPU)) \
  146. $(if $(NODEJS_MIPS_ARCH_VARIANT),--with-mips-arch-variant=$(NODEJS_MIPS_ARCH_VARIANT)) \
  147. $(if $(NODEJS_MIPS_FPU_MODE),--with-mips-fpu-mode=$(NODEJS_MIPS_FPU_MODE)) \
  148. $(NODEJS_CONF_OPTS) \
  149. )
  150. $(foreach f,$(NODEJS_HOST_TOOLS_V8), \
  151. $(SED) "s#<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)$(f)<(EXECUTABLE_SUFFIX)#$(HOST_DIR)/bin/$(f)#" \
  152. $(@D)/tools/v8_gypfiles/v8.gyp
  153. )
  154. $(foreach f,$(NODEJS_HOST_TOOLS_NODE), \
  155. $(SED) "s#<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)$(f)<(EXECUTABLE_SUFFIX)#$(HOST_DIR)/bin/$(f)#" \
  156. -i $(@D)/node.gyp
  157. )
  158. endef
  159. define NODEJS_BUILD_CMDS
  160. $(TARGET_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python2 \
  161. $(MAKE) -C $(@D) \
  162. $(TARGET_CONFIGURE_OPTS) \
  163. NO_LOAD=cctest.target.mk \
  164. PATH=$(@D)/bin:$(BR_PATH) \
  165. LDFLAGS="$(NODEJS_LDFLAGS)" \
  166. LD="$(TARGET_CXX)"
  167. endef
  168. #
  169. # Build the list of modules to install.
  170. #
  171. NODEJS_MODULES_LIST= $(call qstrip,\
  172. $(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL))
  173. # Define NPM for other packages to use
  174. NPM = $(TARGET_CONFIGURE_OPTS) \
  175. LDFLAGS="$(NODEJS_LDFLAGS)" \
  176. LD="$(TARGET_CXX)" \
  177. npm_config_arch=$(NODEJS_CPU) \
  178. npm_config_target_arch=$(NODEJS_CPU) \
  179. npm_config_build_from_source=true \
  180. npm_config_nodedir=$(BUILD_DIR)/nodejs-$(NODEJS_VERSION) \
  181. npm_config_prefix=$(TARGET_DIR)/usr \
  182. npm_config_cache=$(BUILD_DIR)/.npm-cache \
  183. $(HOST_DIR)/bin/npm
  184. #
  185. # We can only call NPM if there's something to install.
  186. #
  187. ifneq ($(NODEJS_MODULES_LIST),)
  188. define NODEJS_INSTALL_MODULES
  189. # If you're having trouble with module installation, adding -d to the
  190. # npm install call below and setting npm_config_rollback=false can both
  191. # help in diagnosing the problem.
  192. $(NPM) install -g $(NODEJS_MODULES_LIST)
  193. endef
  194. endif
  195. define NODEJS_INSTALL_TARGET_CMDS
  196. $(TARGET_MAKE_ENV) PYTHON=$(HOST_DIR)/bin/python2 \
  197. $(MAKE) -C $(@D) install \
  198. DESTDIR=$(TARGET_DIR) \
  199. $(TARGET_CONFIGURE_OPTS) \
  200. NO_LOAD=cctest.target.mk \
  201. PATH=$(@D)/bin:$(BR_PATH) \
  202. LDFLAGS="$(NODEJS_LDFLAGS)" \
  203. LD="$(TARGET_CXX)"
  204. $(NODEJS_INSTALL_MODULES)
  205. endef
  206. # node.js configure is a Python script and does not use autotools
  207. $(eval $(generic-package))
  208. $(eval $(host-generic-package))