On 12/18/2016 12:52 PM, enh wrote: > for configure-like usage you'll need to generate a standalone toolchain: > > https://developer.android.com/ndk/guides/standalone_toolchain.html > > (you'll also want to use --unified-headers when you generate your > standalone toolchain to get headers new enough to have any chance of > being useful.)
I did that and got further. Starting with: $ CROSS_COMPILE=/opt/android/x86_64/bin/x86_64-linux-android- \ LDFLAGS=--static make defconfig (Yes you have to run the config stage with the same CROSS_COMPILE and LDFLAGS you're going to build with, or else it'll make a generated/Config.probed that thinks TOYBOX_SHADOW should be switched on when your toolchain hasn't got it, and so on.) Then I did: $ CROSS_COMPILE=/opt/android/x86_64/bin/x86_64-linux-android- \ LDFLAGS=--static make And it went: In file included from ./toys.h:9:0, from lib/args.c:12: ./lib/portability.h:274:33: fatal error: cutils/sched_policy.h: No such file or directory #include <cutils/sched_policy.h> ^ I can add another compile-time probe for this, but I'm wondering if there's a way to figure it out from the #defines? You added it in commit e0dbc6beaf37: +#ifdef __ANDROID__ +#include <cutils/sched_policy.h> +#else +typedef int SchedPolicy; +int get_sched_policy(int tid, SchedPolicy *policy); +const char *get_sched_policy_name(SchedPolicy policy); +#endif So presumably you understand when it is/isn't there? Anyway, when I #if 0'd that out, it got further but then died with: toys/android/getprop.c:20:31: fatal error: cutils/properties.h: No such file or directory #include <cutils/properties.h> I'm guessing that was the libselinux thing you were talking about, maybe? Anyway, I can switch that app off. Then it died with: In file included from ./toys.h:9:0, from toys/android/log.c:22: ./lib/portability.h:13:18: error: expected ')' before '__attribute__' #define noreturn __attribute__((noreturn)) In file included from toys/android/log.c:23:0: /opt/android/x86_64/sysroot/usr/include/android/log.h:119:30: error: expected ',' or ';' before ')' token __attribute__ ((noreturn)) Which is really _weird_ but it seems like android/log.h #defining noreturn reaches back in time and breaks the earlier #define of noreturn? Or something? (gcc is weird.) Anyway, switching off the "log" command as well... And in addition to getprop, I have to switch off setprop, start, and stop because they all #include <cutils/properties.h> which isn't there. Then it made it through several commands, but the "eject" command died because: toys/other/eject.c:25:21: fatal error: scsi/sg.h: No such file or directory #include <scsi/sg.h> Which is a linux-kernel header, but I can't say I'm hugely surprised. Switch that off... And it's doing pretty well through the rest of the commands. Lots of warnings about implicit declarations (gethostid, crypt) wandering by. I wonder if I can -Werror just _that_ error? (That's going to come back and bite me at link time, I just know it...) Yes. Yes it is: generated/obj/lib_lib.o:lib.c:function verror_msg: error: undefined reference to 'stderr' generated/obj/lib_lib.o:lib.c:function help_exit: error: undefined reference to 'stderr' generated/obj/lib_lib.o:lib.c:function mkpathat: error: undefined reference to 'stderr' generated/obj/lib_lib.o:lib.c:function yesno: error: undefined reference to 'stderr' generated/obj/lib_lib.o:lib.c:function yesno: error: undefined reference to 'stdin' generated/obj/lib_lib.o:lib.c:function bufgetgrgid: error: undefined reference to 'getgrgid_r' generated/obj/lib_lib.o:lib.c:function do_lines: error: undefined reference to 'stdin' generated/obj/lib_linestack.o:linestack.c:function draw_trim_esc: error: undefined reference to 'stdout' generated/obj/lib_xwrap.o:xwrap.c:function xexit: error: undefined reference to 'stdout' generated/obj/lib_xwrap.o:xwrap.c:function xprintf: error: undefined reference to 'stdout' generated/obj/lib_xwrap.o:xwrap.c:function xputs: error: undefined reference to 'stdout' generated/obj/hostname.o:hostname.c:function hostname_main: error: undefined reference to 'sethostname' generated/obj/md5sum.o:md5sum.c:function looplines: error: undefined reference to 'stdin' generated/obj/md5sum.o:md5sum.c:function looplines: error: undefined reference to 'stdin' generated/obj/hostid.o:hostid.c:function hostid_main: error: undefined reference to 'gethostid' generated/obj/mkpasswd.o:mkpasswd.c:function mkpasswd_main: error: undefined reference to 'crypt' collect2: error: ld returned 1 exit status So it couldn't find stderr, stdin, stdout, getgrid_r, gethostid, and crypt. Well that's a _manageable_ list, but the stdin/stdout/stderr stuff I can't easily patch around, that's posix: http://pubs.opengroup.org/onlinepubs/9699919799/functions/stdout.html I'm assuming that AOSP had stdin/stdout/stderr. You can't error_exit() without verror_msg(), it's in pretty much every command. (I think if you build "false" standalone, it might get omitted... "make false", "objdump -d generated/unstripped/false | less"... Nope, it's still there. Probably shouldn't be. I'll throw it on the todo heap.) * I don't see a strong reason _not_ to have a gethostid(), but I could stub it out (or just do the syscall, or read /proc/sys/kernel/hostname) if you have one. I can also probe/stub out getgrid_r() and crypt() which both fall under "do we have /etc/passwd or similar on this system". It would be nice if there was some sort of plan for setting up a "posix container" under android that understood 2 users (root and not root) so we can run AOSP builds as "not root", but that's a todo item. In the meantime consistent stubs would be nice. :) Rob * Ah, it's because everything except true and false has --help output, and: ./echo --help > /dev/full echo: write: No space left on device That's why error_exit doesn't drop out. But I should probably let it do so when you've disabled CONFIG_TOYBOX_HELP_DASHDASH. _______________________________________________ Toybox mailing list Toybox@lists.landley.net http://lists.landley.net/listinfo.cgi/toybox-landley.net