Cleaning CMAke
[apps/low-level-can-service.git] / CAN-config-generator / build.sh
1 #!/bin/bash
2
3 function build {
4         echo "ACTION: build"
5         if [ ! -d "$1/$2" ]; then
6                 echo "INFO: build dir ($1/$2) doesn't exist, created it!"
7                 mkdir -p "$1/$2"
8         fi
9         pushd "$1/$2"
10         #cd "$1/$2"
11         cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=$3 $1
12         make
13         popd
14 }
15
16 function clean {
17         echo "ACTION: clean"
18         if [ -d "$1/$2" ]; then
19                 rm -vrf "$1/$2"
20         fi
21 }
22
23 function rebuild {
24         clean $1 $2
25         build $1 $2 $3
26 }
27
28 function printhelp {
29         echo "Usage: build.sh <action> <subdir> [config]"
30         echo "  action: can be one of the following"
31         echo "          build: build this project."
32         echo "          rebuild: rebuild this project."
33         echo "          clean: clean the previous build."
34         echo "          install: install the build result."
35         echo "  subdir: the subdir into which the build is done."
36         echo "  config: can be Debug or Release. Ignored if the action is 'clean'."
37 }
38
39 function checkparams {
40         if [ "$#" -ne "$(($1+1))" ]; then
41                 echo "ERROR: Wrong number of parameters, expected $1 but got $(($#-1))"
42                 printhelp
43                 exit 1
44         fi
45 }
46
47 function main {
48         CURRENT_DIR=$( dirname "$(readlink -f "$0")" )
49         echo "Current script: $CURRENT_DIR"
50
51         if [ "$#" -lt "1" ]; then
52                 echo "ERROR: At least <action> must be specified!"
53                 exit 1
54         fi
55
56         case "$1" in
57                 "build")
58                         checkparams 3 $*
59                         build $CURRENT_DIR $2 $3
60                         ;;
61                 "rebuild")
62                         checkparams 3 $*
63                         rebuild $CURRENT_DIR $2 $3
64                         ;;
65                 "clean")
66                         checkparams 2 $*
67                         clean $CURRENT_DIR $2
68                         ;;
69                 "install")
70                         checkparams 3 $*
71                         echo "ERROR: Not implemented yet!"
72                         ;;
73                 *)
74                         echo "ERROR: Unknown action '$3'!"
75                         exit 1 
76                         ;;
77         esac
78 }
79
80 main $*
81