|
| 1 | +class Readline < Formula |
| 2 | + desc "Library for command-line editing" |
| 3 | + homepage "https://tiswww.case.edu/php/chet/readline/rltop.html" |
| 4 | + url "https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz" |
| 5 | + mirror "https://ftpmirror.gnu.org/readline/readline-8.2.tar.gz" |
| 6 | + version "8.2.13" |
| 7 | + sha256 "3feb7171f16a84ee82ca18a36d7b9be109a52c04f492a053331d7d1095007c35" |
| 8 | + license "GPL-3.0-or-later" |
| 9 | + |
| 10 | + %w[ |
| 11 | + 001 bbf97f1ec40a929edab5aa81998c1e2ef435436c597754916e6a5868f273aff7 |
| 12 | + 002 e06503822c62f7bc0d9f387d4c78c09e0ce56e53872011363c74786c7cd4c053 |
| 13 | + 003 24f587ba46b46ed2b1868ccaf9947504feba154bb8faabd4adaea63ef7e6acb0 |
| 14 | + 004 79572eeaeb82afdc6869d7ad4cba9d4f519b1218070e17fa90bbecd49bd525ac |
| 15 | + 005 622ba387dae5c185afb4b9b20634804e5f6c1c6e5e87ebee7c35a8f065114c99 |
| 16 | + 006 c7b45ff8c0d24d81482e6e0677e81563d13c74241f7b86c4de00d239bc81f5a1 |
| 17 | + 007 5911a5b980d7900aabdbee483f86dab7056851e6400efb002776a0a4a1bab6f6 |
| 18 | + 008 a177edc9d8c9f82e8c19d0630ab351f3fd1b201d655a1ddb5d51c4cee197b26a |
| 19 | + 009 3d9885e692e1998523fd5c61f558cecd2aafd67a07bd3bfe1d7ad5a31777a116 |
| 20 | + 010 758e2ec65a0c214cfe6161f5cde3c5af4377c67d820ea01d13de3ca165f67b4c |
| 21 | + 011 e0013d907f3a9e6482cc0934de1bd82ee3c3c4fd07a9646aa9899af237544dd7 |
| 22 | + 012 6c8adf8ed4a2ca629f7fd11301ed6293a6248c9da0c674f86217df715efccbd3 |
| 23 | + 013 1ea434957d6ec3a7b61763f1f3552dad0ebdd6754d65888b5cd6d80db3a788a8 |
| 24 | + ].each_slice(2) do |p, checksum| |
| 25 | + patch :p0 do |
| 26 | + url "https://ftp.gnu.org/gnu/readline/readline-8.2-patches/readline82-#{p}" |
| 27 | + mirror "https://ftpmirror.gnu.org/readline/readline-8.2-patches/readline82-#{p}" |
| 28 | + sha256 checksum |
| 29 | + end |
| 30 | + end |
| 31 | + |
| 32 | + # We're not using `url :stable` here because we need `url` to be a string |
| 33 | + # when we use it in the `strategy` block. |
| 34 | + livecheck do |
| 35 | + url :stable |
| 36 | + regex(/href=.*?readline[._-]v?(\d+(?:\.\d+)+)\.t/i) |
| 37 | + strategy :gnu do |page, regex| |
| 38 | + # Match versions from files |
| 39 | + versions = page.scan(regex) |
| 40 | + .flatten |
| 41 | + .uniq |
| 42 | + .map { |v| Version.new(v) } |
| 43 | + .sort |
| 44 | + next versions if versions.blank? |
| 45 | + |
| 46 | + # Assume the last-sorted version is newest |
| 47 | + newest_version = versions.last |
| 48 | + |
| 49 | + # Simply return the found versions if there isn't a patches directory |
| 50 | + # for the "newest" version |
| 51 | + patches_directory = page.match(%r{href=.*?(readline[._-]v?#{newest_version.major_minor}[._-]patches/?)["' >]}i) |
| 52 | + next versions if patches_directory.blank? |
| 53 | + |
| 54 | + # Fetch the page for the patches directory |
| 55 | + patches_page = Homebrew::Livecheck::Strategy.page_content( |
| 56 | + "https://ftp.gnu.org/gnu/readline/#{patches_directory[1]}", |
| 57 | + ) |
| 58 | + next versions if patches_page[:content].blank? |
| 59 | + |
| 60 | + # Generate additional major.minor.patch versions from the patch files in |
| 61 | + # the directory and add those to the versions array |
| 62 | + patches_page[:content].scan(/href=.*?readline[._-]?v?\d+(?:\.\d+)*[._-]0*(\d+)["' >]/i).each do |match| |
| 63 | + versions << "#{newest_version.major_minor}.#{match[0]}" |
| 64 | + end |
| 65 | + |
| 66 | + versions |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + bottle do |
| 71 | + root_url "https://github.com/gromgit/homebrew-core-aarch64_linux/releases/download/readline-8.2.13" |
| 72 | + sha256 cellar: :any_skip_relocation, aarch64_linux: "e99275c523d1a8b4a61303bab92aefdb1d9054f8e5b82f7a327b698e096292ce" |
| 73 | + end |
| 74 | + |
| 75 | + keg_only :shadowed_by_macos, "macOS provides BSD libedit" |
| 76 | + |
| 77 | + uses_from_macos "ncurses" |
| 78 | + |
| 79 | + def install |
| 80 | + system "./configure", "--prefix=#{prefix}", "--with-curses" |
| 81 | + # FIXME: Setting `SHLIB_LIBS` should not be needed, but, on Linux, |
| 82 | + # many dependents expect readline to link with ncurses and |
| 83 | + # are broken without it. Readline should be agnostic about |
| 84 | + # the terminfo library on Linux. |
| 85 | + system "make", "install", "SHLIB_LIBS=-lcurses" |
| 86 | + end |
| 87 | + |
| 88 | + test do |
| 89 | + (testpath/"test.c").write <<~EOS |
| 90 | + #include <stdio.h> |
| 91 | + #include <stdlib.h> |
| 92 | + #include <readline/readline.h> |
| 93 | +
|
| 94 | + int main() |
| 95 | + { |
| 96 | + printf("%s\\n", readline("test> ")); |
| 97 | + return 0; |
| 98 | + } |
| 99 | + EOS |
| 100 | + |
| 101 | + system ENV.cc, "-L", lib, "test.c", "-L#{lib}", "-lreadline", "-o", "test" |
| 102 | + assert_equal "test> Hello, World!\nHello, World!", pipe_output("./test", "Hello, World!\n").strip |
| 103 | + end |
| 104 | +end |
0 commit comments