0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-01-23 01:58:59 +00:00
MarlinFirmware/buildroot/bin/build_example
2024-08-24 20:03:12 -05:00

129 lines
3.7 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Usage:
#
# build_example -b|--base=<folder> - Configurations root folder (e.g., ./.pio/build-BRANCH)
# -c|--config=<path> - Path of the configs to build (within config/examples)
# [-e|--export=N] - Set CONFIG_EXPORT before build and export into the config folder
# [-n|--nofail] - Don't stop on a failed build
# [-r|--reveal] - Reveal the config folder after the build
# [-h|--help] - Print usage and exit
# [--allow] - Allow this script to run standalone
#
HERE=`dirname $0`
. "$HERE/mfutil"
# Get arguments
CLEANER=1
ALLOW=""
BASE=""
CONFIG=""
REVEAL=""
EXPNUM=""
NOFAIL=""
while getopts 'b:c:e:hinr-:' OFLAG; do
case "${OFLAG}" in
b) BASE="$OPTARG" ;;
c) CONFIG="$OPTARG" ;;
e) EXPNUM="$OPTARG" ;;
h) EXIT_USAGE=1 ; break ;;
n) NOFAIL=1 ;;
r) REVEAL=1 ;;
-) IFS="=" read -r ONAM OVAL <<< "$OPTARG"
case "$ONAM" in
allow) ALLOW=1 ;;
base) BASE="$OVAL" ;;
config) CONFIG="$OVAL" ;;
export) EXPNUM="$OVAL" ;;
help) EXIT_USAGE=1 ; break ;;
nofail) NOFAIL=1 ;;
reveal) REVEAL=1 ;;
*) EXIT_USAGE=2 ; echo "$SELF: unrecognized option \`--$ONAM'" ; break ;;
esac
;;
esac
done
[[ $ALLOW || $SHLVL -gt 2 ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; }
# Make sure the examples exist
SUB1="$BASE/config/examples"
[[ -d "$SUB1" ]] || { echo "--base $BASE doesn't contain config/examples" ; exit 1 ; }
# Make sure the specific config folder exists
SUB=$SUB1/$CONFIG
[[ -d "$SUB" ]] || { echo "--config $CONFIG doesn't exist" ; exit 1 ; }
compgen -G "${SUB}Con*.h" > /dev/null || { echo "No configuration files found in $SUB" ; exit 1 ; }
# Delete any previous exported configs
rm -f Marlin/Config.h Marlin/Config-export.h
echo "Getting configuration files from $SUB"
cp "$BASE/config/default"/*.h Marlin/
cp "$SUB"/Config.h Marlin/ 2>/dev/null
cp "$SUB"/Configuration.h Marlin/ 2>/dev/null
cp "$SUB"/Configuration_adv.h Marlin/ 2>/dev/null
cp "$SUB"/_Bootscreen.h Marlin/ 2>/dev/null
cp "$SUB"/_Statusscreen.h Marlin/ 2>/dev/null
set -e
# Strip #error lines from Configuration.h
IFS=$'\n'; set -f
$SED -i~ -e "20,30{/#error/d}" Marlin/Configuration.h
rm Marlin/Configuration.h~
unset IFS; set +f
# Suppress fatal warnings
if ((CLEANER)); then
opt_add NO_CONTROLLER_CUSTOM_WIRING_WARNING
opt_add NO_AUTO_ASSIGN_WARNING
opt_add NO_CREALITY_DRIVER_WARNING
opt_add DIAG_JUMPERS_REMOVED
opt_add DIAG_PINS_REMOVED
opt_add NO_MK3_FAN_PINS_WARNING
opt_add NO_USER_FEEDBACK_WARNING
opt_add NO_Z_SAFE_HOMING_WARNING
opt_add NO_LCD_CONTRAST_WARNING
opt_add NO_MICROPROBE_WARNING
opt_add NO_CONFIGURATION_EMBEDDING_WARNING
fi
FNAME=("-name" "marlin_config.json" \
"-o" "-name" "config.ini" \
"-o" "-name" "schema.json" \
"-o" "-name" "schema.yml")
# If EXPNUM is set then apply to the config before build
if [[ $EXPNUM ]]; then
opt_set CONFIG_EXPORT $EXPNUM
# Clean up old exports
find ./.pio/build \( "${FNAME[@]}" \) -exec rm "{}" \;
fi
set +e
echo "Building the firmware now..."
"$HERE/mftest" -s -a -n1 ; ERR=$?
[[ $ERR -eq 0 ]] && echo "Success" || echo "Failed"
set -e
# Copy exports back to the configs
if [[ $EXPNUM ]]; then
echo "Exporting $EXPNUM"
[[ -f Marlin/Config-export.h ]] && { cp Marlin/Config-export.h "$SUB"/Config.h ; }
find ./.pio/build/ "${FNAME[@]}" -exec cp "{}" "$SUB" \;
fi
# Exit with error unless --nofail is set
[[ $ERR -gt 0 && -z $NOFAIL ]] && exit $ERR
# Reveal the configs after the build, if requested
((REVEAL)) && { echo "Revealing $SUB" ; open "$SUB" ; }
exit 0