home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ircd_os2.zip / config < prev    next >
Text File  |  1996-03-12  |  12KB  |  544 lines

  1. #!/bin/sh
  2. #
  3. # (C) 1993, 1994 By Darren Reed, avalon@coombs.anu.edu.au
  4. # You may distribute this file without changes freely providing this notice
  5. # remains intact.  This file may not be redistributed or made available for
  6. # distribution without the author's prior consent.
  7. #
  8. trap "" 13 14 15
  9. MV=/bin/mv
  10. RM=/bin/rm
  11. SETUP=include/setup.h
  12. #
  13. STDLIBH=undef
  14. STDDEFH=undef
  15. SYSSYSLOGH=undef
  16. MALLOCH=undef
  17. PARAMH=undef
  18. UNISTDH=undef
  19. STRINGH=undef
  20. STRINGSH=undef
  21. NOINDEX=undef
  22. NSTRERROR=undef
  23. NSTRTOKEN=undef
  24. NSTRTOK=undef
  25. NINETADDR=undef
  26. NINETNTOA=undef
  27. NINETNETOF=undef
  28. GETTIMEOFDAY=undef
  29. LRAND48=undef
  30. CCPATH='gcc'
  31. SIGNAL=''
  32. BLOCKING=''
  33. TMP=Configtmp.c
  34. EXEC=Configtmp
  35. PLATE=ConPlate
  36. c=''
  37. n=''
  38. #
  39. 2>/dev/null
  40. if [ "`eval echo -n 'a'`" = "-n a" ] ; then
  41.     c='\c'
  42. else
  43.     n='-n'
  44. fi
  45. #if [ ! -f Makefile.bak ] ; then
  46. #    mv Makefile Makefile.bak
  47. #    cp Makefile.bak Makefile
  48. #    chmod ugo-xw Makefile Makefile.bak
  49. #    chmod u+w Makefile
  50. #fi
  51. echo " "
  52. echo "   Welcome to autoconfigure for the IRC server."
  53. echo "Before running this script and expecting it to work, please fix the"
  54. echo "Makefile in this directory (I can only do so much without your help!)"
  55. echo "and I'll look into it for help and to checkup on your compiler"
  56. echo "preferences, etc"
  57. echo " "
  58. echo "Enter \"none\" at any prompt to effect a null entry."
  59. echo " "
  60. FOO=`egrep "^CC=" Makefile 2>/dev/null | sed -e 's/^[^=]*[     ]*=\(.*\)/\1/'`
  61. while [ -z "$CCPATH" ] ; do
  62.     MYP=`echo "$PATH" | sed -e 's/:/ /g'`
  63.     echo "Which compiler do you use, gcc or cc or...?"
  64.     echo $n "[$FOO] -> $c"
  65.     read cc
  66.     if [ -z "$cc" ] ; then
  67.         cc=$FOO
  68.         CCPATH=$FOO
  69.     elif [ -f $cc ] ; then
  70.         CCPATH=$cc
  71.     else
  72.         for i in $MYP; do
  73.             if [ -f $i/$cc -a -z "$CCPATH" ] ; then
  74.                 CCPATH=$i/$cc
  75.             fi
  76.         done
  77.     fi
  78. done
  79. if [ "$FOO" != "$cc" ] ; then
  80.     MYP=`echo "$CCPATH" | sed -e 's@/@ @g'`
  81.     set $MYP
  82.     if [ $2 ] ; then
  83.         while [ $2 ] ; do
  84.             shift
  85.         done
  86.     fi
  87.     if [ $1 = "gcc" ] ; then
  88.         echo Heh
  89.     fi
  90. fi
  91. echo "Compiler selected: $CCPATH"
  92. echo " "
  93. # Check it out
  94. cat > $TMP <<_EOF_
  95. main() {}
  96. _EOF_
  97. $CCPATH $TMP -o $EXEC >/dev/null 2>&1
  98. #if [ ! -f $EXEC ] ; then
  99. #        echo "You don't have $CCPATH or it's broken!"
  100. #        exit 1
  101. #fi
  102. # Fix Makefile
  103. #
  104. #$RM -f $TMP
  105. #sed -e "s@^CC=\(.*\)@CC=$CCPATH@" Makefile > $TMP
  106. #cp $TMP Makefile
  107. #$RM -f $TMP
  108. #
  109. echo "Enter additional flags to give to $CCPATH"
  110. FOO=`egrep "^CFLAGS=" Makefile 2>/dev/null | sed -e 's/^[^=]*=[     ]*\(.*\)/\1/'`
  111. INC=`egrep "^INCLUDEDIR=" Makefile 2>/dev/null | sed -e 's/^[^=]*=\(.*\)/\1/'`
  112. FOO=`echo "$FOO" | sed -e "s@\\$(INCLUDEDIR)@$INC@"`
  113. echo $n "[$FOO] -> $c"
  114. read cc
  115. if [ "$cc" = "none" ] ; then
  116.     cc=''
  117. elif [ -z "$cc" ] ; then
  118.     cc=$FOO
  119. fi
  120. CFLAGS=$cc
  121. # Fix Makefile
  122. #
  123. #$RM -f $TMP
  124. #sed -e "s@^CFLAGS=\(.*\)@CFLAGS=$CFLAGS@" Makefile > $TMP
  125. #cp $TMP Makefile
  126. #$RM -f $TMP
  127. #
  128. echo " "
  129. echo "If you need to use any extra libraries when compiling the server,"
  130. echo "please tell me now (might need to look at the Makefiles) and please"
  131. echo "include all the -l and -L flags (I'm lame)."
  132. LIBS=`egrep "^IRCDLIBS=" Makefile 2>/dev/null | sed -e 's/^[^=]*=\(.*\)/\1/' | tr -d "\012"`
  133. echo $n "[$LIBS] -> $c"
  134. read cc;
  135. if [ "$cc" = "none" ] ; then
  136.     cc=''
  137. elif [ -z "$cc" ] ; then
  138.     cc=$LIBS
  139. fi
  140. LIBS=$cc
  141. # Fix Makefile
  142. #
  143. #$RM -f $TMP
  144. #sed -e "s@^IRCDLIBS=\(.*\)@IRCDLIBS=$LIBS@" Makefile > $TMP
  145. #cp $TMP Makefile
  146. #$RM -f $TMP
  147. #
  148. COMP="$CCPATH $CFLAGS $TMP -o $EXEC $LIBS"
  149. #
  150. #
  151. echo 'Checking out /usr/include'
  152. echo $n "...Looking for /usr/include/stdlib.h...$c"
  153. if [ -r /usr/include/stdlib.h ] ; then
  154.     STDLIBH=define
  155.     echo  'found!'
  156. else
  157.     echo 'not found :('
  158. fi
  159. # gcc has its own stddef.h
  160. FOO=''
  161. if [ ! -z "`echo $CCPATH | grep gcc`" ] ; then
  162.     FOO=`$CCPATH -v 2>&1 | head -1 | \
  163.         sed -e 's/Reading specs from //' -e 's/specs$/include/'`
  164. fi
  165. echo $n "...Looking for stddef.h...$c"
  166. if [ -r $FOO/stddef.h ] ; then
  167.     STDDEFH=define
  168.         echo "found in $FOO!"
  169. elif [ -r /usr/include/stddef.h ] ; then
  170.         STDDEFH=define
  171.     echo  'found!'
  172. else
  173.     echo 'not found :('
  174. fi
  175. echo $n "...Looking for /usr/include/sys/syslog.h...$c"
  176. if [ -r /usr/include/sys/syslog.h ] ; then
  177.     SYSSYSLOGH=define
  178.     echo  'found!'
  179. else
  180.     echo 'not found :('
  181. fi
  182. echo $n "...Looking for malloc.h...$c"
  183. if [ -r /usr/include/malloc.h ] ; then
  184.     MALLOCH=malloc.h
  185.     echo  'found!'
  186. elif [ -r /usr/include/sys/malloc.h ] ; then
  187.     MALLOCH=sys/malloc.h
  188.     echo  'found!'
  189. else
  190.     echo 'not found :('
  191.     MALLOCH=undef
  192. fi
  193. echo $n "...Looking for /usr/include/sys/param.h...$c"
  194. if [ -r /usr/include/sys/param.h ] ; then
  195.     PARAMH=define
  196.     echo  'found!'
  197. else
  198.     echo 'not found :('
  199. fi
  200. echo $n "...Looking for /usr/include/unistd.h...$c"
  201. if [ -r /usr/include/unistd.h ] ; then
  202.     UNISTDH=define
  203.     echo  'found!'
  204. else
  205.     echo 'not found :('
  206. fi
  207. echo $n "...Looking for /usr/include/string.h...$c"
  208. if [ -r /usr/include/string.h ] ; then
  209.     STRINGH=define
  210.     echo  'found!'
  211. else
  212.     echo 'not found :('
  213. fi
  214. echo $n "...Looking for /usr/include/strings.h...$c"
  215. if [ -r /usr/include/strings.h ] ; then
  216.     STRINGSH=define
  217.     echo  'found!'
  218. else
  219.     echo 'not found :('
  220. fi
  221. #
  222. # to b or not to b
  223. #
  224. echo " "
  225. bzero=bzero
  226. echo $n "Which one, gettimeofday, or lrand48..$c"
  227.     echo "We have a winner! gettimeofday found."
  228.     GETTIMEOFDAY=define
  229. #
  230. # check for non-blocking fd style available..
  231. #
  232. echo " "
  233. echo 'Checking for POSIX/BSD/SYSV non-blocking stuff'
  234. BLOCK=fionbio
  235. echo "Blocking selected: $BLOCK";
  236. #
  237. # reliable signals ?
  238. #
  239. echo 'Looking for reliable signals...'
  240. echo "Hmmm...wonder if you have 'action from POSIX..."
  241. SIGNAL=posix
  242. #
  243. echo 'Now those strings libraries...hmm...which one is it...'
  244. cat > $TMP <<_EOF_
  245. #$STRINGH STRINGH
  246. #$STRINGSH STRINGSH
  247. #ifdef STRINGH
  248. #include <string.h>
  249. #endif
  250. #ifdef STRINGSH
  251. #include <strings.h>
  252. #endif
  253. main()
  254. {
  255.     char *s = index("foo", 'o');
  256.     exit(0);
  257. }
  258. _EOF_
  259. $COMP >/dev/null 2>&1
  260. if [ $? -eq 0 ] ; then
  261.     echo "Cool...you have index()!"
  262. else
  263.     NOINDEX=define
  264.     echo "Grmpf...I guess there is a strchr() out there somewhere..."
  265. fi
  266. $RM -f $EXEC $TMP
  267. #
  268. # getrusage or times ?
  269. #
  270. echo $n "One for debugging, mainly, getrusage(2) or times(2)...$c"
  271. cat > $TMP <<_EOF_
  272. #include <sys/types.h>
  273. #include <sys/time.h>
  274. #include <sys/resource.h>
  275. main()
  276. {
  277.     struct    rusage    rus;
  278.     (void)getrusage(RUSAGE_SELF, &rus);
  279. }
  280. _EOF_
  281. $COMP >/dev/null 2>&1
  282. if [ $? -eq 0 ] ; then
  283.     TIMES=getrusage
  284.     echo "getrusage()"
  285. else
  286.     $RM -f $EXEC $TMP
  287.     cat > $TMP <<_EOF_
  288. #include <sys/types.h>
  289. #include <sys/time.h>
  290. #include <sys/times.h>
  291. main()
  292. {
  293.     struct    tms    tmsbuf;
  294.     (void)times(&tmsbuf);
  295. }
  296. _EOF_
  297.     $COMP >/dev/null 2>&1
  298.     if [ $? -eq 0 ] ; then
  299.         TIMES=times
  300.         echo "times()"
  301.     else
  302.         echo "couldn't get either ?!"
  303.         TIMES=none
  304.     fi
  305. fi
  306. #
  307. # what do we need that isn't here already ?
  308. #
  309. echo "What else do I need that you don't have..."
  310. echo $n "Lets see...$c"
  311. cat > $TMP <<_EOF_
  312. main()
  313. {
  314.     char  *s = strerror(0);
  315.     exit(0);
  316. }
  317. _EOF_
  318. $COMP >/dev/null 2>&1
  319. if [ $? -ne 0 ] ; then
  320.     echo $n " strerror$c"
  321.     NSTRERROR=define
  322. fi
  323. $RM -f $EXEC $TMP
  324. cat > $TMP <<_EOF_
  325. #$STRINGH STRINGH
  326. #$STRINGSH STRINGSH
  327. #ifdef STRINGH
  328. #include <string.h>
  329. #endif
  330. #ifdef STRINGSH
  331. #include <strings.h>
  332. #endif
  333. main()
  334. {
  335.     char  *t = "a", **p = NULL, *s = strtoken(&p, t, ",");
  336.     if (!strcmp(t, s))
  337.         exit(0);
  338.     exit(1);
  339. }
  340. _EOF_
  341. $COMP >/dev/null 2>&1
  342. if [ $? -ne 0 ] ; then
  343.     echo $n " strtoken$c"
  344.     NSTRTOKEN=define
  345. else
  346.     $EXEC
  347.     if [ $? -ne 0 ] ; then
  348.         echo $n " strtoken$c"
  349.         NSTRTOKEN=define
  350.     fi
  351. fi
  352. $RM -f $EXEC $TMP
  353. cat > $TMP <<_EOF_
  354. #$STRINGH STRINGH
  355. #$STRINGSH STRINGSH
  356. #ifdef STRINGH
  357. #include <string.h>
  358. #endif
  359. #ifdef STRINGSH
  360. #include <strings.h>
  361. #endif
  362. main()
  363. {
  364.     char  *t = "a", *s = strtok(t, ",");
  365.     if (!strcmp(t, s))
  366.         exit(0);
  367.     exit(1);
  368. }
  369. _EOF_
  370. $COMP >/dev/null 2>&1
  371. if [ $? -ne 0 ] ; then
  372.     echo $n " strtok$c"
  373.     NSTRTOK=define
  374. else
  375.     $EXEC
  376.     if [ $? -ne 0 ] ; then
  377.         echo $n " strtok$c"
  378.         NSTRTOK=define
  379.     fi
  380. fi
  381. $RM -f $EXEC $TMP
  382. cat > $TMP << _EOF_
  383. #include <sys/types.h>
  384. #include <netinet/in.h>
  385. main()
  386. {
  387.     struct    in_addr in;
  388.     (void)inet_addr("1.2.3.4");
  389. }
  390. _EOF_
  391. $COMP >/dev/null 2>&1
  392. if [ $? -ne 0 ] ; then
  393.     echo $n " inet_addr$c"
  394.     NINETADDR=define
  395. fi
  396. $RM -f $EXEC $TMP
  397. cat > $TMP << _EOF_
  398. #include <sys/types.h>
  399. #include <netinet/in.h>
  400. main()
  401. {
  402.     struct    in_addr    in;
  403.     in.s_addr = 0x12345678;
  404.     (void)inet_ntoa(in);
  405. }
  406. _EOF_
  407. $COMP >/dev/null 2>&1
  408. if [ $? -ne 0 ] ; then
  409.     echo $n " inet_ntoa$c"
  410. fi
  411. $RM -f $EXEC $TMP
  412. cat > $TMP << _EOF_
  413. #include <sys/types.h>
  414. #include <netinet/in.h>
  415. main()
  416. {
  417.     struct    in_addr    in;
  418.     in.s_addr = 0x87654321;
  419.     (void)inet_netof(in);
  420. }
  421. _EOF_
  422. $COMP >/dev/null 2>&1
  423. if [ $? -ne 0 ] ; then
  424.     echo $n " inet_netof$c"
  425.     NINETNETOF=define
  426. fi
  427. $RM -f $EXEC $TMP
  428. echo " "
  429. #
  430. #
  431. #
  432. echo " "
  433. echo "Ok, here's your chance...I think you should use $BLOCK, you want"
  434. echo "which of these ? O_NONBLOCK (POSIX) O_NDELAY (BSD) FIONBIO (SYSV)"
  435. echo $n "[$BLOCK] -> $c"
  436. read cc
  437. if [ "$cc" = "none" ] ; then
  438.     cc=''
  439. elif [ -z "$cc" ] ; then
  440.     cc=$BLOCK
  441. fi
  442. BLOCK=$cc
  443. echo "I found $SIGNAL signals."
  444. if [ "$cc" = "none" ] ; then
  445.     cc=''
  446. elif [ "$SIGNAL" = "posix" ] ; then
  447.     echo "Hmmm...I'm not sure if signal() is reliable or not either..."
  448. fi
  449. echo "You can choose between posix, bsd and sysv.  What'll it be ?"
  450. echo $n "[$SIGNAL] -> $c"
  451. read cc
  452. if [ "$cc" = "none" ] ; then
  453.     cc=''
  454. elif [ -z "$cc" ] ; then
  455.     cc=$SIGNAL
  456. fi
  457. SIGNAL=$cc
  458. if [ "$TIMES" = "none" ] ; then
  459.     echo "I didn't find either getrusage or times earlier...If you do have"
  460.     echo "either of these, please tell me now."
  461. else
  462.     echo "I found $TIMES, out of getrusage and times.  getrusage is"
  463.     echo "more informative.  If you wish to swap your choice, please"
  464.     echo "do so now."
  465. fi
  466. echo $n "[$TIMES] -> $c"
  467. read cc
  468. if [ "$cc" = "none" ] ; then
  469.     cc=''
  470. elif [ -z "$cc" ] ; then
  471.     cc=$TIMES
  472. fi
  473. TIMES=$cc
  474.  
  475. $RM -f $EXEC $TMP $PLATE
  476. $MV -f $SETUP $SETUP.bak 2>/dev/null
  477. cat > $SETUP  <<_EOF_
  478. #ifndef __setup_include__
  479. #define __setup_include__
  480. #$PARAMH    PARAMH
  481. #$UNISTDH    UNISTDH
  482. #$STRINGH    STRINGH
  483. #$STRINGSH    STRINGSH
  484. #$STDLIBH    STDLIBH
  485. #$STDDEFH    STDDEFH
  486. #$SYSSYSLOGH    SYSSYSLOGH
  487. #$NOINDEX    NOINDEX
  488. #$NSTRERROR    NEED_STRERROR
  489. #$NSTRTOKEN    NEED_STRTOKEN
  490. #$NSTRTOK    NEED_STRTOK
  491. #$NINETADDR    NEED_INET_ADDR
  492. #$NINETNTOA    NEED_INET_NTOA
  493. #$NINETNETOF    NEED_INET_NETOF
  494. #$GETTIMEOFDAY    GETTIMEOFDAY
  495. #$LRAND48    LRAND48
  496. _EOF_
  497. if [ "$MALLOCH" = "undef" ] ; then
  498.     echo "#undef    MALLOCH" >> $SETUP
  499. else
  500.     echo "#define    MALLOCH    <$MALLOCH>" >> $SETUP
  501. fi
  502. if [ "$BZERO" = "memset" ] ; then
  503.     cat >> $SETUP <<_EOF_
  504. #define    bzero(a,b)    memset(a,0,b)
  505. #define    bcopy(a,b,c)    memcpy(b,a,c)
  506. #define    bcmp    memcmp
  507. _EOF_
  508. fi
  509. if [ "$BLOCK" = "O_NONBLOCK" ] ; then
  510.     echo "#define    NBLOCK_POSIX" >> $SETUP
  511. elif [ "$BLOCK" = "O_NDELAY" ] ; then
  512.     echo "#define    NBLOCK_BSD" >> $SETUP
  513. else
  514.     echo "#define    NBLOCK_SYSV" >> $SETUP
  515. fi
  516. if [ "$SIGNAL" = "posix" ] ; then
  517.     echo "#define    POSIX_SIGNALS" >> $SETUP
  518. elif [ "$SIGNAL" = "bsd" ] ; then
  519.     echo "#define    BSD_RELIABLE_SIGNALS" >> $SETUP
  520. else
  521.     echo "#define    SYSV_UNRELIABLE_SIGNALS" >> $SETUP
  522. fi
  523. if [ "$TIMES" = "times" ] ; then
  524.     echo "#define    TIMES_2" >> $SETUP
  525.     echo "#undef    GETRUSAGE_2" >> $SETUP
  526. elif [ "$TIMES" = "getrusage" ] ; then
  527.     echo "#undef    TIMES_2" >> $SETUP
  528.     echo "#define    GETRUSAGE_2" >> $SETUP
  529. else
  530.     echo "#undef    TIMES_2" >> $SETUP
  531.     echo "#undef    GETRUSAGE_2" >> $SETUP
  532. fi
  533. echo "#endif" >> $SETUP
  534. touch include/config.h
  535. echo " "
  536. echo "If you would like to issue any shell commands before proceeding, do so"
  537. echo "now.  My findings are in include/setup.h if you wish to change them."
  538. echo $n "--> $c"
  539. read cc
  540. if [ ! -z "$cc" ] ; then
  541.     $cc
  542. fi
  543. exit 0
  544.