Hey,

When compiling the cross compiler for android, it fails because of
undefined symbols to mkfifo, tcgetattr and tcsetattr.
This seems to be because the android ndk defines them as inline.

This patch wraps them (when compiling for android) in __mkfifo
__tcgetattr and __tcsetattr.
>From e51180acf208554dbe06d465f79a196f49e99269 Mon Sep 17 00:00:00 2001
From: Nathan <nathan.hues...@posteo.de>
Date: Thu, 24 Jan 2013 15:32:26 +0100
Subject: [PATCH] Wrap mkfifo, tcsetattr and tcgetattr on android because they
 are inline and cause linker failer

---
 System/Posix/Internals.hs |   13 +++++++++++++
 include/HsBase.h          |    7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/System/Posix/Internals.hs b/System/Posix/Internals.hs
index 1633a3e..cf7b6b7 100644
--- a/System/Posix/Internals.hs
+++ b/System/Posix/Internals.hs
@@ -488,8 +488,13 @@ foreign import ccall unsafe "HsBase.h fork"
 foreign import ccall unsafe "HsBase.h link"
    c_link :: CString -> CString -> IO CInt
 
+#ifndef linux_android_HOST_OS 
 foreign import ccall unsafe "HsBase.h mkfifo"
    c_mkfifo :: CString -> CMode -> IO CInt
+#else
+foreign import ccall unsafe "HsBase.h __mkfifo"
+   c_mkfifo :: CString -> CMode -> IO CInt
+#endif
 
 foreign import ccall unsafe "HsBase.h pipe"
    c_pipe :: Ptr CInt -> IO CInt
@@ -503,11 +508,19 @@ foreign import capi unsafe "signal.h sigaddset"
 foreign import capi unsafe "signal.h sigprocmask"
    c_sigprocmask :: CInt -> Ptr CSigset -> Ptr CSigset -> IO CInt
 
+#ifndef linux_android_HOST_OS 
 foreign import ccall unsafe "HsBase.h tcgetattr"
    c_tcgetattr :: CInt -> Ptr CTermios -> IO CInt
 
 foreign import ccall unsafe "HsBase.h tcsetattr"
    c_tcsetattr :: CInt -> CInt -> Ptr CTermios -> IO CInt
+#else
+foreign import ccall unsafe "HsBase.h __tcgetattr"
+   c_tcgetattr :: CInt -> Ptr CTermios -> IO CInt
+
+foreign import ccall unsafe "HsBase.h __tcsetattr"
+   c_tcsetattr :: CInt -> CInt -> Ptr CTermios -> IO CInt
+#endif
 
 foreign import capi unsafe "HsBase.h utime"
    c_utime :: CString -> Ptr CUtimbuf -> IO CInt
diff --git a/include/HsBase.h b/include/HsBase.h
index b1a62fd..698a9ab 100644
--- a/include/HsBase.h
+++ b/include/HsBase.h
@@ -175,6 +175,13 @@ extern int fdReady(int fd, int write, int msecs, int isSock);
 # endif
 #endif
 
+#ifdef linux_android_HOST_OS
+// On android these functions are inline, so need to wrap them to be able to link them
+INLINE int __mkfifo(const char *__p, mode_t __m) {return mkfifo(__p,__m);}
+INLINE int __tcgetattr(int fd, struct termios *s) {return tcgetattr(fd,s);}
+INLINE int __tcsetattr(int fd, int __opt, const struct termios *s) {return tcsetattr(fd,__opt,s);}
+#endif
+
 INLINE int __hscore_get_errno(void) { return errno; }
 INLINE void __hscore_set_errno(int e) { errno = e; }
 
-- 
1.7.10.4

_______________________________________________
ghc-devs mailing list
ghc-devs@haskell.org
http://www.haskell.org/mailman/listinfo/ghc-devs

Reply via email to