Configure: allow to be run from outside of the source directory.

Note that when run from outside of the source directory, this script
won't generate Makefiles, since there are too many cases to support.

Change-Id: I5db7bde4998134bb98ff027201f45209ff8a2896
Signed-off-by: Piotr Sikora <piotrsikora@google.com>
Reviewed-on: https://nginx-review.googlesource.com/1010
Reviewed-by: Martin Maly <mmaly@google.com>
diff --git a/auto/lib/conf b/auto/lib/conf
index e1e4475..0a0d3dc 100644
--- a/auto/lib/conf
+++ b/auto/lib/conf
@@ -4,7 +4,7 @@
 
 
 if [ $USE_PCRE = YES -o $PCRE != NONE ]; then
-    . auto/lib/pcre/conf
+    . $NGX_AUTO/lib/pcre/conf
 
 else
     if [ $USE_PCRE = DISABLED -a $HTTP_REWRITE = YES ]; then
@@ -22,20 +22,20 @@
 
 
 if [ $USE_OPENSSL = YES ]; then
-    . auto/lib/openssl/conf
+    . $NGX_AUTO/lib/openssl/conf
 fi
 
 if [ $USE_MD5 = YES ]; then
 
     if [ $USE_OPENSSL = YES ]; then
-        have=NGX_HAVE_OPENSSL_MD5_H . auto/have
-        have=NGX_OPENSSL_MD5 . auto/have
-        have=NGX_HAVE_MD5 . auto/have
+        have=NGX_HAVE_OPENSSL_MD5_H . $NGX_AUTO/have
+        have=NGX_OPENSSL_MD5 . $NGX_AUTO/have
+        have=NGX_HAVE_MD5 . $NGX_AUTO/have
         MD5=YES
         MD5_LIB=OpenSSL
 
     else
-        . auto/lib/md5/conf
+        . $NGX_AUTO/lib/md5/conf
     fi
 
 fi
@@ -43,41 +43,41 @@
 if [ $USE_SHA1 = YES ]; then
 
     if [ $USE_OPENSSL = YES ]; then
-        have=NGX_HAVE_OPENSSL_SHA1_H . auto/have
-        have=NGX_HAVE_SHA1 . auto/have
+        have=NGX_HAVE_OPENSSL_SHA1_H . $NGX_AUTO/have
+        have=NGX_HAVE_SHA1 . $NGX_AUTO/have
         SHA1=YES
         SHA1_LIB=OpenSSL
 
     else
-        . auto/lib/sha1/conf
+        . $NGX_AUTO/lib/sha1/conf
     fi
 
 fi
 
 if [ $USE_ZLIB = YES ]; then
-    . auto/lib/zlib/conf
+    . $NGX_AUTO/lib/zlib/conf
 fi
 
 if [ $USE_LIBXSLT = YES ]; then
-    . auto/lib/libxslt/conf
+    . $NGX_AUTO/lib/libxslt/conf
 fi
 
 if [ $USE_LIBGD = YES ]; then
-    . auto/lib/libgd/conf
+    . $NGX_AUTO/lib/libgd/conf
 fi
 
 if [ $USE_PERL = YES ]; then
-    . auto/lib/perl/conf
+    . $NGX_AUTO/lib/perl/conf
 fi
 
 if [ $HTTP_GEOIP = YES ]; then
-    . auto/lib/geoip/conf
+    . $NGX_AUTO/lib/geoip/conf
 fi
 
 if [ $NGX_GOOGLE_PERFTOOLS = YES ]; then
-    . auto/lib/google-perftools/conf
+    . $NGX_AUTO/lib/google-perftools/conf
 fi
 
 if [ $NGX_LIBATOMIC != NO ]; then
-    . auto/lib/libatomic/conf
+    . $NGX_AUTO/lib/libatomic/conf
 fi
diff --git a/auto/lib/geoip/conf b/auto/lib/geoip/conf
index 53c274d..7c8e324 100644
--- a/auto/lib/geoip/conf
+++ b/auto/lib/geoip/conf
@@ -10,7 +10,7 @@
     ngx_feature_path=
     ngx_feature_libs="-lGeoIP"
     ngx_feature_test="GeoIP_open(NULL, 0)"
-    . auto/feature
+    . $NGX_AUTO/feature
 
 
 if [ $ngx_found = no ]; then
