gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH] Various fixes to build for android


From: Samuel CUELLA
Subject: [gpsd-dev] [PATCH] Various fixes to build for android
Date: Tue, 8 Jul 2014 23:07:03 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

Hi list,

I had to build gpsd for an android device that didn't come with default
gps support. In the process, I've found various issues which the
following patch aims to fix. Here is a summary of what it does:

-Feature selection
--SHM_EXPORT_ENABLE guard was placed *after* the inclusion of sys/shm in
shmexport.c and libgps_shm.c. That made the build to fail even if shm
was disabled. The patch moves the guard upwards to exclude the whole
content if shm support is disabled.

-Undefined Symbols
--in_port_t and SUN_LEN are not defined on Android. Patch adds checks to
SConstruct, and fallbacks to generated gpsd_config.h
--getsid syscall wrapped is not included in some versions of bionic as
well. Patch also adds a check and a fallback declaration modeled on
fallbacks for strl* functions [1]. An implementation is provided in
missing-support.h [2]
--fd_set is defined by sys/select.h. Reported undefined during the
build. Moved include from gpsd.c to gpsd.h-head to fix the problem.

-Library symbols and linking
--By default, gpsd doesn't explicitly links libgps (Tried imloads with
no luck as well).  This results in unix_to_iso8601 being UND. Android
Linker fails to link gpsd binary because of this. Patched SContruct to
explicitly link libgpsd against libgps.
--Moved gpsd_write and gpsd_report from gpsd.c to libgpsd_core.c. The
library libgpsd uses these symbols from gpsd whereas it should be the
other way around if libgpsd was to be used by another binary. These
symbols are marked UND which makes the android linker to fail loading
gpsd binary.

[1] I would also suggest to add a dependency on libstrl
(http://ohnopub.net/~ohnobinki/libstrl/).
[2] I would also suggest to remove the conditionals declarations of
strl* from the generated gpsd_config.h, and have an separate include
which would be guarded by HAVE_STRL*s. Theses declartions use size_t
which is not declared, therefore including gpsd_config.h without
including stdlib.h beforehand can lead to compile errors if any of the
HAVE_STRL* is false. Same  problem for the getsid declaration I've added
(uses pid_t). I'd suggest to have only HAVE_* in gpsd_config.h and
various support includes guarded by these macros. Those includes would
also in turn all other needed includes. I'll happily take care of that
if you agree on it.

This is my first patch. I've done the "scons testregress" as requested
on http://www.catb.org/gpsd/hacking.html#contribution.

Signed-off-by: Samuel CUELLA <address@hidden>
---
diff -Nur gpsd-3.10/SConstruct gpsd-3.10-patched/SConstruct
--- gpsd-3.10/SConstruct    2013-11-22 14:10:01.000000000 +0100
+++ gpsd-3.10-patched/SConstruct    2014-07-06 14:40:16.268521314 +0200
@@ -591,6 +591,18 @@
         announce("You do not have kernel PPS available.")
         # Don't turn off PPS here, we might be using the non-kernel version
 
+    #in_port_t is not defined on Android
+    if not config.CheckType("in_port_t","#include <netinet/in.h>"):
+        announce("Did not find in_port_t typedef, assuming unsigned
short int")
+        confdefs.append("typedef unsigned short int in_port_t;\n")
+
+    #SUN_LEN is not defined on Android
+    if not config.CheckDeclaration("SUN_LEN", "#include <sys/un.h>")
and not config.CheckDeclaration("SUN_LEN", "#include <linux/un.h>"):
+        announce("SUN_LEN is not system-defined, using local definition")
+        confdefs.append("#ifndef SUN_LEN\n")
+        confdefs.append("#define SUN_LEN(ptr) ((size_t) (((struct
sockaddr_un *) 0)->sun_path) + strlen((ptr)->sun_path))\n")
+        confdefs.append("#endif /* SUN_LEN */\n")
+
     if config.CheckHeader(["bits/sockaddr.h", "linux/can.h"]):
         confdefs.append("#define HAVE_LINUX_CAN_H 1\n")
         announce("You have kernel CANbus available.")
