Peter's keyboard firmware (QMK) https://qmk.fm/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
14KB

  1. # Determine what keyboard we are building and setup the build environment.
  2. #
  3. # We support folders up to 5 levels deep below `keyboards/`. This file is
  4. # responsible for determining which folder is being used and doing the
  5. # corresponding environment setup.
  6. ifndef VERBOSE
  7. .SILENT:
  8. endif
  9. .DEFAULT_GOAL := all
  10. include common.mk
  11. # Set the filename for the final firmware binary
  12. KEYBOARD_FILESAFE := $(subst /,_,$(KEYBOARD))
  13. TARGET ?= $(KEYBOARD_FILESAFE)_$(KEYMAP)
  14. KEYBOARD_OUTPUT := $(BUILD_DIR)/obj_$(KEYBOARD_FILESAFE)
  15. STM32_PATH := quantum/stm32
  16. # Force expansion
  17. TARGET := $(TARGET)
  18. # For split boards we need to set a master half.
  19. MASTER ?= left
  20. ifdef master
  21. MASTER = $(master)
  22. endif
  23. ifeq ($(MASTER),right)
  24. OPT_DEFS += -DMASTER_IS_ON_RIGHT
  25. else
  26. ifneq ($(MASTER),left)
  27. $(error MASTER does not have a valid value(left/right))
  28. endif
  29. endif
  30. ifdef SKIP_VERSION
  31. OPT_DEFS += -DSKIP_VERSION
  32. endif
  33. # Determine which subfolders exist.
  34. KEYBOARD_FOLDER_PATH_1 := $(KEYBOARD)
  35. KEYBOARD_FOLDER_PATH_2 := $(patsubst %/,%,$(dir $(KEYBOARD_FOLDER_PATH_1)))
  36. KEYBOARD_FOLDER_PATH_3 := $(patsubst %/,%,$(dir $(KEYBOARD_FOLDER_PATH_2)))
  37. KEYBOARD_FOLDER_PATH_4 := $(patsubst %/,%,$(dir $(KEYBOARD_FOLDER_PATH_3)))
  38. KEYBOARD_FOLDER_PATH_5 := $(patsubst %/,%,$(dir $(KEYBOARD_FOLDER_PATH_4)))
  39. KEYBOARD_FOLDER_1 := $(notdir $(KEYBOARD_FOLDER_PATH_1))
  40. KEYBOARD_FOLDER_2 := $(notdir $(KEYBOARD_FOLDER_PATH_2))
  41. KEYBOARD_FOLDER_3 := $(notdir $(KEYBOARD_FOLDER_PATH_3))
  42. KEYBOARD_FOLDER_4 := $(notdir $(KEYBOARD_FOLDER_PATH_4))
  43. KEYBOARD_FOLDER_5 := $(notdir $(KEYBOARD_FOLDER_PATH_5))
  44. KEYBOARD_PATHS :=
  45. KEYBOARD_PATH_1 := keyboards/$(KEYBOARD_FOLDER_PATH_1)
  46. KEYBOARD_PATH_2 := keyboards/$(KEYBOARD_FOLDER_PATH_2)
  47. KEYBOARD_PATH_3 := keyboards/$(KEYBOARD_FOLDER_PATH_3)
  48. KEYBOARD_PATH_4 := keyboards/$(KEYBOARD_FOLDER_PATH_4)
  49. KEYBOARD_PATH_5 := keyboards/$(KEYBOARD_FOLDER_PATH_5)
  50. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/)","")
  51. KEYBOARD_PATHS += $(KEYBOARD_PATH_5)
  52. endif
  53. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/)","")
  54. KEYBOARD_PATHS += $(KEYBOARD_PATH_4)
  55. endif
  56. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/)","")
  57. KEYBOARD_PATHS += $(KEYBOARD_PATH_3)
  58. endif
  59. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/)","")
  60. KEYBOARD_PATHS += $(KEYBOARD_PATH_2)
  61. endif
  62. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/)","")
  63. KEYBOARD_PATHS += $(KEYBOARD_PATH_1)
  64. endif
  65. # Pull in rules.mk files from all our subfolders
  66. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/rules.mk)","")
  67. include $(KEYBOARD_PATH_5)/rules.mk
  68. endif
  69. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/rules.mk)","")
  70. include $(KEYBOARD_PATH_4)/rules.mk
  71. endif
  72. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/rules.mk)","")
  73. include $(KEYBOARD_PATH_3)/rules.mk
  74. endif
  75. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/rules.mk)","")
  76. include $(KEYBOARD_PATH_2)/rules.mk
  77. endif
  78. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/rules.mk)","")
  79. include $(KEYBOARD_PATH_1)/rules.mk
  80. endif
  81. MAIN_KEYMAP_PATH_1 := $(KEYBOARD_PATH_1)/keymaps/$(KEYMAP)
  82. MAIN_KEYMAP_PATH_2 := $(KEYBOARD_PATH_2)/keymaps/$(KEYMAP)
  83. MAIN_KEYMAP_PATH_3 := $(KEYBOARD_PATH_3)/keymaps/$(KEYMAP)
  84. MAIN_KEYMAP_PATH_4 := $(KEYBOARD_PATH_4)/keymaps/$(KEYMAP)
  85. MAIN_KEYMAP_PATH_5 := $(KEYBOARD_PATH_5)/keymaps/$(KEYMAP)
  86. # Check for keymap.json first, so we can regenerate keymap.c
  87. include build_json.mk
  88. ifeq ("$(wildcard $(KEYMAP_PATH))", "")
  89. # Look through the possible keymap folders until we find a matching keymap.c
  90. ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_5)/keymap.c)","")
  91. -include $(MAIN_KEYMAP_PATH_5)/rules.mk
  92. KEYMAP_C := $(MAIN_KEYMAP_PATH_5)/keymap.c
  93. KEYMAP_PATH := $(MAIN_KEYMAP_PATH_5)
  94. else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_4)/keymap.c)","")
  95. -include $(MAIN_KEYMAP_PATH_4)/rules.mk
  96. KEYMAP_C := $(MAIN_KEYMAP_PATH_4)/keymap.c
  97. KEYMAP_PATH := $(MAIN_KEYMAP_PATH_4)
  98. else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_3)/keymap.c)","")
  99. -include $(MAIN_KEYMAP_PATH_3)/rules.mk
  100. KEYMAP_C := $(MAIN_KEYMAP_PATH_3)/keymap.c
  101. KEYMAP_PATH := $(MAIN_KEYMAP_PATH_3)
  102. else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_2)/keymap.c)","")
  103. -include $(MAIN_KEYMAP_PATH_2)/rules.mk
  104. KEYMAP_C := $(MAIN_KEYMAP_PATH_2)/keymap.c
  105. KEYMAP_PATH := $(MAIN_KEYMAP_PATH_2)
  106. else ifneq ("$(wildcard $(MAIN_KEYMAP_PATH_1)/keymap.c)","")
  107. -include $(MAIN_KEYMAP_PATH_1)/rules.mk
  108. KEYMAP_C := $(MAIN_KEYMAP_PATH_1)/keymap.c
  109. KEYMAP_PATH := $(MAIN_KEYMAP_PATH_1)
  110. else ifneq ($(LAYOUTS),)
  111. # If we haven't found a keymap yet fall back to community layouts
  112. include build_layout.mk
  113. else
  114. $(error Could not find keymap)
  115. # this state should never be reached
  116. endif
  117. endif
  118. ifeq ($(strip $(CTPC)), yes)
  119. CONVERT_TO_PROTON_C=yes
  120. endif
  121. ifeq ($(strip $(CONVERT_TO_PROTON_C)), yes)
  122. TARGET := $(TARGET)_proton_c
  123. include $(STM32_PATH)/proton_c.mk
  124. OPT_DEFS += -DCONVERT_TO_PROTON_C
  125. endif
  126. ifneq ($(FORCE_LAYOUT),)
  127. TARGET := $(TARGET)_$(FORCE_LAYOUT)
  128. endif
  129. include quantum/mcu_selection.mk
  130. ifdef MCU_FAMILY
  131. OPT_DEFS += -DQMK_STM32
  132. KEYBOARD_PATHS += $(STM32_PATH)
  133. endif
  134. # Find all the C source files to be compiled in subfolders.
  135. KEYBOARD_SRC :=
  136. KEYBOARD_C_1 := $(KEYBOARD_PATH_1)/$(KEYBOARD_FOLDER_1).c
  137. KEYBOARD_C_2 := $(KEYBOARD_PATH_2)/$(KEYBOARD_FOLDER_2).c
  138. KEYBOARD_C_3 := $(KEYBOARD_PATH_3)/$(KEYBOARD_FOLDER_3).c
  139. KEYBOARD_C_4 := $(KEYBOARD_PATH_4)/$(KEYBOARD_FOLDER_4).c
  140. KEYBOARD_C_5 := $(KEYBOARD_PATH_5)/$(KEYBOARD_FOLDER_5).c
  141. ifneq ("$(wildcard $(KEYBOARD_C_5))","")
  142. KEYBOARD_SRC += $(KEYBOARD_C_5)
  143. endif
  144. ifneq ("$(wildcard $(KEYBOARD_C_4))","")
  145. KEYBOARD_SRC += $(KEYBOARD_C_4)
  146. endif
  147. ifneq ("$(wildcard $(KEYBOARD_C_3))","")
  148. KEYBOARD_SRC += $(KEYBOARD_C_3)
  149. endif
  150. ifneq ("$(wildcard $(KEYBOARD_C_2))","")
  151. KEYBOARD_SRC += $(KEYBOARD_C_2)
  152. endif
  153. ifneq ("$(wildcard $(KEYBOARD_C_1))","")
  154. KEYBOARD_SRC += $(KEYBOARD_C_1)
  155. endif
  156. # Generate KEYBOARD_name_subname for all levels of the keyboard folder
  157. KEYBOARD_FILESAFE_1 := $(subst .,,$(subst /,_,$(KEYBOARD_FOLDER_PATH_1)))
  158. KEYBOARD_FILESAFE_2 := $(subst .,,$(subst /,_,$(KEYBOARD_FOLDER_PATH_2)))
  159. KEYBOARD_FILESAFE_3 := $(subst .,,$(subst /,_,$(KEYBOARD_FOLDER_PATH_3)))
  160. KEYBOARD_FILESAFE_4 := $(subst .,,$(subst /,_,$(KEYBOARD_FOLDER_PATH_4)))
  161. KEYBOARD_FILESAFE_5 := $(subst .,,$(subst /,_,$(KEYBOARD_FOLDER_PATH_5)))
  162. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/)","")
  163. OPT_DEFS += -DKEYBOARD_$(KEYBOARD_FILESAFE_5)
  164. endif
  165. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/)","")
  166. OPT_DEFS += -DKEYBOARD_$(KEYBOARD_FILESAFE_4)
  167. endif
  168. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/)","")
  169. OPT_DEFS += -DKEYBOARD_$(KEYBOARD_FILESAFE_3)
  170. endif
  171. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/)","")
  172. OPT_DEFS += -DKEYBOARD_$(KEYBOARD_FILESAFE_2)
  173. endif
  174. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/)","")
  175. OPT_DEFS += -DKEYBOARD_$(KEYBOARD_FILESAFE_1)
  176. endif
  177. # Setup the define for QMK_KEYBOARD_H. This is used inside of keymaps so
  178. # that the same keymap may be used on multiple keyboards.
  179. #
  180. # We grab the most top-level include file that we can. That file should
  181. # use #ifdef statements to include all the neccesary subfolder includes,
  182. # as described here:
  183. #
  184. # https://docs.qmk.fm/#/feature_layouts?id=tips-for-making-layouts-keyboard-agnostic
  185. #
  186. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/$(KEYBOARD_FOLDER_1).h)","")
  187. QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_1).h
  188. endif
  189. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/$(KEYBOARD_FOLDER_2).h)","")
  190. QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_2).h
  191. endif
  192. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/$(KEYBOARD_FOLDER_3).h)","")
  193. QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_3).h
  194. endif
  195. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/$(KEYBOARD_FOLDER_4).h)","")
  196. QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_4).h
  197. endif
  198. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/$(KEYBOARD_FOLDER_5).h)","")
  199. QMK_KEYBOARD_H = $(KEYBOARD_FOLDER_5).h
  200. endif
  201. # Determine and set parameters based on the keyboard's processor family.
  202. # We can assume a ChibiOS target When MCU_FAMILY is defined since it's
  203. # not used for LUFA
  204. ifdef MCU_FAMILY
  205. FIRMWARE_FORMAT?=bin
  206. PLATFORM=CHIBIOS
  207. else ifdef ARM_ATSAM
  208. PLATFORM=ARM_ATSAM
  209. FIRMWARE_FORMAT=bin
  210. else
  211. PLATFORM=AVR
  212. FIRMWARE_FORMAT?=hex
  213. endif
  214. ifeq ($(PLATFORM),CHIBIOS)
  215. include $(TMK_PATH)/chibios.mk
  216. OPT_OS = chibios
  217. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/bootloader_defs.h)","")
  218. OPT_DEFS += -include $(KEYBOARD_PATH_5)/bootloader_defs.h
  219. else ifneq ("$(wildcard $(KEYBOARD_PATH_5)/boards/$(BOARD)/bootloader_defs.h)","")
  220. OPT_DEFS += -include $(KEYBOARD_PATH_5)/boards/$(BOARD)/bootloader_defs.h
  221. else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/bootloader_defs.h)","")
  222. OPT_DEFS += -include $(KEYBOARD_PATH_4)/bootloader_defs.h
  223. else ifneq ("$(wildcard $(KEYBOARD_PATH_4)/boards/$(BOARD)/bootloader_defs.h)","")
  224. OPT_DEFS += -include $(KEYBOARD_PATH_4)/boards/$(BOARD)/bootloader_defs.h
  225. else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/bootloader_defs.h)","")
  226. OPT_DEFS += -include $(KEYBOARD_PATH_3)/bootloader_defs.h
  227. else ifneq ("$(wildcard $(KEYBOARD_PATH_3)/boards/$(BOARD)/bootloader_defs.h)","")
  228. OPT_DEFS += -include $(KEYBOARD_PATH_3)/boards/$(BOARD)/bootloader_defs.h
  229. else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/bootloader_defs.h)","")
  230. OPT_DEFS += -include $(KEYBOARD_PATH_2)/bootloader_defs.h
  231. else ifneq ("$(wildcard $(KEYBOARD_PATH_2)/boards/$(BOARD)/bootloader_defs.h)","")
  232. OPT_DEFS += -include $(KEYBOARD_PATH_2)/boards/$(BOARD)/bootloader_defs.h
  233. else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/bootloader_defs.h)","")
  234. OPT_DEFS += -include $(KEYBOARD_PATH_1)/bootloader_defs.h
  235. else ifneq ("$(wildcard $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h)","")
  236. OPT_DEFS += -include $(KEYBOARD_PATH_1)/boards/$(BOARD)/bootloader_defs.h
  237. else ifneq ("$(wildcard $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h)","")
  238. OPT_DEFS += -include $(TOP_DIR)/drivers/boards/$(BOARD)/bootloader_defs.h
  239. endif
  240. endif
  241. # Find all of the config.h files and add them to our CONFIG_H define.
  242. CONFIG_H :=
  243. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/config.h)","")
  244. CONFIG_H += $(KEYBOARD_PATH_5)/config.h
  245. endif
  246. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/config.h)","")
  247. CONFIG_H += $(KEYBOARD_PATH_4)/config.h
  248. endif
  249. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/config.h)","")
  250. CONFIG_H += $(KEYBOARD_PATH_3)/config.h
  251. endif
  252. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/config.h)","")
  253. CONFIG_H += $(KEYBOARD_PATH_2)/config.h
  254. endif
  255. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/config.h)","")
  256. CONFIG_H += $(KEYBOARD_PATH_1)/config.h
  257. endif
  258. POST_CONFIG_H :=
  259. ifneq ("$(wildcard $(KEYBOARD_PATH_1)/post_config.h)","")
  260. POST_CONFIG_H += $(KEYBOARD_PATH_1)/post_config.h
  261. endif
  262. ifneq ("$(wildcard $(KEYBOARD_PATH_2)/post_config.h)","")
  263. POST_CONFIG_H += $(KEYBOARD_PATH_2)/post_config.h
  264. endif
  265. ifneq ("$(wildcard $(KEYBOARD_PATH_3)/post_config.h)","")
  266. POST_CONFIG_H += $(KEYBOARD_PATH_3)/post_config.h
  267. endif
  268. ifneq ("$(wildcard $(KEYBOARD_PATH_4)/post_config.h)","")
  269. POST_CONFIG_H += $(KEYBOARD_PATH_4)/post_config.h
  270. endif
  271. ifneq ("$(wildcard $(KEYBOARD_PATH_5)/post_config.h)","")
  272. POST_CONFIG_H += $(KEYBOARD_PATH_5)/post_config.h
  273. endif
  274. # Save the defines and includes here, so we don't include any keymap specific ones
  275. PROJECT_DEFS := $(OPT_DEFS)
  276. PROJECT_INC := $(VPATH) $(EXTRAINCDIRS) $(KEYBOARD_PATHS)
  277. PROJECT_CONFIG := $(CONFIG_H)
  278. # Userspace setup and definitions
  279. ifeq ("$(USER_NAME)","")
  280. USER_NAME := $(KEYMAP)
  281. endif
  282. USER_PATH := users/$(USER_NAME)
  283. -include $(USER_PATH)/rules.mk
  284. ifneq ("$(wildcard $(USER_PATH)/config.h)","")
  285. CONFIG_H += $(USER_PATH)/config.h
  286. endif
  287. # Object files directory
  288. # To put object files in current directory, use a dot (.), do NOT make
  289. # this an empty or blank macro!
  290. KEYMAP_OUTPUT := $(BUILD_DIR)/obj_$(TARGET)
  291. ifneq ("$(wildcard $(KEYMAP_PATH)/config.h)","")
  292. CONFIG_H += $(KEYMAP_PATH)/config.h
  293. endif
  294. # project specific files
  295. SRC += $(KEYBOARD_SRC) \
  296. $(KEYMAP_C) \
  297. $(QUANTUM_SRC)
  298. # Optimize size but this may cause error "relocation truncated to fit"
  299. #EXTRALDFLAGS = -Wl,--relax
  300. # Search Path
  301. VPATH += $(KEYMAP_PATH)
  302. VPATH += $(USER_PATH)
  303. VPATH += $(KEYBOARD_PATHS)
  304. VPATH += $(COMMON_VPATH)
  305. include common_features.mk
  306. include $(TMK_PATH)/protocol.mk
  307. include $(TMK_PATH)/common.mk
  308. include bootloader.mk
  309. SRC += $(patsubst %.c,%.clib,$(LIB_SRC))
  310. SRC += $(patsubst %.c,%.clib,$(QUANTUM_LIB_SRC))
  311. SRC += $(TMK_COMMON_SRC)
  312. OPT_DEFS += $(TMK_COMMON_DEFS)
  313. EXTRALDFLAGS += $(TMK_COMMON_LDFLAGS)
  314. ifeq ($(PLATFORM),AVR)
  315. ifeq ($(strip $(PROTOCOL)), VUSB)
  316. include $(TMK_PATH)/protocol/vusb.mk
  317. else
  318. include $(TMK_PATH)/protocol/lufa.mk
  319. endif
  320. include $(TMK_PATH)/avr.mk
  321. endif
  322. ifeq ($(PLATFORM),ARM_ATSAM)
  323. include $(TMK_PATH)/arm_atsam.mk
  324. include $(TMK_PATH)/protocol/arm_atsam.mk
  325. endif
  326. ifeq ($(PLATFORM),CHIBIOS)
  327. include $(TMK_PATH)/protocol/chibios.mk
  328. endif
  329. ifeq ($(strip $(VISUALIZER_ENABLE)), yes)
  330. VISUALIZER_DIR = $(QUANTUM_DIR)/visualizer
  331. VISUALIZER_PATH = $(QUANTUM_PATH)/visualizer
  332. include $(VISUALIZER_PATH)/visualizer.mk
  333. endif
  334. CONFIG_H += $(POST_CONFIG_H)
  335. ALL_CONFIGS := $(PROJECT_CONFIG) $(CONFIG_H)
  336. OUTPUTS := $(KEYMAP_OUTPUT) $(KEYBOARD_OUTPUT)
  337. $(KEYMAP_OUTPUT)_SRC := $(SRC)
  338. $(KEYMAP_OUTPUT)_DEFS := $(OPT_DEFS) $(GFXDEFS) \
  339. -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYBOARD_H=\"$(QMK_KEYBOARD_H)\" -DQMK_KEYBOARD_CONFIG_H=\"$(KEYBOARD_PATH_1)/config.h\" \
  340. -DQMK_KEYMAP=\"$(KEYMAP)\" -DQMK_KEYMAP_H=\"$(KEYMAP).h\" -DQMK_KEYMAP_CONFIG_H=\"$(KEYMAP_PATH)/config.h\" \
  341. -DQMK_SUBPROJECT -DQMK_SUBPROJECT_H -DQMK_SUBPROJECT_CONFIG_H
  342. $(KEYMAP_OUTPUT)_INC := $(VPATH) $(EXTRAINCDIRS)
  343. $(KEYMAP_OUTPUT)_CONFIG := $(CONFIG_H)
  344. $(KEYBOARD_OUTPUT)_SRC := $(CHIBISRC) $(GFXSRC)
  345. $(KEYBOARD_OUTPUT)_DEFS := $(PROJECT_DEFS) $(GFXDEFS)
  346. $(KEYBOARD_OUTPUT)_INC := $(PROJECT_INC) $(GFXINC)
  347. $(KEYBOARD_OUTPUT)_CONFIG := $(PROJECT_CONFIG)
  348. # Default target.
  349. all: build check-size
  350. build: elf cpfirmware
  351. check-size: build
  352. objs-size: build
  353. include show_options.mk
  354. include $(TMK_PATH)/rules.mk