Improve ansify.sh, can now add DOSCCS/DOCOPYRIGHT stuff, add fixmake.sh which changes...
authorNick Downing <downing.nick@gmail.com>
Tue, 24 Jan 2017 02:30:22 +0000 (13:30 +1100)
committerNick Downing <downing.nick@gmail.com>
Tue, 24 Jan 2017 02:33:33 +0000 (13:33 +1100)
scripts/ansify.sh
scripts/fixmake.sh [new file with mode: 0755]
scripts/make.sh

index 04937e3..b42103b 100755 (executable)
@@ -3,8 +3,24 @@
 ROOT=`dirname $0`/..
 
 all_c=`echo *.c` #`find . -name '*.c' -print |LC_ALL=C sort`
+if test "$all_c" = "*.c"
+then
+  echo "require at least one *.c input file"
+  exit 1
+fi
+
 all_h=`echo *.h` #`find . -name '*.c' -print |LC_ALL=C sort`
+if test "$all_h" = "*.h"
+then
+  all_h=
+fi
+
 std_h=`find $ROOT/cross/usr/include -type f -name '*.h' -print |LC_ALL=C sort`
+if test -z "$std_h"
+then
+  echo "require at least one standard library header file"
+  exit 1
+fi
 
 if test -z "$1" || test "$1" = 0
 then
@@ -22,7 +38,7 @@ then
   rm -f `find $ROOT/cross/usr/include -name '*.h.usedby' -print`
   rm -rf `find $ROOT/cross/usr/include -name '.xify' -print`
 
-  rm -f a conflicts.temp oldprotos.txt oldprotos.temp xx*
+  rm -f a conflicts.temp oldprotos.txt oldprotos.temp xx*
 fi
 
 if test -z "$1" || test "$1" = 1
@@ -38,6 +54,23 @@ then
 
     sed -e 's/^\(#[     ]*\(else\|endif\)\)\([^0-9A-Za-z_].*\)\?/\1/' -i $i
 
+    rm -f xx*
+    csplit -b '%05d' -q $i '/^#[        ]*ifndef[       ]*lint$/' '{*}'
+    for j in xx*
+    do
+      if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[  ]*\(copyright[  ]*\[[   ]*\]\|\*[       ]*copyright\)[  ]*='
+      then
+        sed -e 's/^\(#[         ]*if\)ndef\([   ]*\)lint$/\1\2defined(DOCOPYRIGHT) \&\& !defined(lint)/' -i $j
+      fi
+      if test $j != xx00000 && sed -ne '2p' $j |grep -q 'char[  ]*\(sccsid[     ]*\[[   ]*\]\|\*[       ]*sccsid\)[     ]*='
+      then
+        sed -e 's/^\(#[         ]*if\)ndef\([   ]*\)lint$/\1\2defined(DOSCCS) \&\& !defined(lint)/' -i $j
+      else
+        sed -e 's/^.*char[      ]*\(sccsid[     ]*\[[   ]*\]\|\*[       ]*sccsid\)[     ]*=.*$/#if defined(DOSCCS) \&\& !defined(lint)\n&\n#endif/' -i $j
+      fi
+    done
+    cat xx* >$i
     rm -f xx*
     csplit -b '%05d' -q $i '/^[         ]*{[    ]*$/' '{*}'
     for j in xx*
@@ -78,6 +111,10 @@ then
     echo "group=$group"
 
     $ROOT/cproto-4.6/cproto -i$ROOT/cross/usr/include -Dvax -t -H -s $i |sed -ne '2,$p' >$i.allprotos
+    if ! grep -v '^int main __P((' $i.allprotos
+    then
+      echo -n >$i.allprotos
+    fi
 
     grep "^static " <$i.allprotos >a
     if test -s a
@@ -315,7 +352,7 @@ then
 
     echo "pattern0=$pattern0"
 
-    if test -n "$pattern0"
+    if test -n "$pattern0" && test -n "$all_h_nocomm"
     then
       grep -H "^\\($pattern0\\)$" $all_h_nocomm |grep -v "^$i\.nocomm:" >a
       if test -s a
@@ -521,9 +558,12 @@ then
   echo "===stage 4==="
 
   # checking header loops
-  grep -H '^#include <[^>]*>' $all_h |\
-  sed -e "s:^\(.*\)\:#include <\(.*\)>:\1 \2:" |\
-  tsort >a
+  if test -n "$all_h"
+  then
+    grep -H '^#include <[^>]*>' $all_h |\
+    sed -e "s:^\(.*\)\:#include <\(.*\)>:\1 \2:" |\
+    tsort >a
+  fi
 
   # removing useless extra header inclusions that are pulled in anyway
   touch $ROOT/cross/usr/include/stdarg.h
diff --git a/scripts/fixmake.sh b/scripts/fixmake.sh
new file mode 100755 (executable)
index 0000000..775cfb4
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+f=Makefile
+if test $# -ge 1
+then
+  f=$1
+fi
+
+sed -e 's/     \(-\)\?cc /     \1${CC} /; s/   \(-\)\?ld /     \1${LD} /; s/\([         ]\)cc -M /\1${CC} -M /g; /^# DO NOT DELETE THIS LINE -- make depend uses it$/{N; q}' -i $f
+if grep -q '\${LD}' $f && ! grep -q '^LD[       ]*=' $f
+then
+  sed -e '1iLD=ld' -i $f
+fi
index 56b662b..65c5f84 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/sh
-ROOT=`dirname $0`/..
+ROOT=`pwd`/`dirname $0`/..
 make CC="$ROOT/cross/bin/hostcc -Dvax" LD="$ROOT/cross/bin/hostld" DESTDIR="$ROOT/cross" $@