RPM related changes to build PLUS packages with OSS packaging scripts
diff --git a/rpm/SOURCES/nginx.vh.default.conf b/rpm/SOURCES/nginx.default.conf
similarity index 100%
rename from rpm/SOURCES/nginx.vh.default.conf
rename to rpm/SOURCES/nginx.default.conf
diff --git a/rpm/SPECS/Makefile b/rpm/SPECS/Makefile
index 465b68c..59e77d9 100644
--- a/rpm/SPECS/Makefile
+++ b/rpm/SPECS/Makefile
@@ -2,32 +2,38 @@
 
 CONTRIB?=	../../contrib
 CONTRIB:=	$(abspath $(CONTRIB))
+DOCS?=		../../docs
 
-include $(CONTRIB)/src/nginx/version
+BASE_TARGET?=	oss
+MODULE_TARGET?=	oss
+
+ifeq ($(BASE_TARGET), plus)
+BASE_SUFFIX=-plus
+endif
+
+include $(CONTRIB)/src/nginx$(BASE_SUFFIX)/version
 
 BASE_VERSION=	$(NGINX_VERSION)
 BASE_RELEASE=	1
 PLUS_VERSION=	$(NGINX_PLUS_VERSION)
-BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
+PLUS_RELEASE=   $(BASE_RELEASE)
+BASE_SRC=	nginx$(BASE_SUFFIX)-$(BASE_VERSION).tar.gz
 SRCPATH?=	../SOURCES
 BUILD_ENV_PATH=	${HOME}/rpmbuild
-MODULE_TARGET?=	oss
 MODSRC_PREFIX=
 BUILD_DIR=	%{bdir}
-DOCS?=		../../docs
 
 ifeq ($(MODULE_TARGET), plus)
-MODULE_SPEC_TEMPLATE=	nginx-plus-module.spec.in
 MODULE_SUMMARY_PREFIX=	NGINX Plus
 TARGET_VERSION=$(PLUS_VERSION)
-MODULE_PACKAGE_PREFIX=nginx-plus-module
+MODULE_SUFFIX=-plus
 else
-MODULE_SPEC_TEMPLATE=	nginx-module.spec.in
 MODULE_SUMMARY_PREFIX=	nginx
 TARGET_VERSION=$(BASE_VERSION)
-MODULE_PACKAGE_PREFIX=nginx-module
 endif
 
+MODULE_SPEC_TEMPLATE=	nginx$(MODULE_SUFFIX)-module.spec.in
+MODULE_PACKAGE_PREFIX=nginx$(MODULE_SUFFIX)-module
 MODULE_TARGET_PREFIX=$(TARGET_VERSION)+
 
 MODULE_PACKAGE_VENDOR=	Nginx, Inc.
@@ -81,6 +87,15 @@
 	--with-stream_ssl_module \
 	--with-stream_ssl_preread_module
 
+ifeq ($(BASE_TARGET), plus)
+BASE_CONFIGURE_ARGS+= \
+	--build=nginx-plus-r$(PLUS_VERSION) \
+	--with-http_auth_jwt_module \
+	--with-http_f4f_module \
+	--with-http_hls_module \
+	--with-http_session_log_module
+endif
+
 export CR=\\n
 
 modname = $(shell echo $1 | tr '-' '_')
@@ -110,32 +125,52 @@
 specs:	nginx.spec $(addsuffix .spec, $(addprefix nginx-module-, $(MODULES)))
 
 $(SRCPATH)/$(BASE_SRC):
-	cd $(CONTRIB) && make .sum-nginx
+	cd $(CONTRIB) && make .sum-nginx$(BASE_SUFFIX)
 	cd $(SRCPATH) && ln -s $(CONTRIB)/tarballs/$(BASE_SRC) $(BASE_SRC)
