aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/ledger.rb
blob: 13726f0e4aea2a13c601ec08dbfade7efa9e5c9f (plain)
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
require 'formula'

class Ledger < Formula
  homepage 'http://ledger-cli.org'

  stable do
    url 'https://github.com/downloads/ledger/ledger/ledger-2.6.3.tar.gz'
    sha1 '5b8e7d8199acb116f13720a5a469fff1f14b4041'

    depends_on 'gettext'
    depends_on 'pcre'
    depends_on 'expat'
    depends_on 'libofx' => :optional
  end

  head do
    url 'https://github.com/ledger/ledger.git', :branch => 'master'
    depends_on 'cmake' => :build
    depends_on 'ninja' => :build
    depends_on 'mpfr'
  end

  option 'debug', 'Build with debugging symbols enabled'

  depends_on 'boost'
  depends_on 'gmp'
  depends_on :python => :optional

  def install
    # find Homebrew's libpcre
    ENV.append 'LDFLAGS', "-L#{HOMEBREW_PREFIX}/lib"

    if build.head?
      # Support homebrew not at /usr/local. Also support Xcode-only setups:
      inreplace 'acprep', 'search_prefixes = [', "search_prefixes = ['#{HOMEBREW_PREFIX}','#{MacOS.sdk_path}/usr',"
      args = [((build.include? 'debug') ? 'debug' : 'opt'), "make", "install", "-N", "-j#{ENV.make_jobs}", "--output=build"]

      if build.with? 'python'
        # Per #25118, CMake does a poor job of detecting a brewed Python.
        # We need to tell CMake explicitly where our default python lives.
        # Inspired by
        # https://github.com/Homebrew/homebrew/blob/51d054c/Library/Formula/opencv.rb
        args << '--python' << '--'

        python_prefix = `python-config --prefix`.strip
        args << "-DPYTHON_LIBRARY='#{python_prefix}/Python'"
        args << "-DPYTHON_INCLUDE_DIR='#{python_prefix}/Headers'"
      end

      system "./acprep", "--prefix=#{prefix}", *args
      (share+'ledger').install 'python/demo.py', 'test/input/sample.dat', Dir['contrib']
    else
      args = []
      if build.with? 'libofx'
        args << "--enable-ofx"
        # the libofx.h appears to have moved to a subdirectory
        ENV.append 'CXXFLAGS', "-I#{Formula["libofx"].opt_include}/libofx"
      end
      system "./configure", "--disable-debug", "--disable-dependency-tracking",
                            "--prefix=#{prefix}", *args
      system 'make'
      ENV.deparallelize
      system 'make install'
      (share+'ledger').install 'sample.dat', Dir['scripts']
    end
  end

  test do
    output = `#{bin}/ledger --file #{share}/ledger/sample.dat balance --collapse equity`
    assert_equal '          $-2,500.00  Equity', output.split(/\n/)[0]
    assert_equal 0, $?.exitstatus

    if build.head? and build.with? 'python'
      system "python", "#{share}/ledger/demo.py"
    end
  end
end