@@ -26,7 +26,7 @@
         ngx_feature_libs="-L/usr/local/lib -lGeoIP"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -43,7 +43,7 @@
         ngx_feature_libs="-L/usr/pkg/lib -lGeoIP"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -60,7 +60,7 @@
         ngx_feature_libs="-L/opt/local/lib -lGeoIP"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -78,7 +78,7 @@
         #ngx_feature_path=
         #ngx_feature_libs=
         ngx_feature_test="printf(\"%d\", GEOIP_CITY_EDITION_REV0_V6);"
-        . auto/feature
+        . $NGX_AUTO/feature
     fi
 
 else
diff --git a/auto/lib/google-perftools/conf b/auto/lib/google-perftools/conf
index 5d5ddae..7c350dc 100644
--- a/auto/lib/google-perftools/conf
+++ b/auto/lib/google-perftools/conf
@@ -10,7 +10,7 @@
     ngx_feature_path=
     ngx_feature_libs="-lprofiler"
     ngx_feature_test="ProfilerStop()"
-    . auto/feature
+    . $NGX_AUTO/feature
 
 
 if [ $ngx_found = no ]; then
@@ -25,7 +25,7 @@
         ngx_feature_libs="-L/usr/local/lib -lprofiler"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -41,7 +41,7 @@
         ngx_feature_libs="-L/opt/local/lib -lprofiler"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
diff --git a/auto/lib/libatomic/conf b/auto/lib/libatomic/conf
index d1e484a..28a7a22 100644
--- a/auto/lib/libatomic/conf
+++ b/auto/lib/libatomic/conf
@@ -5,7 +5,7 @@
 
 if [ $NGX_LIBATOMIC != YES ]; then
 
-    have=NGX_HAVE_LIBATOMIC . auto/have
+    have=NGX_HAVE_LIBATOMIC . $NGX_AUTO/have
     CORE_INCS="$CORE_INCS $NGX_LIBATOMIC/src"
     LINK_DEPS="$LINK_DEPS $NGX_LIBATOMIC/src/libatomic_ops.a"
     CORE_LIBS="$CORE_LIBS $NGX_LIBATOMIC/src/libatomic_ops.a"
@@ -27,7 +27,7 @@
                       if (n != 2)
                           return 1;
                       AO_nop();"
-    . auto/feature
+    . $NGX_AUTO/feature
 
     if [ $ngx_found = yes ]; then
         CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
diff --git a/auto/lib/libgd/conf b/auto/lib/libgd/conf
index ff99054..f16d81d 100644
--- a/auto/lib/libgd/conf
+++ b/auto/lib/libgd/conf
@@ -10,7 +10,7 @@
     ngx_feature_path=
     ngx_feature_libs="-lgd"
     ngx_feature_test="gdImagePtr img = gdImageCreateFromGifPtr(1, NULL);"
-    . auto/feature
+    . $NGX_AUTO/feature
 
 
 if [ $ngx_found = no ]; then
@@ -26,7 +26,7 @@
         ngx_feature_libs="-L/usr/local/lib -lgd"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -43,7 +43,7 @@
         ngx_feature_libs="-L/usr/pkg/lib -lgd"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -60,7 +60,7 @@
         ngx_feature_libs="-L/opt/local/lib -lgd"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
diff --git a/auto/lib/libxslt/conf b/auto/lib/libxslt/conf
index bc19d83..e3eb46f 100644
--- a/auto/lib/libxslt/conf
+++ b/auto/lib/libxslt/conf
@@ -19,7 +19,7 @@
                       xmlDocPtr           doc;
                       doc = xmlParseChunk(ctxt, NULL, 0, 0);
                       xsltApplyStylesheet(sheet, doc, NULL);"
-    . auto/feature
+    . $NGX_AUTO/feature
 
 
 if [ $ngx_found = no ]; then
@@ -35,7 +35,7 @@
         ngx_feature_libs="-L/usr/local/lib -lxml2 -lxslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -52,7 +52,7 @@
         ngx_feature_libs="-L/usr/pkg/lib -lxml2 -lxslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -69,7 +69,7 @@
         ngx_feature_libs="-L/opt/local/lib -lxml2 -lxslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -98,7 +98,7 @@
     ngx_feature_path="/usr/include/libxml2"
     ngx_feature_libs="-lexslt"
     ngx_feature_test="exsltRegisterAll();"
-    . auto/feature
+    . $NGX_AUTO/feature
 
 if [ $ngx_found = no ]; then
 
