190 lines
5.8 KiB
Ruby
190 lines
5.8 KiB
Ruby
class MingwW64 < Formula
|
|
desc "Minimalist GNU for Windows and GCC cross-compilers"
|
|
homepage "https://sourceforge.net/projects/mingw-w64/"
|
|
url "https://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v8.0.0.tar.bz2"
|
|
sha256 "44c740ea6ab3924bc3aa169bad11ad3c5766c5c8459e3126d44eabb8735a5762"
|
|
license "ZPL-2.1"
|
|
revision 3
|
|
|
|
livecheck do
|
|
url :stable
|
|
regex(%r{url=.*?release/mingw-w64[._-]v?(\d+(?:\.\d+)+)\.t}i)
|
|
end
|
|
|
|
bottle do
|
|
sha256 big_sur: "cf32456b5f1f3e16079a9ef8767d48fc1ec3423c7f447bb6744c0fe4777e1751"
|
|
sha256 catalina: "15aa7c6ff216ed6c48da13a37ab6aa865e1d9af86ad75cf0445bf8624bd4e382"
|
|
sha256 mojave: "cd3990827011083e2c8decd8f33f409f010bd42257b5d3b67ac1df0686d18d73"
|
|
end
|
|
|
|
# Apple's makeinfo is old and has bugs
|
|
depends_on "texinfo" => :build
|
|
|
|
depends_on "gmp"
|
|
depends_on "isl"
|
|
depends_on "libmpc"
|
|
depends_on "mpfr"
|
|
|
|
resource "binutils" do
|
|
url "https://ftp.gnu.org/gnu/binutils/binutils-2.36.1.tar.xz"
|
|
mirror "https://ftpmirror.gnu.org/binutils/binutils-2.36.1.tar.xz"
|
|
sha256 "e81d9edf373f193af428a0f256674aea62a9d74dfe93f65192d4eae030b0f3b0"
|
|
end
|
|
|
|
resource "gcc" do
|
|
url "https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz"
|
|
mirror "https://ftpmirror.gnu.org/gcc/gcc-10.2.0/gcc-10.2.0.tar.xz"
|
|
sha256 "b8dd4368bb9c7f0b98188317ee0254dd8cc99d1e3a18d0ff146c855fe16c1d8c"
|
|
end
|
|
|
|
def target_archs
|
|
["i686", "x86_64"].freeze
|
|
end
|
|
|
|
def install
|
|
target_archs.each do |arch|
|
|
arch_dir = "#{prefix}/toolchain-#{arch}"
|
|
target = "#{arch}-w64-mingw32"
|
|
|
|
resource("binutils").stage do
|
|
args = %W[
|
|
--target=#{target}
|
|
--with-sysroot=#{arch_dir}
|
|
--prefix=#{arch_dir}
|
|
--enable-targets=#{target}
|
|
--disable-multilib
|
|
--disable-nls
|
|
]
|
|
mkdir "build-#{arch}" do
|
|
system "../configure", *args
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
end
|
|
|
|
# Put the newly built binutils into our PATH
|
|
ENV.prepend_path "PATH", "#{arch_dir}/bin"
|
|
|
|
mkdir "mingw-w64-headers/build-#{arch}" do
|
|
system "../configure", "--host=#{target}", "--prefix=#{arch_dir}/#{target}"
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
# Create a mingw symlink, expected by GCC
|
|
ln_s "#{arch_dir}/#{target}", "#{arch_dir}/mingw"
|
|
|
|
# Build the GCC compiler
|
|
resource("gcc").stage buildpath/"gcc"
|
|
args = %W[
|
|
--target=#{target}
|
|
--with-sysroot=#{arch_dir}
|
|
--prefix=#{arch_dir}
|
|
--with-bugurl=#{tap.issues_url}
|
|
--enable-languages=c,c++,fortran
|
|
--with-ld=#{arch_dir}/bin/#{target}-ld
|
|
--with-as=#{arch_dir}/bin/#{target}-as
|
|
--with-gmp=#{Formula["gmp"].opt_prefix}
|
|
--with-mpfr=#{Formula["mpfr"].opt_prefix}
|
|
--with-mpc=#{Formula["libmpc"].opt_prefix}
|
|
--with-isl=#{Formula["isl"].opt_prefix}
|
|
--with-zstd=no
|
|
--disable-multilib
|
|
--disable-nls
|
|
--enable-threads=posix
|
|
]
|
|
# Avoid reference to sed shim
|
|
args << "SED=/usr/bin/sed"
|
|
|
|
mkdir "#{buildpath}/gcc/build-#{arch}" do
|
|
system "../configure", *args
|
|
system "make", "all-gcc"
|
|
system "make", "install-gcc"
|
|
end
|
|
|
|
# Build the mingw-w64 runtime
|
|
args = %W[
|
|
CC=#{target}-gcc
|
|
CXX=#{target}-g++
|
|
CPP=#{target}-cpp
|
|
--host=#{target}
|
|
--with-sysroot=#{arch_dir}/#{target}
|
|
--prefix=#{arch_dir}/#{target}
|
|
]
|
|
|
|
case arch
|
|
when "i686"
|
|
args << "--enable-lib32" << "--disable-lib64"
|
|
when "x86_64"
|
|
args << "--disable-lib32" << "--enable-lib64"
|
|
end
|
|
|
|
mkdir "mingw-w64-crt/build-#{arch}" do
|
|
system "../configure", *args
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
# Build the winpthreads library
|
|
# we need to build this prior to the
|
|
# GCC runtime libraries, to have `-lpthread`
|
|
# available, for `--enable-threads=posix`
|
|
args = %W[
|
|
CC=#{target}-gcc
|
|
CXX=#{target}-g++
|
|
CPP=#{target}-cpp
|
|
--host=#{target}
|
|
--with-sysroot=#{arch_dir}/#{target}
|
|
--prefix=#{arch_dir}/#{target}
|
|
]
|
|
mkdir "mingw-w64-libraries/winpthreads/build-#{arch}" do
|
|
system "../configure", *args
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
# Finish building GCC (runtime libraries)
|
|
chdir "#{buildpath}/gcc/build-#{arch}" do
|
|
system "make"
|
|
system "make", "install"
|
|
end
|
|
|
|
# Symlinks all binaries into place
|
|
mkdir_p bin
|
|
Dir["#{arch_dir}/bin/*"].each { |f| ln_s f, bin }
|
|
end
|
|
end
|
|
|
|
test do
|
|
(testpath/"hello.c").write <<~EOS
|
|
#include <stdio.h>
|
|
#include <windows.h>
|
|
int main() { puts("Hello world!");
|
|
MessageBox(NULL, TEXT("Hello GUI!"), TEXT("HelloMsg"), 0); return 0; }
|
|
EOS
|
|
(testpath/"hello.cc").write <<~EOS
|
|
#include <iostream>
|
|
int main() { std::cout << "Hello, world!" << std::endl; return 0; }
|
|
EOS
|
|
(testpath/"hello.f90").write <<~EOS
|
|
program hello ; print *, "Hello, world!" ; end program hello
|
|
EOS
|
|
|
|
ENV["LC_ALL"] = "C"
|
|
ENV.remove_macosxsdk
|
|
target_archs.each do |arch|
|
|
target = "#{arch}-w64-mingw32"
|
|
outarch = (arch == "i686") ? "i386" : "x86-64"
|
|
|
|
system "#{bin}/#{target}-gcc", "-o", "test.exe", "hello.c"
|
|
assert_match "file format pei-#{outarch}", shell_output("#{bin}/#{target}-objdump -a test.exe")
|
|
|
|
system "#{bin}/#{target}-g++", "-o", "test.exe", "hello.cc"
|
|
assert_match "file format pei-#{outarch}", shell_output("#{bin}/#{target}-objdump -a test.exe")
|
|
|
|
system "#{bin}/#{target}-gfortran", "-o", "test.exe", "hello.f90"
|
|
assert_match "file format pei-#{outarch}", shell_output("#{bin}/#{target}-objdump -a test.exe")
|
|
end
|
|
end
|
|
end
|