Added support for building NGINX Plus module packages.
diff --git a/debian/Makefile b/debian/Makefile
index 1f19919..5d8a55c 100644
--- a/debian/Makefile
+++ b/debian/Makefile
@@ -2,10 +2,25 @@
 
 BASE_VERSION=	1.11.10
 BASE_RELEASE=	1
+BASE_PREV=	1.11.9
+BASE_NEXT=	1.11.11
 BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
 SRCDIR=		nginx-$(BASE_VERSION)
 SRCPATH?=	../..
 BUILD_ENV_PATH=	${HOME}/debuild
+MODULE_TARGET?=	oss
+
+ifeq ($(MODULE_TARGET), plus)
+MODULE_CONTROL_TEMPLATE=   nginx-plus-module.control.in
+TARGET_SUFFIX=	-plus
+MODULE_SUMMARY_PREFIX=NGINX Plus
+else
+MODULE_CONTROL_TEMPLATE=   nginx-module.control.in
+MODULE_SUMMARY_PREFIX=nginx
+endif
+
+MODULE_PACKAGE_VENDOR=	Sergey Budnevitch <sb@nginx.com>
+MODULE_PACKAGE_URL=	http://nginx.org/
 
 CODENAME=	$(shell lsb_release -cs)
 ARCH=		$(shell uname -m)
@@ -14,6 +29,8 @@
 
 MODULES=	geoip image-filter njs perl xslt
 
+-include Makefile.module-*
+
 MODULE_SUMMARY_geoip=		GeoIP dynamic modules
 MODULE_SUMMARY_image_filter=	image filter dynamic module
 MODULE_SUMMARY_njs=		nginScript dynamic modules
@@ -311,13 +328,17 @@
 	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 \
+	cat $(MODULE_CONTROL_TEMPLATE) | sed \
 		-e "s#%%MODULE%%#$${module_asis}#g" \
-		-e "s#%%SUMMARY%%#nginx $(MODULE_SUMMARY_$(call modname, $@))#g" \
+		-e "s#%%MODULE_PACKAGE_VENDOR%%#$(MODULE_PACKAGE_VENDOR)#g" \
+		-e "s#%%MODULE_PACKAGE_URL%%#$(MODULE_PACKAGE_URL)#g" \
+		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_PREFIX) $(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#%%MAIN_PREV%%#$(BASE_PREV)#g" \
+		-e "s#%%MAIN_NEXT%%#$(BASE_NEXT)#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" \
@@ -337,6 +358,7 @@
 		-e "s#%%CODENAME%%#$(CODENAME)#g" \
 		-e "s#%%MAIN_VERSION%%#$(BASE_VERSION)#g" \
 		-e "s#%%MAIN_RELEASE%%#$(BASE_RELEASE)#g" \
+		-e "s#%%TARGET_SUFFIX%%#$(TARGET_SUFFIX)#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" \
@@ -345,7 +367,7 @@
 	> $${builddir}/$(SRCDIR)/debian/rules ; \
 	cat nginx-module.postinst.in | sed \
 		-e "s#%%MODULE_POST%%#$$post#g" \
-	> $${builddir}/$(SRCDIR)/debian/nginx-module-$${module_asis}.postinst ; \
+	> $${builddir}/$(SRCDIR)/debian/nginx$(TARGET_SUFFIX)-module-$${module_asis}.postinst ; \
 	chmod +x $${builddir}/$(SRCDIR)/debian/rules ; \
 	ln -s $${builddir}/$(SRCDIR)/debian/rules $@ ; \
 	}
@@ -415,7 +437,7 @@
 	}
 
 clean:
-	@rm -rf base module-* rules-base rules-module-* debuild-base debuild-module-* nginx-tests
+	@rm -rf base module-* rules-base rules-module-* debuild-base debuild-module-* nginx-tests $(BASE_SRC)
 
 .PHONY:	default all modules rules test test-debug clean
 
diff --git a/debian/nginx-module.control.in b/debian/nginx-module.control.in
index 29000cb..521e51f 100644
--- a/debian/nginx-module.control.in
+++ b/debian/nginx-module.control.in
@@ -1,7 +1,7 @@
 Source: nginx-module-%%MODULE%%
 Section: httpd
 Priority: optional
-Maintainer: Sergey Budnevitch <sb@nginx.com>
+Maintainer: %%MODULE_PACKAGE_VENDOR%%
 Build-Depends: debhelper (>= 9~),
                dpkg-dev (>= 1.16.1~),
                quilt (>= 0.46-7~),
@@ -10,7 +10,7 @@
                libpcre3-dev,
                zlib1g-dev%%MODULE_BUILD_DEPENDS%%
 Standards-Version: 3.9.8.0
-Homepage: http://nginx.org
+Homepage: %%MODULE_PACKAGE_URL%%
 
 Package: nginx-module-%%MODULE%%
 Architecture: any
