Merged with the default branch.
diff --git a/debian/Makefile b/debian/Makefile
new file mode 100644
index 0000000..582dd8f
--- /dev/null
+++ b/debian/Makefile
@@ -0,0 +1,401 @@
+SHELL=		/bin/bash
+
+BASE_VERSION=	1.10.1
+BASE_RELEASE=	1
+BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
+SRCDIR=		nginx-$(BASE_VERSION)
+SRCPATH?=	../..
+
+CODENAME=	$(shell lsb_release -cs)
+ARCH=		$(shell uname -m)
+NPROC=		$(shell getconf _NPROCESSORS_ONLN)
+MODSRC_PREFIX=	extra/
+
+MODULES=	geoip image-filter njs perl xslt
+
+MODULE_SUMMARY_geoip=		GeoIP dynamic modules
+MODULE_SUMMARY_image_filter=	image filter dynamic module
+MODULE_SUMMARY_njs=		nginScript dynamic modules
+MODULE_SUMMARY_perl=		Perl dynamic module
+MODULE_SUMMARY_xslt=		xslt dynamic module
+
+MODULE_VERSION_geoip=		$(BASE_VERSION)
+MODULE_RELEASE_geoip=		1
+MODULE_VERSION_image_filter=	$(BASE_VERSION)
+MODULE_RELEASE_image_filter=	1
+MODULE_SHAID_njs=		1c50334fbea6
+MODULE_VERSION_njs=		0.0.20160414.$(MODULE_SHAID_njs)
+MODULE_RELEASE_njs=		1
+MODULE_VERSION_perl=		$(BASE_VERSION)
+MODULE_RELEASE_perl=		1
+MODULE_VERSION_xslt=		$(BASE_VERSION)
+MODULE_RELEASE_xslt=		1
+
+MODULE_SOURCES_njs=		njs-$(MODULE_SHAID_njs).tar.gz
+
+MODULE_CONFARGS_geoip=		--with-http_geoip_module=dynamic \
+				--with-stream_geoip_module=dynamic
+MODULE_CONFARGS_image_filter=	--with-http_image_filter_module=dynamic
+MODULE_CONFARGS_njs=		--add-dynamic-module=$(MODSRC_PREFIX)njs-$(MODULE_SHAID_njs)/nginx
+MODULE_CONFARGS_perl=		--with-http_perl_module=dynamic
+MODULE_CONFARGS_xslt=		--with-http_xslt_module=dynamic
+
+# geoip
+
+MODULE_BUILD_DEPENDS_geoip=,libgeoip-dev
+MODULE_DEPENDS_geoip=,libgeoip1
+
+define MODULE_POST_geoip
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_geoip) for nginx have been installed.
+To enable these modules, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_geoip_module.so;
+    load_module modules/ngx_stream_geoip_module.so;
+
+Please refer to the modules documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_geoip_module.html
+http://nginx.org/en/docs/stream/ngx_stream_geoip_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_geoip
+
+# image-filter
+
+MODULE_BUILD_DEPENDS_image_filter=,libgd-dev
+
+define MODULE_POST_image_filter
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_image_filter) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_image_filter_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_image_filter
+
+# njs
+
+MODULE_VERSION_PREFIX_njs=$(BASE_VERSION).
+
+define MODULE_PREINSTALL_njs
+	mkdir -p $$(INSTALLDIR)/usr/share/doc/nginx-module-njs
+	install -m644 $$(BUILDDIR_nginx)/extra/njs-$(MODULE_VERSION_njs)/README $$(INSTALLDIR)/usr/share/doc/nginx-module-njs/
+endef
+export MODULE_PREINSTALL_njs
+
+define MODULE_POST_njs
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_njs) for nginx have been installed.
+To enable these modules, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_js_module.so;
+    load_module modules/ngx_stream_js_module.so;
+
+Please refer to the modules documentation for further details:
+/usr/share/doc/nginx-module-njs/README
+https://www.nginx.com/resources/wiki/nginScript/
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_njs
+
+# perl
+
+MODULE_BUILD_DEPENDS_perl=, libperl-dev
+MODULE_DEPENDS_perl=, $$\{perl:Depends\}
+
+define MODULE_PREINSTALL_perl
+	cd $$(BUILDDIR_nginx) \&\& $$(MAKE) DESTDIR=$$(INSTALLDIR) INSTALLDIRS=vendor -f objs/Makefile install_perl_modules
+	find $$(INSTALLDIR)/ -type f -name .packlist -exec rm -f '{}' \\;
+	find $$(INSTALLDIR)/ -type f -name perllocal.pod -exec rm -f '{}' \\;
+	find $$(INSTALLDIR)/ -type f -empty -exec rm -f '{}' \\;
+	find $$(INSTALLDIR)/ -type f -iname '*.so' -exec chmod 0755 '{}' \\;
+endef
+export MODULE_PREINSTALL_perl
+
+define MODULE_POST_perl
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_perl) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_perl_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_perl_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_perl
+
+# xslt
+
+MODULE_BUILD_DEPENDS_xslt=, libxslt1-dev
+
+define MODULE_POST_xslt
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_xslt) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_xslt_filter_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_xslt_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_xslt
+
+
+BASE_CONFIGURE_ARGS=\
+	--prefix=/etc/nginx \
+	--sbin-path=/usr/sbin/nginx \
+	--modules-path=/usr/lib/nginx/modules \
+	--conf-path=/etc/nginx/nginx.conf \
+	--error-log-path=/var/log/nginx/error.log \
+	--http-log-path=/var/log/nginx/access.log \
+	--pid-path=/var/run/nginx.pid \
+	--lock-path=/var/run/nginx.lock \
+	--http-client-body-temp-path=/var/cache/nginx/client_temp \
+	--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
+	--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
+	--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
+	--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
+	--user=nginx \
+	--group=nginx \
+	--with-file-aio \
+	--with-threads \
+	--with-ipv6 \
+	--with-http_addition_module \
+	--with-http_auth_request_module \
+	--with-http_dav_module \
+	--with-http_flv_module \
+	--with-http_gunzip_module \
+	--with-http_gzip_static_module \
+	--with-http_mp4_module \
+	--with-http_random_index_module \
+	--with-http_realip_module \
+	--with-http_secure_link_module \
+	--with-http_slice_module \
+	--with-http_ssl_module \
+	--with-http_stub_status_module \
+	--with-http_sub_module \
+	--with-http_v2_module \
+	--with-mail \
+	--with-mail_ssl_module \
+	--with-stream \
+	--with-stream_ssl_module
+
+export CR=\\n
+
+modname = $(shell echo $1 | cut -d '-' -f 3- | tr '-' '_')
+
+default:
+	@echo "valid targets: all base $(addprefix module-, $(MODULES)) test test-debug"
+
+all:	base modules
+	@echo "===> all done"
+
+modules:	$(addprefix module-, $(MODULES))
+
+rules:	rules-base $(addprefix rules-module-, $(MODULES))
+
+base:	rules-base
+	@echo "===> Building base package"
+	@$(SHELL) -c "cd debuild-base/$(SRCDIR) ; export DEB_BUILD_OPTIONS=parallel=$(NPROC) ; time -p debuild -us -uc"
+	@find debuild-base/ -maxdepth 1 -type f -exec cp {} ../../ \;
+	@ln -s debuild-base/$(SRCDIR)/debian/nginx/usr/sbin base
+
+$(BASE_SRC):
+	@{ \
+	if [ -f $(SRCPATH)/$(BASE_SRC) ]; then \
+		cp -P $(SRCPATH)/$(BASE_SRC) $(BASE_SRC) ; \
+	elif [ -f $(SRCPATH)/nginx_$(BASE_VERSION).orig.tar.gz ]; then \
+		cp -P $(SRCPATH)/nginx_$(BASE_VERSION).orig.tar.gz $(BASE_SRC) ; \
+	else \
+		wget http://nginx.org/download/$(BASE_SRC) ; \
+	fi ; \
+	}
+
+rules-base: $(BASE_SRC)
+	@echo "===> Creating $@"
+	@{ \
+	set -e ; \
+	mkdir -p debuild-base ; \
+	cp $(BASE_SRC) debuild-base/nginx_$(BASE_VERSION).orig.tar.gz ; \
+	tar -C debuild-base -xf debuild-base/nginx_$(BASE_VERSION).orig.tar.gz ; \
+	mkdir -p debuild-base/$(SRCDIR)/debian ; \
+	mkdir -p debuild-base/$(SRCDIR)/debian/source ; \
+	echo "3.0 (quilt)" > debuild-base/$(SRCDIR)/debian/source/format ; \
+	echo "9" > debuild-base/$(SRCDIR)/debian/compat ; \
+	cat nginx.rules.in | sed \
+		-e 's#%%CODENAME%%#$(CODENAME)#g' \
+		-e 's#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g' \
+		-e 's#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g' \
+		> debuild-base/$(SRCDIR)/debian/rules ; \
+	cat nginx.changelog.in | sed \
+		-e 's#%%CODENAME%%#$(CODENAME)#g' \
+		-e 's#%%MAIN_VERSION%%#$(BASE_VERSION)#g' \
+		-e 's#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g' \
+		> debuild-base/$(SRCDIR)/debian/changelog ; \
+	cp nginx.control.in debuild-base/$(SRCDIR)/debian/control ; \
+	cp copyright ../CHANGES ../CHANGES.ru nginx.* nginx-debug.default debuild-base/$(SRCDIR)/debian/ ; \
+	chmod +x debuild-base/$(SRCDIR)/debian/rules ; \
+	ln -s debuild-base/$(SRCDIR)/debian/rules rules-base ; \
+	}
+
+module-%: rules-module-%
+	@echo "===> Building nginx-$@ package" ; \
+	$(SHELL) -c "cd debuild-$@/$(SRCDIR) ; export DEB_BUILD_OPTIONS=parallel=$(NPROC) ; time -p debuild -us -uc" ; \
+	find debuild-$@/ -maxdepth 1 -type f -exec cp {} ../../ \;; \
+	ln -s debuild-$@/$(SRCDIR)/debian/nginx-$@/usr/lib/nginx/modules $@
+
+rules-module-%: $(BASE_SRC)
+	@echo "===> Creating $@"
+	@{ \
+	set -e ; \
+	curdir=`pwd` ; \
+	module=`echo $@ | cut -d '-' -f 3- | tr '-' '_'` ; \
+	module_asis=`echo $@ | cut -d '-' -f 3-` ; \
+	builddir=`echo debuild-module-$${module_asis}` ; \
+	mkdir -p $${builddir} ; \
+	cp $(BASE_SRC) $${builddir}/nginx-module-$${module_asis}_$(MODULE_VERSION_PREFIX_$(call modname, $@))$(MODULE_VERSION_$(call modname, $@)).orig.tar.gz ; \
+	tar -C $${builddir} -xf $${builddir}/nginx-module-$${module_asis}_$(MODULE_VERSION_PREFIX_$(call modname, $@))$(MODULE_VERSION_$(call modname, $@)).orig.tar.gz ; \
+	mkdir -p $${builddir}/$(SRCDIR)/debian/extra ; \
+	mkdir -p $${builddir}/$(SRCDIR)/debian/source ; \
+	echo "3.0 (quilt)" > $${builddir}/$(SRCDIR)/debian/source/format ; \
+	echo "9" > $${builddir}/$(SRCDIR)/debian/compat ; \
+	for src in $(MODULE_SOURCES_$(call modname, $@)); do \
+		tar -C $${builddir}/$(SRCDIR)/debian/extra -xf extra/$${src} ; \
+	done ; \
+	for p in $(MODULE_PATCHES_$(call modname, $@)); do \
+		( cd $${builddir}/$(SRCDIR)/debian/extra && patch -p1 < $${curdir}/extra/$${p} ) ; \
+	done ; \
+	( cd $${builddir}/$(SRCDIR) && find debian/ -type f -exec file --mime {} \; | fgrep 'charset=binary' | cut -d ':' -f 1 > include-binaries && mv include-binaries debian/source/ ) ; \
+	copyright_file="nginx-module-$${module}.copyright" ; \
+	if [ -f $${copyright_file} ]; then \
+		copyright_source=$${copyright_file} ; \
+	else \
+		copyright_source=copyright ; \
+	fi ; \
+	changelog_file="nginx-module-$${module}.changelog.in" ; \
+	if [ -f $${changelog_file} ]; then \
+		changelog_tmpl=$${changelog_file} ; \
+	else \
+		changelog_tmpl=nginx-module.changelog.in ; \
+	fi ; \
+	cp $${copyright_source} $${builddir}/$(SRCDIR)/debian/copyright ; \
+	definitions=`echo "$$MODULE_DEFINITIONS_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	addcontroltags=`echo "$$MODULE_ADD_CONTROL_TAGS_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	prebuild=`echo "$$MODULE_PREBUILD_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	preinstall=`echo "$$MODULE_PREINSTALL_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	post=`echo "$$MODULE_POST_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	cat nginx-module.control.in | sed \
+		-e "s#%%MODULE%%#$${module_asis}#g" \
+		-e "s#%%SUMMARY%%#nginx $(MODULE_SUMMARY_$(call modname, $@))#g" \
+		-e "s#%%SHORT_SUMMARY%%#$(MODULE_SUMMARY_$(call modname, $@))#g" \
+		-e "s#%%CODENAME%%#$(CODENAME)#g" \
+		-e "s#%%MAIN_VERSION%%#$(BASE_VERSION)#g" \
+		-e "s#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g" \
+		-e "s#%%VERSION_PREFIX%%#$(MODULE_VERSION_PREFIX_$(call modname, $@))#g" \
+		-e "s#%%MODULE_VERSION%%#$(MODULE_VERSION_$(call modname, $@))#g" \
+		-e "s#%%MODULE_RELEASE%%#$(MODULE_RELEASE_$(call modname, $@))#g" \
+		-e "s#%%MODULE_BUILD_DEPENDS%%#$(MODULE_BUILD_DEPENDS_$(call modname, $@))#g" \
+		-e "s#%%MODULE_DEPENDS%%#$(MODULE_DEPENDS_$(call modname, $@))#g" \
+		-e "s#%%ADD_CONTROL_TAGS%%#$${addcontroltags}#g" \
+	> $${builddir}/$(SRCDIR)/debian/control ; \
+	cat $${changelog_tmpl} | sed \
+		-e "s#%%MODULE%%#$${module_asis}#g" \
+		-e "s#%%CODENAME%%#$(CODENAME)#g" \
+		-e "s#%%VERSION_PREFIX%%#$(MODULE_VERSION_PREFIX_$(call modname, $@))#g" \
+		-e "s#%%MODULE_VERSION%%#$(MODULE_VERSION_$(call modname, $@))#g" \
+		-e "s#%%MODULE_RELEASE%%#$(MODULE_RELEASE_$(call modname, $@))#g" \
+	> $${builddir}/$(SRCDIR)/debian/changelog ; \
+	cat nginx-module.rules.in | sed \
+		-e "s#%%MODULE%%#$${module_asis}#g" \
+		-e "s#%%CODENAME%%#$(CODENAME)#g" \
+		-e "s#%%MAIN_VERSION%%#$(BASE_VERSION)#g" \
+		-e "s#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g" \
+		-e "s#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g" \
+		-e "s#%%MODULE_CONFIGURE_ARGS%%#$(MODULE_CONFARGS_$(call modname, $@))#g" \
+		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
+		-e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
+		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
+	> $${builddir}/$(SRCDIR)/debian/rules ; \
+	cat nginx-module.postinst.in | sed \
+		-e "s#%%MODULE_POST%%#$$post#g" \
+	> $${builddir}/$(SRCDIR)/debian/nginx-module-$${module_asis}.postinst ; \
+	chmod +x $${builddir}/$(SRCDIR)/debian/rules ; \
+	ln -s $${builddir}/$(SRCDIR)/debian/rules $@ ; \
+	}
+
+nginx-tests:
+	@{ \
+	if [ -d "$(SRCPATH)/nginx-tests" ]; then \
+		echo "===> Copying tests from $(SRCPATH)/nginx-tests" ; \
+		cp -rP $(SRCPATH)/nginx-tests nginx-tests ; \
+	else \
+		echo "===> Cloning tests" ; \
+		hg clone http://hg.nginx.org/nginx-tests ; \
+	fi ; \
+	}
+
+test: base nginx-tests
+	@echo "===> Running tests with regular binary/modules"
+	@{ \
+	pwd=`pwd` ; \
+	globals= ; \
+	for so in `find module-*/ -maxdepth 1 -type f -name "*module.so"`; do \
+		globals="$$globals load_module $$pwd/$$so;" ; \
+	done ; \
+	if [ -d $$pwd/debuild-module-perl ]; then \
+		globals="$$globals env PERL5LIB=$$pwd/debuild-module-perl/nginx-$(BASE_VERSION)/debian/build-nginx/objs/src/http/modules/perl:$$pwd/debuild-module-perl/nginx-$(BASE_VERSION)/debian/build-nginx/objs/src/http/modules/perl/blib/arch;" ; \
+	fi ; \
+	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx TEST_NGINX_GLOBALS="$$globals" prove . ; \
+	}
+
+test-debug: base nginx-tests
+	@echo "===> Running tests with debug binary/modules"
+	@{ \
+	pwd=`pwd` ; \
+	globals= ; \
+	for so in `find module-*/ -maxdepth 1 -type f -name "*module-debug.so"`; do \
+		globals="$$globals load_module $$pwd/$$so;" ; \
+	done ; \
+	if [ -d $$pwd/debuild-module-perl ]; then \
+		globals="$$globals env PERL5LIB=$$pwd/debuild-module-perl/nginx-$(BASE_VERSION)/debian/build-nginx/objs/src/http/modules/perl:$$pwd/debuild-module-perl/nginx-$(BASE_VERSION)/debian/build-nginx/objs/src/http/modules/perl/blib/arch;" ; \
+	fi ; \
+	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx-debug TEST_NGINX_GLOBALS="$$globals" prove . ; \
+	}
+
+clean:
+	@rm -rf base module-* rules-base rules-module-* debuild-base debuild-module-* nginx-tests
+
+.PHONY:	default all modules rules test test-debug clean
+
+.SECONDARY:
diff --git a/debian/control b/debian/control
deleted file mode 100644
index fb4ae7b..0000000
--- a/debian/control
+++ /dev/null
@@ -1,66 +0,0 @@
-Source: nginx
-Section: httpd
-Priority: optional
-Maintainer: Sergey Budnevitch <sb@nginx.com>
-Build-Depends: debhelper (>= 7.0.50~),
-               libgd2-xpm-dev,
-               libgeoip-dev,
-               libpcre3-dev,
-               libperl-dev,
-               libssl-dev (>= 0.9.7),
-               libxslt1-dev,
-               lsb-release,
-               zlib1g-dev
-Standards-Version: 3.9.1
-Homepage: http://nginx.org
-
-Package: nginx
-Architecture: any
-Depends: ${misc:Depends}, ${shlibs:Depends}, lsb-base, adduser
-Provides: httpd
-Description: high performance web server
- nginx [engine x] is an HTTP and reverse proxy server, as well as
- a mail proxy server.
-
-Package: nginx-dbg
-Architecture: any
-Section: debug
-Priority: extra
-Depends: ${misc:Depends}, nginx (= ${source:Version})
-Description: nginx debug symbols
- This package contains the debugging symbols for nginx.
-
-Package: nginx-module-xslt
-Architecture: any
-Priority: extra
-Depends: ${misc:Depends}, ${shlibs:Depends}, nginx (= ${source:Version})
-Description: xslt module
- This package contains dynamic xslt module for nginx.
-
-Package: nginx-module-image-filter
-Architecture: any
-Priority: extra
-Depends: ${misc:Depends}, ${shlibs:Depends}, nginx (= ${source:Version})
-Description: image filter module
- This package contains dynamic image filter module for nginx.
-
-Package: nginx-module-geoip
-Architecture: any
-Priority: extra
-Depends: ${misc:Depends}, ${shlibs:Depends}, nginx (= ${source:Version})
-Description: geoip module
- This package contains dynamic geoip module for nginx.
-
-Package: nginx-module-perl
-Architecture: any
-Priority: extra
-Depends: ${misc:Depends}, ${shlibs:Depends}, ${perl:Depends}, nginx (= ${source:Version})
-Description: perl module
- This package contains dynamic perl module for nginx.
-
-Package: nginx-module-njs
-Architecture: any
-Priority: extra
-Depends: ${misc:Depends}, ${shlibs:Depends}, nginx (= ${source:Version})
-Description: nJScript module
- This package contains dynamic nJScript module for nginx.
diff --git a/debian/copyright b/debian/copyright
index 804bf7c..83258f0 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -12,7 +12,8 @@
 
 Copyright:
 
