Skip to content

Commit 2199809

Browse files
committed
configure: use AC_CHECK_DECLS instead of AC_EGREP_CPP
1 parent 71f3739 commit 2199809

File tree

8 files changed

+45
-121
lines changed

8 files changed

+45
-121
lines changed

System/Posix/DynamicLinker/Prim.hsc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,16 @@ import GHC.IO.Exception ( unsupportedOperation )
6060

6161
haveRtldNext :: Bool
6262

63-
#ifdef HAVE_RTLDNEXT
63+
#ifdef HAVE_DECL_RTLD_NEXT
6464
haveRtldNext = True
6565
foreign import ccall unsafe "__hsunix_rtldNext" rtldNext :: Ptr a
66-
#else /* HAVE_RTLDNEXT */
66+
#else /* HAVE_DECL_RTLD_NEXT */
6767
haveRtldNext = False
68-
#endif /* HAVE_RTLDNEXT */
68+
#endif /* HAVE_DECL_RTLD_NEXT */
6969

70-
#ifdef HAVE_RTLDDEFAULT
70+
#ifdef HAVE_DECL_RTLD_DEFAULT
7171
foreign import ccall unsafe "__hsunix_rtldDefault" rtldDefault :: Ptr a
72-
#endif /* HAVE_RTLDDEFAULT */
72+
#endif /* HAVE_DECL_RTLD_DEFAULT */
7373

7474
haveRtldLocal :: Bool
7575
haveRtldLocal = True
@@ -128,13 +128,13 @@ data DL = Null | Next | Default | DLHandle (Ptr ()) deriving (Show)
128128
packDL :: DL -> Ptr ()
129129
packDL Null = nullPtr
130130

131-
#ifdef HAVE_RTLDNEXT
131+
#ifdef HAVE_DECL_RTLD_NEXT
132132
packDL Next = rtldNext
133133
#else
134134
packDL Next = error "RTLD_NEXT not available"
135135
#endif
136136

137-
#ifdef HAVE_RTLDDEFAULT
137+
#ifdef HAVE_DECL_RTLD_DEFAULT
138138
packDL Default = rtldDefault
139139
#else
140140
packDL Default = nullPtr

