@@ -124,6 +124,22 @@ stdenv.mkDerivation (rec {
124124 export NIX_LDFLAGS+=" -no_dtrace_dof"
125125 '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
126126 sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
127+ '' + stdenv.lib.optionalString targetPlatform.isMusl ''
128+ echo "patching llvm-targets for musl targets..."
129+ echo "Cloning these existing '*-linux-gnu*' targets:"
130+ grep linux-gnu llvm-targets | sed 's/^/ /'
131+ echo "(go go gadget sed)"
132+ sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
133+ echo "llvm-targets now contains these '*-linux-musl*' targets:"
134+ grep linux-musl llvm-targets | sed 's/^/ /'
135+
136+ echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
137+ # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
138+ for x in configure aclocal.m4; do
139+ substituteInPlace $x \
140+ --replace '*-android*|*-gnueabi*)' \
141+ '*-android*|*-gnueabi*|*-musleabi*)'
142+ done
127143 '';
128144
129145 # TODO(@Ericson2314): Always pass "--target" and always prefix.