home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / guesscfg.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1995-05-18  |  8.8 KB  |  492 lines

  1. #!/bin/sh
  2. #
  3. # guesscfg.sh -    Create a config.h file based on guesses.
  4. #        Called by `config.sh' like this:
  5. #
  6. #            . ./guesscfg.sh $system
  7. #
  8. # This script produces just a first guess that might be ok if your system's
  9. # include files are sane -- i.e. rarely.
  10. # Please read file INSTALL for the constants you should define in `config.h'.
  11. #
  12.  
  13. echo "guessing config.h for ${system:=$1}" >&2
  14.  
  15. if [ $system = WATCOM ]
  16. then
  17.   make="make TARGET=${TARGET:-OS2V2}"
  18. else
  19.   make=make
  20. fi
  21.  
  22. case $system in
  23.   EMX)
  24.     o=.o        # object file extension
  25.     e=.exe        # executable file extension
  26.     null=NUL        # null-device name
  27.     ;;
  28.   WATCOM|OS2-ICC)
  29.     o=.obj
  30.     e=.exe
  31.     null=NUL
  32.     ;;
  33.   *)
  34.     o=.o
  35.     e=
  36.     null=/dev/null
  37.     ;;
  38. esac
  39.  
  40. #
  41. # Some shortcuts, -- yes your shell should know about shell functions :-)
  42. #
  43.  
  44. tmpc=tmp$$
  45. trap "rm -f $tmpc*; exit 0" 0 1 2 3 15
  46.  
  47. if [ "`echo -n asdf`" = "asdf" ]
  48. then
  49.   echo_n ()
  50.   {
  51.     echo -n "$@"
  52.   }
  53. else
  54.   echo_n ()
  55.   {
  56.     echo "$@"'\c'
  57.   }
  58. fi
  59.  
  60. define ()        # a shortcut to add #define-lines to config.h
  61. {
  62.   echo '#define' $1 1
  63. }
  64.  
  65. includes=""
  66.  
  67. hasinc ()        # test if an include file is available
  68. {
  69.   echo_n "$1 ... " >&2
  70.   echo "#include <$1>" > $tmpc.c
  71.   rm -f $tmpc.i
  72.   if $make $tmpc.i >$null 2>&1
  73.   then
  74.     echo "yes" >&2
  75.     includes=$includes" $1"
  76.     rm -f $tmpc.c $tmpc.i
  77.     return 0
  78.   else
  79.     echo "no" >&2
  80.     rm -f $tmpc.c $tmpc.i
  81.     return 1
  82.   fi
  83. }
  84.  
  85. cppinc ()        # output a preprocessed copy of include files to
  86. {            # the standard output.
  87.   for file
  88.   do
  89.     echo "#include <$file>" > $tmpc.c
  90.     rm -f $tmpc.i
  91.     if $make $tmpc.i 2>$null
  92.     then
  93.       cat $tmpc.i
  94.     fi
  95.   done
  96.   rm -f $tmpc.c $tmpc.i
  97. }
  98.  
  99. grepinc ()        # search strings in system include files
  100. {
  101.   gi_text="$1"
  102.   shift
  103.   test `cppinc $* | grep -c $gi_text` -gt 0
  104.   return $?
  105. }
  106.  
  107. has ()            # search identifier in system include files
  108. {
  109.   echo_n "$1 ... " >&2
  110.   ha_symbol="[^a-zA-Z0-9]$1[^a-zA-Z0-9]"
  111.   shift
  112.   if grepinc "$ha_symbol" "$@"
  113.   then
  114.     echo "yes" >&2
  115.     return 0
  116.   else
  117.     echo "no" >&2
  118.     return 1
  119.   fi
  120. }
  121.  
  122. compile ()
  123. {
  124.   echo_n "$1 ... " >&2
  125.   shift
  126.  
  127.   rm -f $tmpc.c $tmpc$o
  128.   for i
  129.   do
  130.     echo $i >> $tmpc.c
  131.   done
  132.  
  133.   if $make $tmpc$o >$null 2>&1
  134.   then
  135.     echo "yes" >&2
  136.     rm -f $tmpc.c $tmpc$o
  137.     return 0
  138.   else
  139.     echo "no" >&2
  140.     rm -f $tmpc.c $tmpc$o
  141.     return 1
  142.   fi
  143. }
  144.  
  145.  
  146. #
  147. # Start output of `config.h':
  148. #
  149.  
  150. {
  151.  
  152. echo "/*
  153.  * config.h --    Automatically generated file, don't change.
  154.  */
  155.  
  156. #ifndef __CONFIG_H
  157. #define __CONFIG_H
  158. "
  159.  
  160. echo '#define HOST_SYSTEM "'$system'"'
  161. define $system
  162.  
  163.  
  164. #
  165. # Make some assumptions about the kind of system.
  166. #
  167.  
  168. if [ -n "$PATH" ]
  169. then
  170.   case $PATH in
  171.     ""|*/*)
  172.       # PATH variable looks unix-like:
  173.       # Assume UNIX file name conventions and ISO-latin1 character set.
  174.       define UNIX_FILENAMES
  175.       define ISO_CHARSET
  176.       ;;
  177.     *)
  178.       # PATH variable looks more like DOS:
  179.       # (ok, this is default. It seems impossible to get the quoting of the \
  180.       #  inside the pattern right for more than one shell at a time.)
  181.       # Assume DOS file name conventions and IBMPC character set.
  182.       define DOS_FILENAMES
  183.       define IBMPC_CHARSET
  184.       ;;
  185.   esac
  186. else
  187.   define UNIX_FILENAMES
  188.   define ISO_CHARSET
  189. fi
  190.  
  191.  
  192. #
  193. # prepare for "nonansi.h", check available include files.
  194. #
  195.  
  196. if hasinc sys/types.h;    then define HAVE_SYS_TYPES_H;    fi
  197. if hasinc sys/ioctl.h;    then define HAVE_SYS_IOCTL_H;    fi
  198. if hasinc fcntl.h;    then define HAVE_FCNTL_H;    fi
  199. if hasinc sys/stat.h;    then define HAVE_SYS_STAT_H;    fi
  200. if hasinc direct.h;    then define HAVE_DIRECT_H;    fi
  201. if hasinc sys/ndir.h;    then define HAVE_SYS_NDIR_H;    fi
  202. if hasinc utime.h;    then define HAVE_UTIME_H;    fi
  203. if hasinc sys/time.h;    then define HAVE_SYS_TIME_H;    fi
  204. if hasinc sys/utime.h;    then define HAVE_SYS_UTIME_H;    fi
  205. if hasinc process.h;    then define HAVE_PROCESS_H;    fi
  206. if hasinc sys/process.h;then define HAVE_SYS_PROCESS_H;    fi
  207. if hasinc poll.h;    then define HAVE_POLL_H;    fi
  208. if hasinc sys/poll.h;    then define HAVE_SYS_POLL_H;    fi
  209. if hasinc sys/select.h;    then define HAVE_SYS_SELECT_H;    fi
  210. if hasinc unistd.h;    then define HAVE_UNISTD_H;    fi
  211. if hasinc io.h;        then define HAVE_IO_H;        fi
  212. if hasinc libc.h;    then define HAVE_LIBC_H;    fi
  213. if hasinc dos.h;    then define HAVE_DOS_H;        fi
  214. if hasinc mem.h;    then define HAVE_MEM_H;        fi
  215. if hasinc memory.h;    then define HAVE_MEMORY_H;    fi
  216. if hasinc strings.h;    then define HAVE_STRINGS_H;    fi
  217.  
  218. if hasinc getopt.h;    then define HAVE_GETOPT_H;    fi
  219. if hasinc locale.h;    then define HAVE_LOCALE_H;    fi
  220.  
  221. if hasinc termios.h;    then define HAVE_TERMIOS_H;    fi 
  222. if hasinc termio.h;    then define HAVE_TERMIO_H;    fi
  223. if hasinc sgtty.h;    then define HAVE_SGTTY_H;    fi
  224. if hasinc curses.h;    then define HAVE_CURSES_H;    fi
  225. if hasinc term.h;    then define HAVE_TERM_H;    fi
  226. if hasinc termcap.h;    then define HAVE_TERMCAP_H;    fi
  227. if hasinc conio.h;    then define HAVE_CONIO_H;    fi
  228.  
  229. # echo $includes >&2
  230.  
  231. #
  232. # check for individual features or lack thereof inside include files.
  233. #
  234.  
  235. funnyincs=""
  236. for inc in unistd.h io.h libc.h direct.h sys/ndir.h
  237. do
  238.   case $includes in
  239.     *$inc*)
  240.       funnyincs=$funnyincs" $inc"
  241.       ;;
  242.   esac
  243. done
  244.  
  245. # echo $funnyincs >&2
  246.  
  247. if has atexit stdlib.h
  248. then
  249.   echo "#define eXit(X) exit(X)"
  250. else
  251.   echo "typedef void (*atexit_fp) (void);"
  252.   echo "int atexit (atexit_fp);"
  253.   echo "void eXit (int);"
  254. fi
  255.  
  256. if grepinc 'int.*sprintf' stdio.h
  257. then
  258.   : sprintf probably ok
  259. else
  260.   echo "#define WRONG_SPRINTF /* does your sprintf() really return char* ? */"
  261. fi
  262.  
  263. if grepinc fpos_t stdio.h sys/types.h
  264. then :
  265. else
  266.   echo "#define fpos_t long"
  267. fi
  268.  
  269. if has random stdlib.h $funnyincs
  270. then
  271.   define HAVE_RANDOM
  272. fi
  273.  
  274. if has acosh math.h
  275. then
  276.   define HAVE_AH_TRIG
  277. else
  278.   echo "double acosh (double);"
  279.   echo "double asinh (double);"
  280.   echo "double atanh (double);"
  281. fi
  282.  
  283. if has pow10 math.h
  284. then :
  285. else
  286.   echo "#define pow10(X) pow (10.0, (X))"
  287. fi
  288.  
  289. if has memmove string.h mem.h memory.h
  290. then
  291.   define HAVE_MEMMOVE
  292. elif has bcopy strings.h
  293. then
  294.   echo "#define memmove(D,S,C) bcopy (S, D, C)"
  295.   define HAVE_MEMMOVE
  296. else
  297.   echo "void memmove (char *, const char *, unsigned);"
  298. fi
  299.  
  300. #if has stpcpy string.h
  301. #then
  302. #  :
  303. #else
  304. #  echo "#define stpcpy(DST,SRC) (strcpy(DST,SRC) + strlen(SRC))"
  305. #fi
  306.  
  307. if has strdup string.h
  308. then
  309.   define HAVE_STRDUP
  310. else
  311.   echo "char *strdup (const char *);"
  312. fi
  313.  
  314. if has strerror string.h
  315. then :
  316. else
  317.   if has sys_errlist stdio.h
  318.   then :
  319.   else
  320.     # well if it doesn't exist, you'll have to write it yourself.
  321.     echo "extern char *sys_errlist [];"
  322.   fi
  323.   echo "#define strerror(x) sys_errlist [x]"
  324. fi
  325.  
  326. if has remove stdio.h $funnyincs
  327. then
  328.   echo "#define HAVE_REMOVE 1"
  329. else
  330.   echo "#define remove unlink"
  331. fi
  332.  
  333. if has rename stdio.h $funnyincs
  334. then
  335.   define HAVE_RENAME
  336. else
  337.   echo "int rename (const char *, const char *);"
  338. fi
  339.  
  340. if has access $funnyincs
  341. then
  342.   define HAVE_ACCESS
  343. else
  344.   echo "int access (const char *fn, int how);"
  345. fi
  346.  
  347. if has getcwd $funnyincs
  348. then :
  349. else
  350.   echo "#define getcwd(P,L) getwd(P)"
  351. fi
  352.  
  353. if has stat sys/stat.h $funnyincs
  354. then
  355.   define HAVE_STAT
  356. fi
  357.  
  358. if has fstat sys/stat.h $funnyincs
  359. then
  360.   define HAVE_FSTAT
  361. fi
  362.  
  363. if has fileno stdio.h $funnyincs
  364. then
  365.   define HAVE_FILENO
  366. fi
  367.  
  368. if has truncate $funnyincs
  369. then
  370.   define HAVE_TRUNCATE
  371. else
  372.   echo "int truncate (const char *path, long length);"
  373. fi
  374.  
  375. if has umask sys/stat.h $funnyincs
  376. then
  377.   define HAVE_UMASK
  378. fi
  379.  
  380. if has link $funnyincs
  381. then
  382.   define HAVE_LINK
  383. fi
  384.  
  385. if has getpid $funnyincs process.h sys/process.h
  386. then
  387.   define HAVE_PID
  388. fi
  389.  
  390. if has getuid $funnyincs process.h sys/process.h
  391. then
  392.   define HAVE_UID
  393. fi
  394.  
  395. if has getgid $funnyincs process.h sys/process.h
  396. then
  397.   define HAVE_GID
  398. fi
  399.  
  400. # Time related:
  401. if has usleep stdlib.h time.h sys/time.h $funnyincs
  402. then
  403.   define HAVE_USLEEP
  404. fi
  405.  
  406. if has select stdlib.h time.h sys/time.h sys/select.h $funnyincs
  407. then
  408.   define HAVE_SELECT
  409. fi
  410.  
  411. if has delay dos.h conio.h i86.h $funnyincs
  412. then
  413.   define HAVE_DELAY
  414. fi
  415.  
  416. if has _sys_siglist signal.h sys/signal.h $funnyincs
  417. then
  418.   define HAVE_SYS_SIGLIST
  419.   echo "#define sys_siglist _sys_siglist"
  420. else
  421.   if has sys_siglist signal.h sys/signal.h $funnyincs
  422.   then
  423.     define HAVE_SYS_SIGLIST
  424.   fi
  425. fi
  426.  
  427. if has raise signal.h sys/signal.h $funnyincs
  428. then
  429.   define HAVE_RAISE
  430. else
  431.   echo "#define raise(X) kill (getpid (), X)"
  432. fi
  433.  
  434. if has ospeed termcap.h
  435. then
  436.   define HAVE_OSPEED
  437. fi
  438.  
  439.  
  440. if has optind getopt.h $funnyincs
  441. then
  442.   : # I assume optarg is defined too.
  443. else
  444.   echo "extern int optind;"
  445.   echo "extern char *optarg;"
  446. fi
  447.  
  448. #
  449. # Compiler properties.
  450. #
  451.  
  452. if compile const \
  453.    "const char *p;"
  454. then : # ok, compiler did grok const.
  455. else
  456.   echo "#define const"
  457. fi
  458.  
  459. if compile "ANSI cpp" \
  460.    "#define STR(X) #X" \
  461.    "char s [] = STR(asdf);"
  462. then : # ok, compiler did understand #X substitution.
  463. else
  464.   define OLDCPP
  465. fi
  466.  
  467. } > config.h
  468.  
  469.  
  470. #
  471. # Determine Cell type, byte sex and alignment restrictions:
  472. #
  473.  
  474. $make clean >&2
  475. rm -f check_c$e check_c$o
  476. if $make check_c$e >&2
  477. then
  478.   ./check_c$e >> config.h
  479.   rm -f check_c$e check_c$o
  480. else
  481.   echo compiling test program failed >&2
  482.   echo aborting. >&2
  483.   rm -f check_c$e check_c$o
  484.   exit 1
  485. fi
  486.  
  487. echo "
  488. #endif" >> config.h
  489.  
  490. # Some shells need this explicitly to execute the trap-code.
  491. exit 0
  492.