@@ -113,7 +113,7 @@
         ngx_feature_libs="-L/usr/local/lib -lexslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -130,7 +130,7 @@
         ngx_feature_libs="-L/usr/pkg/lib -lexslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
@@ -147,7 +147,7 @@
         ngx_feature_libs="-L/opt/local/lib -lexslt"
     fi
 
-    . auto/feature
+    . $NGX_AUTO/feature
 fi
 
 
diff --git a/auto/lib/make b/auto/lib/make
index 58a84a3..20da2c9 100644
--- a/auto/lib/make
+++ b/auto/lib/make
@@ -4,29 +4,29 @@
 
 
 if [ $PCRE != NONE -a $PCRE != NO -a $PCRE != YES ]; then
-    . auto/lib/pcre/make
+    . $NGX_AUTO/lib/pcre/make
 fi
 
 if [ $MD5 != NONE -a $MD5 != NO -a $MD5 != YES ]; then
-    . auto/lib/md5/make
+    . $NGX_AUTO/lib/md5/make
 fi
 
 if [ $SHA1 != NONE -a $SHA1 != NO -a $SHA1 != YES ]; then
-    . auto/lib/sha1/make
+    . $NGX_AUTO/lib/sha1/make
 fi
 
 if [ $OPENSSL != NONE -a $OPENSSL != NO -a $OPENSSL != YES ]; then
-    . auto/lib/openssl/make
+    . $NGX_AUTO/lib/openssl/make
 fi
 
 if [ $ZLIB != NONE -a $ZLIB != NO -a $ZLIB != YES ]; then
-    . auto/lib/zlib/make
+    . $NGX_AUTO/lib/zlib/make
 fi
 
 if [ $NGX_LIBATOMIC != NO -a $NGX_LIBATOMIC != YES ]; then
-    . auto/lib/libatomic/make
+    . $NGX_AUTO/lib/libatomic/make
 fi
 
 if [ $USE_PERL = YES ]; then
-    . auto/lib/perl/make
+    . $NGX_AUTO/lib/perl/make
 fi
diff --git a/auto/lib/md5/conf b/auto/lib/md5/conf
index eb5dfd1..bb5480d 100644
--- a/auto/lib/md5/conf
+++ b/auto/lib/md5/conf
@@ -8,14 +8,14 @@
     if grep MD5_Init $MD5/md5.h 2>&1 >/dev/null; then
         # OpenSSL md5
         OPENSSL_MD5=YES
-        have=NGX_HAVE_OPENSSL_MD5 . auto/have
-        have=NGX_OPENSSL_MD5 . auto/have
+        have=NGX_HAVE_OPENSSL_MD5 . $NGX_AUTO/have
+        have=NGX_OPENSSL_MD5 . $NGX_AUTO/have
     else
         # rsaref md5
         OPENSSL_MD5=NO
     fi
 
-    have=NGX_HAVE_MD5 . auto/have
+    have=NGX_HAVE_MD5 . $NGX_AUTO/have
     CORE_INCS="$CORE_INCS $MD5"
 
     case "$NGX_CC_NAME" in
@@ -59,7 +59,7 @@
             ngx_feature_path=
             ngx_feature_libs="-lmd"
             ngx_feature_test="MD5_CTX md5; MD5Init(&md5)"
-            . auto/feature
+            . $NGX_AUTO/feature
 
             ngx_md5_lib="system md"
 
@@ -69,7 +69,7 @@
 
             ngx_feature="md5 in system md5 library"
             ngx_feature_libs="-lmd5"
-            . auto/feature
+            . $NGX_AUTO/feature
 
             ngx_md5_lib="system md5"
         fi
@@ -83,13 +83,13 @@
             ngx_feature_incs="#include <openssl/md5.h>"
             ngx_feature_libs="-lcrypto"
             ngx_feature_test="MD5_CTX md5; MD5_Init(&md5)"
-            . auto/feature
+            . $NGX_AUTO/feature
 
             ngx_md5_lib="system crypto"
 
             if [ $ngx_found = yes ]; then
-                have=NGX_HAVE_OPENSSL_MD5_H . auto/have
-                have=NGX_HAVE_MD5 . auto/have
+                have=NGX_HAVE_OPENSSL_MD5_H . $NGX_AUTO/have
+                have=NGX_HAVE_MD5 . $NGX_AUTO/have
             fi
         fi
 
