Pārlūkot izejas kodu

Merge branch 'symbol-generating'

* symbol-generating:
  * Check for valid sed at configure
  * Delete tmpfile when bailing out
  * Place -I in INCLUDES var
  * Use gsed if available
  * Bail out if symbols fail to generate
  * Use sed instead of perl
  * Pass CXX and INCLUDES into generate_defs.sh
  * No longer need to define these headers
  * Generate typedefs from headers if available
Bryan Drewery 14 gadi atpakaļ
vecāks
revīzija
e3fbbfeef9
6 mainītis faili ar 142 papildinājumiem un 85 dzēšanām
  1. 7 1
      autotools/configure.ac
  2. 94 8
      configure
  3. 41 6
      src/generate_defs.sh
  4. 0 47
      src/libcrypto.h
  5. 0 16
      src/libssl.h
  6. 0 7
      src/libtcl.h

+ 7 - 1
autotools/configure.ac

@@ -38,6 +38,7 @@ AC_CACHE_SAVE
 
 # Checks for programs
 AC_PROG_MAKE_SET
+AC_PROG_SED
 EGG_PROG_HEAD_1
 EGG_PROG_AWK
 EGG_PROG_BASENAME
@@ -271,7 +272,12 @@ if [ "$GIT_REQUIRED" = "1" ]; then
 fi
 ]
 
-src/generate_defs.sh
+CXX="$CXX" TCLINC="$TCLINC" SSL_INCLUDES="$SSL_INCLUDES" SED="$SED" src/generate_defs.sh
+[
+if [ $? -ne 0 ]; then
+  exit 1
+fi
+]
 
 echo ""
 echo ""

+ 94 - 8
configure

@@ -633,6 +633,7 @@ OBJCOPY
 BASENAME
 AWK
 HEAD_1
+SED
 SET_MAKE
 GCC4DEB
 GCC3DEB
@@ -3840,6 +3841,75 @@ $as_echo "no" >&6; }
   SET_MAKE="MAKE=${MAKE-make}"
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a sed that does not truncate output" >&5
+$as_echo_n "checking for a sed that does not truncate output... " >&6; }
+if ${ac_cv_path_SED+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+            ac_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/
+     for ac_i in 1 2 3 4 5 6 7; do
+       ac_script="$ac_script$as_nl$ac_script"
+     done
+     echo "$ac_script" 2>/dev/null | sed 99q >conftest.sed
+     { ac_script=; unset ac_script;}
+     if test -z "$SED"; then
+  ac_path_SED_found=false
+  # Loop through the user's path and test for each of PROGNAME-LIST
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_prog in sed gsed; do
+    for ac_exec_ext in '' $ac_executable_extensions; do
+      ac_path_SED="$as_dir/$ac_prog$ac_exec_ext"
+      { test -f "$ac_path_SED" && $as_test_x "$ac_path_SED"; } || continue
+# Check for GNU ac_path_SED and select it if it is found.
+  # Check for GNU $ac_path_SED
+case `"$ac_path_SED" --version 2>&1` in
+*GNU*)
+  ac_cv_path_SED="$ac_path_SED" ac_path_SED_found=:;;
+*)
+  ac_count=0
+  $as_echo_n 0123456789 >"conftest.in"
+  while :
+  do
+    cat "conftest.in" "conftest.in" >"conftest.tmp"
+    mv "conftest.tmp" "conftest.in"
+    cp "conftest.in" "conftest.nl"
+    $as_echo '' >> "conftest.nl"
+    "$ac_path_SED" -f conftest.sed < "conftest.nl" >"conftest.out" 2>/dev/null || break
+    diff "conftest.out" "conftest.nl" >/dev/null 2>&1 || break
+    as_fn_arith $ac_count + 1 && ac_count=$as_val
+    if test $ac_count -gt ${ac_path_SED_max-0}; then
+      # Best one so far, save it but keep looking for a better one
+      ac_cv_path_SED="$ac_path_SED"
+      ac_path_SED_max=$ac_count
+    fi
+    # 10*(2^10) chars as input seems more than enough
+    test $ac_count -gt 10 && break
+  done
+  rm -f conftest.in conftest.tmp conftest.nl conftest.out;;
+esac
+
+      $ac_path_SED_found && break 3
+    done
+  done
+  done
+IFS=$as_save_IFS
+  if test -z "$ac_cv_path_SED"; then
+    as_fn_error $? "no acceptable sed could be found in \$PATH" "$LINENO" 5
+  fi
+else
+  ac_cv_path_SED=$SED
+fi
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_path_SED" >&5
+$as_echo "$ac_cv_path_SED" >&6; }
+ SED="$ac_cv_path_SED"
+  rm -f conftest.sed
+
 
 cat << 'EOF' > conftest.head
 a
