# # libMird by Mirar # please submit bug reports and patches to the author # # for licence, read the LICENCE file # # $Id: configure.in,v 1.23 2001/03/26 12:34:03 mirar Exp $ AC_INIT(internal.h) AC_CONFIG_HEADER(config.h) AC_PROG_CC AC_PROG_RANLIB AC_TRY_CPP AC_PATH_PROG(AR, ar, ar, $PATH:$EXTRA_PATH) export AR AC_SUBST(AR) # defaults # enable_memdebug=yes # enable_memstats=yes AC_ARG_ENABLE(memdebug, [ --enable-memdebug turn on run time boundary checks],[enable_memdebug=yes],[enable_memdebug=no]) AC_ARG_ENABLE(memstats, [ --enable-memstats turn on memory usage statistics],[enable_memstats=yes],[enable_memstats=no]) AC_MSG_CHECKING(memory debug) if test x$enable_memdebug = xyes ; then AC_DEFINE(MEM_DEBUG) AC_MSG_RESULT("yes") AC_MSG_CHECKING(memory statistics) if test x$enable_memstats = xyes ; then AC_MSG_RESULT("yes") AC_DEFINE(MEM_STATS) else AC_MSG_RESULT("no") fi else AC_MSG_RESULT("no") fi #---- compiler flags --------------- AC_DEFUN(MY_AC_PROG_CC_FLAG, [AC_CACHE_CHECK(whether ${CC-cc} accepts $1, ac_cv_prog_cc_[]translit($1,[A-Za-z .-],[A-Za-z_]), [echo 'void f(){}' > conftest.c if test -z "`${CC-cc} $1 -c conftest.c 2>&1`"; then ac_cv_prog_cc_[]translit($1,[A-Za-z .-],[A-Za-z_])=yes else ac_cv_prog_cc_[]translit($1,[A-Za-z .-],[A-Za-z_])=no fi rm -f conftest* ]) if test "x$ac_cv_prog_cc_[]translit($1,[A-Za-z .-],[A-Za-z_])" = "xyes"; then CFLAGS="${CFLAGS} $1" fi ]) CFLAGS='' MY_AC_PROG_CC_FLAG(-g) MY_AC_PROG_CC_FLAG(-Wall) if test "x$ac_cv_prog_cc_-Wall" = "xno"; then MY_AC_PROG_CC_FLAG(-W) fi MY_AC_PROG_CC_FLAG(-O) MY_AC_PROG_CC_FLAG(-fPIC) if test "x$ac_cv_prog_cc_-fPIC" = "xno"; then MY_AC_PROG_CC_FLAG(-fpic) fi AC_MSG_CHECKING(for irritating if-if-else-else warnings) AC_CACHE_VAL(mird_cv_stupid_if_if_else_else_warning, [ echo 'int foo(int x,int y)'\ '{ if(x) if(y) x=1; else x=2; else x=3; '\ ' if(x) if(y) x=1; else x=2; return x;}' > conftest.c if ${CC-cc} ${CFLAGS} -c conftest.c 2>&1 | grep -i Warning >/dev/null; then mird_cv_stupid_if_if_else_else_warning=yes else mird_cv_stupid_if_if_else_else_warning=no fi ]) if test "x$mird_cv_stupid_if_if_else_else_warning" = "xyes" ; then AC_MSG_RESULT([yes (stupid gcc)]) # CCFILTER=' 2>&1 | grep -v ambiguous\ \`else'"\\'" MY_AC_PROG_CC_FLAG(-Wno-parentheses) else AC_MSG_RESULT([no (good)]) fi CCFILTER="" #----- ansi prototypes? ----- AC_MSG_CHECKING(ansi prototype capability) AC_CACHE_VAL(mird_cv_sys_ansi_prototypes, [ AC_TRY_COMPILE([int foo(int bar);],[], [mird_cv_sys_ansi_prototypes=yes], [mird_cv_sys_ansi_prototypes=no]) ]) if test "$mird_cv_sys_ansi_prototypes" = "yes"; then AC_MSG_RESULT(yes) else AC_MSG_RESULT([no, giving up]) exit 1 fi #---- large file support, sunos ---- AC_MSG_CHECKING(CFLAGS for large file support) AC_CACHE_VAL(mird_cv_largefile_cflags, [mird_cv_largefile_cflags=`getconf LFS_CFLAGS 2>&5`]) if test "x$mird_cv_largefile_cflags" != "x"; then AC_MSG_RESULT($mird_cv_largefile_cflags) CFLAGS="${CFLAGS} $mird_cv_largefile_cflags" else AC_MSG_RESULT(none) fi AC_MSG_CHECKING(LDFLAGS for large file support) AC_CACHE_VAL(mird_cv_largefile_ldflags, [mird_cv_largefile_ldflags=`getconf LFS_LDFLAGS 2>&5`]) if test "x$mird_cv_largefile_ldflags" != "x"; then AC_MSG_RESULT($mird_cv_largefile_ldflags) LDFLAGS="${LDFLAGS} $mird_cv_largefile_ldflags" else AC_MSG_RESULT(none) fi #---- linking shared libraries ---- # SO is the extension of shared libraries # -- usually so, sl on HP-UX AC_MSG_CHECKING(name of shared libraries) AC_CACHE_VAL(mird_cv_so, [ if test "x`ls -1 /lib/*.sl /usr/lib/*.sl 2>&5`" != "x"; then mird_cv_so=sl; else if test "x`ls -1 /lib/*.so /usr/lib/*.so 2>&5`" != "x"; then mird_cv_so=so; else echo 'guessing: ' >&2 mird_cv_so=so; fi; fi ]) AC_MSG_RESULT(.$mird_cv_so) SO=$mird_cv_so AC_SUBST(SO) SOVER=${SO}.1 AC_SUBST(SOVER) #--- OLD_CFLAGS="$CFLAGS" MY_AC_PROG_CC_FLAG(-R.) MY_AC_PROG_CC_FLAG(-L.) LCFLAGS="$CFLAGS" CFLAGS="$OLD_CFLAGS" AC_DEFUN(MY_AC_PROG_LD_FLAG, [AC_CACHE_CHECK(whether ${LD} accepts $1, ac_cv_prog_ld_[]translit($1,[A-Za-z -],[A-Za-z_]), [echo 'int main(){ return 0; }' > conftest.c ${CC-cc} ${CFLAGS} conftest.c -c -o conftest.o 2>&5 1>&2 if test -z "`${LD} ${LDFLAGS} $1 conftest.o -o conftest.$SO 2>&1`"; then ac_cv_prog_ld_[]translit($1,[A-Za-z -],[A-Za-z_])=yes else ac_cv_prog_ld_[]translit($1,[A-Za-z -],[A-Za-z_])=no fi rm -f conftest* ]) if test "x$ac_cv_prog_ld_[]translit($1,[A-Za-z -],[A-Za-z_])" = "xyes"; then LDFLAGS="${LDFLAGS} $1" fi ]) AC_DEFUN(MY_AC_LD_TEST, [AC_CACHE_CHECK(if $1 creates shared libraries, ac_cv_[]translit($1,[A-Za-z -],[A-Za-z_]), [ac_cv_[]translit($1,[A-Za-z -],[A-Za-z_])=no echo '#include static int x=12; int lib_fun_foo(void){ x=42; printf("working!"); return 17; } ' > conftest1.c echo "${CC-cc} ${CFLAGS} conftest1.c -c -o conftest1.o" >&5 ${CC-cc} ${CFLAGS} conftest1.c -c -o conftest1.o 2>&5 1>&2 echo "$1 ${LCFLAGS} ${LDFLAGS} conftest1.o -o libconftest.${SO}" >&5 if $1 ${LCFLAGS} ${LDFLAGS} conftest1.o -o libconftest.${SO} 2>&5 1>&2; then ls -l *conftest* >&5 echo 'int lib_fun_foo(void); int main(void){ return lib_fun_foo()!=17; }' > conftest2.c echo "${CC-cc} ${LDFLAGS} ${LCFLAGS} conftest2.c -o conftest2 -lconftest" >&5 ${CC-cc} ${LDFLAGS} ${LCFLAGS} conftest2.c -o conftest2 -lconftest 2>&5 1>&2 LD_LIBRARY_PATH="." export LD_LIBRARY_PATH echo "./conftest2" >&5 if ./conftest2 2>&5 1>&2; then ac_cv_[]translit($1,[A-Za-z -],[A-Za-z_])=yes fi fi rm -f conftest* libconftest* ]) if test "x$ac_cv_[]translit($1,[A-Za-z -],[A-Za-z_])" = "xyes"; then LD="$1" fi ]) OLD_LDFLAGS="$LDFLAGS" MY_AC_LD_TEST(gcc -shared) if test "x$ac_cv_gcc_shared" != "xyes"; then LCFLAGS="-L." MY_AC_LD_TEST(ld -G) if test "x$ac_cv_ld_G" != "xyes"; then MY_AC_LD_TEST(ld -Bshareable) if test "x$ac_cv_ld_Bshareable" != "xyes"; then echo === failed to created shared libraries >&2 echo === cannot continue >&2 exit 1 fi fi fi AC_SUBST(LD) MY_AC_PROG_LD_FLAG(-n32) MY_AC_PROG_LD_FLAG(-bexpall) MY_AC_PROG_LD_FLAG(-fPIC) if test "x$ac_cv_prog_ld_-fPIC" = "xno"; then MY_AC_PROG_LD_FLAG(-fpic) fi MY_AC_PROG_LD_FLAG(-KPIC) LDSHARED="$LDFLAGS" LDFLAGS="$OLD_LDFLAGS" AC_SUBST(LDSHARED) NOOPTFLAGS="$(echo "$CFLAGS" | sed 's/-O2//g')" AC_SUBST(NOOPTFLAGS) AC_MSG_CHECKING(for 16 bit int) AC_CACHE_VAL(mird_cv_int16, [AC_TRY_RUN([int main() { return sizeof(short)!=2; }], [mird_cv_int16="short"], [AC_TRY_RUN([int main() { return sizeof(int)!=2; }], [mird_cv_int16=int], [AC_TRY_RUN([int main() { return sizeof(long)!=2; }], [mird_cv_int16=long], [AC_TRY_RUN([int main() { return sizeof(long char)!=2; }], [mird_cv_int16="long long"], [AC_MSG_RESULT([no, giving up]) exit 1],[?])],[?])],[?])], [AC_MSG_RESULT(cross-compiling, can't do that) exit 1])]) AC_MSG_RESULT($mird_cv_int16) AC_DEFINE_UNQUOTED(INT16,$mird_cv_int16) AC_MSG_CHECKING(for 32 bit int) AC_CACHE_VAL(mird_cv_int32, [AC_TRY_RUN([int main() { return sizeof(long)!=4; }], [mird_cv_int32=long], [AC_TRY_RUN([int main() { return sizeof(int)!=4; }], [mird_cv_int32=int], [AC_TRY_RUN([int main() { return sizeof(long long)!=4; }], [mird_cv_int32="long long"], [AC_TRY_RUN([int main() { return sizeof(short)!=4; }], [mird_cv_int32="short"], [AC_MSG_RESULT([no, giving up]) exit 1],[?])],[?])],[?])], [AC_MSG_RESULT(cross-compiling, can't do that) exit 1])]) AC_MSG_RESULT($mird_cv_int32) AC_DEFINE_UNQUOTED(INT32,$mird_cv_int32) AC_MSG_CHECKING(for 64 bit int) AC_CACHE_VAL(mird_cv_int64, [AC_TRY_RUN([int main() { return sizeof(long)!=8; }], [mird_cv_int64=long], [AC_TRY_RUN([int main() { return sizeof(int)!=8; }], [mird_cv_int64=int], [AC_TRY_RUN([int main() { return sizeof(long long)!=8; }], [mird_cv_int64="long long"], [AC_TRY_RUN([int main() { return sizeof(short)!=8; }], [mird_cv_int64="short"], [mird_cv_int64="none"],[?])],[?])],[?])], [AC_MSG_RESULT(cross-compiling, can't do that) exit 1])]) AC_MSG_RESULT($mird_cv_int64) if test "x$mird_cv_int64" != "xnone"; then AC_DEFINE_UNQUOTED(INT64,$mird_cv_int64) INT64=$mird_cv_int64 else INT64=$mird_cv_int32 fi INT32=$mird_cv_int32 AC_CHECK_HEADERS(arpa/inet.h netinet/in.h sys/file.h string.h sys/param.h \ errno.h sys/types.h sys/stat.h fcntl.h strings.h string.h) AC_HAVE_FUNCS(fdatasync ftruncate pread pwrite memset memcmp \ memmove memcpy llseek lseek64) AC_CHECK_LIB(xnet,htonl,[LIBS="${LIBS} -lxnet"]) #---- inline keyword ---- AC_MSG_CHECKING(inline keyword) AC_CACHE_VAL(mird_cv_inline_keyword, [ AC_TRY_LINK([static inline int foo(int bar);],[ exit(0); ], [mird_cv_inline_keyword="static inline"], [ AC_TRY_LINK([static __inline int foo(int bar);],[ exit(0); ], [mird_cv_inline_keyword="static __inline"], [mird_cv_inline_keyword="no"]) ]) ]) if test "$mird_cv_inline_keyword" != "no"; then AC_MSG_RESULT($mird_cv_inline_keyword) AC_DEFINE(HAS_INLINE) AC_DEFINE_UNQUOTED(INLINE,$mird_cv_inline_keyword) else AC_DEFINE_UNQUOTED(INLINE,) AC_MSG_RESULT(no) fi #---- file locking method ------------ AC_MSG_CHECKING(if flock works) AC_CACHE_VAL(mird_cv_has_flock, [AC_TRY_LINK([#include ], [ flock(1,LOCK_EX|LOCK_NB); ], [mird_cv_has_flock=yes], [mird_cv_has_flock=no])]) if test "x$mird_cv_has_flock" = "xyes"; then AC_DEFINE(HAS_FLOCK) fi AC_MSG_RESULT($mird_cv_has_flock) AC_MSG_CHECKING(if lockf works) AC_CACHE_VAL(mird_cv_has_lockf, [AC_TRY_RUN([#include #include #include #include int main() { int fd; fd=open("conftest.file",O_CREAT|O_RDWR,0666); return !!lockf(fd,F_LOCK,0); }], [mird_cv_has_lockf=yes], [mird_cv_has_lockf=no],[?])]) if test "x$mird_cv_has_lockf" = "xyes"; then AC_DEFINE(HAS_LOCKF) fi AC_MSG_RESULT($mird_cv_has_lockf) #---- free space method ------------ AC_MSG_CHECKING(file free space method) AC_CACHE_VAL(mird_cv_file_free, [AC_TRY_LINK( [#include #include #include ], [struct flock fl; fcntl(1,F_FREESP,&fl);], [mird_cv_file_free=fcntl_freesp], [mird_cv_file_free=none]) ]) case "x_$mird_cv_file_free" in x_fcntl_freesp) AC_MSG_RESULT(fcntl(...F_FREESP...)) AC_DEFINE(USE_FCNTL_FREESP) ;; x_none) AC_MSG_RESULT(none) ;; *) echo error exit 1 ;; esac #---- off_t -------------------- AC_MSG_CHECKING(for off_t) AC_CACHE_VAL(mird_cv_off_t, [AC_TRY_RUN([#include int main() { off_t x; return 0; }], [mird_cv_off_t=yes], [mird_cv_off_t=no], [?]) ]) AC_MSG_RESULT($mird_cv_off_t) AC_MSG_CHECKING(for loff_t) AC_CACHE_VAL(mird_cv_loff_t, [AC_TRY_RUN([#include int main() { loff_t x; return 0; }], [mird_cv_loff_t=yes], [mird_cv_loff_t=no], [?]) ]) AC_MSG_RESULT($mird_cv_loff_t) AC_MSG_CHECKING(what off_t type to use) if test "x$mird_cv_loff_t" = "xno"; then if test "x$mird_cv_off_t" = "xno" ; then MIRD_OFF_T="signed long" AC_DEFINE_UNQUOTED(MIRD_OFF_T,signed long) else MIRD_OFF_T="off_t" AC_DEFINE_UNQUOTED(MIRD_OFF_T,off_t) fi else MIRD_OFF_T="loff_t" AC_DEFINE_UNQUOTED(MIRD_OFF_T,loff_t) fi AC_MSG_RESULT($MIRD_OFF_T) AC_MSG_CHECKING(64 bit off_t) AC_CACHE_VAL(mird_cv_64_bit_off_t, [AC_TRY_RUN([#include int main() { return !( (((MIRD_OFF_T)4711)<<32) == 20233590931456);}], [mird_cv_64_bit_off_t=yes], [mird_cv_64_bit_off_t=no], [?]) ]) AC_MSG_RESULT($mird_cv_64_bit_off_t) if test "x$mird_cv_64_bit_off_t" = "xyes"; then OFF_T=$INT64 AC_MSG_CHECKING(how to printf off_t) AC_CACHE_VAL(mird_cv_printf_off_t, [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%lld",((MIRD_OFF_T)4711)<<32); return !!strcmp("20233590931456",buf); }], [mird_cv_printf_off_t="ll"], [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%ld",((MIRD_OFF_T)4711)<<32); return !!strcmp("20233590931456",buf); }], [mird_cv_printf_off_t="l"], [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%d",((MIRD_OFF_T)4711)<<32); return !!strcmp("20233590931456",buf); }], [mird_cv_printf_off_t=""], [echo "(none found?) \c" mird_cv_printf_off_t=""], [?])], [?])], [?]) ]) AC_MSG_RESULT([%${mird_cv_printf_off_t}d, %${mird_cv_printf_off_t}x]) AC_DEFINE_UNQUOTED(PRINTOFFT,"$mird_cv_printf_off_t") else OFF_T=$INT32 AC_MSG_CHECKING(how to printf off_t) AC_CACHE_VAL(mird_cv_printf_off_t, [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%lld",(MIRD_OFF_T)47114711); return !!strcmp("47114711",buf); }], [mird_cv_printf_off_t="ll"], [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%ld",(MIRD_OFF_T)47114711); return !!strcmp("47114711",buf); }], [mird_cv_printf_off_t="l"], [AC_TRY_RUN([#include #include int main() { char buf[32]; sprintf(buf,"%d",(MIRD_OFF_T)47114711); return !!strcmp("47114711",buf); }], [mird_cv_printf_off_t=""], [echo "(none found?) \c" mird_cv_printf_off_t=""], [?])], [?])], [?]) ]) AC_MSG_RESULT([%${mird_cv_printf_off_t}d, %${mird_cv_printf_off_t}x]) AC_DEFINE_UNQUOTED(PRINTOFFT,"$mird_cv_printf_off_t") fi #---- stat block size (unit of stat.st_blocks) -------------------- AC_MSG_CHECKING(unit of stat.st_blocks) AC_CACHE_VAL(mird_cv_stat_blockunit, [mird_cv_stat_blockunit=512 AC_EGREP_CPP(DEV_BSIZE, [#include #include #include #ifdef DEV_BSIZE "DEV_BSIZE" #endif], mird_cv_stat_blockunit=DEV_BSIZE)]) AC_MSG_RESULT($mird_cv_stat_blockunit) AC_DEFINE_UNQUOTED(STAT_BLOCKUNIT,$mird_cv_stat_blockunit) #---- unaligned memory access (at least enough) -------------------- AC_MSG_CHECKING(unaligned memory access) AC_CACHE_VAL(mird_cv_unaligned_access,[ AC_TRY_RUN([ #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_ARPA_INET_H #include #endif long mird_s_key_hash(unsigned char *data, int len) { long z=0; while (len>=4) { z=(z*137912897)+htonl(data); data+=4; len-=4; } return z; } int main() { char *s="blahblahblahblahzotzotzotblahflrpt"; mird_s_key_hash(s,20); mird_s_key_hash(s+1,20); mird_s_key_hash(s+2,20); mird_s_key_hash(s+3,20); mird_s_key_hash(s+4,20); mird_s_key_hash(s+5,20); mird_s_key_hash(s+6,20); mird_s_key_hash(s+7,20); mird_s_key_hash(s+8,20); mird_s_key_hash(s+9,20); mird_s_key_hash(s+10,20); return 0; } ], [mird_cv_unaligned_access=yes], [mird_cv_unaligned_access=no], [?])]) AC_MSG_RESULT($mird_cv_unaligned_access) if test "x$mird_cv_unaligned_access" = "xyes"; then AC_DEFINE(HANDLES_UNALIGNED_ACCESS) fi #---- testing if O_APPEND works --------------------------------- AC_MSG_CHECKING(if O_APPEND works) AC_CACHE_VAL(mird_cv_working_o_append, [mird_cv_working_o_append=no; AC_TRY_RUN([ #include #include #include #include int main() { int fd; fd=open("conftest.tmp",O_CREAT|O_TRUNC|O_APPEND|O_RDWR,0666); write(fd,"hej",3); lseek(fd,0,SEEK_SET); write(fd,"san\n",4); return 0; }], [if grep hejsan conftest.tmp >/dev/null 2>&5; then mird_cv_working_o_append=yes; fi],[],[?])]) AC_MSG_RESULT($mird_cv_working_o_append) if test "x$mird_cv_working_o_append" = "xyes"; then AC_DEFINE(WORKING_O_APPEND) fi #---- testing if O_BINARY works --------------------------------- AC_MSG_CHECKING(if O_BINARY exist) AC_CACHE_VAL(mird_cv_have_o_binary, [mird_cv_have_o_binary=no; rm conftest.tmp; AC_TRY_RUN([ #include #include #include #include int main() { int fd; fd=open("conftest.tmp",O_CREAT|O_TRUNC|O_BINARY|O_RDWR,0666); write(fd,"zoo",3); return 0; }], [if grep zoo conftest.tmp >/dev/null 2>&5; then mird_cv_have_o_binary=yes; fi],[],[?])]) AC_MSG_RESULT($mird_cv_have_o_binary) if test "x$mird_cv_have_o_binary" = "xyes"; then AC_DEFINE(HAVE_O_BINARY) fi #---- testing if ftrunc works --------------------------------- AC_MSG_CHECKING(if ftruncate works) AC_CACHE_VAL(mird_cv_working_ftruncate, [mird_cv_working_ftruncate=no; AC_TRY_RUN([ #include #include #include #include int main() { int fd; fd=open("conftest.tmp",O_CREAT|O_TRUNC|O_APPEND|O_RDWR,0666); write(fd,"hejsan",3); lseek(fd,3,SEEK_SET); ftruncate(fd,3); return 0; }], [if grep -v hejsan conftest.tmp >/dev/null 2>&5 && grep hej conftest.tmp >/dev/null 2>&5 ; then mird_cv_working_ftruncate=yes; fi],[],[?])]) AC_MSG_RESULT($mird_cv_working_ftruncate) if test "x$mird_cv_working_ftruncate" = "xyes"; then AC_DEFINE(WORKING_FTRUNCATE) fi MIRD_BUILDER="`(ls -l \`tty\` || ls -l config.log) | awk '{print $3}'`@`uname -a | awk '{print $2}'`" 2>&5 MIRD_BUILD_TIME="`date`" 2>&5 AC_SUBST(MIRD_BUILDER) AC_SUBST(MIRD_BUILD_TIME) #---- make stuff ------------------- AC_DEFINE(SYSCALL_STATISTICS) UINT32="unsigned $INT32" UINT64="unsigned $INT64" AC_SUBST(INT32) AC_SUBST(INT64) AC_SUBST(UINT32) AC_SUBST(UINT64) AC_SUBST(CCFILTER) AC_SUBST(OFF_T) AC_SUBST(ac_configure_args) AC_OUTPUT(Makefile mird.h)