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