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