2 # Build script for Ohcount.
3 # Written by Mitchell Foral. mitchell<att>caladbolg.net.
6 # Change these for your system configuration.
7 if [ `uname` != "Darwin" ]
13 if [ `uname` == "FreeBSD" ]
15 INC_DIR=/usr/local/include
16 LIB_DIR=/usr/local/lib
19 # You shouldn't have to change the following.
21 WARN="-Wall -Wno-pointer-to-int-cast -Wno-parentheses"
23 SHARED_NAME=libohcount.so
25 RB_SHARED_NAME=ohcount.so
28 INC_DIR=/opt/local/include
29 LIB_DIR=/opt/local/lib
30 # You shouldn't have to change the following.
31 CFLAGS="-fno-common -g"
32 WARN="-Wall -Wno-parentheses"
33 SHARED="-dynamiclib -L$LIB_DIR -lpcre"
34 SHARED_NAME=libohcount.dylib
35 RB_SHARED="-dynamic -bundle -lruby"
36 RB_SHARED_NAME=ohcount.bundle
39 # C compiler and flags
40 cc="gcc -fPIC -g $CFLAGS $WARN -I$INC_DIR -L$LIB_DIR"
43 arch=`ruby/print_arch`
45 # Ohcount source files
46 files="src/sourcefile.c \
53 src/parsed_language.c \
54 src/hash/language_hash.c"
56 # If any src/hash/*.gperf file is newer than the header files (which were
57 # presumably generated together), regenerate the headers.
60 if [[ -z `ls src/hash/ | grep "_hash.h$"` ||
61 ! -z `find src/hash/*.gperf -newer src/hash/parser_hash.h` ]]
63 echo "Generating hash headers"
64 sh -c "cd src/hash/ && ./generate_headers" || exit 1
68 # If src/parser.o does not exist, or if there are Ragel parsers or parser
69 # header files newer than the existing parser.o, recompile parser.o.
72 if [[ ! -f src/parser.o ||
73 ! -z `find src/parsers/*.{h,rl} -newer src/parser.o` ]]
75 bash -c "cd src/parsers/ && bash ./compile" || exit 1
76 echo "Building src/parser.c (will take a while)"
77 bash -c "$cc -c src/parser.c -o src/parser.o" || exit 1
85 if [[ ! -f src/$SHARED_NAME ||
86 ! -z `find src/*.{h,c} -newer src/$SHARED_NAME` ]]
88 echo "Building shared library"
89 sh -c "$cc $SHARED $files -o src/$SHARED_NAME" || exit 1
97 echo "Building Ohcount"
99 sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre -lmagic" || exit 1
106 echo "Building test suite"
107 sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre -lmagic" \
113 echo "Running test suite"
114 sh -c "cd test/unit/ && ./run_tests"
117 build_ruby_bindings()
119 echo "Generating Ruby bindings for $arch"
120 sh -c "swig -ruby -o ruby/ohcount_wrap.c ruby/ohcount.i" || exit 1
122 sh -c "$cc $RB_SHARED ruby/ohcount_wrap.c $files -o ruby/$arch/$RB_SHARED_NAME \
123 -I`ruby -rmkmf -e 'print Config::expand(CONFIG["archdir"])'` \
124 -lpcre -lmagic" || exit 1
125 sh -c "cd test/unit/ruby && ruby ruby_test.rb" || exit 1
128 if [ $# -eq 0 ] || [ $1 == "all" ]
135 elif [ $1 == "shared" ]
138 echo "Build successful; $SHARED_NAME is in src/"
139 elif [ $1 == "ohcount" ]
142 echo "Build successful; ohcount is in bin/"
143 elif [ $1 == "tests" ]
147 elif [ $1 == "ruby" ]
150 echo "Build successful; $RB_SHARED_NAME is in ruby/$arch"
151 elif [ $1 == "clean" ]
154 rm -f test/unit/run_tests
156 rm -f src/parsers/*.h
159 rm -f src/$SHARED_NAME
160 rm -f ruby/$RB_SHARED_NAME
162 rm -f ruby/ohcount_wrap.c
164 echo "Usage: build [all|ohcount|shared|tests|ruby|clean]"