1#!/usr/bin/m4
2#
3# Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
4# Copyright (c) 2015 Elvira Khabirova <lineprinter0@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
29AC_DEFUN([st_MPERS_LOAD_AC_CV], [
30
31pushdef([var], [ac_cv_$1])
32pushdef([saved], [saved_ac_cv_$1])
33pushdef([mpers], [ac_cv_]mpers_name[_$1])
34
35AS_IF([test -n "${var+set}"], [saved="${var}"; unset var])
36AS_IF([test -n "${mpers+set}"], [var="${mpers}"])
37
38popdef([mpers])
39popdef([saved])
40popdef([var])
41
42])
43
44AC_DEFUN([st_MPERS_SAVE_AC_CV], [
45
46pushdef([var], [ac_cv_$1])
47pushdef([saved], [saved_ac_cv_$1])
48pushdef([mpers], [ac_cv_]mpers_name[_$1])
49
50AS_IF([test -n "${var+set}"], [mpers="${var}"])
51AS_IF([test -n "${saved+set}"], [var="${saved}"; unset saved])
52
53popdef([mpers])
54popdef([saved])
55popdef([var])
56
57])
58
59AC_DEFUN([st_MPERS_STRUCT_STAT], [
60
61st_MPERS_LOAD_AC_CV([type_struct_stat$1])
62AC_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>])
67st_MPERS_SAVE_AC_CV([type_struct_stat$1])
68
69st_MPERS_LOAD_AC_CV([member_struct_stat$1_st_mtime_nsec])
70AC_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>])
75st_MPERS_SAVE_AC_CV([member_struct_stat$1_st_mtime_nsec])
76
77])
78
79AC_DEFUN([st_MPERS],[
80
81pushdef([mpers_name], [$1])
82pushdef([MPERS_NAME], translit([$1], [a-z], [A-Z]))
83pushdef([HAVE_MPERS], [HAVE_]MPERS_NAME[_MPERS])
84pushdef([HAVE_RUNTIME], [HAVE_]MPERS_NAME[_RUNTIME])
85pushdef([CFLAG], [-$1])
86pushdef([st_cv_cc], [st_cv_$1_cc])
87pushdef([st_cv_runtime], [st_cv_$1_runtime])
88pushdef([st_cv_mpers], [st_cv_$1_mpers])
89
90case "$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	;;
138esac
139
140AM_CONDITIONAL(HAVE_RUNTIME, [test "$st_cv_mpers$st_cv_runtime" = yesyes])
141AM_CONDITIONAL(HAVE_MPERS, [test "$st_cv_mpers" = yes])
142
143popdef([st_cv_mpers])
144popdef([st_cv_runtime])
145popdef([st_cv_cc])
146popdef([CFLAG])
147popdef([HAVE_RUNTIME])
148popdef([HAVE_MPERS])
149popdef([MPERS_NAME])
150popdef([mpers_name])
151
152])
153