home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / kpathsea / common.ac < prev    next >
Encoding:
Text File  |  1996-09-28  |  2.7 KB  |  99 lines

  1. dnl Common Autoconf sinclude file for kpathsea-using programs.  (Have to
  2. dnl use the m4 `sinclude' builtin instead of `include', since Autoconf
  3. dnl disables `include'.)
  4.  
  5. dnl Write output here, instead of putting a zillion -D's on the command line.
  6. AC_CONFIG_HEADER(c-auto.h)
  7.  
  8. AC_PROG_MAKE_SET
  9.  
  10. AC_PROG_CC
  11. AC_PROG_INSTALL
  12. AC_PROG_RANLIB
  13.  
  14. AC_ISC_POSIX
  15.  
  16. AC_HEADER_DIRENT
  17. AC_HEADER_STDC
  18. AC_FUNC_CLOSEDIR_VOID
  19. AC_CHECK_HEADERS(assert.h float.h limits.h memory.h pwd.h stdlib.h \
  20.                  string.h unistd.h)
  21.  
  22. AC_CHECK_FUNCS(basename bcopy memmove putenv)
  23.  
  24. AC_C_CONST
  25.  
  26.  
  27. # This is a GNU libc invention.
  28. AC_MSG_CHECKING(whether program_invocation_name is predefined)
  29. AC_CACHE_VAL(kb_cv_var_program_inv_name,
  30. [AC_TRY_LINK(, [main() { program_invocation_name = "love"; }],
  31.   kb_cv_var_program_inv_name=yes, kb_cv_var_program_inv_name=no)])dnl
  32. AC_MSG_RESULT($kb_cv_var_program_inv_name)
  33. if test $kb_cv_var_program_inv_name = yes; then
  34.   AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME)
  35. fi
  36.  
  37.  
  38. # Some BSD putenv's, e.g., FreeBSD, do malloc/free's on the environment.
  39. # This test program is due to Mike Hibler <mike@cs.utah.edu>.
  40. # We don't actually need to run this if we don't have putenv, but it
  41. # doesn't hurt.
  42. AC_MSG_CHECKING(whether putenv uses malloc)
  43. AC_CACHE_VAL(kb_cv_func_putenv_malloc,
  44. [AC_TRY_RUN([
  45. #define VAR    "YOW_VAR"
  46. #define STRING1 "GabbaGabbaHey"
  47. #define STRING2 "Yow!!"        /* should be shorter than STRING1 */
  48. extern char *getenv (); /* in case char* and int don't mix gracefully */
  49. main ()
  50. {
  51.   char *str1, *rstr1, *str2, *rstr2;
  52.   str1 = getenv (VAR);
  53.   if (str1)
  54.     exit (1);
  55.   str1 = malloc (strlen (VAR) + 1 + strlen (STRING1) + 1);
  56.   if (str1 == 0)
  57.     exit (2);
  58.   strcpy (str1, VAR);
  59.   strcat (str1, "=");
  60.   strcat (str1, STRING1);
  61.   if (putenv (str1) < 0)
  62.     exit (3);
  63.   rstr1 = getenv (VAR);
  64.   if (rstr1 == 0)
  65.     exit (4);
  66.   rstr1 -= strlen (VAR) + 1;
  67.   if (strncmp (rstr1, VAR, strlen (VAR)))
  68.     exit (5);
  69.   str2 = malloc (strlen (VAR) + 1 + strlen (STRING2) + 1);
  70.   if (str2 == 0 || str1 == str2)
  71.     exit (6);
  72.   strcpy (str2, VAR);
  73.   strcat (str2, "=");
  74.   strcat (str2, STRING2);
  75.   if (putenv (str2) < 0)
  76.     exit (7);
  77.   rstr2 = getenv (VAR);
  78.   if (rstr2 == 0)
  79.     exit (8);
  80.   rstr2 -= strlen (VAR) + 1;
  81. #if 0
  82.   printf ("rstr1=0x%x, rstr2=0x%x\n", rstr1, rstr2);
  83.   /*
  84.    * If string from first call was reused for the second call,
  85.    * you had better not do a free on the first string!
  86.    */
  87.   if (rstr1 == rstr2)
  88.           printf ("#define SMART_PUTENV\n");
  89.   else
  90.           printf ("#undef SMART_PUTENV\n");
  91. #endif
  92.   exit (rstr1 == rstr2 ? 0 : 1);
  93. }], kb_cv_func_putenv_malloc=yes, kb_cv_func_putenv_malloc=no,
  94.     kb_cv_func_putenv_malloc=no)])dnl
  95. AC_MSG_RESULT($kb_cv_func_putenv_malloc)
  96. if test $kb_cv_func_putenv_malloc = yes; then
  97.   AC_DEFINE(SMART_PUTENV)
  98. fi
  99.