aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Formula/ohcount.rb
blob: 7380e122b3e6452e27686f39383bce5d3dcc1722 (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
require 'formula'

class Ohcount < Formula
  homepage 'https://github.com/blackducksw/ohcount'
  url 'https://github.com/blackducksw/ohcount/archive/3.0.0.tar.gz'
  sha1 '7f3fce48bf2a522c5262215699c36625ca6d3d33'

  head do
    url 'https://github.com/blackducksw/ohcount.git'
    depends_on 'libmagic'
  end

  depends_on 'ragel'
  depends_on 'pcre'

  patch :DATA

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

    system "./build", "ohcount"
    bin.install 'bin/ohcount'
  end

  test do
    path = testpath/"test.rb"
    path.write "# comment\n puts\n puts\n"
    stats = `#{bin}/ohcount -i #{path}`.split("\n")[-1]
    assert_equal 0, $?.exitstatus
    assert_equal ["ruby", "2", "1", "33.3%"], stats.split[0..3]
  end
end

__END__
--- a/build
+++ b/build
@@ -29,7 +29,7 @@ else
   INC_DIR=/opt/local/include
   LIB_DIR=/opt/local/lib
   # You shouldn't have to change the following.
-  CFLAGS="-fno-common -g"
+  #CFLAGS="-fno-common -g"
   WARN="-Wall -Wno-parentheses"
   SHARED="-dynamiclib -L$LIB_DIR -lpcre"
   SHARED_NAME=libohcount.dylib
@@ -38,7 +38,7 @@ else
 fi
 
 # C compiler and flags
-cc="gcc -fPIC -g $CFLAGS $WARN -I$INC_DIR -L$LIB_DIR"
+cc="$CC $CFLAGS -O0 $WARN $CPPFLAGS $LDFLAGS"
 
 # Ohcount source files
 files="src/sourcefile.c \