1
0
Fork 0

Better non-Linux support (#2524)

* grep -> $(GREP)

Some UNIXy systems (FreeBSD for example) don't use GNU grep by default.
Allow the user to specify which grep implementation to use so that
GNU grep can be specified.

* Allow using versioned avr-gcc command

Don't hardcode "avr-gcc", and allow strings such as "avr-gcc8", or
"avr-gcc-7.3.0" to match checks for "avr-gcc".
This commit is contained in:
dankm 2018-03-26 14:08:08 -06:00 committed by Jack Humbert
parent ae7284edb8
commit 19a1fbaca2
3 changed files with 16 additions and 15 deletions

View file

@ -71,7 +71,7 @@ RGBLIGHT_ENABLE ?= no
# while [ -z $$USB ]; do \
# sleep 1; \
# ls /dev/tty* > /tmp/2; \
# USB=`diff /tmp/1 /tmp/2 | grep -o '/dev/tty.*'`; \
# USB=`diff /tmp/1 /tmp/2 | $(GREP) -o '/dev/tty.*'`; \
# done; \
# avrdude -p $(MCU) -c avr109 -P $$USB -U flash:w:$(BUILD_DIR)/$(TARGET).hex
#

View file

@ -135,13 +135,14 @@ flip: $(BUILD_DIR)/$(TARGET).hex check-size
$(BATCHISP) -hardware usb -device $(MCU) -operation start reset 0
DFU_PROGRAMMER ?= dfu-programmer
GREP ?= grep
dfu: $(BUILD_DIR)/$(TARGET).hex cpfirmware check-size
until $(DFU_PROGRAMMER) $(MCU) get bootloader-version; do\
echo "Error: Bootloader not found. Trying again in 5s." ;\
sleep 5 ;\
done
if $(DFU_PROGRAMMER) --version 2>&1 | grep -q 0.7 ; then\
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) erase --force;\
else\
$(DFU_PROGRAMMER) $(MCU) erase;\
@ -161,7 +162,7 @@ flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
$(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
if $(DFU_PROGRAMMER) --version 2>&1 | grep -q 0.7 ; then\
if $(DFU_PROGRAMMER) --version 2>&1 | $(GREP) -q 0.7 ; then\
$(DFU_PROGRAMMER) $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep;\
else\
$(DFU_PROGRAMMER) $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep;\
@ -169,7 +170,7 @@ dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
$(DFU_PROGRAMMER) $(MCU) reset
avrdude: $(BUILD_DIR)/$(TARGET).hex check-size
if grep -q -s Microsoft /proc/version; then \
if $(GREP) -q -s Microsoft /proc/version; then \
echo 'ERROR: AVR flashing cannot be automated within the Windows Subsystem for Linux (WSL) currently. Instead, take the .hex file generated and flash it using AVRDUDE, AVRDUDESS, or XLoader.'; \
else \
printf "Detecting USB port, reset your controller now."; \
@ -178,12 +179,12 @@ avrdude: $(BUILD_DIR)/$(TARGET).hex check-size
sleep 0.5; \
printf "."; \
ls /dev/tty* > /tmp/2; \
USB=`comm -13 /tmp/1 /tmp/2 | grep -o '/dev/tty.*'`; \
USB=`comm -13 /tmp/1 /tmp/2 | $(GREP) -o '/dev/tty.*'`; \
mv /tmp/2 /tmp/1; \
done; \
echo ""; \
echo "Detected controller on USB port at $$USB"; \
if grep -q -s 'MINGW\|MSYS' /proc/version; then \
if $(GREP) -q -s 'MINGW\|MSYS' /proc/version; then \
USB=`echo "$$USB" | perl -pne 's/\/dev\/ttyS(\d+)/COM.($$1+1)/e'`; \
echo "Remapped MSYS2 USB port to $$USB"; \
fi; \
@ -252,12 +253,12 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf
bootloader:
make -C lib/lufa/Bootloaders/DFU/ clean
echo -e "#ifndef QMK_KEYBOARD\n#define QMK_KEYBOARD\n" > lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "MANUFACTURER" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "PRODUCT" $(ALL_CONFIGS) -h | tail -1` Bootloader >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "QMK_ESC_OUTPUT" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "QMK_ESC_INPUT" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "QMK_LED" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `grep "QMK_SPEAKER" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "MANUFACTURER" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "PRODUCT" $(ALL_CONFIGS) -h | tail -1` Bootloader >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "QMK_ESC_OUTPUT" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "QMK_ESC_INPUT" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "QMK_LED" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e `$(GREP) "QMK_SPEAKER" $(ALL_CONFIGS) -h | tail -1` >> lib/lufa/Bootloaders/DFU/Keyboard.h
echo -e "\n#endif" >> lib/lufa/Bootloaders/DFU/Keyboard.h
make -C lib/lufa/Bootloaders/DFU/
echo -e "BootloaderDFU.hex copied to $(TARGET)_bootloader.hex"

View file

@ -370,9 +370,9 @@ show_path:
@echo SRC=$(SRC)
@echo OBJ=$(OBJ)
ifeq ($(CC),avr-gcc)
ifeq ($(findstring avr-gcc,$(CC)),avr-gcc)
check-size:
$(eval MAX_SIZE=$(shell n=`avr-gcc -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne '/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'`; echo $$(($$n)) || echo 0))
$(eval MAX_SIZE=$(shell n=`$(CC) -E -mmcu=$(MCU) $(CFLAGS) $(OPT_DEFS) tmk_core/common/avr/bootloader_size.c 2> /dev/null | sed -ne '/^#/n;/^AVR_SIZE:/,$${s/^AVR_SIZE: //;p;}'` && echo $$(($$n)) || echo 0))
$(eval CURRENT_SIZE=$(shell if [ -f $(BUILD_DIR)/$(TARGET).hex ]; then $(SIZE) --target=$(FORMAT) $(BUILD_DIR)/$(TARGET).hex | $(AWK) 'NR==2 {print $$4}'; else printf 0; fi))
if [ $(MAX_SIZE) -gt 0 ] && [ $(CURRENT_SIZE) -gt 0 ]; then \
$(SILENT) || printf "$(MSG_CHECK_FILESIZE)" | $(AWK_CMD); \