input joy sleep wake, revisit string cat code
[vg.git] / vg_build.sh
1 #!/bin/bash
2 # Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved
3 #
4 # Build script utilities
5 # Usage:
6 # 1) in your build script, define the function
7 #
8 # vg_command(){
9 #
10 # }
11 #
12 # it should handle $1 as the switch for different commands
13 # if you want to run an existing command, use run_command <x> to do it.
14 #
15 #
16 # 2) at the end of the build script, include:
17 #
18 # source vg/vg_build.sh
19 #
20 # this runs the triggers that are passed in from the invoker
21 #
22 #
23 # 3) targets with standard tool support should run the command:
24 #
25 # vg_compile_tools
26 #
27 # make sure _compiler _options, and _ext are setup for that target
28 # these will only invoke the tooling compilers if tools is passed to the
29 # build script.
30 #
31 # Util
32 # ==============================================================================
33
34 error(){
35 echo -e "\033[1;31mError:\e[0m $@"
36 exit 1
37 }
38
39 warning(){
40 echo -e "\033[1;33mWarning:\e[0m $@"
41 }
42
43 success(){
44 echo -e "\033[1;32mSuccess:\e[0m $@"
45 }
46
47 logit(){
48 echo -e "\033[0;37m$@\e[0m"
49 }
50
51 titleit(){
52 echo ""
53 echo -e "\033[1;35m$@\e[0m"
54 echo "================================================================"
55 echo ""
56 }
57
58 titleit " vg_build.sh ver: 2.0\n"
59
60 # Compile shit
61 # ==============================================================================
62
63 compiler_cache="ccache"
64
65 # Autodetect ccache unavailible
66 if ! [ -x "$( command -v $compiler_cache )" ]; then
67 compiler_cache=""
68 fi
69
70 compile_x(){
71 cmd="$compiler_cache $_compiler
72 $_options
73 $_warnings
74 $_include
75 $_library
76 $_src
77 -o $_folder/$_dst$_ext
78 $_link
79 $_epilogue"
80
81 logit " $cmd\n"
82 $cmd
83
84 if [ $? -ne 0 ]; then
85 error "compiler failed"
86 fi
87
88 success "Compiled item\n"
89 }
90
91 # Tools scripts
92 # ==============================================================================
93 enable_tools=false
94
95 vg_compile_tools() {
96 if [ $enable_tools = true ]; then source vg/src/tools.sh; fi
97 }
98
99 run_command(){
100 case "$1" in
101 tools)
102 enable_tools=true
103 ;;
104 "")
105 return
106 ;;
107 *)
108 vg_command $1
109 esac
110 }
111
112 run_command $1
113 run_command $2
114 run_command $3
115 run_command $4
116 run_command $5
117 run_command $6
118 run_command $7
119 run_command $8
120 run_command $9