vshost-util-vserver

Build script and sources for util-vserver.
git clone https://ccx.te2000.cz/git/vshost-util-vserver
Log | Files | Refs

ensc_dietlibc.m4 (5675B)


      1 dnl Copyright (C) 2002,2014 Enrico Scholz <enrico.scholz@ensc.de>
      2 dnl
      3 dnl This program is free software; you can redistribute it and/or modify
      4 dnl it under the terms of the GNU General Public License as published by
      5 dnl the Free Software Foundation; version 2 of the License.
      6 dnl
      7 dnl This program is distributed in the hope that it will be useful,
      8 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 dnl GNU General Public License for more details.
     11 dnl
     12 dnl You should have received a copy of the GNU General Public License
     13 dnl along with this program; if not, write to the Free Software
     14 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
     15 
     16 AC_DEFUN([_ENSC_DIETLIBC_C99],
     17 [
     18 	AH_TEMPLATE([ENSC_DIETLIBC_C99], [Define to 1 if dietlibc supports C99])
     19 
     20 	AC_CACHE_CHECK([whether dietlibc supports C99], [ensc_cv_c_dietlibc_c99],
     21 	[
     22 		_ensc_dietlibc_c99_old_CFLAGS=$CFLAGS
     23 		_ensc_dietlibc_c99_old_CC=$CC
     24 
     25 		CFLAGS="-std=c99"
     26 		CC="${DIET:-diet} $CC"
     27 
     28 		AC_LANG_PUSH(C)
     29 		AC_COMPILE_IFELSE([AC_LANG_SOURCE([/* */])],[
     30 			AC_COMPILE_IFELSE([AC_LANG_SOURCE([
     31 				#include <stdint.h>
     32 				#include <sys/cdefs.h>
     33 				#if defined(inline)
     34 				#  error 'inline' badly defined
     35 				#endif
     36 				volatile uint64_t	a;
     37 			])],
     38 			[ensc_cv_c_dietlibc_c99=yes],
     39 			[ensc_cv_c_dietlibc_c99=no])],
     40 			[ensc_cv_c_dietlibc_c99='skipped (compiler does not support C99)'])
     41 		AC_LANG_POP
     42 
     43 		CC=$_ensc_dietlibc_c99_old_CC
     44 		CFLAGS=$_ensc_dietlibc_c99_old_CFLAGS
     45 	])
     46 
     47 	if test x"$ensc_cv_c_dietlibc_c99" = xyes; then
     48 		AC_DEFINE(ENSC_DIETLIBC_C99,1)
     49 	fi
     50 ])
     51 
     52 AC_DEFUN([_ENSC_DIETLIBC_SYSCALL],
     53 [
     54 	AH_TEMPLATE([ENSC_DIETLIBC_HAS_SYSCALL], [Define to 1 if dietlibc declares syscall])
     55 
     56 	AC_CACHE_CHECK([whether dietlibc declares syscall], [ensc_cv_c_dietlibc_syscall],
     57 	[
     58 		_ensc_dietlibc_syscall_old_CC="$CC"
     59 		CC="${DIET:-diet} $CC"
     60 
     61 		AC_LANG_PUSH(C)
     62 		AC_COMPILE_IFELSE([AC_LANG_SOURCE([
     63 			#include <sys/syscall.h>
     64 			long int syscall(long int __sysno, ...);
     65 		])],
     66 		[ensc_cv_c_dietlibc_syscall=no],
     67 		[ensc_cv_c_dietlibc_syscall=yes])
     68 		AC_LANG_POP
     69 
     70 		CC="$_ensc_dietlibc_syscall_old_CC"
     71 	])
     72 
     73 	if test x"$ensc_cv_c_dietlibc_syscall" = xyes; then
     74 		AC_DEFINE(ENSC_DIETLIBC_HAS_SYSCALL,1)
     75 	fi
     76 ])
     77 
     78 AC_DEFUN([_ENSC_DIETLIBC_PIVOT_ROOT],
     79 [
     80 	AH_TEMPLATE([ENSC_DIETLIBC_HAS_PIVOT_ROOT], [Define to 1 if dietlibc declares pivot_root()])
     81 
     82 	AC_CACHE_CHECK([whether dietlibc declares pivot_root], [ensc_cv_c_dietlibc_pivot_root],
     83 	[
     84 		_ensc_dietlibc_pivot_root_old_CC="$CC"
     85 		CC="${DIET:-diet} $CC"
     86 
     87 		AC_LANG_PUSH(C)
     88 		AC_COMPILE_IFELSE([AC_LANG_SOURCE([
     89 			#define _GNU_SOURCE
     90 			#define _LINUX_SOURCE
     91 			#include <unistd.h>
     92 			void pivot_root(void);
     93 		])],
     94 		[ensc_cv_c_dietlibc_pivot_root=no],
     95 		[ensc_cv_c_dietlibc_pivot_root=yes])
     96 		AC_LANG_POP
     97 
     98 		CC="$_ensc_dietlibc_pivot_root_old_CC"
     99 	])
    100 
    101 	if test x"$ensc_cv_c_dietlibc_pivot_root" = xyes; then
    102 		AC_DEFINE([ENSC_DIETLIBC_HAS_PIVOT_ROOT],1)
    103 	fi
    104 ])
    105 
    106 dnl Usage: ENSC_ENABLE_DIETLIBC(<conditional>[,<min-version>])
    107 dnl        <conditional> ... automake-conditional which will be set when
    108 dnl                          dietlibc shall be enabled
    109 dnl        provides:
    110 dnl        * $ENSC_VERSION_DIETLIBC_NUM and
    111 dnl        * $ENSC_VERSION_DIETLIBC
    112 
    113 AC_DEFUN([ENSC_ENABLE_DIETLIBC],
    114 [
    115 	AC_MSG_CHECKING([whether to enable dietlibc])
    116 
    117 	AC_ARG_VAR(DIET,      [The 'diet' wrapper (default: diet)])
    118 	AC_ARG_VAR(DIETFLAGS, [Flags passed to the 'diet' wrapper (default: -O)])
    119 
    120 	: ${DIET:=diet}
    121 	: ${DIETFLAGS=-Os}
    122 
    123 	AC_ARG_ENABLE([dietlibc],
    124 		      [AS_HELP_STRING([--disable-dietlibc],
    125 				      [do not use dietlibc resp. enforce its usage
    126 				       (with --enable-dietlibc) (default: autodetect dietlibc)])],
    127 		      [case "$enableval" in
    128 			  (yes)	use_dietlibc=forced;;
    129 			  (no)	use_dietlibc=forced_no;;
    130 			  (*)	AC_MSG_ERROR(['$enableval' is not a valid value for --enable-dietlibc]);;
    131 		       esac],
    132 		      [which "$DIET" >/dev/null 2>/dev/null && use_dietlibc=detected || use_dietlibc=detected_no])
    133 
    134 	if test "$use_dietlibc" = detected -a "$2"; then
    135 	    _dietlibc_ver=$($DIET -v 2>&1 | sed '1p;d')
    136 	    _dietlibc_ver=${_dietlibc_ver##*diet version }
    137 	    _dietlibc_ver=${_dietlibc_ver##*dietlibc-}
    138 	    _dietlibc_ver_maj=${_dietlibc_ver%%.*}
    139 	    _dietlibc_ver_min=${_dietlibc_ver#*.}
    140 	    _dietlibc_ver_min=${_dietlibc_ver_min%%[[!0-9]]*}
    141 	    _dietlibc_cmp="$2"
    142 	    _dietlibc_cmp_maj=${_dietlibc_cmp%%.*}
    143 	    _dietlibc_cmp_min=${_dietlibc_cmp#*.}
    144 
    145 	    ENSC_VERSION_DIETLIBC=$_dietlibc_ver_maj.$_dietlibc_ver_min
    146 
    147 	    let _dietlibc_ver=_dietlibc_ver_maj*1000+_dietlibc_ver_min 2>/dev/null || _dietlibc_ver=0
    148 	    let _dietlibc_cmp=_dietlibc_cmp_maj*1000+_dietlibc_cmp_min
    149 
    150 	    test $_dietlibc_ver -ge $_dietlibc_cmp || use_dietlibc=detected_old
    151 	else
    152 	    ENSC_VERSION_DIETLIBC=
    153 	    _dietlibc_ver=-1
    154 	fi
    155 
    156 	ENSC_VERSION_DIETLIBC_NUM=$_dietlibc_ver
    157 	ensc_have_dietlibc=no
    158 
    159 	case x"$use_dietlibc" in
    160 	    xdetected)
    161 		AM_CONDITIONAL($1, true)
    162 		AC_MSG_RESULT([yes (autodetected, $ENSC_VERSION_DIETLIBC)])
    163 		ensc_have_dietlibc=yes
    164 		;;
    165 	    xforced)
    166 		AM_CONDITIONAL($1, true)
    167 		AC_MSG_RESULT([yes (forced)])
    168 		ensc_have_dietlibc=yes
    169 		;;
    170 	    xdetected_no)
    171 		AM_CONDITIONAL($1, false)
    172 		AC_MSG_RESULT([no (detected)])
    173 		;;
    174 	    xdetected_old)
    175 		AM_CONDITIONAL($1, false)
    176 		AC_MSG_RESULT([no (too old; $2+ required, $ENSC_VERSION_DIETLIBC found)])
    177 		;;
    178 	    xforced_no)
    179 		AM_CONDITIONAL($1, false)
    180 		AC_MSG_RESULT([no (forced)])
    181 		;;
    182 	    *)
    183 		AC_MSG_ERROR([internal error, use_dietlibc was "$use_dietlibc"])
    184 		;;
    185 	esac
    186 
    187 	if test x"$ensc_have_dietlibc" != xno; then
    188 		_ENSC_DIETLIBC_C99
    189 		_ENSC_DIETLIBC_SYSCALL
    190 		_ENSC_DIETLIBC_PIVOT_ROOT
    191 	fi
    192 ])