From 8e77d7877a0fb9913473f27167de17f6e2b57555 Mon Sep 17 00:00:00 2001 From: Maxie Dion Schmidt Date: Wed, 1 Jun 2022 09:04:53 -0400 Subject: [PATCH] More refinements and efforts to make build output cleaner to read --- .../Chameleon-Mini/BuildScripts/.gitignore | 2 + .../BuildScripts/custom_build_targets.mk | 118 +++-- .../BuildScripts/lufa_build_extra.mk | 417 ++++++++++++++++++ Firmware/Chameleon-Mini/Makefile | 198 ++++++--- 4 files changed, 612 insertions(+), 123 deletions(-) create mode 100644 Firmware/Chameleon-Mini/BuildScripts/.gitignore create mode 100644 Firmware/Chameleon-Mini/BuildScripts/lufa_build_extra.mk diff --git a/Firmware/Chameleon-Mini/BuildScripts/.gitignore b/Firmware/Chameleon-Mini/BuildScripts/.gitignore new file mode 100644 index 00000000..c166b3c5 --- /dev/null +++ b/Firmware/Chameleon-Mini/BuildScripts/.gitignore @@ -0,0 +1,2 @@ +*.mk +*.cfg diff --git a/Firmware/Chameleon-Mini/BuildScripts/custom_build_targets.mk b/Firmware/Chameleon-Mini/BuildScripts/custom_build_targets.mk index 19cd66de..0fb6d2fa 100644 --- a/Firmware/Chameleon-Mini/BuildScripts/custom_build_targets.mk +++ b/Firmware/Chameleon-Mini/BuildScripts/custom_build_targets.mk @@ -1,106 +1,102 @@ +SHELL := $(if $(SHELL), $(SHELL), /bin/sh) +BASH := $(if $(shell which bash), $(shell which bash), /bin/bash) + +TARGET_CUSTOM_BUILD_NAME = +TARGET_CUSTOM_BUILD = $(TARGET)-$(strip $(if $(TARGET_CUSTOM_BUILD_NAME), "CustomBuild_$(TARGET_CUSTOM_BUILD_NAME)", "DefaultBuild")) +DEFAULT_TAG_SUPPORT_BASE = -DCONFIG_ISO14443A_SNIFF_SUPPORT \ + -DCONFIG_ISO14443A_READER_SUPPORT +SUPPORTED_TAGS ?= +SUPPORTED_TAGS_BUILD := $(SUPPORTED_TAGS) +CUSTOM_CONFIG_SETTINGS_BASE := $(DEFAULT_TAG_SUPPORT) $(SUPPORTED_TAGS_BUILD) -DDEFAULT_CONFIGURATION=CONFIG_NONE + ## : Include several standardized custom build target variants: +custom-build: CONFIG_SETTINGS:=$(CUSTOM_CONFIG_SETTINGS_BASE) custom-build: local-clean $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).bin check_size - @cp $(TARGET).hex $(TARGET)-$(TARGET_CUSTOM_BUILD).hex - @cp $(TARGET).eep $(TARGET)-$(TARGET_CUSTOM_BUILD).eep - @cp $(TARGET).bin $(TARGET)-$(TARGET_CUSTOM_BUILD).bin - @echo "" + @cp $(TARGET).hex $(TARGET_CUSTOM_BUILD).hex + @cp $(TARGET).eep $(TARGET_CUSTOM_BUILD).eep + @cp $(TARGET).elf $(TARGET_CUSTOM_BUILD).elf + @cp $(TARGET).bin $(TARGET_CUSTOM_BUILD).bin + @echo $(MSG_TIDY_ENDSEP)$(MSG_TIDY_ENDSEP)$(MSG_TIDY_ENDSEP)"\n" @avr-size -A -x $(TARGET).elf + @echo $(MSG_TIDY_ENDSEP)"\n" @avr-size -B -x $(TARGET).elf - @echo "" + @echo "\n"$(MSG_TIDY_ENDSEP)"\n" @avr-size -C -x $(TARGET).elf - @echo "" - @echo " ==== SUCCESS BUILDING CUSTOM FIRMWARE -- $(TARGET)-$(TARGET_CUSTOM_BUILD) ====" - @echo "" + @echo $(MSG_TIDY_ENDSEP)$(MSG_TIDY_ENDSEP)$(MSG_TIDY_ENDSEP)"\n" + @echo $(FMT_ANSIC_BOLD)$(FMT_ANSIC_EXCLAIM)"[!!!]"$(FMT_ANSIC_END) \ + $(FMT_ANSIC_BOLD)$(FMT_ANSIC_UNDERLINE)"SUCCESS BUILDING CUSTOM FIRMWARE:"$(FMT_ANSIC_END) + @echo $(FMT_ANSIC_BOLD)$(FMT_ANSIC_EXCLAIM)"[!!!]"$(FMT_ANSIC_END) \ + $(FMT_ANSIC_BOLD)"$(TARGET_CUSTOM_BUILD).{hex/eep/elf/bin}"$(FMT_ANSIC_END) + @echo "\n" -default_config_support: DEFAULT_TAG_SUPPORT:= \ - -DCONFIG_ISO14443A_SNIFF_SUPPORT \ - -DCONFIG_ISO14443A_READER_SUPPORT +default_config_support: DEFAULT_TAG_SUPPORT:=$(DEFAULT_TAG_SUPPORT_BASE) nodefault_config_support: DEFAULT_TAG_SUPPORT:= -## : Define a few other useful custom build targets: -mifare: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ +mifare: SUPPORTED_TAGS_BUILD:=\ -DCONFIG_MF_CLASSIC_MINI_4B_SUPPORT \ -DCONFIG_MF_CLASSIC_1K_SUPPORT \ -DCONFIG_MF_CLASSIC_1K_7B_SUPPORT \ -DCONFIG_MF_CLASSIC_4K_SUPPORT \ -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT \ - -DCONFIG_MF_ULTRALIGHT_SUPPORTmifare: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -mifare: TARGET_CUSTOM_BUILD:=CustomBuild_MifareDefaultSupport + -DCONFIG_MF_ULTRALIGHT_SUPPORT +mifare: TARGET_CUSTOM_BUILD_NAME:=MifareDefaultSupport mifare: custom-build mifare-classic: nodefault_config_support -mifare-classic: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ +mifare-classic: SUPPORTED_TAGS_BUILD:=\ -DCONFIG_MF_CLASSIC_MINI_4B_SUPPORT \ -DCONFIG_MF_CLASSIC_1K_SUPPORT \ -DCONFIG_MF_CLASSIC_1K_7B_SUPPORT \ -DCONFIG_MF_CLASSIC_4K_SUPPORT \ -DCONFIG_MF_CLASSIC_4K_7B_SUPPORT -mifare-classic: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -mifare-classic: TARGET_CUSTOM_BUILD:=CustomBuild_MifareClassicSupport +mifare-classic: TARGET_CUSTOM_BUILD_NAME:=MifareClassicSupport mifare-classic: custom-build +desfire: CONFIG_SETTINGS:=$(DESFIRE_CONFIG_SETTINGS_BASE) \ + -fno-inline-small-functions +desfire: TARGET_CUSTOM_BUILD_NAME:=DESFire +desfire: custom-build + +desfire-dev: CONFIG_SETTINGS:=$(DESFIRE_CONFIG_SETTINGS_BASE) \ + -fno-inline-small-functions \ + -DDESFIRE_MIN_OUTGOING_LOGSIZE=0 \ + -DDESFIRE_MIN_INCOMING_LOGSIZE=0 \ + -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING \ + -DDESFIRE_DEFAULT_TESTING_MODE=1 +desfire-dev: TARGET_CUSTOM_BUILD_NAME:=DESFire_DEV +desfire-dev: custom-build + iso-modes: nodefault_config_support -iso-modes: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ +iso-modes: SUPPORTED_TAGS_BUILD:=\ -DCONFIG_ISO14443A_SNIFF_SUPPORT \ -DCONFIG_ISO14443A_READER_SUPPORT \ -DCONFIG_ISO15693_SNIFF_SUPPORT -iso-modes: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -iso-modes: TARGET_CUSTOM_BUILD:=CustomBuild_ISOSniffReaderModeSupport +iso-modes: TARGET_CUSTOM_BUILD_NAME:=ISOSniffReaderModeSupport iso-modes: custom-build ntag215: default_config_support -ntag215: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ - -DCONFIG_NTAG215_SUPPORT -ntag215: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -ntag215: TARGET_CUSTOM_BUILD:=CustomBuild_NTAG215Support +ntag215: SUPPORTED_TAGS_BUILD:=-DCONFIG_NTAG215_SUPPORT +ntag215: TARGET_CUSTOM_BUILD_NAME:=NTAG215Support ntag215: custom-build vicinity: default_config_support -vicinity: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ - -DCONFIG_VICINITY_SUPPORT -vicinity: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -vicinity: TARGET_CUSTOM_BUILD:=CustomBuild_VicinitySupport +vicinity: SUPPORTED_TAGS_BUILD:=-DCONFIG_VICINITY_SUPPORT +vicinity: TARGET_CUSTOM_BUILD_NAME:=VicinitySupport vicinity: custom-build sl2s2002: default_config_support -sl2s2002: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ - -DCONFIG_SL2S2002_SUPPORT -sl2s2002: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -sl2s2002: TARGET_CUSTOM_BUILD:=CustomBuild_SL2S2002Support +sl2s2002: SUPPORTED_TAGS_BUILD:=-DCONFIG_SL2S2002_SUPPORT +sl2s2002: TARGET_CUSTOM_BUILD_NAME:=SL2S2002Support sl2s2002: custom-build tagatit: default_config_support -tagatit: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ +tagatit: SUPPORTED_TAGS_BUILD:=\ -DCONFIG_TITAGITSTANDARD_SUPPORT \ -DCONFIG_TITAGITPLUS_SUPPORT -tagatit: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -tagatit: TARGET_CUSTOM_BUILD:=CustomBuild_TagatitSupport +tagatit: TARGET_CUSTOM_BUILD_NAME:=TagatitSupport tagatit: custom-build em4233: default_config_support -em4233: SUPPORTED_TAGS:=$(DEFAULT_TAG_SUPPORT) \ - -DCONFIG_EM4233_SUPPORT -em4233: CONFIG_SETTINGS:= $(SUPPORTED_TAGS) -DDEFAULT_CONFIGURATION=CONFIG_NONE -em4233: TARGET_CUSTOM_BUILD:=CustomBuild_EM4233Support +em4233: SUPPORTED_TAGS_BUILD:=-DCONFIG_EM4233_SUPPORT +em4233: TARGET_CUSTOM_BUILD_NAME:=EM4233Support em4233: custom-build - -## : Define custom targets for the DESFire build (normal/user mode) and -## : developer mode for use with the Android CMLD application that enables -## : the printing of LIVE logs to the phone's console by default: -desfire-build: local-clean $(TARGET).elf $(TARGET).hex $(TARGET).eep $(TARGET).bin check_size - @cp $(TARGET).hex $(TARGET)-DESFire.hex - @cp $(TARGET).eep $(TARGET)-DESFire.eep - @cp $(TARGET).bin $(TARGET)-DESFire.bin - @echo "" - @avr-size -A -x $(TARGET).elf - @avr-size -B -x $(TARGET).elf - @echo "" - @avr-size -C -x $(TARGET).elf -desfire: CONFIG_SETTINGS:=$(DESFIRE_CONFIG_SETTINGS_BASE) -fno-inline-small-functions -desfire: desfire-build -desfire-dev: CONFIG_SETTINGS:=$(DESFIRE_CONFIG_SETTINGS_BASE) -fno-inline-small-functions \ - -DDESFIRE_MIN_OUTGOING_LOGSIZE=0 \ - -DDESFIRE_MIN_INCOMING_LOGSIZE=0 \ - -DDESFIRE_DEFAULT_LOGGING_MODE=DEBUGGING \ - -DDESFIRE_DEFAULT_TESTING_MODE=1 -desfire-dev: desfire-build diff --git a/Firmware/Chameleon-Mini/BuildScripts/lufa_build_extra.mk b/Firmware/Chameleon-Mini/BuildScripts/lufa_build_extra.mk new file mode 100644 index 00000000..a386d468 --- /dev/null +++ b/Firmware/Chameleon-Mini/BuildScripts/lufa_build_extra.mk @@ -0,0 +1,417 @@ +# +# LUFA Library +# Copyright (C) Dean Camera, 2015. +# +# dean [at] fourwalledcubicle [dot] com +# www.lufa-lib.org +# + +LUFA_BUILD_MODULES += BUILD +LUFA_BUILD_TARGETS += size symbol-sizes all lib elf bin hex lss clean mostlyclean +LUFA_BUILD_MANDATORY_VARS += TARGET ARCH MCU SRC F_USB LUFA_PATH +LUFA_BUILD_OPTIONAL_VARS += BOARD OPTIMIZATION C_STANDARD CPP_STANDARD F_CPU C_FLAGS CPP_FLAGS ASM_FLAGS CC_FLAGS LD_FLAGS OBJDIR OBJECT_FILES DEBUG_TYPE DEBUG_LEVEL LINKER_RELAXATIONS COMPILER_PATH +LUFA_BUILD_PROVIDED_VARS += +LUFA_BUILD_PROVIDED_MACROS += + +# ----------------------------------------------------------------------------- +# LUFA GCC Compiler Buildsystem Makefile Module. +# ----------------------------------------------------------------------------- +# DESCRIPTION: +# Provides a set of targets to build a C, C++ and/or Assembly application +# via the AVR-GCC compiler. +# ----------------------------------------------------------------------------- +# TARGETS: +# +# size - List built application size +# symbol-sizes - Print application symbols from the binary ELF +# file as a list sorted by size in bytes +# all - Build application and list size +# lib - Build and archive source files into a library +# elf - Build application ELF debug object file +# bin - Build application BIN binary object file +# hex - Build application HEX object file +# lss - Build application LSS assembly listing file +# clean - Remove all project intermediary and binary +# output files +# mostlyclean - Remove intermediary output files, but +# preserve binaries +# .s - Compile C/C++ source file into an assembly file +# for manual code inspection +# +# MANDATORY PARAMETERS: +# +# TARGET - Application name +# ARCH - Device architecture name +# MCU - Microcontroller device model name +# SRC - List of input source files (*.c, *.cpp, *.S) +# F_USB - Speed of the input clock of the USB controller +# in Hz +# LUFA_PATH - Path to the LUFA library core +# +# OPTIONAL PARAMETERS: +# +# BOARD - LUFA board hardware +# OPTIMIZATION - Optimization level +# C_STANDARD - C Language Standard to use +# CPP_STANDARD - C++ Language Standard to use +# F_CPU - Speed of the CPU, in Hz +# C_FLAGS - Flags to pass to the C compiler only +# CPP_FLAGS - Flags to pass to the C++ compiler only +# ASM_FLAGS - Flags to pass to the assembler only +# CC_FLAGS - Common flags to pass to the C/C++ compiler and +# assembler +# LD_FLAGS - Flags to pass to the linker +# LINKER_RELAXATIONS - Enable or disable linker relaxations to +# decrease binary size (note: can cause link +# failures on systems with an unpatched binutils) +# OBJDIR - Directory for the output object and dependency +# files; if equal to ".", the output files will +# be generated in the same folder as the sources +# OBJECT_FILES - Extra object files to link in to the binaries +# DEBUG_FORMAT - Format of the debugging information to +# generate in the compiled object files +# DEBUG_LEVEL - Level the debugging information to generate in +# the compiled object files +# COMPILER_PATH - Location of the GCC toolchain to use +# +# PROVIDED VARIABLES: +# +# (None) +# +# PROVIDED MACROS: +# +# (None) +# +# ----------------------------------------------------------------------------- + +SHELL = /bin/sh + +ERROR_IF_UNSET ?= $(if $(filter undefined, $(origin $(strip $(1)))), $(error Makefile $(strip $(1)) value not set)) +ERROR_IF_EMPTY ?= $(if $(strip $($(strip $(1)))), , $(error Makefile $(strip $(1)) option cannot be blank)) +ERROR_IF_NONBOOL ?= $(if $(filter Y N, $($(strip $(1)))), , $(error Makefile $(strip $(1)) option must be Y or N)) + +# Default values of optionally user-supplied variables +COMPILER_PATH ?= +BOARD ?= NONE +OPTIMIZATION ?= s +F_CPU ?= +C_STANDARD ?= gnu99 +CPP_STANDARD ?= gnu++98 +C_FLAGS ?= +CPP_FLAGS ?= +ASM_FLAGS ?= +CC_FLAGS ?= +OBJDIR ?= . +OBJECT_FILES ?= +DEBUG_FORMAT ?= dwarf-2 +DEBUG_LEVEL ?= 2 +LINKER_RELAXATIONS ?= Y + +# Sanity check user supplied values +$(foreach MANDATORY_VAR, $(LUFA_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR))) +$(call ERROR_IF_EMPTY, MCU) +$(call ERROR_IF_EMPTY, TARGET) +$(call ERROR_IF_EMPTY, ARCH) +$(call ERROR_IF_EMPTY, F_USB) +$(call ERROR_IF_EMPTY, LUFA_PATH) +$(call ERROR_IF_EMPTY, BOARD) +$(call ERROR_IF_EMPTY, OPTIMIZATION) +$(call ERROR_IF_EMPTY, C_STANDARD) +$(call ERROR_IF_EMPTY, CPP_STANDARD) +$(call ERROR_IF_EMPTY, OBJDIR) +$(call ERROR_IF_EMPTY, DEBUG_FORMAT) +$(call ERROR_IF_EMPTY, DEBUG_LEVEL) +$(call ERROR_IF_NONBOOL, LINKER_RELAXATIONS) + +# Determine the utility prefix to use for the selected architecture +ifeq ($(ARCH), AVR8) + CROSS := $(COMPILER_PATH)avr +else ifeq ($(ARCH), XMEGA) + CROSS := $(COMPILER_PATH)avr + $(warning The XMEGA device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) +else ifeq ($(ARCH), UC3) + CROSS := $(COMPILER_PATH)avr32 + $(warning The UC3 device support is currently EXPERIMENTAL (incomplete and/or non-functional), and is included for preview purposes only.) +else + $(error Unsupported architecture "$(ARCH)") +endif + +# ANSI colored formatting +FMT_ANSIC_UNDERLINE := "\033[4m" +FMT_ANSIC_BOLD := "\033[1m" +FMT_ANSIC_GREEN := "\033[92m" +FMT_ANSIC_CYAN := "\033[46;97m" +FMT_ANSIC_MAGENTA := "\033[95m" +FMT_ANSIC_EXCLAIM := "\033[31;43;93m" +FMT_ANSIC_BW := "\033[90;30;47m" +FMT_ANSIC_BW_V2 := "\033[97;30;48m" +FMT_ANSIC_RESET := "\033[0m" +FMT_ANSIC_END := "\033[0m" +FMT_CMDHL_BEGIN := $(FMT_ANSIC_UNDERLINE)$(FMT_ANSIC_BOLD)$(FMT_ANSIC_GREEN) +FMT_CMDSEP_BEGIN := $(FMT_ANSIC_BOLD)$(FMT_ANSIC_CYAN) +FMT_CMDSEP_V2_BEGIN := $(FMT_ANSIC_BOLD)$(FMT_ANSIC_BW_V2) +FMT_FILENAME_BEGIN := $(FMT_ANSIC_BOLD)$(FMT_ANSIC_MAGENTA) +FMT_NEWLINE := $(FMT_ANSIC_RESET)$(FMT_ANSIC_END) + +# Output Messages +MSG_INFO_MESSAGE := ' ['$(FMT_CMDHL_BEGIN)'INFO'$(FMT_ANSIC_END)'] :' +MSG_COMPILE_CMD := ' ['$(FMT_CMDHL_BEGIN)'GCC'$(FMT_ANSIC_END)'] :' +MSG_ASSEMBLE_CMD := ' ['$(FMT_CMDHL_BEGIN)'GAS'$(FMT_ANSIC_END)'] :' +MSG_NM_CMD := ' ['$(FMT_CMDHL_BEGIN)'NM'$(FMT_ANSIC_END)'] :' +MSG_REMOVE_CMD := ' ['$(FMT_CMDHL_BEGIN)'RM'$(FMT_ANSIC_END)'] :' +MSG_LINK_CMD := ' ['$(FMT_CMDHL_BEGIN)'LNK'$(FMT_ANSIC_END)'] :' +MSG_ARCHIVE_CMD := ' ['$(FMT_CMDHL_BEGIN)'AR'$(FMT_ANSIC_END)'] :' +MSG_SIZE_CMD := ' ['$(FMT_CMDHL_BEGIN)'SIZE'$(FMT_ANSIC_END)'] :' +MSG_OBJCPY_CMD := ' ['$(FMT_CMDHL_BEGIN)'OBJCPY'$(FMT_ANSIC_END)'] :' +MSG_OBJDMP_CMD := ' ['$(FMT_CMDHL_BEGIN)'OBJDMP'$(FMT_ANSIC_END)'] :' +MSG_NEWLINE := $(FMT_NEWLINE)"\n" +MSG_CMDSEP_LINE := ' ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ' +MSG_CMDSEP_LINE_V2 := ' :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ' +MSG_CMDSEP_LINE_V3 := ' ================================================================================ ' +MSG_TIDY_PRE_FORMATTING := $(FMT_CMDSEP_BEGIN)$(MSG_CMDSEP_LINE)$(MSG_NEWLINE) +MSG_TIDY_INTERMED_FORMATTING := $(FMT_CMDSEP_V2_BEGIN)$(MSG_CMDSEP_LINE_V2)$(MSG_NEWLINE) +MSG_TIDY_POST_FORMATTING := $(FMT_NEWLINE) +MSG_TIDY_ENDSEP := $(FMT_ANSIC_BOLD)$(FMT_ANSIC_BW)$(MSG_CMDSEP_LINE_V3)$(MSG_NEWLINE) + +# Convert input source file list to differentiate them by type +FULL_SOURCE := $(SRC) $(LUFA_SRC) +C_SOURCE := $(filter %.c, $(FULL_SOURCE)) +CPP_SOURCE := $(filter %.cpp, $(FULL_SOURCE)) +ASM_SOURCE := $(filter %.S, $(FULL_SOURCE)) + +# Create a list of unknown source file types, if any are found throw an error +UNKNOWN_SOURCE := $(filter-out $(C_SOURCE) $(CPP_SOURCE) $(ASM_SOURCE), $(FULL_SOURCE)) +ifneq ($(UNKNOWN_SOURCE),) + $(error Unknown input source file formats: $(UNKNOWN_SOURCE)) +endif + +# Convert input source filenames into a list of required output object files +FWSRC_OBJECT_FILES := $(addsuffix .o, $(basename $(FULL_SOURCE))) +OBJECT_FILES += $(sort $(FWSRC_OBJECT_FILES)) +LUFA_OBJECT_FILES := $(addsuffix .o, $(shell basename $(LUFA_SRC))) + +# Check if an output object file directory was specified instead of the input file location +ifneq ($(OBJDIR),.) + # Prefix all the object filenames with the output object file directory path + OBJECT_FILES := $(addprefix $(patsubst %/,%,$(OBJDIR))/, $(notdir $(OBJECT_FILES))) + + # Check if any object file (without path) appears more than once in the object file list + ifneq ($(words $(sort $(OBJECT_FILES))), $(words $(OBJECT_FILES))) + $(error Cannot build with OBJDIR parameter set - one or more object file name is not unique) + endif + + # Create the output object file directory if it does not exist and add it to the virtual path list + $(shell mkdir $(OBJDIR) 2> /dev/null) + $(shell mkdir $(LUFA_OBJDIR) 2> /dev/null) + $(shell mkdir $(TEMPDIR) 2> /dev/null) + VPATH += $(dir $(FULL_SOURCE)) +endif + +# Create a list of dependency files from the list of object files +DEPENDENCY_FILES := $(OBJECT_FILES:%.o=%.d) + +# Create a list of common flags to pass to the compiler/linker/assembler +BASE_CC_FLAGS := -pipe -g$(DEBUG_FORMAT) -g$(DEBUG_LEVEL) +ifeq ($(ARCH), AVR8) + BASE_CC_FLAGS += -mmcu=$(MCU) -fshort-enums -fno-inline-small-functions -fpack-struct +else ifeq ($(ARCH), XMEGA) + BASE_CC_FLAGS += -mmcu=$(MCU) -fshort-enums -fno-inline-small-functions -fpack-struct +else ifeq ($(ARCH), UC3) + BASE_CC_FLAGS += -mpart=$(MCU:at32%=%) -masm-addr-pseudos +endif +BASE_CC_FLAGS += -Wall -fno-strict-aliasing -funsigned-char -funsigned-bitfields -ffunction-sections +BASE_CC_FLAGS += -I. -I$(patsubst %/,%,$(LUFA_PATH))/.. +BASE_CC_FLAGS += -DARCH=ARCH_$(ARCH) -DBOARD=BOARD_$(BOARD) -DF_USB=$(F_USB)UL +ifneq ($(F_CPU),) + BASE_CC_FLAGS += -DF_CPU=$(F_CPU)UL +endif +ifeq ($(LINKER_RELAXATIONS), Y) +BASE_CC_FLAGS += -mrelax +endif + +# This flag is required for bootloaders as GCC will emit invalid jump table +# assembly code for devices with large amounts of flash; the jump table target +# is extracted from FLASH without using the correct ELPM instruction, resulting +# in a pseudo-random jump target. +BASE_CC_FLAGS += -fno-jump-tables + +# Additional language specific compiler flags +BASE_C_FLAGS := -x c -O$(OPTIMIZATION) -std=$(C_STANDARD) -Wstrict-prototypes +BASE_CPP_FLAGS := -x c++ -O$(OPTIMIZATION) -std=$(CPP_STANDARD) +BASE_ASM_FLAGS := -x assembler-with-cpp + +# Create a list of flags to pass to the linker +BASE_LD_FLAGS := -lm -Wl,-Map=$(TARGET).map,--cref -Wl,--gc-sections +ifeq ($(LINKER_RELAXATIONS), Y) + BASE_LD_FLAGS += -Wl,--relax +endif +ifeq ($(ARCH), AVR8) + BASE_LD_FLAGS += -mmcu=$(MCU) +else ifeq ($(ARCH), XMEGA) + BASE_LD_FLAGS += -mmcu=$(MCU) +else ifeq ($(ARCH), UC3) + BASE_LD_FLAGS += -mpart=$(MCU:at32%=%) --rodata-writable --direct-data +endif + +# Determine flags to pass to the size utility based on its reported features (only invoke if size target required) +# and on an architecture where this non-standard patch is available +ifneq ($(ARCH), UC3) +size: SIZE_MCU_FLAG := $(shell $(CROSS)-size --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) ) +size: SIZE_FORMAT_FLAG := $(shell $(CROSS)-size --help | grep -- --format=.*avr > /dev/null && echo --format=avr ) +endif + +# Pre-build informational target, to give compiler and project name information when building +build_begin: + @echo $(MSG_INFO_MESSAGE) Begin compilation of project \"$(TARGET)\"... + @echo "" + @$(CROSS)-gcc --version + +# Post-build informational target, to project name information when building has completed +build_end: + @echo $(MSG_INFO_MESSAGE) Finished building project \"$(TARGET)\". + +# Prints size information of a compiled application (FLASH, RAM and EEPROM usages) +size: $(TARGET).elf + @echo $(MSG_SIZE_CMD) Determining size of \"$<\" + @echo "" + $(CROSS)-size $(SIZE_MCU_FLAG) $(SIZE_FORMAT_FLAG) $< + +# Prints size information on the symbols within a compiled application in decimal bytes +symbol-sizes: $(TARGET).elf + @echo $(MSG_NM_CMD) Extracting \"$<\" symbols with decimal byte sizes + $(CROSS)-nm --size-sort --demangle --radix=d $< + +# Cleans intermediary build files, leaving only the compiled application files +mostlyclean: + @echo $(MSG_REMOVE_CMD) Removing object files of \"$(TARGET)\" + rm -f $(OBJECT_FILES) + @echo $(MSG_REMOVE_CMD) Removing dependency files of \"$(TARGET)\" + rm -f $(DEPENDENCY_FILES) + +# Cleans all build files, leaving only the original source code +clean: mostlyclean + @echo $(MSG_REMOVE_CMD) Removing output files of \"$(TARGET)\" + rm -f $(TARGET).elf $(TARGET).hex $(TARGET).bin $(TARGET).eep $(TARGET).map $(TARGET).lss $(TARGET).sym lib$(TARGET).a + +# Performs a complete build of the user application and prints size information afterwards +all: build_begin elf hex bin lss sym size build_end + +# Helper targets, to build a specific type of output file without having to know the project target name +lib: lib$(TARGET).a +elf: $(TARGET).elf +hex: $(TARGET).hex $(TARGET).eep +bin: $(TARGET).bin +lss: $(TARGET).lss +sym: $(TARGET).sym + +# Default target to *create* the user application's specified source files; if this rule is executed by +# make, the input source file doesn't exist and an error needs to be presented to the user +$(FULL_SOURCE): + $(error Source file does not exist: $@) + +# Compiles an input C source file and generates an assembly listing for it +%.s: %.c $(MAKEFILE_LIST) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_COMPILE_CMD) Generating assembly from C file $(FMT_FILENAME_BEGIN)\"$(notdir $<)\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc -S $(BASE_CC_FLAGS) $(BASE_C_FLAGS) $(CC_FLAGS) $(C_FLAGS) $< -o $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Compiles an input C++ source file and generates an assembly listing for it +%.s: %.cpp $(MAKEFILE_LIST) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_COMPILE_CMD) Generating assembly from C++ file $(FMT_FILENAME_BEGIN)\"$(notdir $<)\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc -S $(BASE_CC_FLAGS) $(BASE_CPP_FLAGS) $(CC_FLAGS) $(CPP_FLAGS) $< -o $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Compiles an input C source file and generates a linkable object file for it +$(OBJDIR)*/%.o: %.c $(MAKEFILE_LIST) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_COMPILE_CMD) Compiling C file $(FMT_FILENAME_BEGIN)\"$(notdir $<)\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_C_FLAGS) $(CC_FLAGS) $(C_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Compiles an input C++ source file and generates a linkable object file for it +$(OBJDIR)*/%.o: %.cpp $(MAKEFILE_LIST) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_COMPILE_CMD) Compiling C++ file $(FMT_FILENAME_BEGIN)\"$(notdir $<)\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_CPP_FLAGS) $(CC_FLAGS) $(CPP_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Assembles an input ASM source file and generates a linkable object file for it +$(OBJDIR)*/%.o: %.S $(MAKEFILE_LIST) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_ASSEMBLE_CMD) Assembling $(FMT_FILENAME_BEGIN)\"$(notdir $<)\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc -c $(BASE_CC_FLAGS) $(BASE_ASM_FLAGS) $(CC_FLAGS) $(ASM_FLAGS) -MMD -MP -MF $(@:%.o=%.d) $< -o $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Generates a library archive file from the user application, which can be linked into other applications +.PRECIOUS : $(OBJECT_FILES) +.SECONDARY : %.a +%.a: $(OBJECT_FILES) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_ARCHIVE_CMD) Archiving object files into $(FMT_FILENAME_BEGIN)\"$@\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-ar rcs $@ $(OBJECT_FILES) + @echo $(MSG_TIDY_POST_FORMATTING) + +# Generates an ELF debug file from the user application, which can be further processed for FLASH and EEPROM data +# files, or used for programming and debugging directly +.PRECIOUS : $(OBJECT_FILES) +.SECONDARY : %.elf +%.elf: $(OBJECT_FILES) + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_LINK_CMD) Linking object files into $(FMT_FILENAME_BEGIN)\"$@\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-gcc $^ -o $@ $(BASE_LD_FLAGS) $(LD_FLAGS) + @echo $(MSG_TIDY_POST_FORMATTING) + +# Extracts out the loadable FLASH memory data from the project ELF file, and creates an Intel HEX format file of it +%.hex: %.elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting HEX file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $< $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Extracts out the loadable FLASH memory data from the project ELF file, and creates an Binary format file of it +%.bin: %.elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting BIN file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-objcopy -O binary -R .eeprom -R .fuse -R .lock -R .signature $< $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Extracts out the loadable EEPROM memory data from the project ELF file, and creates an Intel HEX format file of it +%.eep: %.elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting EEP file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings $< $@ || exit 0 + @echo $(MSG_TIDY_POST_FORMATTING) + +# Creates an assembly listing file from an input project ELF file, containing interleaved assembly and source data +%.lss: %.elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJDMP_CMD) Extracting LSS file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-objdump -h -d -S -z $< > $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Creates a symbol file listing the loadable and discarded symbols from an input project ELF file +%.sym: %.elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_NM_CMD) Extracting SYM file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) + $(CROSS)-nm -n $< > $@ + @echo $(MSG_TIDY_POST_FORMATTING) + +# Include build dependency files +-include $(DEPENDENCY_FILES) + +# Phony build targets for this module +.PHONY: build_begin build_end size symbol-sizes lib elf hex lss clean mostlyclean diff --git a/Firmware/Chameleon-Mini/Makefile b/Firmware/Chameleon-Mini/Makefile index 5980293e..6de09283 100644 --- a/Firmware/Chameleon-Mini/Makefile +++ b/Firmware/Chameleon-Mini/Makefile @@ -2,7 +2,9 @@ ## : Note when using AVR-Toolchain, you have to install cygwin and ## : append cygwin's bin directory to the PATH environment variable ## : because Atmel does not ship sh.exe anymore with the toolchain. -SHELL = /bin/sh +SHELL = /bin/sh +CONFIG_SETTINGS ?= +SETTINGS ?= ## : Supported configurations: ## : CAUTION: Enabling too many configurations in the firmware @@ -144,41 +146,42 @@ DESFIRE_MAINSRC = Application/DESFire DESFIRE_CONFIG_SETTINGS_BASE= -DCONFIG_MF_DESFIRE_SUPPORT -DMEMORY_LIMITED_TESTING \ -DDESFIRE_CRYPTO1_SAVE_SPACE -DDEFAULT_CONFIGURATION=CONFIG_NONE -#include BuildScripts/generate_build_settings_from_config.mk - ## : Fix some issues with standard Makefile targets on MacOS ## : where non-GNU versions of coreutils (and Unix commands like ## : grep, sed, awk) lead to unexpected behavior: -CHECK_SIZE_GREP_CMD=grep -oP "\d+" -ifeq "$(shell uname -s)" "Darwin" - CHECK_SIZE_GREP_CMD=grep -Eo "[[:digit:]]+" -endif +CHECK_SIZE_GREP_ARGS=$(if $(filter "$(shell uname -s)", "Darwin"), -Eo "[[:digit:]]+", -oP "\d+") ## : Memory definitions and objcopy flags to include sections in binaries -## : ++ Start of data section in flash -FLASH_DATA_ADDR = 0x10000 -## : ++ Size of data section in flash -FLASH_DATA_SIZE = 0x10000 -FLASH_DATA_OBJCOPY = --set-section-flags=.flashdata="alloc,load" -## : ++ Start of SPM helper section. Should be last 32Byte in bootloader section -SPM_HELPER_ADDR = 0x21FE0 -SPM_HELPER_OBJCOPY = --set-section-flags=.spmhelper="alloc,load" +## ++ Start of data section in flash +FLASH_DATA_ADDR = 0x10000 +## ++ Size of data section in flash +FLASH_DATA_SIZE = 0x10000 +FLASH_DATA_SECTION_NAME = .flashdata +FLASH_DATA_OBJCOPY = --set-section-flags=$(FLASH_DATA_SECTION_NAME)="alloc,load" +## ++ Start of SPM helper section. +## ++ Should be last 32 bytes in bootloader section +SPM_HELPER_ADDR = 0x21FE0 +SPM_HELPER_OBJCOPY = --set-section-flags=.spmhelper="alloc,load,readonly" ## : Build configuration -ifeq ($(OS),Windows_NT) - BUILD_DATE = "\"$(shell date /t)\"" -else - BUILD_DATE = $(shell date +'\"%Y-%m-%d\"') -endif - COMMIT_ID = $(shell git rev-parse --short HEAD) -MCU = atxmega128a4u -ARCH = XMEGA -BOARD = NONE -F_CPU = 27120000 -F_USB = 48000000 +BUILD_DATE = $(strip $(if $(filter $(OS), Windows_NT), "\"$(shell date /t)\"", $(shell date +'\"%Y-%m-%d\"'))) + +## : Adding the '?=' before the `MCU` variable definition lets it be reset by an environment variable, +## : so that the following works (may be useful for those users working with a RevE generation +## : Chameleon device): +## : $ TARGET=atxmega32a4u make +## : ... OR ... +## : $ TARGET=atxmega32a4u make +MCU ?= atxmega128a4u + +ARCH = XMEGA +BOARD = NONE +F_CPU = 27120000 +F_USB = 48000000 TARGET ?= Chameleon-Mini -OPTIMIZATION = s +OPTIMIZATION = s +SRC = SRC += $(TARGET).c \ LUFADescriptors.c \ System.c \ @@ -236,7 +239,7 @@ SRC += $(DESFIRE_MAINSRC)/../MifareDESFire.c \ $(DESFIRE_MAINSRC)/DESFireUtils.c SRC += Tests/CryptoTests.c \ Tests/ChameleonTerminal.c -SRC += $(LUFA_SRC_USB) \ +LUFA_SRC = $(LUFA_SRC_USB) \ $(LUFA_SRC_USBCLASS) LUFA_PATH = ../LUFA CC_FLAGS = -g0 \ @@ -271,7 +274,11 @@ LD_FLAGS = $(CC_FLAGS) \ -Wl,--section-start=.flashdata=$(FLASH_DATA_ADDR) \ -Wl,--section-start=.spmhelper=$(SPM_HELPER_ADDR) OBJDIR = Bin +LUFA_OBJDIR = LUFABin +TEMPDIR = $(OBJDIR)/Temp OBJECT_FILES = +FWROOT = ../.. +BUILD_SCR = ./BuildScripts ## : AVRDUDE settings AVRDUDE_PROGRAMMER = flip2 @@ -288,27 +295,38 @@ AVRDUDE_WRITE_EEPROM_LATEST = -U eeprom:w:Latest/$(TARGET).eep .PHONY: clean program program-latest dfu-flip dfu-prog check_size style ## : Default target -all: +.DEFAULT all: ## : Include LUFA build script makefiles include $(LUFA_PATH)/Build/lufa_core.mk include $(LUFA_PATH)/Build/lufa_sources.mk -include $(LUFA_PATH)/Build/lufa_build.mk +include $(BUILD_SCR)/lufa_build_extra.mk include $(LUFA_PATH)/Build/lufa_cppcheck.mk ## : Overwrite the LUFA versions of hex/bin file generation to include spmhelper and flashdata sections %.hex: %.elf - @echo $(MSG_OBJCPY_CMD) Extracting HEX file data from \"$<\" + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting $(FMT_ANSIC_LIGHTRED)HEX$(FMT_ANSIC_END) file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) $(CROSS)-objcopy -O ihex -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $< $@ + @echo $(MSG_TIDY_POST_FORMATTING) %.bin: %.elf - @echo $(MSG_OBJCPY_CMD) Extracting BIN file data from \"$<\" + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting $(FMT_ANSIC_LIGHTRED)BIN$(FMT_ANSIC_END) file data from $(FMT_FILENAME_BEGIN)\"$<\"$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) $(CROSS)-objcopy -O binary -R .eeprom -R .fuse -R .lock -R .signature $(FLASH_DATA_OBJCOPY) $< $@ + @echo $(MSG_TIDY_POST_FORMATTING) ## : Extract SPMHelper in the last 32 Byte of the bootloader section to externally combine it with any bootloader spmhelper: $(TARGET).elf - @echo $(MSG_OBJCPY_CMD) Extracting SPM helper HEX file from $(TARGET).elf + @echo $(MSG_TIDY_PRE_FORMATTING) + @echo $(MSG_OBJCPY_CMD) Extracting $(FMT_ANSIC_LIGHTRED)SPM$(FMT_ANSIC_END) helper \ + $(FMT_ANSIC_LIGHTRED)HEX$(FMT_ANSIC_END) file \ + from $(FMT_FILENAME_BEGIN)$(TARGET).elf$(MSG_NEWLINE) + @echo $(MSG_TIDY_INTERMED_FORMATTING) $(CROSS)-objcopy -O ihex -j .spmhelper $(SPM_HELPER_OBJCOPY) $(TARGET).elf $(TARGET).hex + @echo $(MSG_TIDY_POST_FORMATTING) ## : Program the device using avrdude program: $(TARGET).hex $(TARGET).eep check_size @@ -334,49 +352,105 @@ dfu-prog: $(TARGET).hex $(TARGET).eep check_size dfu-programmer $(MCU) flash $(TARGET).hex dfu-programmer $(MCU) reset -check_size: SHELL:=$(shell which bash) -check_size: SHELL_SCRIPT_EXEC_LINES:='\ - set -e; \ - if [ ! -f $(TARGET).elf ]; then \ - exit 0; \ - fi; \ - PROGMEM_SIZE=$$(avr-size $(TARGET).elf | $(CHECK_SIZE_GREP_CMD) | sed -n 4p); \ - MAX_PRGMEM_SIZE=$$(printf "%d\n" $(FLASH_DATA_ADDR)); \ - if [ $$PROGMEM_SIZE -gt $$MAX_PRGMEM_SIZE ]; then \ - echo "make: *** $(TARGET).elf Application Section size $$PROGMEM_SIZE " \ - echo "excedes maximum allowed $$MAX_PRGMEM_SIZE. Please disable some features in Makefile"; \ - exit 1; \ - fi; \ +check_size: BASH:=$(if $(shell which bash), $(shell which bash), /bin/bash) +check_size: BASH_SCRIPT_EXEC_LINES:=' \ + set -e; \ + if [[ ! -f $(TARGET).elf ]]; then \ + exit 0; \ + fi; \ + PROGMEM_SIZE=$$(avr-size $(TARGET).elf | grep $(CHECK_SIZE_GREP_ARGS) | sed -n 4p); \ + MAX_PRGMEM_SIZE=$$(printf "%d\n" $(FLASH_DATA_ADDR)); \ + if [[ $$PROGMEM_SIZE -gt $$MAX_PRGMEM_SIZE ]]; then \ + echo \"make: *** $(TARGET).elf Application Section size $$PROGMEM_SIZE \" \ + echo \"excedes maximum allowed $$MAX_PRGMEM_SIZE. Please disable some features in Makefile\"; \ + exit 1; \ + fi; \ ' check_size: - @$(SHELL) -c $(SHELL_SCRIPT_EXEC_LINES) + @$(BASH) -c $(BASH_SCRIPT_EXEC_LINES) || $(SHELL) -c $(BASH_SCRIPT_EXEC_LINES) style: ## : Make sure astyle is installed @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) ## : Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, Makefile - find . \( -name "*.[ch]" -or -name "Makefile" \) \ - -exec perl -pi -e 's/[ \t]+$$//' {} \; \ + find . \( -name "*.[ch]" -or -name "Makefile" \) \ + -exec perl -pi -e 's/[ \t]+$$//' {} \; \ -exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \ -exec sh -c "echo >> {}" \; ## : Apply astyle on *.c, *.h find . -name "*.[ch]" -exec astyle --formatted --mode=c --suffix=none \ - --indent=spaces=4 --indent-switches \ - --keep-one-line-blocks --max-instatement-indent=60 \ - --style=google --pad-oper --unpad-paren --pad-header \ + --indent=spaces=4 --indent-switches \ + --keep-one-line-blocks --max-instatement-indent=60 \ + --style=google --pad-oper --unpad-paren --pad-header \ --align-pointer=name {} \; +local-clean: BASH:=$(if $(shell which bash), $(shell which bash), /bin/bash) +local-clean: BASH_SCRIPT_EXEC_LINES:=' \ + for lufaobj in $$(ls $(LUFA_OBJDIR)); do \ + lobj_basename=$$(basename $$lufaobj); \ + ln -s $(LUFA_OBJDIR)/$$lobj_basename $(OBJDIR)/$$lobj_basename; \ + done \ + ' local-clean: - @rm -f $(TARGET)*.{elf,hex,eep,bin,lss,map} - @rm -rf $(OBJDIR) - @mkdir $(OBJDIR) + @rm -f $(TARGET)*.{elf,hex,eep,bin,lss,map} + @rm -rf $(OBJDIR) $(LUFA_OBJ) + @mkdir -p $(OBJDIR) $(LUFA_OBJDIR) + @$(BASH) -c $(BASH_SCRIPT_EXEC_LINES) || $(SHELL) -c $(BASH_SCRIPT_EXEC_LINES) -clean: local-clean +local-clean-skip: -git-add-dev: - @make style && git add Makefile BuildScripts/custom_build_targets.mk ./*.{c,h} ./*/*.{c,h} ./*/*/*.{c,h} - @cd ../../Software/DESFireLibNFCTesting && make style && \ - git add Makefile LocalInclude/*.h Source/*.c SampleOutputDumps/*.dump +ifdef $(NOCLEAN) + clean: local-clean-skip +else + clean: local-clean +endif -## : Define custom targets -include BuildScripts/custom_build_targets.mk +git-add-dev: LOCALFW_SOURCE_FILES:=Makefile ./*.{c,h} ./*/*.{c,h} ./*/*/*.{c,h} +git-add-dev: LOCALFW_BUILD_SCRIPT_FILES:=.gitignore custom_build_targets.mk lufa_build_custom.mk +git-add-dev: TESTING_SOURCE_FILES:=Makefile LocalInclude/*.h Source/*.c SampleOutputDumps/*.dump +git-add-dev: BASH:=$(if $(shell which bash), $(shell which bash), /bin/bash) +git-add-dev: BASH_GITCOMMIT_SCRIPT_EXEC_LINES:=' \ + if [ -z \"$(M)\" ]; then \ + git commit -m \"$(M)\"; \ + git push origin; \ + elif [ -z \"$(MSG)\" ]; then \ + git commit -m "$(MSG)"; \ + git push origin; \ + elif [ -z \"$(MESSAGE)\" ]; then \ + git commit -m \"$(MESSAGE)\"; \ + git push origin; \ + fi \ + exit 0; \ + ' +git-add-dev: + @make style && git add $(LOCALFW_SOURCE_FILES) + @cd $(BUILD_SCR) && make style && git add -f $(LOCALFW_BUILD_SCRIPT_FILES) + @cd $(FWROOT)/Software/DESFireLibNFCTesting && make style && git add $(TESTING_SOURCE_FILES) + @$(BASH) -c $(BASH_GITCOMMIT_SCRIPT_LINES) || $(SHELL) -c $(BASH_GITCOMMIT_SCRIPT_LINES) + +configure-chameleon-usb: UDEV_RULES_CONFIG_LINES:='\n \ + \# ChameleonMini (RevG)\n \ + SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"16d0\", ATTRS{idProduct}==\"04b2\", GROUP=\"users\", \ + MODE=\"0666\", SYMLINK+=\"ChameleonMini\", ENV{ID_MM_DEVICE_IGNORE}=\"1\"\n \ + \# ChameleonMini (RevE)\n \ + SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"03eb\", ATTRS{idProduct}==\"2044\", GROUP=\"users\", \ + MODE=\"0666\", SYMLINK+=\"ChameleonMiniE\", ENV{ID_MM_DEVICE_IGNORE}=\"1\"\n \ + \# ChameleonMini DFU mode\n \ + SUBSYSTEMS==\"usb\", ATTRS{idVendor}==\"03eb\", ATTRS{idProduct}==\"2fde\", GROUP=\"users\", \ + MODE=\"0666\" \ + ' +configure-chameleon-usb: + @mkdir -p $(TEMPDIR) && echo $(UDEV_RULES_CONFIG_LINES) > $(TEMPDIR)/98-ChameleonMini.rules + @echo "" + @echo "TO CONFIGURE THE CHAMELEON OVER USB, RUN THE FOLLOWING COMMANDS:" + @echo " $$ sudo cp $(TEMPDIR)/98-ChameleonMini.rules /etc/udev/rules.d/" + @echo " $$ sudo service udev restart" + @echo " $$ sudo udevadm control --reload" + @echo "" + @echo "FOR HELP TROUBLESHOOTING THE CHAMELEON USB CONNECTION, LOOK AT THE FOLLOWING OUTPUT:" + @echo " $$ dmesg | tail | grep -i dev" + @echo " $$ dmesg | tail | grep -i usb" + @echo " $$ sudo udevadm monitor" + +## : Define custom targets and standard build variants +include $(BUILD_SCR)/custom_build_targets.mk