nginx.mk 11 KB

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