Home | History | Annotate | Download | only in netcat
      1 #! /bin/sh
      2 ##
      3 ## Find stupid system include dependencies and account for them.  Squirts
      4 ## a sample .h file to stdout containing [too many of] the right things.
      5 ## If you hose the output into "stupid.h", you will get MORE information.
      6 ## This takes a while to run, because it checks so many things.
      7 ##
      8 ## IF YOU HAVE a system/arch/compiler/whatever that is NOT one of:
      9 ##   msdos-msc6.x  ultrix-vax ultrix-mips  sunos4.1.x-sparc  solaris2.x-sparc
     10 ##   aix-rs6k  linux1.[01].x-x86  freebsd-x86  netbsd-x86 hpux
     11 ##   [... hopefully this list will grow very large]
     12 ## or even if you aren't sure, you would be doing me and the net in general
     13 ## a wonderful service by running this and MAILING me the "full" output, e.g.
     14 ##
     15 ##    chmod +x stupidh
     16 ##    ./stupidh > stupid.h
     17 ##    mail hobbit (at] avian.org < stupid.h
     18 ##
     19 ## WARNING: You may have to change "cc" to "gcc" below if you don't have
     20 ## "cc" [e.g. solaris, thank you very fucking much, Sun].
     21 ## Please note any errors this generates, too...
     22 ##
     23 ## *Hobbit*, 941122 and previous.  VERSION: 1.3 951107
     24 ##
     25 ## edits: Use a consistent naming scheme, for easier identification and cleanup.
     26 ## accomodate gcc's BOGUS assumptions based on input filename.
     27 ## added a few more include-names and try-predefines; some swiped from autoconf.
     28 ## added a couple of things commonly done as #defines so we can SEE 'em
     29 
     30 ## Here is where to change "cc" to "gcc" if needed:
     31 CC=cc
     32 
     33 if test -z "${INCLUDE}" ; then
     34   INCLUDE=/usr/include
     35 fi
     36 
     37 echo '/* STUPIDH run:'
     38 uname -a
     39 echo '*/'
     40 echo ''
     41 
     42 echo "/* Includes, from ${INCLUDE} */"
     43 for xx in \
     44 assert ctype cdefs errno file fcntl ioctl malloc stdio stdlib stdarg iostdio \
     45 stddef dirent direct dir ndir utmp wtmp utmpx wtmpx lastlog login paths \
     46 getopt string strings signal setjmp io param stat types time timeb utime \
     47 dos msdos unistd socket netdb varargs sysinfo systeminfo resource ulimit \
     48 stream stropts pstat sysmacros termio termios sgtty tty ttyent lstat select \
     49 sockio wait vfork bsdtypes mkdev utsname sysexits \
     50 ; do
     51 
     52   XX=''
     53   if test -f ${INCLUDE}/${xx}.h ; then
     54     echo "#include <${xx}.h>"
     55     XX=`echo $xx | tr '[a-z]' '[A-Z]'`
     56   fi
     57   if test -f ${INCLUDE}/sys/${xx}.h ; then
     58     echo "#include <sys/${xx}.h>"
     59     XX=`echo $xx | tr '[a-z]' '[A-Z]'`
     60   fi
     61 
     62 # everyone seems to have their own conventions; this may not be complete.
     63 # thats why this is so STUPID.
     64 # HAS_xx and USE_xx might indicate functions and available library calls,
     65 # not includes.  Deal...
     66 
     67   if test "${XX}" ; then
     68     echo "#define USE_${XX}_H"
     69     echo "#define HAS_${XX}_H"
     70     echo "#define HAS_${XX}"
     71     echo "#define HAS${XX}"
     72     echo "#define HAVE_${XX}_H"
     73     echo "#define HAVE_${XX}"
     74     echo "#define HAVE${XX}H"
     75     echo "#define ${XX}H"
     76     echo ''
     77   fi
     78 # Stupid hack: "dir" and "dirent" might mutually exclusive, a la GNU
     79 # includes.  This is to prevent it from biting us.
     80   if test "${xx}" =  "dirent" ; then
     81     echo "#ifdef _SYS_DIRENT_H"
     82     echo "#undef _SYS_DIRENT_H"
     83     echo "#endif"
     84   fi
     85 
     86 ### To make a DOS batchfile instead, do this [on a unix box!], xfer results,
     87 ### and have "xxx.bat" that types out all the cruft for %INCLUDE%\%1.
     88 ### WARNING: I might not have gotten the superquoting exactly right here...
     89 # echo "if exist %INCLUDE%\\${xx}.h call xxx ${xx}"
     90 # echo "if exist %INCLUDE%\\sys\\${xx}.h call xxx sys/${xx}"
     91 ### You also need to save and manually run the CPP input file, below.
     92 ### I've done this for msc6 and would appreciate results for other compilers.
     93 
     94 done
     95 sync
     96 sleep 1
     97 
     98 ### Note: if all the previous output went to "stupid.h", it will be
     99 ### reincluded in the second part of this.
    100 
    101 sed -e '/^#/d' -e '/^[	 ]*$/d' > st00pid.in << 'EOF'
    102 
    103 ### More recently, some of this was swiped from the "gcc" doc.  Autoconf is
    104 ### worth a harder look for more ideas; havent gotten around to it yet.
    105 # architectures
    106 alpha
    107 dec
    108 ibm
    109 i370
    110 i960
    111 i860
    112 ibm032
    113 a29k
    114 indigo
    115 iris
    116 mips
    117 mipsel
    118 sparc
    119 sparclite
    120 ncr
    121 sh
    122 harris
    123 apple
    124 vax
    125 x86
    126 ix86
    127 i286
    128 i386
    129 i486
    130 i586
    131 pentium
    132 intel
    133 smp
    134 mpu
    135 mpu8080
    136 mpu8086
    137 amiga
    138 hp
    139 hppa
    140 hp400
    141 hp9000
    142 snake
    143 decmips
    144 mc68000
    145 mc68010
    146 mc68020
    147 mc68030
    148 m68000
    149 m68010
    150 m68020
    151 m68030
    152 m68k
    153 m88k
    154 u3b15
    155 u3b
    156 u3b2
    157 u3b5
    158 u3b15
    159 u3b20d
    160 we32k
    161 ppc
    162 powerpc
    163 arm
    164 aviion
    165 ns32000
    166 iapx286
    167 # minor exception to lc-vs-uc thing?
    168 iAPX286
    169 rs6000
    170 rs6k
    171 risc
    172 sun
    173 sun3
    174 sun4
    175 sun4c
    176 sun4m
    177 sequent
    178 apollo
    179 solbourne
    180 pyr
    181 pyramid
    182 interdata
    183 intertec
    184 pdp11
    185 u370
    186 next
    187 mac
    188 macintosh
    189 
    190 # for completeness; ya never know ... yes, found it!! -- solaris inet/common.h
    191 big_endian
    192 little_endian
    193 lsbfirst
    194 msbfirst
    195 
    196 # vendors/OSes
    197 unix
    198 munix
    199 m_unix
    200 gcos
    201 os
    202 gssc
    203 tss
    204 isc
    205 # *This* pair of imbeciles does *caseified defines*.  Pinheads.  One of
    206 # these might trigger before the "tr" step.
    207 NetBSD
    208 netbsd
    209 freebsd
    210 FreeBSD
    211 # cant do 386bsd, I dont think, but ...
    212 _386bsd
    213 bsd386
    214 bsdunix
    215 bsd_2
    216 bsd_20
    217 bsd
    218 bsdi
    219 bsd4
    220 bsd42
    221 bsd43
    222 bsd44
    223 bsd4_2
    224 bsd4_3
    225 bsd4_4
    226 linux
    227 minix
    228 ultrix
    229 ult3
    230 ult4
    231 bull
    232 convex
    233 convex_source
    234 res
    235 rt
    236 esix
    237 dg
    238 dgux
    239 encore
    240 osf
    241 osf1
    242 osf2
    243 # oops:
    244 # osf/1
    245 mach
    246 mach386
    247 mach_386
    248 nextstep
    249 tahoe
    250 reno
    251 sunos
    252 sunos3
    253 sunos4
    254 sunos5
    255 solaris
    256 sun_src_compat
    257 svr3
    258 svr4
    259 svr3_style
    260 svr4_style
    261 sysv
    262 hpux
    263 hp_ux
    264 irix
    265 sgi
    266 sony
    267 news
    268 newsos
    269 news_os
    270 luna
    271 lynxos
    272 riscos
    273 microport
    274 ewsux
    275 ews_ux
    276 mport
    277 dynix
    278 genix
    279 unicos
    280 unixware
    281 msdos
    282 dos
    283 os2
    284 novell
    285 univel
    286 plan9
    287 att
    288 att_unix
    289 sco
    290 odt
    291 aix
    292 aux
    293 a_ux
    294 rsx
    295 vms
    296 
    297 # compiler cruft??
    298 ansi
    299 ansi_source
    300 ansic
    301 stdc
    302 lint
    303 sccs
    304 libc_sccs
    305 ms
    306 msc
    307 microsoft
    308 gcc
    309 gnu
    310 gnuc
    311 gnucc
    312 gnu_source
    313 sabre
    314 saber
    315 cygnus
    316 source
    317 all_source
    318 gprof
    319 prof
    320 posix
    321 posix_source
    322 posix_sources
    323 posix_c_source
    324 xopen_source
    325 args
    326 p
    327 proto
    328 no_proto
    329 prototype
    330 prototypes
    331 reentrant
    332 kernel
    333 str
    334 trace
    335 asm
    336 libcpp
    337 athena
    338 athena_compat
    339 # some preprocessors cant deal with this
    340 # c++
    341 cxx
    342 cplusplus
    343 borland
    344 turbo
    345 turboc
    346 lattice
    347 highc
    348 
    349 # various defines that pop out of other .h files that we need to know about
    350 index
    351 strchr
    352 rindex
    353 strrchr
    354 bcopy
    355 memcpy
    356 bzero
    357 memset
    358 path_login
    359 path_lastlog
    360 path_utmp
    361 path_utmpx
    362 
    363 EOF
    364 
    365 # FL must be named something.c, so STUPID gcc recognized it as a non-object!!
    366 ( FL=st00pid.c
    367   if test -f stupid.h ; then
    368     cp stupid.h $FL
    369     sync
    370     echo '/* Re-including stupid.h */'
    371     sleep 1
    372   else
    373     echo '/* Skipping stupid.h */'
    374   fi
    375   while read xx ; do
    376     XX=`echo $xx | tr '[a-z]' '[A-Z]'`
    377     echo "#ifdef ${xx}" >> $FL
    378     echo "\"${xx}\" = ${xx}" >> $FL
    379     echo "#endif" >> $FL
    380     echo "#ifdef _${xx}" >> $FL
    381     echo "\"_${xx}\" = _${xx}" >> $FL
    382     echo "#endif" >> $FL
    383     echo "#ifdef _${xx}_" >> $FL
    384     echo "\"_${xx}_\" = _${xx}_" >> $FL
    385     echo "#endif" >> $FL
    386     echo "#ifdef __${xx}" >> $FL
    387     echo "\"__${xx}\" = __${xx}" >> $FL
    388     echo "#endif" >> $FL
    389     echo "#ifdef __${xx}__" >> $FL
    390     echo "\"__${xx}__\" = __${xx}__" >> $FL
    391     echo "#endif" >> $FL
    392     echo "#ifdef ${XX}" >> $FL
    393     echo "\"${XX}\" = ${XX}" >> $FL
    394     echo "#endif" >> $FL
    395     echo "#ifdef _${XX}" >> $FL
    396     echo "\"_${XX}\" = _${XX}" >> $FL
    397     echo "#endif" >> $FL
    398     echo "#ifdef _${XX}_" >> $FL
    399     echo "\"_${XX}_\" = _${XX}_" >> $FL
    400     echo "#endif" >> $FL
    401     echo "#ifdef __${XX}" >> $FL
    402     echo "\"__${XX}\" = __${XX}" >> $FL
    403     echo "#endif" >> $FL
    404     echo "#ifdef __${XX}__" >> $FL
    405     echo "\"__${XX}__\" = __${XX}__" >> $FL
    406     echo "#endif" >> $FL
    407   done
    408 # and pick up a few specials
    409   echo "#ifdef major" >> $FL
    410   echo "\"major\" = major (x)" >> $FL
    411   echo "\"minor\" = minor (x)" >> $FL
    412   echo "#endif" >> $FL
    413   echo "#ifdef FD_SETSIZE" >> $FL
    414   echo "\"FD_SETSIZE\" = FD_SETSIZE" >> $FL
    415   echo "#endif" >> $FL
    416 ) < st00pid.in
    417 sync
    418 
    419 echo '/* Compiler predefines:'
    420 ${CC} -E st00pid.c | sed -e '/^#/d' -e '/^[	 ]*$/d'
    421 echo '*/'
    422 sync
    423 
    424 cat > st00pid.c << 'EOF'
    425 #include <stdio.h>
    426 main() {
    427 union {
    428   char *bletch;
    429   int *i;
    430 } yow;
    431 static char orig[16];
    432   strcpy (orig, "ABCDEFGHIJK");
    433   yow.bletch = orig;
    434   printf ("endian thing: %s = 0x%lx, addrbyte = %x -- ",
    435     yow.bletch, *yow.i, *yow.i & 0xFF);
    436   printf (((*yow.i & 0xff) == 0x41) ? "LITTLE\n" : "BIG\n");
    437   printf ("short %d;  int %d;  long %d\n",
    438     sizeof (short), sizeof (int), sizeof (long));
    439 }
    440 EOF
    441 
    442 ${CC} -o st00pid.x st00pid.c
    443 echo '/* Architecture:'
    444 ./st00pid.x
    445 echo '*/'
    446 
    447 ### dont nuke if generating DOS batchfiles
    448 rm -f st00pid.*
    449 sync
    450 exit 0
    451 
    452 ### stuff remaining to deal with:
    453 # maybe take out the slew of HAS_* and HAS* excess predefines, and only use
    454 #   our "standardized" scheme [like we were going to generate a real includible
    455 #   file outa this??]
    456 # various POSIX_ME_HARDERisms:
    457 #   vfork
    458 #   lockf/flock/fcntl/euuugh
    459 #   signal stuff
    460 #   termio/termios/sgtty hair
    461 # strdup and related
    462 # ifdef HAVE_STD_LIB and such nonsense
    463 # auto-sniff cc-vs-gcc somehow?  maybe a straight OR with exit statii..
    464 
    465