nginx.mk 11 KB

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