On 10 Jan 2001, Alexandre Duret-Lutz wrote:
> >>> "gd" == Guido Draheim <[EMAIL PROTECTED]> writes:
>
> gd> Hi everyone,
> gd> in the last days I did hit a problem that I thought was good to
> gd> do with an autoconf-macro - may be someone has already done
> gd> such a beast. It goes about the number of arguments to mkdir(2).
>
> gd> While every unix (posix?) system takes two arguments (the
> gd> filename and the modebits), quite a few platforms only want
> gd> one argument, in my case it was not only win'ish mingw32
> gd> but also vxworks. As a side note: cygwin uses two args,
> gd> mingw32 one arg. I guess quite a few embedded RTOS do also
> gd> define mkdir with just one arg.
>
> gd> The question is: how to reliably detect the number of
> gd> arguments without TRY_RUN since it must be detectable
> gd> for crosscompiling targets. Anyone to give me a hint on
> gd> how to implement such an m4-macro? Or already on disk somewhere?
>
> I have been using the following macro for a few weeks,
> it might not be really perfect but at least it works for the
> hosts I need (this include crosscompiling to mingw32).
>
> dnl AC_FUNC_MKDIR
> dnl Check for mkdir.
> dnl Can define HAVE_MKDIR, HAVE__MKDIR and MKDIR_TAKES_ONE_ARG.
> dnl
> dnl #if HAVE_MKDIR
> dnl # if MKDIR_TAKES_ONE_ARG
> dnl /* Mingw32 */
> dnl # define mkdir(a,b) mkdir(a)
> dnl # endif
> dnl #else
> dnl # if HAVE__MKDIR
> dnl /* plain Win32 */
> dnl # define mkdir(a,b) _mkdir(a)
> dnl # else
> dnl # error "Don't know how to create a directory on this system."
> dnl # endif
> dnl #endif
> dnl
> dnl Written by Alexandre Duret-Lutz <[EMAIL PROTECTED]>.
>
> AC_DEFUN([AC_FUNC_MKDIR],
> [AC_CHECK_FUNCS([mkdir _mkdir])
> AC_CACHE_CHECK([whether mkdir takes one argument],
> [ac_cv_mkdir_takes_one_arg],
> [AC_TRY_COMPILE([
> #include <sys/stat.h>
> #ifdef HAVE_UNISTD_H
> # include <unistd.h>
> #endif
> ],[mkdir (".");],
> [ac_cv_mkdir_takes_one_arg=yes],[ac_cv_mkdir_takes_one_arg=no])])
> if test x"$ac_cv_mkdir_takes_one_arg" = xyes; then
> AC_DEFINE([MKDIR_TAKES_ONE_ARG],1,
> [Define if mkdir takes only one argument.])
> fi
> ])
>
> --
> Alexandre Duret-Lutz
Along these same lines, here is the mkdir check from
the configure.in in Jikes. Note that the mac version
is just for kicks, I don't think it actually works.
dnl We need to do some nasty checks here to make sure that
dnl we know what version of mkdir() to call.
dnl First, we just make sure mkdir() actually exists
AC_CHECK_FUNCS(mkdir, , AC_MSG_ERROR([No mkdir() function found]))
AC_CACHE_CHECK(for mac style mkdir, jikes_cv_mac_mkdir,
AC_TRY_LINK([
#include <sys/stat.h>
#include <stat.mac.h>
], [mkdir("foo.dir", 0);
], jikes_cv_mac_mkdir=yes,
jikes_cv_mac_mkdir=no)
)
AC_CACHE_CHECK(for glibc style mkdir, jikes_cv_glibc_mkdir,
AC_TRY_LINK([
#include <sys/stat.h>
#include <unistd.h>
], [mkdir("foo.dir", S_IRWXU | S_IRWXG | S_IRWXO);
], jikes_cv_glibc_mkdir=yes,
jikes_cv_glibc_mkdir=no)
)
AC_CACHE_CHECK(for libc5 style mkdir, jikes_cv_libc5_mkdir,
AC_TRY_LINK([
#include <sys/stat.h>
#include <unistd.h>
], [mkdir("foo.dir", S_IRWXU);
], jikes_cv_libc5_mkdir=yes,
jikes_cv_libc5_mkdir=no)
)
AC_CACHE_CHECK(for win32 style mkdir, jikes_cv_win32_mkdir,
AC_TRY_LINK([
#include <direct.h>
], [mkdir("foo.dir");
], jikes_cv_win32_mkdir=yes,
jikes_cv_win32_mkdir=no)
)
if test "$jikes_cv_glibc_mkdir" = "yes" ; then
AC_DEFINE(HAVE_GLIBC_MKDIR, ,
[use unix style mkdir(str, S_IRWXU | S_IRWXG | S_IRWXO)])
elif test "$jikes_cv_libc5_mkdir" = "yes" ; then
AC_DEFINE(HAVE_LIBC5_MKDIR, ,
[use unix style mkdir(str, S_IRWXU)])
elif test "$jikes_cv_win32_mkdir" = "yes" ; then
AC_DEFINE(HAVE_WIN32_MKDIR, ,
[use win32 style mkdir(str) from <direct.h>])
elif test "$jikes_cv_mac_mkdir" = "yes" ; then
AC_DEFINE(HAVE_MAC_MKDIR, ,
[use mac style mkdir(str,0) from <stat.mac.h>])
else
AC_MSG_ERROR([Could not locate a working mkdir() implementation])
fi
cheers
Mo DeJong
Red Hat Inc