So here's what I had to do to build and run toybox with the Android NDK:

1) I don't remember which NDK version I have installed and ls -l
/opt/android/x86-64 is unenlightening (NOTICE is 2400 lines of concatenated help
text starting with GPLv2, everything starting with "COPYING" is some variant of
GPL (yet MORE license text), repo.prop is a bunch of git hashes,
manifest_4639204.xml is not close enough to human readable to matter) but the
start of llvm-cc --version is "Android (4639204 based on r316199) clang version
6.0.1" which presumably means something to somebody. It's recent-ish. January 
maybe?

2) I applied the attached patch, some bits of which should get merged and others
I dunno about. (The structure ping wanted... did that git fixed upstream 
already?)

3) "LDFLAGS=--static CROSS_COMPILE=/opt/android/x86-64/bin/llvm- defconfig" and
then switch OFF CONFIG_LOG and CONFIG_GETCONF. The first I vaguely remember
talking about on here and the android guys intentionally don't export the log
functions in the NDK (but you can call the command line utility...?), the second
is missing posix stuff. (Is that fixed upstream or should I try to hack around
it here, or...?)

4) Build, with the same LDFLAGS and CROSS_COMPILE and run the result under
qemu-x86_64 -cpu Nehalem.f (The default cpu qemu emulates has the same immediate
segfault in the start code my netbook does, but if you have it fake an i7 it 
works.)

But hey, I have some sort of test environment now. :)

Rob
diff --git a/lib/lsm.h b/lib/lsm.h
index e21d424..ada54c9 100644
--- a/lib/lsm.h
+++ b/lib/lsm.h
@@ -55,7 +55,7 @@ static inline char *lsm_name(void)
 static inline char *lsm_context(void)
 {
   int ok = 0;
-  char *result;
+  char *result = 0;
 
   if (CFG_TOYBOX_SMACK) ok = smack_new_label_from_self(&result) > 0;
   else ok = getcon(&result) == 0;
diff --git a/lib/portability.h b/lib/portability.h
index 39e6181..de2fb5e 100644
--- a/lib/portability.h
+++ b/lib/portability.h
@@ -256,3 +256,18 @@ extern CODE prioritynames[], facilitynames[];
 #include <sys/random.h>
 #endif
 void xgetrandom(void *buf, unsigned len, unsigned flags);
+
+// Android NDK missing struct icmphdr, work around for now
+struct my_icmphdr {
+  char type, code;
+  unsigned short checksum;
+  union {
+    struct {
+      unsigned short id, sequence;
+    } echo;
+    unsigned gateway;
+    struct {
+      unsigned short unused, mtu;
+    } frag;
+  } un;
+};
diff --git a/toys/net/ftpget.c b/toys/net/ftpget.c
index f41e05b..9d6f6fd 100644
--- a/toys/net/ftpget.c
+++ b/toys/net/ftpget.c
@@ -93,7 +93,7 @@ static int ftp_line(char *cmd, char *arg, int must)
 void ftpget_main(void)
 {
   struct sockaddr_in6 si6;
-  int rc, ii = 1, port;
+  int rc, ii = 1, port = 0;
   socklen_t sl = sizeof(si6);
   char *s, *remote = toys.optargs[2];
   unsigned long long lenl = 0, lenr;
diff --git a/toys/net/ping.c b/toys/net/ping.c
index b21abb7..ae8278e 100644
--- a/toys/net/ping.c
+++ b/toys/net/ping.c
@@ -10,7 +10,7 @@
  *
  * Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint...
 
-// -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes
+// -s > 4088 = sizeof(toybuf)-sizeof(struct my_icmphdr), then kernel adds 20 bytes
 USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i:W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN))
 USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
  
@@ -112,7 +112,7 @@ void ping_main(void)
   int family = 0, len;
   long long tnext, tW, tnow, tw;
   unsigned short seq = 0, pkttime;
-  struct icmphdr *ih = (void *)toybuf;
+  struct my_icmphdr *ih = (void *)toybuf;
 
   // Interval
   if (TT.i) {
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to