2 # Build script for Ohcount.
3 # Written by Mitchell Foral. mitchell<att>caladbolg.net.
6 cc="gcc -fPIC -g -Wall -Wno-pointer-to-int-cast -Wno-parentheses"
9 files="src/sourcefile.c \
15 src/parsed_language.c \
16 src/hash/language_hash.c"
18 # If any src/hash/*.gperf file is newer than the header files (which were
19 # presumably generated together), regenerate the headers.
22 if [[ -z `ls src/hash/ | grep "_hash.h$"` ||
23 ! -z `find src/hash/*.gperf -newer src/hash/parser_hash.h` ]]
25 echo "Generating hash headers"
26 sh -c "cd src/hash/ && ./generate_headers" || exit 1
30 # If src/parser.o does not exist, or if there are Ragel parsers or parser
31 # header files newer than the existing parser.o, recompile parser.o.
34 if [[ ! -f src/parser.o ||
35 ! -z `find src/parsers/*.{h,rl} -newer src/parser.o` ]]
37 sh -c "cd src/parsers/ && ./compile" || exit 1
38 echo "Building src/parser.c (will take a while)"
39 sh -c "$cc -c src/parser.c -o src/parser.o" || exit 1
47 if [[ ! -f src/libohcount.so ||
48 ! -z `find src/*.{h,c} -newer src/libohcount.so` ]]
50 echo "Building shared library"
51 sh -c "$cc -shared $files -o src/libohcount.so" || exit 1
59 echo "Building Ohcount"
61 sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre" || exit 1
68 echo "Building test suite"
69 sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre" \
75 echo "Running test suite"
76 sh -c "cd test/unit/ && ./run_tests"
81 echo "Generating Ruby bindings"
82 sh -c "swig -ruby -o ruby/ohcount_wrap.c ruby/ohcount.i" || exit 1
83 sh -c "$cc -shared ruby/ohcount_wrap.c $files -o ruby/ohcount.so \
84 -I/usr/lib/ruby/1.8/x86_64-linux/ -lpcre" || exit 1
85 sh -c "cd test/unit/gestalt && ruby gestalt_test.rb"
88 if [ $# -eq 0 ] || [ $1 == "all" ]
94 elif [ $1 == "shared" ]
97 echo "Build successful; libohcount.so is in src/"
98 elif [ $1 == "ohcount" ]
101 echo "Build successful; ohcount is in bin/"
102 elif [ $1 == "tests" ]
106 elif [ $1 == "ruby" ]
109 echo "Build successful; ohcount.so is in ruby/"
110 elif [ $1 == "clean" ]
114 rm test/unit/run_tests
120 echo "Usage: build [all|ohcount|shared|tests|ruby|clean]"