#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

CODENAME = $(shell /usr/bin/lsb_release --codename --short)
ARCH     = $(shell uname -m | sed -e 's|x86_64|x64|g' | sed -e 's|i[0-9]86|ia32|g')

OPENSSL_NGX_EXTRA_FLAGS = no-shared enable-unit-test enable-rfc3779 enable-cms no-ssl3 no-ssl3-method no-camellia no-idea no-des no-aria no-bf no-cast no-sm4 no-mdc2 no-rc5 no-seed no-psk no-srp no-gost no-md4 no-rc2 no-rc4 no-blake2 no-rmd160 no-sm3 no-dso no-zlib
ifeq ($(ARCH), x64)
    OPENSSL_NGX_EXTRA_FLAGS += enable-ec_nistp_64_gcc_128
endif

CONFIGURE_OPTS = \
    --prefix=/usr/share/nginx                        \
    --conf-path=/etc/nginx/nginx.conf                \
    --http-log-path=/var/log/nginx/access.log        \
    --error-log-path=/var/log/nginx/error.log        \
    --lock-path=/var/lock/nginx.lock                 \
    --pid-path=/run/nginx.pid                        \
    --http-client-body-temp-path=/var/lib/nginx/body \
    --http-fastcgi-temp-path=/var/lib/nginx/fastcgi  \
    --http-proxy-temp-path=/var/lib/nginx/proxy      \
    --http-scgi-temp-path=/var/lib/nginx/scgi        \
    --http-uwsgi-temp-path=/var/lib/nginx/uwsgi      \
    --with-openssl=openssl                           \
    --with-openssl-opt="$(OPENSSL_NGX_EXTRA_FLAGS)"  \
    --with-cc-opt="-I../openssl/build/include"       \
    --with-ld-opt="-L../openssl/build/lib"           \
    --with-compat                                    \
    --with-debug                                     \
    --with-stream                                    \
    --with-pcre-jit                                  \
    --with-http_ssl_module                           \
    --with-http_v2_module                            \
    --with-http_v3_module                            \
    --with-http_stub_status_module                   \
    --with-http_realip_module                        \
    --with-http_auth_request_module                  \
    --with-http_addition_module                      \
    --with-http_dav_module                           \
    --with-http_gzip_static_module                   \
    --with-http_gunzip_module                        \
    --with-http_image_filter_module                  \
    --with-http_sub_module                           \
    --with-http_xslt_module                          \
    --with-http_secure_link_module                   \
    --add-module=ngx_cache_purge                     \
    --add-module=ngx_brotli                          \
    --add-module=nginx-sla

override_dh_auto_configure:
	./configure $(CONFIGURE_OPTS)

override_dh_auto_install:
	cp openssl/apps/openssl objs/nginx-openssl

%:
	dh $@ --parallel