diff --git a/auto/lib/openssl/conf b/auto/lib/openssl/conf
index bca2050..3b3be49 100644
--- a/auto/lib/openssl/conf
+++ b/auto/lib/openssl/conf
@@ -8,8 +8,8 @@
     case "$CC" in
 
         cl | bcc32)
-            have=NGX_OPENSSL . auto/have
-            have=NGX_SSL . auto/have
+            have=NGX_OPENSSL . $NGX_AUTO/have
+            have=NGX_SSL . $NGX_AUTO/have
 
             CFLAGS="$CFLAGS -DNO_SYS_TYPES_H"
 
@@ -25,8 +25,8 @@
         ;;
 
         *)
-            have=NGX_OPENSSL . auto/have
-            have=NGX_SSL . auto/have
+            have=NGX_OPENSSL . $NGX_AUTO/have
+            have=NGX_SSL . $NGX_AUTO/have
 
             CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
             CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
@@ -53,7 +53,7 @@
         ngx_feature_path=
         ngx_feature_libs="-lssl -lcrypto"
         ngx_feature_test="SSL_library_init()"
-        . auto/feature
+        . $NGX_AUTO/feature
 
         if [ $ngx_found = no ]; then
 
@@ -68,7 +68,7 @@
                 ngx_feature_libs="-L/usr/local/lib -lssl -lcrypto"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = no ]; then
@@ -84,7 +84,7 @@
                 ngx_feature_libs="-L/usr/pkg/lib -lssl -lcrypto"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = no ]; then
@@ -100,11 +100,11 @@
                 ngx_feature_libs="-L/opt/local/lib -lssl -lcrypto"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = yes ]; then
-            have=NGX_SSL . auto/have
+            have=NGX_SSL . $NGX_AUTO/have
             CORE_LIBS="$CORE_LIBS $ngx_feature_libs $NGX_LIBDL"
             OPENSSL=YES
         fi
diff --git a/auto/lib/pcre/conf b/auto/lib/pcre/conf
index 939f01b..6665897 100644
--- a/auto/lib/pcre/conf
+++ b/auto/lib/pcre/conf
@@ -9,15 +9,15 @@
     case "$NGX_CC_NAME" in
 
         msvc* | owc* | bcc)
-            have=NGX_PCRE . auto/have
-            have=PCRE_STATIC . auto/have
+            have=NGX_PCRE . $NGX_AUTO/have
+            have=PCRE_STATIC . $NGX_AUTO/have
             CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
             LINK_DEPS="$LINK_DEPS $PCRE/pcre.lib"
             CORE_LIBS="$CORE_LIBS $PCRE/pcre.lib"
         ;;
 
         icc* )
-            have=NGX_PCRE . auto/have
+            have=NGX_PCRE . $NGX_AUTO/have
             CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
 
             LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
@@ -72,10 +72,10 @@
         ;;
 
         *)
-            have=NGX_PCRE . auto/have
+            have=NGX_PCRE . $NGX_AUTO/have
 
             if [ "$NGX_PLATFORM" = win32 ]; then
-                have=PCRE_STATIC . auto/have
+                have=PCRE_STATIC . $NGX_AUTO/have
             fi
 
             CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
@@ -87,7 +87,7 @@
 
 
     if [ $PCRE_JIT = YES ]; then
-        have=NGX_HAVE_PCRE_JIT . auto/have
+        have=NGX_HAVE_PCRE_JIT . $NGX_AUTO/have
         PCRE_CONF_OPT="$PCRE_CONF_OPT --enable-jit"
     fi
 
@@ -106,7 +106,7 @@
         ngx_feature_test="pcre *re;
                           re = pcre_compile(NULL, 0, NULL, 0, NULL);
                           if (re == NULL) return 1"
-        . auto/feature
+        . $NGX_AUTO/feature
 
         if [ $ngx_found = no ]; then
 
@@ -121,7 +121,7 @@
                 ngx_feature_libs="-L/usr/local/lib -lpcre"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = no ]; then
@@ -132,7 +132,7 @@
             ngx_feature_path="/usr/include/pcre"
             ngx_feature_libs="-lpcre"
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = no ]; then
@@ -148,7 +148,7 @@
                 ngx_feature_libs="-L/usr/pkg/lib -lpcre"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = no ]; then
@@ -164,7 +164,7 @@
                 ngx_feature_libs="-L/opt/local/lib -lpcre"
             fi
 
-            . auto/feature
+            . $NGX_AUTO/feature
         fi
 
         if [ $ngx_found = yes ]; then
