2 # -----------------------------------------------------------------------------
3 # Build automation script designed to work with autotools.
4 # -----------------------------------------------------------------------------
7 # -----------------------------------------------------------------------------
8 # Functions used by Build.rc
11 function setPrefix () {
12 if (( $# != 1 )); then
13 echo "Usage: $0 PREFIX" >&2
20 if (( $# == 0 )); then
21 echo "Usage: $0 VAR [PATH, ...]" >&2
26 local paths=("${@:2}")
32 export $var="$paths";;
34 export $var="${paths[0]}"
36 for path in "${paths[@]:1}"; do
37 local val=$(eval echo \$$var)
38 export $var="$val:$path"
42 # Special case for PATH: we prepend "$prefix/bin" to it.
43 if [[ $var = "PATH" ]]; then
44 PATH="$prefix/bin:$PATH"
49 function setConfigArgs () {
58 function setBuildTarget () {
59 if (( $# != 1 )); then
60 echo "Usage: $0 TARGET" >&2
67 function setDocDirectory () {
68 if (( $# != 1 )); then
69 echo "Usage: $0 DIRECTORY" >&2
76 function setDocTarget () {
77 if (( $# != 1 )); then
78 echo "Usage: $0 TARGET" >&2
84 # -----------------------------------------------------------------------------
87 setPrefix "/usr/local"
88 setPath PATH "/usr/bin" "/bin"
94 if [ -f "Build.rc" ]; then
98 # -----------------------------------------------------------------------------
102 if (( $# == 0 )); then
103 echo "run: Usage: run CMD [ARG...]" >&2
119 function detectNumCPUs () {
120 if sysctl -n "hw.ncpu" 2>/dev/null; then
121 # This works for most BSDs.
123 elif grep -qF processor /proc/cpuinfo 2>/dev/null; then
125 grep -cF processor /proc/cpuinfo
127 echo "WARNING: I don't know how to detect the number of processors on this platform." >&2
132 function runMake () {
133 run gmake -w -j $(detectNumCPUs) $@
136 function configure () {
137 if [[ ! -f configure.ac && ! -f configure.in ]]; then
138 echo "ERROR: Neither configure.ac nor configure.in exists in the current directory." >&2
142 if [[ ! -f configure ]]; then
143 run autoreconf -v -i -f
146 if [[ ! -f "_build/Makefile" ]]; then
149 run ../configure "${configArgs[@]}"
156 runMake -C "_build" $buildTarget
161 runMake -C "_build/$docDirectory" $docTarget
166 runMake -C "_build" check
175 runMake -C "_build" dist
178 function install () {
180 runMake -C "_build" install
189 "install" ) install;;
191 echo "Usage: $0 [build | doc | check | clean | dist | install]" >&2