summaryrefslogtreecommitdiffstats
path: root/tapset/test/build.sh
blob: 05b64f67482b5e8e88e7df1ff940cd0d99d60953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function usage {
   echo -ne " \033[1mUsage:\033[0m build [compile|clean|run]\n"
   echo -ne " \033[1mDo not remove this script from this dir!\033[0m\n"
   exit
}
function clean {
   rm -rf bin
}
function compile {
   if [ ! -d bin ]; then
      mkdir bin
   else
      rm -rf bin/*
   fi
   for file in `ls *.c`
   do
      execn=e_`echo $file|cut -d"." -f1`
      # some depend on external realtime lib...
      if [[ `echo $file|grep clock|wc -l` -gt 0
         || `echo $file|grep timer|wc -l` -gt 0 ]]
      then
         gcc -lrt $file -o bin/$execn
      else
         gcc $file -o bin/$execn
      fi
   done
   if [ `ls *.c|wc -l` -eq `ls bin|wc -l` ]; then
      echo "Success: compiled `ls bin|wc -l` files."
   else
      echo "Some files failed to compile! Try again."
   fi
}
function run {
   if [ ! -d bin -o `ls bin|wc -l` -le 0 ]; then
      echo "No compiled C files! First build compile!"
      exit
   else
      for execn in `ls bin`
      do
         echo "$execn _______________________________"
         ./bin/$execn
      done
   fi
}

if [ $# -ne 1 ];          then
   usage
elif [ $1 == "compile" ]; then
   compile
elif [ $1 == "clean" ];   then
   clean
elif [ $1 == "run" ];     then
   run
else
   usage
fi