nodejs.mk 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ################################################################################
  2. #
  3. # nodejs
  4. #
  5. ################################################################################
  6. NODEJS_VERSION = $(call qstrip,$(BR2_PACKAGE_NODEJS_VERSION_STRING))
  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. # 0.10.x does not have icu support
  27. ifeq ($(findstring 0.10.,$(NODEJS_VERSION)),)
  28. ifeq ($(BR2_PACKAGE_ICU),y)
  29. NODEJS_DEPENDENCIES += icu
  30. NODEJS_CONF_OPTS += --with-intl=system-icu
  31. else
  32. NODEJS_CONF_OPTS += --with-intl=none
  33. endif
  34. endif
  35. ifneq ($(BR2_PACKAGE_NODEJS_NPM),y)
  36. NODEJS_CONF_OPTS += --without-npm
  37. endif
  38. # nodejs build system is based on python, but only support python-2.6 or
  39. # python-2.7. So, we have to enforce PYTHON interpreter to be python2.
  40. define HOST_NODEJS_CONFIGURE_CMDS
  41. # The build system directly calls python. Work around this by forcing python2
  42. # into PATH. See https://github.com/nodejs/node/issues/2735
  43. mkdir -p $(@D)/bin
  44. ln -sf $(HOST_DIR)/usr/bin/python2 $(@D)/bin/python
  45. # Build with the static, built-in OpenSSL which is supplied as part of
  46. # the nodejs source distribution. This is needed on the host because
  47. # NPM is non-functional without it, and host-openssl isn't part of
  48. # buildroot.
  49. (cd $(@D); \
  50. $(HOST_CONFIGURE_OPTS) \
  51. PATH=$(@D)/bin:$(BR_PATH) \
  52. PYTHON=$(HOST_DIR)/usr/bin/python2 \
  53. $(HOST_DIR)/usr/bin/python2 ./configure \
  54. --prefix=$(HOST_DIR)/usr \
  55. --without-snapshot \
  56. --without-dtrace \
  57. --without-etw \
  58. --shared-zlib \
  59. )
  60. endef
  61. define HOST_NODEJS_BUILD_CMDS
  62. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  63. $(MAKE) -C $(@D) \
  64. $(HOST_CONFIGURE_OPTS) \
  65. PATH=$(@D)/bin:$(BR_PATH)
  66. endef
  67. define HOST_NODEJS_INSTALL_CMDS
  68. $(HOST_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  69. $(MAKE) -C $(@D) install \
  70. $(HOST_CONFIGURE_OPTS) \
  71. PATH=$(@D)/bin:$(BR_PATH)
  72. endef
  73. ifeq ($(BR2_i386),y)
  74. NODEJS_CPU = ia32
  75. else ifeq ($(BR2_x86_64),y)
  76. NODEJS_CPU = x64
  77. else ifeq ($(BR2_mips),y)
  78. NODEJS_CPU = mips
  79. else ifeq ($(BR2_mipsel),y)
  80. NODEJS_CPU = mipsel
  81. else ifeq ($(BR2_arm),y)
  82. NODEJS_CPU = arm
  83. # V8 needs to know what floating point ABI the target is using.
  84. NODEJS_ARM_FP = $(call qstrip,$(BR2_GCC_TARGET_FLOAT_ABI))
  85. endif
  86. # MIPS architecture specific options
  87. ifeq ($(BR2_mips)$(BR2_mipsel),y)
  88. ifeq ($(BR2_MIPS_CPU_MIPS32R6),y)
  89. NODEJS_MIPS_ARCH_VARIANT = r6
  90. NODEJS_MIPS_FPU_MODE = fp64
  91. else ifeq ($(BR2_MIPS_CPU_MIPS32R2),y)
  92. NODEJS_MIPS_ARCH_VARIANT = r2
  93. else ifeq ($(BR2_MIPS_CPU_MIPS32),y)
  94. NODEJS_MIPS_ARCH_VARIANT = r1
  95. endif
  96. endif
  97. define NODEJS_CONFIGURE_CMDS
  98. mkdir -p $(@D)/bin
  99. ln -sf $(HOST_DIR)/usr/bin/python2 $(@D)/bin/python
  100. (cd $(@D); \
  101. $(TARGET_CONFIGURE_OPTS) \
  102. PATH=$(@D)/bin:$(BR_PATH) \
  103. LD="$(TARGET_CXX)" \
  104. PYTHON=$(HOST_DIR)/usr/bin/python2 \
  105. $(HOST_DIR)/usr/bin/python2 ./configure \
  106. --prefix=/usr \
  107. --dest-cpu=$(NODEJS_CPU) \
  108. $(if $(NODEJS_ARM_FP),--with-arm-float-abi=$(NODEJS_ARM_FP)) \
  109. $(if $(NODEJS_MIPS_ARCH_VARIANT),--with-mips-arch-variant=$(NODEJS_MIPS_ARCH_VARIANT)) \
  110. $(if $(NODEJS_MIPS_FPU_MODE),--with-mips-fpu-mode=$(NODEJS_MIPS_FPU_MODE)) \
  111. $(NODEJS_CONF_OPTS) \
  112. )
  113. endef
  114. define NODEJS_BUILD_CMDS
  115. $(TARGET_MAKE_ENV) PYTHON=$(HOST_DIR)/usr/bin/python2 \
  116. $(MAKE) -C $(@D) \
  117. $(TARGET_CONFIGURE_OPTS) \
  118. PATH=$(@D)/bin:$(BR_PATH) \
  119. LD="$(TARGET_CXX)"
  120. endef
  121. #
  122. # Build the list of modules to install based on the booleans for
  123. # popular modules, as well as the "additional modules" list.
  124. #
  125. NODEJS_MODULES_LIST= $(call qstrip,\
  126. $(if $(BR2_PACKAGE_NODEJS_MODULES_EXPRESS),express) \
  127. $(if $(BR2_PACKAGE_NODEJS_MODULES_COFFEESCRIPT),coffee-script) \
  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))