You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Swift CLI通过Makefile发布到Homebrew时make install报错排查

问题

我用Swift开发了一款CLI工具,打算通过Homebrew分发,这是我第一次在Homebrew发布内容,完全照着教程写了Formula和Makefile。本地在项目根目录执行make install一切正常,但执行brew install SailorWebFramework/formulae/Compass时,却弹出报错:

make: *** No rule to make target `install'.  Stop.

我怀疑是路径或大小写的问题,求帮忙排查。

相关代码

Formula代码

class Compass < Formula
  desc "Command Line Interface for Sailor - A Frontend Web Framework in Swift"
  homepage "https://github.com/SailorWebFramework/Compass"
  url "https://github.com/SailorWebFramework/Compass", tag: "0.0.1"
  version "0.0.1"

  depends_on "xcode": [:build]

  def install
    system "make", "install",  "prefix=#{prefix}"
  end

  test do
    system "#{bin}compass", "help"
  end
end

Makefile代码

prefix ?= /usr/local
bindir = $(prefix)/bin

# Command building targets.
build:
    swift build -c release --disable-sandbox

install: build
    install -d "$(bindir)"
    install ".build/release/Compass" "$(bindir)"

uninstall:
    $(RM) -rf "$(bindir)/Compass"

clean:
    $(RM) -rf .build

.PHONY: build install uninstall clean

完整报错信息

==> make install prefix=/usr/local/Cellar/compass/0.0.1
make: *** No rule to make target `install'.  Stop.
排查与解决办法

1. 检查Makefile的缩进(最可能的原因)

Makefile语法要求命令行必须用Tab键缩进,不能用空格。你提供的Makefile里,build:、install:等目标下的命令行看起来是空格缩进,这会直接导致make无法识别规则。

  • 解决:把Makefile中所有目标下的命令行,全部替换成Tab键缩进。

2. 确认仓库中Makefile的位置与名称

Homebrew构建时会把源码拉到临时目录,如果你的GitHub仓库里:

  • Makefile的名称是小写的makefile,而非Makefile
  • Makefile不在项目根目录,而是子文件夹里
    都会导致make找不到规则。
  • 解决:
    • 确保仓库根目录下的文件名为Makefile(注意大小写)
    • 如果Makefile在子目录,修改Formula的install方法,先切换到对应目录:
      def install
        cd "path/to/subdir" do
          system "make", "install", "prefix=#{prefix}"
        end
      end
      

3. 修正Formula的URL配置

你当前的URL写法可能没有正确拉取到标签0.0.1的源码,而是拉取了仓库默认分支的内容,导致临时目录里的Makefile不对。

  • 解决:改用GitHub的tarball URL,并添加sha256校验值:
    url "https://github.com/SailorWebFramework/Compass/archive/refs/tags/0.0.1.tar.gz"
    sha256 "替换成该tar包的sha256校验值"
    
    校验值可以通过执行以下命令获取:
    curl -L https://github.com/SailorWebFramework/Compass/archive/refs/tags/0.0.1.tar.gz | shasum -a 256
    

4. 显式指定Makefile路径

在Homebrew的构建环境中,可能存在路径识别问题,显式指定Makefile路径可以避免这个问题:

  • 修改Formula的install方法:
    def install
      system "make", "-f", "#{buildpath}/Makefile", "install", "prefix=#{prefix}"
    end
    

内容的提问来源于stack exchange,提问作者Christopher Bannon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 20:58:18