]> gitweb @ CieloNegro.org - autobuild.git/blob - src/main.bash
src/main.bash: better help message
[autobuild.git] / src / main.bash
1 function runMake () {
2     run gmake -w -j $(detectNumCPUs) $@
3 }
4
5 function configure () {
6     if [[ ! -f configure.ac && ! -f configure.in ]]; then
7         echo "ERROR: Neither configure.ac nor configure.in exists in the current directory." >&2
8         return 1
9     fi
10
11     if [[ ! -f configure ]]; then
12         run autoreconf -v -i -f
13     fi
14
15     if [[ ! -f "_build/Makefile" ]]; then
16         run mkdir -p _build
17         run pushd _build
18         run ../configure "${configArgs[@]}"
19         run popd
20     fi
21 }
22
23 function build () {
24     configure
25     runMake -C "_build" $buildTarget
26 }
27
28 function doc () {
29     configure
30     runMake -C "_build/$docDirectory" $docTarget
31 }
32
33 function check () {
34     build
35     runMake -C "_build" check "$@"
36 }
37
38 function clean () {
39     run rm -rf "_build"
40 }
41
42 function dist () {
43     configure
44     runMake -C "_build" dist
45 }
46
47 function install () {
48     build
49     runMake -C "_build" install "$0"
50 }
51
52 function usage () {
53     cat <<EOF >&2
54 Usage: $0 [COMMAND]
55
56 This is an automation script designed to work with autotools. It creates a
57 directory "./_build" and builds any files inside it.
58
59 If no COMMAND is given, it defaults to "build".
60
61 Commands:
62     build          run "$0 configure" then make(1).
63     check [ARG]    run "$0 build" then "make check [ARG]".
64     configure      run autoreconf(1) and "./configure" if necessary.
65     clean          run "rm -rf _build"
66     dist           run "make dist"
67     doc            similar to "$0 build" but only build the documentation.
68     install [ARG]  run "$0 build" then "make install [ARG]".
69
70 Please report any bugs, feature requests, and pull requests (the most
71 preferred!) to the maintainer presented in the preamble of the "$0" itself.
72 EOF
73     return 1
74 }
75
76 function main () {
77     local cmd
78     case "$1" in
79         ""|"build" ) cmd="build"    ;;
80         "configure") cmd="configure";;
81         "doc"      ) cmd="doc"      ;;
82         "check"    ) cmd="check"    ;;
83         "clean"    ) cmd="clean"    ;;
84         "dist"     ) cmd="dist"     ;;
85         "install"  ) cmd="install"  ;;
86         *)           cmd="usage"    ;;
87     esac
88     if (( $# > 0 )); then
89         shift
90     fi
91     "$cmd" "$@"
92 }
93
94 main "$@"