home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / misc / 3898 < prev    next >
Encoding:
Text File  |  1992-09-04  |  57.2 KB  |  2,201 lines

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