From 31c7acee0a6a7792453dae8b63390d8e433a1c74 Mon Sep 17 00:00:00 2001
From: Robert Story <rstory@localhost>
Date: Wed, 11 Apr 2012 14:13:53 -0400
Subject: [PATCH 03/22] NSPR add dnssec options/flags to configure/makefiles

---
 nsprpub/config/autoconf.mk.in |  12 +++--
 nsprpub/config/config.mk      |   5 ++
 nsprpub/config/nspr-config.in |   6 +--
 nsprpub/configure.in          | 105 ++++++++++++++++++++++++++++++++++++++++++
 nsprpub/pr/tests/Makefile.in  |   6 +++
 5 files changed, 127 insertions(+), 7 deletions(-)

diff --git a/nsprpub/config/autoconf.mk.in b/nsprpub/config/autoconf.mk.in
index 5f093c4..547287b 100644
--- a/nsprpub/config/autoconf.mk.in
+++ b/nsprpub/config/autoconf.mk.in
@@ -80,10 +80,10 @@ CYGWIN_WRAPPER	= @CYGWIN_WRAPPER@
 MT		= @MT@
 
 OS_CPPFLAGS	= @CPPFLAGS@
-OS_CFLAGS	= $(OS_CPPFLAGS) @CFLAGS@ $(DSO_CFLAGS)
-OS_CXXFLAGS	= $(OS_CPPFLAGS) @CXXFLAGS@ $(DSO_CFLAGS)
-OS_LIBS         = @OS_LIBS@
-OS_LDFLAGS	= @LDFLAGS@
+OS_CFLAGS	= $(OS_CPPFLAGS) @CFLAGS@ $(DSO_CFLAGS) $(VAL_CFLAGS)
+OS_CXXFLAGS	= $(OS_CPPFLAGS) @CXXFLAGS@ $(DSO_CFLAGS) $(VAL_CFLAGS)
+OS_LIBS         = @OS_LIBS@ $(VAL_LIBS)
+OS_LDFLAGS	= @LDFLAGS@ $(VAL_LDFLAGS)
 OS_DLLFLAGS	= @OS_DLLFLAGS@
 DLLFLAGS	= @DLLFLAGS@
 EXEFLAGS  = @EXEFLAGS@
@@ -99,6 +99,10 @@ WRAP_LDFLAGS	= @WRAP_LDFLAGS@
 DSO_CFLAGS	= @DSO_CFLAGS@
 DSO_LDOPTS	= @DSO_LDOPTS@
 
+VAL_CFLAGS	= @VAL_CFLAGS@
+VAL_LDFLAGS	= @VAL_LDFLAGS@ $(VAL_LIBS)
+VAL_LIBS	= @VAL_LIBS@
+
 RESOLVE_LINK_SYMBOLS = @RESOLVE_LINK_SYMBOLS@
 
 HOST_CC		= @HOST_CC@
diff --git a/nsprpub/config/config.mk b/nsprpub/config/config.mk
index 05db076..9807860 100644
--- a/nsprpub/config/config.mk
+++ b/nsprpub/config/config.mk
@@ -63,6 +63,11 @@ endif
 endif # MOZ_PROFILE_USE
 endif # NO_PROFILE_GUIDED_OPTIMIZE
 
+ifdef MOZ_DNSSEC
+CFLAGS += $(VAL_CFLAGS)
+LDFLAGS += $(VAL_LDFLAGS)
+endif # MOZ_DNSSEC
+
 define MAKE_OBJDIR
 if test ! -d $(@D); then rm -rf $(@D); $(NSINSTALL) -D $(@D); fi
 endef
diff --git a/nsprpub/config/nspr-config.in b/nsprpub/config/nspr-config.in
index 2cb62a0..b03607b 100755
--- a/nsprpub/config/nspr-config.in
+++ b/nsprpub/config/nspr-config.in
@@ -122,7 +122,7 @@ if test "$echo_libdir" = "yes"; then
 fi
 
 if test "$echo_cflags" = "yes"; then
-    echo -I$includedir
+    echo -I$includedir @VAL_CFLAGS@
 fi
 
 if test "$echo_libs" = "yes"; then