diff --git a/debian/nginx-module.rules.in b/debian/nginx-module.rules.in
index 1705d5e..73538f7 100755
--- a/debian/nginx-module.rules.in
+++ b/debian/nginx-module.rules.in
@@ -8,7 +8,7 @@
 
 BUILDDIR_nginx = $(CURDIR)/debian/build-nginx
 BUILDDIR_nginx_debug = $(CURDIR)/debian/build-nginx-debug
-INSTALLDIR = $(CURDIR)/debian/nginx-module-%%MODULE%%
+INSTALLDIR = $(CURDIR)/debian/nginx%%TARGET_SUFFIX%%-module-%%MODULE%%
 BASEDIR = $(CURDIR)
 
 ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
@@ -65,7 +65,7 @@
 
 build-dbg.%: install
 	dh_testdir
-	dh_strip --dbg-package=nginx-module-%%MODULE%%-dbg
+	dh_strip --dbg-package=nginx%%TARGET_SUFFIX%%-module-%%MODULE%%-dbg
 
 build-dbg: build-dbg.nginx
 	dh_testdir
diff --git a/debian/nginx-plus-module.control.in b/debian/nginx-plus-module.control.in
new file mode 100644
index 0000000..5bbe0c1
--- /dev/null
+++ b/debian/nginx-plus-module.control.in
@@ -0,0 +1,31 @@
+Source: nginx-module-%%MODULE%%
+Section: httpd
+Priority: optional
+Maintainer: %%MODULE_PACKAGE_VENDOR%%
+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: %%MODULE_PACKAGE_URL%%
+
+Package: nginx-plus-module-%%MODULE%%
+Architecture: any
+Depends: ${misc:Depends},
+         ${shlibs:Depends},
+         nginx-plus (>> %%MAIN_PREV%%), nginx-plus (<< %%MAIN_NEXT%%)%%MODULE_DEPENDS%%%%ADD_CONTROL_TAGS%%
+Description: %%SUMMARY%%
+ %%SHORT_SUMMARY%% for NGINX Plus
+
+Package: nginx-plus-module-%%MODULE%%-dbg
+Architecture: any
+Section: debug
+Priority: extra
+Depends: nginx-plus (>> %%MAIN_PREV%%), nginx-plus (<< %%MAIN_NEXT%%),
+         nginx-plus-module-%%MODULE%% (= %%VERSION_PREFIX%%%%MODULE_VERSION%%-%%MODULE_RELEASE%%~%%CODENAME%%),
+         ${misc:Depends}
+Description: debug symbols for the nginx-plus-module-%%MODULE%%
+ %%SHORT_SUMMARY%% for NGINX Plus (debug symbols)
diff --git a/rpm/SPECS/Makefile b/rpm/SPECS/Makefile
index 464cd63..a0feab8 100644
--- a/rpm/SPECS/Makefile
+++ b/rpm/SPECS/Makefile
@@ -5,9 +5,24 @@
 BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
 SRCPATH?=	../SOURCES
 BUILD_ENV_PATH=	${HOME}/rpmbuild
+MODULE_TARGET?=	oss                                                     
+
+ifeq ($(MODULE_TARGET), plus)
+MODULE_SPEC_TEMPLATE=	nginx-plus-module.spec.in
+MODULE_SUMMARY_PREFIX=	NGINX Plus
+else
+MODULE_SPEC_TEMPLATE=	nginx-module.spec.in
+MODULE_SUMMARY_PREFIX=	nginx
+endif
+
+MODULE_PACKAGE_VENDOR=	Nginx, Inc.
+MODULE_PACKAGE_URL=	http://nginx.org/
+MODULE_PACKAGE_LICENSE=2-clause BSD-like license
 
 MODULES=	geoip image-filter njs perl xslt
 
+-include Makefile.module-*
+
 MODULE_SUMMARY_geoip=		GeoIP dynamic modules
 MODULE_SUMMARY_image_filter=	image filter dynamic module
 MODULE_SUMMARY_njs=		nginScript dynamic modules
@@ -312,14 +327,22 @@
 	else \
 		changelog_file=nginx-module.changelog.in ; \
 	fi ; \