@@ -5768,7 +5838,7 @@ $as_echo_n "checking whether the Tcl system has changed... " >&6; }
   egg_tcl_id="${TCLLIB}:${TCLLIBFN}:${TCLINC}:${TCLINCFN}"
   if test "$egg_tcl_id" != ":::"; then
     egg_tcl_cached="yes"
-    if test "${egg_cv_var_tcl_id+set}" = set; then :
+    if ${egg_cv_var_tcl_id+:} false; then :
   $as_echo_n "(cached) " >&6
 else
 
@@ -5807,7 +5877,7 @@ $as_echo "no" >&6; }
 
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl version" >&5
 $as_echo_n "checking for Tcl version... " >&6; }
-    if test "${egg_cv_var_tcl_version+set}" = set; then :
+    if ${egg_cv_var_tcl_version+:} false; then :
   $as_echo_n "(cached) " >&6
 else
 
@@ -5831,7 +5901,7 @@ $as_echo "not found" >&6; }
     fi
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl patch level" >&5
 $as_echo_n "checking for Tcl patch level... " >&6; }
-    if test "${egg_cv_var_tcl_patch_level+set}" = set; then :
+    if ${egg_cv_var_tcl_patch_level+:} false; then :
   $as_echo_n "(cached) " >&6
 else
 
@@ -5905,7 +5975,7 @@ EOF
   as_ac_Lib=`$as_echo "ac_cv_lib_$TCL_TEST_LIB''_Tcl_Free" | $as_tr_sh`
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl_Free in -l$TCL_TEST_LIB" >&5
 $as_echo_n "checking for Tcl_Free in -l$TCL_TEST_LIB... " >&6; }
-if eval "test \"\${$as_ac_Lib+set}\"" = set; then :
+if eval \${$as_ac_Lib+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -5964,7 +6034,7 @@ $as_echo "#define HAVE_TCL_FREE 1" >>confdefs.h
   as_ac_Lib=`$as_echo "ac_cv_lib_$TCL_TEST_LIB''_Tcl_SetNotifier" | $as_tr_sh`
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl_SetNotifier in -l$TCL_TEST_LIB" >&5
 $as_echo_n "checking for Tcl_SetNotifier in -l$TCL_TEST_LIB... " >&6; }
-if eval "test \"\${$as_ac_Lib+set}\"" = set; then :
+if eval \${$as_ac_Lib+:} false; then :
   $as_echo_n "(cached) " >&6
 else
   ac_check_lib_save_LIBS=$LIBS
@@ -6127,10 +6197,21 @@ $as_echo "$as_me: WARNING: cache variable $ac_var contains a newline" >&2;} ;;
      :end' >>confcache
 if diff "$cache_file" confcache >/dev/null 2>&1; then :; else
   if test -w "$cache_file"; then
-    test "x$cache_file" != "x/dev/null" &&
+    if test "x$cache_file" != "x/dev/null"; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: updating cache $cache_file" >&5
 $as_echo "$as_me: updating cache $cache_file" >&6;}
