-
-
Notifications
You must be signed in to change notification settings - Fork 189
285 lines (233 loc) · 9.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
require_relative "../Library/EmacsBase"
class EmacsPlusAT28 < EmacsBase
init 28
url "https://ftp.gnu.org/gnu/emacs/emacs-28.2.tar.xz"
mirror "https://ftpmirror.gnu.org/emacs/emacs-28.2.tar.xz"
sha256 "ee21182233ef3232dc97b486af2d86e14042dbb65bbc535df562c3a858232488"
desc "GNU Emacs text editor"
homepage "https://www.gnu.org/software/emacs/"
head do
url "https://github.com/emacs-mirror/emacs.git", :branch => "emacs-28"
end
#
# Options
#
# Opt-out
option "without-cocoa", "Build a non-Cocoa version of Emacs"
# Opt-in
option "with-ctags", "Don't remove the ctags executable that Emacs provides"
option "with-x11", "Experimental: build with x11 support"
option "with-no-titlebar", "Experimental: build without titlebar"
option "with-no-titlebar-and-round-corners", "Experimental: build without titlebar and round coners"
option "with-debug", "Build with debug symbols and debugger friendly optimizations"
option "with-xwidgets", "Experimental: build with xwidgets support"
option "with-no-frame-refocus", "Disables frame re-focus (ie. closing one frame does not refocus another one)"
option "with-native-comp", "Build with native compilation"
#
# Dependencies
#
depends_on "make" => :build
depends_on "autoconf" => :build
depends_on "gnu-sed" => :build
depends_on "gnu-tar" => :build
depends_on "grep" => :build
depends_on "awk" => :build
depends_on "coreutils" => :build
depends_on "pkg-config" => :build
depends_on "texinfo" => :build
depends_on "xz" => :build
depends_on "gnutls"
depends_on "librsvg"
depends_on "little-cms2"
depends_on "jansson"
depends_on "imagemagick" => :optional
depends_on "dbus" => :optional
depends_on "mailutils" => :optional
if build.with? "x11"
depends_on "libxaw"
depends_on "freetype" => :recommended
depends_on "fontconfig" => :recommended
end
if build.with? "native-comp"
# `libgccjit` and `gcc` are required when Emacs compiles `*.elc` files asynchronously (JIT)
depends_on "libgccjit"
depends_on "gcc"
depends_on "gmp" => :build
depends_on "libjpeg" => :build
depends_on "zlib" => :build
end
#
# Incompatible options
#
if build.with? "xwidgets"
unless (build.with? "cocoa") && (build.without? "x11")
odie "--with-xwidgets is not available when building --with-x11"
end
end
if build.with? "no-titlebar"
if build.with? "no-titlebar-and-round-corners"
odie "--with-no-titlebar and --with-no-titlebar-and-round-corners are mutually exclusive"
end
end
#
# Icons
#
inject_icon_options
#
# Patches
#
local_patch "no-titlebar", sha: "2fa80efc5cda7e96d88a5d145c9313092a6e53d38825c41967c745f08778c41b" if build.with? "no-titlebar"
local_patch "no-titlebar-and-round-corners", sha: "ba7606186fe1b9e675147fed2c8080efa2824dc6679f6a9550b792533aec98be" if build.with? "no-titlebar-and-round-corners"
local_patch "no-frame-refocus-cocoa", sha: "fb5777dc890aa07349f143ae65c2bcf43edad6febfd564b01a2235c5a15fcabd" if build.with? "no-frame-refocus"
local_patch "fix-window-role", sha: "1f8423ea7e6e66c9ac6dd8e37b119972daa1264de00172a24a79a710efcb8130"
local_patch "system-appearance", sha: "d6ee159839b38b6af539d7b9bdff231263e451c1fd42eec0d125318c9db8cd92"
#
# Install
#
def install
args = %W[
--disable-dependency-tracking
--disable-silent-rules
--enable-locallisppath=#{HOMEBREW_PREFIX}/share/emacs/site-lisp
--infodir=#{info}/emacs
--prefix=#{prefix}
]
args << "--with-xml2"
args << "--with-gnutls"
args << "--with-native-compilation" if build.with? "native-comp"
ENV.append "CFLAGS", "-g -Og" if build.with? "debug"
ENV.append "CFLAGS", "-O2 -DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT"
# Necessary for libgccjit library discovery
if build.with? "native-comp"
gcc_ver = Formula["gcc"].any_installed_version
gcc_ver_major = gcc_ver.major
gcc_lib="#{HOMEBREW_PREFIX}/lib/gcc/#{gcc_ver_major}"
ENV.append "CFLAGS", "-I#{Formula["gcc"].include}"
ENV.append "CFLAGS", "-I#{Formula["libgccjit"].include}"
ENV.append "LDFLAGS", "-L#{gcc_lib}"
ENV.append "LDFLAGS", "-I#{Formula["gcc"].include}"
ENV.append "LDFLAGS", "-I#{Formula["libgccjit"].include}"
end
args <<
if build.with? "dbus"
"--with-dbus"
else
"--without-dbus"
end
# Note that if ./configure is passed --with-imagemagick but can't find the
# library it does not fail but imagemagick support will not be available.
# See: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=24455
args <<
if build.with?("imagemagick")
"--with-imagemagick"
else
"--without-imagemagick"
end
if build.with? "imagemagick"
imagemagick_lib_path = Formula["imagemagick"].opt_lib/"pkgconfig"
ohai "ImageMagick PKG_CONFIG_PATH: ", imagemagick_lib_path
ENV.prepend_path "PKG_CONFIG_PATH", imagemagick_lib_path
end
args << "--with-modules"
args << "--with-rsvg"
args << "--without-pop" if build.with? "mailutils"
args << "--with-xwidgets" if build.with? "xwidgets"
system "./autogen.sh"
if (build.with? "cocoa") && (build.without? "x11")
args << "--with-ns" << "--disable-ns-self-contained"
system "./configure", *args
# Disable aligned_alloc on Mojave. See issue: https://github.com/daviderestivo/homebrew-emacs-head/issues/15
if OS.mac? && MacOS.version <= :mojave
ohai "Force disabling of aligned_alloc on macOS <= Mojave"
configure_h_filtered = File.read("src/config.h")
.gsub("#define HAVE_ALIGNED_ALLOC 1", "#undef HAVE_ALIGNED_ALLOC")
.gsub("#define HAVE_DECL_ALIGNED_ALLOC 1", "#undef HAVE_DECL_ALIGNED_ALLOC")
.gsub("#define HAVE_ALLOCA 1", "#undef HAVE_ALLOCA")
.gsub("#define HAVE_ALLOCA_H 1", "#undef HAVE_ALLOCA_H")
File.open("src/config.h", "w") do |f|
f.write(configure_h_filtered)
end
end
system "gmake"
system "gmake", "install"
icons_dir = buildpath/"nextstep/Emacs.app/Contents/Resources"
ICONS_CONFIG.each_key do |icon|
next if build.without? "#{icon}-icon"
rm "#{icons_dir}/Emacs.icns"
resource("#{icon}-icon").stage do
icons_dir.install Dir["*.icns*"].first => "Emacs.icns"
end
end
# (prefix/"share/emacs/#{version}").install "lisp"
prefix.install "nextstep/Emacs.app"
(prefix/"Emacs.app/Contents").install "native-lisp" if build.with? "native-comp"
# inject PATH to Info.plist
inject_path
# inject description for protected resources usage
inject_protected_resources_usage_desc
# Replace the symlink with one that avoids starting Cocoa.
(bin/"emacs").unlink # Kill the existing symlink
(bin/"emacs").write <<~EOS
#!/bin/bash
exec #{prefix}/Emacs.app/Contents/MacOS/Emacs "$@"
EOS
else
if build.with? "x11"
# These libs are not specified in xft's .pc. See:
# https://trac.macports.org/browser/trunk/dports/editors/emacs/Portfile#L74
# https://github.com/Homebrew/homebrew/issues/8156
ENV.append "LDFLAGS", "-lfreetype -lfontconfig"
args << "--with-x"
args << "--with-gif=no" << "--with-tiff=no" << "--with-jpeg=no"
else
args << "--without-x"
end
args << "--without-ns"
system "./configure", *args
# Disable aligned_alloc on Mojave. See issue: https://github.com/daviderestivo/homebrew-emacs-head/issues/15
if OS.mac? && MacOS.version <= :mojave
ohai "Force disabling of aligned_alloc on macOS <= Mojave"
configure_h_filtered = File.read("src/config.h")
.gsub("#define HAVE_ALIGNED_ALLOC 1", "#undef HAVE_ALIGNED_ALLOC")
.gsub("#define HAVE_DECL_ALIGNED_ALLOC 1", "#undef HAVE_DECL_ALIGNED_ALLOC")
.gsub("#define HAVE_ALLOCA 1", "#undef HAVE_ALLOCA")
.gsub("#define HAVE_ALLOCA_H 1", "#undef HAVE_ALLOCA_H")
File.open("src/config.h", "w") do |f|
f.write(configure_h_filtered)
end
end
system "gmake"
system "gmake", "install"
end
# Follow MacPorts and don't install ctags from Emacs. This allows Vim
# and Emacs and ctags to play together without violence.
if build.without? "ctags"
(bin/"ctags").unlink
(man1/"ctags.1.gz").unlink
end
end
def caveats
<<~EOS
Emacs.app was installed to:
#{prefix}
To link the application to default Homebrew App location:
osascript -e 'tell application "Finder" to make alias file to posix file "#{prefix}/Emacs.app" at posix file "/Applications" with properties {name:"Emacs.app"}'
Your PATH value was injected into Emacs.app/Contents/Info.plist
Report any issues to https://github.com/d12frosted/homebrew-emacs-plus
EOS
end
def post_install
if build.with? "native-comp"
ln_sf "#{Dir[opt_prefix/"lib/emacs/*"].first}/native-lisp", "#{opt_prefix}/Emacs.app/Contents/native-lisp"
end
end
service do
run [opt_bin/"emacs", "--fg-daemon"]
keep_alive true
log_path "/tmp/homebrew.mxcl.emacs-plus.stdout.log"
error_log_path "/tmp/homebrew.mxcl.emacs-plus.stderr.log"
end
test do
assert_equal "4", shell_output("#{bin}/emacs --batch --eval=\"(print (+ 2 2))\"").strip
end
end