-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamext-modes.mk
83 lines (64 loc) · 2.3 KB
/
amext-modes.mk
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
#
# Custom compilation modes
# Compile one target several times with different
# configuration variables.
#
# Sample:
# CFLAGS = -O2
# bin_PROGRAM = prog
# prog_SOURCES = prog.c
#
# AM_MODES = debug
# CFLAGS_debug = -O0 -g
#
# Result:
# prog - compiled with -O2
# prog-debug - compiled with -O0 -g
#
AM_MODES ?=
# Variables that can be overrided with $(var)_$(mode)
AM_MODE_OVERRIDE += CC CXX CFLAGS CPPFLAGS DEFS LDFLAGS LIBS
## add "-MODE" string before file extension
# 1-mode, 2-filename
ModeName = $(basename $(2))-$(1)$(suffix $(2))
## add mode suffix to all plain filenames
# 1-mode, 2-file names, options
ModeFilter = $(foreach f,$(2),$(if $(filter /% -%,$(f)),$(f),$(call ModeName,$(1),$(f))))
## set per-target var
# 1-dbgvar, 2-var, 3-final
ModeVarX = $(3): $(2) = $$($(1))$(NewLine)
# 1-mode, 2-var, 3-final
ModeVarOverride = $(if $($(2)_$(1)),$(call ModeVarX,$(2)_$(1),$(2),$(3)))
# 1-mode, 2-final
ModeVarOverrideAll = $(foreach v,$(AM_MODE_OVERRIDE),$(call ModeVarOverride,$(1),$(v),$(2)))
## copy target, replace vars
# 1=cleantgt,2=rawtgt,3=prim,4=dest,5=flags,6=mode,7-newtgt,8-cleantgt,9-list
define AddModes4
$(trace8)
$(IFEQ) ($$(filter $(9),$$(am_TARGETLISTS)),)
am_TARGETLISTS += $(9)
$(ENDIF)
# add new target to old list
$(9) += $(7)
# copy details, change library names
$(8)_SOURCES := $$($(1)_SOURCES)
nodist_$$(8)_SOURCES := $$(nodist_$(1)_SOURCES)
$(8)_CPPFLAGS := $$($(1)_CPPFLAGS)
$(8)_CFLAGS := $$($(1)_CFLAGS)
$(8)_LDFLAGS := $$($(1)_LDFLAGS)
$(8)_LIBADD := $$(call ModeFilter,$(6),$$($(1)_LIBADD))
$(8)_LDADD := $$(call ModeFilter,$(6),$$($(1)_LDADD))
# add variable replacements
$(call ModeVarOverrideAll,$(6),$(call FinalTargetFile,$(8),$(7),$(3)))
endef
## add clean name, list name
# 1=cleantgt,2=rawtgt,3=prim,4=dest,5=flags,6-mode,7-raw tgt
AddModes3 = $(call AddModes4,$(1),$(2),$(3),$(4),$(5),$(6),$(7),$(call CleanName,$(7)),$(subst $(Space),_,$(5)_$(4)_$(3)))
## loop over modes
# 1=cleantgt,2=rawtgt,3=prim,4=dest,5=flags
AddModes2 = $(trace5)$(foreach m,$(AM_MODES),$(call AddModes3,$(1),$(2),$(3),$(4),$(5),$(m),$(call ModeName,$(m),$(2))))
## ignore small primaries
# 1=cleantgt,2=rawtgt,3=prim,4=dest,5=flags
AddModes = $(trace5)$(if $(filter $(3),$(AM_BIG_PRIMARIES)),$(call AddModes2,$(1),$(2),$(3),$(4),$(5)))
# Install hook
AM_TARGET_HOOKS += AddModes