Jelajahi Sumber

Merge branch 'symbol-generating-portability'

* symbol-generating-portability:
  * Fix unportable \<\> by using grep -w
  * Fix sed 'unused label' issue on FreeBSD
  * Fix portability for symbol generating
Bryan Drewery 14 tahun lalu
induk
melakukan
bb69329e14
2 mengubah file dengan 14 tambahan dan 8 penghapusan
  1. 7 5
      src/generate_defs.sh
  2. 7 3
      src/generate_symbol.sh

+ 7 - 5
src/generate_defs.sh

@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 
 if [ -z "$SED" -o -z "$CXX" ]; then
   echo "This must be ran by configure" >&2
@@ -26,11 +26,13 @@ for file in $(grep -l DLSYM_GLOBAL src/*.c|grep -v "src/_"); do
   echo "extern \"C\" {" > $defsFile_wrappers
   echo "extern \"C\" {" > $defsFile_post
   touch $defsFile_pre
-  pushd src >/dev/null 2>&1
+  cd 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
+  $SED -e :a -e N -e '$!ba' -e 's/,\n/,/g' $TMPFILE > $TMPFILE.sed
+  mv $TMPFILE.sed $TMPFILE
+
+  cd .. >/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
@@ -40,7 +42,7 @@ for file in $(grep -l DLSYM_GLOBAL src/*.c|grep -v "src/_"); do
     # ... 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')
+      typedef=$(grep -w "${symbol}" $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
 

+ 7 - 3
src/generate_symbol.sh

@@ -1,4 +1,4 @@
-#! /bin/bash
+#! /bin/sh
 
 # X="typedef int (*Tcl_Eval_t)(Tcl_Interp*, const char*);"
 
@@ -12,10 +12,13 @@ while read line; do
   params_full=""
   param_names=""
 
+  # Set params to $1,$2, etc
   set $params
   paramCount=$#
+  lastParam=$(expr $paramCount - 1)
+  i=0
 
-  for (( i=0; i < $paramCount; i++)); do
+  while [ $i -lt $paramCount ]; do
     x="x${i}"
     if [ $1 = "void" ]; then
       params_full="void"
@@ -23,12 +26,13 @@ while read line; do
     else
       params_full="${params_full}${1} ${x}"
       param_names="${param_names}${x}"
-      if ! [[ $i = $(expr $paramCount - 1) ]]; then
+      if [ $i -ne $lastParam ]; then
         params_full="${params_full},"
         param_names="${param_names}, "
       fi
     fi
     shift
+    i=$((i + 1))
   done
 
   cat << EOF