]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - rules.mk
Merge branch 'rhaberkorn-serial-mouse'
[tmk_firmware.git] / rules.mk
index 9143f9bcff2f03134713d6bce9140963896c9b44..7a40d1de9f4ae5a05015a9896b1dec0cb434a3c3 100644 (file)
--- a/rules.mk
+++ b/rules.mk
 #
 # make extcoff = Convert ELF to AVR Extended COFF.
 #
-# make program = Download the hex file to the device, using avrdude.
-#                Please customize the avrdude settings below first!
+# make program = Download the hex file to the device.
+#                Please customize your programmer settings(PROGRAM_CMD)
+#
+# make teensy = Download the hex file to the device, using teensy_loader_cli.
+#               (must have teensy_loader_cli installed).
+#
+# make dfu = Download the hex file to the device, using dfu-programmer (must
+#            have dfu-programmer installed).
+#
+# make flip = Download the hex file to the device, using Atmel FLIP (must
+#             have Atmel FLIP installed).
+#
+# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
+#               (must have dfu-programmer installed).
+#
+# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
+#                (must have Atmel FLIP installed).
 #
 # make debug = Start either simulavr or avarice as specified for debugging, 
 #              with avr-gdb or avr-insight as the front end for debugging.
@@ -109,8 +124,10 @@ CFLAGS += -O$(OPT)
 CFLAGS += -funsigned-char
 CFLAGS += -funsigned-bitfields
 CFLAGS += -ffunction-sections
+CFLAGS += -fno-inline-small-functions
 CFLAGS += -fpack-struct
 CFLAGS += -fshort-enums
+CFLAGS += -fno-strict-aliasing
 CFLAGS += -Wall
 CFLAGS += -Wstrict-prototypes
 #CFLAGS += -mshort-calls
@@ -121,7 +138,9 @@ CFLAGS += -Wstrict-prototypes
 CFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 CFLAGS += $(CSTANDARD)
-CFLAGS += -include $(CONFIG_H)
+ifdef CONFIG_H
+    CFLAGS += -include $(CONFIG_H)
+endif
 
 
 #---------------- Compiler Options C++ ----------------
@@ -139,6 +158,10 @@ CPPFLAGS += -funsigned-bitfields
 CPPFLAGS += -fpack-struct
 CPPFLAGS += -fshort-enums
 CPPFLAGS += -fno-exceptions
+CPPFLAGS += -ffunction-sections
+CPPFLAGS += -fdata-sections
+# to supress "warning: only initialized variables can be placed into program memory area"
+CPPFLAGS += -w
 CPPFLAGS += -Wall
 CPPFLAGS += -Wundef
 #CPPFLAGS += -mshort-calls
@@ -149,7 +172,9 @@ CPPFLAGS += -Wundef
 CPPFLAGS += -Wa,-adhlns=$(@:%.o=%.lst)
 CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
 #CPPFLAGS += $(CSTANDARD)
-CPPFLAGS += -include $(CONFIG_H)
+ifdef CONFIG_H
+    CPPFLAGS += -include $(CONFIG_H)
+endif
 
 
 #---------------- Assembler Options ----------------
@@ -162,7 +187,10 @@ CPPFLAGS += -include $(CONFIG_H)
 #  -listing-cont-lines: Sets the maximum number of continuation lines of hex 
 #       dump that will be displayed for a given single line of source input.
 ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
-ASFLAGS += -include $(CONFIG_H)
+ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
+ifdef CONFIG_H
+    ASFLAGS += -include $(CONFIG_H)
+endif
 
 
 #---------------- Library Options ----------------
@@ -312,15 +340,16 @@ LST = $(patsubst %.c,$(OBJDIR)/%.lst,$(patsubst %.cpp,$(OBJDIR)/%.lst,$(patsubst
 
 
 # Compiler flags to generate dependency files.
-GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
+#GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
+GENDEPFLAGS = -MMD -MP -MF .dep/$(subst /,_,$@).d
 
 
 # Combine all necessary flags and optional flags.
 # Add target processor to flags.
 # You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
-ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
-ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
-ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
+ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
+ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
+ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
 
 
 
@@ -381,6 +410,34 @@ gccversion :
 program: $(TARGET).hex $(TARGET).eep
        $(PROGRAM_CMD)
 
+teensy: $(TARGET).hex
+       teensy_loader_cli -mmcu=$(MCU) -w -v $(TARGET).hex
+
+flip: $(TARGET).hex
+       batchisp -hardware usb -device $(MCU) -operation erase f
+       batchisp -hardware usb -device $(MCU) -operation loadbuffer $(TARGET).hex program
+       batchisp -hardware usb -device $(MCU) -operation start reset 0
+
+dfu: $(TARGET).hex
+       dfu-programmer $(MCU) erase
+       dfu-programmer $(MCU) flash $(TARGET).hex
+       dfu-programmer $(MCU) reset
+       
+dfu-start:
+       dfu-programmer $(MCU) reset
+       dfu-programmer $(MCU) start
+
+flip-ee: $(TARGET).hex $(TARGET).eep
+       $(COPY) $(TARGET).eep $(TARGET)eep.hex
+       batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
+       batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(TARGET)eep.hex program
+       batchisp -hardware usb -device $(MCU) -operation start reset 0
+       $(REMOVE) $(TARGET)eep.hex
+
+dfu-ee: $(TARGET).hex $(TARGET).eep
+       dfu-programmer $(MCU) eeprom-flash $(TARGET).eep
+       dfu-programmer $(MCU) reset
+
 
 # Generate avr-gdb config/init file which does the following:
 #     define the reset signal, load the target file, connect to target, and set 
@@ -482,6 +539,7 @@ extcoff: $(TARGET).elf
 # Compile: create object files from C source files.
 $(OBJDIR)/%.o : %.c
        @echo
+       mkdir -p $(@D)
        @echo $(MSG_COMPILING) $<
        $(CC) -c $(ALL_CFLAGS) $< -o $@ 
 
@@ -489,6 +547,7 @@ $(OBJDIR)/%.o : %.c
 # Compile: create object files from C++ source files.
 $(OBJDIR)/%.o : %.cpp
        @echo
+       mkdir -p $(@D)
        @echo $(MSG_COMPILING_CPP) $<
        $(CC) -c $(ALL_CPPFLAGS) $< -o $@ 
 
@@ -512,7 +571,7 @@ $(OBJDIR)/%.o : %.S
 
 # Create preprocessed source for use in sending a bug report.
 %.i : %.c
-       $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
+       $(CC) -E -mmcu=$(MCU) $(CFLAGS) $< -o $@ 
 
 
 # Target: clean project.
@@ -532,7 +591,11 @@ clean_list :
        $(REMOVE) $(OBJ:.o=.s)
        $(REMOVE) $(OBJ:.o=.i)
        $(REMOVE) -r .dep
-       $(REMOVEDIR) $(OBJDIR)
+       $(REMOVE) -r $(OBJDIR)
+
+show_path:
+       @echo VPATH=$(VPATH)
+       @echo SRC=$(SRC)
 
 
 # Create object files directory
@@ -546,5 +609,5 @@ $(shell mkdir $(OBJDIR) 2>/dev/null)
 # Listing of phony targets.
 .PHONY : all begin finish end sizebefore sizeafter gccversion \
 build elf hex eep lss sym coff extcoff \
-clean clean_list program debug gdb-config
-
+clean clean_list debug gdb-config show_path \
+program teensy dfu flip dfu-ee flip-ee dfu-start