]> gitweb @ CieloNegro.org - autobuild.git/blob - src/main.bash
4e87e8cf8b5e8987ea7b15b0dc6a7208248a014b
[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 distcheck () {
48     configure
49     runMake -C "_build" distcheck
50 }
51
52 function install () {
53     build
54     runMake -C "_build" install "$0"
55 }
56
57 function usage () {
58     cat <<EOF >&2
59 Usage: $0 [COMMAND]
60
61 This is an automation script designed to work with autotools. It creates a
62 directory "./_build" and builds any files inside it.
63
64 If no COMMAND is given, it defaults to "build".
65
66 Commands:
67     build          run "$0 configure" then make(1).
68     check [ARG]    run "$0 build" then "make check [ARG]".
69     configure      run autoreconf(1) and "./configure" if necessary.
70     clean          run "rm -rf _build"
71     dist           run "make dist"
72     distcheck      run "$0 configure" then "make distcheck"
73     doc            similar to "$0 build" but only build the documentation.
74     install [ARG]  run "$0 build" then "make install [ARG]".
75
76 Please report any bugs, feature requests, and pull requests (the most
77 preferred!) to the maintainer presented in the preamble of the "$0" itself.
78 EOF
79     return 1
80 }
81
82 function main () {
83     local cmd
84     case "$1" in
85         ""|"build" ) cmd="build"    ;;
86         "configure") cmd="configure";;
87         "doc"      ) cmd="doc"      ;;
88         "check"    ) cmd="check"    ;;
89         "clean"    ) cmd="clean"    ;;
90         "dist"     ) cmd="dist"     ;;
91         "distcheck") cmd="distcheck";;
92         "install"  ) cmd="install"  ;;
93         *)           cmd="usage"    ;;
94     esac
95     if (( $# > 0 )); then
96         shift
97     fi
98     "$cmd" "$@"
99 }
100
101 main "$@"