summaryrefslogtreecommitdiff
path: root/apps/compiler/compiler.sh
blob: dcb94a6b65b4276c87b69a6caa37cf82b626b5d1 (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
74
75
76
#!/usr/bin/env bash

set -e

CURRENT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

source "$CURRENT_PATH/includes/includes.sh"

function run_option() {
    re='^[0-9]+$'
    if [[ $1 =~ $re ]] && test "${comp_functions[$1-1]+'test'}"; then
        ${comp_functions[$1-1]}
    elif [ -n "$(type -t comp_$1)" ] && [ "$(type -t comp_$1)" = function ]; then
        fun="comp_$1"
        $fun
    else
        echo "invalid option, use --help option for the commands list"
    fi
}

function comp_quit() {
    exit 0
}

comp_options=(
    "build: Configure and compile"
    "clean: Clean build files"
    "configure: Run CMake"
    "compile: Compile only"
    "all: clean, configure and compile"
    "ccacheClean: Clean ccache files, normally not needed"
    "ccacheShowStats: show ccache statistics"
    "quit: Close this menu")
comp_functions=(
    "comp_build"
    "comp_clean"
    "comp_configure"
    "comp_compile"
    "comp_all"
    "comp_ccacheClean"
    "comp_ccacheShowStats"
    "comp_quit")

PS3='[ Please enter your choice ]: '

runHooks "ON_AFTER_OPTIONS" #you can create your custom options

function _switch() {
    _reply="$1"
    _opt="$2"

    case $_reply in
        ""|"--help")
            echo "Available commands:"
            printf '%s\n' "${options[@]}"
            ;;
        *)
            run_option $_reply $_opt
        ;;
    esac
}


while true
do
    # run option directly if specified in argument
    [ ! -z $1 ] && _switch $@
    [ ! -z $1 ] && exit 0

    select opt in "${comp_options[@]}"
    do
        echo "==== ACORE COMPILER ===="
        _switch $REPLY
        break;
    done
done