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@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: 31CC=cc 32 33if test -z "${INCLUDE}" ; then 34 INCLUDE=/usr/include 35fi 36 37echo '/* STUPIDH run:' 38uname -a 39echo '*/' 40echo '' 41 42echo "/* Includes, from ${INCLUDE} */" 43for xx in \ 44assert ctype cdefs errno file fcntl ioctl malloc stdio stdlib stdarg iostdio \ 45stddef dirent direct dir ndir utmp wtmp utmpx wtmpx lastlog login paths \ 46getopt string strings signal setjmp io param stat types time timeb utime \ 47dos msdos unistd socket netdb varargs sysinfo systeminfo resource ulimit \ 48stream stropts pstat sysmacros termio termios sgtty tty ttyent lstat select \ 49sockio 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 94done 95sync 96sleep 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 101sed -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 106alpha 107dec 108ibm 109i370 110i960 111i860 112ibm032 113a29k 114indigo 115iris 116mips 117mipsel 118sparc 119sparclite 120ncr 121sh 122harris 123apple 124vax 125x86 126ix86 127i286 128i386 129i486 130i586 131pentium 132intel 133smp 134mpu 135mpu8080 136mpu8086 137amiga 138hp 139hppa 140hp400 141hp9000 142snake 143decmips 144mc68000 145mc68010 146mc68020 147mc68030 148m68000 149m68010 150m68020 151m68030 152m68k 153m88k 154u3b15 155u3b 156u3b2 157u3b5 158u3b15 159u3b20d 160we32k 161ppc 162powerpc 163arm 164aviion 165ns32000 166iapx286 167# minor exception to lc-vs-uc thing? 168iAPX286 169rs6000 170rs6k 171risc 172sun 173sun3 174sun4 175sun4c 176sun4m 177sequent 178apollo 179solbourne 180pyr 181pyramid 182interdata 183intertec 184pdp11 185u370 186next 187mac 188macintosh 189 190# for completeness; ya never know ... yes, found it!! -- solaris inet/common.h 191big_endian 192little_endian 193lsbfirst 194msbfirst 195 196# vendors/OSes 197unix 198munix 199m_unix 200gcos 201os 202gssc 203tss 204isc 205# *This* pair of imbeciles does *caseified defines*. Pinheads. One of 206# these might trigger before the "tr" step. 207NetBSD 208netbsd 209freebsd 210FreeBSD 211# cant do 386bsd, I dont think, but ... 212_386bsd 213bsd386 214bsdunix 215bsd_2 216bsd_20 217bsd 218bsdi 219bsd4 220bsd42 221bsd43 222bsd44 223bsd4_2 224bsd4_3 225bsd4_4 226linux 227minix 228ultrix 229ult3 230ult4 231bull 232convex 233convex_source 234res 235rt 236esix 237dg 238dgux 239encore 240osf 241osf1 242osf2 243# oops: 244# osf/1 245mach 246mach386 247mach_386 248nextstep 249tahoe 250reno 251sunos 252sunos3 253sunos4 254sunos5 255solaris 256sun_src_compat 257svr3 258svr4 259svr3_style 260svr4_style 261sysv 262hpux 263hp_ux 264irix 265sgi 266sony 267news 268newsos 269news_os 270luna 271lynxos 272riscos 273microport 274ewsux 275ews_ux 276mport 277dynix 278genix 279unicos 280unixware 281msdos 282dos 283os2 284novell 285univel 286plan9 287att 288att_unix 289sco 290odt 291aix 292aux 293a_ux 294rsx 295vms 296 297# compiler cruft?? 298ansi 299ansi_source 300ansic 301stdc 302lint 303sccs 304libc_sccs 305ms 306msc 307microsoft 308gcc 309gnu 310gnuc 311gnucc 312gnu_source 313sabre 314saber 315cygnus 316source 317all_source 318gprof 319prof 320posix 321posix_source 322posix_sources 323posix_c_source 324xopen_source 325args 326p 327proto 328no_proto 329prototype 330prototypes 331reentrant 332kernel 333str 334trace 335asm 336libcpp 337athena 338athena_compat 339# some preprocessors cant deal with this 340# c++ 341cxx 342cplusplus 343borland 344turbo 345turboc 346lattice 347highc 348 349# various defines that pop out of other .h files that we need to know about 350index 351strchr 352rindex 353strrchr 354bcopy 355memcpy 356bzero 357memset 358path_login 359path_lastlog 360path_utmp 361path_utmpx 362 363EOF 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 417sync 418 419echo '/* Compiler predefines:' 420${CC} -E st00pid.c | sed -e '/^#/d' -e '/^[ ]*$/d' 421echo '*/' 422sync 423 424cat > st00pid.c << 'EOF' 425#include <stdio.h> 426main() { 427union { 428 char *bletch; 429 int *i; 430} yow; 431static 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} 440EOF 441 442${CC} -o st00pid.x st00pid.c 443echo '/* Architecture:' 444./st00pid.x 445echo '*/' 446 447### dont nuke if generating DOS batchfiles 448rm -f st00pid.* 449sync 450exit 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