Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

cmake.bash 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env bash
  2. # This is bash lib file for the convenience build scripts
  3. # Don't call this script directly
  4. # Jacob Alexander 2015-2016
  5. # Check if compiler has been overridden by the environment
  6. Compiler=${COMPILER:-${Compiler}}
  7. # Append to BuildPath, depending on which compiler this is
  8. BuildPath=${BuildPath}.${Compiler}
  9. # Make sure all of the relevant variables have been set
  10. # NOTE: PartialMaps and DefaultMap do not have to be set
  11. VariablesList=(BuildPath Chip Compiler)
  12. ExitEarly=false
  13. for var in ${VariablesList[@]}; do
  14. if [ -z ${!var+x} ]; then
  15. echo "ERROR: Unset variable => '${var}'"
  16. ExitEarly=true
  17. fi
  18. done
  19. # Error was detected, exit immediately
  20. if $ExitEarly; then
  21. exit 1
  22. fi
  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. # Internal Variables
  31. CMakeListsPath="../.."
  32. PROG_NAME=$(basename $0)
  33. # Process the command line arguments (if any)
  34. while (( "$#" >= "1" )); do
  35. # Scan each argument
  36. key="$1"
  37. case $key in
  38. -c|--cmakelists-path)
  39. CMakeListsPath="$2"
  40. shift
  41. ;;
  42. -f|--force-rebuild)
  43. # Remove the old directory first
  44. rm -rf "${BuildPath}"
  45. ;;
  46. -o|--output-path)
  47. BuildPath="$2"
  48. shift
  49. ;;
  50. -h|--help)
  51. echo "Usage: $PROG_NAME [options...]"
  52. echo ""
  53. echo "Convenience script to build the source of a given keyboard."
  54. echo "Edit '$PROG_NAME' to configure the keyboard options such as KLL layouts."
  55. echo ""
  56. echo "Arguments:"
  57. echo " -c, --cmakelists-path PATH Set the path of CMakeLists.txt"
  58. echo " Default: ${CMakeListsPath}"
  59. echo " -f, --force-rebuild Deletes the old build directory and rebuilds from scratch."
  60. echo " -o, --output-path PATH Set the path of the build files."
  61. echo " Default: ${BuildPath}"
  62. echo " -h, --help This message."
  63. exit 1
  64. ;;
  65. *)
  66. echo "INVALID ARG: '$1'"
  67. exit 2
  68. ;;
  69. esac
  70. # Shift to the next argument
  71. shift
  72. done
  73. # Run CMake commands
  74. mkdir -p "${BuildPath}"
  75. cd "${BuildPath}"
  76. # Cygwin
  77. if [[ $(uname -s) == MINGW32_NT* ]] || [[ $(uname -s) == CYGWIN* ]]; then
  78. if [[ -z "$wincmake_path" ]]; then
  79. echo "Error wincmake_path environment variable has not been set, see -> https://github.com/kiibohd/controller/wiki/Windows-Setup"
  80. exit 1
  81. fi
  82. echo "Cygwin Build"
  83. PATH="$wincmake_path":"${PATH}" cmake -DCHIP="${Chip}" -DCOMPILER="${Compiler}" "${CMakeListsPath}" -G 'Unix Makefiles'
  84. # Linux / Mac (and everything else)
  85. else
  86. cmake -DCHIP="${Chip}" -DCOMPILER="${Compiler}" "${CMakeListsPath}"
  87. return_code=$?
  88. fi
  89. if [ $return_code != 0 ] ; then
  90. echo "Error in cmake. Exiting..."
  91. exit $return_code
  92. fi
  93. make
  94. return_code=$?
  95. if [ $return_code != 0 ] ; then
  96. echo "Error in make. Exiting..."
  97. exit $return_code
  98. fi
  99. echo "Firmware has been compiled into: '${BuildPath}'"
  100. cd -