Makefile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ifndef VERBOSE
  2. .SILENT:
  3. endif
  4. .DEFAULT_GOAL := all
  5. space := $(subst ,, )
  6. ESCAPED_ABS_PATH = $(subst $(space),_SPACE_,$(abspath $1))
  7. starting_makefile := $(call ESCAPED_ABS_PATH,$(firstword $(MAKEFILE_LIST)))
  8. mkfile_path := $(call ESCAPED_ABS_PATH,$(lastword $(MAKEFILE_LIST))))
  9. abs_tmk_root := $(patsubst %/,%,$(dir $(mkfile_path)))
  10. ifneq (,$(findstring /keyboards/,$(starting_makefile)))
  11. possible_keyboard:=$(patsubst %/,%,$(dir $(patsubst $(abs_tmk_root)/keyboards/%,%,$(starting_makefile))))
  12. ifneq (,$(findstring /keymaps/,$(possible_keyboard)))
  13. KEYMAP_DIR:=$(lastword $(subst /keymaps/, ,$(possible_keyboard)))
  14. KEYBOARD_DIR:=$(firstword $(subst /keymaps/, ,$(possible_keyboard)))
  15. ifneq (,$(findstring /,$(KEYBOARD_DIR)))
  16. # SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR)))
  17. # KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR)))
  18. tmk_root = ../../..
  19. else
  20. tmk_root = ../../../..
  21. endif
  22. else
  23. KEYMAP_DIR:=default
  24. KEYBOARD_DIR:=$(possible_keyboard)
  25. ifneq (,$(findstring /,$(KEYBOARD_DIR)))
  26. # SUBPROJECT_DIR:=$(lastword $(subst /, ,$(KEYBOARD_DIR)))
  27. # KEYBOARD_DIR:=$(firstword $(subst /, ,$(KEYBOARD_DIR)))
  28. tmk_root = ../../..
  29. else
  30. tmk_root = ../..
  31. endif
  32. endif
  33. else
  34. tmk_root = .
  35. endif
  36. # $(info $(KEYBOARD_DIR))
  37. # $(info $(KEYMAP_DIR))
  38. # $(info $(SUBPROJECT_DIR))
  39. # Directory common source filess exist
  40. TOP_DIR = $(tmk_root)
  41. TMK_DIR = tmk_core
  42. TMK_PATH = $(TOP_DIR)/$(TMK_DIR)
  43. LIB_PATH = $(TOP_DIR)/lib
  44. QUANTUM_DIR = quantum
  45. QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR)
  46. ifdef keyboard
  47. KEYBOARD ?= $(keyboard)
  48. endif
  49. ifdef KEYBOARD_DIR
  50. KEYBOARD ?= $(KEYBOARD_DIR)
  51. endif
  52. ifndef KEYBOARD
  53. KEYBOARD=planck
  54. endif
  55. MASTER ?= left
  56. ifdef master
  57. MASTER = $(master)
  58. endif
  59. # converts things to keyboards/subproject
  60. ifneq (,$(findstring /,$(KEYBOARD)))
  61. TEMP:=$(KEYBOARD)
  62. KEYBOARD:=$(firstword $(subst /, ,$(TEMP)))
  63. SUBPROJECT:=$(lastword $(subst /, ,$(TEMP)))
  64. endif
  65. KEYBOARD_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD)
  66. ifdef sub
  67. SUBPROJECT=$(sub)
  68. endif
  69. ifdef subproject
  70. SUBPROJECT=$(subproject)
  71. endif
  72. ifneq ("$(wildcard $(KEYBOARD_PATH)/$(KEYBOARD).c)","")
  73. KEYBOARD_FILE = keyboards/$(KEYBOARD)/$(KEYBOARD).c
  74. ifneq ($(call ESCAPED_ABS_PATH,$(KEYBOARD_PATH)/Makefile),$(starting_makefile))
  75. -include $(KEYBOARD_PATH)/Makefile
  76. endif
  77. else
  78. $(error "$(KEYBOARD_PATH)/$(KEYBOARD).c" does not exist)
  79. endif
  80. ifdef SUBPROJECT_DEFAULT
  81. SUBPROJECT?=$(SUBPROJECT_DEFAULT)
  82. endif
  83. ifdef SUBPROJECT
  84. SUBPROJECT_PATH = $(TOP_DIR)/keyboards/$(KEYBOARD)/$(SUBPROJECT)
  85. ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","")
  86. OPT_DEFS += -DSUBPROJECT_$(SUBPROJECT)
  87. SUBPROJECT_FILE = keyboards/$(KEYBOARD)/$(SUBPROJECT)/$(SUBPROJECT).c
  88. ifneq ($(call ESCAPED_ABS_PATH,$(SUBPROJECT_PATH)/Makefile),$(starting_makefile))
  89. -include $(SUBPROJECT_PATH)/Makefile
  90. endif
  91. else
  92. $(error "$(SUBPROJECT_PATH)/$(SUBPROJECT).c" does not exist)
  93. endif
  94. endif
  95. ifdef keymap
  96. KEYMAP ?= $(keymap)
  97. endif
  98. ifdef KEYMAP_DIR
  99. KEYMAP ?= $(KEYMAP_DIR)
  100. endif
  101. ifndef KEYMAP
  102. KEYMAP = default
  103. endif
  104. KEYMAP_PATH = $(KEYBOARD_PATH)/keymaps/$(KEYMAP)
  105. ifneq ("$(wildcard $(KEYMAP_PATH)/keymap.c)","")
  106. KEYMAP_FILE = keyboards/$(KEYBOARD)/keymaps/$(KEYMAP)/keymap.c
  107. ifneq ($(call ESCAPED_ABS_PATH,$(KEYMAP_PATH)/Makefile),$(starting_makefile))
  108. -include $(KEYMAP_PATH)/Makefile
  109. endif
  110. else
  111. ifeq ("$(wildcard $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)/keymap.c)","")
  112. $(error "$(KEYMAP_PATH)/keymap.c" does not exist)
  113. else
  114. KEYMAP_PATH = $(SUBPROJECT_PATH)/keymaps/$(KEYMAP)
  115. KEYMAP_FILE = keyboards/$(KEYBOARD)/$(SUBPROJECT)/keymaps/$(KEYMAP)/keymap.c
  116. ifneq ($(call ESCAPED_ABS_PATH,$(KEYMAP_PATH)/Makefile),$(starting_makefile))
  117. -include $(KEYMAP_PATH)/Makefile
  118. endif
  119. endif
  120. endif
  121. ifdef SUBPROJECT
  122. TARGET ?= $(KEYBOARD)_$(SUBPROJECT)_$(KEYMAP)
  123. else
  124. TARGET ?= $(KEYBOARD)_$(KEYMAP)
  125. endif
  126. BUILD_DIR = $(TOP_DIR)/.build
  127. # Object files directory
  128. # To put object files in current directory, use a dot (.), do NOT make
  129. # this an empty or blank macro!
  130. OBJDIR = $(BUILD_DIR)/obj_$(TARGET)
  131. ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
  132. CONFIG_H = $(KEYMAP_PATH)/config.h
  133. else
  134. CONFIG_H = $(KEYBOARD_PATH)/config.h
  135. ifdef SUBPROJECT
  136. ifneq ("$(wildcard $(SUBPROJECT_PATH)/$(SUBPROJECT).c)","")
  137. CONFIG_H = $(SUBPROJECT_PATH)/config.h
  138. endif
  139. endif
  140. endif
  141. # # project specific files
  142. SRC += $(KEYBOARD_FILE) \
  143. $(KEYMAP_FILE) \
  144. $(QUANTUM_DIR)/quantum.c \
  145. $(QUANTUM_DIR)/keymap_common.c \
  146. $(QUANTUM_DIR)/keycode_config.c \
  147. $(QUANTUM_DIR)/process_keycode/process_leader.c
  148. ifdef SUBPROJECT
  149. SRC += $(SUBPROJECT_FILE)
  150. endif
  151. ifdef SUBPROJECT
  152. SRC += $(SUBPROJECT_FILE)
  153. endif
  154. ifdef SUBPROJECT
  155. SRC += $(SUBPROJECT_FILE)
  156. endif
  157. ifndef CUSTOM_MATRIX
  158. SRC += $(QUANTUM_DIR)/matrix.c
  159. endif
  160. ifeq ($(strip $(MIDI_ENABLE)), yes)
  161. OPT_DEFS += -DMIDI_ENABLE
  162. SRC += $(QUANTUM_DIR)/process_keycode/process_midi.c
  163. endif
  164. ifeq ($(strip $(AUDIO_ENABLE)), yes)
  165. OPT_DEFS += -DAUDIO_ENABLE
  166. SRC += $(QUANTUM_DIR)/process_keycode/process_music.c
  167. SRC += $(QUANTUM_DIR)/audio/audio.c
  168. SRC += $(QUANTUM_DIR)/audio/voices.c
  169. SRC += $(QUANTUM_DIR)/audio/luts.c
  170. endif
  171. ifeq ($(strip $(UCIS_ENABLE)), yes)
  172. OPT_DEFS += -DUCIS_ENABLE
  173. UNICODE_ENABLE = yes
  174. endif
  175. ifeq ($(strip $(UNICODE_ENABLE)), yes)
  176. OPT_DEFS += -DUNICODE_ENABLE
  177. SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c
  178. endif
  179. ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
  180. OPT_DEFS += -DRGBLIGHT_ENABLE
  181. SRC += $(QUANTUM_DIR)/light_ws2812.c
  182. SRC += $(QUANTUM_DIR)/rgblight.c
  183. endif
  184. ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
  185. OPT_DEFS += -DTAP_DANCE_ENABLE
  186. SRC += $(QUANTUM_DIR)/process_keycode/process_tap_dance.c
  187. endif
  188. ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes)
  189. SERIAL_DIR = $(QUANTUM_DIR)/serial_link
  190. SERIAL_PATH = $(QUANTUM_PATH)/serial_link
  191. SERIAL_SRC = $(wildcard $(SERIAL_PATH)/protocol/*.c)
  192. SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c)
  193. SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC))
  194. OPT_DEFS += -DSERIAL_LINK_ENABLE
  195. VAPTH += $(SERIAL_PATH)
  196. endif
  197. # Optimize size but this may cause error "relocation truncated to fit"
  198. #EXTRALDFLAGS = -Wl,--relax
  199. # Search Path
  200. VPATH += $(KEYMAP_PATH)
  201. ifdef SUBPROJECT
  202. VPATH += $(SUBPROJECT_PATH)
  203. endif
  204. VPATH += $(KEYBOARD_PATH)
  205. VPATH += $(TOP_DIR)
  206. VPATH += $(TMK_PATH)
  207. VPATH += $(QUANTUM_PATH)
  208. VPATH += $(QUANTUM_PATH)/keymap_extras
  209. VPATH += $(QUANTUM_PATH)/audio
  210. VPATH += $(QUANTUM_PATH)/process_keycode
  211. # We can assume a ChibiOS target When MCU_FAMILY is defined, since it's not used for LUFA
  212. ifdef MCU_FAMILY
  213. PLATFORM=CHIBIOS
  214. else
  215. PLATFORM=AVR
  216. endif
  217. include $(TMK_PATH)/common.mk
  218. ifeq ($(PLATFORM),AVR)
  219. include $(TMK_PATH)/protocol/lufa.mk
  220. include $(TMK_PATH)/avr.mk
  221. else ifeq ($(PLATFORM),CHIBIOS)
  222. include $(TMK_PATH)/protocol/chibios.mk
  223. include $(TMK_PATH)/chibios.mk
  224. OPT_OS = chibios
  225. else
  226. $(error Unknown platform)
  227. endif
  228. ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
  229. VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer
  230. VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer
  231. include $(VISUALIZER_PATH)/visualizer.mk
  232. endif
  233. include $(TMK_PATH)/rules.mk
  234. GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags 2>/dev/null || date +"%Y-%m-%d-%H:%M:%S")
  235. BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S")
  236. OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\"
  237. $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(QUANTUM_PATH)/version.h)
  238. $(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h)