It says,
> I'd like to say one small thing before the actual > content starts: Please contribute! Attached are two files that produce six feature tests. The first file is "misc.def" which defines the six tests. The second file is "config.tpl" which defines how to create an autoconf feature test, given a definition. Of course, you have to have my play toy to do the conversion: http://www.gnu.org/software/autogen but some of you already knew that. :-) Cheers, Bruce P.S. an example + I added the generated output, too: > group = ag; /* specifies the prefix, a la "AC" or "AM" */ > test = { > name = posix_sysinfo; > type = run; > check = "sysinfo(2) is POSIX"; > code = <<- _EOF_ > #include <sys/systeminfo.h> > int main() { char z[ 256 ]; > long sz = sysinfo( SI_SYSNAME, z, sizeof( z )); > return (sz > 0) ? 0 : 1; } > _EOF_; > doc = > "Check that the POSIX compliant sysinfo(2) call works properly.\n" > "Linux has its own weirdo alternative."; > }; yields this. I think this is harder to understand and harder to do correctly: dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_POSIX_SYSINFO dnl dnl Check that the POSIX compliant sysinfo(2) call works properly. dnl Linux has its own weirdo alternative. dnl AC_DEFUN(AG_CHECK_POSIX_SYSINFO,[ AC_MSG_CHECKING([whether sysinfo(2) is POSIX]) AC_CACHE_VAL([ag_cv_posix_sysinfo],[ AC_TRY_RUN([#include <sys/systeminfo.h> int main() { char z[ 256 ]; long sz = sysinfo( SI_SYSNAME, z, sizeof( z )); return (sz > 0) ? 0 : 1; }],[ag_cv_posix_sysinfo=yes],[ag_cv_posix_sysinfo=no], [ag_cv_posix_sysinfo=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_posix_sysinfo]) if test x$ag_cv_posix_sysinfo = xyes then AC_DEFINE(HAVE_POSIX_SYSINFO, 1, [Define this if sysinfo(2) is POSIX]) fi ]) # end of AC_DEFUN
autogen definitions config.tpl; /* * Maintainer: Bruce Korb <[EMAIL PROTECTED]> * Created: Tue Nov 24 01:07:30 1998 * Last Modified: $Date: 2001/09/29 20:41:00 $ * by: Bruce Korb <[EMAIL PROTECTED]> * ------------------------------------------------------------------- * $Id: misc.def,v 1.6 2001/09/29 20:41:00 bkorb Exp $ * ------------------------------------------------------------------- */ group = ag; test = { name = allocated_ctime; type = run; check = "ctime() allocates memory for its result"; code = <<- _EOF_ #include <time.h> int main (int argc, char** argv) { time_t timeVal = time( (time_t*)NULL ); char* pzTime = ctime( &timeVal ); free( (void*)pzTime ); return 0; } _EOF_; doc = "Check whether we need to free the memory returned by ctime."; }; test = { name = strftime; type = run; check = "strftime() works"; code = <<- _EOF_ #include <time.h> char t_buf[ 64 ]; int main() { static const char z[] = "Thursday Aug 28 240"; struct tm tm; tm.tm_sec = 36; /* seconds after the minute [0, 61] */ tm.tm_min = 44; /* minutes after the hour [0, 59] */ tm.tm_hour = 12; /* hour since midnight [0, 23] */ tm.tm_mday = 28; /* day of the month [1, 31] */ tm.tm_mon = 7; /* months since January [0, 11] */ tm.tm_year = 86; /* years since 1900 */ tm.tm_wday = 4; /* days since Sunday [0, 6] */ tm.tm_yday = 239; /* days since January 1 [0, 365] */ tm.tm_isdst = 1; /* flag for daylight savings time */ strftime( t_buf, sizeof( t_buf ), "%A %b %d %j", &tm ); return (strcmp( t_buf, z ) != 0); } _EOF_; doc = "Check for existence and functioning of strftime routine."; }; test = { name = posix_regcomp; type = run; check = "POSIX compliant regcomp()/regexec()"; code = <<- _EOF_ #include <sys/types.h> #include <regex.h> int main() { regex_t re; return regcomp( &re, "^.*$", REG_EXTENDED|REG_ICASE|REG_NEWLINE ); } _EOF_; doc = "Check that the POSIX compliant regular expression compiler\n" "is available in the POSIX specified manner, and it works."; }; test = { name = sys_siglist; type = run; check = "there is a global text array sys_siglist"; code = <<- _EOF_ #include <signal.h> int main() { const char* pz = sys_siglist[1]; return (pz != 0) ? 0 : 1; } _EOF_; doc = "Check that the POSIX compliant regular expression compiler\n" "is available in the POSIX specified manner, and it works."; }; test = { name = posix_sysinfo; type = run; check = "sysinfo(2) is POSIX"; code = <<- _EOF_ #include <sys/systeminfo.h> int main() { char z[ 256 ]; long sz = sysinfo( SI_SYSNAME, z, sizeof( z )); return (sz > 0) ? 0 : 1; } _EOF_; doc = "Check that the POSIX compliant sysinfo(2) call works properly.\n" "Linux has its own weirdo alternative."; }; test = { name = uname_syscall; type = run; check = "uname(2) is POSIX"; code = <<- _EOF_ #include <sys/utsname.h> int main() { struct utsname unm; return uname( &unm ); } _EOF_; doc = "Check that the POSIX compliant uname(2) call works properly."; }; /* misc.def ends here */
[= AutoGen5 template -*- Mode: M4 -*- m4 # Maintainer: Bruce Korb <[EMAIL PROTECTED]> # Created: Tue Nov 24 01:07:30 1998 # Last Modified: $Date: 2001/10/02 21:21:21 $ # by: Bruce Korb <[EMAIL PROTECTED]> # # This template uses the following definitions: # # 1. group - defines a prefix for the names. The default is "ac". # 2. test - an autoconf test to perform: # 2.a name - name of the test # 2.b type - "run", "link" or "compile" # 2.c check - short display name for user entertainment # 2.d code - the test code to compile, link and/or run. # 2.e doc - useful explanitory text (setenv "SHELL" "/bin/sh") =][= (dne "dnl " "dnl ") =] dnl dnl This file defines [=(count "test")=] configuration tests dnl[= (define down-name "") (define cache-name "") (define test-name "") (define group-prefix (if (exist? "group") (string-append (string-downcase! (get "group")) "_") "ac_" )) =][= FOR test "\n\ndnl # # # # # # # # # # # # #\ndnl" =] dnl [= (set! test-name (string-upcase! (string-append group-prefix "CHECK_" (get "name")))) (set! down-name (string-downcase! (get "name"))) (set! cache-name (string-append group-prefix "cv_" down-name)) (. test-name) =] dnl [=(shellf "sed 's,^,dnl ,' <<_EOF_\n%s\n_EOF_" (get "doc")) =][= # (prefix "dnl " (get "doc")) =] dnl AC_DEFUN([=(. test-name)=],[ AC_MSG_CHECKING([whether [=check=]]) AC_CACHE_VAL([[=(. cache-name)=]],[[= CASE (get "type") =][= = run =] AC_TRY_RUN([[=code=]],[[=(. cache-name)=]=yes],[[=(. cache-name)=]=no],[[= (. cache-name)=]=no] ) # end of TRY_RUN[= # This _should_ be done, but TRY_RUN blindly obliterates "core.c" # before we get here, so this is now obsolete: # for f in *core* do if test -f $f && test $f -nt conftest${ac_exeext} then rm -f $f ; fi done=][= = link =] AC_TRY_LINK([[=code=]],[[=(. cache-name)=]=yes],[[=(. cache-name)=]=no] ) # end of TRY_LINK[= = compile =][= * =][=% type (error "`%s' is an unknown CHECK type") =][= ESAC =]]) # end of CACHE_VAL AC_MSG_RESULT([$[=(. cache-name)=]]) if test x$[=(. cache-name)=] = xyes then AC_DEFINE(HAVE_[=% name (string-upcase! "%s")=], 1, [Define this if [=check=]]) fi ]) # end of AC_DEFUN[= ENDFOR test =][= # end of config.tpl =]
dnl -*- buffer-read-only: t -*- vi: set ro: dnl dnl DO NOT EDIT THIS FILE (misc.m4) dnl dnl It has been AutoGen-ed Monday November 5, 2001 at 07:47:33 PM PST dnl From the definitions misc.def dnl and the template file config.tpl dnl dnl This file defines 6 configuration tests dnl dnl AG_CHECK_ALLOCATED_CTIME dnl dnl Check whether we need to free the memory returned by ctime. dnl AC_DEFUN(AG_CHECK_ALLOCATED_CTIME,[ AC_MSG_CHECKING([whether ctime() allocates memory for its result]) AC_CACHE_VAL([ag_cv_allocated_ctime],[ AC_TRY_RUN([#include <time.h> int main (int argc, char** argv) { time_t timeVal = time( (time_t*)NULL ); char* pzTime = ctime( &timeVal ); free( (void*)pzTime ); return 0; }],[ag_cv_allocated_ctime=yes],[ag_cv_allocated_ctime=no],[ag_cv_allocated_ctime=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_allocated_ctime]) if test x$ag_cv_allocated_ctime = xyes then AC_DEFINE(HAVE_ALLOCATED_CTIME, 1, [Define this if ctime() allocates memory for its result]) fi ]) # end of AC_DEFUN dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_STRFTIME dnl dnl Check for existence and functioning of strftime routine. dnl AC_DEFUN(AG_CHECK_STRFTIME,[ AC_MSG_CHECKING([whether strftime() works]) AC_CACHE_VAL([ag_cv_strftime],[ AC_TRY_RUN([#include <time.h> char t_buf[ 64 ]; int main() { static const char z[] = "Thursday Aug 28 240"; struct tm tm; tm.tm_sec = 36; /* seconds after the minute [0, 61] */ tm.tm_min = 44; /* minutes after the hour [0, 59] */ tm.tm_hour = 12; /* hour since midnight [0, 23] */ tm.tm_mday = 28; /* day of the month [1, 31] */ tm.tm_mon = 7; /* months since January [0, 11] */ tm.tm_year = 86; /* years since 1900 */ tm.tm_wday = 4; /* days since Sunday [0, 6] */ tm.tm_yday = 239; /* days since January 1 [0, 365] */ tm.tm_isdst = 1; /* flag for daylight savings time */ strftime( t_buf, sizeof( t_buf ), "%A %b %d %j", &tm ); return (strcmp( t_buf, z ) != 0); }],[ag_cv_strftime=yes],[ag_cv_strftime=no],[ag_cv_strftime=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_strftime]) if test x$ag_cv_strftime = xyes then AC_DEFINE(HAVE_STRFTIME, 1, [Define this if strftime() works]) fi ]) # end of AC_DEFUN dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_POSIX_REGCOMP dnl dnl Check that the POSIX compliant regular expression compiler dnl is available in the POSIX specified manner, and it works. dnl AC_DEFUN(AG_CHECK_POSIX_REGCOMP,[ AC_MSG_CHECKING([whether POSIX compliant regcomp()/regexec()]) AC_CACHE_VAL([ag_cv_posix_regcomp],[ AC_TRY_RUN([#include <sys/types.h> #include <regex.h> int main() { regex_t re; return regcomp( &re, "^.*$", REG_EXTENDED|REG_ICASE|REG_NEWLINE ); }],[ag_cv_posix_regcomp=yes],[ag_cv_posix_regcomp=no],[ag_cv_posix_regcomp=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_posix_regcomp]) if test x$ag_cv_posix_regcomp = xyes then AC_DEFINE(HAVE_POSIX_REGCOMP, 1, [Define this if POSIX compliant regcomp()/regexec()]) fi ]) # end of AC_DEFUN dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_SYS_SIGLIST dnl dnl Check that the POSIX compliant regular expression compiler dnl is available in the POSIX specified manner, and it works. dnl AC_DEFUN(AG_CHECK_SYS_SIGLIST,[ AC_MSG_CHECKING([whether there is a global text array sys_siglist]) AC_CACHE_VAL([ag_cv_sys_siglist],[ AC_TRY_RUN([#include <signal.h> int main() { const char* pz = sys_siglist[1]; return (pz != 0) ? 0 : 1; }],[ag_cv_sys_siglist=yes],[ag_cv_sys_siglist=no],[ag_cv_sys_siglist=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_sys_siglist]) if test x$ag_cv_sys_siglist = xyes then AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define this if there is a global text array sys_siglist]) fi ]) # end of AC_DEFUN dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_POSIX_SYSINFO dnl dnl Check that the POSIX compliant sysinfo(2) call works properly. dnl Linux has its own weirdo alternative. dnl AC_DEFUN(AG_CHECK_POSIX_SYSINFO,[ AC_MSG_CHECKING([whether sysinfo(2) is POSIX]) AC_CACHE_VAL([ag_cv_posix_sysinfo],[ AC_TRY_RUN([#include <sys/systeminfo.h> int main() { char z[ 256 ]; long sz = sysinfo( SI_SYSNAME, z, sizeof( z )); return (sz > 0) ? 0 : 1; }],[ag_cv_posix_sysinfo=yes],[ag_cv_posix_sysinfo=no],[ag_cv_posix_sysinfo=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_posix_sysinfo]) if test x$ag_cv_posix_sysinfo = xyes then AC_DEFINE(HAVE_POSIX_SYSINFO, 1, [Define this if sysinfo(2) is POSIX]) fi ]) # end of AC_DEFUN dnl # # # # # # # # # # # # # dnl dnl AG_CHECK_UNAME_SYSCALL dnl dnl Check that the POSIX compliant uname(2) call works properly. dnl AC_DEFUN(AG_CHECK_UNAME_SYSCALL,[ AC_MSG_CHECKING([whether uname(2) is POSIX]) AC_CACHE_VAL([ag_cv_uname_syscall],[ AC_TRY_RUN([#include <sys/utsname.h> int main() { struct utsname unm; return uname( &unm ); }],[ag_cv_uname_syscall=yes],[ag_cv_uname_syscall=no],[ag_cv_uname_syscall=no] ) # end of TRY_RUN]) # end of CACHE_VAL AC_MSG_RESULT([$ag_cv_uname_syscall]) if test x$ag_cv_uname_syscall = xyes then AC_DEFINE(HAVE_UNAME_SYSCALL, 1, [Define this if uname(2) is POSIX]) fi ]) # end of AC_DEFUN