+	pkgname=$(shell echo $@ | cut -d '.' -f 1) ; \
+	if [ "$(MODULE_TARGET)" = "plus" ]; then \
+		pkgname=`echo $${pkgname} | sed -e "s#^nginx-#nginx-plus-#"` ; \
+	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"` ; \
+	buildenv=`echo "$$MODULE_ENV_$(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" \
+	cat $(MODULE_SPEC_TEMPLATE) | sed \
+		-e "s#%%NAME%%#$${pkgname}#g" \
+		-e "s#%%MODULE_PACKAGE_VENDOR%%#$(MODULE_PACKAGE_VENDOR)#g" \
+		-e "s#%%MODULE_PACKAGE_URL%%#$(MODULE_PACKAGE_URL)#g" \
+		-e "s#%%MODULE_PACKAGE_LICENSE%%#$(MODULE_PACKAGE_LICENSE)#g" \
+		-e "s#%%SUMMARY%%#$(MODULE_SUMMARY_PREFIX) $(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" \
@@ -335,6 +358,9 @@
 		-e "s#%%MODULE_PREP_PATCHES%%#$${preppatches}#g" \
 		-e "s#%%MODULE_DEFINITIONS%%#$${definitions}#g" \
 		-e "s#%%MODULE_PREBUILD%%#$${prebuild}#g" \
+		-e "s#%%MODULE_ENV%%#$${buildenv}#g" \
+		-e "s#%%MODULE_CC_OPT_DEBUG%%#$(MODULE_CC_OPT_DEBUG_$(call modname, $@))#g" \
+		-e "s#%%MODULE_CC_OPT_NODEBUG%%#$(MODULE_CC_OPT_NODEBUG_$(call modname, $@))#g" \
 		-e "s#%%MODULE_PREINSTALL%%#$${preinstall}#g" \
 		-e "s#%%MODULE_FILES%%#$${files}#g" \
 		-e "s#%%MODULE_POST%%#$${post}#g" \
@@ -412,6 +438,7 @@
 	@rm -f base module-*
 	@rm -f nginx.spec nginx-module-*.spec
 	@rm -rf nginx-tests
+	@rm -f $(BASE_SRC)
 
 .PHONY:	default all modules specs test test-debug clean
 
diff --git a/rpm/SPECS/nginx-module.spec.in b/rpm/SPECS/nginx-module.spec.in
index 2d07334..718f6d8 100644
--- a/rpm/SPECS/nginx-module.spec.in
+++ b/rpm/SPECS/nginx-module.spec.in
@@ -28,8 +28,8 @@
 Name: %%NAME%%
 Version: %%VERSION_PREFIX%%%%VERSION%%
 Release: %%RELEASE%%%{?dist}.ngx
-Vendor: Nginx, Inc.
-URL: http://nginx.org/
+Vendor: %%MODULE_PACKAGE_VENDOR%%
+URL: %%MODULE_PACKAGE_URL%%
 Group: %{_group}
 
 Source0: http://nginx.org/download/nginx-%{main_version}.tar.gz
@@ -38,7 +38,7 @@
 
 %%MODULE_PATCHES%%
 
-License: 2-clause BSD-like license
+License: %%MODULE_PACKAGE_LICENSE%%
 
 BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{main_release}-root
 BuildRequires: zlib-devel
diff --git a/rpm/SPECS/nginx-plus-module.spec.in b/rpm/SPECS/nginx-plus-module.spec.in
new file mode 100644
index 0000000..55c36f9
--- /dev/null
+++ b/rpm/SPECS/nginx-plus-module.spec.in
@@ -0,0 +1,117 @@
+#
+%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
+
+%define main_version %%MAIN_VERSION%%
+%define main_release %%MAIN_RELEASE%%%{?dist}.ngx
+
+%define bdir %{_builddir}/%{name}-%{main_version}
+
+Summary: %%SUMMARY%%
+Name: %%NAME%%
+Version: %%VERSION%%
+Release: %%RELEASE%%%{?dist}.ngx
+Vendor: %%MODULE_PACKAGE_VENDOR%%
+URL: %%MODULE_PACKAGE_URL%%
+Group: %{_group}
+
+Source0: http://nginx.org/download/nginx-%{main_version}.tar.gz
+Source1: %%COPYRIGHT_SOURCE%%
+%%MODULE_SOURCES%%
+
+%%MODULE_PATCHES%%
+
+License: %%MODULE_PACKAGE_LICENSE%%
+
+BuildRoot: %{_tmppath}/%{name}-%{main_version}-%{main_release}-root
+BuildRequires: zlib-devel
+BuildRequires: pcre-devel
+Requires: nginx-plus == %%MAIN_VERSION%%
+
+%description
+NGINX Plus: %%SHORT_SUMMARY%%.
+
+%if 0%{?suse_version} || 0%{?amzn}
+%debug_package
+%endif
+
+%define WITH_CC_OPT $(echo %{optflags} $(pcre-config --cflags))
+%define WITH_LD_OPT -Wl,-z,relro -Wl,-z,now
+
+%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}
+%%MODULE_ENV%%
+./configure %{BASE_CONFIGURE_ARGS} %{MODULE_CONFIGURE_ARGS} \
+	--with-cc-opt="%{WITH_CC_OPT} %%MODULE_CC_OPT_DEBUG%%" \
+	--with-ld-opt="%{WITH_LD_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
+%%MODULE_ENV%%
+./configure %{BASE_CONFIGURE_ARGS} %{MODULE_CONFIGURE_ARGS} \
+	--with-cc-opt="%{WITH_CC_OPT} %%MODULE_CC_OPT_NODEBUG%%" \
+	--with-ld-opt="%{WITH_LD_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%%
+
+%pre
+
+%post
+if [ $1 -eq 1 ]; then
+%%MODULE_POST%%
+fi
+
+%preun
+
+%postun
+
+%changelog