2015-08-10 20:49:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-03-16 03:51:23 +00:00
|
|
|
# This is bash lib file for the convenience build scripts
|
|
|
|
# Don't call this script directly
|
2016-07-18 00:23:33 +00:00
|
|
|
# Jacob Alexander 2015-2016
|
|
|
|
|
|
|
|
# Check if compiler has been overridden by the environment
|
|
|
|
Compiler=${COMPILER:-${Compiler}}
|
|
|
|
|
|
|
|
# Append to BuildPath, depending on which compiler this is
|
|
|
|
BuildPath=${BuildPath}.${Compiler}
|
2015-03-16 03:51:23 +00:00
|
|
|
|
|
|
|
# Make sure all of the relevant variables have been set
|
|
|
|
# NOTE: PartialMaps and DefaultMap do not have to be set
|
|
|
|
VariablesList=(BuildPath BaseMap ScanModule MacroModule OutputModule DebugModule Chip Compiler)
|
|
|
|
ExitEarly=false
|
|
|
|
for var in ${VariablesList[@]}; do
|
|
|
|
if [ -z ${!var+x} ]; then
|
|
|
|
echo "ERROR: Unset variable => '${var}'"
|
|
|
|
ExitEarly=true
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Error was detected, exit immediately
|
|
|
|
if $ExitEarly; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# Prepare PartialMaps
|
|
|
|
PartialMapsExpanded="${PartialMaps[1]}"
|
|
|
|
count=2 # Start the loop at index 2
|
|
|
|
while [ "$count" -le "${#PartialMaps[@]}" ]; do
|
|
|
|
PartialMapsExpanded="${PartialMapsExpanded};${PartialMaps[count]}"
|
|
|
|
count=$(($count+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Internal Variables
|
2016-07-18 00:23:33 +00:00
|
|
|
CMakeListsPath=${CMakeListsPath:-"../.."}
|
2015-03-16 03:51:23 +00:00
|
|
|
PROG_NAME=$(basename $0)
|
|
|
|
|
|
|
|
|
|
|
|
# Process the command line arguments (if any)
|
|
|
|
while (( "$#" >= "1" )); do
|
|
|
|
# Scan each argument
|
|
|
|
key="$1"
|
|
|
|
case $key in
|
|
|
|
-c|--cmakelists-path)
|
|
|
|
CMakeListsPath="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-f|--force-rebuild)
|
|
|
|
# Remove the old directory first
|
|
|
|
rm -rf "${BuildPath}"
|
|
|
|
;;
|
|
|
|
-o|--output-path)
|
|
|
|
BuildPath="$2"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h|--help)
|
|
|
|
echo "Usage: $PROG_NAME [options...]"
|
|
|
|
echo ""
|
|
|
|
echo "Convenience script to build the source of a given keyboard."
|
|
|
|
echo "Edit '$PROG_NAME' to configure the keyboard options such as KLL layouts."
|
|
|
|
echo ""
|
|
|
|
echo "Arguments:"
|
|
|
|
echo " -c, --cmakelists-path PATH Set the path of CMakeLists.txt"
|
|
|
|
echo " Default: ${CMakeListsPath}"
|
|
|
|
echo " -f, --force-rebuild Deletes the old build directory and rebuilds from scratch."
|
|
|
|
echo " -o, --output-path PATH Set the path of the build files."
|
|
|
|
echo " Default: ${BuildPath}"
|
|
|
|
echo " -h, --help This message."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "INVALID ARG: '$1'"
|
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Shift to the next argument
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Run CMake commands
|
|
|
|
mkdir -p "${BuildPath}"
|
|
|
|
cd "${BuildPath}"
|
2016-08-01 03:41:00 +00:00
|
|
|
|
|
|
|
# Cygwin
|
|
|
|
if [[ $(uname -s) == MINGW32_NT* ]] || [[ $(uname -s) == CYGWIN* ]]; then
|
|
|
|
if [[ -z "$wincmake_path" ]]; then
|
|
|
|
echo "Error wincmake_path environment variable has not been set, see -> https://github.com/kiibohd/controller/wiki/Windows-Setup"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-31 08:09:44 +00:00
|
|
|
echo "Cygwin Build"
|
2016-08-01 03:41:00 +00:00
|
|
|
PATH="$wincmake_path":"${PATH}" cmake -DCHIP="${Chip}" -DCOMPILER="${Compiler}" -DScanModule="${ScanModule}" -DMacroModule="${MacroModule}" -DOutputModule="${OutputModule}" -DDebugModule="${DebugModule}" -DBaseMap="${BaseMap}" -DDefaultMap="${DefaultMap}" -DPartialMaps="${PartialMapsExpanded}" "${CMakeListsPath}" -G 'Unix Makefiles'
|
|
|
|
return_code=$?
|
|
|
|
|
|
|
|
# Linux / Mac (and everything else)
|
|
|
|
else
|
|
|
|
cmake -DCHIP="${Chip}" -DCOMPILER="${Compiler}" -DScanModule="${ScanModule}" -DMacroModule="${MacroModule}" -DOutputModule="${OutputModule}" -DDebugModule="${DebugModule}" -DBaseMap="${BaseMap}" -DDefaultMap="${DefaultMap}" -DPartialMaps="${PartialMapsExpanded}" "${CMakeListsPath}"
|
|
|
|
return_code=$?
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2015-10-18 19:40:18 +00:00
|
|
|
if [ $return_code != 0 ] ; then
|
2016-08-31 08:09:44 +00:00
|
|
|
echo "Error in cmake. Exiting..."
|
|
|
|
exit $return_code
|
2015-10-18 19:40:18 +00:00
|
|
|
fi
|
|
|
|
|
2015-03-16 03:51:23 +00:00
|
|
|
make
|
2015-10-18 19:40:18 +00:00
|
|
|
return_code=$?
|
|
|
|
if [ $return_code != 0 ] ; then
|
2016-08-31 08:09:44 +00:00
|
|
|
echo "Error in make. Exiting..."
|
|
|
|
exit $return_code
|
2015-10-18 19:40:18 +00:00
|
|
|
fi
|
2015-03-16 03:51:23 +00:00
|
|
|
|
|
|
|
echo "Firmware has been compiled into: '${BuildPath}'"
|
2015-08-22 06:23:52 +00:00
|
|
|
cd -
|
2015-03-16 03:51:23 +00:00
|
|
|
|