- Copyright (C) Igor Sysoev
+Copyright (C) 2002-2016 Igor Sysoev
+Copyright (C) 2011-2016 Nginx, Inc.
 
 License:
 
diff --git a/debian/nginx-module-geoip.install b/debian/nginx-module-geoip.install
deleted file mode 100644
index d6069de..0000000
--- a/debian/nginx-module-geoip.install
+++ /dev/null
@@ -1,2 +0,0 @@
-objs/ngx_http_geoip_module.so usr/lib/nginx/modules
-objs/ngx_http_geoip_module-debug.so usr/lib/nginx/modules
diff --git a/debian/nginx-module-geoip.preinst b/debian/nginx-module-geoip.preinst
deleted file mode 100644
index cdfe806..0000000
--- a/debian/nginx-module-geoip.preinst
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-case "$1" in
-    install)
-        cat <<BANNER
-----------------------------------------------------------------------
-
-The GeoIP dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_geoip_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_geoip_module.html
-
-----------------------------------------------------------------------
-BANNER
-        ;;
-    upgrade|abort-upgrade)
-        ;;
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/nginx-module-image-filter.install b/debian/nginx-module-image-filter.install
deleted file mode 100644
index 4c1c443..0000000
--- a/debian/nginx-module-image-filter.install
+++ /dev/null
@@ -1,2 +0,0 @@
-objs/ngx_http_image_filter_module.so usr/lib/nginx/modules
-objs/ngx_http_image_filter_module-debug.so usr/lib/nginx/modules
diff --git a/debian/nginx-module-image-filter.preinst b/debian/nginx-module-image-filter.preinst
deleted file mode 100644
index 6269778..0000000
--- a/debian/nginx-module-image-filter.preinst
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-case "$1" in
-    install)
-        cat <<BANNER
-----------------------------------------------------------------------
-
-The image filter dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_image_filter_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
-
-----------------------------------------------------------------------
-BANNER
-        ;;
-    upgrade|abort-upgrade)
-        ;;
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/nginx-module-njs.install b/debian/nginx-module-njs.install
deleted file mode 100644
index 7510377..0000000
--- a/debian/nginx-module-njs.install
+++ /dev/null
@@ -1,2 +0,0 @@
-objs/ngx_http_js_module.so usr/lib/nginx/modules
-objs/ngx_http_js_module-debug.so usr/lib/nginx/modules
diff --git a/debian/nginx-module-njs.preinst b/debian/nginx-module-njs.preinst
deleted file mode 100644
index 55a49d3..0000000
--- a/debian/nginx-module-njs.preinst
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-case "$1" in
-    install)
-        cat <<BANNER
-----------------------------------------------------------------------
-
-The nJScript dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_njs_filter_module.so;
-
-Please refer to the module documentation for further details:
-https://www.nginx.com/resources/wiki/nginScript/
-
-----------------------------------------------------------------------
-BANNER
-        ;;
-    upgrade|abort-upgrade)
-        ;;
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/nginx-module-njs.version b/debian/nginx-module-njs.version
deleted file mode 100644
index 6acd589..0000000
--- a/debian/nginx-module-njs.version
+++ /dev/null
@@ -1 +0,0 @@
-1.10.1.0.0.20160414.1c50334fbea6-1
diff --git a/debian/nginx-module-perl.install b/debian/nginx-module-perl.install
deleted file mode 100755
index 9ac1028..0000000
--- a/debian/nginx-module-perl.install
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl -w
-
-use Config;
-
-my $vendorarch = substr($Config{vendorarch}, 1);
-
-print <<EOT;
-objs/ngx_http_perl_module.so usr/lib/nginx/modules
-objs/ngx_http_perl_module-debug.so usr/lib/nginx/modules
-EOT
-
-print "objs/src/http/modules/perl/blib/arch/auto/nginx/nginx.so    $vendorarch/auto/nginx\n";
-print "objs/src/http/modules/perl/blib/arch/auto/nginx/nginx-debug.so    $vendorarch/auto/nginx\n";
-print "objs/src/http/modules/perl/blib/lib/nginx.pm    $vendorarch\n";
diff --git a/debian/nginx-module-perl.preinst b/debian/nginx-module-perl.preinst
deleted file mode 100644
index 9db420f..0000000
--- a/debian/nginx-module-perl.preinst
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-case "$1" in
-    install)
-        cat <<BANNER
-----------------------------------------------------------------------
-
-The perl dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_perl_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_perl_module.html
-
-----------------------------------------------------------------------
-BANNER
-        ;;
-    upgrade|abort-upgrade)
-        ;;
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/nginx-module-xslt.install b/debian/nginx-module-xslt.install
deleted file mode 100644
index 7eb5cc9..0000000
--- a/debian/nginx-module-xslt.install
+++ /dev/null
@@ -1,2 +0,0 @@
-objs/ngx_http_xslt_filter_module.so usr/lib/nginx/modules
-objs/ngx_http_xslt_filter_module-debug.so usr/lib/nginx/modules
diff --git a/debian/nginx-module-xslt.preinst b/debian/nginx-module-xslt.preinst
deleted file mode 100644
index 6bf94d3..0000000
--- a/debian/nginx-module-xslt.preinst
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-case "$1" in
-    install)
-        cat <<BANNER
-----------------------------------------------------------------------
-
-The XSLT dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_xslt_filter_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_xslt_module.html
-
-----------------------------------------------------------------------
-BANNER
-        ;;
-    upgrade|abort-upgrade)
-        ;;
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 0
-        ;;
-esac
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/nginx-module.changelog.in b/debian/nginx-module.changelog.in
new file mode 100644
index 0000000..c0be416
--- /dev/null
+++ b/debian/nginx-module.changelog.in
@@ -0,0 +1,5 @@
+nginx-module-%%MODULE%% (%%VERSION_PREFIX%%%%MODULE_VERSION%%-%%MODULE_RELEASE%%~%%CODENAME%%) %%CODENAME%%; urgency=low
+
+  * base version updated to 1.10.1-1
+
+ -- Konstantin Pavlov <thresh@nginx.com>  Tue, 31 May 2016 16:30:00 +0300
diff --git a/debian/nginx-module.control.in b/debian/nginx-module.control.in
new file mode 100644
index 0000000..29000cb
--- /dev/null
+++ b/debian/nginx-module.control.in
@@ -0,0 +1,31 @@
+Source: nginx-module-%%MODULE%%
+Section: httpd
+Priority: optional
+Maintainer: Sergey Budnevitch <sb@nginx.com>
+Build-Depends: debhelper (>= 9~),
+               dpkg-dev (>= 1.16.1~),
+               quilt (>= 0.46-7~),
+               lsb-release,
+               libssl-dev (>= 1.0.1),
+               libpcre3-dev,
+               zlib1g-dev%%MODULE_BUILD_DEPENDS%%
+Standards-Version: 3.9.8.0
+Homepage: http://nginx.org
+
+Package: nginx-module-%%MODULE%%
+Architecture: any
+Depends: ${misc:Depends},
+         ${shlibs:Depends},
+         nginx (= %%MAIN_VERSION%%-%%MAIN_RELEASE%%~%%CODENAME%%)%%MODULE_DEPENDS%%%%ADD_CONTROL_TAGS%%
+Description: %%SUMMARY%%
+ %%SHORT_SUMMARY%% for nginx
+
+Package: nginx-module-%%MODULE%%-dbg
+Architecture: any
+Section: debug
+Priority: extra
+Depends: nginx (= %%MAIN_VERSION%%-%%MAIN_RELEASE%%~%%CODENAME%%),
+         nginx-module-%%MODULE%% (= %%VERSION_PREFIX%%%%MODULE_VERSION%%-%%MODULE_RELEASE%%~%%CODENAME%%),
+         ${misc:Depends}
+Description: debug symbols for the nginx-module-%%MODULE%%
+ %%SHORT_SUMMARY%% for nginx (debug symbols)
diff --git a/debian/nginx-module.postinst.in b/debian/nginx-module.postinst.in
new file mode 100644
index 0000000..781e25c
--- /dev/null
+++ b/debian/nginx-module.postinst.in
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" != "configure" ]; then
+    exit 0
+fi
+
+%%MODULE_POST%%
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/nginx-module.rules.in b/debian/nginx-module.rules.in
new file mode 100755
index 0000000..bbbacfe
--- /dev/null
+++ b/debian/nginx-module.rules.in
@@ -0,0 +1,129 @@
+#!/usr/bin/make -f
+
+#export DH_VERBOSE=1
+export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie                              
+DPKG_EXPORT_BUILDFLAGS = 1                                                      
+include /usr/share/dpkg/buildflags.mk
+
+BUILDDIR_nginx = $(CURDIR)/debian/build-nginx
+BUILDDIR_nginx_debug = $(CURDIR)/debian/build-nginx-debug
+INSTALLDIR = $(CURDIR)/debian/nginx-module-%%MODULE%%
+BASEDIR = $(CURDIR)
+
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+	ifeq (${NUMJOBS}, 0)
+		NUMJOBS = 1
+	endif
+else
+	NUMJOBS = 1
+endif
+
+%%MODULE_DEFINITIONS%%
+
+config.env.%:
+	dh_testdir
+	mkdir -p $(BUILDDIR_$*)
+	cp -Pa $(CURDIR)/auto $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/conf $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/configure $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/contrib $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/man $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/src $(BUILDDIR_$*)/
+	test -d $(CURDIR)/debian/extra && cp -Pa $(CURDIR)/debian/extra $(BUILDDIR_$*)/
+	touch $@
+
+config.pre.nginx:
+	dh_testdir
+%%MODULE_PREBUILD%%
+	touch $@
+
+config.pre.nginx_debug: config.pre.nginx
+	dh_testdir
+	rm -rf $(BUILDDIR_nginx_debug)/extra && cp -Pa $(BUILDDIR_nginx)/extra $(BUILDDIR_nginx_debug)/
+	touch $@
+
+config.status.nginx: config.env.nginx config.pre.nginx
+	cd $(BUILDDIR_nginx) && \
+	CFLAGS="" ./configure %%BASE_CONFIGURE_ARGS%% %%MODULE_CONFIGURE_ARGS%% --with-cc-opt="$(CFLAGS)" --with-ld-opt="$(LDFLAGS)"
+	touch $@
+
+config.status.nginx_debug: config.env.nginx_debug config.pre.nginx_debug
+	cd $(BUILDDIR_nginx_debug) && \
+	CFLAGS="" ./configure %%BASE_CONFIGURE_ARGS%% %%MODULE_CONFIGURE_ARGS%% --with-cc-opt="$(CFLAGS)" --with-ld-opt="$(LDFLAGS)" --with-debug
+	touch $@
+
+build-arch.%: config.status.%
+	dh_testdir
+	dh_prep
+	$(MAKE) -j$(NUMJOBS) -C $(BUILDDIR_$*) modules
+
+build-arch: build-arch.nginx build-arch.nginx_debug
+	dh_testdir
+	touch $@
+
+build-dbg.%: install
+	dh_testdir
+	dh_strip --dbg-package=nginx-module-%%MODULE%%-dbg
+
+build-dbg: build-dbg.nginx
+	dh_testdir
+	touch $@
+
+build-indep:
+	dh_testdir
+	touch $@
+
+build: build-arch build-indep
+	dh_testdir
+	touch $@
+
+clean:
+	dh_testdir
+	dh_testroot
+	dh_clean
+	rm -rf $(CURDIR)/debian/build-*
+	find $(CURDIR) -maxdepth 1 -size 0 -delete
+
+post-build:
+	for so in `find $(BUILDDIR_nginx_debug)/objs/ -maxdepth 1 -type f -name "*.so"`; do \
+	    debugso=`echo $${so} | sed -e "s|.so|-debug.so|"` ; \
+	    mv $${so} $${debugso} ; \
+	done
+
+install:
+	dh_testdir
+	dh_testroot
+	dh_prep
+	dh_installdirs
+	dh_install
+%%MODULE_PREINSTALL%%
+	mkdir -p $(INSTALLDIR)/usr/lib/nginx/modules
+	for so in `find $(BUILDDIR_nginx_debug)/objs/ -maxdepth 1 -type f -name "*.so"`; do \
+	    install -m755 $${so} $(INSTALLDIR)/usr/lib/nginx/modules/ ; \
+	done
+	for so in `find $(BUILDDIR_nginx)/objs/ -maxdepth 1 -type f -name "*.so"`; do \
+	    install -m755 $${so} $(INSTALLDIR)/usr/lib/nginx/modules/ ; \
+	done
+
+binary-indep: build post-build install
+
+binary-arch: install build-dbg
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs -a
+	dh_installdocs -a
+	dh_lintian -a
+	dh_link -aA
+	dh_compress -a
+	dh_perl -a
+	dh_fixperms -a
+	dh_installdeb -a
+	dh_shlibdeps -a
+	dh_gencontrol -a
+	dh_md5sums -a
+	dh_builddeb -a
+
+binary: binary-indep binary-arch
+
+.PHONY: build clean binary-indep binary-arch binary install
diff --git a/debian/changelog b/debian/nginx.changelog.in
similarity index 98%
rename from debian/changelog
rename to debian/nginx.changelog.in
index 7ceab21..515fa0f 100644
--- a/debian/changelog
+++ b/debian/nginx.changelog.in
@@ -1,4 +1,4 @@
-nginx (1.10.1-1~%%CODENAME%%) %%CODENAME%%; urgency=low
+nginx (%%MAIN_VERSION%%-%%MAIN_RELEASE%%~%%CODENAME%%) %%CODENAME%%; urgency=low
 
   * 1.10.1
 
