nodejs.mk 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ################################################################################
  2. #
  3. # nodejs
  4. #
  5. ################################################################################
  6. NODEJS_VERSION = 8.1.2
  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 zlib \
  10. $(call qstrip,$(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL_DEPS))
  11. HOST_NODEJS_DEPENDENCIES = host-python host-zlib
  12. NODEJS_LICENSE = MIT (core code); MIT, Apache and BSD family licenses (Bundled components)
  13. NODEJS_LICENSE_FILES = LICENSE
  14. NODEJS_CONF_OPTS = \
  15. --without-snapshot \
  16. --shared-zlib \
  17. --without-dtrace \
  18. --without-etw \
  19. --dest-os=linux
  20. ifeq ($(BR2_PACKAGE_OPENSSL),y)
  21. NODEJS_DEPENDENCIES += openssl
  22. NODEJS_CONF_OPTS += --shared-openssl
  23. else
  24. NODEJS_CONF_OPTS += --without-ssl
  25. endif
  26. ifeq ($(BR2_PACKAGE_ICU),y)
  27. NODEJS_DEPENDENCIES += icu
  28. NODEJS_CONF_OPTS += --with-intl=system-icu
  29. else
  30. NODEJS_CONF_OPTS += --with-intl=none
  31. endif
  32. ifneq ($(BR2_PACKAGE_NODEJS_NPM),y)
  33. NODEJS_CONF_OPTS += --without-npm
  34. endif
  35. # nodejs build system is based on python, but only support python-2.6 or
  36. # python-2.7. So, we have to enforce PYTHON interpreter to be python2.
  37. define HOST_NODEJS_CONFIGURE_CMDS
  38. # The build system directly calls python. Work around this by forcing python2
  39. # into PATH. See https://github.com/nodejs/node/issues/2735
  40. mkdir -p $(@D)/bin
  41. ln -sf $(HOST_DIR)/usr/bin/python2 $(@D)/bin/python
  42. # Build with the static, built-in OpenSSL which is supplied as part of
  43. # the nodejs source distribution. This is needed on the host because
  44. # NPM is non-functional without it, and host-openssl isn't part of
  45. # buildroot.
  46. (cd $(@D); \
  47. $(HOST_CONFIGURE_OPTS) \
  48. PATH=$(@D)/bin:$(BR_PATH) \
  49. PYTHON=$(HOST_DIR)/usr/bin/python2 \
  50. $(HOST_DIR)/usr/bin/python2 ./configure \
  51. --prefix=$(HOST_DIR)/usr \
  52. --without-snapshot \
  53. --without-dtrace \
  54. --without-etw \
  55. --shared-zlib \
  56. --with-intl=none \
  57. )
  58. endef
  59. define HOST_NODEJS_BUILD_CMDS
  60. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  61. $(MAKE) -C $(@D) \
  62. $(HOST_CONFIGURE_OPTS) \
  63. PATH=$(@D)/bin:$(BR_PATH)
  64. endef
  65. define HOST_NODEJS_INSTALL_CMDS
  66. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  67. $(MAKE) -C $(@D) install \
  68. $(HOST_CONFIGURE_OPTS) \
  69. PATH=$(@D)/bin:$(BR_PATH)
  70. $(INSTALL) -m755 -D $(@D)/out/Release/mkpeephole $(HOST_DIR)/usr/bin/mkpeephole
  71. endef
  72. ifeq ($(BR2_i386),y)
  73. NODEJS_CPU = ia32
  74. else ifeq ($(BR2_x86_64),y)
  75. NODEJS_CPU = x64
  76. else ifeq ($(BR2_mips),y)
  77. NODEJS_CPU = mips
  78. else ifeq ($(BR2_mipsel),y)
  79. NODEJS_CPU = mipsel
  80. else ifeq ($(BR2_arm),y)
  81. NODEJS_CPU = arm
  82. else ifeq ($(BR2_aarch64),y)
  83. NODEJS_CPU = arm64
  84. # V8 needs to know what floating point ABI the target is using.
  85. NODEJS_ARM_FP = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  86. endif
  87. # MIPS architecture specific options
  88. ifeq ($(BR2_mips)$(BR2_mipsel),y)
  89. ifeq ($(BR2_MIPS_CPU_MIPS32R6),y)
  90. NODEJS_MIPS_ARCH_VARIANT = r6
  91. NODEJS_MIPS_FPU_MODE = fp64
  92. else ifeq ($(BR2_MIPS_CPU_MIPS32R2),y)
  93. NODEJS_MIPS_ARCH_VARIANT = r2
  94. else ifeq ($(BR2_MIPS_CPU_MIPS32),y)
  95. NODEJS_MIPS_ARCH_VARIANT = r1
  96. endif
  97. endif
  98. define NODEJS_CONFIGURE_CMDS
  99. mkdir -p $(@D)/bin
  100. ln -sf $(HOST_DIR)/usr/bin/python2 $(@D)/bin/python
  101. (cd $(@D); \
  102. $(TARGET_CONFIGURE_OPTS) \
  103. PATH=$(@D)/bin:$(BR_PATH) \
  104. LD="$(TARGET_CXX)" \
  105. PYTHON=$(HOST_DIR)/usr/bin/python2 \
  106. $(HOST_DIR)/usr/bin/python2 ./configure \
  107. --prefix=/usr \
  108. --dest-cpu=$(NODEJS_CPU) \
  109. $(if $(NODEJS_ARM_FP),--with-arm-float-abi=$(NODEJS_ARM_FP)) \
  110. $(if $(NODEJS_MIPS_ARCH_VARIANT),--with-mips-arch-variant=$(NODEJS_MIPS_ARCH_VARIANT)) \
  111. $(if $(NODEJS_MIPS_FPU_MODE),--with-mips-fpu-mode=$(NODEJS_MIPS_FPU_MODE)) \
  112. $(NODEJS_CONF_OPTS) \
  113. )
  114. # use host version of mkpeephole
  115. sed "s#<(mkpeephole_exec)#$(HOST_DIR)/usr/bin/mkpeephole#g" -i $(@D)/deps/v8/src/v8.gyp
  116. endef
  117. define NODEJS_BUILD_CMDS
  118. $(TARGET_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  119. $(MAKE) -C $(@D) \
  120. $(TARGET_CONFIGURE_OPTS) \
  121. PATH=$(@D)/bin:$(BR_PATH) \
  122. LD="$(TARGET_CXX)"
  123. endef
  124. #
  125. # Build the list of modules to install.
  126. #
  127. NODEJS_MODULES_LIST= $(call qstrip,\
  128. $(BR2_PACKAGE_NODEJS_MODULES_ADDITIONAL))
  129. # Define NPM for other packages to use
  130. NPM = $(TARGET_CONFIGURE_OPTS) \
  131. LD="$(TARGET_CXX)" \
  132. npm_config_arch=$(NODEJS_CPU) \
  133. npm_config_target_arch=$(NODEJS_CPU) \
  134. npm_config_build_from_source=true \
  135. npm_config_nodedir=$(BUILD_DIR)/nodejs-$(NODEJS_VERSION) \
  136. npm_config_prefix=$(TARGET_DIR)/usr \
  137. $(HOST_DIR)/usr/bin/npm
  138. #
  139. # We can only call NPM if there's something to install.
  140. #
  141. ifneq ($(NODEJS_MODULES_LIST),)
  142. define NODEJS_INSTALL_MODULES
  143. # If you're having trouble with module installation, adding -d to the
  144. # npm install call below and setting npm_config_rollback=false can both
  145. # help in diagnosing the problem.
  146. $(NPM) install -g $(NODEJS_MODULES_LIST)
  147. endef
  148. endif
  149. define NODEJS_INSTALL_TARGET_CMDS
  150. $(TARGET_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  151. $(MAKE) -C $(@D) install \
  152. DESTDIR=$(TARGET_DIR) \
  153. $(TARGET_CONFIGURE_OPTS) \
  154. PATH=$(@D)/bin:$(BR_PATH) \
  155. LD="$(TARGET_CXX)"
  156. $(NODEJS_INSTALL_MODULES)
  157. endef
  158. # node.js configure is a Python script and does not use autotools
  159. $(eval $(generic-package))
  160. $(eval $(host-generic-package))