@@ -136,12 +136,12 @@ if test "$echo_libs" = "yes"; then
       if test -n "$lib_nspr"; then
 	libdirs="$libdirs -lnspr${major_version}"
       fi
-      os_ldflags="@LDFLAGS@"
+      os_ldflags="@LDFLAGS@ @VAL_LDFLAGS@"
       for i in $os_ldflags ; do
 	if echo $i | grep \^-L >/dev/null; then
 	  libdirs="$libdirs $i"
         fi
       done
-      echo $libdirs @OS_LIBS@
+      echo $libdirs @OS_LIBS@ @VAL_LIBS@
 fi      
 
diff --git a/nsprpub/configure.in b/nsprpub/configure.in
index a07e384..8148ab9 100644
--- a/nsprpub/configure.in
+++ b/nsprpub/configure.in
@@ -2547,6 +2547,7 @@ dnl AC_HEADER_STDC
 dnl AC_HEADER_SYS_WAIT
 dnl AC_CHECK_HEADERS(fcntl.h limits.h sys/file.h sys/ioctl.h sys/time.h unistd.h)
 
+
 dnl ========================================================
 dnl Check for typedefs and structs
 dnl ========================================================
@@ -3065,6 +3066,110 @@ AC_ARG_WITH(wrap-malloc,
     WRAP_LDFLAGS="${WRAP_LDFLAGS} $withval")
 
 dnl ========================================================
+dnl = Add DNSSEC support
+dnl ========================================================
+
+AC_ARG_WITH(system-val,
+[  --with-system-val[=PFX]
+                  Use system DNSSEC validator [installed at prefix PFX]],
+   ,
+   [with_system_val=no])
+
+AC_ARG_WITH(system-openssl,
+[  --with-system-openssl[=PFX]
+                  Use system openssl libraries [installed at prefix PFX]],
+   ,
+   [with_system_openssl=no])
+
+_SAVE_LDFLAGS="$LDFLAGS"
+_SAVE_CFLAGS="$CFLAGS"
+VAL_LIBS=""
+VAL_CFLAGS=""
+VAL_LDFLAGS=""
+OPENSSL_LIBS=""
+if test "x$with_system_val" != xno; then
+  if test "x$with_system_val" != xyes; then
+    VAL_CFLAGS="-I${with_system_val}/include"
+    VAL_LDFLAGS="-L${with_system_val}/lib"
+  fi
+  if test -n "$_WIN32_MSVC"; then
+    VAL_LIBS="${with_system_val}/lib/libval-threads.a ${with_system_val}/lib/libsres.a ${with_system_val}/lib/libcrypto.a ${with_system_val}/lib/libpthread.dll.a ${with_system_val}/lib/libgcc.a user32.lib gdi32.lib Ws2_32.lib"
+    AC_DEFINE(MOZ_DNSSEC)
+  else
+    if test "x$with_system_openssl" != xno; then
+        if test "x$with_system_openssl" != xyes; then
+            CFLAGS="$CFLAGS -I${with_system_openssl}/include"
+            LDFLAGS="$LDFLAGS -L${with_system_openssl}/lib"
+            OPENSSL_PATH="${with_system_openssl}"
+        else
+            OPENSSL_PATH="/usr/lib"
+        fi
+    else
+        OPENSSL_PATH="/usr/lib"
+    fi
+    LDFLAGS="$LDFLAGS $VAL_LDFLAGS"
+    CFLAGS="$CFLAGS $VAL_CFLAGS"
+    AC_CHECK_LIB(crypto, EVP_md5, OPENSSL_LIBS="-lcrypto")
+
+    dnl look for static lib
+    AC_CHECK_LIB(ssl, SSL_get_SSL_CTX, , [AC_MSG_ERROR(Cannot find OpenSSL libraries.)])
+    if test -n "$USE_64"; then
+       if test -e "${OPENSSL_PATH}64/libssl.a"; then
+          OPENSSL_LIBS="$OPENSSL_LIBS ${OPENSSL_PATH}64/libssl.a"
+       elif test -e "${OPENSSL_PATH}/libssl.a"; then
+          OPENSSL_LIBS="$OPENSSL_LIBS $OPENSSL_PATH/libssl.a"
+       else
+          AC_MSG_ERROR("Static SSL library not found.")
+       fi
+    else
+       if test -e "${OPENSSL_PATH}/libssl.a"; then
+          OPENSSL_LIBS="$OPENSSL_LIBS $OPENSSL_PATH/libssl.a"
+       else
+          AC_MSG_ERROR("Static SSL library not found.")
+       fi
+    fi
+
+    dnl with static openssl, apparently we need to pull in libkrb5
+    AC_CHECK_LIB(krb5, krb5_init_context, OPENSSL_LIBS="$OPENSSL_LIBS -lkrb5")
+    AC_CHECK_LIB(k5crypto, krb5_checksum_size, OPENSSL_LIBS="$OPENSSL_LIBS -lk5crypto")
+
+    dnl val-threads check
+    AC_CHECK_LIB(val-threads, val_gethostbyname,
+        [VAL_LIBS="-lval-threads -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS}"
+         AC_DEFINE(MOZ_DNSSEC)],
+         [AC_MSG_ERROR(Cannot find val_gethostbyname.)],
+        -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS})
+  fi
+  dnl functions added in 1.11
+  AC_CHECK_LIB(val-threads, val_getaddrinfo_submit,
+                AC_DEFINE(HAVE_VAL_GETADDRINFO_SUBMIT), ,
+                -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS})
+  dnl functions added in 1.12
+  AC_CHECK_LIB(val-threads, val_context_setqflags,
+                AC_DEFINE(HAVE_VAL_CONTEXT_SETQFLAGS), ,
+                -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS})
+
+  dnl functions added in 1.13
+  AC_CHECK_LIB(val-threads, val_freeaddrinfo,
+                AC_DEFINE(HAVE_VAL_FREEADDRINFO), ,
+                -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS})
+  AC_CHECK_LIB(val-threads, val_getaddrinfo_cancel,
+                AC_DEFINE(HAVE_VAL_GETADDRINFO_CANCEL), ,
+                -lsres ${OPENSSL_LIBS} ${_PTHREAD_LDFLAGS})
+fi
+LDFLAGS="$_SAVE_LDFLAGS"
+CFLAGS="$_SAVE_CFLAGS"
+
+AC_SUBST(VAL_LIBS)
+AC_SUBST(VAL_CFLAGS)
+AC_SUBST(VAL_LDFLAGS)
+AC_SUBST(HAVE_VAL_CONTEXT_SETQFLAGS)
+AC_SUBST(HAVE_VAL_GETADDRINFO_SUBMIT)
+AC_SUBST(HAVE_VAL_FREEADDRINFO)
+AC_SUBST(HAVE_VAL_GETADDRINFO_CANCEL)
+AC_SUBST(MOZ_DNSSEC)
+
+dnl ========================================================
 dnl Substitution of found variables.
 dnl ========================================================
 AC_SUBST(SHELL_OVERRIDE)
