Skip to content

Commit

Permalink
Refactor Homebrew formula using Makefile
Browse files Browse the repository at this point in the history
See details in this blog post: https://nshipster.com/homebrew/
  • Loading branch information
Jeehut committed Feb 13, 2019
1 parent b2903aa commit dfcd04a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
20 changes: 7 additions & 13 deletions Formula/beak.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
class Beak < Formula
desc "A command line interface for your Swift scripts"
desc "Command-line interface for your Swift scripts"
homepage "https://github.com/yonaskolb/Beak"
url "https://github.com/yonaskolb/Beak/archive/0.4.0.tar.gz"
sha256 "c306292c94aadd648437a2334936231baaa9ba195738aeeb28379fcb34900d41"
head "https://github.com/yonaskolb/Beak.git"
url "https://github.com/yonaskolb/Beak.git", :tag => "0.4.0", :revision => "8508e02da82c279b3cf1719bd226dc8c94538a71"

depends_on :xcode
depends_on :xcode => ["10.0", :build]

def install

# fixes an issue an issue in homebrew when both Xcode 9.3+ and command line tools are installed
# see more details here https://github.com/Homebrew/brew/pull/4147
ENV["CC"] = Utils.popen_read("xcrun -find clang").chomp
system "make", "install", "prefix=#{prefix}"
end

build_path = "#{buildpath}/.build/release/beak"
ohai "Building Beak"
system("swift build --disable-sandbox -c release -Xswiftc -static-stdlib")
bin.install build_path
test do
system bin/"beak", "version"
end
end
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
SHELL = /bin/bash

prefix ?= /usr/local
bindir ?= $(prefix)/bin
libdir ?= $(prefix)/lib
srcdir = Sources

REPODIR = $(shell pwd)
BUILDDIR = $(REPODIR)/.build
SOURCES = $(wildcard $(srcdir)/**/*.swift)

.DEFAULT_GOAL = all

.PHONY: all
all: beak

beak: $(SOURCES)
@swift build \
-c release \
--disable-sandbox \
--build-path "$(BUILDDIR)"

.PHONY: install
install: beak
@install -d "$(bindir)" "$(libdir)"
@install "$(BUILDDIR)/release/beak" "$(bindir)"

.PHONY: uninstall
uninstall:
@rm -rf "$(bindir)/beak"

.PHONY: clean
distclean:
@rm -f $(BUILDDIR)/release

.PHONY: clean
clean: distclean
@rm -rf $(BUILDDIR)

0 comments on commit dfcd04a

Please sign in to comment.