summaryrefslogtreecommitdiff
path: root/build_keyboard.mk
blob: f843572f66a1b75ff45311fa7769adb395839872 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
ifndef VERBOSE
.SILENT:
endif

.DEFAULT_GOAL := all

include message.mk


# Directory common source filess exist
TOP_DIR = .
TMK_DIR = tmk_core
TMK_PATH = $(TOP_DIR)/$(TMK_DIR)
LIB_PATH = $(TOP_DIR)/lib

QUANTUM_DIR = quantum
QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)

BUILD_DIR := $(TOP_DIR)/.build

ifneq ($(SUBPROJECT),)
	TARGET ?= $(KEYBOARD)_$(SUBPROJECT)_$(KEYMAP)
	KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD)_$(SUBPROJECT)
else
	TARGET ?= $(KEYBOARD)_$(KEYMAP)
	KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD)
endif

# Force expansion
TARGET := $(TARGET)


MASTER ?= left
ifdef master
	MASTER = $(master)
endif

KEYBOARD_PATH := keyboards/$(KEYBOARD)
KEYBOARD_C := $(KEYBOARD_PATH)/$(KEYBOARD).c

ifneq ("$(wildcard $(KEYBOARD_C))","")
    include $(KEYBOARD_PATH)/rules.mk
else 
    $(error "$(KEYBOARD_C)" does not exist)
endif


ifneq ($(SUBPROJECT),)
    SUBPROJECT_PATH := keyboards/$(KEYBOARD)/$(SUBPROJECT)
    SUBPROJECT_C := $(SUBPROJECT_PATH)/$(SUBPROJECT).c
    ifneq ("$(wildcard $(SUBPROJECT_C))","")
        OPT_DEFS += -DSUBPROJECT_$(SUBPROJECT)
        include $(SUBPROJECT_PATH)/rules.mk
    else 
        $(error "$(SUBPROJECT_PATH)/$(SUBPROJECT).c" does not exist)
    endif
endif

# We can assume a ChibiOS target When MCU_FAMILY is defined, since it's not used for LUFA
ifdef MCU_FAMILY
	PLATFORM=CHIBIOS
else
	PLATFORM=AVR
endif

ifeq ($(PLATFORM),CHIBIOS)
	include $(TMK_PATH)/protocol/chibios.mk
	include $(TMK_PATH)/chibios.mk
	OPT_OS = chibios
	ifneq ("$(wildcard $(SUBPROJECT_PATH)/bootloader_defs.h)","")
		OPT_DEFS += -include $(SUBPROJECT_PATH)/bootloader_defs.h
	else ifneq ("$(wildcard $(SUBPROJECT_PATH)/boards/$(BOARD)/bootloader_defs.h)","")
		OPT_DEFS += -include $(SUBPROJECT_PATH)/boards/$(BOARD)/bootloader_defs.h
	else ifneq ("$(wildcard $(KEYBOARD_PATH)/bootloader_defs.h)","")
		OPT_DEFS += -include $(KEYBOARD_PATH)/bootloader_defs.h
	else ifneq ("$(wildcard $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h)","")
		OPT_DEFS += -include $(KEYBOARD_PATH)/boards/$(BOARD)/bootloader_defs.h
	endif
endif

CONFIG_H = $(KEYBOARD_PATH)/config.h
ifneq ($(SUBPROJECT),)
	ifneq ("$(wildcard $(SUBPROJECT_C))","")
		CONFIG_H = $(SUBPROJECT_PATH)/config.h
	endif
endif

# Save the defines and includes here, so we don't include any keymap specific ones 
PROJECT_DEFS := $(OPT_DEFS)
PROJECT_INC := $(VPATH) $(EXTRAINCDIRS) $(SUBPROJECT_PATH) $(KEYBOARD_PATH)
PROJECT_CONFIG := $(CONFIG_H)

MAIN_KEYMAP_PATH := $(KEYBOARD_PATH)/keymaps/$(KEYMAP)
MAIN_KEYMAP_C := $(MAIN_KEYMAP_PATH)/keymap.c
SUBPROJ_KEYMAP_PATH := $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)
SUBPROJ_KEYMAP_C := $(SUBPROJ_KEYMAP_PATH)/keymap.c
ifneq ("$(wildcard $(SUBPROJ_KEYMAP_C))","")
    -include $(SUBPROJ_KEYMAP_PATH)/Makefile
    KEYMAP_C := $(SUBPROJ_KEYMAP_C)
    KEYMAP_PATH := $(SUBPROJ_KEYMAP_PATH)
