home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / src / osdef.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2002-04-09  |  2.8 KB  |  90 lines

  1. #! /bin/sh
  2. #
  3. # osdef.sh -- copy osdef.h.in to osdef.h while removing declarations
  4. # found in the system header files. Caution: weird sed magic going on here.
  5. # Warnings are printed if sed did not survive.
  6. #
  7. # (C) Michael Schroeder, Juergen Weigert
  8. #
  9. # osdef.h.in has been split into osdef1.h.in and osdef2.h.in, because some
  10. # sed's could not handle the amount of commands (is 50 commands the limit?).
  11. #
  12. # 31.10.95 jw.
  13.  
  14. if test -z "$CC"; then
  15.   CC=cc
  16. fi
  17. if test -z "$srcdir"; then
  18.   srcdir=.
  19. fi
  20.  
  21. rm -f core* *.core
  22.  
  23. cat << EOF > osdef0.c
  24. #define select select_declared_wrong
  25. #define tgetstr tgetstr_declared_wrong
  26. #include "auto/config.h"
  27. #include "os_unix.h"    /* bring in most header files, more follow below */
  28. #include "os_unixx.h"    /* bring in header files for os_unix.c */
  29.  
  30. #ifdef HAVE_TERMCAP_H
  31. # include <termcap.h>    /* only for term.c */
  32. #endif
  33.  
  34. #ifdef HAVE_FCNTL_H
  35. # include <fcntl.h>        /* only used in a few files */
  36. #endif
  37.  
  38. #ifdef HAVE_SYS_STATFS_H
  39. # include <sys/types.h>
  40. # include <sys/statfs.h>    /* only for memfile.c */
  41. #endif
  42. EOF
  43.  
  44. $CC -I. -I$srcdir -E osdef0.c >osdef0.cc
  45.  
  46. # insert a space in front of each line, so that a function name at the
  47. # start of the line is matched with "[)*,     ]\1[     (]"
  48. sed < osdef0.cc -e '/\(..*\)/s// \1/' > osdef0.ccc
  49.  
  50. sed < $srcdir/osdef1.h.in -n -e '/^extern/s@.*[)*     ][)*     ]*\([a-zA-Z_][a-zA-Z0-9_]*\) __ARGS.*@/[)*,     ][(]*\1[)]*[     (]/i\\\
  51. \\/\\[^a-zA-Z_\\]\1 __ARGS\\/d@p' > osdef11.sed
  52.  
  53. sed < $srcdir/osdef2.h.in -n -e '/^extern/s@.*[)*     ][)*     ]*\([a-zA-Z_][a-zA-Z0-9_]*\) __ARGS.*@/[)*,     ][(]*\1[)]*[     (]/i\\\
  54. \\/\\[^a-zA-Z_\\]\1 __ARGS\\/d@p' > osdef21.sed
  55.  
  56. cat << EOF > osdef2.sed
  57. 1i\\
  58. /*
  59. 1i\\
  60.  * osdef.h is automagically created from osdef?.h.in by osdef.sh -- DO NOT EDIT
  61. 1i\\
  62.  */
  63. EOF
  64.  
  65. cat osdef0.ccc | sed -n -f osdef11.sed >> osdef2.sed
  66. sed -f osdef2.sed < $srcdir/osdef1.h.in > auto/osdef.h
  67.  
  68. cat osdef0.ccc | sed -n -f osdef21.sed > osdef2.sed
  69. sed -f osdef2.sed < $srcdir/osdef2.h.in >> auto/osdef.h
  70.  
  71. rm osdef0.c osdef0.cc osdef0.ccc osdef11.sed osdef21.sed osdef2.sed
  72.  
  73. if test -f core*; then
  74.   file core*
  75.   echo "  Sorry, your sed is broken. Call the system administrator."
  76.   echo "  Meanwhile, you may try to compile Vim with an empty osdef.h file."
  77.   echo "  If you compiler complains about missing prototypes, move the needed"
  78.   echo "  ones from osdef1.h.in and osdef2.h.in to osdef.h."
  79.   exit 1
  80. fi
  81. cat $srcdir/osdef1.h.in $srcdir/osdef2.h.in >osdefX.h.in
  82. if eval test "`diff auto/osdef.h osdefX.h.in | wc -l`" -eq 4; then
  83.   echo "  Hmm, sed is very pessimistic about your system header files."
  84.   echo "  But it did not dump core -- strange! Let's continue carefully..."
  85.   echo "  If this fails, you may want to remove offending lines from osdef.h"
  86.   echo "  or try with an empty osdef.h file, if your compiler can do without"
  87.   echo "  function declarations."
  88. fi
  89. rm osdefX.h.in
  90.