home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / dbmalloc / part02 < prev    next >
Encoding:
Text File  |  1992-09-03  |  56.9 KB  |  2,195 lines

  1. Newsgroups: comp.sources.misc
  2. From: cpcahil@vti.com (Conor P. Cahill)
  3. Subject:  v32i007:  dbmalloc - Debug Malloc Library PL14, Part02/10
  4. Message-ID: <1992Sep4.151803.12409@sparky.imd.sterling.com>
  5. X-Md4-Signature: cda2b8042dd9b1480821f4d65e3b2fd6
  6. Date: Fri, 4 Sep 1992 15:18:03 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: cpcahil@vti.com (Conor P. Cahill)
  10. Posting-number: Volume 32, Issue 7
  11. Archive-name: dbmalloc/part02
  12. Environment: C, UNIX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 2 (of 10)."
  21. # Contents:  PROBLEMS Buildpatch Configure Runtests teststack.c
  22. # Wrapped by cpcahil@virtech on Thu Sep  3 18:39:18 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'PROBLEMS' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'PROBLEMS'\"
  26. else
  27. echo shar: Extracting \"'PROBLEMS'\" \(13221 characters\)
  28. sed "s/^X//" >'PROBLEMS' <<'END_OF_FILE'
  29. X
  30. XThis file documents the problems that have been found when the library
  31. Xis ported to different machines.  Where possible, a generic solution
  32. Xhas been added to the library so that the problem does not re-occur.
  33. X
  34. XNOTES specific to a particular implementation are included at the end
  35. Xof this file.  Search for ^SYSTEM if you want to jump to them:
  36. X
  37. X0. Configure script has a problem
  38. X    
  39. X    One note about problems with configure is that they are frequently
  40. X    caused by someone who has installed an ansi compiler like gcc and
  41. X    hasn't changed the system include files accordingly.
  42. X
  43. X    Configure will attempt to guess at the correct settings even if it
  44. X    is not able to determine if they are correct.  Theses guessed at 
  45. X    settings will be flaged by a '/* *GUESS* */' to the right of the
  46. X    definition and should be reviewed to make sure they are right.
  47. X
  48. X    If this happens, you should determine if the problem is a problem
  49. X    with the script itself, or with the script being able to determine
  50. X    the correct settings for your compiler/os combination.  
  51. X
  52. X    If you find that it is a bug in the script, please report it to 
  53. X    the author so that the fix can be incorporated into future releases.
  54. X    This is most likely the cause of a problem.  You should pay 
  55. X    particular attention to the fact that Configure *guesses* that it
  56. X    found the correct settings by compiling a test module and verifying
  57. X    that there were no warning messages generated.  It is possible that
  58. X    you have a strict ANSI compiler that is warning about something in
  59. X    the test file cctest.c which really has nothing to do with the 
  60. X    Configuration.
  61. X    
  62. X    If, however, the script appears to be processing the data correctly,
  63. X    but is still unable to determine the correct settings for your system
  64. X    you will have to configure the file by hand.  This involves the
  65. X    following steps:
  66. X
  67. X    A) create .configure file that contains the following lines
  68. X
  69. X        #define VOIDTYPE     <voidtype>
  70. X        #define CONST        <const>
  71. X        #define DATATYPE    <malloc_datatype>
  72. X        #define SIZETYPE    <malloc_sizetype>
  73. X        #define MEMDATA        <mem_datatype>
  74. X        #define MEMSIZE        <mem_sizetype>
  75. X        #define MEMCMPTYPE    <mem_comptype>
  76. X        #define STRSIZE        <str_sizetype>
  77. X        #define STRCMPTYPE    <str_comptype>
  78. X
  79. X    where
  80. X
  81. X        voidtype        is void if your compiler understands
  82. X                void data types, int otherwise
  83. X        const        is const if your compiler understands
  84. X                constant variables
  85. X        malloc_datatype    is the base type of the pointer returned by
  86. X                malloc (usually char or void)
  87. X        malloc_sizetype    is the type of the size argument used by
  88. X                malloc and its associates (usually size_t,
  89. X                int, or unsigned int)
  90. X        mem_datatype    is the base type of the pointer returned by
  91. X                the mem* functions (like memcpy()). This is
  92. X                usually char or void.
  93. X        mem_sizetype    is the type of the len argument used by
  94. X                the mem* functions (usually size_t,
  95. X                int, or unsigned int).
  96. X        mem_comptype    type to be used for comparisons of the differing
  97. X                characters in the memory comparison functions.
  98. X                This will usually be char or unsigned char. ANSI
  99. X                C says it will be unsigned char.
  100. X        str_sizetype    is the type of the len argument used by
  101. X                the str* functions (like strncpy()).  This is
  102. X                usually size_t, int, or unsigned int.
  103. X        str_comptype    type to be used for comparisons of the differing
  104. X                characters in the string comparison functions.
  105. X                This will usually be char or unsigned char. ANSI
  106. X                C says it will be unsigned char.
  107. X
  108. X    B) create .configure.s file that contains the following lines:
  109. X
  110. X        #define ABORT_SIGNAL    <abortsignum>
  111. X        #define WRTSIZE        <write_sizetype>
  112. X
  113. X    where
  114. X    
  115. X        abortsignum        is the signal number used to abort a program.
  116. X                This is usually SIGABRT or SIGIOT.
  117. X        write_sizetype    is the type of the size (or length) parameter
  118. X                to the write system call.  This will usually
  119. X                be size_t, unsigned int, or int
  120. X
  121. X    In addition
  122. X
  123. X        if your compiler/libraries do not support the putenv() 
  124. X        call, but instead support setenv(), add the following line:
  125. X
  126. X            #define USE_SETENV 1
  127. X
  128. X        If your system has an Intrinsic.h file in /usr/include/X11,
  129. X        add the following line:
  130. X
  131. X            #define FOUND_X_INTRINSIC 1
  132. X
  133. X        If wait.h is available for wait() system call parameter 
  134. X        definitions, add the following line:
  135. X    
  136. X            #define NEED_WAIT 1
  137. X    
  138. X        If you are running X11R4 or before and you intend to use the
  139. X        library to link with X programs, add the following line:
  140. X
  141. X            #define DONT_FORCE_HEAPSTUFF 1
  142. X
  143. X    C) If you want to preclude the use of the system memset and memcpy
  144. X    modules (which if they can be used will usually result in a 
  145. X    significant performance gain), create a .configure.O (capital letter o)
  146. X    file with something in it (i.e. date > .configure.O).
  147. X
  148. X    D) run Configure to generate the appropriate .h files (and if you
  149. X    didn't create the .configure.O file in step C, the converted system
  150. X    memset and memcpy routines, if they are compatible and useful)
  151. X
  152. X    NOTE: Configure attempts to grab the memset.o and memmove(or memcpy)
  153. X    routines from libc.a, if it can find them, and convert them for
  154. X    use by the library since these modules are usually modified by the
  155. X    vendor so that they take advantage of assembly language features
  156. X    to improve performance. 
  157. X
  158. X    If libc.a cannot be found, or if the system modules are not compatible
  159. X    with the malloclib versions (this frequently happens with memcpy since
  160. X    the malloclib version correctly handles moving data around in
  161. X    overlapped regions), then Configure will not include them and the
  162. X    library will include its own version (which has been optimized in a
  163. X    portable fashion).
  164. X
  165. X    If the files datamc.O and datams.O do not get created, then this was
  166. X    the case.  You can improve the performance of the library significantly
  167. X    by coding compatible libraries in assembly language if your cpu
  168. X    has specialized data movement instructions.  See the datamc.c routine
  169. X    for a sample of such a mechanism used to optimize memcpy() operations
  170. X    on a 386.
  171. X
  172. X    If you do this, and it passes all of the tests (including the 1,000,000
  173. X    allocation test for testmalloc), please send it in and I will include
  174. X    it in the next release.
  175. X
  176. X
  177. X1. Compilation problems with the library itself.
  178. X
  179. X    This is a fairly common problem and is most often associated with
  180. X    the settings for the .configure #defines.  If you get any compilation
  181. X    errors for modules within this library, the first thing you should
  182. X    do is verify that you are using the correct settings for these
  183. X    typedefs.  Review the description on what they should be set to and 
  184. X    review the original settings.
  185. X
  186. X    Another common problem is attempting to compile the library and/or
  187. X    test with a strict ANSI-C compiler.  Since ANSI reserves symbols
  188. X    like malloc, memcpy, strcpy, etc you can expect to have a lot of
  189. X    problems.  This is especially so if the ANSI is very strict 
  190. X    because the library does make use of UNIX functionality like fork,
  191. X    wait, open, write, etc.
  192. X
  193. X    If you have access to an standard K&R compiler (or a more relaxed 
  194. X    ANSI compiler, especially one that uses the system K&R style header
  195. X    files (i.e. gcc without -pedantic on a system with a non-ANSI cc)
  196. X    you should use it to compile the library.  Once the library is
  197. X    compiled, you should be able to use it with code compiled under
  198. X    other compilers (assuming, of course, that they are compatible).
  199. X    
  200. X
  201. X2. Conflicts with system provided string.h/memory.h includes
  202. X
  203. X    The library provides its own versions of these functions, but includes
  204. X    the system header files so that if it compiles with no errors, you
  205. X    will know that the two agree exactly.   The Configure script should
  206. X    have ensured that they agreed, but is it possible that it got them
  207. X    wrong.  Check the .configure file to determine if the #defines are
  208. X    set correctly (as described in step 0)
  209. X
  210. X3. Duplicate symbols from libc.a (or its equivalent shared library)
  211. X
  212. X    This is most often caused by one of the system library functions
  213. X    including an additional function/variable definition in one of the
  214. X    memory/string library modules. (i.e. some systems have a cfree()
  215. X    call that is in the calloc.o library module).
  216. X
  217. X    There are several ways to get around this problem.  The best way
  218. X    would be to duplicate the functionality of the extra reference 
  219. X    where ever it is appropriate in the malloc library (similarly to
  220. X    the addition of cfree in the calloc.c module).   If you do this,
  221. X    please send me the new function and a description of the system and/or
  222. X    compiler so that I can determine if it should go into the standard
  223. X    distribution.
  224. X
  225. X    Another mechanism that has been reportedly used in some architectures
  226. X    is to ignore the duplicate symbol errors and just chmod the executable
  227. X    so that it is executable (i.e. chmod +x).  I don't know if this is 
  228. X    all that safe, or if it will work on your system, but it has been 
  229. X    reported to successfully work in this fashion.
  230. X    
  231. X    Another, less desirable way would be to disable the offending function
  232. X    in this library.  This option is less desirable because the disabled
  233. X    function would no longer provide any error checking (which is 
  234. X    supposed to be the purpose of this library).
  235. X
  236. X    With shared libraries, there are some formats (perhaps all) that
  237. X    have explicit references to functions in the shared library that
  238. X    are duplicated in the debug library.  On these systems, the
  239. X    only way around the problem is to not use the shared library 
  240. X    when linking the test version of the software.
  241. X
  242. X4. Compilation errors in string.c and/or memory.c
  243. X
  244. X    There are several compilers that provide in-line expansion of
  245. X    routines like strcpy.  This can cause real problems when we 
  246. X    try to compile our own version.  If you can disable the in-line
  247. X    expansion, that is the best way to go.  This should only be
  248. X    needed for the malloc library itself.  The source you are debugging
  249. X    should include the malloc.h file and therefore won't be calling
  250. X    strcpy, but instead will be calling DBstrcpy (because of a macro
  251. X    in malloc.h).
  252. X
  253. X    Disabling the in-lining of functions is usually accomplished by
  254. X    setting a compiler flag, or sometimes by predefining some #def
  255. X    that is used by system include files.
  256. X
  257. X    If you can't disable the in-line expansion, you will have to 
  258. X    disable the debug versions of the offending functions in the
  259. X    malloc library by adding a #ifdef around the code.  Be sure to
  260. X    just disable the functions that are giving you problems (i.e. don't
  261. X    disable all of string.c and don't disable the DB functions, because
  262. X    any code that includes malloc.h will attempt to use them).
  263. X
  264. X5. Conflicts/problems with prototypes.h
  265. X
  266. X    Prototypes.h is a generated file that has zillions of function
  267. X    prototypes for the malloc library.  You should not need to remake
  268. X    this module.  If, however, you have made changes to the calling
  269. X    arguments for some of the functions due to conflicts with system
  270. X    headers, you may have to modify or rebuild this file.
  271. X
  272. X    To rebuild the file using the makefile targets you must have the
  273. X    cproto prototype generator (available in comp.sources.misc, vols 17
  274. X    and 18).
  275. X
  276. X6. Argument mis-matches and syntax errors when including malloc.h
  277. X
  278. X    This is usually the result of including malloc.h before string.h
  279. X    and/or memory.h which causes lots of problems.  malloc.h attempts
  280. X    to avoid this problem by #defining a bunch of typical symbols used
  281. X    to preclude multiple inclusions of these files, but some systems do
  282. X    not have this multiple inclusion protection, or use a slightly 
  283. X    different symbol for the protection.
  284. X
  285. X    To get around this problem you could do one of the following:
  286. X
  287. X        1. change the code so that it includes malloc.h last.
  288. X        2. add multiple inclusion protection to the system include
  289. X           files.
  290. X        3. remove the #defines from malloc.h (which decreases the
  291. X           ability for the debug library to identify the source of
  292. X           the problems).
  293. X
  294. X    Another problem with including malloc.h will occur if you have local
  295. X    definitions of things like:
  296. X
  297. X            char * strcpy();
  298. X    
  299. X    which will result in a preprocessor or compiler error because of the
  300. X    #defines in malloc.h.  The recommended solution to this problem is
  301. X    to remove the local definitions and include the system header files
  302. X    that have the definitions (string.h in this case).  If you can't or
  303. X    don't want to do this, you can add #ifndef _DEBUG_MALLOC_INC and 
  304. X    #endif around the local definitions so that they are not included if
  305. X    the debugging version of malloc.h is included.
  306. X
  307. X    Yet another similar problem is the use of standard symbols for variable
  308. X    and/or structure element names.  This happens most often with the
  309. X    variable index. 
  310. X
  311. X    To fix this, you can change the name of the variable, #undef index
  312. X    after including the malloc library, or remove the #define index
  313. X    line from malloc.h
  314. X
  315. X**************************************************************************
  316. XSYSTEM SPECIFIC PROBLEMS
  317. X
  318. X
  319. XSun Sparc w/ SunOS 4.x and GCC 2.1
  320. X
  321. X    The header files provided by sun do not contain ansi standard 
  322. X    definitions for many of the modules used by the library and cause
  323. X    problems when included by code compiled by GCC.  This includes
  324. X    things like <memory.h> which has a prototype for memcpy which
  325. X    is something like void * memcpy(); and doesn't agree with the
  326. X    builtin definition in gcc (void * memcpy(void *, const void*, int)).
  327. X
  328. X    The solution to this problem would be to define the correct
  329. X    prototypes for memory.h in the system include file or in the
  330. X    gcc version of the include file. 
  331. X
  332. END_OF_FILE
  333. if test 13221 -ne `wc -c <'PROBLEMS'`; then
  334.     echo shar: \"'PROBLEMS'\" unpacked with wrong size!
  335. fi
  336. # end of 'PROBLEMS'
  337. fi
  338. if test -f 'Buildpatch' -a "${1}" != "-c" ; then 
  339.   echo shar: Will not clobber existing file \"'Buildpatch'\"
  340. else
  341. echo shar: Extracting \"'Buildpatch'\" \(4439 characters\)
  342. sed "s/^X//" >'Buildpatch' <<'END_OF_FILE'
  343. X#
  344. X# Buildpatch - shell script for automatically building patch files
  345. X#
  346. X# $Id: Buildpatch,v 1.12 1992/04/29 18:24:06 cpcahil Exp $
  347. X#
  348. Xif [ $# = 0 ]; then
  349. X    echo "usage: Buildpatch srcfiles..."
  350. X    exit 1
  351. Xfi
  352. X
  353. X#
  354. X# see if any files are still locked.  If so, we cannot proceed (they must be
  355. X# unlocked before a patch file can be built
  356. X#
  357. Xif rlog -l $* 2>rlog.err | grep "locked by:" >/dev/null; then
  358. X    echo "all files must be checked in before a patch file can be built"
  359. X    exit 1
  360. Xfi
  361. X
  362. Xif [ -s rlog.err ]; then
  363. X    echo "all files must be checked in before a patch file can be built"
  364. X    exit 1
  365. Xfi
  366. X
  367. Xrm -f rlog.err
  368. X
  369. X#
  370. X# determine the old and new patch levels and name the patchfile
  371. X#
  372. Xrm -f patchlevel    2> /dev/null
  373. Xco -q patchlevel     2> /dev/null
  374. X
  375. Xread title oldlevel < patchlevel
  376. X
  377. Xif [ "$oldlevel" -lt 10 ]; then
  378. X    OPATCH=patch.0$oldlevel
  379. X    ODIR=patches/p.0$oldlevel
  380. Xelse
  381. X    OPATCH=patch.$oldlevel
  382. X    ODIR=patches/p.$oldlevel
  383. Xfi
  384. X
  385. X#
  386. X# if the old patch is still lying around, move it the the save directory
  387. X#
  388. Xif [ -s "OPATCH" ]; then
  389. X
  390. X    if [ ! -d "$ODIR" ]; then
  391. X        mkdir $ODIR
  392. X    fi
  393. X
  394. X    mv ${OPATCH}* ${ODIR}
  395. X
  396. X    echo "Saved ${OPATCH} to ${ODIR}"
  397. Xfi
  398. X
  399. Xlevel=`expr "$oldlevel" + 1`
  400. X
  401. Xif [ "$level" -lt 10 ]; then
  402. X    PATCH=patch.0$level
  403. Xelse
  404. X    PATCH=patch.$level
  405. Xfi
  406. X    
  407. X
  408. X#
  409. X# check out current version of all files
  410. X#
  411. Xco -q -u $*
  412. X
  413. X#
  414. X# create the new patchlevel file
  415. X#
  416. Xecho "Buillding patch number $level..."
  417. Xco -q -l patchlevel
  418. Xecho "$title $level" > patchlevel 
  419. Xci -u -q -m"patch number $level" -t/dev/null patchlevel
  420. X
  421. X#
  422. X# create a new, empty patch file and empty directory for old versions of files
  423. X# Note that if the patch file already exists, we assume it is special directions
  424. X# for the patch and don't remove them.
  425. X#
  426. Xif [ -s $PATCH.inst ]; then
  427. X    cp $PATCH.inst $PATCH
  428. X    chmod 644 $PATCH
  429. Xelse
  430. X    cp /dev/null $PATCH
  431. X    chmod 644 $PATCH
  432. Xfi
  433. X
  434. Xif [ -d old ]; then
  435. X    rm -rf old
  436. Xfi
  437. Xmkdir old
  438. X
  439. X#
  440. X# Unpack the old shar files into the old directory
  441. X#
  442. X(
  443. X    echo "Building old directory for diff base"
  444. X
  445. X    cd old
  446. X    if [ "$oldlevel" -lt 10 ]; then
  447. X        oldlevel=0$oldlevel
  448. X    fi
  449. X
  450. X    #
  451. X    # if there isn't an oldshar directory, move them from the source
  452. X    # directory to the oldshar directory
  453. X    #
  454. X    if [ !  -d ../oldshars/$oldlevel ]; then
  455. X        mkdir ../oldshars/$oldlevel
  456. X        mv ../mallocshar.* ../oldshars/$oldlevel
  457. X    fi
  458. X
  459. X    #
  460. X    # unshar them into the current directory    
  461. X    #
  462. X    unshar -h /dev/null ../oldshars/$oldlevel/* > /dev/null 2>&1
  463. X
  464. X    #
  465. X    # if there are any commands to run before the patch is applied
  466. X    # run them now so that they are used when the patch is generated
  467. X    #
  468. X    grep "^CMD:" ../$PATCH | sed -e "s/^CMD://" > commands
  469. X
  470. X    if [ -s commands ]; then
  471. X        sh -x commands
  472. X    fi
  473. X)
  474. X
  475. X#
  476. X# process each source file
  477. X#
  478. Xecho "Generating diffs"
  479. Xfor i in $*
  480. Xdo
  481. X    #
  482. X    # if the file exists (then it has been changed and must be part of
  483. X    # the patch file
  484. X    #
  485. X    if [ -s $i ]; then
  486. X
  487. X        #
  488. X        # if the file hasn't changed, skip it
  489. X        #
  490. X        if cmp -s $i old/$i ; then
  491. X            continue;
  492. X        fi
  493. X
  494. X        #
  495. X        # name the file
  496. X        #
  497. X        echo "\nIndex: $i" >> $PATCH
  498. X
  499. X        #
  500. X        # if there is an old version, add the prerequisite
  501. X        #
  502. X        if [ -s old/$i ]; then
  503. X            
  504. X            #
  505. X            # get old rcs id
  506. X            #
  507. X            PREREQ="`rlog -rpatchlevel_$oldlevel $i |
  508. X                 grep '^revision' | cut -f2 -d' ' 2>/dev/null`"
  509. X
  510. X            #
  511. X            # if the id is in the file, add the prereq line
  512. X            #
  513. X            if fgrep "$PREREQ" old/$i > /dev/null 2>&1; then
  514. X
  515. X                echo "Prereq: $PREREQ" >> $PATCH
  516. X
  517. X            elif [ "$i" = "patchlevel" ]; then
  518. X
  519. X                echo "Prereq: $oldlevel" >> $PATCH
  520. X
  521. X            fi
  522. X        else
  523. X            > old/$i
  524. X        fi
  525. X
  526. X        # 
  527. X        # diff the file to generate the patch stuff
  528. X        #
  529. X        diff -c old/$i $i >> $PATCH
  530. X
  531. X    fi
  532. X
  533. Xdone
  534. X
  535. X#
  536. X# and now to check to verify that the patchfile correctly updates the
  537. X# old code to the current version.  First apply the patch to the old
  538. X# code and then see if there are any differences between the files.
  539. X#
  540. Xecho "Verifying patch..."
  541. X(
  542. X    cd old
  543. X
  544. X    patch < ../$PATCH > /dev/null 2>&1
  545. X)
  546. X
  547. XFILES="`
  548. Xfor i in $*
  549. Xdo
  550. X    if cmp -s $i old/$i; then
  551. X        continue;
  552. X    fi
  553. X
  554. X    echo file $i did not patch correctly > /dev/tty
  555. X    echo $i
  556. Xdone `"
  557. X
  558. Xif [ ! -z "$FILES" ]; then
  559. X
  560. X    echo "patch file did not build correctly($FILES)."
  561. X    exit 1
  562. X
  563. Xfi
  564. X
  565. Xrm -rf old
  566. X
  567. Xecho "Verification complete"
  568. X
  569. X#
  570. X# and now freeze all the files at this patchlevel, and checkout the current
  571. X# versions of the files
  572. X#
  573. X
  574. Xecho "freezing source at patch level $level"
  575. Xecho "." | rcsfreeze patchlevel_$level  > /dev/null 2>&1 
  576. X
  577. Xecho "checking out current version (unlocked)"
  578. Xco -q -u -rpatchlevel_$level $*
  579. X
  580. X#
  581. X# build patch shar files from patch file
  582. X#
  583. Xshar3 -F -c -o$PATCH -L60 $PATCH
  584. X
  585. Xexit 0
  586. END_OF_FILE
  587. if test 4439 -ne `wc -c <'Buildpatch'`; then
  588.     echo shar: \"'Buildpatch'\" unpacked with wrong size!
  589. fi
  590. # end of 'Buildpatch'
  591. fi
  592. if test -f 'Configure' -a "${1}" != "-c" ; then 
  593.   echo shar: Will not clobber existing file \"'Configure'\"
  594. else
  595. echo shar: Extracting \"'Configure'\" \(29712 characters\)
  596. sed "s/^X//" >'Configure' <<'END_OF_FILE'
  597. X#!/bin/sh
  598. X#
  599. X#
  600. X# (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  601. X#
  602. X# This software may be distributed freely as long as the following conditions
  603. X# are met:
  604. X#         * the distribution, or any derivative thereof, may not be
  605. X#          included as part of a commercial product
  606. X#        * full source code is provided including this copyright
  607. X#        * there is no charge for the software itself (there may be
  608. X#          a minimal charge for the copying or distribution effort)
  609. X#        * this copyright notice is not modified or removed from any
  610. X#          source file
  611. X#
  612. X# $Id: Configure,v 1.22 1992/08/22 16:27:13 cpcahil Exp $
  613. X#
  614. X# This shell script attempts to automatically determine the correct settings
  615. X# for the malloc library include file and compile pre-defines.  This script has
  616. X# been tested by the author in the following environments:
  617. X#
  618. X#    Intel 486    ISC UNIX 3.0    cc & gcc 2.1
  619. X#    Intel 486    DELL SVR4     cc & gcc 1.40
  620. X#    HP9000        HP/UX 8.0    cc & cc -Aa -D_POSIX_SOURCE
  621. X#    AT&T 3B2-600    SVR4.1ES    cc (relaxed ansi - no cc flags)
  622. X#    IBM RS6000    AIX 3.1        cc 
  623. X#    Sun Sparc 2    SunOS 4.1.1    cc
  624. X#
  625. X# It has also been reported to work in the following environments:
  626. X#
  627. X#    DG AViiON    DG/UX        gcc 2.1 & cc (which is gcc -traditional)
  628. X#    Sun Sparc 2    SunOS 4.1.1    cc (apparently in the sys5 environment)
  629. X#    Hp 9000/400    HP-UX 7.0x    cc
  630. X#    Hp 9000/700    HP-UX 8.05    cc
  631. X#    Sun Sparc     SunOs 4.1.1    cc (in bsd environment)
  632. X#    Motorola 88K    SysV 3.2
  633. X#    DecStation 5100    Ultrix 4.2    
  634. X#    IBM rs/6000    AIX 3.1.1    
  635. X#    IBM rs/6000    AIX 3.2    
  636. X#    Intel 486    ESIX SysV 4.0
  637. X#
  638. X# If you run this script in a different environment it may not work correctly or
  639. X# it may make an incorrect determination, so be more cautious about the results.
  640. X#
  641. XSP="           "
  642. XCCFILE=CF$$c
  643. XCCLIST="gcc2 gcc como CC g++ c89 cc pcc"
  644. XCONFFILE=.configure
  645. XDIRLIST="`echo $PATH | tr ':' ' '`"
  646. XINCDIR=/usr/include
  647. XLIBDIRS="/lib /usr/lib /usr/ucb/lib"
  648. XTMPDIR=/tmp
  649. XTMPBREAK=${TMPDIR}/CF$$break
  650. XTMPCC=${TMPDIR}/CF$$cc
  651. XTMPCCFILE=${TMPDIR}/${CCFILE}.c
  652. XTMPCOMP=${TMPDIR}/CF$$cmp
  653. XTMPDEF=${TMPDIR}/CF$$def
  654. XTMPEND=${TMPDIR}/CF$$end
  655. XTMPFATAL=${TMPDIR}/CF$$fatal
  656. XTMPFIRST=${TMPDIR}/CF$$first
  657. XTMPFOUND=${TMPDIR}/CF$$fnd
  658. XTMPPREDEF=${TMPDIR}/CF$$pred
  659. XTMPSET=${TMPDIR}/CF$$set
  660. XTMPSKIPPED=${TMPDIR}/CF$$skip
  661. XWARN_REGEXP="[Ww]arning|^w "\"".*"\"",L[0-9]*/C[0-9]*:"
  662. X
  663. Xif [ $# != 0 ]; then
  664. X    debug=$1
  665. X
  666. X    if [ $debug -gt 10 ]; then
  667. X        set -x
  668. X    fi
  669. Xelse
  670. X    debug=0
  671. Xfi
  672. X
  673. X#
  674. X# if we already have a configuration 
  675. X#
  676. Xif [ $# = 0 -a -s "${CONFFILE}" -a -s "${CONFFILE}.s" ]; then
  677. X
  678. X    echo "Using existing configuration.  If this is not correct, you"
  679. X    echo "need to remove the ${CONFFILE} file and re-run the make"
  680. X
  681. Xelse
  682. X
  683. X    echo "Determining the correct configuration for malloc.h on this" \
  684. X            "system."
  685. X    echo "This may take a while, please be patient"
  686. X
  687. X    
  688. X    #
  689. X    # Determine default sizetype (for use when we are guessing at 
  690. X    # parameter settings).
  691. X    #
  692. X    grep size_t ${INCDIR}/sys/types.h >/dev/null 2>&1
  693. X    if [ $? = 0 ]; then
  694. X        dfltsize=size_t
  695. X    else
  696. X        dfltsize="unsigned int"
  697. X    fi
  698. X
  699. X    #
  700. X    # determine the compiler(s) that are available on this system
  701. X    #
  702. X
  703. X    echo "    Looking for compilers..."
  704. X    rm -f ${TMPCOMP}
  705. X    touch ${TMPCOMP}
  706. X
  707. X    #
  708. X    # if in debug mode and the compiler is specified as an argument
  709. X    #
  710. X    if [ $# -gt 1 ]; then
  711. X        echo $2 > ${TMPCOMP}
  712. X    else
  713. X
  714. X        #
  715. X        # look for the listed compilers.  Note that cc is last.  This
  716. X        # is as it should be because cc is probably the only compiler
  717. X        # listed that doesn't have one of the pre-defined symbols that
  718. X        # we look for and therefore must be last because the
  719. X        # configuration check loop requires that all compilers other
  720. X        # than the last compiler have one of the pre-defined symbols.
  721. X        #
  722. X        for compiler in ${CCLIST}
  723. X        do
  724. X            for dir in ${DIRLIST}
  725. X            do
  726. X                if [ -s $dir/$compiler ]; then
  727. X                    echo "        found $compiler in $dir"
  728. X                    echo $dir/$compiler >> ${TMPCOMP}
  729. X                    #
  730. X                    # if this is gcc, also add a second 
  731. X                    #   entry with the -traditional flag
  732. X                    #
  733. X                    if [ $compiler = "gcc" ]; then
  734. X                        echo $dir/$compiler \
  735. X                          -traditional >> ${TMPCOMP}
  736. X                    fi
  737. X                    
  738. X                    break
  739. X                fi
  740. X            done
  741. X        done
  742. X
  743. X        #
  744. X        # if we didn't find any compilers
  745. X        #
  746. X        if [ ! -s ${TMPCOMP} ]; then
  747. X            echo "I can't find your compiler"
  748. X            echo 1 > ${TMPFATAL}
  749. X            exit 1
  750. X        fi
  751. X
  752. X    fi
  753. X
  754. X    rm -f ${TMPSET} ${TMPEND} ${TMPSET}.s ${TMPEND}.s ${TMPFIRST} ${TMPSKIPPED}
  755. X
  756. X    cp /dev/null ${TMPSET}
  757. X    cp /dev/null ${TMPSET}.s
  758. X    cp /dev/null ${TMPEND}
  759. X    cp /dev/null ${TMPEND}.s
  760. X    first=1
  761. X    ending=
  762. X    #
  763. X    # for each compiler. 
  764. X    #
  765. X    echo "    checking compiler configuration(s)..."
  766. X    while read cc
  767. X    do
  768. X        (
  769. X        echo "        checking $cc..."
  770. X
  771. X        #
  772. X        # if we should be using any special flags for this compile
  773. X        #
  774. X        if [ -s Config.flags ]; then
  775. X            newcc="`basename $cc`"
  776. X            newcc="`eval grep \"\^$newcc\" Config.flags`"
  777. X            if [ ! -z "$newcc" ]; then
  778. X                cc="$newcc"
  779. X            fi
  780. X        fi
  781. X
  782. X        if [ -s ${TMPFIRST} ]; then
  783. X            #
  784. X            # See if the current set of defines meets the conditions
  785. X            # for this compiler.  If so, there is no need to verify
  786. X            # the parameters further.
  787. X            #
  788. X            rm -f ${TMPCCFILE}
  789. X            cat ${TMPSET} ${TMPEND} cctest.c > ${TMPCCFILE}
  790. X            $cc -DMALLOC_COMPILETEST -DMEM_COMPILETEST \
  791. X               -DSTR_COMPILETEST -DFREE_COMPILETEST -DEXITTEST\
  792. X               -c ${TMPCCFILE} >${TMPCC} 2>&1
  793. X            ccresult=$?
  794. X
  795. X            rm -f ${TMPCCFILE}
  796. X
  797. X            if [ $ccresult = 0 ]; then
  798. X                if egrep "${WARN_REGEXP}" ${TMPCC}>/dev/null; then
  799. X                    rm ${TMPCC};
  800. X                else
  801. X                    continue
  802. X                fi
  803. X            fi
  804. X
  805. X            #
  806. X            # otherwise if the last compiler didn't have a
  807. X            # pre-defined symbol we can't add another set
  808. X            # because it would conflict with the previous 
  809. X            # set of definitions.
  810. X            #
  811. X            if [ ! -s ${TMPPREDEF} ]; then
  812. X            
  813. X                echo "${SP}More than one compiler and no way to tell the" \
  814. X                     "difference between them"
  815. X                echo "${SP}So, hopefully the one set of defs will suffice"
  816. X                echo "break" > ${TMPBREAK}
  817. X                exit
  818. X            fi
  819. X
  820. X            PREDEF=`cat ${TMPPREDEF}`
  821. X
  822. X            if [ ! -s ${TMPSKIPPED} ]; then
  823. X                echo >> ${TMPSET}
  824. X                echo "#else  /* $PREDEF */" >> ${TMPSET}
  825. X                echo >> ${TMPSET}
  826. X    
  827. X                echo >> ${TMPSET}.s
  828. X                echo "#else  /* $PREDEF */" >> ${TMPSET}.s
  829. X                echo >> ${TMPSET}.s
  830. X            fi
  831. X
  832. X        fi
  833. X
  834. X        #
  835. X        # add the appropriate #ifdef to the settings file for this 
  836. X        # compiler (if it has any)
  837. X        #
  838. X        $cc -DPRE_DEFINES -o cctest cctest.c > /dev/null 2>&1
  839. X
  840. X        ./cctest > ${TMPPREDEF}1
  841. X
  842. X        if [ ! -s ${TMPPREDEF}1 ]; then
  843. X            echo "skipped" >> ${TMPSKIPPED}
  844. X            echo "${SP}Failed to determine pre-definitions for this compiler"
  845. X            echo "${SP}    skipping this set of pre-defs.  NOTE: this problem"
  846. X            echo "${SP}    is usually caused by a compiler installed without"
  847. X            echo "${SP}    its libraries (like g++)"
  848. X            exit 0
  849. X            
  850. X        else
  851. X
  852. X            rm -f ${TMPSKIPPED}
  853. X
  854. X            PREDEF=`cat ${TMPPREDEF}1`
  855. X
  856. X            if [ "x${PREDEF}" = "xnone" ]; then
  857. X                cp /dev/null ${TMPPREDEF}
  858. X                PREDEF=""
  859. X            else
  860. X
  861. X                mv ${TMPPREDEF}1 ${TMPPREDEF}
  862. X
  863. X                echo >> ${TMPSET}
  864. X                echo "#if       $PREDEF" >> ${TMPSET}
  865. X                echo >> ${TMPSET}
  866. X
  867. X                if [ -s ${TMPEND}.o ]; then
  868. X                    rm -f ${TMPEND}.o
  869. X                fi
  870. X                if [ -s ${TMPEND} ]; then
  871. X                    mv ${TMPEND} ${TMPEND}.o
  872. X                fi
  873. X                echo > ${TMPEND}
  874. X                echo "#endif /* $PREDEF */" >> ${TMPEND}
  875. X                echo >> ${TMPEND}
  876. X
  877. X                if [ -s ${TMPEND}.o ]; then
  878. X                    cat ${TMPEND}.o >> ${TMPEND}
  879. X                    rm -f ${TMPEND}.o
  880. X                fi
  881. X
  882. X                echo >> ${TMPSET}.s
  883. X                echo "#if       $PREDEF" >> ${TMPSET}.s
  884. X                echo >> ${TMPSET}.s
  885. X
  886. X                if [ -s ${TMPEND}.s.o ]; then
  887. X                    rm -f ${TMPEND}.s.o
  888. X                fi
  889. X                if [ -s ${TMPEND}.s ]; then
  890. X                    mv ${TMPEND}.s ${TMPEND}.s.o
  891. X                fi
  892. X                echo > ${TMPEND}.s
  893. X                echo "#endif /* $PREDEF */" >> ${TMPEND}.s
  894. X                echo >> ${TMPEND}.s
  895. X
  896. X                if [ -s ${TMPEND}.s.o ]; then
  897. X                    cat ${TMPEND}.s.o >> ${TMPEND}.s
  898. X                    rm -f ${TMPEND}.s.o
  899. X                fi
  900. X            fi
  901. X        fi
  902. X
  903. X        #
  904. X        # flag that this is not the first time
  905. X        #
  906. X        echo "second" > ${TMPFIRST}
  907. X
  908. X        #
  909. X        # First step is to determine the correct settings for the
  910. X        # DATATYPE, SIZETYPE and VOIDTYPE pre-defines for this compiler.
  911. X        #
  912. X        # Check void
  913. X        #
  914. X        $cc -DVOIDTEST -c cctest.c > ${TMPCC} 2>&1
  915. X        cc_result=$?
  916. X        egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  917. X        grep_result=$?
  918. X
  919. X        if [ $cc_result = 0 -a $grep_result != 0 ] ; then
  920. X            voidtype=void
  921. X        else
  922. X            voidtype=int
  923. X        fi
  924. X
  925. X        echo "#define VOIDTYPE $voidtype" >> ${TMPSET}
  926. X
  927. X        #
  928. X        # Check const
  929. X        #
  930. X        $cc -DCONSTTEST -c cctest.c > ${TMPCC} 2>&1
  931. X        cc_result=$?
  932. X        egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  933. X        grep_result=$?
  934. X
  935. X        if [ $cc_result = 0 -a $grep_result != 0 ] ; then
  936. X            const=const
  937. X        else
  938. X            const=
  939. X        fi
  940. X
  941. X        echo "#define CONST $const" >> ${TMPSET}
  942. X
  943. X        #
  944. X        # Check ABORT_SIGNAL.  Note that this goes into the settings.s
  945. X        # file which eventually goes into sysdefs.h
  946. X        #
  947. X        $cc -DSIGABRTTEST -c cctest.c > ${TMPCC} 2>&1
  948. X        cc_result=$?
  949. X        egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  950. X        grep_result=$?
  951. X        if [ $cc_result = 0 -a $grep_result != 0 ] ; then
  952. X            abortsig=SIGABRT
  953. X        else
  954. X            $cc -DSIGIOTTEST -c cctest.c > ${TMPCC} 2>&1
  955. X            cc_result=$?
  956. X            egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  957. X            grep_result=$?
  958. X            if [ $cc_result = 0 -a $grep_result != 0 ] ; then
  959. X                abortsig=SIGIOT
  960. X            else
  961. X                abortsig=6
  962. X            fi
  963. X        fi
  964. X
  965. X        echo "/*" >> ${TMPSET}.s
  966. X        echo " * Signal to use to abort program " >> ${TMPSET}.s
  967. X        echo " */" >> ${TMPSET}.s
  968. X        echo "#define ABORT_SIGNAL $abortsig" >> ${TMPSET}.s
  969. X        echo "" >> ${TMPSET}.s
  970. X
  971. X        #
  972. X        # Check SETENV stuff.  Note that this goes into the settings.s
  973. X        # file which eventually goes into sysdefs.h
  974. X        #
  975. X        $cc -DSETENVTEST cctest.c > ${TMPCC} 2>&1
  976. X        cc_result=$?
  977. X        egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  978. X        gres=$?
  979. X        grep "setenv" ${TMPCC} > /dev/null 2>&1
  980. X        gres2=$?
  981. X        if [ $cc_result = 0 -a $gres != 0 -a $gres2 != 0 ]; then
  982. X            echo "/*" >> ${TMPSET}.s
  983. X            echo " * Use setenv() for env mods" >> ${TMPSET}.s
  984. X            echo " */" >> ${TMPSET}.s
  985. X            echo "#define USE_SETENV 1" >> ${TMPSET}.s
  986. X            echo "" >> ${TMPSET}.s
  987. X        fi
  988. X
  989. X        #
  990. X        # Check to see if POSIX header files (in particular,
  991. X        # <unistd.h>) are available
  992. X        #
  993. X        $cc -DPOSIXHEADERTEST cctest.c > ${TMPCC} 2>&1
  994. X        cc_result=$?
  995. X        egrep "$WARN_REGEXP" ${TMPCC} > /dev/null 2>&1
  996. X        gres=$?
  997. X        if [ $cc_result = 0 -a $gres != 0 ]; then
  998. X            echo "/*" >> ${TMPSET}.s
  999. X            echo " * POSIX header files are available" >> ${TMPSET}.s
  1000. X            echo " */" >> ${TMPSET}.s
  1001. X            echo "#define POSIX_HEADERS 1" >> ${TMPSET}.s
  1002. X            echo "" >> ${TMPSET}.s
  1003. X            USE_UNISTD=-DUSE_UNISTD
  1004. X        else
  1005. X            USE_UNISTD=
  1006. X        fi
  1007. X
  1008. X        #
  1009. X        # Check to see if ANSI header files (in particular,
  1010. X        # <stdlib.h>) are available
  1011. X        #
  1012. X        $cc -DANSIHEADERTEST cctest.c > ${TMPCC} 2>&1
  1013. X        cc_result=$?
  1014. X        egrep "$WARN_REGEXP" ${TMPCC} > /dev/null 2>&1
  1015. X        gres=$?
  1016. X        if [ $cc_result = 0 -a $gres != 0 ]; then
  1017. X            echo "/*" >> ${TMPSET}.s
  1018. X            echo " * ANSI header files are available" >> ${TMPSET}.s
  1019. X            echo " */" >> ${TMPSET}.s
  1020. X            echo "#define ANSI_HEADERS 1" >> ${TMPSET}.s
  1021. X            echo "" >> ${TMPSET}.s
  1022. X            USE_STDLIB=-DUSE_STDLIB
  1023. X        else
  1024. X            USE_STDLIB=
  1025. X        fi
  1026. X
  1027. X        #
  1028. X        # Check the type of exit
  1029. X        #
  1030. X        
  1031. X        for type in ${voidtype} int
  1032. X        do
  1033. X            $cc -DEXITTEST ${USE_UNISTD} ${USE_STDLIB} \
  1034. X                -DEXITTYPE=${type} -c cctest.c > ${TMPCC} 2>&1
  1035. X            cc_result=$?
  1036. X            egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  1037. X            grep_result=$?
  1038. X
  1039. X            if [ $cc_result = 0 -a $grep_result != 0 ] ; then
  1040. X                exittype=${type}
  1041. X                break
  1042. X            else
  1043. X                exittype=
  1044. X            fi
  1045. X        done
  1046. X        
  1047. X        if [ "x${exittype}" != "x" ]; then
  1048. X            echo "#define EXITTYPE $exittype" >> ${TMPSET}
  1049. X        else
  1050. X            echo "${SP}couldn't determine the correct setting for"
  1051. X            echo "${SP}  the return type of exit, guessing"
  1052. X            echo "${SP}  VOIDTYPE"
  1053. X            echo "#define EXITTYPE VOIDTYPE  /* *GUESS* */" \
  1054. X                >> ${TMPSET}
  1055. X        fi
  1056. X
  1057. X        #
  1058. X        # Check to see if <malloc.h> is available -- if it
  1059. X        # isn't, we don't have to try using it later in the
  1060. X        # script and things will go faster
  1061. X        # 
  1062. X        $cc -DMALLOCHTEST cctest.c > ${TMPCC} 2>&1
  1063. X        cc_result=$?
  1064. X        egrep "$WARN_REGEXP" ${TMPCC} > /dev/null 2>&1
  1065. X        gres=$?
  1066. X        if [ $cc_result = 0 -a $gres != 0 ]; then
  1067. X            USE_MALLOC=-DUSE_MALLOC
  1068. X        else
  1069. X            USE_MALLOC=
  1070. X        fi
  1071. X
  1072. X        #
  1073. X        # check ASM stuff for i386 systems (need for underscore and/or repe
  1074. X        # instruction
  1075. X        #
  1076. X        echo "/*" >> ${TMPSET}.s
  1077. X        echo " * ASM settings that only apply to 80x86 systems ">> ${TMPSET}.s
  1078. X        echo " */" >> ${TMPSET}.s
  1079. X        echo "" >> ${TMPSET}.s
  1080. X
  1081. X        $cc -DASM_UNDTEST cctest.c > ${TMPCC} 2>&1
  1082. X        cc_result=$?
  1083. X        if [ -s a.out ]; then
  1084. X            res=`./a.out 2>&1`
  1085. X        else
  1086. X            res=""
  1087. X        fi
  1088. X
  1089. X        echo "/*" >> ${TMPSET}.s
  1090. X        echo " * Use Underscores for ASM global symbols" >> ${TMPSET}.s
  1091. X        echo " */" >> ${TMPSET}.s
  1092. X        if [ $cc_result = 0 -a "$res" = "OK" ]; then
  1093. X            cflag="-DUSE_UNDERSCORE"
  1094. X            echo "#define USE_UNDERSCORE 1" >> ${TMPSET}.s
  1095. X        else
  1096. X            cflag=""
  1097. X            echo "/* #define USE_UNDERSCORE 1 */" >> ${TMPSET}.s
  1098. X        fi
  1099. X        echo "" >> ${TMPSET}.s
  1100. X
  1101. X        $cc -DASM_REPTEST $cflag cctest.c > ${TMPCC} 2>&1
  1102. X        cc_result=$?
  1103. X        if [ -s a.out ]; then
  1104. X            res=`./a.out 2>&1`
  1105. X        else
  1106. X            res=""
  1107. X        fi
  1108. X
  1109. X        echo "/*" >> ${TMPSET}.s
  1110. X        echo " * Use REPE instruction for ASM repeat op" >> ${TMPSET}.s
  1111. X        echo " */" >> ${TMPSET}.s
  1112. X
  1113. X        if [ $cc_result = 0 -a "$res" = "OK" ]; then
  1114. X            echo "#define USE_REPE 1" >> ${TMPSET}.s
  1115. X        else
  1116. X            echo "/*#define USE_REPE 1*/" >> ${TMPSET}.s
  1117. X        fi
  1118. X        echo "" >> ${TMPSET}.s
  1119. X
  1120. X        #
  1121. X        # the only way to test the malloc and size datatypes is to
  1122. X        # define them and install them into the test malloc.h to
  1123. X        # see if they are valid
  1124. X        #
  1125. X        # NOTE: this will fail if a prior version of the debug
  1126. X        # malloc.h is in the include path for the compiler before
  1127. X        # the system malloc.h file.
  1128. X        #
  1129. X
  1130. X        #
  1131. X        # check settings for malloc
  1132. X        #
  1133. X        if [ "$debug" -gt 0 ]; then
  1134. X            DSP="${SP}    "
  1135. X            echo "${DSP}Checking malloc"
  1136. X            DSP="${DSP}    "
  1137. X        fi
  1138. X
  1139. X        rm -f ${TMPDEF}
  1140. X        for fileinc in ${USE_STDLIB} ${USE_MALLOC} "${USE_STDLIB} ${USE_MALLOC}"
  1141. X        do
  1142. X                for datatype in void char
  1143. X                do
  1144. X                    for sizetype in size_t int "unsigned int" \
  1145. X                        long "unsigned long"
  1146. X                    do
  1147. X                        if [ $debug != 0 ]; then
  1148. X                            echo "${DSP}data:$datatype size:$sizetype"
  1149. X                        fi
  1150. X
  1151. X                        #
  1152. X                        # compile the test module
  1153. X                        #
  1154. X                        $cc -DDATATYPE="$datatype" -DSIZETYPE="$sizetype"   \
  1155. X                            $fileinc -DCONST="$const" -DMALLOC_COMPILETEST  \
  1156. X                            -c cctest.c >${TMPCC} 2>&1
  1157. X                        result=$?
  1158. X
  1159. X                        if [ $debug -gt 5 ]; then
  1160. X                            cat ${TMPCC}
  1161. X                        fi
  1162. X                        if [ $result = 0 ]; then
  1163. X                            egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  1164. X                            if [ $? != 0 ]; then
  1165. X                                echo "#define DATATYPE $datatype" > ${TMPDEF}
  1166. X                                echo "#define SIZETYPE $sizetype" >> ${TMPDEF}
  1167. X                                break
  1168. X                            fi
  1169. X                        fi
  1170. X
  1171. X                    done
  1172. X
  1173. X                    if [ -s ${TMPDEF} ]; then
  1174. X                        break
  1175. X                    fi
  1176. X
  1177. X                done
  1178. X
  1179. X                if [ -s ${TMPDEF} ]; then
  1180. X                    break
  1181. X                fi
  1182. X
  1183. X        done
  1184. X
  1185. X        if [ ! -s ${TMPDEF} ]; then
  1186. X            #
  1187. X            # guess at what the correct settings should be.  If the compiler
  1188. X            # supports the void data type, guess that the pointer returned
  1189. X            # by malloc is a void * and the size is size_t, otherwise use
  1190. X            # char * and unsigned int
  1191. X            #
  1192. X            if [ "$voidtype" = void ]; then
  1193. X                datatype=void
  1194. X                sizetype=size_t
  1195. X            else
  1196. X                datatype=char
  1197. X                sizetype="unsigned int"
  1198. X            fi
  1199. X
  1200. X            echo "${SP}couldn't determine the correct settings for the datatype"
  1201. X            echo "${SP}  and sizetype parameters for malloc, guessing that the"
  1202. X            echo "${SP}  datatype is $datatype and sizetype is $sizetype"
  1203. X
  1204. X            #
  1205. X            # put the guesses into the tmpdef file and flag them as a guess
  1206. X            #
  1207. X            echo "#define DATATYPE $datatype  /* *GUESS* */" >  ${TMPDEF}
  1208. X            echo "#define SIZETYPE $sizetype  /* *GUESS* */" >> ${TMPDEF}
  1209. X        fi
  1210. X
  1211. X        cat < ${TMPDEF} >> ${TMPSET}
  1212. X
  1213. X        rm -f ${TMPDEF}
  1214. X        for fileinc in ${USE_STDLIB} ${USE_MALLOC} "${USE_STDLIB} ${USE_MALLOC}"
  1215. X        do
  1216. X            for freetype in ${voidtype} int
  1217. X            do
  1218. X                if [ $debug != 0 ]; then
  1219. X                    echo "${DSP}freetype:$freetype"
  1220. X                fi
  1221. X
  1222. X                #
  1223. X                # compile the test module
  1224. X                #
  1225. X                $cc -DFREETYPE="$freetype" -DDATATYPE="$datatype" \
  1226. X                    $fileinc -DCONST="$const" -DFREE_COMPILETEST  \
  1227. X                    -c cctest.c >${TMPCC} 2>&1
  1228. X                result=$?
  1229. X
  1230. X                if [ $debug -gt 5 ]; then
  1231. X                    cat ${TMPCC}
  1232. X                fi
  1233. X                if [ $result = 0 ]; then
  1234. X                    egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  1235. X                    if [ $? != 0 ]; then
  1236. X                        echo "#define FREETYPE $freetype" > ${TMPDEF}
  1237. X                        break
  1238. X                    fi
  1239. X                fi
  1240. X            done
  1241. X
  1242. X            if [ -s ${TMPDEF} ]; then
  1243. X                break;
  1244. X            fi
  1245. X        done
  1246. X
  1247. X        if [ ! -s ${TMPDEF} ]; then
  1248. X            #
  1249. X            # guess at what the correct settings should be.
  1250. X            #
  1251. X
  1252. X            echo "${SP}couldn't determine the correct settings for the return"
  1253. X            echo "${SP}  value of free, guessing VOIDTYPE"
  1254. X
  1255. X            #
  1256. X            # put the guesses into the tmpdef file and flag them as a guess
  1257. X            #
  1258. X            echo "#define FREETYPE VOIDTYPE  /* *GUESS* */" >  ${TMPDEF}
  1259. X        fi
  1260. X
  1261. X        cat < ${TMPDEF} >> ${TMPSET}
  1262. X
  1263. X        #
  1264. X        # check settings for memory functions
  1265. X        #
  1266. X        if [ "$debug" -gt 0 ]; then
  1267. X            DSP="${SP}    "
  1268. X            echo "${DSP}Checking memory functions"
  1269. X            DSP="${DSP}    "
  1270. X        fi
  1271. X        rm -f ${TMPDEF}
  1272. X
  1273. X        #
  1274. X        # see if we should try to use string.h if memory.h fails.
  1275. X        #
  1276. X        if grep "memcpy" ${INCDIR}/string.h > /dev/null 2>&1; then
  1277. X            extra="-DUSE_STRING_H"
  1278. X        else
  1279. X            extra=""
  1280. X        fi
  1281. X
  1282. X        # 
  1283. X        # for each include file we are checking
  1284. X        #
  1285. X        for fileinc in -DUSE_MEMORY_H  $extra
  1286. X        do
  1287. X            if [ $debug -ge 1 ]; then
  1288. X                echo "${DSP}checking inc: $fileinc"
  1289. X                ODSP="${DSP}"
  1290. X                DSP="${DSP}    "
  1291. X            fi
  1292. X            for datatype in void char
  1293. X            do
  1294. X                for sizetype in size_t int "unsigned int" long "unsigned long"
  1295. X                do
  1296. X                    if [ $debug -ge 3 ]; then
  1297. X                        echo "${DSP}data:$datatype size:$sizetype"
  1298. X                    fi
  1299. X
  1300. X                    #
  1301. X                    # compile the test module
  1302. X                    #
  1303. X                    $cc -DMEMDATA="$datatype" -DMEMSIZE="$sizetype" \
  1304. X                        -DCONST="$const" -DMEM_COMPILETEST  \
  1305. X                        $fileinc -c cctest.c >${TMPCC} 2>&1
  1306. X                    result=$?
  1307. X                    if [ $debug -gt 10 ]; then
  1308. X                        cat ${TMPCC}
  1309. X                    fi
  1310. X                    if [ $result = 0 ]; then
  1311. X                        egrep "${WARN_REGEXP}" ${TMPCC} > /dev/null 2>&1
  1312. X                        if [ $? != 0 ]; then
  1313. X                            echo "#define MEMDATA $datatype" > ${TMPDEF}
  1314. X                            echo "#define MEMSIZE $sizetype" >> ${TMPDEF}
  1315. X                            break
  1316. X                        fi
  1317. X                    fi
  1318. X
  1319. X                done
  1320. X
  1321. X                if [ -s ${TMPDEF} ]; then
  1322. X                    break
  1323. X                fi
  1324. X            done
  1325. X
  1326. X            if [ $debug -ge 1 ]; then
  1327. X                DSP="${ODSP}"
  1328. X            fi
  1329. X
  1330. X            if [ -s ${TMPDEF} ]; then
  1331. X                break;
  1332. X            fi
  1333. X
  1334. X        done
  1335. X
  1336. X        if [ ! -s ${TMPDEF} ]; then
  1337. X            #
  1338. X            # guess at what the correct settings should be.  If the compiler
  1339. X            # supports the void data type, guess that the pointer used by
  1340. X            # memcpy is a void * and the size is size_t, otherwise use
  1341. X            # char * and unsigned int
  1342. X            #
  1343. X            if [ "$voidtype" = void ]; then
  1344. X                datatype=void
  1345. X                sizetype=size_t
  1346. X            else
  1347. X                datatype=char
  1348. X                sizetype="unsigned int"
  1349. X            fi
  1350. X
  1351. X            echo "${SP}Couldn't determine the correct settings for the datatype"
  1352. X            echo "${SP}  and sizetype parameters for mem* functions, I will"
  1353. X            echo "${SP}  guess that the datatype is $datatype and sizetype"
  1354. X            echo "${SP}  is $sizetype"
  1355. X
  1356. X            #
  1357. X            # put the guesses into the tmpdef file and flag them as a guess
  1358. X            #
  1359. X            echo "#define MEMDATA $datatype  /* *GUESS* */" >  ${TMPDEF}
  1360. X            echo "#define MEMSIZE $sizetype  /* *GUESS* */" >> ${TMPDEF}
  1361. X        fi
  1362. X
  1363. X        cat < ${TMPDEF} >> ${TMPSET}
  1364. X
  1365. X        #
  1366. X        # check memory comparison setting
  1367. X        #
  1368. X        if [ "$debug" -gt 0 ]; then
  1369. X            DSP="${SP}    "
  1370. X            echo "${DSP}Checking memory func comparision type"
  1371. X            DSP="${DSP}    "
  1372. X        fi
  1373. X        rm -f ${TMPDEF}
  1374. X        for comptype in "char" "unsigned char" "signed char"
  1375. X        do
  1376. X            if [ "x$comptype" = "xchar" ]; then
  1377. X                testtype=TESTCHAR
  1378. X            else
  1379. X                testtype=TESTUCHAR
  1380. X            fi
  1381. X
  1382. X            #
  1383. X            # compile the test module
  1384. X            #
  1385. X            rm -f cctest
  1386. X            $cc -D$testtype -DCOMPARETEST=memcmp \
  1387. X                cctest.c -o cctest >${TMPCC} 2>&1
  1388. X    
  1389. X            if [ -s ./cctest ]; then
  1390. X                ./cctest
  1391. X                if [ $? = 0 ]; then
  1392. X                    echo "#define MEMCMPTYPE $comptype" \
  1393. X                            > ${TMPDEF}
  1394. X                    break
  1395. X                fi
  1396. X            fi
  1397. X            rm -f ${TMPCC};
  1398. X        done
  1399. X
  1400. X        if [ ! -s ${TMPDEF} ]; then
  1401. X            #
  1402. X            # if we don't know, then guess the natural character type
  1403. X            # (which may be signed or unsigned)
  1404. X            #
  1405. X            comptype=char
  1406. X
  1407. X            echo "${SP}Couldn't determine the correct settings for the"
  1408. X            echo "${SP}  comparison type for the memory funcs, I will guess"
  1409. X            echo "${SP}  that the comparison type is $comptype"
  1410. X
  1411. X            #
  1412. X            # put the guesses into the tmpdef file and flag them as a guess
  1413. X            #
  1414. X            echo "#define MEMCMPTYPE $comptype  /* *GUESS* */" >  ${TMPDEF}
  1415. X        fi
  1416. X
  1417. X        cat < ${TMPDEF} >> ${TMPSET}
  1418. X
  1419. X        #
  1420. X        # check settings for string functions
  1421. X        #
  1422. X        rm -f ${TMPDEF}
  1423. X        for sizetype in size_t int "unsigned int" long "unsigned long"
  1424. X        do
  1425. X            #
  1426. X            # compile the test module
  1427. X            #
  1428. X            $cc -DSTRSIZE="$sizetype"   -DCONST="$const" \
  1429. X                -DSTR_COMPILETEST  -c cctest.c >${TMPCC} 2>&1
  1430. X            
  1431. X            if [ $? = 0 ]; then
  1432. X                if egrep "${WARN_REGEXP}" ${TMPCC}>/dev/null; then
  1433. X                    rm ${TMPCC};
  1434. X                else
  1435. X                    echo "#define STRSIZE $sizetype" > ${TMPDEF}
  1436. X                    break
  1437. X                fi
  1438. X            fi
  1439. X
  1440. X        done
  1441. X        
  1442. X        if [ ! -s ${TMPDEF} ]; then
  1443. X            #
  1444. X            # guess at what the correct setting should be.  If size_t is in
  1445. X            # /usr/include/string.h, use it, otherwise use the default size 
  1446. X            # type
  1447. X            #
  1448. X            if grep size_t ${INCDIR}/string.h >/dev/null 2>&1; then
  1449. X                sizetype=size_t
  1450. X            else
  1451. X                sizetype="$dfltsize"
  1452. X            fi
  1453. X
  1454. X            echo "${SP}Couldn't determine the correct settings for the sizetype"
  1455. X            echo "${SP}  parameter for the string functions.  I will guess "
  1456. X            echo "${SP}  that the correct setting is $sizetype"
  1457. X
  1458. X            #
  1459. X            # put the guesses into the tmpdef file and flag them as a guess
  1460. X            #
  1461. X            echo "#define STRSIZE $sizetype  /* *GUESS* */" >> ${TMPDEF}
  1462. X        fi
  1463. X
  1464. X        cat < ${TMPDEF} >> ${TMPSET}
  1465. X
  1466. X        #
  1467. X        # check string comparison setting
  1468. X        #
  1469. X        rm -f ${TMPDEF}
  1470. X        for comptype in "char" "unsigned char" "signed char"
  1471. X        do
  1472. X            if [ "x$comptype" = "xchar" ]; then
  1473. X                testtype=TESTCHAR
  1474. X            else
  1475. X                testtype=TESTUCHAR
  1476. X            fi
  1477. X
  1478. X            #
  1479. X            # compile the test module
  1480. X            #
  1481. X            rm -f cctest
  1482. X            $cc -D$testtype -DCOMPARETEST=strncmp \
  1483. X                cctest.c -o cctest >${TMPCC} 2>&1
  1484. X    
  1485. X            if [ -s ./cctest ]; then
  1486. X                ./cctest
  1487. X                if [ $? = 0 ]; then
  1488. X                    echo "#define STRCMPTYPE $comptype" \
  1489. X                            > ${TMPDEF}
  1490. X                    break
  1491. X                fi
  1492. X            fi
  1493. X            rm -f ${TMPCC};
  1494. X        done
  1495. X
  1496. X        if [ ! -s ${TMPDEF} ]; then
  1497. X            #
  1498. X            # if we don't know, then guess the natural character type
  1499. X            # (which may be signed or unsigned)
  1500. X            #
  1501. X            comptype=char
  1502. X
  1503. X            echo "${SP}Couldn't determine the correct settings for the"
  1504. X            echo "${SP}  comparison type for the string funcs, I will guess"
  1505. X            echo "${SP}  that the comparison type is $comptype"
  1506. X
  1507. X            #
  1508. X            # put the guesses into the tmpdef file and flag them as a guess
  1509. X            #
  1510. X            echo "#define STRCMPTYPE $comptype  /* *GUESS* */" >  ${TMPDEF}
  1511. X        fi
  1512. X
  1513. X        cat < ${TMPDEF} >> ${TMPSET}
  1514. X        
  1515. X        #
  1516. X        # check settings for write size
  1517. X        #
  1518. X        rm -f ${TMPDEF}
  1519. X        for fileinc in -DUSE_SYSENT -DUSE_NONE
  1520. X        do
  1521. X            for sizetype in size_t "unsigned int" int long "unsigned long"
  1522. X            do
  1523. X                #
  1524. X                # compile the test module
  1525. X                #
  1526. X                $cc -DWRTSIZE="$sizetype"   $fileinc -DCONST="$const" \
  1527. X                    ${USE_UNISTD} ${USE_STDLIB} \
  1528. X                    -DWRT_COMPILETEST  -c cctest.c >${TMPCC} 2>&1
  1529. X                
  1530. X                if [ $? = 0 ]; then
  1531. X                    if egrep "${WARN_REGEXP}" ${TMPCC} >/dev/null; then
  1532. X                        rm ${TMPCC};
  1533. X                    else
  1534. X                        echo "#define WRTSIZE $sizetype" > ${TMPDEF}
  1535. X                        break
  1536. X                    fi
  1537. X                fi
  1538. X
  1539. X            done
  1540. X        done
  1541. X        
  1542. X        if [ ! -s ${TMPDEF} ]; then
  1543. X            #
  1544. X            # if we don't know, then guess the natural character type
  1545. X            # (which may be signed or unsigned)
  1546. X            #
  1547. X            sizetype="$dfltsize"
  1548. X
  1549. X            echo "${SP}Couldn't determine the correct settings for the"
  1550. X            echo "${SP}  sizetype parameter for the write func, I will guess"
  1551. X            echo "${SP}  that the sizetype is $sizetype"
  1552. X
  1553. X            #
  1554. X            # put the guesses into the tmpdef file and flag them as a guess
  1555. X            #
  1556. X            echo "#define WRTSIZE $siztype  /* *GUESS* */" >  ${TMPDEF}
  1557. X        fi
  1558. X
  1559. X        cat < ${TMPDEF} >> ${TMPSET}.s
  1560. X
  1561. X        #
  1562. X        # now that we have the settings determined, lets see if we have
  1563. X        # any routines that are built in by the compiler.  These will
  1564. X        # typically be string functions like strcpy and/or memory funcs
  1565. X        #
  1566. X        # -- not implemented yet
  1567. X        #
  1568. X        
  1569. X        ) < /dev/null
  1570. X
  1571. X        if [ -s ${TMPBREAK} ]; then
  1572. X            break;
  1573. X        fi
  1574. X
  1575. X    done < ${TMPCOMP}
  1576. X
  1577. X    if [ -s ${TMPFATAL} ]; then
  1578. X        exit `cat ${TMPFATAL}`
  1579. X    fi
  1580. X
  1581. X    cat ${TMPEND} >> ${TMPSET}
  1582. X
  1583. X    cp ${TMPSET} ${CONFFILE}
  1584. X
  1585. X    #
  1586. X    # now make the correct determinations for building the library (see
  1587. X    # what #defs are needed for the compilation).
  1588. X    #
  1589. X
  1590. X    rm -f ${CONFFILE}.s
  1591. X    (
  1592. X    echo "/*"
  1593. X    echo " * This file is mechanically generated by the Configure script."
  1594. X    echo " * If there is something wrong here, modify the configure script"
  1595. X    echo " * so that it is no longer generated wrong and please send email"
  1596. X    echo " * to the author so that the fix is included with the next patch"
  1597. X    echo " * release."
  1598. X    echo " */"
  1599. X    echo ""
  1600. X    echo "#ifndef _SYSDEF_H     /* double inclusion guard */"
  1601. X    echo "#define _SYSDEF_H 1"
  1602. X    echo ""
  1603. X    ) > ${CONFFILE}.s
  1604. X
  1605. X    #
  1606. X    # put in the compiler settings
  1607. X    #
  1608. X    cat ${TMPSET}.s >> ${CONFFILE}.s
  1609. X
  1610. X    if [ -s ${TMPEND}.s ]; then
  1611. X        cat ${TMPEND}.s >> ${CONFFILE}.s
  1612. X    fi
  1613. X
  1614. X    rm -f ${TMPFOUND}
  1615. X
  1616. X    #
  1617. X    # if we have the Intrinsic.h file, then set the flag to indicate so
  1618. X    #
  1619. X    if [ -s /usr/include/X11/Intrinsic.h ]; then
  1620. X        (    
  1621. X        echo "/*" 
  1622. X        echo " * Found X intrinsic file in /usr/include/X11"
  1623. X        echo " */"
  1624. X        echo "#define FOUND_X_INTRINSIC 1"
  1625. X        echo ""
  1626. X        ) >> ${CONFFILE}.s
  1627. X    else
  1628. X        (    
  1629. X        echo "/*" 
  1630. X        echo " * Didn't find X intrinsic file in /usr/include/X11"
  1631. X        echo " */"
  1632. X        echo "/* #define FOUND_X_INTRINSIC 1 */" 
  1633. X        echo ""
  1634. X        ) >> ${CONFFILE}.s
  1635. X    fi
  1636. X    
  1637. X
  1638. X    #
  1639. X    # if wait.h is present in /usr/include/sys/wait.h
  1640. X    #
  1641. X    if [ -s /usr/include/sys/wait.h ]; then
  1642. X        (    
  1643. X        echo "/*" 
  1644. X        echo " * Found wait.h in /usr/include/sys"
  1645. X        echo " */"
  1646. X        echo "#define NEED_WAIT 1"
  1647. X        echo ""
  1648. X        ) >> ${CONFFILE}.s
  1649. X    else
  1650. X        (    
  1651. X        echo "/*" 
  1652. X        echo " * Didn't find wait.h in /usr/include/sys"
  1653. X        echo " */"
  1654. X        echo "/* #define NEED_WAIT 1 */" 
  1655. X        echo ""
  1656. X        ) >> ${CONFFILE}.s
  1657. X    fi
  1658. X    
  1659. X    #
  1660. X    # check to see if the XtAlloc module includes definitions for the Heap
  1661. X    # management.  Note that this is generic for all compilers, so it
  1662. X    # will come after the per-compiler stuff in ${CONFFILE}.s
  1663. X    #
  1664. X    for i in $LIBDIRS
  1665. X    do
  1666. X        if [ -s $i/libXt.a ]; then
  1667. X            ar xv $i/libXt.a Alloc.o > /dev/null 2>&1
  1668. X            heap=`( nm Alloc.o | grep XtHeapInit ) 2>/dev/null`
  1669. X            rm -f Alloc.o
  1670. X            echo found >> ${TMPFOUND}
  1671. X
  1672. X            if [ -z "$heap" ]; then
  1673. X            
  1674. X                (
  1675. X                echo "/*" 
  1676. X                echo " * don't force inclusion of XtHeap"
  1677. X                echo " */"
  1678. X                echo "#define DONT_FORCE_HEAPSTUFF 1"
  1679. X                echo ""
  1680. X                ) >> ${CONFFILE}.s
  1681. X        
  1682. X                break
  1683. X            fi
  1684. X
  1685. X        fi
  1686. X    done
  1687. X
  1688. X    if [ ! -s ${TMPFOUND} ]; then
  1689. X        (
  1690. X        echo "/*" 
  1691. X        echo " * don't force inclusion of XtHeap"
  1692. X        echo " */"
  1693. X        echo "#define DONT_FORCE_HEAPSTUFF 1"
  1694. X        echo ""
  1695. X        ) >> ${CONFFILE}.s
  1696. X    fi
  1697. X
  1698. X    (
  1699. X    echo ""
  1700. X    echo "#endif  /* _SYSDEF_H */"
  1701. X    echo ""
  1702. X    ) >> ${CONFFILE}.s
  1703. X
  1704. Xfi
  1705. X
  1706. X#
  1707. X# if we guessed at any of the settings, tell the user about it
  1708. X#
  1709. Xif grep "\*GUESS\*" ${CONFFILE} ${CONFFILE}.s > /dev/null 2>&1; then
  1710. X    echo ""
  1711. X    echo "    Warning: There were some settings that I could not determine"
  1712. X    echo "             the correct values for and so I have guessed at the"
  1713. X    echo "             correct settings.  You should review the .configure"
  1714. X    echo "             and .configure.s files and review the settings to"
  1715. X    echo "             make sure they are correct.  The settings that were"
  1716. X    echo "             guessed at will be marked with '/* *GUESS* */'"
  1717. X    echo ""
  1718. X    echo "             See the PROBLEMS file for a description of what the"
  1719. X    echo "             settings are supposed to be"
  1720. X    echo ""
  1721. X    echo "             Most of the time you can ignore this warning and"
  1722. X    echo "             just continue with the compilation of the library"
  1723. X    echo "             and have no problems."
  1724. X    echo ""
  1725. X    echo "             Once you determine that the settings are correct, you"
  1726. X    echo "             can remove the GUESS flags and you will no longer get"
  1727. X    echo "             this warning when building the library"
  1728. X    echo ""
  1729. Xfi
  1730. X
  1731. X#
  1732. X# Create malloc.h with the new settings
  1733. X#
  1734. Xed malloc.h.org <<ended > /dev/null 2>&1
  1735. X/^DATATYPES_MARKER/
  1736. Xd
  1737. X. r ${CONFFILE}
  1738. Xw malloc.h
  1739. Xq
  1740. Xended
  1741. X
  1742. X#
  1743. X# and now add in the system definitions
  1744. X#
  1745. Xcp ${CONFFILE}.s sysdefs.h
  1746. X
  1747. X#
  1748. X# and now handle the memset and memcpy routines (if it hasn't been done
  1749. X# already)
  1750. X#
  1751. Xif [ ! -s ${CONFFILE}.O ]; then
  1752. X
  1753. X    #
  1754. X    # find compiler for testing modified modules Note that we only use cc
  1755. X    # or gcc for this step because we think that these are the only usefull
  1756. X    # compilers to perform this step
  1757. X    #
  1758. X    rm -f ${TMPCC}
  1759. X    for compiler in cc gcc
  1760. X    do
  1761. X        for dir in ${DIRLIST}
  1762. X        do
  1763. X            if [ -s ${dir}/${compiler} ]; then
  1764. X                echo "${dir}/${compiler}" > ${TMPCC}
  1765. X                break
  1766. X            fi
  1767. X        done
  1768. X        if [ -s ${TMPCC} ]; then
  1769. X            break;
  1770. X        fi
  1771. X    done
  1772. X
  1773. X    cc=`cat ${TMPCC} < /dev/null`
  1774. X
  1775. X    #
  1776. X    # find libc.a
  1777. X    #
  1778. X    for i in $LIBDIRS
  1779. X    do
  1780. X        if [ -s $i/libc.a ]; then
  1781. X        
  1782. X            LIBC=$i/libc.a
  1783. X            break
  1784. X        
  1785. X        fi
  1786. X    done
  1787. X
  1788. X    ar xv ${LIBC} memcpy.o memset.o memmove.o > /dev/null 2>&1
  1789. X
  1790. X    #
  1791. X    # If at least one of the modules were found, build the changestr module
  1792. X    #
  1793. X    if [ -s memset.o -o -s memcpy.o  -o -s memmove.o ]; then
  1794. X
  1795. X        ${cc} -DCHANGESTR cctest.c -o changestr > /dev/null 2>&1
  1796. X
  1797. X    fi
  1798. X
  1799. X    if [ -s memmove.o ]; then
  1800. X        TESTPGMS="memset memmove"
  1801. X    else
  1802. X        TESTPGMS="memset memcpy"
  1803. X    fi
  1804. X
  1805. X    #
  1806. X    # if we found memset.o
  1807. X    #
  1808. X    for i in ${TESTPGMS}
  1809. X    do
  1810. X        #
  1811. X        # get the name of the target
  1812. X        #
  1813. X        case $i in
  1814. X            memmove|memcpy)
  1815. X                tgtstr=DataMC
  1816. X                tgtfile=datamc
  1817. X                def=TESTDATAMC
  1818. X                ;;
  1819. X            memset)
  1820. X                tgtstr=DataMS
  1821. X                tgtfile=datams
  1822. X                def=TESTDATAMS
  1823. X                ;;
  1824. X        esac
  1825. X
  1826. X        rm -f ${tgtfile}.O
  1827. X
  1828. X        if [ -s ${i}.o ]; then
  1829. X
  1830. X            #
  1831. X            # change the file
  1832. X            #
  1833. X            chmod +w ${i}.o
  1834. X            ./changestr ${i}.o ${i} ${tgtstr}
  1835. X
  1836. X            if [ $? = 0 ]; then
  1837. X        
  1838. X                #
  1839. X                # test new memset module
  1840. X                # 
  1841. X                rm -f cctest
  1842. X                ${cc} -D${def} cctest.c -o cctest ${i}.o  \
  1843. X                    > /dev/null 2>&1
  1844. X
  1845. X                if [ -s cctest ];  then
  1846. X                    output=`./cctest`
  1847. X                else
  1848. X                    output=0
  1849. X                fi
  1850. X            else
  1851. X                output=0
  1852. X            fi
  1853. X
  1854. X            #
  1855. X            # if the output from the command is correct then
  1856. X            # save the .o file in DataMS.O so that the
  1857. X            # makefile knows to use it
  1858. X            #
  1859. X            if [ "x${output}" = "xx   yyy" ]; then
  1860. X            
  1861. X                #
  1862. X                # move the object module so the makefile
  1863. X                # knows to use it
  1864. X                #
  1865. X                rm -f ${tgtfile}.O
  1866. X                mv ${i}.o ${tgtfile}.O
  1867. X                rm -f ${i}.o
  1868. X        
  1869. X            fi
  1870. X
  1871. X            #
  1872. X            # clean up after ourselves
  1873. X            #
  1874. X            rm -f ${i}.o
  1875. X
  1876. X        fi
  1877. X
  1878. X    done
  1879. X
  1880. X    echo "Configured .O files at `date`" >> ${CONFFILE}.O
  1881. X
  1882. Xfi
  1883. X
  1884. Xrm -f changestr
  1885. X
  1886. X#
  1887. X# clean up after ourselves
  1888. X#
  1889. Xrm  -f ${TMPDIR}/CF$$* cctest cctest.o ${CCFILE}.[co] a.out
  1890. END_OF_FILE
  1891. if test 29712 -ne `wc -c <'Configure'`; then
  1892.     echo shar: \"'Configure'\" unpacked with wrong size!
  1893. fi
  1894. chmod +x 'Configure'
  1895. # end of 'Configure'
  1896. fi
  1897. if test -f 'Runtests' -a "${1}" != "-c" ; then 
  1898.   echo shar: Will not clobber existing file \"'Runtests'\"
  1899. else
  1900. echo shar: Extracting \"'Runtests'\" \(3975 characters\)
  1901. sed "s/^X//" >'Runtests' <<'END_OF_FILE'
  1902. X#!/bin/sh
  1903. X#
  1904. X#
  1905. X# (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1906. X#
  1907. X# This software may be distributed freely as long as the following conditions
  1908. X# are met:
  1909. X#         * the distribution, or any derivative thereof, may not be
  1910. X#          included as part of a commercial product
  1911. X#        * full source code is provided including this copyright
  1912. X#        * there is no charge for the software itself (there may be
  1913. X#          a minimal charge for the copying or distribution effort)
  1914. X#        * this copyright notice is not modified or removed from any
  1915. X#          source file
  1916. X#
  1917. X# $Id: Runtests,v 1.13 1992/08/22 16:27:13 cpcahil Exp $
  1918. X#
  1919. X# This shell attempts to run all of the tests distributed with the
  1920. X# malloc library and detmine if they pass.
  1921. X#
  1922. X# The following tests are processed
  1923. X#
  1924. X#    testmem        - test str* and mem* functions
  1925. X#    teststack    - test stack mechanism
  1926. X#    testmalloc    - test malloc routines
  1927. X#    testerr        - test error conditions
  1928. X#
  1929. X
  1930. X#
  1931. X# before we run any tests, lets make sure we have the programs that
  1932. X# we intend to test
  1933. X#
  1934. X
  1935. Xif [ ! -r testmem -o ! -r teststack -o ! -r testmalloc -o ! -r testerr ]; then
  1936. X
  1937. X    echo "All of the test programs are not available.  Pleas run"
  1938. X    echo "make tests before you run this shell"
  1939. X    exit 1
  1940. X
  1941. Xfi
  1942. X
  1943. X#
  1944. X# these tests have to run with the default malloc environment variables,
  1945. X# so make sure they are not overridden (otherwise the validation of the
  1946. X# results may be incorrect)
  1947. X#
  1948. XMALLOC_CKCHAIN=0
  1949. XMALLOC_DETAIL=0
  1950. XMALLOC_WARN=0
  1951. XMALLOC_FATAL=1
  1952. XMALLOC_CKDATA=1
  1953. XMALLOC_LOWFRAG=0
  1954. XMALLOC_REUSE=1
  1955. XMALLOC_ERRFILE="-"
  1956. XMALLOC_FILLAREA=3
  1957. XMALLOC_SHOW_LINKS=0
  1958. X
  1959. Xexport MALLOC_CKCHAIN MALLOC_DETAIL MALLOC_WARN MALLOC_FATAL MALLOC_CKDATA
  1960. Xexport MALLOC_LOWFRAG MALLOC_REUSE MALLOC_ERRFILE MALLOC_FILLAREA
  1961. Xexport MALLOC_SHOW_LINKS
  1962. X
  1963. X
  1964. X
  1965. XOUT=Runtests.out
  1966. XTMPOUT=/tmp/err.$$
  1967. XTMPFILE=/tmp/ttt.$$
  1968. Xfailed=0
  1969. X
  1970. Xrm -f $OUT
  1971. Xcat <<endcat > $OUT
  1972. X
  1973. XThis file contains the outputs from the tests run by the Runtests script.
  1974. XFor more info on a particular test, check the README file
  1975. X
  1976. Xendcat
  1977. X
  1978. X#
  1979. X# run testmem and verify that it had no output and returned a zero exit code
  1980. X#
  1981. Xecho "************ Running testmem test..." >> $OUT
  1982. X
  1983. Xrm -f ${TMPOUT}
  1984. X./testmem > ${TMPOUT} 2>&1
  1985. Xif [ $? != 0 -o -s ${TMPOUT} ]; then
  1986. X    echo "FAILED testmem test"
  1987. X    echo "FAILED testmem test" >> $OUT
  1988. X    failed=`expr $failed + 1`
  1989. Xfi
  1990. X
  1991. Xcat ${TMPOUT} >> $OUT
  1992. X
  1993. X#
  1994. X# run stack tests and verify the output is correct
  1995. X#
  1996. Xecho "************ Running stack test" >> $OUT
  1997. X./teststack > ${TMPOUT} 2>&1
  1998. Xresult=$?
  1999. Xlines=`grep "\->" ${TMPOUT} | wc -l | sed -e "s/ //g"`
  2000. Xif [ $result != 0 -o "x$lines" != "x53" ]; then
  2001. X    echo "FAILED teststack test"
  2002. X    echo "FAILED teststack test" >> $OUT
  2003. X    failed=`expr $failed + 1`
  2004. Xfi
  2005. X
  2006. Xcat ${TMPOUT} >> $OUT
  2007. X
  2008. X#
  2009. X# run the malloc tests.  Note that we only run 5,000 iterations of the test and
  2010. X# a real test should be well over 1,000,000 tests.  However, since I don't want
  2011. X# the user thinking the system has locked up, I will just run the short test
  2012. X# here.  (this can be overridden by passing an arugment to Runtests (any
  2013. X# arugment will do))
  2014. X#
  2015. Xecho "************ Running malloc test" >> $OUT
  2016. X./testmalloc 5000 > ${TMPOUT} 2>&1
  2017. Xresult=$?
  2018. Xline="`grep 'Did 5000 iterations' ${TMPOUT}`"
  2019. Xline2="`grep Warning ${TMPOUT}`"
  2020. Xif [ $result != 0 -o -z "$line" -o ! -z "$line2" ]; then
  2021. X    echo "FAILED malloc test"
  2022. X    echo "FAILED malloc test" >> $OUT
  2023. X    failed=`expr $failed + 1`
  2024. Xfi
  2025. X
  2026. Xcat ${TMPOUT} >> $OUT
  2027. X
  2028. X#
  2029. X# run the malloc error test.  Note that this test *should* abort therefore we
  2030. X# have to run it in a sub-shell in order to ensure that the user doesn't see
  2031. X# an error message
  2032. X#
  2033. Xecho "************ Running error test" >> $OUT
  2034. Xsh -c "./testerr" > ${TMPOUT} 2>&1 
  2035. Xsed -e "111,\$ d" -e "/ was /d" < ${TMPOUT} > ${TMPFILE}
  2036. Xcmp ${TMPFILE} testerr.base
  2037. Xif [ $? != 0 ]; then
  2038. X    echo "FAILED error test"
  2039. X    echo "FAILED error test" >> $OUT
  2040. X    failed=`expr $failed + 1`
  2041. Xfi
  2042. X
  2043. Xcat ${TMPOUT} >> $OUT
  2044. X
  2045. Xrm -f ${TMPOUT} ${TMPFILE}
  2046. X
  2047. Xif [ $failed = 0 ]; then
  2048. X
  2049. X    echo "All tests seem to have passed.  Review $OUT to make sure"
  2050. X
  2051. Xfi
  2052. X
  2053. Xrm -f core a.out
  2054. X
  2055. Xexit $failed
  2056. X
  2057. END_OF_FILE
  2058. if test 3975 -ne `wc -c <'Runtests'`; then
  2059.     echo shar: \"'Runtests'\" unpacked with wrong size!
  2060. fi
  2061. chmod +x 'Runtests'
  2062. # end of 'Runtests'
  2063. fi
  2064. if test -f 'teststack.c' -a "${1}" != "-c" ; then 
  2065.   echo shar: Will not clobber existing file \"'teststack.c'\"
  2066. else
  2067. echo shar: Extracting \"'teststack.c'\" \(1337 characters\)
  2068. sed "s/^X//" >'teststack.c' <<'END_OF_FILE'
  2069. X/*
  2070. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  2071. X *
  2072. X * This software may be distributed freely as long as the following conditions
  2073. X * are met:
  2074. X *         * the distribution, or any derivative thereof, may not be
  2075. X *          included as part of a commercial product
  2076. X *        * full source code is provided including this copyright
  2077. X *        * there is no charge for the software itself (there may be
  2078. X *          a minimal charge for the copying or distribution effort)
  2079. X *        * this copyright notice is not modified or removed from any
  2080. X *          source file
  2081. X */
  2082. X
  2083. X#include "sysdefs.h"
  2084. X#include <stdio.h>
  2085. X#if ANSI_HEADERS
  2086. X#include <stdlib.h>
  2087. X#endif
  2088. X#include <sys/types.h>
  2089. X#include "malloc.h"
  2090. X
  2091. XVOIDTYPE    sub1();
  2092. XVOIDTYPE    sub2();
  2093. XVOIDTYPE    sub3();
  2094. X
  2095. X/*ARGSUSED*/
  2096. Xint
  2097. Xmain(argc,argv)
  2098. X    int              argc;
  2099. X    char            **argv[];
  2100. X{
  2101. X
  2102. X    char            * s;
  2103. X
  2104. X    malloc_enter("main");
  2105. X
  2106. X    s = malloc(10);
  2107. X
  2108. X    sub1();
  2109. X    sub2();
  2110. X    sub3();
  2111. X    
  2112. X    malloc_leave("main");
  2113. X    
  2114. X    malloc_dump(1);
  2115. X
  2116. X    return(0);
  2117. X}
  2118. X
  2119. XVOIDTYPE
  2120. Xsub1()
  2121. X{
  2122. X    char     * s;
  2123. X    malloc_enter("sub1");
  2124. X
  2125. X    s = malloc(0);    
  2126. X
  2127. X    sub2();
  2128. X
  2129. X    sub3();
  2130. X    
  2131. X    sub2();
  2132. X
  2133. X    s = malloc(10);
  2134. X
  2135. X    malloc_leave("sub1");
  2136. X}
  2137. X
  2138. XVOIDTYPE
  2139. Xsub2()
  2140. X{
  2141. X    char     * s;
  2142. X    malloc_enter("sub2");
  2143. X
  2144. X    s = malloc(0);    
  2145. X
  2146. X    sub3();
  2147. X    
  2148. X    s = malloc(10);
  2149. X
  2150. X    malloc_leave("sub2");
  2151. X}
  2152. X
  2153. XVOIDTYPE
  2154. Xsub3()
  2155. X{
  2156. X    char     * s;
  2157. X    malloc_enter("sub3");
  2158. X
  2159. X    s = malloc(1);    
  2160. X
  2161. X    strcpy(s,"1");
  2162. X
  2163. X    malloc_leave("sub3");
  2164. X}
  2165. X
  2166. END_OF_FILE
  2167. if test 1337 -ne `wc -c <'teststack.c'`; then
  2168.     echo shar: \"'teststack.c'\" unpacked with wrong size!
  2169. fi
  2170. # end of 'teststack.c'
  2171. fi
  2172. echo shar: End of archive 2 \(of 10\).
  2173. cp /dev/null ark2isdone
  2174. MISSING=""
  2175. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2176.     if test ! -f ark${I}isdone ; then
  2177.     MISSING="${MISSING} ${I}"
  2178.     fi
  2179. done
  2180. if test "${MISSING}" = "" ; then
  2181.     echo You have unpacked all 10 archives.
  2182.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2183. else
  2184.     echo You still need to unpack the following archives:
  2185.     echo "        " ${MISSING}
  2186. fi
  2187. ##  End of shell archive.
  2188. exit 0
  2189. *** SENTINEL(tm) The ultimate Debugging Environment - email for more info ***
  2190.  
  2191. Conor P. Cahill              (703)430-9247            cpcahil@virtech.vti.com
  2192. Virtual Technologies, Inc.  46030 Manekin Plaza          Dulles, VA 21066 
  2193.  
  2194. exit 0 # Just in case...
  2195.