@@ -21,7 +21,7 @@
 
   * 1.9.14
 
- -- Konstantin Pavlov <thresh@nginx.com>  Tue, 04 Apr 2016 17:30:00 +0300
+ -- Konstantin Pavlov <thresh@nginx.com>  Tue, 05 Apr 2016 17:30:00 +0300
 
 nginx (1.9.13-1~%%CODENAME%%) %%CODENAME%%; urgency=low
 
diff --git a/debian/nginx.control.in b/debian/nginx.control.in
new file mode 100644
index 0000000..31a0360
--- /dev/null
+++ b/debian/nginx.control.in
@@ -0,0 +1,29 @@
+Source: nginx
+Section: httpd
+Priority: optional
+Maintainer: Sergey Budnevitch <sb@nginx.com>
+Build-Depends: debhelper (>= 9~),
+               dpkg-dev (>= 1.16.1~),
+               quilt (>= 0.46-7~),
+               lsb-release,
+               libssl-dev (>= 0.9.7),
+               libpcre3-dev,
+               zlib1g-dev
+Standards-Version: 3.9.8.0
+Homepage: http://nginx.org
+
+Package: nginx
+Architecture: any
+Depends: ${misc:Depends}, ${shlibs:Depends}, lsb-base, adduser
+Provides: httpd
+Description: high performance web server
+ nginx [engine x] is an HTTP and reverse proxy server, as well as
+ a mail proxy server.
+
+Package: nginx-dbg
+Architecture: any
+Section: debug
+Priority: extra
+Depends: ${misc:Depends}, nginx (= ${binary:Version})
+Description: nginx debug symbols
+ This package contains the debugging symbols for nginx.
diff --git a/debian/nginx.docs b/debian/nginx.docs
index 6268349..687f935 100644
--- a/debian/nginx.docs
+++ b/debian/nginx.docs
@@ -1,2 +1,2 @@
-README
 CHANGES.ru
+README
diff --git a/debian/init.d.in b/debian/nginx.init.in
similarity index 100%
rename from debian/init.d.in
rename to debian/nginx.init.in
diff --git a/debian/nginx.install b/debian/nginx.install
new file mode 100644
index 0000000..0865ff1
--- /dev/null
+++ b/debian/nginx.install
@@ -0,0 +1,12 @@
+debian/nginx.conf			etc/nginx
+conf/win-utf				etc/nginx
+conf/koi-utf				etc/nginx
+conf/koi-win				etc/nginx
+conf/mime.types				etc/nginx
+conf/scgi_params			etc/nginx
+conf/fastcgi_params			etc/nginx
+conf/uwsgi_params			etc/nginx
+html/index.html				usr/share/nginx/html
+html/50x.html				usr/share/nginx/html
+debian/build-nginx/objs/nginx		usr/sbin
+debian/build-nginx-debug/objs/nginx-debug	usr/sbin
diff --git a/debian/nginx.lintian-overrides b/debian/nginx.lintian-overrides
new file mode 100644
index 0000000..1894327
--- /dev/null
+++ b/debian/nginx.lintian-overrides
@@ -0,0 +1,6 @@
+# there is no separate man page for nginx-debug
+nginx binary: binary-without-manpage usr/sbin/nginx-debug
+# the name is not wrong
+nginx: wrong-name-for-upstream-changelog usr/share/doc/nginx/CHANGES.ru.gz
+# nginx-debug is not intended to be registered in rc.d
+nginx: script-in-etc-init.d-not-registered-via-update-rc.d etc/init.d/nginx-debug
diff --git a/debian/logrotate b/debian/nginx.logrotate
similarity index 63%
rename from debian/logrotate
rename to debian/nginx.logrotate
index a94b400..24139f6 100644
--- a/debian/logrotate
+++ b/debian/nginx.logrotate
@@ -8,6 +8,8 @@
         create 640 nginx adm
         sharedscripts
         postrotate
-                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
+                if [ -f /var/run/nginx.pid ]; then
+                        kill -USR1 `cat /var/run/nginx.pid`
+                fi
         endscript
 }
diff --git a/debian/nginx.manpages b/debian/nginx.manpages
new file mode 100644
index 0000000..7497da2
--- /dev/null
+++ b/debian/nginx.manpages
@@ -0,0 +1 @@
+objs/nginx.8
diff --git a/debian/nginx.postinst b/debian/nginx.postinst
index e0b6e6b..4932ec3 100644
--- a/debian/nginx.postinst
+++ b/debian/nginx.postinst
@@ -28,7 +28,6 @@
         /etc/init.d/nginx upgrade || echo \
             "Binary upgrade failed, please check nginx's error.log"
     else
-        update-rc.d nginx defaults >/dev/null
         if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
             invoke-rc.d nginx start || true
         else
@@ -36,3 +35,7 @@
         fi
     fi
 fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/nginx.prerm b/debian/nginx.prerm
index 7c26a4f..5f15bd8 100644
--- a/debian/nginx.prerm
+++ b/debian/nginx.prerm
@@ -19,4 +19,6 @@
         ;;
 esac
 
+#DEBHELPER#
+
 exit 0
