MacOS

自定义brew Formula for Icu4c 自定义版本

本文由 简悦 SimpRead 转码, 原文地址 blog.csdn.net

自定义 brew 安装源来安装不在 brew 版本库中的软件或者版本,以下以自定义安装 icu4c 73 版本为例。

自定义的 icu4c@73.rb 安装源示例, 注意这里可能会安装多个版本的软件,所以. rb 文件的命名为要安装的软件名 + 大版本名,类名为 Icu4cAT73

效果图

icu4c@73.rb 文件示例

# 自定义brew Formula for Icu4c 自定义版本
# 使用方法:
# 1. 直接指定rb文件安装: brew install icu4c@73.rb
# 2. 将icu4c@73.rb文件放到brew的默认Formula路径 然后执行 brew install icu4c@73
# 路径:/opt/homebrew/Library/Taps/xiang/homebrew-taps/Formula/icu4c@73.rb
# 
# 注意下面的class名称,Icu4c 驼峰命名的要安装的软件名称 Icu4c,
# 后面的 AT 即 @ (@转换为slug命名即 AT)加大版本号 73 注意不能有特殊符号
class Icu4cAT73 < Formula
  # 软件描述信息
  desc "C/C++ and Java libraries for Unicode and globalization"
  # 软件提供商URL
  homepage "https://site.icu-project.org/home"
  # 软件包的下载地址
  url "https://github.com/unicode-org/icu/releases/download/release-73-2/icu4c-73_2-src.tgz"
  # 镜像地址
  # mirror "http://192.168.2.88/icu4c-73_2-src.tgz"
  # 版本号
  version "73.2"
  # 软件镜像包的 sha256签名信息,下载到本地可使用 openssl sha256 icu4c-73_2-src.tgz 命令来计算
  sha256 "818a80712ed3caacd9b652305e01afc7fa167e6f2e94996da44b90c2ab604ce1"
  # 版权
  license "GPL"

  # 新版本检测
  livecheck do
    # 要检测的URL地址
    url "https://github.com/unicode-org/icu/releases"
    # 正则提取版本信息
    regex(/href=.*?release-([0-9._-]+)"/i)
  end
  keg_only :provided_by_macos, "macOS provides libicucore.dylib (but nothing else)"
  # 安装方法
  def install
    # 定义./configure 配置参数
    args = %W[
      --prefix=#{prefix}
      --disable-samples
      --disable-tests
      --enable-static
      --with-library-bits=64
    ]
    # 注意默认路径是压缩包解压后的根目录,因为 进入到source目录
    cd "source" do
      system "./configure", *args
      system "make"
      system "make", "install"
    end
  end
  # 测试方法定义,这里可以定义多个测试项目
  test do
    if File.exist? "/usr/share/dict/words"
      system "#{bin}/gendict", "--uchars", "/usr/share/dict/words", "dict"
    else
      (testpath/"hello").write "hello\nworld\n"
      system "#{bin}/gendict", "--uchars", "hello", "dict"
    end
  end
end
# 安装自定义的formula
brew install  icu4c@73

# 检查安装信息 
brew info icu4c@73

安装后默认会将软件的安装目录 /usr/local/Cellar/icu4c@73/73.2 链接到 /usr/local/opt/icu4c@73

在使用的时候直接使用 /usr/local/opt/icu4c@73 ,这样后面更新相同的大版本 brew 会自动更新相关的软链接

创建软连接,解决其他软件找不到库的问题

# 创建软链接 解决php5.6不能运行问题
ln -sf /usr/local/opt/icu4c@73/lib/libicui18n.73.2.dylib ln -sf /opt/homebrew/Cellar/icu4c@73/73.2/lib/libicui18n.73.2.dylib /opt/homebrew/opt/icu4c/lib/libicui18n.73.dylib
ln -sf /opt/homebrew/Cellar/icu4c@73/73.2/lib/libicuuc.73.2.dylib /opt/homebrew/opt/icu4c/lib/libicuuc.73.dylib
ln -sf /opt/homebrew/Cellar/icu4c@73/73.2/lib/libicudata.73.2.dylib /opt/homebrew/opt/icu4c/lib/libicudata.73.dylib
ln -sf /opt/homebrew/Cellar/icu4c@73/73.2/lib/libicuio.73.2.dylib /opt/homebrew/opt/icu4c/lib/libicuio.73.dylib

如果不需要了,执行 brew uninstall icu4c@73

或者 直接删除相关文件即可 目录 /usr/local/Cellar/icu4c@73/73.2 软连接 /usr/local/opt/icu4c@73

rm -rf /usr/local/Cellar/icu4c@73/73.2
rm -rf  /usr/local/opt/icu4c@73

#删除相关软链接
rm -f /usr/local/lib/libicui18n.73.dylib
rm -f /usr/local/lib/libicuuc.73.dylib
rm -f /usr/local/lib/libicudata.73.dylib
rm -f /usr/local/lib/libicuio.73.dylib

留言