summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5642aa2839a4f24fb84c2d1ba18709d4057ca43b (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
ifndef VERBOSE
.SILENT:
endif

space := $(subst ,, )
starting_makefile := $(subst $(space),_SPACE_,$(abspath $(firstword $(MAKEFILE_LIST))))
mkfile_path := $(subst $(space),_SPACE_,$(abspath $(lastword $(MAKEFILE_LIST))))
abs_tmk_root := $(patsubst %/,%,$(dir $(mkfile_path)))

ifneq (,$(findstring /keyboards/,$(starting_makefile)))
	possible_keyboard:=$(patsubst %/,%,$(dir $(patsubst $(abs_tmk_root)/keyboards/%,%,$(starting_makefile))))
	ifneq (,$(findstring /keymaps/,$(possible_keyboard)))
		KEYMAP_DIR:=$(lastword $(subst /keymaps/, ,$(possible_keyboard)))
		KEYBOARD_DIR:=$(firstword $(subst /keymaps/, ,$(possible_keyboard)))
		ifneq (,$(findstring /,$(KEYBOARD_DIR)))
			# SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR)))
			# KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR)))
			tmk_root = ../../..
		else
			tmk_root = ../../../..
		endif
	else
		KEYMAP_DIR:=default
		KEYBOARD_DIR:=$(possible_keyboard)
		ifneq (,$(findstring /,$(KEYBOARD_DIR)))
			# SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR)))
			# KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR)))
			tmk_root = ../../..
		else
			tmk_root = ../..
		endif
	endif
else
	tmk_root = .
endif
# $(info $(KEYBOARD_DIR))
# $(info $(KEYMAP_DIR))
# $(info $(SUBPROJECT_DIR))

# Directory common source filess exist
TOP_DIR = $(tmk_root)
TMK_DIR = tmk_core
TMK_PATH = $(TOP_DIR)/$(TMK_DIR)

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


ifdef keyboard
	KEYBOARD ?= $(keyboard)
endif
ifdef KEYBOARD_DIR
	KEYBOARD ?= $(KEYBOARD_DIR)
endif
ifndef KEYBOARD
	KEYBOARD=planck
endif

# converts things to keyboards/subproject
ifneq (,$(findstring /,$(KEYBOARD)))
	TEMP:=$(KEYBOARD)
	KEYBOARD:=$(firstword $(subst /, ,$(TEMP)))
	SUBPROJECT:=$(lastword $(subst /, ,$(TEMP)))
endif

KEYBOARD_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD)

ifneq ("$(wildcard $(KEYBOARD_PATH)/$(KEYBOARD).c)","")
	KEYBOARD_FILE = keyboards/$(KEYBOARD)/$(KEYBOARD).c
	ifndef ARCH
		include $(KEYBOARD_PATH)/Makefile
	endif
else 
$(error "$(KEYBOARD_PATH)/$(KEYBOARD).c" does not exist)
endif

ifdef sub
	SUBPROJECT=$(sub)
endif
ifdef subproject
	SUBPROJECT=$(subproject)
endif

ifdef SUBPROJECT_DEFAULT
	SUBPROJECT?=$(SUBPROJECT_DEFAULT)
endif

ifdef SUBPROJECT
	SUBPROJECT_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)
	ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","")
		OPT_DEFS += -DSUBPROJECT_$(SUBPROJECT)
		SUBPROJECT_FILE = keyboards/$(KEYBOARD)/$(SUBPROJECT)/$(SUBPROJECT).c
		-include $(SUBPROJECT_PATH)/Makefile
	else 
$(error "$(SUBPROJECT_PATH)/$(SUBPROJECT).c" does not exist)
	endif
endif

ifdef keymap
	KEYMAP ?= $(keymap)
endif
ifdef KEYMAP_DIR
	KEYMAP ?= $(KEYMAP_DIR)
endif
ifndef KEYMAP
	KEYMAP = default
endif
KEYMAP_PATH = $(KEYBOARD_PATH)/keymaps/$(KEYMAP)
ifneq ("$(wildcard $(KEYMAP_PATH)/keymap.c)","")
	KEYMAP_FILE = keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/keymap.c
	-include $(KEYMAP_PATH)/Makefile
else 
$(error "$(KEYMAP_PATH)/keymap.c" does not exist)
endif

ifdef SUBPROJECT
	TARGET ?= $(KEYBOARD)_$(SUBPROJECT)_$(KEYMAP)
else
	TARGET ?= $(KEYBOARD)_$(KEYMAP)
endif


ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
	CONFIG_H = $(KEYMAP_PATH)/config.h
else
	CONFIG_H = $(KEYBOARD_PATH)/config.h
	ifdef SUBPROJECT
		ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","")
			CONFIG_H = $(SUBPROJECT_PATH)/config.h
		endif
	endif
endif

# # project specific files
SRC += $(KEYBOARD_FILE) \
	$(KEYMAP_FILE) \
	$(QUANTUM_DIR)/quantum.c \
	$(QUANTUM_DIR)/keymap.c \
	$(QUANTUM_DIR)/keycode_config.c \
	$(QUANTUM_DIR)/process_keycode/process_leader.c

ifdef SUBPROJECT
	SRC += $(SUBPROJECT_FILE)
endif

ifdef SUBPROJECT
	SRC += $(SUBPROJECT_FILE)
endif

ifdef SUBPROJECT
	SRC += $(SUBPROJECT_FILE)
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_audio.c
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

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

# Search Path
VPATH += $(KEYMAP_PATH)
ifdef 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)/protocol/lufa.mk
include $(TMK_PATH)/common.mk
include $(TMK_PATH)/rules.mk

GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S")
BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S")
OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\"
OPT_DEFS += -DQMK_VERSION=\"$(GIT_VERSION)\" -DQMK_BUILDDATE=\"$(BUILD_DATE)\"