else ifneq ("$(wildcard $(MAIN_KEYMAP_C))","")
    -include $(MAIN_KEYMAP_PATH)/Makefile
    KEYMAP_C := $(MAIN_KEYMAP_C)
    KEYMAP_PATH := $(MAIN_KEYMAP_PATH)
else
    $(error "$(MAIN_KEYMAP_C)/keymap.c" does not exist)
endif


# Object files directory
#     To put object files in current directory, use a dot (.), do NOT make
#     this an empty or blank macro!
KEYMAP_OUTPUT := $(BUILD_DIR)/obj_$(TARGET)


ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
	CONFIG_H = $(KEYMAP_PATH)/config.h
endif

# # project specific files
SRC += $(KEYBOARD_C) \
	$(KEYMAP_C) \
	$(QUANTUM_DIR)/quantum.c \
	$(QUANTUM_DIR)/keymap_common.c \
	$(QUANTUM_DIR)/keycode_config.c \
	$(QUANTUM_DIR)/process_keycode/process_leader.c

ifneq ($(SUBPROJECT),)
	SRC += $(SUBPROJECT_C)
endif

ifndef CUSTOM_MATRIX
	SRC += $(QUANTUM_DIR)/matrix.c
endif

ifeq ($(strip $(MIDI_ENABLE)), yes)
    OPT_DEFS += -DMIDI_ENABLE
	SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
endif

ifeq ($(strip $(VIRTSER_ENABLE)), yes)
    OPT_DEFS += -DVIRTSER_ENABLE
endif

ifeq ($(strip $(AUDIO_ENABLE)), yes)
    OPT_DEFS += -DAUDIO_ENABLE
	SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
	SRC += $(QUANTUM_DIR)/audio/audio.c
	SRC += $(QUANTUM_DIR)/audio/voices.c
	SRC += $(QUANTUM_DIR)/audio/luts.c
endif

ifeq ($(strip $(UNICODE_ENABLE)), yes)
    OPT_DEFS += -DUNICODE_ENABLE
	SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
endif

ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
	OPT_DEFS += -DRGBLIGHT_ENABLE
	SRC += $(QUANTUM_DIR)/light_ws2812.c
	SRC += $(QUANTUM_DIR)/rgblight.c
endif

ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
	OPT_DEFS += -DTAP_DANCE_ENABLE
	SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
endif

ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
	SERIAL_DIR = $(QUANTUM_DIR)/serial_link
	SERIAL_PATH = $(QUANTUM_PATH)/serial_link
	SERIAL_SRC = $(wildcard $(SERIAL_PATH)/protocol/*.c)
	SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
	SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
	OPT_DEFS += -DSERIAL_LINK_ENABLE
	VAPTH += $(SERIAL_PATH)
endif

# Optimize size but this may cause error "relocation truncated to fit"
#EXTRALDFLAGS = -Wl,--relax

# Search Path
VPATH += $(KEYMAP_PATH)
ifneq ($(SUBPROJECT),)
	VPATH += $(SUBPROJECT_PATH)
endif
VPATH += $(KEYBOARD_PATH)
VPATH += $(TOP_DIR)
VPATH += $(TMK_PATH)
VPATH += $(QUANTUM_PATH)
VPATH += $(QUANTUM_PATH)/keymap_extras
VPATH += $(QUANTUM_PATH)/audio
VPATH += $(QUANTUM_PATH)/process_keycode


include $(TMK_PATH)/common.mk
ifeq ($(PLATFORM),AVR)
	include $(TMK_PATH)/protocol/lufa.mk
	include $(TMK_PATH)/avr.mk
endif

ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
	VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer
	VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer
	include $(VISUALIZER_PATH)/visualizer.mk
endif


OUTPUTS := $(KEYMAP_OUTPUT) $(KEYBOARD_OUTPUT)
$(KEYMAP_OUTPUT)_SRC := $(SRC)
$(KEYMAP_OUTPUT)_DEFS := $(OPT_DEFS) -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\" 
$(KEYMAP_OUTPUT)_INC := $(EXTRAINCDIRS) $(VPATH)
$(KEYMAP_OUTPUT)_CONFIG := $(CONFIG_H)
$(KEYBOARD_OUTPUT)_SRC := $(CHIBISRC)
$(KEYBOARD_OUTPUT)_DEFS := $(PROJECT_DEFS)
$(KEYBOARD_OUTPUT)_INC := $(PROJECT_INC)
$(KEYBOARD_OUTPUT)_CONFIG  := $(PROJECT_CONFIG)


include $(TMK_PATH)/rules.mk