nodejs.mk 4.8 KB

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