ergodox-firmware/src/makefile

172 lines
6.6 KiB
Makefile
Raw Normal View History

# -----------------------------------------------------------------------------
# makefile for the ergoDOX firmware
#
# - .h file dependencies are automatically generated
#
# - This makefile was originally (extensively) modified from the WinAVR
# makefile template, mostly by removing stuff. The copy I used was from
# [pjrc : usb_keyboard] (http://pjrc.com/teensy/usb_keyboard.zip).
# -----------------------------------------------------------------------------
# Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (MIT) (see "license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
2012-06-13 01:11:18 +02:00
TARGET := firmware # the name we want for our program binary
FORMAT := ihex # the program binary's format
KEYBOARD := ergodox # keyboard model; see "src/keyboard" for what's available
LAYOUT := qwerty # keyboard layout; see "src/keyboard/*/layout" for what's
# available
2012-04-29 07:39:23 +02:00
2012-06-13 01:11:18 +02:00
MCU := atmega32u4 # processor type (for teensy 2.0); must match real life
BOARD := teensy-2-0 # see the libraries you're using for what's available
F_CPU := 16000000 # processor speed, in Hz
KB_DEBOUNCE_TIME := 5 # in ms; see keyswitch spec for necessary value; 5ms
# should be good for cherry mx switches
# firmware stuff
2012-06-13 01:11:18 +02:00
SRC := $(wildcard *.c)
2012-04-28 00:39:26 +02:00
# keyboard and layout stuff
2012-04-29 07:39:23 +02:00
# --- remove whitespace from vars
KEYBOARD := $(strip $(KEYBOARD))
LAYOUT := $(strip $(LAYOUT))
# --- include stuff
SRC += $(wildcard keyboard/$(KEYBOARD)*.c)
SRC += $(wildcard keyboard/$(KEYBOARD)/*.c)
SRC += $(wildcard keyboard/$(KEYBOARD)/controller/*.c)
SRC += $(wildcard keyboard/$(KEYBOARD)/layout/$(LAYOUT)*.c)
# library stuff
# - add more "*/*/..."s as necessary to compile everything.
2012-04-28 00:39:26 +02:00
# - parts of the stuff under "lib" may not be necessary, depending on other
# options, but it's all included here. hopefully any unnecessary stuff gets
# compiled out. else, the makefile will have to become more complicated.
SRC += $(wildcard lib/*.c)
SRC += $(wildcard lib/*/*.c)
SRC += $(wildcard lib/*/*/*.c)
SRC += $(wildcard lib-other/*.c)
SRC += $(wildcard lib-other/*/*.c)
SRC += $(wildcard lib-other/*/*/*.c)
OBJ = $(SRC:%.c=%.o)
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2012-06-13 01:11:18 +02:00
CFLAGS := -mmcu=$(MCU) # processor type (teensy 2.0); must match real
# life
2012-04-29 07:39:23 +02:00
CFLAGS += -DF_CPU=$(F_CPU) # processor frequency; must match initialization
# in source
CFLAGS += -I.. # search for includes in the toplevel directory
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2012-04-28 09:46:35 +02:00
CFLAGS += -DMAKEFILE_BOARD='$(strip $(BOARD))'
CFLAGS += -DMAKEFILE_KEYBOARD='$(strip $(KEYBOARD))'
CFLAGS += -DMAKEFILE_KEYBOARD_LAYOUT='$(strip $(LAYOUT))'
CFLAGS += -DKB_DEBOUNCE_TIME='$(strip $(KB_DEBOUNCE_TIME))'
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -std=gnu99 # use C99 plus GCC extensions
CFLAGS += -Os # optimize for size
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -Wall # enable lots of common warnings
CFLAGS += -Wstrict-prototypes # "warn if a function is declared or defined
# without specifying the argument types"
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -fpack-struct # "pack all structure members together without holes"
CFLAGS += -fshort-enums # "allocate to an 'enum' type only as many bytes as it
# needs for the declared range of possible values"
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
CFLAGS += -ffunction-sections # \ "place each function or data into its own
CFLAGS += -fdata-sections # / section in the output file if the
# target supports arbitrary sections." for
# linker optimizations, and discarding
# unused code.
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2012-06-13 01:11:18 +02:00
LDFLAGS := -Wl,-Map=$(strip $(TARGET)).map,--cref # generate a link map, with
2012-06-12 01:11:56 +02:00
# a cross reference table
LDFLAGS += -Wl,--relax # for some linker optimizations
LDFLAGS += -Wl,--gc-sections # discard unused functions and data
2012-04-25 09:14:12 +02:00
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
GENDEPFLAGS += -MMD -MP -MF $@.dep # generate dependency files
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2012-06-13 01:11:18 +02:00
CC := avr-gcc
OBJCOPY := avr-objcopy
SIZE := avr-size
2012-04-25 09:14:12 +02:00
2012-04-29 07:39:23 +02:00
# remove whitespace from some of the variables
2012-06-13 01:11:18 +02:00
TARGET := $(strip $(TARGET))
FORMAT := $(strip $(FORMAT))
2012-04-25 09:14:12 +02:00
# -----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
.PHONY: all clean
all: $(TARGET).hex $(TARGET).eep
@echo
@echo '---------------------------------------------------------------'
@echo '------- done --------------------------------------------------'
@echo
$(SIZE) --target=$(FORMAT) $(TARGET).hex
@echo
$(SIZE) --target=$(FORMAT) $(TARGET).eep
@echo
@echo '. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .'
@echo
$(SIZE) -C --mcu=atmega32u4 $(TARGET).elf
@echo '. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .'
@echo
@echo 'you can load "$(TARGET).hex" and "$(TARGET).eep" onto the'
@echo 'Teensy using the Teensy loader'
@echo
@echo '---------------------------------------------------------------'
@echo
clean:
@echo
@echo --- cleaning ---
git clean -dX # remove ignored files and directories
# -----------------------------------------------------------------------------
.SECONDARY:
%.hex: %.elf
@echo
@echo --- making $@ ---
# from the WinAVR makefile template (modified)
$(OBJCOPY) -O $(FORMAT) \
-R .eeprom -R .fuse -R .lock -R .signature \
$< $@
%.eep: %.elf
@echo
@echo --- making $@ ---
# from the WinAVR makefile template (modified)
-$(OBJCOPY) -O $(FORMAT) \
-j .eeprom \
--set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 \
--no-change-warnings \
$< $@ || exit 0
%.elf: $(OBJ)
@echo
@echo --- making $@ ---
2012-04-25 09:14:12 +02:00
$(CC) $(strip $(CFLAGS)) $(strip $(LDFLAGS)) $^ --output $@
%.o: %.c
@echo
@echo --- making $@ ---
2012-04-25 09:14:12 +02:00
$(CC) -c $(strip $(CFLAGS)) $(strip $(GENDEPFLAGS)) $< -o $@
# -----------------------------------------------------------------------------
-include $(OBJ:%=%.dep)