forked from qmk/qmk_userspace
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
130 lines (102 loc) · 4.67 KB
/
Makefile
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
# Copyright 2018-2024 Nick Brassel (@tzarc)
# SPDX-License-Identifier: GPL-2.0-or-later
# avoid 'Entering|Leaving directory' messages
MAKEFLAGS += --no-print-directory
QMK_USERSPACE := $(patsubst %/,%,$(dir $(shell realpath "$(lastword $(MAKEFILE_LIST))")))
ifeq ($(QMK_USERSPACE),)
QMK_USERSPACE := $(shell pwd)
endif
# Add extra binaries to path
#export PATH := $(QMK_USERSPACE)/bin:$(PATH)
# Deal with macOS
ifeq ($(shell uname -s),Darwin)
SED = gsed
ECHO = gecho
else
SED = sed
ECHO = echo
endif
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Cleaning
.PHONY: clean distclean userspace_clean
userspace_clean:
@rm -f $(QMK_USERSPACE)/compile_commands.json || true
clean: userspace_clean
@$(MAKE) -C $(QMK_USERSPACE)/qmk_firmware clean
distclean: userspace_clean
@$(MAKE) -C $(QMK_USERSPACE)/qmk_firmware distclean
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Builds
# short name ! keyboard path ! keymap name
BOARD_DEFS := \
reverb!dasky/reverb!dasky \
crkbd!crkbd!dasky \
# short name ! keyboard path ! keymap name ! link source ! link target
LINKED_BOARD_DEFS := \
nah!keyboards/dasky/nah!dasky!keyboards-dev/nah \
echo!keyboards/dasky/echo!dasky!keyboards-dev/echo \
stinky!keyboards/stinky!default!keyboards-dev/stinky \
g303!keyboards/logitech/g303!default!mouse-dev/g303 \
cp!keyboards/mb/cp!dasky!keyboards-dev/cp \
sp!keyboards/dasky/sp!default!keyboards-dev/sp \
halved!keyboards/dasky/halved!default!mouse-dev/halved \
cirque!keyboards/cirque_gen4_dev_kit!default!mouse-dev/cirque_gen4_dev_kit \
pr!keyboards/pointright!default!keyboards-dev/pointright \
pl!keyboards/pointleft!default!keyboards-dev/pointleft \
r5!keyboards/rival5!default!mouse-dev/rival5 \
keyboards_folder := keyboards/
empty :=
define handle_board_entry
board_name_$1 := $$(word 1,$$(subst !, ,$1))
board_keyboard_$1 := $$(word 2,$$(subst !, ,$1))
board_keyboard_stripped_$1 := $$(subst $$(keyboards_folder),$$(empty),$$(board_keyboard_$1))
board_keymap_$1 := $$(word 3,$$(subst !, ,$1))
.PHONY: $$(board_name_$1) bin_$$(board_name_$1)
$$(board_name_$1): bin_$$(board_name_$1)
bin_$$(board_name_$1):
@$(ECHO) -e "\e[38;5;14mBuilding: $$(board_keyboard_stripped_$1):$$(board_keymap_$1)\e[0m"
+@cd "$(QMK_USERSPACE)/qmk_firmware" \
&& { \
[ -z "$$(NO_COMPILEDB)" ] \
&& qmk compile --compiledb -kb $$(board_keyboard_stripped_$1) -km $$(board_keymap_$1) \
|| qmk compile -kb $$(board_keyboard_stripped_$1) -km $$(board_keymap_$1); \
}
@[ -e "$$(QMK_USERSPACE)/qmk_firmware/compile_commands.json" ] && cp $$(QMK_USERSPACE)/qmk_firmware/compile_commands.json $$(QMK_USERSPACE) \
|| true
endef
$(foreach board_entry,$(BOARD_DEFS),$(eval $(call handle_board_entry,$(board_entry))))
define handle_linked_board_entry
board_name_$1 := $$(word 1,$$(subst !, ,$1))
board_keyboard_$1 := $$(word 2,$$(subst !, ,$1))
board_keymap_$1 := $$(word 3,$$(subst !, ,$1))
link_source_$1 := $$(word 4,$$(subst !, ,$1))
link_target_$1 := $$(word 5,$$(subst !, ,$1))
ifeq ($$(link_target_$1),)
link_target_$1 := $$(board_keyboard_$1)
endif
bin_$$(board_name_$1): link_$$(link_target_$1)
.PHONY: links link_$$(link_target_$1) unlinks unlink_$$(link_target_$1)
links: link_$$(link_target_$1)
link_$$(link_target_$1):
@if [ ! -L "$(QMK_USERSPACE)/qmk_firmware/$$(link_target_$1)" ] ; then \
$(ECHO) -e "\e[38;5;14mSymlinking: $$(link_source_$1) -> $$(link_target_$1)\e[0m" ; \
ln -sf $(QMK_USERSPACE)/$$(link_source_$1) $(QMK_USERSPACE)/qmk_firmware/$$(link_target_$1) ; \
if [ -z "$$(grep -P '^$$(link_target_$1)$$$$' $(QMK_USERSPACE)/qmk_firmware/.git/info/exclude 2>/dev/null)" ] ; then \
$(ECHO) $$(link_target_$1) >> $(QMK_USERSPACE)/qmk_firmware/.git/info/exclude ; \
fi ; \
fi
unlinks: unlink_$$(link_target_$1)
unlink_$$(link_target_$1):
@if [ -L "$(QMK_USERSPACE)/qmk_firmware/$$(link_target_$1)" ] ; then \
$(ECHO) -e "\e[38;5;14mRemoving symlink: $$(link_source_$1) -> $$(link_target_$1)\e[0m" ; \
rm $(QMK_USERSPACE)/qmk_firmware/$$(link_target_$1) || true; \
$(SED) -i "\@^$$(link_target_$1)@d" $(QMK_USERSPACE)/qmk_firmware/.git/info/exclude; \
fi
clean: unlink_$$(link_target_$1)
distclean: unlink_$$(link_target_$1)
generated-files: links
endef
$(foreach board_entry,$(LINKED_BOARD_DEFS),$(eval $(call handle_board_entry,$(board_entry))))
$(foreach board_entry,$(LINKED_BOARD_DEFS),$(eval $(call handle_linked_board_entry,$(board_entry))))
.PHONY: all
all: nah echo stinky prime g303 reverb crkbd sp cp