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" ]
12 # You shouldn't have to change the following.
14 WARN="-Wall -Wno-pointer-to-int-cast -Wno-parentheses"
16 SHARED_NAME=libohcount.so
18 RB_SHARED_NAME=ohcount.so
21 INC_DIR=/opt/local/include
22 LIB_DIR=/opt/local/lib
23 # You shouldn't have to change the following.
25 WARN="-Wall -Wno-parentheses -O3 -Oz"
26 SHARED="-dynamiclib -L$LIB_DIR -lpcre"
27 SHARED_NAME=libohcount.dylib
28 RB_SHARED="-dynamic -bundle -lruby"
29 RB_SHARED_NAME=ohcount.bundle
32 # C compiler and flags
33 cc="gcc -fPIC -g $CFLAGS $WARN -I$INC_DIR -L$LIB_DIR"
35 # Ohcount source files
36 files="src/sourcefile.c \
42 src/parsed_language.c \
43 src/hash/language_hash.c"
45 # If any src/hash/*.gperf file is newer than the header files (which were
46 # presumably generated together), regenerate the headers.
49 if [[ -z `ls src/hash/ | grep "_hash.h$"` ||
50 ! -z `find src/hash/*.gperf -newer src/hash/parser_hash.h` ]]
52 echo "Generating hash headers"
53 sh -c "cd src/hash/ && ./generate_headers" || exit 1
57 # If src/parser.o does not exist, or if there are Ragel parsers or parser
58 # header files newer than the existing parser.o, recompile parser.o.
61 if [[ ! -f src/parser.o ||
62 ! -z `find src/parsers/*.{h,rl} -newer src/parser.o` ]]
64 bash -c "cd src/parsers/ && bash ./compile" || exit 1
65 echo "Building src/parser.c (will take a while)"
66 bash -c "$cc -c src/parser.c -o src/parser.o" || exit 1
74 if [[ ! -f src/$SHARED_NAME ||
75 ! -z `find src/*.{h,c} -newer src/$SHARED_NAME` ]]
77 echo "Building shared library"
78 sh -c "$cc $SHARED $files -o src/$SHARED_NAME" || exit 1
86 echo "Building Ohcount"
88 sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre" || exit 1
95 echo "Building test suite"
96 sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre" \
102 echo "Running test suite"
103 sh -c "cd test/unit/ && ./run_tests"
106 build_ruby_bindings()
108 arch=`ruby -rmkmf -e 'print Config::expand(CONFIG["arch"])'`
109 echo "Generating Ruby bindings for $arch"
110 sh -c "swig -ruby -o ruby/ohcount_wrap.c ruby/ohcount.i" || exit 1
112 sh -c "$cc $RB_SHARED ruby/ohcount_wrap.c $files -o ruby/$arch/$RB_SHARED_NAME \
113 -I`ruby -rmkmf -e 'print Config::expand(CONFIG["archdir"])'` \
115 sh -c "cd test/unit/ruby && ruby ruby_test.rb" || exit 1
118 if [ $# -eq 0 ] || [ $1 == "all" ]
124 elif [ $1 == "shared" ]
127 echo "Build successful; $SHARED_NAME is in src/"
128 elif [ $1 == "ohcount" ]
131 echo "Build successful; ohcount is in bin/"
132 elif [ $1 == "tests" ]
136 elif [ $1 == "ruby" ]
139 echo "Build successful; $RB_SHARED_NAME is in ruby/"
140 elif [ $1 == "clean" ]
143 rm test/unit/run_tests
149 rm ruby/$RB_SHARED_NAME
151 echo "Usage: build [all|ohcount|shared|tests|ruby|clean]"