]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - m4/ul.m4
agetty: Fix input of non-ASCII characters in get_logname()
[thirdparty/util-linux.git] / m4 / ul.m4
index 0932131331a193267277cb90b08fbd55a9b2600e..9b3e73d22ad2c4e440f440ace6260faf8ca3b4d1 100644 (file)
--- a/m4/ul.m4
+++ b/m4/ul.m4
@@ -1,11 +1,37 @@
+dnl If needed, define the m4_ifblank and m4_ifnblank macros from autoconf 2.64
+dnl This allows us to run with earlier Autoconfs as well.
+dnl
+dnl m4_ifblank(COND, [IF-BLANK], [IF-TEXT])
+dnl m4_ifnblank(COND, [IF-TEXT], [IF-BLANK])
+dnl ----------------------------------------
+dnl If COND is empty, or consists only of blanks (space, tab, newline),
+dnl then expand IF-BLANK, otherwise expand IF-TEXT.  This differs from
+dnl m4_ifval only if COND has just whitespace, but it helps optimize in
+dnl spite of users who mistakenly leave trailing space after what they
+dnl thought was an empty argument:
+dnl   macro(
+dnl         []
+dnl        )
+dnl
+dnl Writing one macro in terms of the other causes extra overhead, so
+dnl we inline both definitions.
+ifdef([m4_ifblank],[],[
+m4_define([m4_ifblank],
+[m4_if(m4_translit([[$1]],  [ ][       ][
+]), [], [$2], [$3])])])
+
+ifdef([m4_ifnblank],[],[
+m4_define([m4_ifnblank],
+[m4_if(m4_translit([[$1]],  [ ][       ][
+]), [], [$3], [$2])])])
 
 dnl UL_PKG_STATIC(VARIABLE, MODULES)
 dnl
 dnl Calls pkg-config --static
 dnl
 AC_DEFUN([UL_PKG_STATIC], [
-  if AC_RUN_LOG([pkg-config --exists --print-errors "$2"]); then
-    $1=`pkg-config --libs --static "$2"`
+  if AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$2"]); then
+    $1=`$PKG_CONFIG --libs --static "$2"`
   else
     AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
   fi
@@ -13,7 +39,7 @@ AC_DEFUN([UL_PKG_STATIC], [
 
 dnl UL_CHECK_LIB(LIBRARY, FUNCTION, [VARSUFFIX = $1]))
 dnl
-dnl The VARSUFFIX is optional and overrides the default behaviour. For example:
+dnl The VARSUFFIX is optional and overrides the default behavior. For example:
 dnl     UL_CHECK_LIB(yyy, func, xxx) generates have_xxx and HAVE_LIBXXX
 dnl     UL_CHECK_LIB(yyy, func)      generates have_yyy and HAVE_LIBYYY
 dnl
@@ -92,7 +118,6 @@ AC_DEFUN([UL_CHECK_SYSCALL], [
       ])
     ul_cv_syscall_$1=$syscall
     ])
-  AM_CONDITIONAL([HAVE_]m4_toupper($1), [test "x$ul_cv_syscall_$1" != xno])
   case $ul_cv_syscall_$1 in #(
   no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
   SYS_*) ;;
@@ -148,14 +173,14 @@ AC_DEFUN([UL_REQUIRES_LINUX], [
     check:yes)
       [build_]suffix=yes ;;
     check:*)
-      AC_MSG_WARN([non-linux system; do not build $1])
+      AC_MSG_WARN([non-linux system; not building $1])
       [build_]suffix=no ;;
     esac
   fi
 ])
 
 
-dnl UL_EXCLUDE_ARCH(NAME, ARCH, VARSUFFIX = $1])
+dnl UL_EXCLUDE_ARCH(NAME, ARCH, [VARSUFFIX = $1])
 dnl
 dnl Modifies $build_<name>  variable according to $enable_<name> and $host. The
 dnl $enable_<name> could be "yes", "no" and "check". If build_<name> is "no" then
@@ -175,7 +200,7 @@ AC_DEFUN([UL_EXCLUDE_ARCH], [
     yes:*)
       [build_]suffix=yes ;;
     check:$2)
-      AC_MSG_WARN([exclude for $host architecture; do not build $1])
+      AC_MSG_WARN([excluded for $host architecture; not building $1])
       [build_]suffix=no ;;
     check:*)
       [build_]suffix=yes ;;
@@ -183,17 +208,17 @@ AC_DEFUN([UL_EXCLUDE_ARCH], [
   fi
 ])
 
-dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC [VARSUFFIX=$1])
+dnl UL_REQUIRES_HAVE(NAME, HAVENAME, HAVEDESC, [VARSUFFIX=$1])
 dnl
 dnl Modifies $build_<name> variable according to $enable_<name> and
