rpm, debian: prepare-build-env target introduced.
diff --git a/debian/Makefile b/debian/Makefile
index 7a10c93..1f19919 100644
--- a/debian/Makefile
+++ b/debian/Makefile
@@ -5,6 +5,7 @@
 BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
 SRCDIR=		nginx-$(BASE_VERSION)
 SRCPATH?=	../..
+BUILD_ENV_PATH=	${HOME}/debuild
 
 CODENAME=	$(shell lsb_release -cs)
 ARCH=		$(shell uname -m)
@@ -388,6 +389,31 @@
 	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx-debug TEST_NGINX_GLOBALS="$$globals" prove . ; \
 	}
 
+prepare-build-env: $(BASE_SRC)
+	@{ \
+	set -e ; \
+	cwd=`pwd` ; \
+	case $$cwd in $(BUILD_ENV_PATH)*) \
+		echo "You are in $(BUILD_ENV_PATH), skipping" >&2 ; \
+		exit 1 ; \
+	esac ; \
+	if [ -e $(BUILD_ENV_PATH) ]; then \
+		echo "$(BUILD_ENV_PATH) is already exists and going to be removed." ; \
+		echo "Press Enter to continue or Ctrl+C to exit" ; \
+		read ; \
+		rm -rf $(BUILD_ENV_PATH) ; \
+	fi ; \
+	mkdir -p $(BUILD_ENV_PATH) ; \
+	tar -C $(BUILD_ENV_PATH) -xf $(BASE_SRC) ; \
+	cp -rP $${cwd} $(BUILD_ENV_PATH)/nginx-$(BASE_VERSION)/ ; \
+	cp $(BASE_SRC) $(BUILD_ENV_PATH)/nginx_$(BASE_VERSION).orig.tar.gz ; \
+	echo "Build environment has been created in: $(BUILD_ENV_PATH)" ; \
+	echo ; \
+	echo "Please do the following in order to get available build targets:" ; \
+	echo "    cd $(BUILD_ENV_PATH)/nginx-$(BASE_VERSION)/debian" ; \
+	echo "    make" ; \
+	}
+
 clean:
 	@rm -rf base module-* rules-base rules-module-* debuild-base debuild-module-* nginx-tests
 
diff --git a/rpm/SPECS/Makefile b/rpm/SPECS/Makefile
index 4f6c33e..464cd63 100644
--- a/rpm/SPECS/Makefile
+++ b/rpm/SPECS/Makefile
@@ -4,6 +4,7 @@
 BASE_RELEASE=	1
 BASE_SRC=	nginx-$(BASE_VERSION).tar.gz
 SRCPATH?=	../SOURCES
+BUILD_ENV_PATH=	${HOME}/rpmbuild
 
 MODULES=	geoip image-filter njs perl xslt
 
@@ -248,6 +249,9 @@
 
 specs:	nginx.spec $(addsuffix .spec, $(addprefix nginx-module-, $(MODULES)))
 
+$(BASE_SRC):
+	wget http://nginx.org/download/$(BASE_SRC)
+
 $(SRCPATH)/$(BASE_SRC):
 	@cd $(SRCPATH) && wget http://nginx.org/download/$(BASE_SRC)
 
@@ -378,6 +382,32 @@
 	cd nginx-tests && TEST_NGINX_BINARY=$$pwd/base/nginx-debug TEST_NGINX_GLOBALS="$$globals" prove . ; \
 	}
 
+prepare-build-env: $(BASE_SRC)
+	@{ \
+	set -e ; \
+	cwd=`pwd` ; \
+	case $$cwd in $(BUILD_ENV_PATH)*) \
+		echo "You are in $(BUILD_ENV_PATH), skipping" >&2 ; \
+		exit 1 ; \
+	esac ; \
+	if [ -e $(BUILD_ENV_PATH) ]; then \
+		echo "$(BUILD_ENV_PATH) is already exists and going to be removed." ; \
+		echo "Press Enter to continue or Ctrl+C to exit" ; \
+		read ; \
+		rm -rf $(BUILD_ENV_PATH) ; \
+	fi ; \
+	mkdir -p $(BUILD_ENV_PATH) ; \
+	pd=`dirname $${cwd}` ; \
+	cp -rP $${pd}/SPECS $(BUILD_ENV_PATH)/ ; \
+	cp -rP $${pd}/SOURCES $(BUILD_ENV_PATH)/ ; \
+	cp $(BASE_SRC) $(BUILD_ENV_PATH)/SOURCES/ ; \
+	echo "Build environment has been created in: $(BUILD_ENV_PATH)" ; \
+	echo ; \
+	echo "Please do the following in order to get available build targets:" ; \
+	echo "    cd $(BUILD_ENV_PATH)/SPECS" ; \
+	echo "    make" ; \
+	}
+
 clean:
 	@rm -f base module-*
 	@rm -f nginx.spec nginx-module-*.spec