-    cat confcache >$cache_file
+      if test ! -f "$cache_file" || test -h "$cache_file"; then
+	cat confcache >"$cache_file"
+      else
+        case $cache_file in #(
+        */* | ?:*)
+	  mv -f confcache "$cache_file"$$ &&
+	  mv -f "$cache_file"$$ "$cache_file" ;; #(
+        *)
+	  mv -f confcache "$cache_file" ;;
+	esac
+      fi
+    fi
   else
     { $as_echo "$as_me:${as_lineno-$LINENO}: not updating unwritable cache $cache_file" >&5
 $as_echo "$as_me: not updating unwritable cache $cache_file" >&6;}
@@ -9833,7 +9914,12 @@ if [ "$GIT_REQUIRED" = "1" ]; then
 fi
 
 
-src/generate_defs.sh
+CXX="$CXX" TCLINC="$TCLINC" SSL_INCLUDES="$SSL_INCLUDES" SED="$SED" src/generate_defs.sh
+
+if [ $? -ne 0 ]; then
+  exit 1
+fi
+
 
 echo ""
 echo ""

+ 41 - 6
src/generate_defs.sh

@@ -1,26 +1,61 @@
 #! /bin/bash
 
+if [ -z "$SED" -o -z "$CXX" ]; then
+  echo "This must be ran by configure" >&2
+  exit 1
+fi
 echo "Generating lib symbols"
+INCLUDES="-I${TCLINC} ${SSL_INCLUDES}"
 
 mkdir -p src/.defs > /dev/null 2>&1
-
+TMPFILE=$(mktemp "/tmp/pre.XXXXXX")
 for file in $(grep -l DLSYM_GLOBAL src/*.c|grep -v "src/_"); do
   defsFile_wrappers="src/.defs/$(basename $file .c)_defs.c"
   defsFile_pre="src/.defs/$(basename $file .c)_pre.h"
   defsFile_post="src/.defs/$(basename $file .c)_post.h"
 
-  rm -f $defsFile_pre $defsFile_post > /dev/null 2>&1
+  rm -f $defsFile_pre $defsFile_post $defsFile_wrappers > /dev/null 2>&1
+  touch $defsFile_pre $defsFile_post $defsFile_wrappers
+done
+
+for file in $(grep -l DLSYM_GLOBAL src/*.c|grep -v "src/_"); do
+  defsFile_wrappers="src/.defs/$(basename $file .c)_defs.c"
+  defsFile_pre="src/.defs/$(basename $file .c)_pre.h"
+  defsFile_post="src/.defs/$(basename $file .c)_post.h"
 
   echo "extern \"C\" {" > $defsFile_wrappers
   echo "extern \"C\" {" > $defsFile_post
-
-  for symbol in $(sed -n -e 's/.*DLSYM_GLOBAL(.*, \([^)]*\).*/\1/p' $file|sort -u); do
+  touch $defsFile_pre
+  pushd src >/dev/null 2>&1
+  $CXX -E -I. -I.. -I../lib ${INCLUDES} -DHAVE_CONFIG_H ../${file} > $TMPFILE
+  # Fix wrapped prototypes
+  $SED -i -e ':a;N;$!ba;s/,\n/,/g' $TMPFILE
+  popd >/dev/null 2>&1
+
+  for symbol in $($SED -n -e 's/.*DLSYM_GLOBAL(.*, \([^)]*\).*/\1/p' $file|sort -u); do
     echo "#define ${symbol} ORIGINAL_SYMBOL_${symbol}" >> $defsFile_pre
     echo "#undef ${symbol}" >> $defsFile_post
-    grep "^typedef .*(\*${symbol}_t)" $(dirname $file)/$(basename $file .c).h | src/generate_symbol.sh >> $defsFile_wrappers 2>> $defsFile_post
+    # Check if the typedef is already defined ...
+    typedef=$(grep "^typedef .*(\*${symbol}_t)" $(dirname $file)/$(basename $file .c).h)
+    # ... if not, generate it
+    if [ -z "$typedef" ]; then
+      # Trim off any extern "C", trim out the variable names, cleanup whitespace issues
+      typedef=$($SED -n -e "/\<${symbol}\>/p" $TMPFILE | head -n 1 | $SED -e 's/extern "C" *//' -e "s/\(.*\) *${symbol} *(\(.*\));/typedef \1 (*${symbol}_t)(\2);/" -e 's/[_0-9A-Za-z]*\(,\)/\1/g' -e 's/[_0-9A-Za-z]*\();\)/\1/g' -e 's/  */ /g' -e 's/ \([,)]\)/\1/g' -e 's/ *()/(void)/g')
+      echo "$typedef" >> $defsFile_post
+    fi
+
+    if [ "${typedef%;}" = "${typedef}" ]; then
+      echo "Error: Unable to generate typedef for: ${symbol}" >&2
+      echo "$typedef"
+      rm -rf $TMPFILE
+      exit 1
+    fi
+
+    #pipe typedef into generate_symbol.sh
+    echo "$typedef" | src/generate_symbol.sh >> $defsFile_wrappers 2>> $defsFile_post
   done
 
   echo "}" >> $defsFile_wrappers
   echo "}" >> $defsFile_post
 done
-
+rm -f $TMPFILE

+ 0 - 47
src/libcrypto.h

@@ -25,54 +25,7 @@
 #include "dl.h"
 #include <bdlib/src/String.h>
 
-typedef void (*AES_cbc_encrypt_t)(const unsigned char*, unsigned char*, const size_t, const AES_KEY*, unsigned char*, const int);
-typedef void (*AES_decrypt_t)(const unsigned char*, unsigned char*, const AES_KEY*);
-typedef void (*AES_encrypt_t)(const unsigned char*, unsigned char*, const AES_KEY*);
-typedef int (*AES_set_decrypt_key_t)(const unsigned char*, const int, AES_KEY*);
-typedef int (*AES_set_encrypt_key_t)(const unsigned char*, const int, AES_KEY*);
 
