Skip to content

Commit

Permalink
libmps: build Release version with system Clang (cc)
Browse files Browse the repository at this point in the history
  • Loading branch information
nailuoGG committed Jan 21, 2025
1 parent 3307e64 commit 8d7db4e
Showing 1 changed file with 15 additions and 28 deletions.
43 changes: 15 additions & 28 deletions Formula/lib/libmps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class Libmps < Formula
license "BSD-2-Clause"
head "https://github.com/Ravenbrook/mps.git", branch: "master"

# Add --with-debug option to build both Release and Debug versions
option "with-debug", "Build with debugging symbols and generate both Release (libmps.a) and Debug (libmps-debug.a) versions"
option "with-debug", "Build debug version (libmps-debug.a) alongside release version"

bottle do
sha256 cellar: :any_skip_relocation, arm64_sequoia: "c651514f2ee9c277517272b328db0e41ab0cc06b3998302e591db274dc70f104"
Expand All @@ -20,47 +19,35 @@ class Libmps < Formula
sha256 cellar: :any_skip_relocation, x86_64_linux: "c54043c0fcf718172a1d9f20e9eae7287180d26f4306f652c19f3d460faf68e9"
end

depends_on xcode: :build

def install
if OS.mac?
# Always build Release version
system "xcodebuild", "-scheme", "mps",
"-configuration", "Release",
"-project", "code/mps.xcodeproj",
"OTHER_CFLAGS=-Wno-error=unused-but-set-variable -Wno-unused-but-set-variable",
"SYMROOT=#{buildpath}/build"

# Install Release library
lib.install "build/Release/libmps.a"
cd "code" do
# Build Release version with system Clang (cc)
system ENV.cc, "-O2", "-c", "mps.c", "-o", "mps.o"
system "ar", "rvs", "libmps.a", "mps.o"
lib.install "libmps.a"

# Build Debug version if --with-debug is specified
if build.with? "debug"
system "xcodebuild", "-scheme", "mps",
"-configuration", "Debug",
"-project", "code/mps.xcodeproj",
"OTHER_CFLAGS=-O0 -g -DCONFIG_VAR_COOL",
"SYMROOT=#{buildpath}/build-debug"
# Build Debug version if requested
if build.with? "debug"
system ENV.cc, "-O0", "-g", "-DCONFIG_VAR_COOL", "-c", "mps.c", "-o", "mps-debug.o"
system "ar", "rvs", "libmps-debug.a", "mps-debug.o"
lib.install "libmps-debug.a"
end

# Install Debug library with different name
lib.install "build-debug/Debug/libmps.a" => "libmps-debug.a"
# Install headers
include.install Dir["mps*.h"]
end

# Install header files
include.install Dir["code/mps*.h"]
else
# Keep original Linux build method
ENV.deparallelize
# Build Release version for Linux
system "./configure", "--prefix=#{prefix}", "CFLAGS=-O2"
system "make"
system "make", "install"

# Build Debug version if --with-debug is specified
if build.with? "debug"
system "make", "clean"
system "./configure", "--prefix=#{prefix}", "CFLAGS=-O0 -g -DCONFIG_VAR_COOL"
system "make"
# Install Debug library with different name
lib.install "libmps.a" => "libmps-debug.a"
end
end
Expand Down

0 comments on commit 8d7db4e

Please sign in to comment.