[Toybox] [PATCH] toybox compiled on OS X 10.6

Rob Landley rob at landley.net
Mon Mar 12 22:10:20 PDT 2012


On 02/28/2012 06:09 AM, Georgi Chorbadzhiyski wrote:
> Apparently I have too much free time on my hands, so with the attached patches
> I'm able to compile toybox with allyesconfig on OS X 10.6.
> 
> What is needed:
>   - First install gsed (port install gsed), the sed that comes with OS X can
>     not generate needed header files. It spews lots errors:

Patch #0001:

In the short term, create a directory with a symlink from "sed" to the
gsed binary, and insert it at the start of your $PATH.

In the longer term: I plan to add sed to toybox, and the ability to
build individual commands standalone.  I'd like to make toybox build
its' own sed standalone, and use that.

(I was going to say "test the host sed to see if it's good enough"...
but why test?  Build the toybox one, use the toybox one.  No different
than building our own instlist binary during install.  (Because toybox
is a target binary so you can't do "./toybox --list" when cross
compiling, that's why.)

patch #0002:

I agree with this in principle, but look at the first hunk:

--- a/lib/lib.c
+++ b/lib/lib.c
@@ -800,7 +800,7 @@ int yesno(char *prompt, int def)
        for (i=0; i<3 && !isatty(i); i++);
        if (i == 3) return 1;

-       fdprintf(i, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ? 'n' :
'N');
+       fprintf(stderr, "%s (%c/%c):", prompt, def ? 'Y' : 'y', def ?
'n' : 'N');
        while (read(i, &buf, 1)) {

In the fdprintf, "i" can be 0, 1, or 2.  You're hardwiring it to 2,
which is not the same behavior.  (With filehandles it's easy to loop
through stdin, stdout, and stderr.  With FILE *, not so much.)

It's possible that the _correct_ behavior here is to look at the
controlling tty, ala fopen("/dev/tty"), which assumes you've got a fully
populated /dev (not always the case) but I think we can live with that.
(Sigh.  When I get back into toysh I'm going to have to refamiliarize
myself with all the controlling terminal details.  getsid(), getpgrp(),
tcgetpgrp(), and so on...)

Still, it's not quite the drop-in replacement you're making it, code
that uses thsi stuff has to change from file descripter to FILE *, which
impacts get_line() as well.  A later hunk breaks patch (TT.fileout is
never actually stdout, it's the new file we're creating with patches
applied).

patch #0003:

Um, Aboriginal Linux is using gcc 4.2.1 (and binutils 2.17) for the same
reason Apple is: that was the last GPLv2 release.  It supports
--ffunction-sections and such just fine.

I suspect the problem here is that Mac's binutils doesn't produce ELF
output files, it produces mach-o format, and _that_ may not support
these flags.

I'm uncomfortable special casing Linux, since it's the common case.
Lemme get back to this one, I need to think about the right way to do it.

patch #0004:

I don't want to sprinkle #ifdef linux into toys/*.c.

If we can add some kidn of portability/apple directory with alternate
implementations of stuff, or put really clever macros into
lib/portability.h, I'm all for it.  If we can't,

More to the point: I'm all for making commands work on the macintosh,
but this doesn't.  This stubs them out.  I'd much rather just disable
them in the config (the way unshare vanishes on systems that don't
support it: you can't select it, the option goes away when the build
environment can't compile it) than produce a misleading NOP command.

patch #0005:

This looks promising.  I think everything this patch does can be cleaned
up to fit in portability.h or similar.  (I won't get to it tonight, but
hopefully tomorrow...)

patch 0006:

Actually, those variants of getline() and getdelim() are posix-2008:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html

Possibly it needs another header or #define
_YES_I_REALLY_MEANT_TO_INCLUDE_THAT somewhere?

> What I'm going to do with this patches? Depends on what Rob thinks. Currently they
> are just a quick hack. I'm certainly not any kind of OS X (or BSD) expert or have
> much interest in these OSes. I can probably clean the patches some more and if they
> are applied do some kind of testing from time to time, compiling toybox on OS X.

I'm all for getting it working.

0005 I can do now (well, tomorrow), 0004 should be a
scripts/genconfig.sh thing (again, easy-ish).

0006 if you could investigate why posix-2008 functions don't work on
macosx that would be nice. It seems like they _should_, I'd like to
understand why they don't before trying to replace them.

0001: I need to do sed, let's revisit that once I've added sed to toybox.

0002: I need to translate a lot of the fd stuff to FILE * stuff in
general, although only two of these look like they actually break stuff
(and you noted that in your message).

0003: I need to think about that some more.  After some sleep.

Thanks,

Rob



More information about the Toybox mailing list