-typedef void (*BF_decrypt_t)(BF_LONG*, const BF_KEY*);
-typedef void (*BF_encrypt_t)(BF_LONG*, const BF_KEY*);
-typedef void (*BF_set_key_t)(BF_KEY*, int, const unsigned char*);
-
-typedef char* (*ERR_error_string_t)(unsigned long, char*);
-typedef void (*ERR_free_strings_t)(void);
-typedef unsigned long (*ERR_get_error_t)(void);
-
-typedef void (*OPENSSL_cleanse_t)(void*, size_t);
-
-typedef const char* (*RAND_file_name_t)(char*, size_t);
-typedef int (*RAND_load_file_t)(const char*, long);
-typedef void (*RAND_seed_t)(const void*, int);
-typedef int (*RAND_status_t)(void);
-typedef int (*RAND_write_file_t)(const char*);
-
-typedef int (*MD5_Final_t)(unsigned char*, MD5_CTX*);
-typedef int (*MD5_Init_t)(MD5_CTX*);
-typedef int (*MD5_Update_t)(MD5_CTX*, const void*, size_t);
-typedef int (*SHA1_Final_t)(unsigned char*, SHA_CTX*);
-typedef int (*SHA1_Init_t)(SHA_CTX*);
-typedef int (*SHA1_Update_t)(SHA_CTX*, const void*, size_t);
-typedef int (*SHA256_Final_t)(unsigned char*, SHA256_CTX *);
-typedef int (*SHA256_Init_t)(SHA256_CTX*);
-typedef int (*SHA256_Update_t)(SHA256_CTX*, const void*, size_t);
-
-typedef BIGNUM* (*BN_bin2bn_t)(const unsigned char*, int, BIGNUM*);
-typedef BIGNUM* (*BN_dup_t)(const BIGNUM*);
-typedef int (*BN_bn2bin_t)(const BIGNUM*, unsigned char*);
-typedef int (*BN_dec2bn_t)(BIGNUM**, const char*);
-typedef int (*BN_hex2bn_t)(BIGNUM**, const char*);
-typedef int (*BN_num_bits_t)(const BIGNUM*);
-typedef void (*BN_clear_free_t)(BIGNUM*);
-
-typedef int (*DH_compute_key_t)(unsigned char*, const BIGNUM*, DH*);
-typedef void (*DH_free_t)(DH*);
-typedef int (*DH_generate_key_t)(DH*);
-typedef DH* (*DH_new_t)(void);
-typedef int (*DH_size_t)(const DH*);
-
-typedef void (*EVP_cleanup_t)(void);
-typedef void (*CRYPTO_cleanup_all_ex_data_t)(void);
 
 int load_libcrypto();
 int unload_libcrypto();

+ 0 - 16
src/libssl.h

@@ -22,22 +22,6 @@ typedef DH* (*dh_callback_t)(SSL*, int, int);
 
 #include ".defs/libssl_post.h"
 
-typedef int (*SSL_get_error_t)(const SSL*, int);
-typedef void (*SSL_free_t)(SSL*);
-typedef int (*SSL_connect_t)(SSL*);
-typedef int (*SSL_read_t)(SSL*, void*, int);
-typedef int (*SSL_write_t)(SSL*, const void*, int);
-typedef SSL* (*SSL_new_t)(SSL_CTX*);
-typedef const SSL_METHOD* (*SSLv23_client_method_t)(void);
-typedef int (*SSL_shutdown_t)(SSL*);
-typedef int (*SSL_set_fd_t)(SSL*, int);
-typedef int (*SSL_pending_t)(const SSL*);
-typedef void (*SSL_load_error_strings_t)(void);
-typedef int (*SSL_library_init_t)(void);
-typedef void (*SSL_CTX_free_t)(SSL_CTX*);
-typedef SSL_CTX* (*SSL_CTX_new_t)(const SSL_METHOD*);
-typedef long (*SSL_CTX_ctrl_t)(SSL_CTX*, int, long, void*);
-typedef int (*SSL_CTX_set_cipher_list_t)(SSL_CTX*, const char*);
 typedef void (*SSL_CTX_set_tmp_dh_callback_t)(SSL_CTX*, dh_callback_t);
 
 int load_libssl();

+ 0 - 7
src/libtcl.h

@@ -12,13 +12,6 @@
 
 #include ".defs/libtcl_post.h"
 
-typedef int (*Tcl_Eval_t)(Tcl_Interp*, const char*);
-typedef Tcl_Command (*Tcl_CreateCommand_t)(Tcl_Interp*, const char*, Tcl_CmdProc*, ClientData, Tcl_CmdDeleteProc*);
-typedef const char* (*Tcl_GetStringResult_t)(Tcl_Interp*);
-typedef void (*Tcl_DeleteInterp_t)(Tcl_Interp*);
-typedef Tcl_Interp* (*Tcl_CreateInterp_t)(void);
-typedef void (*Tcl_FindExecutable_t)(const char*);
-typedef int (*Tcl_Init_t)(Tcl_Interp*);
 
 #define STDVAR (ClientData cd, Tcl_Interp *interp, int argc, const char *argv[])