Home | History | Annotate | Download | only in m4
      1 #!/usr/bin/m4
      2 #
      3 # Copyright (c) 2015-2016 Dmitry V. Levin <ldv (at] altlinux.org>
      4 # Copyright (c) 2015 Elvira Khabirova <lineprinter0 (at] gmail.com>
      5 # All rights reserved.
      6 #
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 # 3. The name of the author may not be used to endorse or promote products
     16 #    derived from this software without specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 
     29 AC_DEFUN([st_MPERS_LOAD_AC_CV], [
     30 
     31 pushdef([var], [ac_cv_$1])
     32 pushdef([saved], [saved_ac_cv_$1])
     33 pushdef([mpers], [ac_cv_]mpers_name[_$1])
     34 
     35 AS_IF([test -n "${var+set}"], [saved="${var}"; unset var])
     36 AS_IF([test -n "${mpers+set}"], [var="${mpers}"])
     37 
     38 popdef([mpers])
     39 popdef([saved])
     40 popdef([var])
     41 
     42 ])
     43 
     44 AC_DEFUN([st_MPERS_SAVE_AC_CV], [
     45 
     46 pushdef([var], [ac_cv_$1])
     47 pushdef([saved], [saved_ac_cv_$1])
     48 pushdef([mpers], [ac_cv_]mpers_name[_$1])
     49 
     50 AS_IF([test -n "${var+set}"], [mpers="${var}"])
     51 AS_IF([test -n "${saved+set}"], [var="${saved}"; unset saved])
     52 
     53 popdef([mpers])
     54 popdef([saved])
     55 popdef([var])
     56 
     57 ])
     58 
     59 AC_DEFUN([st_MPERS_STRUCT_STAT], [
     60 
     61 st_MPERS_LOAD_AC_CV([type_struct_stat$1])
     62 AC_CHECK_TYPE([struct stat$1],
     63 	      AC_DEFINE([HAVE_]MPERS_NAME[_STRUCT_STAT$1], [1],
     64 			[Define to 1 if MPERS_NAME has the type 'struct stat$1'.]),,
     65 [#include <sys/types.h>
     66 #include <asm/stat.h>])
     67 st_MPERS_SAVE_AC_CV([type_struct_stat$1])
     68 
     69 st_MPERS_LOAD_AC_CV([member_struct_stat$1_st_mtime_nsec])
     70 AC_CHECK_MEMBER([struct stat$1.st_mtime_nsec],
     71 		AC_DEFINE([HAVE_]MPERS_NAME[_STRUCT_STAT$1_ST_MTIME_NSEC], [1],
     72 			  [Define to 1 if 'st_mtime_nsec' is a member of MPERS_NAME 'struct stat$1'.]),,
     73 [#include <sys/types.h>
     74 #include <asm/stat.h>])
     75 st_MPERS_SAVE_AC_CV([member_struct_stat$1_st_mtime_nsec])
     76 
     77 ])
     78 
     79 AC_DEFUN([st_MPERS],[
     80 
     81 pushdef([mpers_name], [$1])
     82 pushdef([MPERS_NAME], translit([$1], [a-z], [A-Z]))
     83 pushdef([HAVE_MPERS], [HAVE_]MPERS_NAME[_MPERS])
     84 pushdef([HAVE_RUNTIME], [HAVE_]MPERS_NAME[_RUNTIME])
     85 pushdef([CFLAG], [-$1])
     86 pushdef([st_cv_cc], [st_cv_$1_cc])
     87 pushdef([st_cv_runtime], [st_cv_$1_runtime])
     88 pushdef([st_cv_mpers], [st_cv_$1_mpers])
     89 
     90 case "$arch" in
     91 	[$2])
     92 	AH_TEMPLATE([HAVE_GNU_STUBS_32_H],
     93 		    [Define to 1 if you have the <gnu/stubs-32.h> header file.])
     94 	AH_TEMPLATE([HAVE_GNU_STUBS_X32_H],
     95 		    [Define to 1 if you have the <gnu/stubs-x32.h> header file.])
     96 	pushdef([gnu_stubs], [gnu/stubs-][m4_substr([$1], 1)][.h])
     97 	AC_CHECK_HEADERS([gnu_stubs], [IFLAG=],
     98 			 [mkdir -p gnu
     99 			  : > gnu_stubs
    100 			  AC_MSG_NOTICE([Created empty gnu_stubs])
    101 			  IFLAG=-I.])
    102 	popdef([gnu_stubs])
    103 	saved_CFLAGS="$CFLAGS"
    104 	CFLAGS="$CFLAGS CFLAG $IFLAG"
    105 	AC_CACHE_CHECK([for CFLAG compile support], [st_cv_cc],
    106 		[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#include <stdint.h>
    107 						     int main(){return 0;}]])],
    108 				   [st_cv_cc=yes],
    109 				   [st_cv_cc=no])])
    110 	if test $st_cv_cc = yes; then
    111 		AC_CACHE_CHECK([for CFLAG runtime support], [st_cv_runtime],
    112 			[AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdint.h>
    113 							 int main(){return 0;}]])],
    114 				       [st_cv_runtime=yes],
    115 				       [st_cv_runtime=no],
    116 				       [st_cv_runtime=no])])
    117 		AC_CACHE_CHECK([whether mpers.sh CFLAG works], [st_cv_mpers],
    118 			[if CC="$CC" CPP="$CPP" CPPFLAGS="$CPPFLAGS" \
    119 			    $srcdir/mpers_test.sh [$1]; then
    120 				st_cv_mpers=yes
    121 			 else
    122 				st_cv_mpers=no
    123 			 fi])
    124 		if test $st_cv_mpers = yes; then
    125 			AC_DEFINE(HAVE_MPERS, [1],
    126 				  [Define to 1 if you have CFLAG mpers support])
    127 			st_MPERS_STRUCT_STAT([])
    128 			st_MPERS_STRUCT_STAT([64])
    129 		fi
    130 	fi
    131 	CFLAGS="$saved_CFLAGS"
    132 	;;
    133 
    134 	*)
    135 	st_cv_runtime=no
    136 	st_cv_mpers=no
    137 	;;
    138 esac
    139 
    140 AM_CONDITIONAL(HAVE_RUNTIME, [test "$st_cv_mpers$st_cv_runtime" = yesyes])
    141 AM_CONDITIONAL(HAVE_MPERS, [test "$st_cv_mpers" = yes])
    142 
    143 popdef([st_cv_mpers])
    144 popdef([st_cv_runtime])
    145 popdef([st_cv_cc])
    146 popdef([CFLAG])
    147 popdef([HAVE_RUNTIME])
    148 popdef([HAVE_MPERS])
    149 popdef([MPERS_NAME])
    150 popdef([mpers_name])
    151 
    152 ])
    153