]> git.donarmstrong.com Git - qmk_firmware.git/blob - build_keyboard.mk
tweak page-toc settings
[qmk_firmware.git] / build_keyboard.mk
1 ifndef VERBOSE
2 .SILENT:
3 endif
4
5 .DEFAULT_GOAL := all
6
7 include common.mk
8
9 ifneq ($(SUBPROJECT),)
10     TARGET ?= $(KEYBOARD)_$(SUBPROJECT)_$(KEYMAP)
11     KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD)_$(SUBPROJECT)
12 else
13     TARGET ?= $(KEYBOARD)_$(KEYMAP)
14     KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD)
15 endif
16
17 # Force expansion
18 TARGET := $(TARGET)
19
20
21 MASTER ?= left
22 ifdef master
23     MASTER = $(master)
24 endif
25
26 ifeq ($(MASTER),right)
27     OPT_DEFS += -DMASTER_IS_ON_RIGHT
28 else
29     ifneq ($(MASTER),left)
30 $(error MASTER does not have a valid value(left/right))
31     endif
32 endif
33
34 KEYBOARD_PATH := keyboards/$(KEYBOARD)
35 KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c
36
37 ifneq ("$(wildcard $(KEYBOARD_C))","")
38     include $(KEYBOARD_PATH)/rules.mk
39 else
40     $(error "$(KEYBOARD_C)" does not exist)
41 endif
42
43 ifneq ($(SUBPROJECT),)
44     SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT)
45     SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c
46     ifneq ("$(wildcard $(SUBPROJECT_C))","")
47         OPT_DEFS += -DSUBPROJECT_$(SUBPROJECT)
48         include $(SUBPROJECT_PATH)/rules.mk
49     else
50         $(error "$(SUBPROJECT_PATH)/$(SUBPROJECT).c" does not exist)
51     endif
52 endif
53
54 # We can assume a ChibiOS target When MCU_FAMILY is defined, since it's not used for LUFA
55 ifdef MCU_FAMILY
56     PLATFORM=CHIBIOS
57 else
58     PLATFORM=AVR
59 endif
60
61 ifeq ($(PLATFORM),CHIBIOS)
62     include $(TMK_PATH)/protocol/chibios.mk
63     include $(TMK_PATH)/chibios.mk
64     OPT_OS = chibios
65     ifneq ("$(wildcard $(SUBPROJECT_PATH)/bootloader_defs.h)","")
66         OPT_DEFS += -include $(SUBPROJECT_PATH)/bootloader_defs.h
67     else ifneq ("$(wildcard $(SUBPROJECT_PATH)/boards/$(BOARD)/bootloader_defs.h)","")
68         OPT_DEFS += -include $(SUBPROJECT_PATH)/boards/$(BOARD)/bootloader_defs.h
69     else ifneq ("$(wildcard $(KEYBOARD_PATH)/bootloader_defs.h)","")
70         OPT_DEFS += -include $(KEYBOARD_PATH)/bootloader_defs.h
71     else ifneq ("$(wildcard $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h)","")
72         OPT_DEFS += -include $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h
73     endif
74 endif
75
76 CONFIG_H = $(KEYBOARD_PATH)/config.h
77 ifneq ($(SUBPROJECT),)
78     ifneq ("$(wildcard $(SUBPROJECT_C))","")
79         CONFIG_H = $(SUBPROJECT_PATH)/config.h
80     endif
81 endif
82
83 # Save the defines and includes here, so we don't include any keymap specific ones
84 PROJECT_DEFS := $(OPT_DEFS)
85 PROJECT_INC := $(VPATH) $(EXTRAINCDIRS) $(SUBPROJECT_PATH) $(KEYBOARD_PATH)
86 PROJECT_CONFIG := $(CONFIG_H)
87
88 MAIN_KEYMAP_PATH := $(KEYBOARD_PATH)/keymaps/$(KEYMAP)
89 MAIN_KEYMAP_C := $(MAIN_KEYMAP_PATH)/keymap.c
90 SUBPROJ_KEYMAP_PATH := $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)
91 SUBPROJ_KEYMAP_C := $(SUBPROJ_KEYMAP_PATH)/keymap.c
92 ifneq ("$(wildcard $(SUBPROJ_KEYMAP_C))","")
93     -include $(SUBPROJ_KEYMAP_PATH)/Makefile
94     KEYMAP_C := $(SUBPROJ_KEYMAP_C)
95     KEYMAP_PATH := $(SUBPROJ_KEYMAP_PATH)
96 else ifneq ("$(wildcard $(MAIN_KEYMAP_C))","")
97     -include $(MAIN_KEYMAP_PATH)/Makefile
98     KEYMAP_C := $(MAIN_KEYMAP_C)
99     KEYMAP_PATH := $(MAIN_KEYMAP_PATH)
100 else
101     $(error "$(MAIN_KEYMAP_C)/keymap.c" does not exist)
102 endif
103
104
105 # Object files directory
106 #     To put object files in current directory, use a dot (.), do NOT make
107 #     this an empty or blank macro!
108 KEYMAP_OUTPUT := $(BUILD_DIR)/obj_$(TARGET)
109
110
111 ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
112     CONFIG_H = $(KEYMAP_PATH)/config.h
113 endif
114
115 # # project specific files
116 SRC += $(KEYBOARD_C) \
117     $(KEYMAP_C) \
118     $(QUANTUM_SRC)
119
120 ifneq ($(SUBPROJECT),)
121     SRC += $(SUBPROJECT_C)
122 endif
123
124 # Optimize size but this may cause error "relocation truncated to fit"
125 #EXTRALDFLAGS = -Wl,--relax
126
127 # Search Path
128 VPATH += $(KEYMAP_PATH)
129 ifneq ($(SUBPROJECT),)
130     VPATH += $(SUBPROJECT_PATH)
131 endif
132 VPATH += $(KEYBOARD_PATH)
133 VPATH += $(COMMON_VPATH)
134
135 include common_features.mk
136 include $(TMK_PATH)/protocol.mk
137 include $(TMK_PATH)/common.mk
138
139 SRC += $(TMK_COMMON_SRC)
140 OPT_DEFS += $(TMK_COMMON_DEFS)
141 EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)
142
143 ifeq ($(PLATFORM),AVR)
144 ifeq ($(strip $(PROTOCOL)), VUSB)
145     include $(TMK_PATH)/protocol/vusb.mk
146 else
147     include $(TMK_PATH)/protocol/lufa.mk
148 endif
149     include $(TMK_PATH)/avr.mk
150 endif
151
152 ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
153     VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer
154     VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer
155     include $(VISUALIZER_PATH)/visualizer.mk
156 endif
157
158 OUTPUTS := $(KEYMAP_OUTPUT) $(KEYBOARD_OUTPUT)
159 $(KEYMAP_OUTPUT)_SRC := $(SRC)
160 $(KEYMAP_OUTPUT)_DEFS := $(OPT_DEFS) $(GFXDEFS) -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\"
161 $(KEYMAP_OUTPUT)_INC :=  $(VPATH) $(EXTRAINCDIRS)
162 $(KEYMAP_OUTPUT)_CONFIG := $(CONFIG_H)
163 $(KEYBOARD_OUTPUT)_SRC := $(CHIBISRC) $(GFXSRC)
164 $(KEYBOARD_OUTPUT)_DEFS := $(PROJECT_DEFS) $(GFXDEFS)
165 $(KEYBOARD_OUTPUT)_INC := $(PROJECT_INC) $(GFXINC)
166 $(KEYBOARD_OUTPUT)_CONFIG  := $(PROJECT_CONFIG)
167
168 # Default target.
169 all: build sizeafter
170
171 # Change the build target to build a HEX file or a library.
172 build: elf hex
173 #build: elf hex eep lss sym
174 #build: lib
175
176
177 include $(TMK_PATH)/rules.mk
178