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