Mercurial > louis > kiibohd-controller
annotate Keyboards/cmake.bash @ 401:99f93dec8fea
Start removing select Linux-isms
bash might not be in /bin. Don't expect it there.
author | Dan McGregor <dan.mcgregor@usask.ca> |
---|---|
date | Mon, 10 Aug 2015 14:49:46 -0600 |
parents | 4ca343d30b73 |
children |
rev | line source |
---|---|
401
99f93dec8fea
Start removing select Linux-isms
Dan McGregor <dan.mcgregor@usask.ca>
parents:
393
diff
changeset
|
1 #!/usr/bin/env bash |
312
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
2 # This is bash lib file for the convenience build scripts |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
3 # Don't call this script directly |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
4 # Jacob Alexander 2015 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
5 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
6 # Make sure all of the relevant variables have been set |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
7 # NOTE: PartialMaps and DefaultMap do not have to be set |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
8 VariablesList=(BuildPath BaseMap ScanModule MacroModule OutputModule DebugModule Chip Compiler) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
9 ExitEarly=false |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
10 for var in ${VariablesList[@]}; do |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
11 if [ -z ${!var+x} ]; then |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
12 echo "ERROR: Unset variable => '${var}'" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
13 ExitEarly=true |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
14 fi |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
15 done |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
16 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
17 # Error was detected, exit immediately |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
18 if $ExitEarly; then |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
19 exit 1 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
20 fi |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
21 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
22 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
23 # Prepare PartialMaps |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
24 PartialMapsExpanded="${PartialMaps[1]}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
25 count=2 # Start the loop at index 2 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
26 while [ "$count" -le "${#PartialMaps[@]}" ]; do |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
27 PartialMapsExpanded="${PartialMapsExpanded};${PartialMaps[count]}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
28 count=$(($count+1)) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
29 done |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
30 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
31 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
32 # Internal Variables |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
33 CMakeListsPath="../.." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
34 PROG_NAME=$(basename $0) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
35 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
36 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
37 # Process the command line arguments (if any) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
38 while (( "$#" >= "1" )); do |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
39 # Scan each argument |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
40 key="$1" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
41 case $key in |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
42 -c|--cmakelists-path) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
43 CMakeListsPath="$2" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
44 shift |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
45 ;; |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
46 -f|--force-rebuild) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
47 # Remove the old directory first |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
48 rm -rf "${BuildPath}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
49 ;; |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
50 -o|--output-path) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
51 BuildPath="$2" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
52 shift |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
53 ;; |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
54 -h|--help) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
55 echo "Usage: $PROG_NAME [options...]" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
56 echo "" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
57 echo "Convenience script to build the source of a given keyboard." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
58 echo "Edit '$PROG_NAME' to configure the keyboard options such as KLL layouts." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
59 echo "" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
60 echo "Arguments:" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
61 echo " -c, --cmakelists-path PATH Set the path of CMakeLists.txt" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
62 echo " Default: ${CMakeListsPath}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
63 echo " -f, --force-rebuild Deletes the old build directory and rebuilds from scratch." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
64 echo " -o, --output-path PATH Set the path of the build files." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
65 echo " Default: ${BuildPath}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
66 echo " -h, --help This message." |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
67 exit 1 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
68 ;; |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
69 *) |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
70 echo "INVALID ARG: '$1'" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
71 exit 2 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
72 ;; |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
73 esac |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
74 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
75 # Shift to the next argument |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
76 shift |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
77 done |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
78 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
79 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
80 # Run CMake commands |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
81 ## TODO Check for windows and do windows specific things ## |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
82 mkdir -p "${BuildPath}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
83 cd "${BuildPath}" |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
84 cmake -DCHIP="${Chip}" -DCOMPILER="${Compiler}" -DScanModule="${ScanModule}" -DMacroModule="${MacroModule}" -DOutputModule="${OutputModule}" -DDebugModule="${DebugModule}" -DBaseMap="${BaseMap}" -DDefaultMap="${DefaultMap}" -DPartialMaps="${PartialMapsExpanded}" "${CMakeListsPath}" |
393
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
85 return_code=$? |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
86 if [ $return_code != 0 ] ; then |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
87 echo "Error in cmake. Exiting..." |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
88 exit $return_code |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
89 fi |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
90 |
312
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
91 make |
393
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
92 return_code=$? |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
93 if [ $return_code != 0 ] ; then |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
94 echo "Error in make. Exiting..." |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
95 exit $return_code |
4ca343d30b73
Exit quickly when cmake or make fail
Mason Donahue <masond+github@gmail.com>
parents:
373
diff
changeset
|
96 fi |
312
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
97 |
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
98 echo "Firmware has been compiled into: '${BuildPath}'" |
373
83cb0d4b57e3
Updating convenience build scripts to build Left and Right sides
Jacob Alexander <haata@kiibohd.com>
parents:
312
diff
changeset
|
99 cd - |
312
c5f083de1838
Adding convenience compiler scripts.
Jacob Alexander <haata@kiibohd.com>
parents:
diff
changeset
|
100 |