diff --git a/debian/nginx.rules.in b/debian/nginx.rules.in
new file mode 100755
index 0000000..afa208b
--- /dev/null
+++ b/debian/nginx.rules.in
@@ -0,0 +1,133 @@
+#!/usr/bin/make -f
+
+#export DH_VERBOSE=1
+export DEB_BUILD_MAINT_OPTIONS=hardening=+all,-pie
+DPKG_EXPORT_BUILDFLAGS = 1
+include /usr/share/dpkg/buildflags.mk
+
+PKGS = nginx nginx-dbg
+
+BUILDDIR_nginx = $(CURDIR)/debian/build-nginx
+BUILDDIR_nginx_debug = $(CURDIR)/debian/build-nginx-debug
+INSTALLDIR = $(CURDIR)/debian/nginx
+BASEDIR = $(CURDIR)
+
+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
+	ifeq (${NUMJOBS}, 0)
+		NUMJOBS = 1
+	endif
+else
+	NUMJOBS = 1
+endif
+
+DO_PKGS = $(PKGS)
+
+config.env.%:
+	dh_testdir
+	mkdir -p $(BUILDDIR_$*)
+	cp -Pa $(CURDIR)/auto $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/conf $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/configure $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/contrib $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/man $(BUILDDIR_$*)/
+	cp -Pa $(CURDIR)/src $(BUILDDIR_$*)/
+	touch $@
+
+config.status.nginx: config.env.nginx
+	cd $(BUILDDIR_nginx) && \
+	CFLAGS="" ./configure %%BASE_CONFIGURE_ARGS%% --with-cc-opt="$(CFLAGS)" --with-ld-opt="$(LDFLAGS)"
+	touch $@
+
+config.status.nginx_debug: config.env.nginx_debug
+	cd $(BUILDDIR_nginx_debug) && \
+	CFLAGS="" ./configure %%BASE_CONFIGURE_ARGS%% --with-cc-opt="$(CFLAGS)" --with-ld-opt="$(LDFLAGS)" --with-debug
+	touch $@
+
+build-arch.%: config.status.%
+	dh_testdir
+	dh_prep
+	$(MAKE) -j$(NUMJOBS) -C $(BUILDDIR_$*) build
+
+build-arch: build-arch.nginx build-arch.nginx_debug
+	dh_testdir
+	touch $@
+
+build-dbg.%: install
+	dh_testdir
+	dh_strip --dbg-package=nginx-dbg
+
+build-dbg: build-dbg.nginx
+	dh_testdir
+	touch $@
+
+build-indep:
+	dh_testdir
+	touch $@
+
+build: build-arch build-indep
+	dh_testdir
+	touch $@
+
+clean:
+	dh_testdir
+	dh_testroot
+	dh_clean
+	rm -f $(CURDIR)/objs
+	rm -rf $(CURDIR)/debian/build-*
+	rm -f $(CURDIR)/debian/*.init
+	find $(CURDIR) -maxdepth 1 -size 0 -delete
+
+post-build:
+	mv $(BUILDDIR_nginx_debug)/objs/nginx $(BUILDDIR_nginx_debug)/objs/nginx-debug
+	ln -s $(BUILDDIR_nginx)/objs $(CURDIR)/objs
+	cp $(BUILDDIR_nginx)/objs/nginx.8 $(BUILDDIR_nginx)/objs/nginx-debug.8
+
+install:
+	dh_testdir
+	dh_testroot
+	dh_prep
+	dh_installdirs
+	dh_install
+	mkdir -p $(INSTALLDIR)/usr/lib/nginx/modules
+	mkdir -p $(INSTALLDIR)/usr/share/doc/nginx
+	install -m 644 debian/CHANGES $(INSTALLDIR)/usr/share/doc/nginx/changelog
+	install -m 644 debian/nginx.vh.default.conf $(INSTALLDIR)/etc/nginx/conf.d/default.conf
+	ln -s /usr/lib/nginx/modules $(INSTALLDIR)/etc/nginx/modules
+
+binary-indep: build post-build install
+	dh_testdir
+	dh_testroot
+	dh_installman -i -pnginx
+	dh_installdebconf
+	sed -e 's/%%PROVIDES%%/nginx/g' \
+		-e 's/%%DEFAULTSTART%%/2 3 4 5/g' \
+		-e 's/%%DEFAULTSTOP%%/0 1 6/g' \
+		< debian/nginx.init.in > debian/nginx.init
+	dh_installinit -i -pnginx --no-restart-on-upgrade --no-start --name=nginx
+	sed -e 's/%%PROVIDES%%/nginx-debug/g' \
+		-e 's/%%DEFAULTSTART%%//g' \
+		-e 's/%%DEFAULTSTOP%%/0 1 2 3 4 5 6/g' \
+		< debian/nginx.init.in > debian/nginx-debug.init
+	dh_installinit -i -pnginx --no-restart-on-upgrade --no-start --noscripts --name=nginx-debug
+	dh_installlogrotate -i -pnginx --name=nginx
+
+binary-arch: install build-dbg
+	dh_testdir
+	dh_testroot
+	dh_installchangelogs -a
+	dh_installdocs -a
+	dh_lintian -a
+	dh_link -aA
+	dh_compress -a
+	dh_perl -a
+	dh_fixperms -a
+	dh_installdeb -a
+	dh_shlibdeps -a
+	dh_gencontrol -a
+	dh_md5sums -a
+	dh_builddeb $(foreach p,$(DO_PKGS),-p$(p))
+
+binary: binary-indep binary-arch
+
+.PHONY: build clean binary-indep binary-arch binary install
diff --git a/debian/rules b/debian/rules
deleted file mode 100755
index 341cf09..0000000
--- a/debian/rules
+++ /dev/null
@@ -1,129 +0,0 @@
-#!/usr/bin/make -f
-
-#export DH_VERBOSE=1
-CFLAGS ?= $(shell dpkg-buildflags --get CFLAGS)
-LDFLAGS ?= $(shell dpkg-buildflags --get LDFLAGS)
-WITH_HTTP2 := $(shell printf \
-	"Source: nginx\nBuild-Depends: libssl-dev (>= 1.0.1)\n" | \
-	dpkg-checkbuilddeps - >/dev/null 2>&1 && \
-	echo "--with-http_v2_module")
-PKGS = nginx nginx-dbg \
-	nginx-module-xslt nginx-module-geoip nginx-module-image-filter \
-	nginx-module-perl nginx-module-njs
-COMMON_CONFIGURE_ARGS := \
-	--prefix=/etc/nginx \
-	--sbin-path=/usr/sbin/nginx \
-	--modules-path=/usr/lib/nginx/modules \
-	--conf-path=/etc/nginx/nginx.conf \
-	--error-log-path=/var/log/nginx/error.log \
-	--http-log-path=/var/log/nginx/access.log \
-	--pid-path=/var/run/nginx.pid \
-	--lock-path=/var/run/nginx.lock \
-	--http-client-body-temp-path=/var/cache/nginx/client_temp \
-	--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
-	--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
-	--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
-	--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
-	--user=nginx \
-	--group=nginx \
-	--with-http_ssl_module \
-	--with-http_realip_module \
-	--with-http_addition_module \
-	--with-http_sub_module \
-	--with-http_dav_module \
-	--with-http_flv_module \
-	--with-http_mp4_module \
-	--with-http_gunzip_module \
-	--with-http_gzip_static_module \
-	--with-http_random_index_module \
-	--with-http_secure_link_module \
-	--with-http_stub_status_module \
-	--with-http_auth_request_module \
-	--with-http_xslt_module=dynamic \
-	--with-http_image_filter_module=dynamic \
-	--with-http_geoip_module=dynamic \
-	--with-http_perl_module=dynamic \
-	--add-dynamic-module=debian/extra/njs-1c50334fbea6/nginx \
-	--with-threads \
-	--with-stream \
-	--with-stream_ssl_module \
-	--with-http_slice_module \
-	--with-mail \
-	--with-mail_ssl_module \
-	--with-file-aio \
-	--with-ipv6 \
-	$(WITH_HTTP2) \
-	--with-cc-opt="$(CFLAGS)" \
-	--with-ld-opt="$(LDFLAGS)"
-
-%:
-	dh $@ 
-
-override_dh_auto_configure: configure_debug
-
-override_dh_strip:
-	dh_strip --dbg-package=nginx-dbg
-
-override_dh_auto_build:
-	dh_auto_build
-	mv objs/nginx objs/nginx-debug
-	mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so
-	mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so
-	mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so
-	mv objs/ngx_http_perl_module.so objs/ngx_http_perl_module-debug.so
-	mv objs/src/http/modules/perl/blib/arch/auto/nginx/nginx.so objs/src/http/modules/perl/blib/arch/auto/nginx/nginx-debug.so
-	mv objs/ngx_http_js_module.so objs/ngx_http_js_module-debug.so
-	CFLAGS="" ./configure $(COMMON_CONFIGURE_ARGS)
-	dh_auto_build
-
-configure_debug:
-	CFLAGS="" ./configure $(COMMON_CONFIGURE_ARGS) \
-		--with-debug
-
-override_dh_auto_install:
-	sed -e 's/%%PROVIDES%%/nginx/g' \
-		-e 's/%%DEFAULTSTART%%/2 3 4 5/g' \
-		-e 's/%%DEFAULTSTOP%%/0 1 6/g' \
-		< debian/init.d.in > debian/init.d
-	dh_auto_install
-	mkdir -p debian/nginx/etc/init.d debian/nginx/etc/default \
-		debian/nginx/usr/lib/nginx/modules
-	sed -e 's/%%PROVIDES%%/nginx-debug/g' \
-		-e 's/%%DEFAULTSTART%%//g' \
-		-e 's/%%DEFAULTSTOP%%/0 1 2 3 4 5 6/g' \
-		< debian/init.d.in > debian/debug.init.d
-	/usr/bin/install -m 755 debian/debug.init.d \
-		debian/nginx/etc/init.d/nginx-debug
-	/usr/bin/install -m 644 debian/nginx-debug.default \
-		debian/nginx/etc/default/nginx-debug
-	/usr/bin/install -m 644 debian/nginx.conf debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/win-utf debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/koi-utf debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/koi-win debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/mime.types debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/scgi_params debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/fastcgi_params debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 conf/uwsgi_params debian/nginx/etc/nginx/
-	/usr/bin/install -m 644 html/index.html \
-		debian/nginx/usr/share/nginx/html/
-	/usr/bin/install -m 644 html/50x.html \
-		debian/nginx/usr/share/nginx/html/
-	/usr/bin/install -m 644 debian/nginx.vh.default.conf \
-		debian/nginx/etc/nginx/conf.d/default.conf
-	/usr/bin/install -m 755 objs/nginx  debian/nginx/usr/sbin/
-	/usr/bin/install -m 755 objs/nginx-debug  debian/nginx/usr/sbin/
-	cd debian/nginx/etc/nginx && /bin/ln -s \
-		../../usr/lib/nginx/modules modules && cd -
-
-override_dh_gencontrol:
-	for p in $(PKGS); do \
-		if [ -e debian/$$p.version ]; then \
-			dpkg-gencontrol -p$$p -ldebian/changelog -Tdebian/$$p.substvars -Pdebian/$$p -v`cat debian/$$p.version`~`lsb_release -cs`; \
-		else \
-			dpkg-gencontrol -p$$p -ldebian/changelog -Tdebian/$$p.substvars -Pdebian/$$p ; \
-		fi ; \
-	done
-
-override_dh_clean:
-	dh_clean
-	rm -f debian/*init.d
diff --git a/debian/source/lintian-overrides b/debian/source/lintian-overrides
new file mode 100644
index 0000000..c4bc670
--- /dev/null
+++ b/debian/source/lintian-overrides
@@ -0,0 +1,3 @@
+# this is just wrong for us
+nginx source: changelog-should-mention-nmu
+nginx source: source-nmu-has-incorrect-version-number
diff --git a/rpm/SOURCES/logrotate b/rpm/SOURCES/logrotate
index a94b400..24139f6 100644
--- a/rpm/SOURCES/logrotate
+++ b/rpm/SOURCES/logrotate
@@ -8,6 +8,8 @@
         create 640 nginx adm
         sharedscripts
         postrotate
-                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
+                if [ -f /var/run/nginx.pid ]; then
+                        kill -USR1 `cat /var/run/nginx.pid`
+                fi
         endscript
 }
diff --git a/rpm/SOURCES/nginx.suse.logrotate b/rpm/SOURCES/nginx.suse.logrotate
index 76737fe..988b3b2 100644
--- a/rpm/SOURCES/nginx.suse.logrotate
+++ b/rpm/SOURCES/nginx.suse.logrotate
@@ -8,6 +8,8 @@
         create 640 nginx trusted
         sharedscripts
         postrotate
-                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
+                if [ -f /var/run/nginx.pid ]; then
+                        kill -USR1 `cat /var/run/nginx.pid`
+                fi
         endscript
 }
diff --git a/rpm/SPECS/Makefile b/rpm/SPECS/Makefile
new file mode 100644
index 0000000..7ee5c73
--- /dev/null
+++ b/rpm/SPECS/Makefile
@@ -0,0 +1,392 @@
+SHELL=		/bin/bash
+
+BASE_VERSION=	1.10.1
+BASE_RELEASE=	1
+BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
+SRCPATH?=	../SOURCES
+
+MODULES=	geoip image-filter njs perl xslt
+
+MODULE_SUMMARY_geoip=		GeoIP dynamic modules
+MODULE_SUMMARY_image_filter=	image filter dynamic module
+MODULE_SUMMARY_njs=		nginScript dynamic modules
+MODULE_SUMMARY_perl=		Perl dynamic module
+MODULE_SUMMARY_xslt=		xslt dynamic module
+
+MODULE_VERSION_geoip=		$(BASE_VERSION)
+MODULE_RELEASE_geoip=		1
+MODULE_VERSION_image_filter=	$(BASE_VERSION)
+MODULE_RELEASE_image_filter=	1
+MODULE_SHAID_njs=		1c50334fbea6
+MODULE_VERSION_njs=		0.0.20160414.$(MODULE_SHAID_njs)
+MODULE_RELEASE_njs=		1
+MODULE_VERSION_perl=		$(BASE_VERSION)
+MODULE_RELEASE_perl=		1
+MODULE_VERSION_xslt=		$(BASE_VERSION)
+MODULE_RELEASE_xslt=		1
+
+MODULE_SOURCES_njs=		njs-$(MODULE_SHAID_njs).tar.gz
+
+MODULE_CONFARGS_geoip=		--with-http_geoip_module=dynamic \
+				--with-stream_geoip_module=dynamic
+MODULE_CONFARGS_image_filter=	--with-http_image_filter_module=dynamic
+MODULE_CONFARGS_njs=		--add-dynamic-module=njs-$(MODULE_SHAID_njs)/nginx
+MODULE_CONFARGS_perl=		--with-http_perl_module=dynamic
+MODULE_CONFARGS_xslt=		--with-http_xslt_module=dynamic
+
+# geoip
+
+define MODULE_DEFINITIONS_geoip
+%if 0%{?suse_version} == 1315
+BuildRequires: libGeoIP-devel
+Requires: libGeoIP1
+%else
+BuildRequires: GeoIP-devel
+Requires: GeoIP
+%endif
+endef
+export MODULE_DEFINITIONS_geoip
+
+define MODULE_POST_geoip
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_geoip) for nginx have been installed.
+To enable these modules, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_geoip_module.so;
+    load_module modules/ngx_stream_geoip_module.so;
+
+Please refer to the modules documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_geoip_module.html
+http://nginx.org/en/docs/stream/ngx_stream_geoip_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_geoip
+
+# image-filter
+
+define MODULE_DEFINITIONS_image_filter
+BuildRequires: gd-devel
+Requires: gd
+endef
+export MODULE_DEFINITIONS_image_filter
+
+define MODULE_POST_image_filter
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_image_filter) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_image_filter_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_image_filter
+
+# njs
+
+MODULE_VERSION_PREFIX_njs=$(BASE_VERSION).
+
+define MODULE_PREINSTALL_njs
+%{__install} -m644 %{bdir}/njs-$(MODULE_SHAID_njs)/README \
+    $$RPM_BUILD_ROOT%{_datadir}/doc/nginx-module-njs/
+endef
+export MODULE_PREINSTALL_njs
+
+define MODULE_POST_njs
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_njs) for nginx have been installed.
+To enable these modules, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_js_module.so;
+    load_module modules/ngx_stream_js_module.so;
+
+Please refer to the modules documentation for further details:
+/usr/share/doc/nginx-module-njs/README
+https://www.nginx.com/resources/wiki/nginScript/
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_njs
+
+# perl
+
+define MODULE_DEFINITIONS_perl
+%if (0%{?rhel} \&\& 0%{?rhel} == 5) || (0%{?suse_version} == 1315)
+BuildRequires: perl
+%else
+BuildRequires: perl-devel
+BuildRequires: perl-ExtUtils-Embed
+%endif
+Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $$version))
+endef
+export MODULE_DEFINITIONS_perl
+
+define MODULE_PREINSTALL_perl
+%{__make} DESTDIR=$$RPM_BUILD_ROOT INSTALLDIRS=vendor -f objs/Makefile install_perl_modules
+find %{buildroot} -type f -name .packlist -exec rm -f '{}' \\;
+find %{buildroot} -type f -name perllocal.pod -exec rm -f '{}' \\;
+find %{buildroot} -type f -empty -exec rm -f '{}' \\;
+find %{buildroot} -type f -iname '*.so' -exec chmod 0755 '{}' \\;
+endef
+export MODULE_PREINSTALL_perl
+
+define MODULE_FILES_perl
+%dir %{perl_vendorarch}/auto/nginx
+%{perl_vendorarch}/nginx.pm
+%{perl_vendorarch}/auto/nginx/nginx.so
+%{perl_vendorarch}/auto/nginx/nginx-debug.so
+%{_mandir}/man3/nginx.3pm*
+endef
+export MODULE_FILES_perl
+
+define MODULE_POST_perl
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_perl) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_perl_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_perl_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_perl
+
+# xslt
+
+define MODULE_DEFINITIONS_xslt
+BuildRequires: libxslt-devel
+Requires: libxslt
+endef
+export MODULE_DEFINITIONS_xslt
+
+define MODULE_POST_xslt
+cat <<BANNER
+----------------------------------------------------------------------
+
+The $(MODULE_SUMMARY_xslt) for nginx has been installed.
+To enable this module, add the following to /etc/nginx/nginx.conf
+and reload nginx:
+
+    load_module modules/ngx_http_xslt_filter_module.so;
+
+Please refer to the module documentation for further details:
+http://nginx.org/en/docs/http/ngx_http_xslt_module.html
+
+----------------------------------------------------------------------
+BANNER
+endef
+export MODULE_POST_xslt
+
+
+BASE_CONFIGURE_ARGS=\
+	--prefix=%{_sysconfdir}/nginx \
+	--sbin-path=%{_sbindir}/nginx \
+	--modules-path=%{_libdir}/nginx/modules \
+	--conf-path=%{_sysconfdir}/nginx/nginx.conf \
+	--error-log-path=%{_localstatedir}/log/nginx/error.log \
+	--http-log-path=%{_localstatedir}/log/nginx/access.log \
+	--pid-path=%{_localstatedir}/run/nginx.pid \
+	--lock-path=%{_localstatedir}/run/nginx.lock \
+	--http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
+	--http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
+	--http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
+	--http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
+	--http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
+	--user=%{nginx_user} \
+	--group=%{nginx_group} \
+	--with-file-aio \
+	--with-threads \
+	--with-ipv6 \
+	--with-http_addition_module \
+	--with-http_auth_request_module \
+	--with-http_dav_module \
+	--with-http_flv_module \
+	--with-http_gunzip_module \
+	--with-http_gzip_static_module \
+	--with-http_mp4_module \
+	--with-http_random_index_module \
+	--with-http_realip_module \
+	--with-http_secure_link_module \
+	--with-http_slice_module \
+	--with-http_ssl_module \
+	--with-http_stub_status_module \
+	--with-http_sub_module \
+	--with-http_v2_module \
+	--with-mail \
+	--with-mail_ssl_module \
+	--with-stream \
+	--with-stream_ssl_module
+
+export CR=\\n
+
+modname = $(shell echo $1 | cut -c 14- | cut -d '.' -f 1 | tr '-' '_')
+
+default:
+	@echo "valid targets: all base $(addprefix module-, $(MODULES)) test test-debug"
+
+all:	base modules
+	@echo "===> all done"
+
+modules:	$(addprefix module-, $(MODULES))
+
+specs:	nginx.spec $(addsuffix .spec, $(addprefix nginx-module-, $(MODULES)))
+
+$(SRCPATH)/$(BASE_SRC):
+	@cd $(SRCPATH) && wget http://nginx.org/download/$(BASE_SRC)
+
+base:	nginx.spec $(SRCPATH)/$(BASE_SRC)
+	@echo "===> Building base package"
+	@$(SHELL) -c "time -p rpmbuild -ba nginx.spec"
+	@ln -s ../BUILD/nginx-$(BASE_VERSION)/objs base
+
+nginx.spec:
+	@echo "===> Creating $@"
+	@{ \
+	set -e ; \
+	cat nginx.spec.in | sed \
+		-e 's#%%MAIN_VERSION%%#$(BASE_VERSION)#g' \
+		-e 's#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g' \
+		-e 's#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g' \
+		> nginx.spec ; \
+	}
+
+module-%: nginx-module-%.spec $(SRCPATH)/$(BASE_SRC)
+	@echo "===> Building nginx-$@ package" ; \
+	$(SHELL) -c "time -p rpmbuild -ba nginx-$@.spec" ; \
+	ln -s ../BUILD/nginx-$@-$(BASE_VERSION)/objs $@
+
+nginx-module-%.spec:
+	@echo "===> Creating $@"
+	@{ \
+	set -e ; \
+	i=100 ; \
+	sources= ; \
+	prepsources= ; \
+	for src in $(MODULE_SOURCES_$(call modname, $@)); do \
+		s="`printf "Source%d: %s\n" $${i} $${src}`" ; \
+		sources="$${sources}\n$${s}" ; \
+		s="`printf "tar zxf %%{SOURCE%d\}" $${i}`" ; \
+		prepsources="$${prepsources}\n$${s}" ; \
+		i=$$(($${i}+1)) ; \
+	done ; \
+	i=100 ; \
+	patches= ; \
+	preppatches= ; \
+	for src in $(MODULE_PATCHES_$(call modname, $@)); do \
+		s="`printf "Patch%d: %s\n" $${i} $${src}`" ; \
+		patches="$${patches}\n$${s}" ; \
+		s="`printf "%%patch%d -p1" $${i}`" ; \
+		preppatches="$${preppatches}\n$${s}" ; \
+		i=$$(($${i}+1)) ; \
+	done ; \
+	module_copyright=`echo $@ | sed -e "s#.spec#.copyright#"` ; \
+	if [ -f ../SOURCES/$${module_copyright} ]; then \
+		copyright_source=$${module_copyright} ; \
+	else \
+		copyright_source=COPYRIGHT ; \
+	fi ; \
+	module_changelog=`echo $@ | sed -e "s#.spec#.changelog.in#"` ; \
+	if [ -f $${module_changelog} ]; then \
+		changelog_file=$${module_changelog} ; \
+	else \
+		changelog_file=nginx-module.changelog.in ; \
+	fi ; \
+	definitions=`echo "$$MODULE_DEFINITIONS_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	prebuild=`echo "$$MODULE_PREBUILD_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	preinstall=`echo "$$MODULE_PREINSTALL_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	files=`echo "$$MODULE_FILES_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	post=`echo "$$MODULE_POST_$(call modname, $@)" | sed -e ':a' -e 'N' -e '$$!ba' -e "s/\n/\$$CR/g"` ; \
+	cat nginx-module.spec.in | sed \
+		-e "s#%%NAME%%#$(shell echo $@ | cut -d '.' -f 1)#g" \
+		-e "s#%%SUMMARY%%#nginx $(MODULE_SUMMARY_$(call modname, $@))#g" \
+		-e "s#%%SHORT_SUMMARY%%#$(MODULE_SUMMARY_$(call modname, $@))#g" \
+		-e "s#%%MAIN_VERSION%%#$(BASE_VERSION)#g" \
+		-e "s#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g" \
+		-e "s#%%VERSION_PREFIX%%#$(MODULE_VERSION_PREFIX_$(call modname, $@))#g" \
+		-e "s#%%VERSION%%#$(MODULE_VERSION_$(call modname, $@))#g" \
+		-e "s#%%RELEASE%%#$(MODULE_RELEASE_$(call modname, $@))#g" \
+		-e "s#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g" \
+		-e "s#%%MODULE_CONFIGURE_ARGS%%#$(MODULE_CONFARGS_$(call modname, $@))#g" \
+		-e "s#%%COPYRIGHT_SOURCE%%#$${copyright_source}#g" \
+		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
+		-e "s#%%MODULE_PATCHES%%#$${patches}#g" \
+		-e "s#%%MODULE_PREP_SOURCES%%#$${prepsources}#g" \
+		-e "s#%%MODULE_PREP_PATCHES%%#$${preppatches}#g" \
+		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
+		-e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
+		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
+		-e "s#%%MODULE_FILES%%#$${files}#g" \
+		-e "s#%%MODULE_POST%%#$${post}#g" \
+		> $@.tmp && \
+	cat $${changelog_file} | grep -v "^#" >> $@.tmp && \
+	mv $@.tmp $@ ; \
+	}
+
+nginx-tests:
+	@{ \
+	if [ -d "../nginx-tests" ]; then \
+		echo "===> Copying tests from ../nginx-tests" ; \
+		cp -rP ../nginx-tests nginx-tests ; \
+	else \
+		echo "===> Cloning tests" ; \
+		hg clone http://hg.nginx.org/nginx-tests ; \
+	fi ; \
+	}
+
+test: base nginx-tests
+	@echo "===> Running tests with regular binary/modules"
+	@{ \
+	pwd=`pwd` ; \
+	globals= ; \
+	for so in `find module-*/ -maxdepth 1 -type f -name "*module.so"`; do \
+		globals="$$globals load_module $$pwd/$$so;" ; \
+	done ; \
+	if [ -d $$pwd/module-perl ]; then \
+		globals="$$globals env PERL5LIB=$$pwd/module-perl/src/http/modules/perl:$$pwd/module-perl/src/http/modules/perl/blib/arch;" ; \
+	fi ; \
+	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx TEST_NGINX_GLOBALS="$$globals" prove . ; \
+	}
+
+test-debug: base nginx-tests
+	@echo "===> Running tests with debug binary/modules"
+	@{ \
+	pwd=`pwd` ; \
+	globals= ; \
+	for so in `find module-*/ -maxdepth 1 -type f -name "*module-debug.so"`; do \
+		globals="$$globals load_module $$pwd/$$so;" ; \
+	done ; \
+	if [ -d $$pwd/module-perl ]; then \
+		globals="$$globals env PERL5LIB=$$pwd/module-perl/src/http/modules/perl:$$pwd/module-perl/src/http/modules/perl/blib/arch;" ; \
+	fi ; \
+	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx-debug TEST_NGINX_GLOBALS="$$globals" prove . ; \
+	}
+
+clean:
+	@rm -f base module-*
+	@rm -f nginx.spec nginx-module-*.spec
+	@rm -rf nginx-tests
+
+.PHONY:	default all modules specs test test-debug clean
+
+.SECONDARY:
diff --git a/rpm/SPECS/nginx-module.changelog.in b/rpm/SPECS/nginx-module.changelog.in
new file mode 100644
index 0000000..2bdfb08
--- /dev/null
+++ b/rpm/SPECS/nginx-module.changelog.in
@@ -0,0 +1,4 @@
+# default changelog for module packages
+#
+* Tue May 31 2016 Konstantin Pavlov <thresh@nginx.com>
+- base version updated to 1.10.1
diff --git a/rpm/SPECS/nginx-module.spec.in b/rpm/SPECS/nginx-module.spec.in
new file mode 100644
index 0000000..b6a278d
--- /dev/null
+++ b/rpm/SPECS/nginx-module.spec.in
@@ -0,0 +1,111 @@
+#
+%define nginx_user nginx
+%define nginx_group nginx
+
+%%MODULE_DEFINITIONS%%
+
+%if 0%{?rhel} || 0%{?amzn}
+%define _group System Environment/Daemons
+BuildRequires: openssl-devel
+%endif
+
+%if 0%{?suse_version} == 1315
+%define _group Productivity/Networking/Web/Servers
+BuildRequires: libopenssl-devel
+%endif
+
+%if 0%{?rhel} == 7
+%define epoch 1
+Epoch: %{epoch}
+%endif
+
+%define main_version %%MAIN_VERSION%%
+%define main_release %%MAIN_RELEASE%%%{?dist}.ngx
+
+%define bdir %{_builddir}/%{name}-%{main_version}
+
+Summary: %%SUMMARY%%
+Name: %%NAME%%
+Version: %%VERSION_PREFIX%%%%VERSION%%
+Release: %%RELEASE%%%{?dist}.ngx
+Vendor: Nginx, Inc.
+URL: http://nginx.org/
+Group: %{_group}
+
+Source0: http://nginx.org/download/nginx-%{main_version}.tar.gz
+Source1: %%COPYRIGHT_SOURCE%%
+%%MODULE_SOURCES%%
+
+%%MODULE_PATCHES%%
+
+License: 2-clause BSD-like license
+
+BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{main_release}-root
+BuildRequires: zlib-devel
+BuildRequires: pcre-devel
+Requires: nginx == %{?epoch:%{epoch}:}%%MAIN_VERSION%%-%%MAIN_RELEASE%%%{?dist}.ngx
+
+%description
+nginx %%SHORT_SUMMARY%%.
+
+%if 0%{?suse_version} || 0%{?amzn}
+%debug_package
+%endif
+
+%define WITH_CC_OPT $(echo %{optflags} $(pcre-config --cflags))
+
+%define BASE_CONFIGURE_ARGS $(echo "%%BASE_CONFIGURE_ARGS%%")
+%define MODULE_CONFIGURE_ARGS $(echo "%%MODULE_CONFIGURE_ARGS%%")
+
+%prep
+%setup -qcTn %{name}-%{main_version}
+tar --strip-components=1 -zxf %{SOURCE0}
+%%MODULE_PREP_SOURCES%%
+%%MODULE_PREP_PATCHES%%
+
+%build
+%%MODULE_PREBUILD%%
+cd %{bdir}
+./configure %{BASE_CONFIGURE_ARGS} %{MODULE_CONFIGURE_ARGS} \
+	--with-cc-opt="%{WITH_CC_OPT}" \
+	--with-debug
+make %{?_smp_mflags} modules
+for so in `find %{bdir}/objs/ -type f -name "*.so"`; do
+debugso=`echo $so | sed -e "s|.so|-debug.so|"`
+mv $so $debugso
+done
+./configure %{BASE_CONFIGURE_ARGS} %{MODULE_CONFIGURE_ARGS} \
+	--with-cc-opt="%{WITH_CC_OPT}"
+make %{?_smp_mflags} modules
+
+%install
+cd %{bdir}
+%{__rm} -rf $RPM_BUILD_ROOT
+%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/doc/%%NAME%%
+%{__install} -m 644 -p %{SOURCE1} \
+    $RPM_BUILD_ROOT%{_datadir}/doc/%%NAME%%/
+
+%%MODULE_PREINSTALL%%
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_libdir}/nginx/modules
+for so in `find %{bdir}/objs/ -maxdepth 1 -type f -name "*.so"`; do
+%{__install} -m755 $so \
+   $RPM_BUILD_ROOT%{_libdir}/nginx/modules/
+done
+
+%clean
+%{__rm} -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+%{_libdir}/nginx/modules/*
+%dir %{_datadir}/doc/%%NAME%%
+%{_datadir}/doc/%%NAME%%/*
+%%MODULE_FILES%%
+
+%post
+if [ $1 -eq 1 ]; then
+%%MODULE_POST%%
+fi
+
+%changelog
diff --git a/rpm/SPECS/nginx.spec b/rpm/SPECS/nginx.spec
deleted file mode 100644
index 8bec863..0000000
--- a/rpm/SPECS/nginx.spec
+++ /dev/null
@@ -1,790 +0,0 @@
-#
-%define nginx_home %{_localstatedir}/cache/nginx
-%define nginx_user nginx
-%define nginx_group nginx
-%define nginx_loggroup adm
-
-# distribution specific definitions
-%define use_systemd (0%{?fedora} && 0%{?fedora} >= 18) || (0%{?rhel} && 0%{?rhel} >= 7) || (0%{?suse_version} == 1315)
-
-%if 0%{?rhel}  == 5
-%define _group System Environment/Daemons
-Requires(pre): shadow-utils
-Requires: initscripts >= 8.36
-Requires(post): chkconfig
-Requires: openssl
-BuildRequires: openssl-devel
-BuildRequires: perl
-BuildRequires: GeoIP-devel
-%endif
-
-%if 0%{?rhel}  == 6
-%define _group System Environment/Daemons
-%define with_http2 1
-Requires(pre): shadow-utils
-Requires: initscripts >= 8.36
-Requires(post): chkconfig
-Requires: openssl >= 1.0.1
-BuildRequires: openssl-devel >= 1.0.1
-BuildRequires: perl-devel
-BuildRequires: perl-ExtUtils-Embed
-BuildRequires: GeoIP-devel
-%endif
-
-%if 0%{?rhel}  == 7
-%define _group System Environment/Daemons
-%define epoch 1
-%define with_http2 1
-Epoch: %{epoch}
-Requires(pre): shadow-utils
-Requires: systemd
-Requires: openssl >= 1.0.1
-BuildRequires: systemd
-BuildRequires: openssl-devel >= 1.0.1
-BuildRequires: perl-devel
-BuildRequires: perl-ExtUtils-Embed
-BuildRequires: GeoIP-devel
-%endif
-
-%if 0%{?suse_version} == 1315
-%define _group Productivity/Networking/Web/Servers
-%define with_http2 1
-%define nginx_loggroup trusted
-Requires(pre): shadow
-Requires: systemd
-BuildRequires: libopenssl-devel
-BuildRequires: systemd
-BuildRequires: perl
-BuildRequires: libGeoIP-devel
-%endif
-
-# end of distribution specific definitions
-
-%define main_version                 1.10.1
-%define main_release                 1%{?dist}.ngx
-%define module_xslt_version          %{main_version}
-%define module_xslt_release          1%{?dist}.ngx
-%define module_geoip_version         %{main_version}
-%define module_geoip_release         1%{?dist}.ngx
-%define module_image_filter_version  %{main_version}
-%define module_image_filter_release  1%{?dist}.ngx
-%define module_perl_version          %{main_version}
-%define module_perl_release          1%{?dist}.ngx
-%define module_njs_shaid             1c50334fbea6
-%define module_njs_version           %{main_version}.0.0.20160414.%{module_njs_shaid}
-%define module_njs_release           1%{?dist}.ngx
-
-%define bdir %{_builddir}/%{name}-%{main_version}
-
-%define WITH_CC_OPT $(echo %{optflags} $(pcre-config --cflags))
-
-%define COMMON_CONFIGURE_ARGS $(echo "\
-        --prefix=%{_sysconfdir}/nginx \
-        --sbin-path=%{_sbindir}/nginx \
-        --modules-path=%{_libdir}/nginx/modules \
-        --conf-path=%{_sysconfdir}/nginx/nginx.conf \
-        --error-log-path=%{_localstatedir}/log/nginx/error.log \
-        --http-log-path=%{_localstatedir}/log/nginx/access.log \
-        --pid-path=%{_localstatedir}/run/nginx.pid \
-        --lock-path=%{_localstatedir}/run/nginx.lock \
-        --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
-        --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
-        --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
-        --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
-        --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
-        --user=%{nginx_user} \
-        --group=%{nginx_group} \
-        --with-http_ssl_module \
-        --with-http_realip_module \
-        --with-http_addition_module \
-        --with-http_sub_module \
-        --with-http_dav_module \
-        --with-http_flv_module \
-        --with-http_mp4_module \
-        --with-http_gunzip_module \
-        --with-http_gzip_static_module \
-        --with-http_random_index_module \
-        --with-http_secure_link_module \
-        --with-http_stub_status_module \
-        --with-http_auth_request_module \
-        --with-http_xslt_module=dynamic \
-        --with-http_image_filter_module=dynamic \
-        --with-http_geoip_module=dynamic \
-        --with-http_perl_module=dynamic \
-        --add-dynamic-module=njs-%{module_njs_shaid}/nginx \
-        --with-threads \
-        --with-stream \
-        --with-stream_ssl_module \
-        --with-http_slice_module \
-        --with-mail \
-        --with-mail_ssl_module \
-        --with-file-aio \
-        --with-ipv6 \
-        %{?with_http2:--with-http_v2_module}")
-
-Summary: High performance web server
-Name: nginx
-Version: %{main_version}
-Release: %{main_release}
-Vendor: Nginx, Inc.
-URL: http://nginx.org/
-Group: %{_group}
-
-Source0: http://nginx.org/download/%{name}-%{version}.tar.gz
-Source1: logrotate
-Source2: nginx.init.in
-Source3: nginx.sysconf
-Source4: nginx.conf
-Source5: nginx.vh.default.conf
-Source7: nginx-debug.sysconf
-Source8: nginx.service
-Source9: nginx.upgrade.sh
-Source10: nginx.suse.logrotate
-Source11: nginx-debug.service
-Source12: COPYRIGHT
-Source13: njs-%{module_njs_shaid}.tar.gz
-
-License: 2-clause BSD-like license
-
-BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{main_release}-root
-BuildRequires: zlib-devel
-BuildRequires: pcre-devel
-BuildRequires: libxslt-devel
-BuildRequires: gd-devel
-
-Provides: webserver
-
-%description
-nginx [engine x] is an HTTP and reverse proxy server, as well as
-a mail proxy server.
-
-%if 0%{?suse_version} == 1315
-%debug_package
-%endif
-
-%package module-xslt
-Version: %{module_xslt_version}
-Release: %{module_xslt_release}
-Group: %{_group}
-Requires: nginx = %{?epoch:%{epoch}:}%{main_version}-%{main_release}
-Summary: nginx xslt module
-%description module-xslt
-Dynamic xslt module for nginx.
-
-%package module-image-filter
-Version: %{module_image_filter_version}
-Release: %{module_image_filter_release}
-Group: %{_group}
-Requires: nginx = %{?epoch:%{epoch}:}%{main_version}-%{main_release}
-Summary: nginx image filter module
-%description module-image-filter
-Dynamic image filter module for nginx.
-
-%package module-geoip
-Version: %{module_geoip_version}
-Release: %{module_geoip_release}
-Group: %{_group}
-Requires: nginx = %{?epoch:%{epoch}:}%{main_version}-%{main_release}
-Summary: nginx geoip module
-%description module-geoip
-Dynamic geoip module for nginx.
-
-%package module-perl
-Version: %{module_perl_version}
-Release: %{module_perl_release}
-Group: %{_group}
-Requires: nginx = %{?epoch:%{epoch}:}%{main_version}-%{main_release}
-Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
-Summary: nginx perl module
-%description module-perl
-Dynamic perl module for nginx.
-
-%package module-njs
-Version: %{module_njs_version}
-Release: %{module_njs_release}
-Group: %{_group}
-Requires: nginx = %{?epoch:%{epoch}:}%{main_version}-%{main_release}
-Summary: nginx nJScript module
-%description module-njs
-Dynamic nJScript module for nginx.
-
-%prep
-%setup -q
-tar xvzf %SOURCE13
-cp %{SOURCE2} .
-sed -e 's|%%DEFAULTSTART%%|2 3 4 5|g' -e 's|%%DEFAULTSTOP%%|0 1 6|g' \
-    -e 's|%%PROVIDES%%|nginx|g' < %{SOURCE2} > nginx.init
-sed -e 's|%%DEFAULTSTART%%||g' -e 's|%%DEFAULTSTOP%%|0 1 2 3 4 5 6|g' \
-    -e 's|%%PROVIDES%%|nginx-debug|g' < %{SOURCE2} > nginx-debug.init
-
-%build
-./configure %{COMMON_CONFIGURE_ARGS} \
-    --with-cc-opt="%{WITH_CC_OPT}" \
-    --with-debug
-make %{?_smp_mflags}
-%{__mv} %{bdir}/objs/nginx \
-    %{bdir}/objs/nginx-debug
-%{__mv} %{bdir}/objs/ngx_http_xslt_filter_module.so \
-    %{bdir}/objs/ngx_http_xslt_filter_module-debug.so
-%{__mv} %{bdir}/objs/ngx_http_image_filter_module.so \
-    %{bdir}/objs/ngx_http_image_filter_module-debug.so
-%{__mv} %{bdir}/objs/ngx_http_geoip_module.so \
-    %{bdir}/objs/ngx_http_geoip_module-debug.so
-%{__mv} %{bdir}/objs/ngx_http_perl_module.so \
-    %{bdir}/objs/ngx_http_perl_module-debug.so
-%{__mv} %{bdir}/objs/src/http/modules/perl/blib/arch/auto/nginx/nginx.so \
-    %{bdir}/objs/src/http/modules/perl/blib/arch/auto/nginx/nginx-debug.so
-%{__mv} %{bdir}/objs/ngx_http_js_module.so \
-    %{bdir}/objs/ngx_http_js_module-debug.so
-./configure %{COMMON_CONFIGURE_ARGS} \
-    --with-cc-opt="%{WITH_CC_OPT}"
-make %{?_smp_mflags}
-
-%install
-%{__rm} -rf $RPM_BUILD_ROOT
-%{__make} DESTDIR=$RPM_BUILD_ROOT INSTALLDIRS=vendor install
-
-find %{buildroot} -type f -name .packlist -exec rm -f '{}' \;
-find %{buildroot} -type f -name perllocal.pod -exec rm -f '{}' \;
-find %{buildroot} -type f -empty -exec rm -f '{}' \;
-find %{buildroot} -type f -name nginx.so -exec chmod u+w '{}' \;
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/nginx
-%{__mv} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/html $RPM_BUILD_ROOT%{_datadir}/nginx/
-
-%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default
-%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/fastcgi.conf
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx
-%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx
-%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_libdir}/nginx/modules
-cd $RPM_BUILD_ROOT%{_sysconfdir}/nginx && \
-    %{__ln_s} ../..%{_libdir}/nginx/modules modules && cd -
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/doc/%{name}-%{main_version}
-%{__install} -m 644 -p %{SOURCE12} \
-    $RPM_BUILD_ROOT%{_datadir}/doc/%{name}-%{main_version}/
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d
-%{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
-%{__install} -m 644 -p %{SOURCE4} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
-%{__install} -m 644 -p %{SOURCE5} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/default.conf
-
-%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
-%{__install} -m 644 -p %{SOURCE3} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx
-%{__install} -m 644 -p %{SOURCE7} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx-debug
-
-%if %{use_systemd}
-# install systemd-specific files
-%{__mkdir} -p $RPM_BUILD_ROOT%{_unitdir}
-%{__install} -m644 %SOURCE8 \
-    $RPM_BUILD_ROOT%{_unitdir}/nginx.service
-%{__install} -m644 %SOURCE11 \
-    $RPM_BUILD_ROOT%{_unitdir}/nginx-debug.service
-%{__mkdir} -p $RPM_BUILD_ROOT%{_libexecdir}/initscripts/legacy-actions/nginx
-%{__install} -m755 %SOURCE9 \
-    $RPM_BUILD_ROOT%{_libexecdir}/initscripts/legacy-actions/nginx/upgrade
-%else
-# install SYSV init stuff
-%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
-%{__install} -m755 nginx.init $RPM_BUILD_ROOT%{_initrddir}/nginx
-%{__install} -m755 nginx-debug.init $RPM_BUILD_ROOT%{_initrddir}/nginx-debug
-%endif
-
-# install log rotation stuff
-%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
-%if 0%{?suse_version}
-%{__install} -m 644 -p %{SOURCE10} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx
-%else
-%{__install} -m 644 -p %{SOURCE1} \
-    $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx
-%endif
-
-%{__install} -m755 %{bdir}/objs/nginx-debug \
-    $RPM_BUILD_ROOT%{_sbindir}/nginx-debug
-
-%{__install} -m644 %{bdir}/objs/ngx_http_xslt_filter_module-debug.so \
-    $RPM_BUILD_ROOT%{_libdir}/nginx/modules/ngx_http_xslt_filter_module-debug.so
-%{__install} -m644 %{bdir}/objs/ngx_http_image_filter_module-debug.so \
-    $RPM_BUILD_ROOT%{_libdir}/nginx/modules/ngx_http_image_filter_module-debug.so
-%{__install} -m644 %{bdir}/objs/ngx_http_geoip_module-debug.so \
-    $RPM_BUILD_ROOT%{_libdir}/nginx/modules/ngx_http_geoip_module-debug.so
-%{__install} -m644 %{bdir}/objs/ngx_http_perl_module-debug.so \
-    $RPM_BUILD_ROOT%{_libdir}/nginx/modules/ngx_http_perl_module-debug.so
-%{__mkdir} -p $RPM_BUILD_ROOT%{perl_vendorarch}/auto/nginx
-%{__install} -m644 %{bdir}/objs/src/http/modules/perl/blib/arch/auto/nginx/nginx-debug.so \
-    $RPM_BUILD_ROOT%{perl_vendorarch}/auto/nginx/nginx-debug.so
-%{__install} -m644 %{bdir}/objs/ngx_http_js_module-debug.so \
-    $RPM_BUILD_ROOT%{_libdir}/nginx/modules/ngx_http_js_module-debug.so
-
-%clean
-%{__rm} -rf $RPM_BUILD_ROOT
-
-%files
-%defattr(-,root,root)
-
-%{_sbindir}/nginx
-%{_sbindir}/nginx-debug
-
-%dir %{_sysconfdir}/nginx
-%dir %{_sysconfdir}/nginx/conf.d
-%{_sysconfdir}/nginx/modules
-
-%config(noreplace) %{_sysconfdir}/nginx/nginx.conf
-%config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf
-%config(noreplace) %{_sysconfdir}/nginx/mime.types
-%config(noreplace) %{_sysconfdir}/nginx/fastcgi_params
-%config(noreplace) %{_sysconfdir}/nginx/scgi_params
-%config(noreplace) %{_sysconfdir}/nginx/uwsgi_params
-%config(noreplace) %{_sysconfdir}/nginx/koi-utf
-%config(noreplace) %{_sysconfdir}/nginx/koi-win
-%config(noreplace) %{_sysconfdir}/nginx/win-utf
-
-%config(noreplace) %{_sysconfdir}/logrotate.d/nginx
-%config(noreplace) %{_sysconfdir}/sysconfig/nginx
-%config(noreplace) %{_sysconfdir}/sysconfig/nginx-debug
-%if %{use_systemd}
-%{_unitdir}/nginx.service
-%{_unitdir}/nginx-debug.service
-%dir %{_libexecdir}/initscripts/legacy-actions/nginx
-%{_libexecdir}/initscripts/legacy-actions/nginx/*
-%else
-%{_initrddir}/nginx
-%{_initrddir}/nginx-debug
-%endif
-
-%attr(0755,root,root) %dir %{_libdir}/nginx
-%attr(0755,root,root) %dir %{_libdir}/nginx/modules
-%dir %{_datadir}/nginx
-%dir %{_datadir}/nginx/html
-%{_datadir}/nginx/html/*
-
-%attr(0755,root,root) %dir %{_localstatedir}/cache/nginx
-%attr(0755,root,root) %dir %{_localstatedir}/log/nginx
-
-%dir %{_datadir}/doc/%{name}-%{main_version}
-%doc %{_datadir}/doc/%{name}-%{main_version}/COPYRIGHT
-
-%files module-xslt
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_xslt_filter_module.so
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_xslt_filter_module-debug.so
-
-%files module-image-filter
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_image_filter_module.so
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_image_filter_module-debug.so
-
-%files module-geoip
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_geoip_module.so
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_geoip_module-debug.so
-
-%files module-perl
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_perl_module.so
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_perl_module-debug.so
-%dir %{perl_vendorarch}/auto/nginx
-%{perl_vendorarch}/nginx.pm
-%{perl_vendorarch}/auto/nginx/nginx.so
-%{perl_vendorarch}/auto/nginx/nginx-debug.so
-%{_mandir}/man3/nginx.3pm*
-
-%files module-njs
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_js_module.so
-%attr(0644,root,root) %{_libdir}/nginx/modules/ngx_http_js_module-debug.so
-
-%pre
-# Add the "nginx" user
-getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group}
-getent passwd %{nginx_user} >/dev/null || \
-    useradd -r -g %{nginx_group} -s /sbin/nologin \
-    -d %{nginx_home} -c "nginx user"  %{nginx_user}
-exit 0
-
-%post
-# Register the nginx service
-if [ $1 -eq 1 ]; then
-%if %{use_systemd}
-    /usr/bin/systemctl preset nginx.service >/dev/null 2>&1 ||:
-    /usr/bin/systemctl preset nginx-debug.service >/dev/null 2>&1 ||:
-%else
-    /sbin/chkconfig --add nginx
-    /sbin/chkconfig --add nginx-debug
-%endif
-    # print site info
-    cat <<BANNER
-----------------------------------------------------------------------
-
-Thanks for using nginx!
-
-Please find the official documentation for nginx here:
-* http://nginx.org/en/docs/
-
-Commercial subscriptions for nginx are available on:
-* http://nginx.com/products/
-
-----------------------------------------------------------------------
-BANNER
-
-    # Touch and set permisions on default log files on installation
-
-    if [ -d %{_localstatedir}/log/nginx ]; then
-        if [ ! -e %{_localstatedir}/log/nginx/access.log ]; then
-            touch %{_localstatedir}/log/nginx/access.log
-            %{__chmod} 640 %{_localstatedir}/log/nginx/access.log
-            %{__chown} nginx:%{nginx_loggroup} %{_localstatedir}/log/nginx/access.log
-        fi
-
-        if [ ! -e %{_localstatedir}/log/nginx/error.log ]; then
-            touch %{_localstatedir}/log/nginx/error.log
-            %{__chmod} 640 %{_localstatedir}/log/nginx/error.log
-            %{__chown} nginx:%{nginx_loggroup} %{_localstatedir}/log/nginx/error.log
-        fi
-    fi
-fi
-
-%post module-xslt
-if [ $1 -eq 1 ]; then
-    cat <<BANNER
-----------------------------------------------------------------------
-
-The XSLT dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_xslt_filter_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_xslt_module.html
-
-----------------------------------------------------------------------
-BANNER
-fi
-
-%post module-geoip
-if [ $1 -eq 1 ]; then
-    cat <<BANNER
-----------------------------------------------------------------------
-
-The GeoIP dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_geoip_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_geoip_module.html
-
-----------------------------------------------------------------------
-BANNER
-fi
-
-%post module-image-filter
-if [ $1 -eq 1 ]; then
-    cat <<BANNER
-----------------------------------------------------------------------
-
-The image filter dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_image_filter_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_image_filter_module.html
-
-----------------------------------------------------------------------
-BANNER
-fi
-
-%post module-perl
-if [ $1 -eq 1 ]; then
-    cat <<BANNER
-----------------------------------------------------------------------
-
-The perl dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_perl_module.so;
-
-Please refer to the module documentation for further details:
-http://nginx.org/en/docs/http/ngx_http_perl_module.html
-
-----------------------------------------------------------------------
-BANNER
-fi
-
-%post module-njs
-if [ $1 -eq 1 ]; then
-    cat <<BANNER
-----------------------------------------------------------------------
-
-The nJScript dynamic module for nginx has been installed.
-To enable this module, add the following to /etc/nginx/nginx.conf
-and reload nginx:
-
-    load_module modules/ngx_http_js_module.so;
-
-Please refer to the module documentation for further details:
-https://www.nginx.com/resources/wiki/nginScript/
-
-----------------------------------------------------------------------
-BANNER
-fi
-
-%preun
-if [ $1 -eq 0 ]; then
-%if %use_systemd
-    /usr/bin/systemctl --no-reload disable nginx.service >/dev/null 2>&1 ||:
-    /usr/bin/systemctl stop nginx.service >/dev/null 2>&1 ||:
-%else
-    /sbin/service nginx stop > /dev/null 2>&1
-    /sbin/chkconfig --del nginx
-    /sbin/chkconfig --del nginx-debug
-%endif
-fi
-
-%postun
-%if %use_systemd
-/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:
-%endif
-if [ $1 -ge 1 ]; then
-    /sbin/service nginx status  >/dev/null 2>&1 || exit 0
-    /sbin/service nginx upgrade >/dev/null 2>&1 || echo \
-        "Binary upgrade failed, please check nginx's error.log"
-fi
-
-%changelog
-* Tue May 31 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.10.1
-
-* Tue Apr 26 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.10.0
-
-* Tue Apr 19 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.15
-- njs updated to 1c50334fbea6.
-
-* Tue Apr 04 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.14
-
-* Tue Mar 29 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.13
-- Added perl and nJScript dynamic modules
-- Fixed Requires section for dynamic modules on CentOS7/RHEL7
-
-* Wed Feb 24 2016 Sergey Budnevitch <sb@nginx.com>
-- common configure args are now in macros
-- xslt, image-filter and geoip dynamic modules added
-- 1.9.12
-
-* Tue Feb  9 2016 Sergey Budnevitch <sb@nginx.com>
-- dynamic modules path and symlink in %{_sysconfdir}/nginx added
-- 1.9.11
-
-* Tue Jan 26 2016 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.10
-
-* Wed Dec  9 2015 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.9
-
-* Tue Dec  8 2015 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.8
-- http_slice module enabled
-
-* Tue Nov 17 2015 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.7
-
-* Tue Oct 27 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.9.6
-
-* Tue Sep 22 2015 Andrei Belov <defan@nginx.com>
-- 1.9.5
-- http_spdy module replaced with http_v2 module
-
-* Tue Aug 18 2015 Konstantin Pavlov <thresh@nginx.com>
-- 1.9.4
-
-* Tue Jul 14 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.9.3
-
-* Tue May 26 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.9.1
-
-* Tue Apr 28 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.9.0
-- thread pool support added
-- stream module added
-- example_ssl.conf removed
-
-* Tue Apr  7 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.7.12
-
-* Tue Mar 24 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.7.11
-
-* Tue Feb 10 2015 Sergey Budnevitch <sb@nginx.com>
-- 1.7.10
-
-* Tue Dec 23 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.9
-
-* Tue Dec  2 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.8
-
-* Tue Sep 30 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.6
-
-* Tue Sep 16 2014 Sergey Budnevitch <sb@nginx.com>
-- epoch added to the EPEL7/CentOS7 spec to override EPEL one
-- 1.7.5
-
-* Tue Aug  5 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.4
-
-* Tue Jul  8 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.3
-
-* Tue Jun 17 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.2
-
-* Tue May 27 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.7.1
-- incorrect sysconfig filename finding in the initscript fixed
-
-* Thu Apr 24 2014 Konstantin Pavlov <thresh@nginx.com>
-- 1.7.0
-
-* Tue Apr  8 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.5.13
-- built spdy module on rhel/centos 6
-
-* Tue Mar 18 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.5.12
-- spec cleanup
-- openssl version dependence added
-- upgrade() function in the init script improved
-- warning added when binary upgrade returns non-zero exit code
-
-* Tue Mar  4 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.5.11
-
-* Tue Feb  4 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.5.10
-
-* Wed Jan 22 2014 Sergey Budnevitch <sb@nginx.com>
-- 1.5.9
-
-* Tue Dec 17 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.8
-- fixed invalid week days in the changelog
-
-* Tue Nov 19 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.7
-
-* Tue Oct  1 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.6
-
-* Tue Sep 17 2013 Andrei Belov <defan@nginx.com>
-- 1.5.5
-
-* Tue Aug 27 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.4
-- auth request module added
-
-* Tue Jul 30 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.3
-
-* Tue Jul  2 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.2
-
-* Tue Jun  4 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.1
-
-* Mon May  6 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.5.0
-
-* Tue Apr 16 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.3.16
-
-* Tue Mar 26 2013 Sergey Budnevitch <sb@nginx.com>
-- 1.3.15
-- gunzip module added
-- set permissions on default log files at installation
-
-* Tue Feb 12 2013 Sergey Budnevitch <sb@nginx.com>
-- excess slash removed from --prefix
-- 1.2.7
-
-* Tue Dec 11 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.6
-
-* Tue Nov 13 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.5
-
-* Tue Sep 25 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.4
-
-* Tue Aug  7 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.3
-- nginx-debug package now actually contains non stripped binary
-
-* Tue Jul  3 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.2
-
-* Tue Jun  5 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.1
-
-* Mon Apr 23 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.2.0
-
-* Thu Apr 12 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.0.15
-
-* Thu Mar 15 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.0.14
-- OpenSUSE init script and SuSE specific changes to spec file added
-
-* Mon Mar  5 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.0.13
-
-* Mon Feb  6 2012 Sergey Budnevitch <sb@nginx.com>
-- 1.0.12
-- banner added to install script
-
-* Thu Dec 15 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.11
-- init script enhancements (thanks to Gena Makhomed)
-- one second sleep during upgrade replaced with 0.1 sec usleep
-
-* Tue Nov 15 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.10
-
-* Tue Nov  1 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.9
-- nginx-debug package added
-
-* Tue Oct 11 2011 Sergey Budnevitch <sb@nginx.com>
-- spec file cleanup (thanks to Yury V. Zaytsev)
-- log dir permitions fixed
-- logrotate creates new logfiles with nginx owner
-- "upgrade" argument to init-script added (based on fedora one)
-
-* Sat Oct  1 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.8
-- built with mp4 module
-
-* Fri Sep 30 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.7
-
-* Tue Aug 30 2011 Sergey Budnevitch <sb@nginx.com>
-- 1.0.6
-- replace "conf.d/*" config include with "conf.d/*.conf" in default nginx.conf
-
-* Wed Aug 10 2011 Sergey Budnevitch
-- Initial release
diff --git a/rpm/SPECS/nginx.spec.in b/rpm/SPECS/nginx.spec.in
new file mode 100644
index 0000000..901c9ce
--- /dev/null
+++ b/rpm/SPECS/nginx.spec.in
@@ -0,0 +1,532 @@
+#
+%define nginx_home %{_localstatedir}/cache/nginx
+%define nginx_user nginx
+%define nginx_group nginx
+%define nginx_loggroup adm
+
+# distribution specific definitions
+%define use_systemd (0%{?fedora} && 0%{?fedora} >= 18) || (0%{?rhel} && 0%{?rhel} >= 7) || (0%{?suse_version} == 1315)
+
+%if 0%{?rhel} == 5
+%define _group System Environment/Daemons
+Requires(pre): shadow-utils
+Requires: initscripts >= 8.36
+Requires(post): chkconfig
+Requires: openssl
+BuildRequires: openssl-devel
+%endif
+
+%if 0%{?rhel} == 6
+%define _group System Environment/Daemons
+Requires(pre): shadow-utils
+Requires: initscripts >= 8.36
+Requires(post): chkconfig
+Requires: openssl >= 1.0.1
+BuildRequires: openssl-devel >= 1.0.1
+%endif
+
+%if 0%{?rhel} == 7
+%define _group System Environment/Daemons
+%define epoch 1
+Epoch: %{epoch}
+Requires(pre): shadow-utils
+Requires: systemd
+Requires: openssl >= 1.0.1
+BuildRequires: systemd
+BuildRequires: openssl-devel >= 1.0.1
+%endif
+
+%if 0%{?suse_version} == 1315
+%define _group Productivity/Networking/Web/Servers
+%define nginx_loggroup trusted
+Requires(pre): shadow
+Requires: systemd
+BuildRequires: libopenssl-devel
+BuildRequires: systemd
+%endif
+
+# end of distribution specific definitions
+
+%define main_version %%MAIN_VERSION%%
+%define main_release %%MAIN_RELEASE%%%{?dist}.ngx
+
+%define bdir %{_builddir}/%{name}-%{main_version}
+
+%define WITH_CC_OPT $(echo %{optflags} $(pcre-config --cflags))
+
+%define BASE_CONFIGURE_ARGS $(echo "%%BASE_CONFIGURE_ARGS%%")
+
+Summary: High performance web server
+Name: nginx
+Version: %{main_version}
+Release: %{main_release}
+Vendor: Nginx, Inc.
+URL: http://nginx.org/
+Group: %{_group}
+
+Source0: http://nginx.org/download/%{name}-%{version}.tar.gz
+Source1: logrotate
+Source2: nginx.init.in
+Source3: nginx.sysconf
+Source4: nginx.conf
+Source5: nginx.vh.default.conf
+Source7: nginx-debug.sysconf
+Source8: nginx.service
+Source9: nginx.upgrade.sh
+Source10: nginx.suse.logrotate
+Source11: nginx-debug.service
+Source12: COPYRIGHT
+
+License: 2-clause BSD-like license
+
+BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{main_release}-root
+BuildRequires: zlib-devel
+BuildRequires: pcre-devel
+
+Provides: webserver
+
+%description
+nginx [engine x] is an HTTP and reverse proxy server, as well as
+a mail proxy server.
+
+%if 0%{?suse_version} == 1315
+%debug_package
+%endif
+
+%prep
+%setup -q
+cp %{SOURCE2} .
+sed -e 's|%%DEFAULTSTART%%|2 3 4 5|g' -e 's|%%DEFAULTSTOP%%|0 1 6|g' \
+    -e 's|%%PROVIDES%%|nginx|g' < %{SOURCE2} > nginx.init
+sed -e 's|%%DEFAULTSTART%%||g' -e 's|%%DEFAULTSTOP%%|0 1 2 3 4 5 6|g' \
+    -e 's|%%PROVIDES%%|nginx-debug|g' < %{SOURCE2} > nginx-debug.init
+
+%build
+./configure %{BASE_CONFIGURE_ARGS} \
+    --with-cc-opt="%{WITH_CC_OPT}" \
+    --with-debug
+make %{?_smp_mflags}
+%{__mv} %{bdir}/objs/nginx \
+    %{bdir}/objs/nginx-debug
+./configure %{BASE_CONFIGURE_ARGS} \
+    --with-cc-opt="%{WITH_CC_OPT}"
+make %{?_smp_mflags}
+
+%install
+%{__rm} -rf $RPM_BUILD_ROOT
+%{__make} DESTDIR=$RPM_BUILD_ROOT INSTALLDIRS=vendor install
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/nginx
+%{__mv} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/html $RPM_BUILD_ROOT%{_datadir}/nginx/
+
+%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/*.default
+%{__rm} -f $RPM_BUILD_ROOT%{_sysconfdir}/nginx/fastcgi.conf
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/log/nginx
+%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/run/nginx
+%{__mkdir} -p $RPM_BUILD_ROOT%{_localstatedir}/cache/nginx
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_libdir}/nginx/modules
+cd $RPM_BUILD_ROOT%{_sysconfdir}/nginx && \
+    %{__ln_s} ../..%{_libdir}/nginx/modules modules && cd -
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_datadir}/doc/%{name}-%{main_version}
+%{__install} -m 644 -p %{SOURCE12} \
+    $RPM_BUILD_ROOT%{_datadir}/doc/%{name}-%{main_version}/
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d
+%{__rm} $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
+%{__install} -m 644 -p %{SOURCE4} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/nginx/nginx.conf
+%{__install} -m 644 -p %{SOURCE5} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/nginx/conf.d/default.conf
+
+%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
+%{__install} -m 644 -p %{SOURCE3} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx
+%{__install} -m 644 -p %{SOURCE7} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/nginx-debug
+
+%{__install} -p -D -m 0644 %{bdir}/objs/nginx.8 \
+    $RPM_BUILD_ROOT%{_mandir}/man8/nginx.8
+
+%if %{use_systemd}
+# install systemd-specific files
+%{__mkdir} -p $RPM_BUILD_ROOT%{_unitdir}
+%{__install} -m644 %SOURCE8 \
+    $RPM_BUILD_ROOT%{_unitdir}/nginx.service
+%{__install} -m644 %SOURCE11 \
+    $RPM_BUILD_ROOT%{_unitdir}/nginx-debug.service
+%{__mkdir} -p $RPM_BUILD_ROOT%{_libexecdir}/initscripts/legacy-actions/nginx
+%{__install} -m755 %SOURCE9 \
+    $RPM_BUILD_ROOT%{_libexecdir}/initscripts/legacy-actions/nginx/upgrade
+%else
+# install SYSV init stuff
+%{__mkdir} -p $RPM_BUILD_ROOT%{_initrddir}
+%{__install} -m755 nginx.init $RPM_BUILD_ROOT%{_initrddir}/nginx
+%{__install} -m755 nginx-debug.init $RPM_BUILD_ROOT%{_initrddir}/nginx-debug
+%endif
+
+# install log rotation stuff
+%{__mkdir} -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
+%if 0%{?suse_version}
+%{__install} -m 644 -p %{SOURCE10} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx
+%else
+%{__install} -m 644 -p %{SOURCE1} \
+    $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/nginx
+%endif
+
+%{__install} -m755 %{bdir}/objs/nginx-debug \
+    $RPM_BUILD_ROOT%{_sbindir}/nginx-debug
+
+%clean
+%{__rm} -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+
+%{_sbindir}/nginx
+%{_sbindir}/nginx-debug
+
+%dir %{_sysconfdir}/nginx
+%dir %{_sysconfdir}/nginx/conf.d
+%{_sysconfdir}/nginx/modules
+
+%config(noreplace) %{_sysconfdir}/nginx/nginx.conf
+%config(noreplace) %{_sysconfdir}/nginx/conf.d/default.conf
+%config(noreplace) %{_sysconfdir}/nginx/mime.types
+%config(noreplace) %{_sysconfdir}/nginx/fastcgi_params
+%config(noreplace) %{_sysconfdir}/nginx/scgi_params
+%config(noreplace) %{_sysconfdir}/nginx/uwsgi_params
+%config(noreplace) %{_sysconfdir}/nginx/koi-utf
+%config(noreplace) %{_sysconfdir}/nginx/koi-win
+%config(noreplace) %{_sysconfdir}/nginx/win-utf
+
+%config(noreplace) %{_sysconfdir}/logrotate.d/nginx
+%config(noreplace) %{_sysconfdir}/sysconfig/nginx
+%config(noreplace) %{_sysconfdir}/sysconfig/nginx-debug
+%if %{use_systemd}
+%{_unitdir}/nginx.service
+%{_unitdir}/nginx-debug.service
+%dir %{_libexecdir}/initscripts/legacy-actions/nginx
+%{_libexecdir}/initscripts/legacy-actions/nginx/*
+%else
+%{_initrddir}/nginx
+%{_initrddir}/nginx-debug
+%endif
+
+%attr(0755,root,root) %dir %{_libdir}/nginx
+%attr(0755,root,root) %dir %{_libdir}/nginx/modules
+%dir %{_datadir}/nginx
+%dir %{_datadir}/nginx/html
+%{_datadir}/nginx/html/*
+
+%attr(0755,root,root) %dir %{_localstatedir}/cache/nginx
+%attr(0755,root,root) %dir %{_localstatedir}/log/nginx
+
+%dir %{_datadir}/doc/%{name}-%{main_version}
+%doc %{_datadir}/doc/%{name}-%{main_version}/COPYRIGHT
+%{_mandir}/man8/nginx.8*
+
+%pre
+# Add the "nginx" user
+getent group %{nginx_group} >/dev/null || groupadd -r %{nginx_group}
+getent passwd %{nginx_user} >/dev/null || \
+    useradd -r -g %{nginx_group} -s /sbin/nologin \
+    -d %{nginx_home} -c "nginx user"  %{nginx_user}
+exit 0
+
+%post
+# Register the nginx service
+if [ $1 -eq 1 ]; then
+%if %{use_systemd}
+    /usr/bin/systemctl preset nginx.service >/dev/null 2>&1 ||:
+    /usr/bin/systemctl preset nginx-debug.service >/dev/null 2>&1 ||:
+%else
+    /sbin/chkconfig --add nginx
+    /sbin/chkconfig --add nginx-debug
+%endif
+    # print site info
+    cat <<BANNER
+----------------------------------------------------------------------
+
+Thanks for using nginx!
+
+Please find the official documentation for nginx here:
+* http://nginx.org/en/docs/
+
+Commercial subscriptions for nginx are available on:
+* http://nginx.com/products/
+
+----------------------------------------------------------------------
+BANNER
+
+    # Touch and set permisions on default log files on installation
+
+    if [ -d %{_localstatedir}/log/nginx ]; then
+        if [ ! -e %{_localstatedir}/log/nginx/access.log ]; then
+            touch %{_localstatedir}/log/nginx/access.log
+            %{__chmod} 640 %{_localstatedir}/log/nginx/access.log
+            %{__chown} nginx:%{nginx_loggroup} %{_localstatedir}/log/nginx/access.log
+        fi
+
+        if [ ! -e %{_localstatedir}/log/nginx/error.log ]; then
+            touch %{_localstatedir}/log/nginx/error.log
+            %{__chmod} 640 %{_localstatedir}/log/nginx/error.log
+            %{__chown} nginx:%{nginx_loggroup} %{_localstatedir}/log/nginx/error.log
+        fi
+    fi
+fi
+
+%preun
+if [ $1 -eq 0 ]; then
+%if %use_systemd
+    /usr/bin/systemctl --no-reload disable nginx.service >/dev/null 2>&1 ||:
+    /usr/bin/systemctl stop nginx.service >/dev/null 2>&1 ||:
+%else
+    /sbin/service nginx stop > /dev/null 2>&1
+    /sbin/chkconfig --del nginx
+    /sbin/chkconfig --del nginx-debug
+%endif
+fi
+
+%postun
+%if %use_systemd
+/usr/bin/systemctl daemon-reload >/dev/null 2>&1 ||:
+%endif
+if [ $1 -ge 1 ]; then
+    /sbin/service nginx status  >/dev/null 2>&1 || exit 0
+    /sbin/service nginx upgrade >/dev/null 2>&1 || echo \
+        "Binary upgrade failed, please check nginx's error.log"
+fi
+
+%changelog
+* Tue May 31 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.10.1
+
+* Tue Apr 26 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.10.0
+
+* Tue Apr 19 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.15
+- njs updated to 1c50334fbea6.
+
+* Tue Apr 05 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.14
+
+* Tue Mar 29 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.13
+- Added perl and nJScript dynamic modules
+- Fixed Requires section for dynamic modules on CentOS7/RHEL7
+
+* Wed Feb 24 2016 Sergey Budnevitch <sb@nginx.com>
+- common configure args are now in macros
+- xslt, image-filter and geoip dynamic modules added
+- 1.9.12
+
+* Tue Feb  9 2016 Sergey Budnevitch <sb@nginx.com>
+- dynamic modules path and symlink in %{_sysconfdir}/nginx added
+- 1.9.11
+
+* Tue Jan 26 2016 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.10
+
+* Wed Dec  9 2015 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.9
+
+* Tue Dec  8 2015 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.8
+- http_slice module enabled
+
+* Tue Nov 17 2015 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.7
+
+* Tue Oct 27 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.9.6
+
+* Tue Sep 22 2015 Andrei Belov <defan@nginx.com>
+- 1.9.5
+- http_spdy module replaced with http_v2 module
+
+* Tue Aug 18 2015 Konstantin Pavlov <thresh@nginx.com>
+- 1.9.4
+
+* Tue Jul 14 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.9.3
+
+* Tue May 26 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.9.1
+
+* Tue Apr 28 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.9.0
+- thread pool support added
+- stream module added
+- example_ssl.conf removed
+
+* Tue Apr  7 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.7.12
+
+* Tue Mar 24 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.7.11
+
+* Tue Feb 10 2015 Sergey Budnevitch <sb@nginx.com>
+- 1.7.10
+
+* Tue Dec 23 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.9
+
+* Tue Dec  2 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.8
+
+* Tue Sep 30 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.6
+
+* Tue Sep 16 2014 Sergey Budnevitch <sb@nginx.com>
+- epoch added to the EPEL7/CentOS7 spec to override EPEL one
+- 1.7.5
+
+* Tue Aug  5 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.4
+
+* Tue Jul  8 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.3
+
+* Tue Jun 17 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.2
+
+* Tue May 27 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.7.1
+- incorrect sysconfig filename finding in the initscript fixed
+
+* Thu Apr 24 2014 Konstantin Pavlov <thresh@nginx.com>
+- 1.7.0
+
+* Tue Apr  8 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.5.13
+- built spdy module on rhel/centos 6
+
+* Tue Mar 18 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.5.12
+- spec cleanup
+- openssl version dependence added
+- upgrade() function in the init script improved
+- warning added when binary upgrade returns non-zero exit code
+
+* Tue Mar  4 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.5.11
+
+* Tue Feb  4 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.5.10
+
+* Wed Jan 22 2014 Sergey Budnevitch <sb@nginx.com>
+- 1.5.9
+
+* Tue Dec 17 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.8
+- fixed invalid week days in the changelog
+
+* Tue Nov 19 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.7
+
+* Tue Oct  1 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.6
+
+* Tue Sep 17 2013 Andrei Belov <defan@nginx.com>
+- 1.5.5
+
+* Tue Aug 27 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.4
+- auth request module added
+
+* Tue Jul 30 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.3
+
+* Tue Jul  2 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.2
+
+* Tue Jun  4 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.1
+
+* Mon May  6 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.5.0
+
+* Tue Apr 16 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.3.16
+
+* Tue Mar 26 2013 Sergey Budnevitch <sb@nginx.com>
+- 1.3.15
+- gunzip module added
+- set permissions on default log files at installation
+
+* Tue Feb 12 2013 Sergey Budnevitch <sb@nginx.com>
+- excess slash removed from --prefix
+- 1.2.7
+
+* Tue Dec 11 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.6
+
+* Tue Nov 13 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.5
+
+* Tue Sep 25 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.4
+
+* Tue Aug  7 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.3
+- nginx-debug package now actually contains non stripped binary
+
+* Tue Jul  3 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.2
+
+* Tue Jun  5 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.1
+
+* Mon Apr 23 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.2.0
+
+* Thu Apr 12 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.0.15
+
+* Thu Mar 15 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.0.14
+- OpenSUSE init script and SuSE specific changes to spec file added
+
+* Mon Mar  5 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.0.13
+
+* Mon Feb  6 2012 Sergey Budnevitch <sb@nginx.com>
+- 1.0.12
+- banner added to install script
+
+* Thu Dec 15 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.11
+- init script enhancements (thanks to Gena Makhomed)
+- one second sleep during upgrade replaced with 0.1 sec usleep
+
+* Tue Nov 15 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.10
+
+* Tue Nov  1 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.9
+- nginx-debug package added
+
+* Tue Oct 11 2011 Sergey Budnevitch <sb@nginx.com>
+- spec file cleanup (thanks to Yury V. Zaytsev)
+- log dir permitions fixed
+- logrotate creates new logfiles with nginx owner
+- "upgrade" argument to init-script added (based on fedora one)
+
+* Sat Oct  1 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.8
+- built with mp4 module
+
+* Fri Sep 30 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.7
+
+* Tue Aug 30 2011 Sergey Budnevitch <sb@nginx.com>
+- 1.0.6
+- replace "conf.d/*" config include with "conf.d/*.conf" in default nginx.conf
+
+* Wed Aug 10 2011 Sergey Budnevitch
+- Initial release