11class Openblas < Formula
22 desc "Optimized BLAS library"
33 homepage "https://www.openblas.net/"
4- url "https://github.com/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.29.tar.gz"
5- sha256 "38240eee1b29e2bde47ebb5d61160207dc68668a54cac62c076bb5032013b1eb"
64 # The main license is BSD-3-Clause. Additionally,
75 # 1. OpenBLAS is based on GotoBLAS2 so some code is under original BSD-2-Clause-Views
86 # 2. lapack-netlib/ is a bundled LAPACK so it is BSD-3-Clause-Open-MPI
@@ -11,6 +9,23 @@ class Openblas < Formula
119 license all_of : [ "BSD-3-Clause" , "BSD-2-Clause-Views" , "BSD-3-Clause-Open-MPI" , "BSD-2-Clause" ]
1210 head "https://github.com/OpenMathLib/OpenBLAS.git" , branch : "develop"
1311
12+ stable do
13+ url "https://github.com/OpenMathLib/OpenBLAS/archive/refs/tags/v0.3.29.tar.gz"
14+ sha256 "38240eee1b29e2bde47ebb5d61160207dc68668a54cac62c076bb5032013b1eb"
15+
16+ # Remove patch in the next release
17+ patch do
18+ url "https://github.com/OpenMathLib/OpenBLAS/commit/70865a894e5963724ff9ccb05323ac2234a918b9.patch?full_index=1"
19+ sha256 "80beeb28e5baf21af05ac114a1cca97855faf298e40b3b290005977fad260f52"
20+ end
21+
22+ # Remove patch in the next release
23+ patch do
24+ url "https://github.com/ywwry66/OpenBLAS/commit/44632f3c5a8133d49117b2cd4fcf56ce1e77ec72.patch?full_index=1"
25+ sha256 "1fd8ce124f9513c51dd15ff55f136b3cb06997bc5cd386e8250474ab41fe6a69"
26+ end
27+ end
28+
1429 livecheck do
1530 url :stable
1631 strategy :github_latest
@@ -28,21 +43,18 @@ class Openblas < Formula
2843
2944 keg_only :shadowed_by_macos , "macOS provides BLAS in Accelerate.framework"
3045
46+ depends_on "cmake" => :build
47+ depends_on "pkgconf" => :test
3148 depends_on "gcc" # for gfortran
32- fails_with :clang
49+
50+ on_macos do
51+ depends_on "libomp"
52+ end
3353
3454 def install
3555 ENV . runtime_cpu_detection
36- ENV . deparallelize # build is parallel by default, but setting -j confuses it
37-
38- # The build log has many warnings of macOS build version mismatches.
39- ENV [ "MACOSX_DEPLOYMENT_TARGET" ] = MacOS . version . to_s if OS . mac?
40- ENV [ "DYNAMIC_ARCH" ] = "1"
41- ENV [ "USE_OPENMP" ] = "1"
42- # Force a large NUM_THREADS to support larger Macs than the VMs that build the bottles
43- ENV [ "NUM_THREADS" ] = "56"
44- # See available targets in TargetList.txt
45- ENV [ "TARGET" ] = case Hardware . oldest_cpu
56+
57+ target = case Hardware . oldest_cpu
4658 when :arm_vortex_tempest
4759 "VORTEX"
4860 when :westmere
@@ -51,16 +63,30 @@ def install
5163 Hardware . oldest_cpu . upcase . to_s
5264 end
5365
54- # Apple Silicon does not support SVE
55- # https://github.com/xianyi/OpenBLAS/issues/4212
56- ENV [ "NO_SVE" ] = "1" if Hardware ::CPU . arm?
66+ args = %W[
67+ -DUSE_OPENMP=ON
68+ -DBUILD_SHARED_LIBS=ON
69+ -DBUILD_STATIC_LIBS=ON
70+ -DNUM_THREADS=64
71+ -DTARGET=#{ target }
72+ ]
5773
58- # Must call in two steps
59- system "make" , "CC=#{ ENV . cc } " , "FC=gfortran" , "libs" , "netlib" , "shared"
60- system "make" , "PREFIX=#{ prefix } " , "install"
74+ args << "-DDYNAMIC_ARCH=ON" if !OS . mac? || Hardware ::CPU . intel?
75+
76+ if OS . mac?
77+ libomp = Formula [ "libomp" ]
78+ args << "-DOpenMP_Fortran_LIB_NAMES=omp"
79+ args << "-DOpenMP_omp_LIBRARY=#{ libomp . opt_lib } /libomp.dylib"
80+ end
81+
82+ system "cmake" , "-S" , "." , "-B" , "build" , *args , *std_cmake_args
83+ system "cmake" , "--build" , "build"
84+ system "cmake" , "--install" , "build"
6185
6286 lib . install_symlink shared_library ( "libopenblas" ) => shared_library ( "libblas" )
6387 lib . install_symlink shared_library ( "libopenblas" ) => shared_library ( "liblapack" )
88+
89+ inreplace lib /"pkgconfig/openblas.pc" , prefix , opt_prefix
6490 end
6591
6692 test do
@@ -85,8 +111,10 @@ def install
85111 return 0;
86112 }
87113 C
88- system ENV . cc , "test.c" , "-I#{ include } " , "-L#{ lib } " , "-lopenblas" ,
89- "-o" , "test"
114+
115+ ENV . prepend_path "PKG_CONFIG_PATH" , lib /"pkgconfig"
116+ flags = shell_output ( "pkgconf --cflags --libs openblas" ) . chomp . split
117+ system ENV . cc , "test.c" , "-o" , "test" , *flags
90118 system "./test"
91119 end
92120end
0 commit comments