aboutsummaryrefslogtreecommitdiffstats
path: root/tools/chbuild.sh
blob: 6323dcb2f161ca4a9ad5137f334cced7ee5c48bc (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash

#
# Author: Fabien Poussin
# Date: 21/04/2017
# Version: 1.0
#

renice +10 $$
JOBS=$(grep -c ^processor /proc/cpuinfo)
SKIP_ARRAY=(Win32)
RETCODE=0


function test_skip {
    Array=$1
    SKIP=0
    for var in "${SKIP_ARRAY[@]}"
    do
      if [[ $1 == *"${var}"* ]]; then
        SKIP=1
        break
      fi
    done
    return $SKIP
}

function chbuild {
  projects=$(find $1 -name Makefile -printf '%h ')
  OK=0
  NOK=0
  FAIL=()
  SUCCESS=()
  SKIPPED=()
  for t in $projects
  do
    test_skip $t
    if [ $? -ne 0 ]; then
      printf "SKIPPING: ${t}\n"
      SKIPPED+=($t)
      continue
    fi
    pushd $t > /dev/null
    printf "BUILDING: ${t}\n"
    make --quiet -j $JOBS > /dev/null
    if [ $? -ne 0 ]; then
      ((NOK++))
      FAIL+=($t)
      RETCODE=1
    else
      ((OK++))
      SUCCESS+=($t)
    fi
    popd > /dev/null
  done
  printf "\n${1}: ${OK} builds ok, ${NOK} builds failed\n"
#  printf 'SUCCESS: %s\n' "${SUCCESS[@]}"
  printf 'FAIL: %s\n' "${FAIL[@]}"
  printf 'SKIPPED: %s\n' "${SKIPPED[@]}"
  printf "\n"
  return $NOK
}

if [ -z "$1" ]
  then
    printf "This script looks for Makefiles and tries to build the projects\n"
    printf "Usage: chbuild.sh PATH\n"
    exit 1
fi

chbuild $1

exit $RETCODE