]> gitweb @ CieloNegro.org - autobuild.git/blob - src/main.bash
The 'source' built-in command tries to search for the given filename in PATH when...
[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 other () {
62     runMake -C "_build" "$@"
63 }
64
65 function usage () {
66     cat <<EOF >&2
67 Usage: $0 [COMMAND]
68
69 This is an automation script designed to work with autotools. It creates a
70 directory "./_build" and builds any files inside it. Its behaviour is
71 somewhat configurable: See "./Build.rc" for details.
72
73 If no COMMAND is given, it defaults to "build".
74
75 Commands:
76     build          run "$0 configure" then make(1)
77     check [ARGS]   run "$0 build" then "make check [ARGS]"
78     autogen        run autoreconf(1)
79     configure      run "$0 autogen" and "./configure" if necessary
80     clean          run "rm -rf _build"
81     dist           run "make dist"
82     distcheck      run "$0 configure" then "make distcheck"
83     doc            similar to "$0 build" but only build the documentation
84     help           print this message
85     install [ARGS] run "$0 build" then "make install [ARGS]"
86     -- [ARGS]      run "make [ARGS]"
87
88 Please report any bugs, feature requests, and pull requests (the most
89 preferred!) to the maintainer presented in the preamble of the "$0" itself.
90 EOF
91     return 1
92 }
93
94 function main () {
95     local cmd
96     case "$1" in
97         ""|"build" ) cmd="build"    ;;
98         "autogen"  ) cmd="autogen"  ;;
99         "configure") cmd="configure";;
100         "doc"      ) cmd="doc"      ;;
101         "check"    ) cmd="check"    ;;
102         "clean"    ) cmd="clean"    ;;
103         "dist"     ) cmd="dist"     ;;
104         "distcheck") cmd="distcheck";;
105         "help"     ) cmd="usage"    ;;
106         "install"  ) cmd="install"  ;;
107         "--"       ) cmd="other"    ;;
108         *)           cmd="usage"    ;;
109     esac
110     if (( $# > 0 )); then
111         shift
112     fi
113     "$cmd" "$@"
114 }
115
116 main "$@"