aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/rules.mk
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/rules.mk')
-rw-r--r--tmk_core/rules.mk220
1 files changed, 11 insertions, 209 deletions
diff --git a/tmk_core/rules.mk b/tmk_core/rules.mk
index f8f77e892..96eba24d6 100644
--- a/tmk_core/rules.mk
+++ b/tmk_core/rules.mk
@@ -20,26 +20,11 @@
20# Output format. (can be srec, ihex, binary) 20# Output format. (can be srec, ihex, binary)
21FORMAT = ihex 21FORMAT = ihex
22 22
23BUILD_DIR = .build
24
25# Object files directory
26# To put object files in current directory, use a dot (.), do NOT make
27# this an empty or blank macro!
28OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
29
30
31# Optimization level, can be [0, 1, 2, 3, s]. 23# Optimization level, can be [0, 1, 2, 3, s].
32# 0 = turn off optimization. s = optimize for size. 24# 0 = turn off optimization. s = optimize for size.
33# (Note: 3 is not always the best optimization level. See avr-libc FAQ.) 25# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
34OPT = s 26OPT = s
35 27
36
37# Debugging format.
38# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
39# AVR Studio 4.10 requires dwarf-2.
40# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
41DEBUG = dwarf-2
42
43COLOR ?= true 28COLOR ?= true
44 29
45ifeq ($(COLOR),true) 30ifeq ($(COLOR),true)
@@ -87,7 +72,7 @@ BUILD_CMD = LOG=$$($(CMD) 2>&1) ; if [ $$? -gt 0 ]; then $(PRINT_ERROR); elif [
87# Each directory must be seperated by a space. 72# Each directory must be seperated by a space.
88# Use forward slashes for directory separators. 73# Use forward slashes for directory separators.
89# For a directory that has spaces, enclose it in quotes. 74# For a directory that has spaces, enclose it in quotes.
90EXTRAINCDIRS = $(subst :, ,$(VPATH)) 75EXTRAINCDIRS += $(subst :, ,$(VPATH))
91 76
92 77
93# Compiler flag to set the C Standard level. 78# Compiler flag to set the C Standard level.
@@ -99,17 +84,14 @@ CSTANDARD = -std=gnu99
99 84
100 85
101# Place -D or -U options here for C sources 86# Place -D or -U options here for C sources
102CDEFS = -DF_CPU=$(F_CPU)UL
103CDEFS += $(OPT_DEFS) 87CDEFS += $(OPT_DEFS)
104 88
105 89
106# Place -D or -U options here for ASM sources 90# Place -D or -U options here for ASM sources
107ADEFS = -DF_CPU=$(F_CPU)
108ADEFS += $(OPT_DEFS) 91ADEFS += $(OPT_DEFS)
109 92
110 93
111# Place -D or -U options here for C++ sources 94# Place -D or -U options here for C++ sources
112CPPDEFS = -DF_CPU=$(F_CPU)UL
113#CPPDEFS += -D__STDC_LIMIT_MACROS 95#CPPDEFS += -D__STDC_LIMIT_MACROS
114#CPPDEFS += -D__STDC_CONSTANT_MACROS 96#CPPDEFS += -D__STDC_CONSTANT_MACROS
115CPPDEFS += $(OPT_DEFS) 97CPPDEFS += $(OPT_DEFS)
@@ -123,17 +105,9 @@ CPPDEFS += $(OPT_DEFS)
123# -Wall...: warning level 105# -Wall...: warning level
124# -Wa,...: tell GCC to pass this to the assembler. 106# -Wa,...: tell GCC to pass this to the assembler.
125# -adhlns...: create assembler listing 107# -adhlns...: create assembler listing
126CFLAGS = -g$(DEBUG) 108CFLAGS += -g$(DEBUG)
127CFLAGS += $(CDEFS) 109CFLAGS += $(CDEFS)
128CFLAGS += -O$(OPT) 110CFLAGS += -O$(OPT)
129CFLAGS += -funsigned-char
130CFLAGS += -funsigned-bitfields
131CFLAGS += -ffunction-sections
132CFLAGS += -fdata-sections
133CFLAGS += -fno-inline-small-functions
134CFLAGS += -fpack-struct
135CFLAGS += -fshort-enums
136CFLAGS += -fno-strict-aliasing
137# add color 111# add color
138ifeq ($(COLOR),true) 112ifeq ($(COLOR),true)
139ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "") 113ifeq ("$(shell echo "int main(){}" | $(CC) -fdiagnostics-color -x c - -o /dev/null 2>&1)", "")
@@ -162,16 +136,9 @@ endif
162# -Wall...: warning level 136# -Wall...: warning level
163# -Wa,...: tell GCC to pass this to the assembler. 137# -Wa,...: tell GCC to pass this to the assembler.
164# -adhlns...: create assembler listing 138# -adhlns...: create assembler listing
165CPPFLAGS = -g$(DEBUG) 139CPPFLAGS += -g$(DEBUG)
166CPPFLAGS += $(CPPDEFS) 140CPPFLAGS += $(CPPDEFS)
167CPPFLAGS += -O$(OPT) 141CPPFLAGS += -O$(OPT)
168CPPFLAGS += -funsigned-char
169CPPFLAGS += -funsigned-bitfields
170CPPFLAGS += -fpack-struct
171CPPFLAGS += -fshort-enums
172CPPFLAGS += -fno-exceptions
173CPPFLAGS += -ffunction-sections
174CPPFLAGS += -fdata-sections
175# to supress "warning: only initialized variables can be placed into program memory area" 142# to supress "warning: only initialized variables can be placed into program memory area"
176CPPFLAGS += -w 143CPPFLAGS += -w
177CPPFLAGS += -Wall 144CPPFLAGS += -Wall
@@ -198,7 +165,7 @@ endif
198# files -- see avr-libc docs [FIXME: not yet described there] 165# files -- see avr-libc docs [FIXME: not yet described there]
199# -listing-cont-lines: Sets the maximum number of continuation lines of hex 166# -listing-cont-lines: Sets the maximum number of continuation lines of hex
200# dump that will be displayed for a given single line of source input. 167# dump that will be displayed for a given single line of source input.
201ASFLAGS = $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100 168ASFLAGS += $(ADEFS) -Wa,-adhlns=$(@:%.o=%.lst),-gstabs,--listing-cont-lines=100
202ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) 169ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
203ifdef CONFIG_H 170ifdef CONFIG_H
204 ASFLAGS += -include $(CONFIG_H) 171 ASFLAGS += -include $(CONFIG_H)
@@ -232,28 +199,6 @@ SCANF_LIB =
232MATH_LIB = -lm 199MATH_LIB = -lm
233 200
234 201
235# List any extra directories to look for libraries here.
236# Each directory must be seperated by a space.
237# Use forward slashes for directory separators.
238# For a directory that has spaces, enclose it in quotes.
239EXTRALIBDIRS =
240
241
242
243#---------------- External Memory Options ----------------
244
245# 64 KB of external RAM, starting after internal RAM (ATmega128!),
246# used for variables (.data/.bss) and heap (malloc()).
247#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
248
249# 64 KB of external RAM, starting after internal RAM (ATmega128!),
250# only used for heap (malloc()).
251#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
252
253EXTMEMOPTS =
254
255
256
257#---------------- Linker Options ---------------- 202#---------------- Linker Options ----------------
258# -Wl,...: tell GCC to pass this to linker. 203# -Wl,...: tell GCC to pass this to linker.
259# -Map: create map file 204# -Map: create map file
@@ -262,9 +207,8 @@ EXTMEMOPTS =
262# Comennt out "--relax" option to avoid a error such: 207# Comennt out "--relax" option to avoid a error such:
263# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12' 208# (.vectors+0x30): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_12'
264# 209#
265LDFLAGS = -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref 210LDFLAGS += -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref
266#LDFLAGS += -Wl,--relax 211#LDFLAGS += -Wl,--relax
267LDFLAGS += -Wl,--gc-sections
268LDFLAGS += $(EXTMEMOPTS) 212LDFLAGS += $(EXTMEMOPTS)
269LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS)) 213LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
270LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) 214LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
@@ -272,59 +216,13 @@ LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
272# You can give EXTRALDFLAGS at 'make' command line. 216# You can give EXTRALDFLAGS at 'make' command line.
273LDFLAGS += $(EXTRALDFLAGS) 217LDFLAGS += $(EXTRALDFLAGS)
274 218
275
276
277#---------------- Debugging Options ----------------
278
279# For simulavr only - target MCU frequency.
280DEBUG_MFREQ = $(F_CPU)
281
282# Set the DEBUG_UI to either gdb or insight.
283# DEBUG_UI = gdb
284DEBUG_UI = insight
285
286# Set the debugging back-end to either avarice, simulavr.
287DEBUG_BACKEND = avarice
288#DEBUG_BACKEND = simulavr
289
290# GDB Init Filename.
291GDBINIT_FILE = __avr_gdbinit
292
293# When using avarice settings for the JTAG
294JTAG_DEV = /dev/com1
295
296# Debugging port used to communicate between GDB / avarice / simulavr.
297DEBUG_PORT = 4242
298
299# Debugging host used to communicate between GDB / avarice / simulavr, normally
300# just set to localhost unless doing some sort of crazy debugging when
301# avarice is running on a different computer.
302DEBUG_HOST = localhost
303
304
305
306#============================================================================
307
308
309# Define programs and commands. 219# Define programs and commands.
310SHELL = sh 220SHELL = sh
311CC = avr-gcc
312OBJCOPY = avr-objcopy
313OBJDUMP = avr-objdump
314SIZE = avr-size
315AR = avr-ar rcs
316NM = avr-nm
317REMOVE = rm -f 221REMOVE = rm -f
318REMOVEDIR = rmdir 222REMOVEDIR = rmdir
319COPY = cp 223COPY = cp
320WINSHELL = cmd 224WINSHELL = cmd
321SECHO = $(SILENT) || echo 225SECHO = $(SILENT) || echo
322# Autodecct teensy loader
323ifneq (, $(shell which teensy-loader-cli 2>/dev/null))
324 TEENSY_LOADER_CLI = teensy-loader-cli
325else
326 TEENSY_LOADER_CLI = teensy_loader_cli
327endif
328 226
329# Define Messages 227# Define Messages
330# English 228# English
@@ -347,8 +245,6 @@ MSG_CLEANING = Cleaning project:
347MSG_CREATING_LIBRARY = Creating library: 245MSG_CREATING_LIBRARY = Creating library:
348 246
349 247
350
351
352# Define all object files. 248# Define all object files.
353OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC)))) 249OBJ = $(patsubst %.c,$(OBJDIR)/%.o,$(patsubst %.cpp,$(OBJDIR)/%.o,$(patsubst %.S,$(OBJDIR)/%.o,$(SRC))))
354 250
@@ -364,9 +260,9 @@ GENDEPFLAGS = -MMD -MP -MF $(BUILD_DIR)/.dep/$(subst /,_,$@).d
364# Combine all necessary flags and optional flags. 260# Combine all necessary flags and optional flags.
365# Add target processor to flags. 261# Add target processor to flags.
366# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar 262# You can give extra flags at 'make' command line like: make EXTRAFLAGS=-DFOO=bar
367ALL_CFLAGS = -mmcu=$(MCU) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) 263ALL_CFLAGS = $(MCUFLAGS) $(CFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
368ALL_CPPFLAGS = -mmcu=$(MCU) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS) 264ALL_CPPFLAGS = $(MCUFLAGS) -x c++ $(CPPFLAGS) $(GENDEPFLAGS) $(EXTRAFLAGS)
369ALL_ASFLAGS = -mmcu=$(MCU) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS) 265ALL_ASFLAGS = $(MCUFLAGS) -x assembler-with-cpp $(ASFLAGS) $(EXTRAFLAGS)
370 266
371# Default target. 267# Default target.
372all: 268all:
@@ -432,104 +328,10 @@ sizeafter:
432gccversion : 328gccversion :
433 @$(SILENT) || $(CC) --version 329 @$(SILENT) || $(CC) --version
434 330
435
436
437# Program the device.
438program: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
439 $(PROGRAM_CMD)
440
441teensy: $(BUILD_DIR)/$(TARGET).hex
442 $(TEENSY_LOADER_CLI) -mmcu=$(MCU) -w -v $(BUILD_DIR)/$(TARGET).hex
443
444flip: $(BUILD_DIR)/$(TARGET).hex
445 batchisp -hardware usb -device $(MCU) -operation erase f
446 batchisp -hardware usb -device $(MCU) -operation loadbuffer $(BUILD_DIR)/$(TARGET).hex program
447 batchisp -hardware usb -device $(MCU) -operation start reset 0
448
449dfu: $(BUILD_DIR)/$(TARGET).hex sizeafter
450ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
451 dfu-programmer $(MCU) erase --force
452else
453 dfu-programmer $(MCU) erase
454endif
455 dfu-programmer $(MCU) flash $(BUILD_DIR)/$(TARGET).hex
456 dfu-programmer $(MCU) reset
457
458dfu-start:
459 dfu-programmer $(MCU) reset
460 dfu-programmer $(MCU) start
461
462flip-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
463 $(COPY) $(BUILD_DIR)/$(TARGET).eep $(BUILD_DIR)/$(TARGET)eep.hex
464 batchisp -hardware usb -device $(MCU) -operation memory EEPROM erase
465 batchisp -hardware usb -device $(MCU) -operation memory EEPROM loadbuffer $(BUILD_DIR)/$(TARGET)eep.hex program
466 batchisp -hardware usb -device $(MCU) -operation start reset 0
467 $(REMOVE) $(BUILD_DIR)/$(TARGET)eep.hex
468
469dfu-ee: $(BUILD_DIR)/$(TARGET).hex $(BUILD_DIR)/$(TARGET).eep
470ifneq (, $(findstring 0.7, $(shell dfu-programmer --version 2>&1)))
471 dfu-programmer $(MCU) flash --eeprom $(BUILD_DIR)/$(TARGET).eep
472else
473 dfu-programmer $(MCU) flash-eeprom $(BUILD_DIR)/$(TARGET).eep
474endif
475 dfu-programmer $(MCU) reset
476
477
478# Generate avr-gdb config/init file which does the following:
479# define the reset signal, load the target file, connect to target, and set
480# a breakpoint at main().
481gdb-config:
482 @$(REMOVE) $(GDBINIT_FILE)
483 @echo define reset >> $(GDBINIT_FILE)
484 @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
485 @echo end >> $(GDBINIT_FILE)
486 @echo file $(BUILD_DIR)/$(TARGET).elf >> $(GDBINIT_FILE)
487 @echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
488ifeq ($(DEBUG_BACKEND),simulavr)
489 @echo load >> $(GDBINIT_FILE)
490endif
491 @echo break main >> $(GDBINIT_FILE)
492
493debug: gdb-config $(BUILD_DIR)/$(TARGET).elf
494ifeq ($(DEBUG_BACKEND), avarice)
495 @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
496 @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
497 $(BUILD_DIR)/$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
498 @$(WINSHELL) /c pause
499
500else
501 @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
502 $(DEBUG_MFREQ) --port $(DEBUG_PORT)
503endif
504 @$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
505
506
507
508
509# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
510COFFCONVERT = $(OBJCOPY) --debugging
511COFFCONVERT += --change-section-address .data-0x800000
512COFFCONVERT += --change-section-address .bss-0x800000
513COFFCONVERT += --change-section-address .noinit-0x800000
514COFFCONVERT += --change-section-address .eeprom-0x810000
515
516
517
518coff: $(BUILD_DIR)/$(TARGET).elf
519 @$(SECHO) $(MSG_COFF) $(BUILD_DIR)/$(TARGET).cof
520 $(COFFCONVERT) -O coff-avr $< $(BUILD_DIR)/$(TARGET).cof
521
522
523extcoff: $(BUILD_DIR)/$(TARGET).elf
524 @$(SECHO) $(MSG_EXTENDED_COFF) $(BUILD_DIR)/$(TARGET).cof
525 $(COFFCONVERT) -O coff-ext-avr $< $(BUILD_DIR)/$(TARGET).cof
526
527
528
529# Create final output files (.hex, .eep) from ELF output file. 331# Create final output files (.hex, .eep) from ELF output file.
530%.hex: %.elf 332%.hex: %.elf
531 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD) 333 @$(SILENT) || printf "$(MSG_FLASH) $@" | $(AWK_CMD)
532 $(eval CMD=$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock -R .signature $< $@) 334 $(eval CMD=$(HEX) $< $@)
533 @$(BUILD_CMD) 335 @$(BUILD_CMD)
534 @if $(AUTOGEN); then \ 336 @if $(AUTOGEN); then \
535 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \ 337 $(SILENT) || printf "Copying $(TARGET).hex to keymaps/$(KEYMAP)/$(KEYBOARD)_$(KEYMAP).hex\n"; \
@@ -540,7 +342,7 @@ extcoff: $(BUILD_DIR)/$(TARGET).elf
540 342
541%.eep: %.elf 343%.eep: %.elf
542 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD) 344 @$(SILENT) || printf "$(MSG_EEPROM) $@" | $(AWK_CMD)
543 $(eval CMD=$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" --change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0) 345 $(eval CMD=$(EEP) $< $@ || exit 0)
544 @$(BUILD_CMD) 346 @$(BUILD_CMD)
545 347
546# Create extended listing file from ELF output file. 348# Create extended listing file from ELF output file.
@@ -622,7 +424,7 @@ show_path:
622 @echo VPATH=$(VPATH) 424 @echo VPATH=$(VPATH)
623 @echo SRC=$(SRC) 425 @echo SRC=$(SRC)
624 426
625SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/.))) 427SUBDIRS := $(filter-out %/util/ %/doc/ %/keymaps/ %/old_keymap_files/,$(dir $(wildcard $(TOP_DIR)/keyboards/**/*/Makefile)))
626SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.)) 428SUBDIRS := $(SUBDIRS) $(dir $(wildcard $(TOP_DIR)/keyboards/*/.))
627SUBDIRS := $(sort $(SUBDIRS)) 429SUBDIRS := $(sort $(SUBDIRS))
628# $(error $(SUBDIRS)) 430# $(error $(SUBDIRS))