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