-dnl $have_<havename>.  The <havedesc> is description used ifor warning/error
+dnl $have_<havename>.  The <havedesc> is description used for warning/error
 dnl message (e.g. "function").
 dnl
 dnl The <havename> maybe a list, then at least one of the items in the list
 dnl have to exist, for example: [ncurses, tinfo] means that have_ncurser=yes
 dnl *or* have_tinfo=yes must be defined.
 dnl
-dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
+dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
 dnl
 AC_DEFUN([UL_REQUIRES_HAVE], [
   m4_define([suffix], m4_default([$4],$1))
@@ -217,15 +242,51 @@ AC_DEFUN([UL_REQUIRES_HAVE], [
     check:yes)
       [build_]suffix=yes ;;
     check:*)
-      AC_MSG_WARN([$3 not found; do not build $1])
+      AC_MSG_WARN([$3 not found; not building $1])
       [build_]suffix=no ;;
     esac
   fi
 ])
 
+dnl UL_REQUIRES_HAVE(NAME, PROGRAM_PROLOGUE, PROGRAM_BODY, DESC, [VARSUFFIX=$1])
+dnl
+dnl Modifies $build_<name> variable according to $enable_<name> and
+dnl ability compile AC_LANG_PROGRAM(<program_prologue>, <program_body>).  
+dnl
+dnl The <desc> is description used for warning/error dnl message (e.g. "foo support").
+dnl
+dnl The default <name> for $build_ and $enable_ could be overwrited by option $5.
+
+AC_DEFUN([UL_REQUIRES_COMPILE], [
+  m4_define([suffix], m4_default([$5],$1))
+
+  if test "x$[build_]suffix" != xno; then
+
+    AC_MSG_CHECKING([$4])
+    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
+       [AC_MSG_RESULT([yes])
+        [ul_haveprogram_]suffix=yes],
+       [AC_MSG_RESULT([no])
+        [ul_haveprogram_]suffix=no])
+
+    case $[enable_]suffix:$[ul_haveprogram_]suffix in #(
+    no:*)
+      [build_]suffix=no ;;
+    yes:yes)
+      [build_]suffix=yes ;;
+    yes:*)
+      AC_MSG_ERROR([$1 selected, but required $4 not available]);;
+    check:yes)
+      [build_]suffix=yes ;;
+    check:*)
+      AC_MSG_WARN([$4 not found; not building $1])
+      [build_]suffix=no ;;
+    esac
+  fi
+])
 
 dnl
-dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC [VARSUFFIX=$1])
+dnl UL_CONFLICTS_BUILD(NAME, ANOTHER, ANOTHERDESC, [VARSUFFIX=$1])
 dnl
 dnl - ends with error if $enable_<name> and $build_<another>
 dnl   are both set to 'yes'
@@ -235,7 +296,7 @@ dnl
 dnl The <havedesc> is description used for warning/error
 dnl message (e.g. "function").
 dnl
-dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
+dnl The default <name> for $build_ and $enable_ could be overwrited by option $4.
 dnl
 AC_DEFUN([UL_CONFLICTS_BUILD], [
   m4_define([suffix], m4_default([$4],$1))
@@ -275,7 +336,7 @@ AC_DEFUN([UL_REQUIRES_BUILD], [
     check:yes)
       [build_]suffix=yes ;;
     check:*)
-      AC_MSG_WARN([$2 disabled; do not build $1])
+      AC_MSG_WARN([$2 disabled; not building $1])
       [build_]suffix=no ;;
     esac
   fi
@@ -297,13 +358,6 @@ AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
   m4_define([suffix], m4_default([$4],$1))
   m4_define([callname], m4_default([$3],$1))
 
-  dnl This is default, $3 will redefine the condition
-  dnl
-  dnl TODO: remove this junk, AM_CONDITIONAL should not be used for any HAVE_*
-  dnl       variables, all we need is BUILD_* only.
-  dnl
-  AM_CONDITIONAL([HAVE_]m4_toupper(callname), [false])
-
   if test "x$[build_]suffix" != xno; then
     if test "x$[enable_]suffix" = xno; then
       [build_]suffix=no
@@ -315,7 +369,7 @@ AC_DEFUN([UL_REQUIRES_SYSCALL_CHECK], [
       yes:no)
         AC_MSG_ERROR([$1 selected but callname syscall not found]) ;;
       check:no)
-        AC_MSG_WARN([callname syscall not found; do not build $1])
+        AC_MSG_WARN([callname syscall not found; not building $1])
         [build_]suffix=no ;;
       *)
         dnl default $ul_cv_syscall_ is SYS_ value
@@ -331,7 +385,7 @@ dnl Initializes $build_<name>  variable according to $enable_<name>. If
 dnl $enable_<name> is undefined then ENABLE_STATE is used and $enable_<name> is
 dnl set to ENABLE_STATE.
 dnl
-dnl The default <name> for $build_ and $enable_ could be overwrited by option $2.
+dnl The default <name> for $build_ and $enable_ could be overwrited by option $3.
 dnl
 AC_DEFUN([UL_BUILD_INIT], [
   m4_define([suffix], m4_default([$3],$1))
@@ -343,6 +397,10 @@ else
 fi],
 [if test "x$ul_default_estate" != x; then
   enable_[]suffix=$ul_default_estate
+  build_[]suffix=yes
+  if test "x$ul_default_estate" = xno; then
+    build_[]suffix=no
+  fi
 else[]
   ifelse(
       [$2], [check],[
@@ -370,3 +428,100 @@ AC_DEFUN([UL_DEFAULT_ENABLE], [
     enable_[]suffix=$2
   fi
 ])
+
+
+dnl UL_ENABLE_ALIAS(NAME, MASTERNAME)
+dnl
+dnl Initializes $enable_<name> variable according to $enable_<mastername>. This
+dnl is useful for example if you want to use one --enable-mastername option
+dnl for group of programs.
+dnl
+AC_DEFUN([UL_ENABLE_ALIAS], [
+  m4_define([suffix], $1)
+  m4_define([mastersuffix], $2)
+
+  enable_[]suffix=$enable_[]mastersuffix
+])
+
+
+dnl UL_NCURSES_CHECK(NAME)
+dnl
+dnl Initializes $have_<name>, NCURSES_LIBS and NCURSES_CFLAGS variables according to
+dnl <name>{6,5}_config output.
+dnl
+dnl The expected <name> is ncurses or ncursesw.
+dnl
+AC_DEFUN([UL_NCURSES_CHECK], [
+  m4_define([suffix], $1)
+  m4_define([SUFFIX], m4_toupper($1))
+
+  # ncurses6-config
+  #
+  AS_IF([test "x$have_[]suffix" = xno], [
+    AC_CHECK_TOOL(SUFFIX[]6_CONFIG, suffix[]6-config)
+    if AC_RUN_LOG([$SUFFIX[]6_CONFIG --version >/dev/null]); then
+      have_[]suffix=yes
+      NCURSES_LIBS=`$SUFFIX[]6_CONFIG --libs`
+      NCURSES_CFLAGS=`$SUFFIX[]6_CONFIG --cflags`
+    else
+      have_[]suffix=no
+    fi
+  ])
+
+  # ncurses5-config
+  #
+  AS_IF([test "x$have_[]suffix" = xno], [
+    AC_CHECK_TOOL(SUFFIX[]5_CONFIG, suffix[]5-config)
+    if AC_RUN_LOG([$SUFFIX[]5_CONFIG --version >/dev/null]); then
+      have_[]suffix=yes
+      NCURSES_LIBS=`$SUFFIX[]5_CONFIG --libs`
+      NCURSES_CFLAGS=`$SUFFIX[]5_CONFIG --cflags`
+    else
+      have_[]suffix=no
+    fi
+  ])
+
+  # pkg-config (not supported by ncurses upstream by default)
+  #
+  AS_IF([test "x$have_[]suffix" = xno], [
+    PKG_CHECK_MODULES(SUFFIX, [$1], [
+      have_[]suffix=yes
+      NCURSES_LIBS=${SUFFIX[]_LIBS}
+      NCURSES_CFLAGS=${SUFFIX[]_CFLAGS}
+    ],[have_[]suffix=no])
+  ])
+
+  # classic autoconf way
+  #
+  AS_IF([test "x$have_[]suffix" = xno], [
+    AC_CHECK_LIB([$1], [initscr], [have_[]suffix=yes], [have_[]suffix=no])
+    AS_IF([test "x$have_[]suffix" = xyes], [NCURSES_LIBS="-l[]suffix"])
+  ])
+])
+
+dnl
+dnl UL_TINFO_CHECK(NAME)
+dnl
+dnl Initializes $have_<name>, TINFO_LIBS and TINFO_CFLAGS variables.
+dnl
+dnl The expected <name> is tinfow or tinfo.
+dnl
+AC_DEFUN([UL_TINFO_CHECK], [
+  m4_define([suffix], $1)
+  m4_define([SUFFIX], m4_toupper($1))
+
+  PKG_CHECK_MODULES(SUFFIX, [$1], [
+    dnl pkg-config success
+    have_[]suffix=yes
+    TINFO_LIBS=${SUFFIX[]_LIBS}
+    TINFO_CFLAGS=${SUFFIX[]_CFLAGS}
+    UL_PKG_STATIC([TINFO_LIBS_STATIC], [$1])
+  ],[
+    dnl If pkg-config failed, fall back to classic searching.
+    AC_CHECK_LIB([$1], [tgetent], [
+       have_[]suffix=yes
+       TINFO_LIBS="-l[]suffix"
+       TINFO_LIBS_STATIC="-l[]suffix"
+       TINFO_CFLAGS=""])
+  ])
+])