+	cp -p $(DOCS)/nginx.copyright ../SOURCES/ ;
+ifeq ($(BASE_TARGET), plus)
+	cp $(DOCS)/swagger-ui/* $(DOCS)/nginx-modules-reference.pdf $(SRCPATH)
+	cp $(CONTRIB)/tarballs/dashboard.html $(SRCPATH)
+	cp $(DOCS)/EULA* $(SRCPATH)
+endif
 
 base:	nginx.spec $(SRCPATH)/$(BASE_SRC)
 	@echo "===> Building base package" ; \
-	$(SHELL) -c "time -p rpmbuild -D \"_topdir `pwd`/../\" -ba nginx.spec" && \
-	ln -s ../BUILD/nginx-$(BASE_VERSION)/objs base
+	$(SHELL) -c "time -p rpmbuild -D \"_topdir `pwd`/../\" -ba nginx$(BASE_SUFFIX).spec" && \
+	ln -s ../BUILD/nginx$(BASE_SUFFIX)-$(BASE_VERSION)/objs base
 
 nginx.rpm-changelog:
 	@echo "===> Generating $@"
-	@cd $(DOCS) && DEST=$(CURDIR) VERSIONMASK=1 make $(CURDIR)/nginx.rpm-changelog
+	@cd $(DOCS) && DEST=$(CURDIR) VERSIONMASK=1 make $(CURDIR)/nginx$(BASE_SUFFIX).rpm-changelog
 
 nginx.spec: nginx.rpm-changelog
 	@echo "===> Creating $@"
 	@{ \
 	set -e ; \
-	cat nginx.spec.in | sed \
+	patch_files=`find $(CONTRIB)/src/nginx$(BASE_SUFFIX)/ \
+		-type f -name '*.patch' -printf "%f\n" | sort`; \
+	patches=`for i in $$patch_files; do echo $$i; done | \
+		nl -v0 -w 1 -s": " | \
+		sed -n  -e ':a' \
+			-e 's/^/Patch/' -e '1h;1!H;' -e '$$!{n;ba}' \
+			-e 'x' -e "s/$$/$$CR/; s/\\n/$$CR/g" -e 'p' `; \
+	for patch in $$patch_files; do \
+		cp -v $(CONTRIB)/src/nginx$(BASE_SUFFIX)/$$patch $(SRCPATH) ; \
+	done; \
+	cat nginx$(BASE_SUFFIX).spec.in | sed \
 		-e 's#%%BASE_VERSION%%#$(BASE_VERSION)#g' \
 		-e 's#%%BASE_RELEASE%%#$(BASE_RELEASE)#g' \
+		-e 's#%%PLUS_VERSION%%#$(PLUS_VERSION)#g' \
+		-e 's#%%PLUS_RELEASE%%#$(PLUS_RELEASE)#g' \
+		-e "s#%%BASE_PATCHES%%#$$patches#g" \
 		-e 's#%%BASE_CONFIGURE_ARGS%%#$(BASE_CONFIGURE_ARGS)#g' \
-		> nginx.spec ; \
-	cat nginx.rpm-changelog | sed \
+		> nginx$(BASE_SUFFIX).spec ; \
+	cat nginx$(BASE_SUFFIX).rpm-changelog | sed \
 		-e 's#%%BASE_VERSION%%#$(BASE_VERSION)#g' \
 		-e 's#%%BASE_RELEASE%%#$(BASE_RELEASE)#g' \
-	>> nginx.spec ; \
-	cp -p $(DOCS)/nginx.copyright ../SOURCES/ ; \
+    	-e 's#%%PLUS_VERSION%%#$(PLUS_VERSION)#g' \
+    	-e 's#%%PLUS_RELEASE%%#$(PLUS_RELEASE)#g' \
+	>> nginx$(BASE_SUFFIX).spec ; \
 	}
 
 .deps-module-%:
@@ -152,7 +187,7 @@
 
 nginx-module-%.rpm-changelog:
 	@echo "===> Generating $@"
-	@cd $(DOCS) && DEST=$(CURDIR) VERSIONMASK=1 make $(CURDIR)/nginx-module-$*.rpm-changelog
+	@cd $(DOCS) && DEST=$(CURDIR) VERSIONMASK=1 make $(CURDIR)/$@
 
 nginx-module-%.spec: nginx-module-%.rpm-changelog
 	@echo "===> Creating $@"
@@ -204,9 +239,7 @@
 	module_copyright=`echo $@ | sed -e "s#.spec#.copyright#"` ; \
 	cp -p $(DOCS)/$${module_copyright} ../SOURCES/ ; \
 	pkgname=$(shell echo $@ | cut -d '.' -f 1) ; \
-	if [ "$(MODULE_TARGET)" = "plus" ]; then \
-		pkgname=`echo $${pkgname} | sed -e "s#^nginx-#nginx-plus-#"` ; \
-	fi ; \
+	pkgname=`echo $${pkgname} | sed -e "s#^nginx-#nginx$(MODULE_SUFFIX)-#"` ; \
 	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"` ; \
@@ -228,6 +261,7 @@
 		-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#%%BASE_SUFFIX%%#$(BASE_SUFFIX)#g" \
 		-e "s#%%MODULE_CONFIGURE_ARGS%%#$(MODULE_CONFARGS_$(call modname, $*))#g" \
 		-e "s#%%COPYRIGHT_SOURCE%%#$${module_copyright}#g" \
 		-e "s#%%MODULE_SOURCES%%#$${sources}#g" \
@@ -249,6 +283,7 @@
 		-e 's#%%TARGET_VERSION%%#$(TARGET_VERSION)#g' \
 		-e 's#%%BASE_VERSION%%#$(BASE_VERSION)#g' \
 		-e 's#%%BASE_RELEASE%%#$(BASE_RELEASE)#g' \
+		-e "s#%%PLUS_VERSION%%#$(PLUS_VERSION)#g" \
 		-e "s#%%MODULE_VERSION%%#$(MODULE_VERSION_$(call modname, $*))#g" \
 		-e "s#%%MODULE_RELEASE%%#$(MODULE_RELEASE_$(call modname, $*))#g" \
 		>> $@.tmp && \
@@ -258,11 +293,65 @@
 check-compat-%:
 	@module=`echo $@ | cut -d '-' -f 3 | tr '-' '_'` ; \
 	case "$${module}" in \
-	    geoip) \
+		brotli) \
+		if [	`rpm --eval '0%{?suse_version}'` -gt 0 -a `rpm --eval '0%{?suse_version}'` -lt 1500 -o \
+				`rpm --eval '0%{?fedora}'` -gt 0 -a `rpm --eval '0%{?fedora}'` -lt 29 -o \
+				`rpm --eval '0%{?amzn}'` -eq 1 ]; then \
+			echo "Brotli can't be build on SLES < 15, Fedora < 29 or Amazon Linux" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		;; \
+		geoip) \
 		if [ `rpm --eval '0%{?rhel}'` -ge 8 ]; then \
-		    echo "GeoIP can not be build on RHEL/CentOS >= 8" > \
-		    nginx-module-$${module}.skip ; \
-		    exit ; \
+			echo "GeoIP can not be build on RHEL/CentOS >= 8" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		;; \
+		geoip2) \
+		if [ `rpm --eval '0%{?suse_version}'` -gt 0 -a `rpm --eval '0%{?suse_version}'` -lt 1500 ]; then \
+			echo "GeoIP2 can not be built on SuSe linux < 15 due to libmaxminddb absence" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		;; \
+		lua) \
+		if [ `rpm --eval '%{_arch}'` = "ppc64le" ]; then \
+			echo "Lua module can not be built on ppc64le" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		;; \
+		modsecurity) \
+		if [ "`rpm --eval '%{_arch}'`" = "ppc64le" ]; then \
+			echo "ModSecurity can not be built on ppc64le" > \
+			nginx-module-$${module}.skip ; \
+		fi ; \
+		;; \
+		opentracing) \
+		if [ "`rpm --eval '0%{?suse_version}'`" -gt 0 -a "`rpm --eval '0%{?suse_version}'`" -lt 1500 ]; then \
+			echo "OpenTracing can not be built on SLES < 15 due to absence of yaml-cpp" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		if [ "`rpm --eval '0%{?amzn}'`" -eq 1 ]; then \
+			echo "OpenTracing can not be built on Amazon Linux due to old yaml-cpp library" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		if [ "`rpm --eval '%{_arch}'`" = "ppc64le" ]; then \
+			echo "OpenTracing can not be built on ppc64le" > \
+			nginx-module-$${module}.skip ; \
+			exit ; \
+		fi ; \
+		if [ `rpm --eval '0%{?rhel}'` -gt 0 ]; then \
+			cmake3 -version >/dev/null 2>&1 ; \
+			if [ $$? -ne 0 ]; then \
+			echo "OpenTracing requires cmake3 on RHEL/CentOS/Amazon Linux" > \
+			nginx-module-$${module}.skip ; \
+			fi ; \
+			exit ; \
 		fi ; \
 		;; \
 	esac
@@ -295,7 +384,7 @@
 		export LD_LIBRARY_PATH=$$pwd/module-opentracing/../opentracing-cpp-$(OPENTRACING_CPP_VERSION)/usr/local/lib ; \
 	fi ;  \
 	if [ -d $$pwd/module-lua ]; then \
-		globals_http="lua_package_path '$$pwd/../BUILD/nginx-module-lua-$(BASE_VERSION)/lua-resty-core-$(LUA_RESTY_CORE_VERSION)/lib/?.lua;$$pwd/../BUILD/nginx-module-lua-$(BASE_VERSION)/lua-resty-lrucache-$(LUA_RESTY_LRUCACHE_VERSION)/lib/?.lua;;';" ; \
+		globals_http="lua_package_path '$$pwd/../BUILD/$(MODULE_PACKAGE_PREFIX)-lua-$(BASE_VERSION)/lua-resty-core-$(LUA_RESTY_CORE_VERSION)/lib/?.lua;$$pwd/../BUILD/$(MODULE_PACKAGE_PREFIX)-lua-$(BASE_VERSION)/lua-resty-lrucache-$(LUA_RESTY_LRUCACHE_VERSION)/lib/?.lua;;';" ; \
 		globals_stream="$$globals_http" ; \
 	fi ; \
 	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx TEST_NGINX_GLOBALS="$$globals" TEST_NGINX_GLOBALS_HTTP="$$globals_http" TEST_NGINX_GLOBALS_STREAM="$$globals_stream" prove $$PROVE_ARGS . ; \
@@ -318,7 +407,7 @@
 		export LD_LIBRARY_PATH=$$pwd/module-opentracing/../opentracing-cpp-$(OPENTRACING_CPP_VERSION)/usr/local/lib ; \
 	fi ;  \
 	if [ -d $$pwd/module-lua ]; then \
-		globals_http="lua_package_path '$$pwd/../BUILD/nginx-module-lua-$(BASE_VERSION)/lua-resty-core-$(LUA_RESTY_CORE_VERSION)/lib/?.lua;$$pwd/../BUILD/nginx-module-lua-$(BASE_VERSION)/lua-resty-lrucache-$(LUA_RESTY_LRUCACHE_VERSION)/lib/?.lua;;';" ; \
+		globals_http="lua_package_path '$$pwd/../BUILD/$(MODULE_PACKAGE_PREFIX)-lua-$(BASE_VERSION)/lua-resty-core-$(LUA_RESTY_CORE_VERSION)/lib/?.lua;$$pwd/../BUILD/$(MODULE_PACKAGE_PREFIX)-lua-$(BASE_VERSION)/lua-resty-lrucache-$(LUA_RESTY_LRUCACHE_VERSION)/lib/?.lua;;';" ; \
 		globals_stream="$$globals_http" ; \
 	fi ; \
 	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx-debug TEST_NGINX_GLOBALS="$$globals" TEST_NGINX_GLOBALS_HTTP="$$globals_http" TEST_NGINX_GLOBALS_STREAM="$$globals_stream" prove $$PROVE_ARGS . ; \
diff --git a/rpm/SPECS/Makefile.module-modsecurity b/rpm/SPECS/Makefile.module-modsecurity
index 04abb49..e066b89 100644
--- a/rpm/SPECS/Makefile.module-modsecurity
+++ b/rpm/SPECS/Makefile.module-modsecurity
@@ -26,7 +26,7 @@
 
 define MODULE_DEFINITIONS_modsecurity
 BuildRequires: gcc-c++
-BuildRequires: yajl-devel
+BuildRequires: pkgconfig(yajl)
 BuildRequires: libcurl-devel
 BuildRequires: libxml2-devel
 endef
diff --git a/rpm/SPECS/Makefile.module-opentracing b/rpm/SPECS/Makefile.module-opentracing
index 4fbc070..219853f 100644
--- a/rpm/SPECS/Makefile.module-opentracing
+++ b/rpm/SPECS/Makefile.module-opentracing
@@ -100,6 +100,7 @@
 OpenTracing_DIR=%{bdir}/opentracing-cpp-$(OPENTRACING_CPP_VERSION)/usr/local/lib/cmake/OpenTracing \
 thrift_DIR=%{bdir}/thrift-$(THRIFT_VERSION)/usr/local/lib/cmake/thrift \
 %{_cmake_cmd} \
+	-DJAEGERTRACING_BUILD_EXAMPLES=OFF \
 	-DBUILD_TESTING=OFF \
 	-DJAEGERTRACING_PLUGIN=ON \
 	-DCMAKE_BUILD_TYPE=Release \
diff --git a/rpm/SPECS/Makefile.module-passenger b/rpm/SPECS/Makefile.module-passenger
index 1fa2793..141c7e9 100644
--- a/rpm/SPECS/Makefile.module-passenger
+++ b/rpm/SPECS/Makefile.module-passenger
@@ -20,7 +20,7 @@
 	touch $@
 
 define MODULE_DEFINITIONS_passenger
-BuildRequires: rubygem-rake
+BuildRequires: rubygem(rake)
 endef
 export MODULE_DEFINITIONS_passenger
 
diff --git a/rpm/SPECS/nginx-module.spec.in b/rpm/SPECS/nginx-module.spec.in
index 78ac7db..e64074e 100644
--- a/rpm/SPECS/nginx-module.spec.in
+++ b/rpm/SPECS/nginx-module.spec.in
@@ -62,7 +62,7 @@
 %description
 nginx %%SHORT_SUMMARY%%.
 
-%if 0%{?suse_version} || 0%{?amzn}
+%if 0%{?suse_version}
 %debug_package
 %endif
 
diff --git a/rpm/SPECS/nginx-plus-module.spec.in b/rpm/SPECS/nginx-plus-module.spec.in
index 0862eff..b6157a1 100644
--- a/rpm/SPECS/nginx-plus-module.spec.in
+++ b/rpm/SPECS/nginx-plus-module.spec.in
@@ -2,6 +2,12 @@
 %define nginx_user nginx
 %define nginx_group nginx
 
+%if "%%MODULE_CONFIGURE_ARGS%%" == ""
+%define META_MODULE 1
+%else
+%define META_MODULE 0
+%endif
+
 %if 0%{?rhel} || 0%{?amzn}
 %define _group System Environment/Daemons
 BuildRequires: openssl-devel
@@ -29,6 +35,9 @@
 %%MODULE_DEFINITIONS%%
 
 %define base_version %%BASE_VERSION%%
+%if "x%%BASE_SUFFIX%%" != "x"
+%define base_suffix %%BASE_SUFFIX%%
+%endif
 %define base_release %%BASE_RELEASE%%%{?dist}.ngx
 %define plus_version %%PLUS_VERSION%%
 
@@ -42,7 +51,11 @@
 URL: %%MODULE_PACKAGE_URL%%
 Group: %{_group}
 
-Source0: https://nginx.org/download/nginx-%{base_version}.tar.gz
+%if %{META_MODULE} == 1
+BuildArch: noarch
+%endif
+
+Source0: nginx%{?base_suffix}-%{base_version}.tar.gz
 Source1: %%COPYRIGHT_SOURCE%%
 %%MODULE_SOURCES%%
 
@@ -59,7 +72,7 @@
 %description
 NGINX Plus: %%SHORT_SUMMARY%%.
 
-%if 0%{?suse_version} || 0%{?amzn}
+%if 0%{?suse_version}
 %debug_package
 %endif
 
@@ -71,28 +84,34 @@
 
 %prep
 %setup -qcTn %{name}-%{base_version}
-tar --strip-components=1 -zxf %{SOURCE0}
+%if %{META_MODULE} == 0
+	tar --strip-components=1 -zxf %{SOURCE0}
+	if ! test -e configure ; then ln -s auto/configure ./ ; fi
+%endif
 %%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} %%MODULE_LD_OPT_DEBUG%%" \
-	--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%%" \
-	--with-ld-opt="%{WITH_LD_OPT} %%MODULE_LD_OPT%%"
-make %{?_smp_mflags} modules
+
+%if %{META_MODULE} == 0
+	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} %%MODULE_LD_OPT_DEBUG%%" \
+		--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%%" \
+		--with-ld-opt="%{WITH_LD_OPT} %%MODULE_LD_OPT%%"
+	make %{?_smp_mflags} modules
+%endif
 
 %check
 %{__rm} -rf $RPM_BUILD_ROOT/usr/src
@@ -112,18 +131,22 @@
 
 %%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
+%if %{META_MODULE} == 0
+	%{__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
+%endif
 
 %clean
 %{__rm} -rf $RPM_BUILD_ROOT
 
 %files
 %defattr(-,root,root)
+%if %{META_MODULE} == 0
 %{_libdir}/nginx/modules/*
+%endif
 %dir %{_datadir}/doc/%%NAME%%
 %{_datadir}/doc/%%NAME%%/*
 %%MODULE_FILES%%
diff --git a/rpm/SPECS/nginx.spec.in b/rpm/SPECS/nginx.spec.in
index dbb0311..8791c57 100644
--- a/rpm/SPECS/nginx.spec.in
+++ b/rpm/SPECS/nginx.spec.in
@@ -84,7 +84,7 @@
 Source2: nginx.init.in
 Source3: nginx.sysconf
 Source4: nginx.conf
-Source5: nginx.vh.default.conf
+Source5: nginx.default.conf
 Source7: nginx-debug.sysconf
 Source8: nginx.service
 Source9: nginx.upgrade.sh
@@ -93,6 +93,8 @@
 Source12: nginx.copyright
 Source13: nginx.check-reload.sh
 
+%%BASE_PATCHES%%
+
 License: 2-clause BSD-like license
 
 BuildRoot: %{_tmppath}/%{name}-%{base_version}-%{base_release}-root
@@ -111,7 +113,7 @@
 %endif
 
 %prep
-%setup -q
+%autosetup -p1
 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