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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#!/usr/bin/env bash
# Build script for Ohcount.
# Written by Mitchell Foral. mitchell<att>caladbolg.net.
# Options
# Change these for your system configuration.
if [ `uname` != "Darwin" ]
then
# Linux
INC_DIR=
LIB_DIR=
if [ `uname` == "FreeBSD" ]
then
INC_DIR=/usr/local/include
LIB_DIR=/usr/local/lib
fi
# You shouldn't have to change the following.
CFLAGS=-O3
CFLAGS="$CFLAGS -DTMP_FILES_ARE_DT_UNKNOWN" # workaround bug on centos/SF servers
WARN="-Wall -Wno-pointer-to-int-cast -Wno-parentheses"
SHARED=-shared
SHARED_NAME=libohcount.so
RB_SHARED=-shared
RB_SHARED_NAME=ohcount.so
else
# Mac OSX
INC_DIR=/opt/local/include
LIB_DIR=/opt/local/lib
# You shouldn't have to change the following.
CFLAGS="-fno-common -g"
WARN="-Wall -Wno-parentheses"
SHARED="-dynamiclib -L$LIB_DIR -lpcre"
SHARED_NAME=libohcount.dylib
RB_SHARED="-dynamic -bundle -lruby"
RB_SHARED_NAME=ohcount.bundle
fi
# C compiler and flags
cc="gcc -fPIC -g $CFLAGS $WARN -I$INC_DIR -L$LIB_DIR"
# Ohcount source files
files="src/sourcefile.c \
src/detector.c \
src/licenses.c \
src/parser.o \
src/loc.c \
src/log.c \
src/diff.c \
src/parsed_language.c \
src/hash/language_hash.c"
# If any src/hash/*.gperf file is newer than the header files (which were
# presumably generated together), regenerate the headers.
build_hash_headers()
{
if [[ -z `ls src/hash/ | grep "_hash.h$"` ||
! -z `find src/hash/*.gperf -newer src/hash/parser_hash.h` ]]
then
echo "Generating hash headers"
sh -c "cd src/hash/ && ./generate_headers" || exit 1
fi
}
# If src/parser.o does not exist, or if there are Ragel parsers or parser
# header files newer than the existing parser.o, recompile parser.o.
build_parser_o()
{
if [[ ! -f src/parser.o ||
! -z `find src/parsers/*.{h,rl} -newer src/parser.o` ]]
then
bash -c "cd src/parsers/ && bash ./compile" || exit 1
echo "Building src/parser.c (will take a while)"
bash -c "$cc -c src/parser.c -o src/parser.o" || exit 1
fi
}
build_shared()
{
build_hash_headers
build_parser_o
if [[ ! -f src/$SHARED_NAME ||
! -z `find src/*.{h,c} -newer src/$SHARED_NAME` ]]
then
echo "Building shared library"
sh -c "$cc $SHARED $files -o src/$SHARED_NAME" || exit 1
fi
}
build_ohcount()
{
build_hash_headers
build_parser_o
echo "Building Ohcount"
mkdir -p bin/
sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre" || exit 1
}
build_test_suite()
{
build_hash_headers
build_parser_o
echo "Building test suite"
sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre" \
|| exit 1
}
run_test_suite()
{
echo "Running test suite"
sh -c "cd test/unit/ && ./run_tests"
}
build_ruby_bindings()
{
arch=`ruby -rmkmf -e 'print Config::expand(CONFIG["arch"])'`
echo "Generating Ruby bindings for $arch"
sh -c "swig -ruby -o ruby/ohcount_wrap.c ruby/ohcount.i" || exit 1
mkdir -p ruby/$arch
sh -c "$cc $RB_SHARED ruby/ohcount_wrap.c $files -o ruby/$arch/$RB_SHARED_NAME \
-I`ruby -rmkmf -e 'print Config::expand(CONFIG["archdir"])'` \
-lpcre" || exit 1
sh -c "cd test/unit/ruby && ruby ruby_test.rb" || exit 1
}
if [ $# -eq 0 ] || [ $1 == "all" ]
then
build_ohcount
build_test_suite
run_test_suite
echo $success
elif [ $1 == "shared" ]
then
build_shared
echo "Build successful; $SHARED_NAME is in src/"
elif [ $1 == "ohcount" ]
then
build_ohcount
echo "Build successful; ohcount is in bin/"
elif [ $1 == "tests" ]
then
build_test_suite
run_test_suite
elif [ $1 == "ruby" ]
then
build_ruby_bindings
echo "Build successful; $RB_SHARED_NAME is in ruby/$arch"
elif [ $1 == "clean" ]
then
rm -f bin/ohcount
rm -f test/unit/run_tests
rm -f src/parser.o
rm -f src/parsers/*.h
rm -f src/hash/*.h
rm -f src/hash/*.c
rm -f src/$SHARED_NAME
rm -f ruby/$RB_SHARED_NAME
rm -rf ruby/`ruby -rmkmf -e 'print Config::expand(CONFIG["arch"])'`/*
else
echo "Usage: build [all|ohcount|shared|tests|ruby|clean]"
fi
|