@@ -180,7 +180,7 @@
                               pcre_free_study(NULL);
                               pcre_config(PCRE_CONFIG_JIT, &jit);
                               if (jit != 1) return 1;"
-            . auto/feature
+            . $NGX_AUTO/feature
 
             if [ $ngx_found = yes ]; then
                 PCRE_JIT=YES
diff --git a/auto/lib/perl/conf b/auto/lib/perl/conf
index 2a1a3fe..5be94c8 100644
--- a/auto/lib/perl/conf
+++ b/auto/lib/perl/conf
@@ -45,7 +45,7 @@
     ngx_perl_module="$ngx_perl_libdir/nginx/nginx.$ngx_perl_dlext"
 
     if $NGX_PERL -V:usemultiplicity | grep define > /dev/null; then
-        have=NGX_HAVE_PERL_MULTIPLICITY . auto/have
+        have=NGX_HAVE_PERL_MULTIPLICITY . $NGX_AUTO/have
         echo " + perl interpreter multiplicity found"
     fi
 
@@ -65,7 +65,7 @@
 
     if test -n "$NGX_PERL_MODULES"; then
         have=NGX_PERL_MODULES value="(u_char *) \"$NGX_PERL_MODULES\""
-        . auto/define
+        . $NGX_AUTO/define
         NGX_PERL_MODULES_MAN=$NGX_PERL_MODULES/man3
     fi
 
diff --git a/auto/lib/sha1/conf b/auto/lib/sha1/conf
index fd69afd..ccc672a 100644
--- a/auto/lib/sha1/conf
+++ b/auto/lib/sha1/conf
@@ -5,7 +5,7 @@
 
 if [ $SHA1 != NONE ]; then
 
-    have=NGX_HAVE_SHA1 . auto/have
+    have=NGX_HAVE_SHA1 . $NGX_AUTO/have
     CORE_INCS="$CORE_INCS $SHA1"
 
     case "$NGX_CC_NAME" in
@@ -49,7 +49,7 @@
         ngx_feature_path=
         ngx_feature_libs="-lmd"
         ngx_feature_test="SHA_CTX sha1; SHA1_Init(&sha1)"
-        . auto/feature
+        . $NGX_AUTO/feature
 
         ngx_sha1_lib="system md"
 
@@ -60,12 +60,12 @@
             ngx_feature="sha1 in system OpenSSL crypto library"
             ngx_feature_incs="#include <openssl/sha.h>"
             ngx_feature_libs="-lcrypto"
-            . auto/feature
+            . $NGX_AUTO/feature
 
             ngx_sha1_lib="system crypto"
 
             if [ $ngx_found = yes ]; then
-                have=NGX_HAVE_OPENSSL_SHA1_H . auto/have
+                have=NGX_HAVE_OPENSSL_SHA1_H . $NGX_AUTO/have
             fi
         fi
 
diff --git a/auto/lib/zlib/conf b/auto/lib/zlib/conf
index 26db642..b9011a3 100644
--- a/auto/lib/zlib/conf
+++ b/auto/lib/zlib/conf
@@ -9,13 +9,13 @@
     case "$NGX_CC_NAME" in
 
         msvc* | owc* | bcc)
-            have=NGX_ZLIB . auto/have
+            have=NGX_ZLIB . $NGX_AUTO/have
             LINK_DEPS="$LINK_DEPS $ZLIB/zlib.lib"
             CORE_LIBS="$CORE_LIBS $ZLIB/zlib.lib"
         ;;
 
         icc*)
-            have=NGX_ZLIB . auto/have
+            have=NGX_ZLIB . $NGX_AUTO/have
             LINK_DEPS="$LINK_DEPS $ZLIB/libz.a"
 
             # to allow -ipo optimization we link with the *.o but not library
@@ -32,7 +32,7 @@
         ;;
 
         *)
-            have=NGX_ZLIB . auto/have
+            have=NGX_ZLIB . $NGX_AUTO/have
             LINK_DEPS="$LINK_DEPS $ZLIB/libz.a"
             CORE_LIBS="$CORE_LIBS $ZLIB/libz.a"
             #CORE_LIBS="$CORE_LIBS -L $ZLIB -lz"
@@ -54,7 +54,7 @@
         ngx_feature_path=
         ngx_feature_libs="-lz"
         ngx_feature_test="z_stream z; deflate(&z, Z_NO_FLUSH)"
-        . auto/feature
+        . $NGX_AUTO/feature
 
 
         if [ $ngx_found = yes ]; then