aboutsummaryrefslogtreecommitdiff
path: root/make/lib_platforms.mk
blob: 9cf9704fd174cc5231ae69de335fc8d4628015e9 (plain) (blame)
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
# compiler-rt Configuration Support
#
# This should be included following 'lib_util.mk'.

# The simple variables configurations can define.
PlainConfigVariables := Configs Description
PerConfigVariables := UniversalArchs Arch $(AvailableOptions)
RequiredConfigVariables := Configs Description

###
# Load Platforms

# Template: subdir_traverse_template subdir
define load_platform_template
$(call Set,PlatformName,$(basename $(notdir $(1))))
ifneq ($(DEBUGMAKE),)
  $$(info MAKE: $(PlatformName): Loading platform)
endif

# Construct the variable key for this directory.
$(call Set,PlatformKey,Platform.$(PlatformName))
$(call Append,PlatformKeys,$(PlatformKey))
$(call Set,$(PlatformKey).Name,$(PlatformName))
$(call Set,$(PlatformKey).Path,$(1))

# Reset platform specific variables to sentinel value.
$$(foreach var,$(PlainConfigVariables) $(PerConfigVariables),\
  $$(call Set,$$(var),UNDEFINED))
$$(foreach var,$(PerConfigVariables),\
  $$(foreach config,$$(Configs),\
    $$(call Set,$$(var).$$(config),UNDEFINED)))
$$(foreach var,$(PerConfigVariables),\
  $$(foreach arch,$(AvailableArchs),\
    $$(call Set,$$(var).$$(arch),UNDEFINED)))

# Get the platform variables.
include make/options.mk
include $(1)

# Check for undefined required variables.
$$(foreach var,$(RequiredConfigVariables),\
  $$(if $$(call strneq,UNDEFINED,$$($$(var))),, \
	$$(error $(Dir): variable '$$(var)' was not undefined)))

# Check that exactly one of UniversalArchs or Arch was defined.
$$(if $$(and $$(call strneq,UNDEFINED,$$(UniversalArchs)),\
             $$(call strneq,UNDEFINED,$$(Arch))),\
    $$(error '$(1)': cannot define both 'UniversalArchs' and 'Arch'))
$$(if $$(or $$(call strneq,UNDEFINED,$$(UniversalArchs)),\
            $$(call strneq,UNDEFINED,$$(Arch))),,\
    $$(error '$(1)': must define one of 'UniversalArchs' and 'Arch'))

# Collect all the platform variables for subsequent use.
$$(foreach var,$(PlainConfigVariables) $(PerConfigVariables),\
  $$(if $$(call strneq,UNDEFINED,$$($$(var))),\
    $$(call CopyVariable,$$(var),$(PlatformKey).$$(var))))
$$(foreach var,$(PerConfigVariables),\
  $$(foreach config,$$(Configs),\
    $$(if $$(call strneq,UNDEFINED,$$($$(var).$$(config))),\
      $$(call CopyVariable,$$(var).$$(config),$(PlatformKey).$$(var).$$(config))))\
  $$(foreach arch,$(AvailableArchs),\
    $$(if $$(call strneq,UNDEFINED,$$($$(var).$$(arch))),\
      $$(call CopyVariable,$$(var).$$(arch),$(PlatformKey).$$(var).$$(arch))))\
  $$(foreach config,$$(Configs),\
    $$(foreach arch,$(AvailableArchs),\
      $$(if $$(call strneq,UNDEFINED,$$($$(var).$$(config).$$(arch))),\
        $$(call CopyVariable,$$(var).$$(config).$$(arch),\
                $(PlatformKey).$$(var).$$(config).$$(arch))))))

ifneq ($(DEBUGMAKE),)
  $$(info MAKE: $(PlatformName): Done loading platform)
endif
endef

# Evaluate this now so we do not have to worry about order of evaluation.
PlatformFiles := $(wildcard make/platform/*.mk)
ifneq ($(DEBUGMAKE),)
 $(info MAKE: Loading platforms: $(PlatformFiles))
endif

$(foreach file,$(PlatformFiles),\
  $(eval $(call load_platform_template,$(file))))