Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 120 lines (109 sloc) 2.85 kB
d1eea11 Initial import of build script.
mitchell authored
1 #!/bin/sh
2 # Build script for Ohcount.
3 # Written by Mitchell Foral. mitchell<att>caladbolg.net.
4
5 # C compiler and flags
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
6 cc="gcc -fPIC -g -Wall -Wno-pointer-to-int-cast -Wno-parentheses"
d1eea11 Initial import of build script.
mitchell authored
7
8 # Ohcount source files
9 files="src/sourcefile.c \
10 src/detector.c \
11 src/licenses.c \
12 src/parser.o \
13 src/loc.c \
14 src/diff.c \
6f64a91 Added Ruby interface.
mitchell authored
15 src/parsed_language.c \
16 src/hash/language_hash.c"
d1eea11 Initial import of build script.
mitchell authored
17
18 # If any src/hash/*.gperf file is newer than the header files (which were
19 # presumably generated together), regenerate the headers.
20 build_hash_headers()
21 {
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
22 if [[ -z `ls src/hash/ | grep "_hash.h$"` ||
d1eea11 Initial import of build script.
mitchell authored
23 ! -z `find src/hash/*.gperf -newer src/hash/parser_hash.h` ]]
24 then
25 echo "Generating hash headers"
26 sh -c "cd src/hash/ && ./generate_headers" || exit 1
27 fi
28 }
29
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.
32 build_parser_o()
33 {
34 if [[ ! -f src/parser.o ||
35 ! -z `find src/parsers/*.{h,rl} -newer src/parser.o` ]]
36 then
37 sh -c "cd src/parsers/ && ./compile" || exit 1
38 echo "Building src/parser.c (will take a while)"
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
39 sh -c "$cc -c src/parser.c -o src/parser.o" || exit 1
40 fi
41 }
42
43 build_shared()
44 {
45 build_hash_headers
46 build_parser_o
47 if [[ ! -f src/libohcount.so ||
48 ! -z `find src/*.{h,c} -newer src/libohcount.so` ]]
49 then
50 echo "Building shared library"
51 sh -c "$cc -shared $files -o src/libohcount.so" || exit 1
d1eea11 Initial import of build script.
mitchell authored
52 fi
53 }
54
55 build_ohcount()
56 {
57 build_hash_headers
58 build_parser_o
59 echo "Building Ohcount"
ee3dc15 Modified build file to create 'bin/' directory if it does not exist.
mitchell authored
60 mkdir -p bin/
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
61 sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre" || exit 1
d1eea11 Initial import of build script.
mitchell authored
62 }
63
64 build_test_suite()
65 {
66 build_hash_headers
67 build_parser_o
68 echo "Building test suite"
69 sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre" \
70 || exit 1
71 }
72
73 run_test_suite()
74 {
75 echo "Running test suite"
76 sh -c "cd test/unit/ && ./run_tests"
77 }
78
6f64a91 Added Ruby interface.
mitchell authored
79 build_ruby_bindings()
80 {
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 }
86
d1eea11 Initial import of build script.
mitchell authored
87 if [ $# -eq 0 ] || [ $1 == "all" ]
88 then
89 build_ohcount
90 build_test_suite
91 run_test_suite
92 echo $success
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
93 elif [ $1 == "shared" ]
94 then
95 build_shared
96 echo "Build successful; libohcount.so is in src/"
d1eea11 Initial import of build script.
mitchell authored
97 elif [ $1 == "ohcount" ]
98 then
99 build_ohcount
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
100 echo "Build successful; ohcount is in bin/"
d1eea11 Initial import of build script.
mitchell authored
101 elif [ $1 == "tests" ]
102 then
103 build_test_suite
104 run_test_suite
6f64a91 Added Ruby interface.
mitchell authored
105 elif [ $1 == "ruby" ]
106 then
107 build_ruby_bindings
108 echo "Build successful; ohcount.so is in ruby/"
d1eea11 Initial import of build script.
mitchell authored
109 elif [ $1 == "clean" ]
110 then
a7b1053 Add option to build file to build Ohcount as shared library.
mitchell authored
111 rm src/libohcount.so
d1eea11 Initial import of build script.
mitchell authored
112 rm bin/ohcount
113 rm test/unit/run_tests
114 rm src/parser.o
115 rm src/parsers/*.h
6f64a91 Added Ruby interface.
mitchell authored
116 rm src/hash/*.c
d1eea11 Initial import of build script.
mitchell authored
117 else
6f64a91 Added Ruby interface.
mitchell authored
118 echo "Usage: build [all|ohcount|shared|tests|ruby|clean]"
d1eea11 Initial import of build script.
mitchell authored
119 fi
Something went wrong with that request. Please try again.