System/Posix/Fcntl.hsc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ module System.Posix.Fcntl (
3030
import Foreign.C
3131
import System.Posix.Types
3232

33-
#if !HAVE_POSIX_FALLOCATE || !HAVE_O_DIRECT
33+
#if !HAVE_POSIX_FALLOCATE || !HAVE_DECL_O_DIRECT
3434
import System.IO.Error ( ioeSetLocation )
3535
import GHC.IO.Exception ( unsupportedOperation )
3636
#endif
3737

38-
#if HAVE_O_DIRECT
38+
#if HAVE_DECL_O_DIRECT
3939
import Data.Bits (complement, (.&.), (.|.))
4040
import System.Posix.Internals (c_fcntl_read)
4141
#endif
4242

43-
#if HAVE_O_DIRECT || HAVE_F_NOCACHE
43+
#if HAVE_DECL_O_DIRECT || HAVE_DECL_F_NOCACHE
4444
import System.Posix.Internals (c_fcntl_write)
4545
#endif
4646

@@ -128,20 +128,20 @@ fileAllocate _ _ _ = ioError (ioeSetLocation unsupportedOperation
128128
-- Throws 'IOError' (\"unsupported operation\") if platform does not support
129129
-- getting the cache mode.
130130
--
131-
-- Use @#if HAVE_O_DIRECT@ CPP guard to detect availability. Use @#include
132-
-- "HsUnix.h"@ to bring @HAVE_O_DIRECT@ into scope.
131+
-- Use @#if HAVE_DECL_O_DIRECT@ CPP guard to detect availability. Use @#include
132+
-- "HsUnix.h"@ to bring @HAVE_DECL_O_DIRECT@ into scope.
133133
--
134134
-- @since 2.8.7.0
135135
fileGetCaching :: Fd -> IO Bool
136-
#if HAVE_O_DIRECT
136+
#if HAVE_DECL_O_DIRECT
137137
fileGetCaching (Fd fd) = do
138138
r <- throwErrnoIfMinus1 "fileGetCaching" (c_fcntl_read fd #{const F_GETFL})
139139
return ((r .&. opt_val) == 0)
140140
where
141141
opt_val = #{const O_DIRECT}
142142
#else
143143
{-# WARNING fileGetCaching
144-
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_O_DIRECT@)" #-}
144+
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_DECL_O_DIRECT@)" #-}
145145
fileGetCaching _ = ioError (ioeSetLocation unsupportedOperation "fileGetCaching")
146146
#endif
147147

@@ -158,25 +158,25 @@ fileGetCaching _ = ioError (ioeSetLocation unsupportedOperation "fileGetCaching"
158158
-- Throws 'IOError' (\"unsupported operation\") if platform does not support
159159
-- setting the cache mode.
160160
--
161-
-- Use @#if HAVE_O_DIRECT || HAVE_F_NOCACHE@ CPP guard to detect availability.
162-
-- Use @#include "HsUnix.h"@ to bring @HAVE_O_DIRECT@ and @HAVE_F_NOCACHE@ into
161+
-- Use @#if HAVE_DECL_O_DIRECT || HAVE_DECL_F_NOCACHE@ CPP guard to detect availability.
162+
-- Use @#include "HsUnix.h"@ to bring @HAVE_DECL_O_DIRECT@ and @HAVE_DECL_F_NOCACHE@ into
163163
-- scope.
164164
--
165165
-- @since 2.8.7.0
166166
fileSetCaching :: Fd -> Bool -> IO ()
167-
#if HAVE_O_DIRECT
167+
#if HAVE_DECL_O_DIRECT
168168
fileSetCaching (Fd fd) val = do
169169
r <- throwErrnoIfMinus1 "fileSetCaching" (c_fcntl_read fd #{const F_GETFL})
170170
let r' | val = fromIntegral r .&. complement opt_val
171171
| otherwise = fromIntegral r .|. opt_val
172172
throwErrnoIfMinus1_ "fileSetCaching" (c_fcntl_write fd #{const F_SETFL} r')
173173
where
174174
opt_val = #{const O_DIRECT}
175-
#elif HAVE_F_NOCACHE
175+
#elif HAVE_DECL_F_NOCACHE
176176
fileSetCaching (Fd fd) val = do
177177
throwErrnoIfMinus1_ "fileSetCaching" (c_fcntl_write fd #{const F_NOCACHE} (if val then 0 else 1))
178178
#else
179179
{-# WARNING fileSetCaching
180-
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_O_DIRECT || HAVE_F_NOCACHE @)" #-}
180+
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_DECL_O_DIRECT || HAVE_DECL_F_NOCACHE @)" #-}
181181
fileSetCaching _ _ = ioError (ioeSetLocation unsupportedOperation "fileSetCaching")
182182
#endif

System/Posix/IO/Common.hsc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,21 +371,21 @@ data LockRequest = ReadLock
371371

372372
type FileLock = (LockRequest, SeekMode, FileOffset, FileOffset)
373373

374-
#if !defined(HAVE_F_GETLK)
374+
#if !defined(HAVE_DECL_F_GETLK)
375375

376376
getLock :: Fd -> FileLock -> IO (Maybe (ProcessID, FileLock))
377377
{-# WARNING getLock
378-
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_F_GETLK@)" #-}
378+
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_DECL_F_GETLK@)" #-}
379379
getLock _ _ = ioError (ioeSetLocation unsupportedOperation "getLock")
380380

381381
setLock :: Fd -> FileLock -> IO ()
382382
{-# WARNING setLock
383-
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_F_GETLK@)" #-}
383+
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_DECL_F_GETLK@)" #-}
384384
setLock _ _ = ioError (ioeSetLocation unsupportedOperation "setLock")
385385

386386
waitToSetLock :: Fd -> FileLock -> IO ()
387387
{-# WARNING waitToSetLock
388-
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_F_GETLK@)" #-}
388+
"operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_DECL_F_GETLK@)" #-}
389389
waitToSetLock _ _ = ioError (ioeSetLocation unsupportedOperation "waitToSetLock")
390390

391391
#else
@@ -449,7 +449,7 @@ waitToSetLock (Fd fd) lock = do
449449
throwErrnoIfMinus1_ "waitToSetLock"
450450
(Base.c_fcntl_lock fd (#const F_SETLKW) p_flock)
451451

452-
#endif // HAVE_F_GETLK
452+
#endif // HAVE_DECL_F_GETLK
453453

454454
-- -----------------------------------------------------------------------------
455455
-- fd{Read,Write}Buf

System/Posix/User.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ getAllGroupEntries = error "System.Posix.User.getAllGroupEntries: not supported"
493493

494494
#if defined(HAVE_GETGRGID_R) || defined(HAVE_GETGRNAM_R)
495495
grBufSize :: Int
496-
#if defined(HAVE_SYSCONF) && defined(HAVE_SC_GETGR_R_SIZE_MAX)
496+
#if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_GETGR_R_SIZE_MAX)
497497
grBufSize = sysconfWithDefault 1024 (#const _SC_GETGR_R_SIZE_MAX)
498498
#else
499499
grBufSize = 1024
@@ -615,7 +615,7 @@ getAllUserEntries = error "System.Posix.User.getAllUserEntries: not supported"
615615

616616
#if defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWNAM_R)
617617
pwBufSize :: Int
618-
#if defined(HAVE_SYSCONF) && defined(HAVE_SC_GETPW_R_SIZE_MAX)
618+
#if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_GETPW_R_SIZE_MAX)
619619
pwBufSize = sysconfWithDefault 1024 (#const _SC_GETPW_R_SIZE_MAX)
620620
#else
621621
pwBufSize = 1024

System/Posix/User/ByteString.hsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ getAllGroupEntries = error "System.Posix.User.getAllGroupEntries: not supported"
456456

457457
#if defined(HAVE_GETGRGID_R) || defined(HAVE_GETGRNAM_R)
458458
grBufSize :: Int
459-
#if defined(HAVE_SYSCONF) && defined(HAVE_SC_GETGR_R_SIZE_MAX)
459+
#if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_GETGR_R_SIZE_MAX)
460460
grBufSize = sysconfWithDefault 1024 (#const _SC_GETGR_R_SIZE_MAX)
461461
#else
462462
grBufSize = 1024
@@ -532,7 +532,7 @@ getAllUserEntries = error "System.Posix.User.getAllUserEntries: not supported"
532532

533533
#if defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWNAM_R)
534534
pwBufSize :: Int
535-
#if defined(HAVE_SYSCONF) && defined(HAVE_SC_GETPW_R_SIZE_MAX)
535+
#if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_GETPW_R_SIZE_MAX)
536536
pwBufSize = sysconfWithDefault 1024 (#const _SC_GETPW_R_SIZE_MAX)
537537
#else
538538
pwBufSize = 1024

cbits/HsUnix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
char **__hsunix_get_environ (void) {return environ;}
1212

13-
#ifdef HAVE_RTLDNEXT
13+
#ifdef HAVE_DECL_RTLD_NEXT
1414
void *__hsunix_rtldNext (void) {return RTLD_NEXT;}
1515
#endif
1616

17-
#ifdef HAVE_RTLDDEFAULT
17+
#ifdef HAVE_DECL_RTLD_DEFAULT
1818
void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;}
1919
#endif
2020

configure.ac

Lines changed: 13 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -105,48 +105,11 @@ AC_MSG_RESULT(no)
105105
]
106106
)
107107

108-
109-
AC_MSG_CHECKING(for F_GETLK from fcntl.h)
110-
AC_EGREP_CPP(yes,
111-
[
112-
#include <fcntl.h>
113-
#ifdef F_GETLK
114-
yes
115-
#endif
116-
], [
117-
AC_MSG_RESULT(yes)
118-
AC_DEFINE([HAVE_F_GETLK], [1], [Define to 1 if F_GETLK is available.])
119-
], [
120-
AC_MSG_RESULT(no)
121-
])
122-
123-
AC_MSG_CHECKING(for O_DIRECT open flag)
124-
AC_EGREP_CPP(yes,
125-
[
126-
#include <fcntl.h>
127-
#ifdef O_DIRECT
128-
yes
129-
#endif
130-
], [
131-
AC_MSG_RESULT(yes)
132-
AC_DEFINE([HAVE_O_DIRECT], [1], [Define to 1 if O_DIRECT open flag is available.])
133-
], [
134-
AC_MSG_RESULT(no)
135-
])
136-
137-
AC_MSG_CHECKING(for F_NOCACHE from fcntl.h)
138-
AC_EGREP_CPP(yes,
139-
[
140-
#include <fcntl.h>
141-
#ifdef F_NOCACHE
142-
yes
143-
#endif
144-
], [
145-
AC_MSG_RESULT(yes)
146-
AC_DEFINE([HAVE_F_NOCACHE], [1], [Define to 1 if F_NOCACHE available.])
147-
], [
148-
AC_MSG_RESULT(no)
149-
])
108+
AC_CHECK_DECLS([F_GETLK, O_DIRECT, F_NOCACHE], [], [], [AC_INCLUDES_DEFAULT
109+
#ifdef HAVE_FCNTL_H
110+
#include <fcntl.h>
111+
#endif
112+
])
150113

151114
dnl not available on android so check for it
152115
AC_CANONICAL_TARGET
@@ -232,29 +195,11 @@ FP_CHECK_CONSTS([SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIG
232195
#include <signal.h>
233196
#endif])
234197

235-
AC_MSG_CHECKING([for _SC_GETGR_R_SIZE_MAX])
236-
AC_EGREP_CPP(we_have_that_sysconf_thing,
237-
[
238-
#include <unistd.h>
239-
#ifdef _SC_GETGR_R_SIZE_MAX
240-
we_have_that_sysconf_thing
241-
#endif
242-
],
243-
[AC_MSG_RESULT([yes])
244-
AC_DEFINE([HAVE_SC_GETGR_R_SIZE_MAX], [1], [Define to 1 if <unistd.h> defines _SC_GETGR_R_SIZE_MAX.])],
245-
[AC_MSG_RESULT([no])])
246-
247-
AC_MSG_CHECKING([for _SC_GETPW_R_SIZE_MAX])
248-
AC_EGREP_CPP(we_have_that_sysconf_thing,
249-
[
198+
AC_CHECK_DECLS([_SC_GETGR_R_SIZE_MAX, _SC_GETPW_R_SIZE_MAX], [], [], [AC_INCLUDES_DEFAULT
199+
#ifdef HAVE_UNISTD_H
250200
#include <unistd.h>
251-
#ifdef _SC_GETPW_R_SIZE_MAX
252-
we_have_that_sysconf_thing
253201
#endif
254-
],
255-
[AC_MSG_RESULT([yes])
256-
AC_DEFINE([HAVE_SC_GETPW_R_SIZE_MAX], [1], [Define to 1 if <unistd.h> defines _SC_GETPW_R_SIZE_MAX.])],
257-
[AC_MSG_RESULT([no])])
202+
])
258203

259204
dnl ---------- usleep ----------
260205
dnl --- stolen from guile configure ---
@@ -288,33 +233,12 @@ esac
288233
dnl On some hosts (e.g. SuSe and Ubuntu Linux) RTLD_NEXT and RTLD_DEFAULT are
289234
dnl not visible without setting _GNU_SOURCE, which we really don't want to.
290235
dnl Also see comments in System/Posix/DynamicLinker/Prim.hsc.
291-
AC_MSG_CHECKING(for RTLD_NEXT from dlfcn.h)
292-
AC_EGREP_CPP(yes,
293-
[
294-
#include <dlfcn.h>
295-
#ifdef RTLD_NEXT
296-
yes
297-
#endif
298-
], [
299-
AC_MSG_RESULT(yes)
300-
AC_DEFINE([HAVE_RTLDNEXT], [1], [Define to 1 if we can see RTLD_NEXT in dlfcn.h.])
301-
], [
302-
AC_MSG_RESULT(no)
303-
])
304236

305-
AC_MSG_CHECKING(for RTLD_DEFAULT from dlfcn.h)
306-
AC_EGREP_CPP(yes,
307-
[
308-
#include <dlfcn.h>
309-
#ifdef RTLD_DEFAULT
310-
yes
311-
#endif
312-
], [
313-
AC_MSG_RESULT(yes)
314-
AC_DEFINE([HAVE_RTLDDEFAULT], [1], [Define to 1 if RTLD_DEFAULT is available.])
315-
], [
316-
AC_MSG_RESULT(no)
317-
])
237+
AC_CHECK_DECLS([RTLD_NEXT, RTLD_DEFAULT], [], [], [AC_INCLUDES_DEFAULT
238+
#ifdef HAVE_DLFCN_H
239+
#include <dlfcn.h>
240+
#endif
241+
])
318242

319243
AC_CHECK_FUNCS(openpty,,
320244
AC_CHECK_LIB(util,openpty,

include/HsUnix.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ extern HsInt nocldstop;
100100
/* defined in libc */
101101
extern char **environ;
102102

103-
#ifdef HAVE_RTLDNEXT
103+
#ifdef HAVE_DECL_RTLD_NEXT
104104
void *__hsunix_rtldNext (void);
105105
#endif
106106

107-
#ifdef HAVE_RTLDDEFAULT
107+
#ifdef HAVE_DECL_RTLD_DEFAULT
108108
void *__hsunix_rtldDefault (void);
109109
#endif
110110

0 commit comments

Comments
 (0)