@@ -631,7 +643,7 @@
 
     # check function after libraries, because some function require library
     # for example clock_gettime() require librt on Linux
-    for f in ("daemon", "strlcpy", "strlcat", "clock_gettime"):
+    for f in ("daemon", "strlcpy", "strlcat", "clock_gettime","getsid"):
         if config.CheckFunc(f):
             confdefs.append("#define HAVE_%s 1\n" % f.upper())
         else:
@@ -697,6 +709,17 @@
 }
 # endif
 #endif
+#ifndef HAVE_GETSID
+# ifdef __cplusplus
+extern "C" {
+# endif
+#include <unistd.h>
+pid_t getsid(pid_t pid);
+# ifdef __cplusplus
+}
+# endif
+#endif
+
 
 #define GPSD_CONFIG_H
 ''')
@@ -781,6 +804,7 @@
     "rtcm3_json.c",
     "shared_json.c",
     "strl.c",
+    "missing-support.c",
 ]
 
 if env['libgpsmm']:
@@ -922,11 +946,13 @@
                           parse_flags=dbus_libs + rtlibs)
 env.Clean(compiled_gpslib, "gps_maskdump.c")
 
+#Added -lgps because it exports unix_to_iso8601. Was UND in readelf.
Android cannot look it up if not explicitly linked.
 compiled_gpsdlib = Library(env=env,
                            target="gpsd",
                            sources=libgpsd_sources,
                            version=libgpsd_version,
-                           parse_flags=usblibs + rtlibs + bluezlibs)
+                           parse_flags=usblibs + rtlibs + bluezlibs +
["-lgps"])
+
 
 libraries = [compiled_gpslib, compiled_gpsdlib]
 
diff -Nur gpsd-3.10/gpsd.c gpsd-3.10-patched/gpsd.c
--- gpsd-3.10/gpsd.c    2013-11-21 09:57:44.000000000 +0100
+++ gpsd-3.10-patched/gpsd.c    2014-07-06 13:28:25.581412319 +0200
@@ -9,7 +9,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/time.h>        /* for select() */
-#include <sys/select.h>
 #include <stdio.h>
 #include <time.h>
 #include <string.h>
@@ -162,25 +161,6 @@
     signalled = (sig_atomic_t) sig;
 }
 
-ssize_t gpsd_write(struct gps_device_t *session,
-           const char *buf,
-           const size_t len)
-/* pass low-level data to devices straight through */
-{
-    return gpsd_serial_write(session, buf, len);
-}
-
-void gpsd_report(const int debuglevel, const int errlevel,
-         const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start(ap, fmt);
-    gpsd_labeled_report(debuglevel, errlevel, "gpsd:", fmt, ap);
-    va_end(ap);
-           
-}
-
 static void typelist(void)
 /* list installed drivers and enabled features */
 {
diff -Nur gpsd-3.10/gpsd.h-head gpsd-3.10-patched/gpsd.h-head
--- gpsd-3.10/gpsd.h-head    2013-11-21 09:57:44.000000000 +0100
+++ gpsd-3.10-patched/gpsd.h-head    2014-07-06 13:28:25.582412306 +0200
@@ -9,6 +9,7 @@
 
 #include <stdbool.h>
 #include <stdio.h>
+#include <sys/select.h> /*fd_set*/
 
 #ifndef GPSD_CONFIG_H
 /* Feature configuration switches begin here */
diff -Nur gpsd-3.10/libgps_shm.c gpsd-3.10-patched/libgps_shm.c
--- gpsd-3.10/libgps_shm.c    2013-11-21 09:57:44.000000000 +0100
+++ gpsd-3.10-patched/libgps_shm.c    2014-07-06 13:58:53.876555484 +0200
@@ -14,6 +14,9 @@
    BSD terms apply: see the file COPYING in the distribution root for
details.
 
 ***************************************************************************/
+#include "gpsd.h" /*could be gpsd_config.h first if size_t mentions are
offloaded to another file*/
+#ifdef SHM_EXPORT_ENABLE
+
 #include <stddef.h>
 #include <string.h>
 #include <errno.h>
@@ -22,11 +25,8 @@
 #include <sys/ipc.h>
 #include <sys/shm.h>
 
-#include "gpsd.h"
 #include "libgps.h"
 
-#ifdef SHM_EXPORT_ENABLE
-
 /address@hidden@*/
 struct privdata_t
 {
diff -Nur gpsd-3.10/libgpsd_core.c gpsd-3.10-patched/libgpsd_core.c
--- gpsd-3.10/libgpsd_core.c    2013-11-21 09:57:44.000000000 +0100
+++ gpsd-3.10-patched/libgpsd_core.c    2014-07-06 13:28:25.582412306 +0200
@@ -75,6 +75,28 @@
 }
 
 
+/*Moved here form gpsd.c -> libgpsd uses that symbol without having it
because it was defined in gpsd.c*/
+ssize_t gpsd_write(struct gps_device_t *session,
+           const char *buf,
+           const size_t len)
+/* pass low-level data to devices straight through */
+{
+    return gpsd_serial_write(session, buf, len);
+}
+
+
+/*Moved here form gpsd.c -> libgpsd uses that symbol without having it
because it was defined in gpsd.c*/
+void gpsd_report(const int debuglevel, const int errlevel,
+         const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    gpsd_labeled_report(debuglevel, errlevel, "gpsd:", fmt, ap);
+    va_end(ap);
+           
+}
+
 void gpsd_labeled_report(const int debuglevel, const int errlevel,
              const char *label, const char *fmt, va_list ap)
 /* assemble command in printf(3) style, use stderr or syslog */
diff -Nur gpsd-3.10/missing-support.c gpsd-3.10-patched/missing-support.c
--- gpsd-3.10/missing-support.c    1970-01-01 01:00:00.000000000 +0100
+++ gpsd-3.10-patched/missing-support.c    2014-07-06 13:28:25.582412306
+0200
@@ -0,0 +1,16 @@
+/*
+ * This file is Copyright (c) 2010 by the GPSD project
+ * BSD terms apply: see the file COPYING in the distribution root for
details.
+ */
+#include "string.h" /*gpsd_config.h is likely to mention size_t*/
+#include "gpsd_config.h"
+
+
+#ifndef HAVE_GETSID
+#include <unistd.h>
+#include <sys/syscall.h>
+
+pid_t getsid(pid_t pid) {
+  return syscall(__NR_getsid, pid);
+}
+#endif /* HAVE_GETSID */
diff -Nur gpsd-3.10/shmexport.c gpsd-3.10-patched/shmexport.c
--- gpsd-3.10/shmexport.c    2013-11-21 09:57:44.000000000 +0100
+++ gpsd-3.10-patched/shmexport.c    2014-07-06 13:58:58.531497290 +0200
@@ -14,6 +14,9 @@
    BSD terms apply: see the file COPYING in the distribution root for
details.
 
 ***************************************************************************/
+#include "gpsd.h" /*could be gpsd_config.h first if size_t mentions are
offloaded to another file*/
+#ifdef SHM_EXPORT_ENABLE
+
 #include <stddef.h>
 #include <string.h>
 #include <errno.h>
@@ -21,11 +24,8 @@
 #include <sys/ipc.h>
 #include <sys/shm.h>
 
-#include "gpsd.h"
 #include "libgps.h" /* for SHM_PSEUDO_FD */
 
-#ifdef SHM_EXPORT_ENABLE
-
 /*@ -mustfreeonly -nullstate -mayaliasunique @*/
 
 bool shm_acquire(struct gps_context_t *context)

---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]