arsv / perl-cross

configure and cross-compile perl
Other
81 stars 29 forks source link

minor edits for darwin host support #68

Closed kiwiroy closed 6 years ago

kiwiroy commented 6 years ago

overview

motivation

When using /bin/sh, echo does not support the -n flag which results in it being printed along with the string with undesired effects. readelf needs to be replaced with gobjdump on Mac, but this doesn't support -s, but does allow --syms as readelf does. (readelf with gcc 6.4, macports barfs with "Error: Not an ELF file - it has the wrong magic bytes at the start" for try.o)

wrapper

I have a small wrapper called readelf in $PATH thus:

#!/bin/bash
exec gobjdump "$@"

And similar for objdump -> gobjdump and sed -> gsed.

arsv commented 6 years ago

#!/bin/bash has been changed to #!/bin/sh (and the code updated to run well with busybox sh and dash) some time ago to allow builds on Linux hosts that have no bash installed, and/or prefer not to use bash for this purpose. I'm pretty sure there are users who depend on this, too. Switching back to bash is not a good idea at this point.

If your build infrastructure allows it, patching that after unpacking perl-cross may be a better solution. Either sh -> bash, or maybe try to replace echo with printf if Darwin sh supports printf.

No objections to readelf changes if that's enough to get it working on Darwin. If you're ok with that, I'd apply the readelf parts of the patch only.

kiwiroy commented 6 years ago

@arsv sorry I wasn't aware /bin/sh was a fixed requirement. f3f08f6 switches to use env to achieve the same affect (untested on busybox).

arsv commented 6 years ago

Yeah but that would be a really weird thing to do in Linux. And dependency on env isn't really any better than dependency on echo -n.

Could you please check if the following fragment works correctly in Darwin? https://gist.github.com/arsv/18e6c930897275b378c427a2d6a81522

kiwiroy commented 6 years ago

That fragment works as expected.

kiwiroy commented 6 years ago

There's also the fragments here and here and the message in the latter

New applications are encouraged to use printf instead of echo.

There is also enable -n echo which will be in effect for the script and might be best in a case block. See bdbda87

case "$SHELL" in
  */bash)
    enable -n echo
    ;;
esac
arsv commented 6 years ago

Bash is not the problem, echo -n works just fine in bash. Pretty much anything would work in bash, including printf. The case should be between Darwin) and *) everything else, it's Darwin sh that needs special treatment for its lack of echo -n.

By the way, does printf work in Darwin shell?

kiwiroy commented 6 years ago

When sh is bash or is linked to bash it behaves like sh and or if certain shopt settings are set. There may be a version 3 vs 4 bash difference also, I don't have a Linux with bash v3 to confirm though. printf is available on Darwin.

arsv commented 6 years ago

Please take a look at https://github.com/arsv/perl-cross/tree/darwin and try it on Darwin is possible. I tweaked you commit a bit, if you're ok with that I'd merge it.

Only mstart actually needs no-newline printing. The other cases used echo -n > $file to truncate $file.

kiwiroy commented 6 years ago

@arsv ab8d05c is great. Thanks.

arsv commented 6 years ago

Ok, thanks, changes merged.