forked from FiloSottile/homebrew-musl-cross
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusl-cross.rb
134 lines (111 loc) · 5.38 KB
/
musl-cross.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
class MuslCross < Formula
desc "Linux cross compilers based on musl libc"
homepage "https://github.com/richfelker/musl-cross-make"
url "https://api.github.com/repos/lemonrock/musl-cross-make/tarball/41f51cb4c5fdd25ff4bf6d52030fd8c5452c14e4"
sha256 "4934df0af0f84acd00295ec396b53a6dfa7ef0c5b178e9f253a1f8ac13a4f400"
head "https://github.com/lemonrock/musl-cross-make.git"
option "with-aarch64", "Build cross-compilers targeting arm-linux-muslaarch64"
option "with-arm-hf", "Build cross-compilers targeting arm-linux-musleabihf"
option "with-arm", "Build cross-compilers targeting arm-linux-musleabi"
option "with-i486", "Build cross-compilers targeting i486-linux-musl"
option "with-mips", "Build cross-compilers targeting mips-linux-musl"
option "with-mipsel", "Build cross-compilers targeting mipsel-linux-musl"
option "with-mips64", "Build cross-compilers targeting mips64-linux-musl"
option "with-mips64el", "Build cross-compilers targeting mips64el-linux-musl"
option "without-x86_64", "Do not build cross-compilers targeting x86_64-linux-musl"
depends_on "gnu-sed" => :build
depends_on "make" => :build
resource "linux-5.8.5.tar.xz" do
url "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.8.5.tar.xz"
sha256 "9d4ec36b158734f86e583a56f5a03721807d606ea1df6a97e6dd993ea605947f"
end
resource "mpfr-4.0.2.tar.bz2" do
url "https://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.bz2"
sha256 "c05e3f02d09e0e9019384cdd58e0f19c64e6db1fd6f5ecf77b4b1c61ca253acc"
end
resource "mpc-1.1.0.tar.gz" do
url "https://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz"
sha256 "6985c538143c1208dcb1ac42cedad6ff52e267b47e5f970183a3e75125b43c2e"
end
resource "gmp-6.1.2.tar.bz2" do
url "https://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.bz2"
sha256 "5275bb04f4863a13516b2f39392ac5e272f5e1bb8057b18aec1c9b79d73d8fb2"
end
resource "musl-1.2.2.tar.gz" do
url "https://www.musl-libc.org/releases/musl-1.2.2.tar.gz"
sha256 "9b969322012d796dc23dda27a35866034fa67d8fb67e0e2c45c913c3d43219dd"
end
resource "binutils-2.33.1.tar.bz2" do
url "https://ftp.gnu.org/gnu/binutils/binutils-2.33.1.tar.bz2"
sha256 "0cb4843da15a65a953907c96bad658283f3c4419d6bcc56bf2789db16306adb2"
end
resource "config.sub" do
url "https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=3d5db9ebe860"
sha256 "75d5d255a2a273b6e651f82eecfabf6cbcd8eaeae70e86b417384c8f4a58d8d3"
end
resource "gcc-9.2.0.tar.xz" do
url "https://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.xz"
sha256 "ea6ef08f121239da5695f76c9b33637a118dcf63e24164422231917fa61fb206"
end
resource "isl-0.21.tar.bz2" do
url "http://isl.gforge.inria.fr/isl-0.21.tar.bz2"
sha256 "d18ca11f8ad1a39ab6d03d3dcb3365ab416720fcb65b42d69f34f51bf0a0e859"
end
def install
targets = []
targets.push "x86_64-linux-musl" if build.with? "x86_64"
targets.push "aarch64-linux-musl" if build.with? "aarch64"
targets.push "arm-linux-musleabihf" if build.with? "arm-hf"
targets.push "arm-linux-musleabi" if build.with? "arm"
targets.push "i486-linux-musl" if build.with? "i486"
targets.push "mips-linux-musl" if build.with? "mips"
targets.push "mipsel-linux-musl" if build.with? "mipsel"
targets.push "mips64-linux-musl" if build.with? "mips64"
targets.push "mips64el-linux-musl" if build.with? "mips64el"
(buildpath/"resources").mkpath
resources.each do |resource|
cp resource.fetch, buildpath/"resources"/resource.name
end
(buildpath/"config.mak").write <<~EOS
# Force version overrides
MUSL_VER = 1.2.2
LINUX_VER = 5.8.5
SOURCES = #{buildpath/"resources"}
OUTPUT = #{libexec}
# Drop some features for faster and smaller builds
#COMMON_CONFIG += --disable-nls
#GCC_CONFIG += --disable-libquadmath --disable-decimal-float
#GCC_CONFIG += --disable-libitm --disable-fixed-point
# Keep the local build path out of binaries and libraries
COMMON_CONFIG += --with-debug-prefix-map=#{buildpath}=
# https://llvm.org/bugs/show_bug.cgi?id=19650
# https://github.com/richfelker/musl-cross-make/issues/11
ifeq ($(shell $(CXX) -v 2>&1 | grep -c "clang"), 1)
TOOLCHAIN_CONFIG += CXX="$(CXX) -fbracket-depth=512"
endif
EOS
ENV.prepend_path "PATH", "#{Formula["gnu-sed"].opt_libexec}/gnubin"
targets.each do |target|
system Formula["make"].opt_bin/"gmake", "install", "TARGET=#{target}"
end
bin.install_symlink Dir["#{libexec}/bin/*"]
end
test do
(testpath/"hello.c").write <<~EOS
#include <stdio.h>
int main()
{
printf("Hello, world!");
}
EOS
system "#{bin}/x86_64-linux-musl-cc", (testpath/"hello.c") if build.with? "x86_64"
system "#{bin}/i486-linux-musl-cc", (testpath/"hello.c") if build.with? "i486"
system "#{bin}/aarch64-linux-musl-cc", (testpath/"hello.c") if build.with? "aarch64"
system "#{bin}/arm-linux-musleabihf-cc", (testpath/"hello.c") if build.with? "arm-hf"
system "#{bin}/arm-linux-musleabi-cc", (testpath/"hello.c") if build.with? "arm"
system "#{bin}/mips-linux-musl-cc", (testpath/"hello.c") if build.with? "mips"
system "#{bin}/mipsel-linux-musl-cc", (testpath/"hello.c") if build.with? "mipsel"
system "#{bin}/mips64-linux-musl-cc", (testpath/"hello.c") if build.with? "mips64"
system "#{bin}/mips64el-linux-musl-cc", (testpath/"hello.c") if build.with? "mips64el"
end
end