]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - sim/m4/sim_ac_platform.m4
sim: formally assume unistd.h always exists (via gnulib)
[thirdparty/binutils-gdb.git] / sim / m4 / sim_ac_platform.m4
1 dnl Copyright (C) 1997-2023 Free Software Foundation, Inc.
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; either version 3 of the License, or
6 dnl (at your option) any later version.
7 dnl
8 dnl This program is distributed in the hope that it will be useful,
9 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 dnl GNU General Public License for more details.
12 dnl
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program. If not, see <http://www.gnu.org/licenses/>.
15 dnl
16 dnl Check for various platform settings.
17 AC_DEFUN([SIM_AC_PLATFORM],
18 [dnl
19 dnl Check for common headers.
20 dnl NB: You can assume C11 headers exist.
21 dnl NB: We use gnulib from ../gnulib/, so we don't probe headers it provides.
22 AC_CHECK_HEADERS_ONCE(m4_flatten([
23 dlfcn.h
24 fcntl.h
25 fpu_control.h
26 termios.h
27 utime.h
28 linux/if_tun.h
29 linux/mii.h
30 linux/types.h
31 net/if.h
32 netinet/in.h
33 netinet/tcp.h
34 sys/ioctl.h
35 sys/mman.h
36 sys/mount.h
37 sys/param.h
38 sys/resource.h
39 sys/socket.h
40 sys/stat.h
41 sys/statfs.h
42 sys/termio.h
43 sys/termios.h
44 sys/types.h
45 sys/vfs.h
46 ]))
47 AC_HEADER_DIRENT
48
49 dnl NB: We use gnulib from ../gnulib/, so we don't probe functions it provides.
50 AC_CHECK_FUNCS_ONCE(m4_flatten([
51 __setfpucw
52 access
53 aint
54 anint
55 cfgetispeed
56 cfgetospeed
57 cfsetispeed
58 cfsetospeed
59 chdir
60 chmod
61 dup
62 dup2
63 execv
64 execve
65 fcntl
66 fork
67 fstat
68 fstatfs
69 ftruncate
70 getdirentries
71 getegid
72 geteuid
73 getgid
74 getpid
75 getppid
76 getrusage
77 gettimeofday
78 getuid
79 ioctl
80 kill
81 link
82 lseek
83 lstat
84 mkdir
85 mmap
86 munmap
87 pipe
88 posix_fallocate
89 pread
90 rmdir
91 setregid
92 setreuid
93 setgid
94 setuid
95 sigaction
96 sigprocmask
97 sqrt
98 stat
99 strsignal
100 symlink
101 tcdrain
102 tcflow
103 tcflush
104 tcgetattr
105 tcgetpgrp
106 tcsendbreak
107 tcsetattr
108 tcsetpgrp
109 time
110 truncate
111 umask
112 unlink
113 utime
114 ]))
115
116 AC_STRUCT_ST_BLKSIZE
117 AC_STRUCT_ST_BLOCKS
118 AC_STRUCT_ST_RDEV
119 AC_STRUCT_TIMEZONE
120
121 AC_CHECK_MEMBERS([[struct stat.st_dev], [struct stat.st_ino],
122 [struct stat.st_mode], [struct stat.st_nlink], [struct stat.st_uid],
123 [struct stat.st_gid], [struct stat.st_rdev], [struct stat.st_size],
124 [struct stat.st_blksize], [struct stat.st_blocks], [struct stat.st_atime],
125 [struct stat.st_mtime], [struct stat.st_ctime]], [], [],
126 [[#ifdef HAVE_SYS_TYPES_H
127 #include <sys/types.h>
128 #endif
129 #ifdef HAVE_SYS_STAT_H
130 #include <sys/stat.h>
131 #endif]])
132
133 AC_CHECK_TYPES([__int128])
134 AC_CHECK_TYPES(socklen_t, [], [],
135 [#include <sys/types.h>
136 #include <sys/socket.h>
137 ])
138
139 dnl Types used by common code
140 AC_TYPE_GETGROUPS
141 AC_TYPE_MODE_T
142 AC_TYPE_OFF_T
143 AC_TYPE_PID_T
144 AC_TYPE_SIGNAL
145 AC_TYPE_SIZE_T
146 AC_TYPE_UID_T
147
148 LT_INIT
149
150 dnl Libraries.
151 AC_SEARCH_LIBS([bind], [socket])
152 AC_SEARCH_LIBS([gethostbyname], [nsl])
153 AC_SEARCH_LIBS([fabs], [m])
154 AC_SEARCH_LIBS([log2], [m])
155
156 AC_SEARCH_LIBS([dlopen], [dl])
157 if test "${ac_cv_lib_dl_dlopen}" = "yes"; then
158 PKG_CHECK_MODULES(SDL, sdl2, [dnl
159 SDL_CFLAGS="${SDL_CFLAGS} -DHAVE_SDL=2"
160 ], [
161 PKG_CHECK_MODULES(SDL, sdl, [dnl
162 SDL_CFLAGS="${SDL_CFLAGS} -DHAVE_SDL=1"
163 ], [:])
164 ])
165 dnl If we use SDL, we need dlopen support.
166 AS_IF([test -n "$SDL_CFLAGS"], [dnl
167 AS_IF([test "$ac_cv_search_dlopen" = no], [dnl
168 AC_MSG_WARN([SDL support requires dlopen support])
169 ])
170 ])
171 else
172 SDL_CFLAGS=
173 fi
174 dnl We dlopen the libs at runtime, so never pass down SDL_LIBS.
175 SDL_LIBS=
176 AC_SUBST(SDL_CFLAGS)
177
178 dnl In the Cygwin environment, we need some additional flags.
179 AC_CACHE_CHECK([for cygwin], sim_cv_os_cygwin,
180 [AC_EGREP_CPP(lose, [
181 #ifdef __CYGWIN__
182 lose
183 #endif],[sim_cv_os_cygwin=yes],[sim_cv_os_cygwin=no])])
184
185 dnl Keep in sync with gdb's configure.ac list.
186 AC_SEARCH_LIBS(tgetent, [termcap tinfo curses ncurses],
187 [TERMCAP_LIB=$ac_cv_search_tgetent], [TERMCAP_LIB=""])
188 if test x$sim_cv_os_cygwin = xyes; then
189 TERMCAP_LIB="${TERMCAP_LIB} -luser32"
190 fi
191 AC_SUBST(TERMCAP_LIB)
192
193 dnl We prefer the in-tree readline. Top-level dependencies make sure
194 dnl src/readline (if it's there) is configured before src/sim.
195 if test -r ../readline/Makefile; then
196 READLINE_LIB=../readline/readline/libreadline.a
197 READLINE_CFLAGS='-I$(READLINE_SRC)/..'
198 else
199 AC_CHECK_LIB(readline, readline, READLINE_LIB=-lreadline,
200 AC_ERROR([the required "readline" library is missing]), $TERMCAP_LIB)
201 READLINE_CFLAGS=
202 fi
203 AC_SUBST(READLINE_LIB)
204 AC_SUBST(READLINE_CFLAGS)
205
206 dnl Determine whether we have a known getopt prototype in unistd.h
207 dnl to make sure that we have correct getopt declaration on
208 dnl include/getopt.h. The purpose of this is to sync with other Binutils
209 dnl components and this logic is copied from ld/configure.ac.
210 AC_MSG_CHECKING(for a known getopt prototype in unistd.h)
211 AC_CACHE_VAL(sim_cv_decl_getopt_unistd_h,
212 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>], [extern int getopt (int, char *const*, const char *);])],
213 sim_cv_decl_getopt_unistd_h=yes, sim_cv_decl_getopt_unistd_h=no)])
214 AC_MSG_RESULT($sim_cv_decl_getopt_unistd_h)
215 if test $sim_cv_decl_getopt_unistd_h = yes; then
216 AC_DEFINE([HAVE_DECL_GETOPT], 1,
217 [Is the prototype for getopt in <unistd.h> in the expected format?])
218 fi
219 ])