nixpkgs/pkgs/development/tools/simavr/setup-hook-darwin.sh
Thomas Watson 6e13168f47 simavr: fix build on Darwin
Remove unnecessary compiler flag not recognized by Clang.

Borrow setup hook from Wine which filters out Darwin-specific flags not
recognized by avr-gcc, which is used to build the test firmware.
2023-01-08 23:01:27 -06:00

35 lines
1.7 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

fixupCFlagsForDarwin() {
# Because its getting called from a Darwin stdenv, avr-gcc will pick up on
# Darwin-specific flags, and it will barf and die on -iframework in
# particular. Strip them out, so simavr can compile its test firmware.
cflagsFilter='s|-F[^ ]*||g;s|-iframework [^ ]*||g;s|-isystem [^ ]*||g;s| *| |g'
# The `CoreFoundation` reference is added by `linkSystemCoreFoundationFramework` in the
# Apple SDKs setup hook. Remove that because avr-gcc will fail due to file not found.
ldFlagsFilter='s|/nix/store/[^-]*-apple-framework-CoreFoundation[^ ]*||g'
# `cc-wrapper.sh`` supports getting flags from a system-specific salt. While it is currently a
# tuple, thats not considered a stable interface, so the derivation will provide them.
export NIX_CFLAGS_COMPILE_@darwinSuffixSalt@=${NIX_CFLAGS_COMPILE-}
export NIX_LDFLAGS_@darwinSuffixSalt@=${NIX_LDFLAGS-}
echo removing @darwinSuffixSalt@-specific flags from NIX_CFLAGS_COMPILE for @avrSuffixSalt@
export NIX_CFLAGS_COMPILE_@avrSuffixSalt@+="$(sed "$cflagsFilter" <<< "$NIX_CFLAGS_COMPILE")"
echo removing @darwinSuffixSalt@-specific flags from NIX_LDFLAGS for @avrSuffixSalt@
export NIX_LDFLAGS_@avrSuffixSalt@+="$(sed "$ldFlagsFilter;$cflagsFilter" <<< "$NIX_LDFLAGS")"
# Make sure the global flags arent accidentally influencing the platform-specific flags.
export NIX_CFLAGS_COMPILE=""
export NIX_LDFLAGS=""
}
# This is pretty hacky, but this hook _must_ run after `linkSystemCoreFoundationFramework`.
function runFixupCFlagsForDarwinLast() {
preConfigureHooks+=(fixupCFlagsForDarwin)
}
if [ -z "${dontFixupCFlagsForDarwin-}" ]; then
postUnpackHooks+=(runFixupCFlagsForDarwinLast)
fi