Skip to content

Commit dfcd04a

Browse files
committed
Refactor Homebrew formula using Makefile
See details in this blog post: https://nshipster.com/homebrew/
1 parent b2903aa commit dfcd04a

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

Formula/beak.rb

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
class Beak < Formula
2-
desc "A command line interface for your Swift scripts"
2+
desc "Command-line interface for your Swift scripts"
33
homepage "https://github.com/yonaskolb/Beak"
4-
url "https://github.com/yonaskolb/Beak/archive/0.4.0.tar.gz"
5-
sha256 "c306292c94aadd648437a2334936231baaa9ba195738aeeb28379fcb34900d41"
6-
head "https://github.com/yonaskolb/Beak.git"
4+
url "https://github.com/yonaskolb/Beak.git", :tag => "0.4.0", :revision => "8508e02da82c279b3cf1719bd226dc8c94538a71"
75

8-
depends_on :xcode
6+
depends_on :xcode => ["10.0", :build]
97

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

16-
build_path = "#{buildpath}/.build/release/beak"
17-
ohai "Building Beak"
18-
system("swift build --disable-sandbox -c release -Xswiftc -static-stdlib")
19-
bin.install build_path
12+
test do
13+
system bin/"beak", "version"
2014
end
2115
end

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
SHELL = /bin/bash
2+
3+
prefix ?= /usr/local
4+
bindir ?= $(prefix)/bin
5+
libdir ?= $(prefix)/lib
6+
srcdir = Sources
7+
8+
REPODIR = $(shell pwd)
9+
BUILDDIR = $(REPODIR)/.build
10+
SOURCES = $(wildcard $(srcdir)/**/*.swift)
11+
12+
.DEFAULT_GOAL = all
13+
14+
.PHONY: all
15+
all: beak
16+
17+
beak: $(SOURCES)
18+
@swift build \
19+
-c release \
20+
--disable-sandbox \
21+
--build-path "$(BUILDDIR)"
22+
23+
.PHONY: install
24+
install: beak
25+
@install -d "$(bindir)" "$(libdir)"
26+
@install "$(BUILDDIR)/release/beak" "$(bindir)"
27+
28+
.PHONY: uninstall
29+
uninstall:
30+
@rm -rf "$(bindir)/beak"
31+
32+
.PHONY: clean
33+
distclean:
34+
@rm -f $(BUILDDIR)/release
35+
36+
.PHONY: clean
37+
clean: distclean
38+
@rm -rf $(BUILDDIR)

0 commit comments

Comments
 (0)