Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 60 additions & 9 deletions Formula/coot.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
class Coot < Formula
desc "Crystallographic Object-Oriented Toolkit"
homepage "https://www2.mrc-lmb.cam.ac.uk/personal/pemsley/coot/"
url "https://github.com/pemsley/coot/archive/refs/tags/Release-1.3.1.tar.gz"
sha256 "39069510b2bd499a407d5cc9202d4df591b353c344dd21aaf30e2ceab8260025"
url "https://github.com/pemsley/coot/archive/refs/tags/Release-1.3.2.tar.gz"
sha256 "8bd71e6582e87a8d2959bc1b956875a7f62c575b5a93ca60f2e575eaab42ff57"
license any_of: ["GPL-3.0-only", "LGPL-3.0-only", "GPL-2.0-or-later"]
head "https://github.com/pemsley/coot.git", branch: "main"

# Track the tagged releases; the default git strategy otherwise picks junk
# tags like revision-count-* and reports a bogus version.
livecheck do
url :stable
strategy :github_latest
Expand Down Expand Up @@ -105,12 +103,63 @@ def install
"\nexec_prefix="
ENV.cxx11
ENV.libcxx
# clang 15 (macOS 14) predates C++20 parenthesized aggregate initialization
# (P0960, landed in clang 16), so this `new T(str)` on the plain aggregate
# em_placement_data_t fails to compile there. Brace-initialize it instead,
# which is valid C++17 and behaves identically (obj stays value-initialized).

if OS.mac?
# coot's bare GTK4 window has no Dock icon on macOS. Build a tiny
# static helper that calls NSApplication#setApplicationIconImage via
# AppKit, and link it only into the MacCoot binary (see the OS_DARWIN
# block appended to src/Makefile.am below).
dock_icon_source = buildpath/"src/coot-macos-dock-icon.mm"
dock_icon_source.write <<~OBJCPP
#import <AppKit/AppKit.h>

extern "C" void set_coot_macos_dock_icon(const char *path) {
@autoreleasepool {
NSString *icon_path = [NSString stringWithUTF8String:path];
NSImage *image = [[NSImage alloc] initWithContentsOfFile:icon_path];
if (image != nil) {
[[NSApplication sharedApplication] setApplicationIconImage:image];
[image release];
}
}
}
OBJCPP
system ENV.cxx, "-c", dock_icon_source, "-o", "src/coot-macos-dock-icon.o"
system "ar", "rcs", "src/libcoot-macos-dock-icon.a", "src/coot-macos-dock-icon.o"

# extern "C" linkage specifications are only valid at namespace scope,
# so the declaration goes just above startup(), and only the call
# itself goes inline after gtk_init().
inreplace "src/startup.cc", "int startup(int argc, char **argv) {", <<~CPP.chomp
#ifdef __APPLE__
extern "C" void set_coot_macos_dock_icon(const char *path);
#endif

int startup(int argc, char **argv) {
CPP

inreplace "src/startup.cc", "gtk_init();", <<~CPP.chomp
gtk_init();

#ifdef __APPLE__
set_coot_macos_dock_icon("#{pkgshare}/coot-dock-icon.png");
#endif
CPP

inreplace "src/Makefile.am" do |s|
s.inreplace_string.sub!(/(MacCoot_LDADD\s*=.*?\$\(EMBEDDED_PYTHON_LIBS\))(\nelse\ncoot_1_LDADD)/m) do
"#{Regexp.last_match(1)} \\\n\tlibcoot-macos-dock-icon.a#{Regexp.last_match(2)}"
end
end
# automake requires linker flags such as -framework to live in
# _LDFLAGS rather than _LDADD.
inreplace "src/Makefile.am",
"MacCoot_LDFLAGS = $(EXPORT_DYNAMIC_FLAG_SPEC)",
"MacCoot_LDFLAGS = $(EXPORT_DYNAMIC_FLAG_SPEC) -framework AppKit"
end

inreplace "src/cc-interface-map-utils.cc",
"new em_placement_data_t(em_placement_output_file_name)",
"new em_placement_data_t(em_placement_output_file_name, 0)",
"new em_placement_data_t{em_placement_output_file_name}"
inreplace "autogen.sh", "libtool", "glibtool"
system "./autogen.sh"
Expand Down Expand Up @@ -152,6 +201,8 @@ def install
system "make"
ENV.deparallelize { system "make", "install" }
bin.install_symlink libexec/"Maccoot"
# install the Dock icon image referenced by the AppKit helper above
pkgshare.install "pixmaps/icons/hicolor_apps_256x256_coot.png" => "coot-dock-icon.png" if OS.mac?
# install reference data
# install data, #{pkgshare} is /path/to/share/coot
(pkgshare/"reference-structures").install resource("reference-structures")
Expand Down