2017-02-07 12:24:21 +00:00
|
|
|
class MingwW64 < Formula
|
|
|
|
desc "Minimalist GNU for Windows and GCC cross-compilers"
|
|
|
|
homepage "https://mingw-w64.org/"
|
|
|
|
url "https://downloads.sourceforge.net/project/mingw-w64/mingw-w64/mingw-w64-release/mingw-w64-v5.0.1.tar.bz2"
|
|
|
|
sha256 "9bb5cd7df78817377841a63555e73596dc0af4acbb71b09bd48de7cf24aeadd2"
|
|
|
|
|
2017-02-11 19:31:02 +00:00
|
|
|
bottle do
|
|
|
|
sha256 "99d147a5ad2241d17eebf18ccc5a6614175d7b71f2046c091408d1b63578c261" => :sierra
|
|
|
|
sha256 "f060770a90c6e41d00a471f6ac3dfa6a5bb7429c988d2304c1c0c7634ebc4ec1" => :el_capitan
|
|
|
|
sha256 "16dbc5c0951a5a57f89554a7af90d1889d41bd92ea3c4d7ea1d9bb0d7550bf2c" => :yosemite
|
|
|
|
end
|
|
|
|
|
2017-02-07 12:24:21 +00:00
|
|
|
depends_on "gmp"
|
|
|
|
depends_on "mpfr"
|
|
|
|
depends_on "libmpc"
|
|
|
|
depends_on "isl"
|
|
|
|
|
|
|
|
# Apple's makeinfo is old and has bugs
|
|
|
|
depends_on "texinfo" => :build
|
|
|
|
|
|
|
|
resource "binutils" do
|
|
|
|
url "https://ftpmirror.gnu.org/binutils/binutils-2.27.tar.gz"
|
|
|
|
sha256 "26253bf0f360ceeba1d9ab6965c57c6a48a01a8343382130d1ed47c468a3094f"
|
|
|
|
end
|
|
|
|
|
|
|
|
resource "gcc" do
|
|
|
|
url "https://ftpmirror.gnu.org/gcc/gcc-6.3.0/gcc-6.3.0.tar.bz2"
|
|
|
|
sha256 "f06ae7f3f790fbf0f018f6d40e844451e6bc3b7bc96e128e63b09825c1f8b29f"
|
|
|
|
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}
|
|
|
|
--prefix=#{arch_dir}
|
|
|
|
--enable-targets=#{target}
|
|
|
|
--disable-multilib
|
|
|
|
]
|
|
|
|
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}
|
|
|
|
--prefix=#{arch_dir}
|
|
|
|
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
|
|
|
|
--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}
|
|
|
|
--disable-multilib
|
|
|
|
]
|
|
|
|
|
|
|
|
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
|
|
|
|
LD=#{target}-gcc
|
|
|
|
--host=#{target}
|
|
|
|
--prefix=#{arch_dir}/#{target}
|
|
|
|
]
|
|
|
|
|
|
|
|
if arch == "i686"
|
|
|
|
args << "--enable-lib32" << "--disable-lib64"
|
|
|
|
elsif arch == "x86_64"
|
|
|
|
args << "--disable-lib32" << "--enable-lib64"
|
|
|
|
end
|
|
|
|
|
|
|
|
mkdir "mingw-w64-crt/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
|
|
|
|
|
|
|
|
# Build the winpthreads library
|
|
|
|
args = %W[
|
|
|
|
CC=#{target}-gcc
|
|
|
|
CXX=#{target}-g++
|
|
|
|
CPP=#{target}-cpp
|
|
|
|
--host=#{target}
|
|
|
|
--prefix=#{arch_dir}/#{target}
|
|
|
|
]
|
|
|
|
mkdir "mingw-w64-libraries/winpthreads/build-#{arch}" do
|
|
|
|
system "../configure", *args
|
|
|
|
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.undent
|
|
|
|
#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.undent
|
|
|
|
#include <iostream>
|
|
|
|
int main() { std::cout << "Hello, world!" << std::endl; return 0; }
|
|
|
|
EOS
|
|
|
|
(testpath/"hello.f90").write <<-EOS.undent
|
|
|
|
program hello ; print *, "Hello, world!" ; end program hello
|
|
|
|
EOS
|
|
|
|
|
|
|
|
ENV["LC_ALL"] = "C"
|
|
|
|
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
|