xref: /OK3568_Linux_fs/buildroot/package/nginx/nginx.mk (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1################################################################################
2#
3# nginx
4#
5################################################################################
6
7NGINX_VERSION = 1.20.1
8NGINX_SITE = http://nginx.org/download
9NGINX_LICENSE = BSD-2-Clause
10NGINX_LICENSE_FILES = LICENSE
11NGINX_CPE_ID_VENDOR = nginx
12NGINX_DEPENDENCIES = \
13	host-pkgconf \
14	$(if $(BR2_PACKAGE_LIBXCRYPT),libxcrypt)
15
16NGINX_CONF_OPTS = \
17	--crossbuild=Linux::$(BR2_ARCH) \
18	--with-cc="$(TARGET_CC)" \
19	--with-cpp="$(TARGET_CC)" \
20	--with-ld-opt="$(TARGET_LDFLAGS)"
21
22# www-data user and group are used for nginx. Because these user and group
23# are already set by buildroot, it is not necessary to redefine them.
24# See system/skeleton/etc/passwd
25#   username: www-data    uid: 33
26#   groupname: www-data   gid: 33
27#
28# So, we just need to create the directories used by nginx with the right
29# ownership.
30define NGINX_PERMISSIONS
31	/var/lib/nginx d 755 33 33 - - - - -
32endef
33
34# disable external libatomic_ops because its detection fails.
35NGINX_CONF_ENV += \
36	ngx_force_c_compiler=yes \
37	ngx_force_c99_have_variadic_macros=yes \
38	ngx_force_gcc_have_variadic_macros=yes \
39	ngx_force_gcc_have_atomic=yes \
40	ngx_force_have_epoll=yes \
41	ngx_force_have_sendfile=yes \
42	ngx_force_have_sendfile64=yes \
43	ngx_force_have_pr_set_dumpable=yes \
44	ngx_force_have_timer_event=yes \
45	ngx_force_have_map_anon=yes \
46	ngx_force_have_map_devzero=yes \
47	ngx_force_have_sysvshm=yes \
48	ngx_force_have_posix_sem=yes
49
50# prefix: nginx root configuration location
51NGINX_CONF_OPTS += \
52	--force-endianness=$(call qstrip,$(call LOWERCASE,$(BR2_ENDIAN))) \
53	--prefix=/usr \
54	--conf-path=/etc/nginx/nginx.conf \
55	--sbin-path=/usr/sbin/nginx \
56	--pid-path=/run/nginx.pid \
57	--lock-path=/run/lock/nginx.lock \
58	--user=www-data \
59	--group=www-data \
60	--error-log-path=/var/log/nginx/error.log \
61	--http-log-path=/var/log/nginx/access.log \
62	--http-client-body-temp-path=/var/cache/nginx/client-body \
63	--http-proxy-temp-path=/var/cache/nginx/proxy \
64	--http-fastcgi-temp-path=/var/cache/nginx/fastcgi \
65	--http-scgi-temp-path=/var/cache/nginx/scgi \
66	--http-uwsgi-temp-path=/var/cache/nginx/uwsgi
67
68NGINX_CONF_OPTS += \
69	$(if $(BR2_PACKAGE_NGINX_FILE_AIO),--with-file-aio) \
70	$(if $(BR2_PACKAGE_NGINX_THREADS),--with-threads)
71
72ifeq ($(BR2_PACKAGE_LIBATOMIC_OPS),y)
73NGINX_DEPENDENCIES += libatomic_ops
74NGINX_CONF_OPTS += --with-libatomic
75NGINX_CONF_ENV += ngx_force_have_libatomic=yes
76ifeq ($(BR2_sparc_v8)$(BR2_sparc_leon3),y)
77NGINX_CFLAGS += "-DAO_NO_SPARC_V9"
78endif
79else
80NGINX_CONF_ENV += ngx_force_have_libatomic=no
81endif
82
83ifeq ($(BR2_PACKAGE_PCRE),y)
84NGINX_DEPENDENCIES += pcre
85NGINX_CONF_OPTS += --with-pcre
86else
87NGINX_CONF_OPTS += --without-pcre
88endif
89
90# modules disabled or not activated because of missing dependencies:
91# - google_perftools  (googleperftools)
92# - http_perl_module  (host-perl)
93# - pcre-jit          (want to rebuild pcre)
94
95# Notes:
96# * Feature/module option are *not* symetric.
97#   If a feature is on by default, only its --without-xxx option exists;
98#   if a feature is off by default, only its --with-xxx option exists.
99# * The configure script fails if unknown options are passed on the command
100#   line.
101
102# misc. modules
103NGINX_CONF_OPTS += \
104	$(if $(BR2_PACKAGE_NGINX_SELECT_MODULE),--with-select_module,--without-select_module) \
105	$(if $(BR2_PACKAGE_NGINX_POLL_MODULE),--with-poll_module,--without-poll_module)
106
107ifneq ($(BR2_PACKAGE_NGINX_ADD_MODULES),)
108NGINX_CONF_OPTS += \
109	$(addprefix --add-module=,$(call qstrip,$(BR2_PACKAGE_NGINX_ADD_MODULES)))
110endif
111
112# http server modules
113ifeq ($(BR2_PACKAGE_NGINX_HTTP),y)
114ifeq ($(BR2_PACKAGE_NGINX_HTTP_CACHE),y)
115NGINX_DEPENDENCIES += openssl
116else
117NGINX_CONF_OPTS += --without-http-cache
118endif
119
120ifeq ($(BR2_PACKAGE_NGINX_HTTP_V2_MODULE),y)
121NGINX_DEPENDENCIES += zlib
122NGINX_CONF_OPTS += --with-http_v2_module
123endif
124
125ifeq ($(BR2_PACKAGE_NGINX_HTTP_SSL_MODULE),y)
126NGINX_DEPENDENCIES += openssl
127NGINX_CONF_OPTS += --with-http_ssl_module
128endif
129
130ifeq ($(BR2_PACKAGE_NGINX_HTTP_XSLT_MODULE),y)
131NGINX_DEPENDENCIES += libxml2 libxslt
132NGINX_CONF_OPTS += --with-http_xslt_module
133endif
134
135ifeq ($(BR2_PACKAGE_NGINX_HTTP_IMAGE_FILTER_MODULE),y)
136NGINX_DEPENDENCIES += gd jpeg libpng
137NGINX_CONF_OPTS += --with-http_image_filter_module
138endif
139
140ifeq ($(BR2_PACKAGE_NGINX_HTTP_GEOIP_MODULE),y)
141NGINX_DEPENDENCIES += geoip
142NGINX_CONF_OPTS += --with-http_geoip_module
143endif
144
145ifeq ($(BR2_PACKAGE_NGINX_HTTP_GUNZIP_MODULE),y)
146NGINX_DEPENDENCIES += zlib
147NGINX_CONF_OPTS += --with-http_gunzip_module
148endif
149
150ifeq ($(BR2_PACKAGE_NGINX_HTTP_GZIP_STATIC_MODULE),y)
151NGINX_DEPENDENCIES += zlib
152NGINX_CONF_OPTS += --with-http_gzip_static_module
153endif
154
155ifeq ($(BR2_PACKAGE_NGINX_HTTP_SECURE_LINK_MODULE),y)
156NGINX_DEPENDENCIES += openssl
157NGINX_CONF_OPTS += --with-http_secure_link_module
158endif
159
160ifeq ($(BR2_PACKAGE_NGINX_HTTP_GZIP_MODULE),y)
161NGINX_DEPENDENCIES += zlib
162else
163NGINX_CONF_OPTS += --without-http_gzip_module
164endif
165
166ifeq ($(BR2_PACKAGE_NGINX_HTTP_REWRITE_MODULE),y)
167NGINX_DEPENDENCIES += pcre
168else
169NGINX_CONF_OPTS += --without-http_rewrite_module
170endif
171
172NGINX_CONF_OPTS += \
173	$(if $(BR2_PACKAGE_NGINX_HTTP_REALIP_MODULE),--with-http_realip_module) \
174	$(if $(BR2_PACKAGE_NGINX_HTTP_ADDITION_MODULE),--with-http_addition_module) \
175	$(if $(BR2_PACKAGE_NGINX_HTTP_SUB_MODULE),--with-http_sub_module) \
176	$(if $(BR2_PACKAGE_NGINX_HTTP_DAV_MODULE),--with-http_dav_module) \
177	$(if $(BR2_PACKAGE_NGINX_HTTP_FLV_MODULE),--with-http_flv_module) \
178	$(if $(BR2_PACKAGE_NGINX_HTTP_MP4_MODULE),--with-http_mp4_module) \
179	$(if $(BR2_PACKAGE_NGINX_HTTP_AUTH_REQUEST_MODULE),--with-http_auth_request_module) \
180	$(if $(BR2_PACKAGE_NGINX_HTTP_RANDOM_INDEX_MODULE),--with-http_random_index_module) \
181	$(if $(BR2_PACKAGE_NGINX_HTTP_DEGRADATION_MODULE),--with-http_degradation_module) \
182	$(if $(BR2_PACKAGE_NGINX_HTTP_SLICE_MODULE),--with-http_slice_module) \
183	$(if $(BR2_PACKAGE_NGINX_HTTP_STUB_STATUS_MODULE),--with-http_stub_status_module) \
184	$(if $(BR2_PACKAGE_NGINX_HTTP_CHARSET_MODULE),,--without-http_charset_module) \
185	$(if $(BR2_PACKAGE_NGINX_HTTP_SSI_MODULE),,--without-http_ssi_module) \
186	$(if $(BR2_PACKAGE_NGINX_HTTP_USERID_MODULE),,--without-http_userid_module) \
187	$(if $(BR2_PACKAGE_NGINX_HTTP_ACCESS_MODULE),,--without-http_access_module) \
188	$(if $(BR2_PACKAGE_NGINX_HTTP_AUTH_BASIC_MODULE),,--without-http_auth_basic_module) \
189	$(if $(BR2_PACKAGE_NGINX_HTTP_AUTOINDEX_MODULE),,--without-http_autoindex_module) \
190	$(if $(BR2_PACKAGE_NGINX_HTTP_GEO_MODULE),,--without-http_geo_module) \
191	$(if $(BR2_PACKAGE_NGINX_HTTP_MAP_MODULE),,--without-http_map_module) \
192	$(if $(BR2_PACKAGE_NGINX_HTTP_SPLIT_CLIENTS_MODULE),,--without-http_split_clients_module) \
193	$(if $(BR2_PACKAGE_NGINX_HTTP_REFERER_MODULE),,--without-http_referer_module) \
194	$(if $(BR2_PACKAGE_NGINX_HTTP_PROXY_MODULE),,--without-http_proxy_module) \
195	$(if $(BR2_PACKAGE_NGINX_HTTP_FASTCGI_MODULE),,--without-http_fastcgi_module) \
196	$(if $(BR2_PACKAGE_NGINX_HTTP_UWSGI_MODULE),,--without-http_uwsgi_module) \
197	$(if $(BR2_PACKAGE_NGINX_HTTP_SCGI_MODULE),,--without-http_scgi_module) \
198	$(if $(BR2_PACKAGE_NGINX_HTTP_MEMCACHED_MODULE),,--without-http_memcached_module) \
199	$(if $(BR2_PACKAGE_NGINX_HTTP_LIMIT_CONN_MODULE),,--without-http_limit_conn_module) \
200	$(if $(BR2_PACKAGE_NGINX_HTTP_LIMIT_REQ_MODULE),,--without-http_limit_req_module) \
201	$(if $(BR2_PACKAGE_NGINX_HTTP_EMPTY_GIF_MODULE),,--without-http_empty_gif_module) \
202	$(if $(BR2_PACKAGE_NGINX_HTTP_BROWSER_MODULE),,--without-http_browser_module) \
203	$(if $(BR2_PACKAGE_NGINX_HTTP_UPSTREAM_IP_HASH_MODULE),,--without-http_upstream_ip_hash_module) \
204	$(if $(BR2_PACKAGE_NGINX_HTTP_UPSTREAM_LEAST_CONN_MODULE),,--without-http_upstream_least_conn_module) \
205	$(if $(BR2_PACKAGE_NGINX_HTTP_UPSTREAM_RANDOM_MODULE),,--without-http_upstream_random_module) \
206	$(if $(BR2_PACKAGE_NGINX_HTTP_UPSTREAM_KEEPALIVE_MODULE),,--without-http_upstream_keepalive_module)
207
208else # !BR2_PACKAGE_NGINX_HTTP
209NGINX_CONF_OPTS += --without-http
210endif # BR2_PACKAGE_NGINX_HTTP
211
212# mail modules
213ifeq ($(BR2_PACKAGE_NGINX_MAIL),y)
214NGINX_CONF_OPTS += --with-mail
215
216ifeq ($(BR2_PACKAGE_NGINX_MAIL_SSL_MODULE),y)
217NGINX_DEPENDENCIES += openssl
218NGINX_CONF_OPTS += --with-mail_ssl_module
219endif
220
221NGINX_CONF_OPTS += \
222	$(if $(BR2_PACKAGE_NGINX_MAIL_POP3_MODULE),,--without-mail_pop3_module) \
223	$(if $(BR2_PACKAGE_NGINX_MAIL_IMAP_MODULE),,--without-mail_imap_module) \
224	$(if $(BR2_PACKAGE_NGINX_MAIL_SMTP_MODULE),,--without-mail_smtp_module)
225
226endif # BR2_PACKAGE_NGINX_MAIL
227
228# stream modules
229ifeq ($(BR2_PACKAGE_NGINX_STREAM),y)
230NGINX_CONF_OPTS += --with-stream
231
232ifeq ($(BR2_PACKAGE_NGINX_STREAM_REALIP_MODULE),y)
233NGINX_CONF_OPTS += --with-stream_realip_module
234endif
235
236ifeq ($(BR2_PACKAGE_NGINX_STREAM_SET_MODULE),)
237NGINX_CONF_OPTS += --without-stream_set_module
238endif
239
240ifeq ($(BR2_PACKAGE_NGINX_STREAM_SSL_MODULE),y)
241NGINX_DEPENDENCIES += openssl
242NGINX_CONF_OPTS += --with-stream_ssl_module
243endif
244
245ifeq ($(BR2_PACKAGE_NGINX_STREAM_GEOIP_MODULE),y)
246NGINX_DEPENDENCIES += geoip
247NGINX_CONF_OPTS += --with-stream_geoip_module
248endif
249
250ifeq ($(BR2_PACKAGE_NGINX_STREAM_SSL_PREREAD_MODULE),y)
251NGINX_CONF_OPTS += --with-stream_ssl_preread_module
252endif
253
254NGINX_CONF_OPTS += \
255	$(if $(BR2_PACKAGE_NGINX_STREAM_LIMIT_CONN_MODULE),,--without-stream_limit_conn_module) \
256	$(if $(BR2_PACKAGE_NGINX_STREAM_ACCESS_MODULE),,--without-stream_access_module) \
257	$(if $(BR2_PACKAGE_NGINX_STREAM_GEO_MODULE),,--without-stream_geo_module) \
258	$(if $(BR2_PACKAGE_NGINX_STREAM_MAP_MODULE),,--without-stream_map_module) \
259	$(if $(BR2_PACKAGE_NGINX_STREAM_SPLIT_CLIENTS_MODULE),,--without-stream_split_clients_module) \
260	$(if $(BR2_PACKAGE_NGINX_STREAM_RETURN_MODULE),,--without-stream_return_module) \
261	$(if $(BR2_PACKAGE_NGINX_STREAM_UPSTREAM_HASH_MODULE),,--without-stream_upstream_hash_module) \
262	$(if $(BR2_PACKAGE_NGINX_STREAM_UPSTREAM_LEAST_CONN_MODULE),,--without-stream_upstream_least_conn_module) \
263	$(if $(BR2_PACKAGE_NGINX_STREAM_UPSTREAM_RANDOM_MODULE),,--without-stream_upstream_random_module) \
264	$(if $(BR2_PACKAGE_NGINX_STREAM_UPSTREAM_ZONE_MODULE),,--without-stream_upstream_zone_module)
265
266endif # BR2_PACKAGE_NGINX_STREAM
267
268# external modules
269ifeq ($(BR2_PACKAGE_NGINX_UPLOAD),y)
270NGINX_CONF_OPTS += $(addprefix --add-module=,$(NGINX_UPLOAD_DIR))
271NGINX_DEPENDENCIES += nginx-upload
272endif
273
274ifeq ($(BR2_PACKAGE_NGINX_DAV_EXT),y)
275NGINX_CONF_OPTS += --add-module=$(NGINX_DAV_EXT_DIR)
276NGINX_DEPENDENCIES += nginx-dav-ext
277endif
278
279ifeq ($(BR2_PACKAGE_NGINX_NAXSI),y)
280NGINX_DEPENDENCIES += nginx-naxsi
281NGINX_CONF_OPTS += --add-module=$(NGINX_NAXSI_DIR)/naxsi_src
282endif
283
284ifeq ($(BR2_PACKAGE_NGINX_MODSECURITY),y)
285NGINX_DEPENDENCIES += nginx-modsecurity
286NGINX_CONF_OPTS += --add-module=$(NGINX_MODSECURITY_DIR)
287endif
288
289# Debug logging
290NGINX_CONF_OPTS += $(if $(BR2_PACKAGE_NGINX_DEBUG),--with-debug)
291
292define NGINX_DISABLE_WERROR
293	$(SED) 's/-Werror//g' -i $(@D)/auto/cc/*
294endef
295
296NGINX_PRE_CONFIGURE_HOOKS += NGINX_DISABLE_WERROR
297
298define NGINX_CONFIGURE_CMDS
299	cd $(@D) ; $(NGINX_CONF_ENV) \
300		PKG_CONFIG="$(PKG_CONFIG_HOST_BINARY)" \
301		./configure $(NGINX_CONF_OPTS) \
302			--with-cc-opt="$(TARGET_CFLAGS) $(NGINX_CFLAGS)"
303endef
304
305define NGINX_BUILD_CMDS
306	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
307endef
308
309define NGINX_INSTALL_TARGET_CMDS
310	$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) install
311	$(RM) $(TARGET_DIR)/usr/sbin/nginx.old
312	$(INSTALL) -D -m 0664 package/nginx/nginx.logrotate \
313		$(TARGET_DIR)/etc/logrotate.d/nginx
314endef
315
316define NGINX_INSTALL_INIT_SYSTEMD
317	$(INSTALL) -D -m 0644 package/nginx/nginx.service \
318		$(TARGET_DIR)/usr/lib/systemd/system/nginx.service
319endef
320
321define NGINX_INSTALL_INIT_SYSV
322	$(INSTALL) -D -m 0755 package/nginx/S50nginx \
323		$(TARGET_DIR)/etc/init.d/S50nginx
324endef
325
326$(eval $(generic-package))
327