diff --git a/nsprpub/pr/tests/Makefile.in b/nsprpub/pr/tests/Makefile.in
index 50e8776..6a63112 100644
--- a/nsprpub/pr/tests/Makefile.in
+++ b/nsprpub/pr/tests/Makefile.in
@@ -379,6 +379,10 @@ LIBPTHREAD =
 XCFLAGS = $(OS_CFLAGS)
 endif
 
+ifneq ($(VAL_LIBS),)
+EXTRA_LIBS += $(OS_LDFLAGS) $(OS_LIBS)
+endif
+
 #####################################################
 #
 # The rules
@@ -458,6 +462,8 @@ $(OBJDIR)/socket: $(OBJDIR)/socket.o
 	$(PURE) $(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBNSPR) $(LIBPTHREAD) $(EXTRA_LIBS) -o $@
 $(OBJDIR)/testfile: $(OBJDIR)/testfile.o
 	$(PURE) $(CC) $(XCFLAGS) $< $(LDOPTS) $(LIBPLC) $(LIBNSPR) $(LIBPTHREAD) $(EXTRA_LIBS) -o $@
+$(OBJDIR)/getai: $(OBJDIR)/getai.o
+	$(PURE) $(CC) $(XCFLAGS) $(DEFINES) $< $(LDOPTS) $(LIBPLC) $(LIBNSPR) $(LIBPTHREAD) $(EXTRA_LIBS) -o $@
 endif
 
 #
-- 
1.7.11.7

