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