2 $(if
$D,$(info Info
: Avoiding redundant
include ($(MAKEFILE_LIST
))))
5 unexport _WLAN_COMMON_MK
# in case of make -e
7 ################################################################
8 # Summary and Namespace Rules
9 ################################################################
10 # This is a special makefile fragment intended for common use.
11 # The most important design principle is that it be used only to
12 # define variables and functions in a tightly controlled namespace.
13 # If a make include file is used to set rules, pattern rules,
14 # or well known variables like CFLAGS, it can have unexpected
15 # effects on the including makefile, with the result that people
16 # either stop including it or stop changing it.
17 # Therefore, the only way to keep this a file which can be
18 # safely included by any GNU makefile and extended at will is
19 # to allow it only to set variables and only in its own namespace.
20 # The namespace is "WLAN_CamelCase" for normal variables,
21 # "wlan_lowercase" for functions, and WLAN_UPPERCASE for boolean
22 # "constants" (these are all really just make variables; only the
23 # usage patterns differ).
24 # Internal (logically file-scoped) variables are prefixed with "-"
25 # and have no other namespace restrictions.
26 # Every variable defined here should match one of these patterns.
28 ################################################################
29 # Enforce required conditions
30 ################################################################
32 ifneq (,$(filter 3.7% 3.80,$(MAKE_VERSION
)))
33 $(error
$(MAKE
): Error
: version
$(MAKE_VERSION
) too old
, 3.81+ required
)
36 ################################################################
37 # Derive including makefile since it's a little tricky.
38 ################################################################
40 WLAN_Makefile
:= $(abspath
$(lastword
$(filter-out $(lastword
$(MAKEFILE_LIST
)),$(MAKEFILE_LIST
))))
42 ################################################################
43 # Shiny new ideas, can be enabled via environment for testing.
44 ################################################################
47 $(info Info
: BUILDING WITH
"WLAN_MakeBeta" ENABLED
!)
49 #export SHELLOPTS ?= pipefail
54 ################################################################
55 # Allow a makefile to force this file into all child makes.
56 ################################################################
58 ifdef WLAN_StickyCommon
59 export MAKEFILES
:= $(MAKEFILES
) $(abspath
$(lastword
$(MAKEFILE_LIST
)))
62 ################################################################
63 # Host type determination
64 ################################################################
66 _common-uname-s
:= $(shell uname
-s
)
68 # Typically this will not be tested explicitly; it's the default condition.
69 WLAN_HOST_TYPE
:= unix
71 ifneq (,$(filter Linux
,$(_common-uname-s
)))
73 else ifneq (,$(filter CYGWIN
%,$(_common-uname-s
)))
75 WLAN_WINDOWS_HOST
:= 1
76 else ifneq (,$(filter Darwin
,$(_common-uname-s
)))
79 else ifneq (,$(filter FreeBSD NetBSD
,$(_common-uname-s
)))
81 else ifneq (,$(filter SunOS
%,$(_common-uname-s
)))
82 WLAN_SOLARIS_HOST
:= 1
85 ################################################################
87 ################################################################
90 space
:= $(empty
) $(empty
)
93 ################################################################
95 ################################################################
97 # Provides enhanced-format messages from make logic.
98 wlan_die
= $(error Error
: $1)
99 wlan_warning
= $(warning Warning
: $1)
100 wlan_info
= $(info Info
: $1)
102 # Debug function to enable make verbosity.
103 wlan_dbg
= $(if
$D,$(call wlan_info
,$1))
105 # Debug function to expose values of the listed variables.
106 wlan_dbgv
= $(foreach _
,$1,$(call wlan_dbg
,$_=$($_)))
108 # Make-time assertion.
110 ifeq (,$(findstring clean,$(MAKECMDGOALS
)))
111 $(if
$1,,$(call wlan_die
,$2))
115 # Checks for the presence of an option in an option string
116 # like "aaa-bbb-ccc-ddd".
117 wlan_opt
= $(if
$(findstring -$1-,-$2-),1,0)
119 # Compares two dotted numeric strings (e.g 2.3.16.1) for $1 >= $2
120 define wlan_version_ge
121 $(findstring TRUE
,$(shell bash
-c
'sort -cu -t. -k1,1nr -k2,2nr -k3,3nr -k4,4nr <(echo -e "$2\n$1") 2>&1 || echo TRUE'))
124 # This is a useful macro to wrap around a compiler command line,
125 # e.g. "$(call wlan_cc,<command-line>). It organizes flags in a
126 # readable way while taking care not to change any ordering
127 # which matters. It also provides a hook for externally
128 # imposed C flags which can be passed in from the top level.
129 # This would be the best place to add a check for
130 # command line length. Requires a $(strlen) function;
133 $(filter-out -D
% -I
%,$1) $(filter -D
%,$1) $(filter -I
%,$1) $(WLAN_EXTERNAL_CFLAGS
)
136 # Applies the standard cygpath translation for a path on Cygwin.
138 $(if
$(WLAN_CYGWIN_HOST
),$(shell cygpath
-m
$1),$1)
141 ################################################################
142 # Standard make variables
143 ################################################################
145 # This points to the root of the build tree, currently known to
146 # be 2 levels above the directory of this file.
147 ifndef WLAN_TreeBaseA
148 ifdef WLAN_CYGWIN_HOST
149 WLAN_TreeBaseA
:= $(shell cygpath
-m
-a
$(dir $(lastword
$(MAKEFILE_LIST
)))..
/..
)
151 WLAN_TreeBaseA
:= $(subst \
,/,$(realpath
$(dir $(lastword
$(MAKEFILE_LIST
)))..
/..
))
155 # We've observed a bug, or at least a surprising behavior, in emake which
156 # causes the $(realpath) above to fail so this fallback is used.
157 ifndef WLAN_TreeBaseA
158 WLAN_TreeBaseA
:= $(shell cd
$(dir $(lastword
$(MAKEFILE_LIST
)))..
/..
&& pwd
)
161 # Export these values so they can be used by scripts or nmake/pmake makefiles.
162 export WLAN_TreeBaseA
164 # We may eventually remove this and require an
165 # explict absolute-vs-relative choice.
166 export WLAN_TreeBase
:= $(WLAN_TreeBaseA
)
168 # Pick up the "relpath" make function.
169 include $(WLAN_TreeBaseA
)/src-rt-6.x
.4708/makefiles
/RelPath.mk
171 # This is a relativized version of $(WLAN_TreeBaseA).
172 export WLAN_TreeBaseR
= $(call relpath
,$(WLAN_TreeBaseA
))
174 # For compatibility, due to the prevalence of $(SRCBASE)
175 WLAN_SrcBaseA
:= $(WLAN_TreeBaseA
)/src-rt-6.x
.4708
176 WLAN_SrcBaseR
= $(patsubst %/,%,$(dir $(WLAN_TreeBaseR
)))
178 # Show makefile list before we start including things.
179 $(call wlan_dbgv
, CURDIR MAKEFILE_LIST
)
181 ################################################################
182 # Pick up the "universal settings file" containing
183 # the list of all available software components.
184 ################################################################
186 include $(WLAN_TreeBaseA
)/src-rt-6.x
.4708/tools
/release
/WLAN.usf
188 ################################################################
189 # Calculate paths to requested components.
190 ################################################################
192 # This uses pattern matching to pull component paths from
193 # their basenames (e.g. src/wl/xyz => xyz).
194 # It also strips out component paths which don't currently exist.
195 # This may be required due to our "partial-source" build styles
196 # and the fact that linux mkdep throws an error when a directory
197 # specified with -I doesn't exist.
198 define _common-component-names-to-rel-paths
200 $(patsubst $(WLAN_TreeBaseA
)/%,%,$(wildcard $(addprefix $(WLAN_TreeBaseA
)/,\
201 $(sort $(foreach name
,$(if
$1,$1,$(WLAN_AllComponentPaths
)),$(filter %/$(name
),$(WLAN_AllComponentPaths
))))))))
204 # If WLAN_ComponentsInUse is unset it defaults to the full set (for now, anyway - TODO).
205 # It's also possible to request the full set with a literal '*'.
206 ifeq (,$(WLAN_ComponentsInUse
))
207 WLAN_ComponentsInUse
:= $(sort $(notdir $(WLAN_AllComponentPaths
)))
208 # $(call wlan_die,no SW component request)
209 else ifeq (*,$(WLAN_ComponentsInUse
))
210 WLAN_ComponentsInUse
:= $(sort $(notdir $(WLAN_AllComponentPaths
)))
211 $(call wlan_info
,all SW components requested
("$(WLAN_ComponentsInUse)"))
213 WLAN_ComponentsInUse
:= $(sort $(WLAN_ComponentsInUse
))
215 WLAN_ComponentPathsInUse
:= $(call _common-component-names-to-rel-paths
,$(WLAN_ComponentsInUse
))
217 # Test that all requested components exist.
218 ifneq ($(sort $(WLAN_ComponentsInUse
)),$(notdir $(WLAN_ComponentPathsInUse
)))
219 # TODO - turned off until old branches support this infrastructure.
220 # $(call wlan_warning,bogus component request: "$(sort $(WLAN_ComponentsInUse))" != "$(notdir $(WLAN_ComponentPathsInUse))")
223 # Loop through all components in use. If an xyz.mk file exists at the base of
224 # component xyz's subtree, include it and use its contents to modify the list
225 # of include and src dirs. Otherwise, use the defaults for that component.
226 # Also generate a WLAN_ComponentBaseDir_xyz variable for each component "xyz".
227 WLAN_ComponentIncPathsInUse
:=
228 WLAN_ComponentSrcPathsInUse
:=
229 $(foreach _path
,$(WLAN_ComponentPathsInUse
), \
230 $(if
$(wildcard $(WLAN_TreeBaseA
)/$(_path
)/$(notdir $(_path
)).mk
),$(eval
include $(WLAN_TreeBaseA
)/$(_path
)/$(notdir $(_path
)).mk
)) \
231 $(eval
$(notdir $(_path
))_IncDirs ?
= include) \
232 $(eval
$(notdir $(_path
))_SrcDirs ?
= src
) \
233 $(eval WLAN_ComponentIncPathsInUse
+= $(addprefix $(_path
)/,$($(notdir $(_path
))_IncDirs
))) \
234 $(eval WLAN_ComponentSrcPathsInUse
+= $(addprefix $(_path
)/,$($(notdir $(_path
))_SrcDirs
))) \
235 $(eval WLAN_ComponentBaseDir_
$$(notdir $(_path
)) := $$(WLAN_TreeBaseA
)/$(_path
)) \
238 # Public convenience macros based on WLAN_ComponentPathsInUse list.
239 export WLAN_ComponentSrcDirsR
= $(addprefix $(WLAN_TreeBaseR
)/,$(WLAN_ComponentSrcPathsInUse
))
240 export WLAN_ComponentIncDirsR
= $(addprefix $(WLAN_TreeBaseR
)/,$(WLAN_ComponentIncPathsInUse
))
241 export WLAN_ComponentIncPathR
= $(addprefix -I
,$(WLAN_ComponentIncDirsR
))
243 export WLAN_ComponentSrcDirsA
= $(addprefix $(WLAN_TreeBaseA
)/,$(WLAN_ComponentSrcPathsInUse
))
244 export WLAN_ComponentIncDirsA
= $(addprefix $(WLAN_TreeBaseA
)/,$(WLAN_ComponentIncPathsInUse
))
245 export WLAN_ComponentIncPathA
= $(addprefix -I
,$(WLAN_ComponentIncDirsA
))
247 export WLAN_ComponentSrcDirs
= $(WLAN_ComponentSrcDirsA
)
248 export WLAN_ComponentIncDirs
= $(WLAN_ComponentIncDirsA
)
249 export WLAN_ComponentIncPath
= $(WLAN_ComponentIncPathA
)
251 # Dump a representative sample of derived variables in debug mode.
252 $(call wlan_dbgv
, WLAN_TreeBaseA WLAN_TreeBaseR WLAN_SrcBaseA WLAN_SrcBaseR \
253 WLAN_ComponentPathsInUse WLAN_ComponentIncPath WLAN_ComponentIncPathR \
254 WLAN_ComponentSrcDirs WLAN_ComponentSrcDirsR
)
256 # Special case for Windows to reflect CL in the build log if used.
257 ifdef WLAN_WINDOWS_HOST
259 $(info Info
: CL
=$(CL
))
263 # A big hammer for debugging each shell invocation.
264 # Warning: this can get lost if a sub-makefile sets SHELL explicitly, and
265 # if so the parent should add $WLAN_ShellDebugSHELL to the call.
269 ifdef WLAN_ShellDebug
270 ORIG_SHELL
:= $(SHELL
)
271 SHELL
= $(strip $(warning Shell
: ORIG_SHELL
=$(ORIG_SHELL
) PATH
=$(PATH
))$(ORIG_SHELL
)) -x
272 WLAN_ShellDebugSHELL
:= SHELL
='$$(warning Shell: ORIG_SHELL=$$(ORIG_SHELL) PATH=$$(PATH))$(ORIG_SHELL) -x'
275 # Variables of general utility.
277 WLAN_Python
:= python
279 WLAN_WINPFX ?
= //broadcom
/sjca
281 # These macros are used to stash an extra copy of generated source files,
282 # such that when a source release is made those files can be reconstituted
283 # from the stash during builds. Required if the generating tools or inputs
285 define wlan_copy_to_gen
286 $(if
$(WLAN_COPY_GEN
),&& mkdir
-pv
$(subst $(abspath
$2),$(abspath
$2/$(WLAN_GenBaseDir
)),$(dir $1)) && \
287 cp
-pv
$1 $(subst $(abspath
$2),$(abspath
$2/$(WLAN_GenBaseDir
)),$1.GEN
))
290 ################################################################
291 # CLM function; generates a rule to run ClmCompiler iff the XML exists.
292 # USAGE: $(call WLAN_GenClmCompilerRule,target-dir,src-base[,flags[,ext]])
293 # This macro uses GNU make's eval function to generate an
294 # explicit rule to generate a particular CLM data file each time
295 # it's called. Make variables which should be evaluated during eval
296 # processing get one $, those which must defer till "runtime" get $$.
297 # The CLM "base flags" are the default minimal set, the "ext flags"
298 # are those which must be present for all release builds.
299 # The "clm_compiled" phony target is provided for makefiles which need
300 # to defer some other processing until CLM data is ready, and "clm_clean"
301 # and "CLM_DATA_FILES" make it easier for internal client makefiles to
302 # clean up CLM data (externally, this is treated as source and not removed).
303 # The outermost conditional allows this rule to become a no-op
304 # in external settings where there is no XML input file while allowing
305 # it to turn back on automatically if an XML file is provided.
306 # A vpath is used to find the XML input because this file is not allowed
307 # to be present in external builds. Use of vpath allows it to be "poached"
308 # from the internal build as necessary.
309 # There are a few ways to set ClmCompiler flags: passing them as the $3
310 # parameter (preferred) or by overriding CLMCOMPDEFFLAGS. Additionally,
311 # when the make variable CLM_TYPE is defined it points to a config file
312 # for the compiler. The CLMCOMPEXTFLAGS variable contains "external flags"
313 # which must be present for all external builds. It can be forced to "" for
315 # Note: the .c file is listed with and without a path due to the way the
316 # Linux kernel Makefiles generate .depend data.
317 # The undocumented $5 parameter has been used for dongle testing
318 # against variant XML but its semantics are subject to change.
319 CLMCOMPDEFFLAGS ?
= --region
'\#a/0' --region
'\#r/0' --full_set
320 CLMCOMPEXTFLAGS
:= --obfuscate
321 define WLAN_GenClmCompilerRule
323 .PHONY
: clm_compiled clm_clean
324 vpath wlc_clm_data
$4.c
$1 $$(abspath
$1)
325 ifneq (,$(wildcard $(addsuffix /wl
/clm
/private
/wlc_clm_data.xml
,$2 $2/..
/..
/src
$2/..
/..
/..
/src
)))
326 vpath wlc_clm_data.xml
$(wildcard $(addsuffix /wl
/clm
/private
,$5 $2 $2/..
/..
/src
$2/..
/..
/..
/src
))
327 vpath
%.clm
$(addsuffix /wl
/clm
/types
,$2 $2/..
/..
/src
$2/..
/..
/..
/src
)
328 $$(sort $1/wlc_clm_data
$4.c .
/wlc_clm_data
$4.c
): wlc_clm_data.xml
$$(if
$$(CLM_TYPE
),$$(CLM_TYPE
).clm
) ; \
329 $$(strip $$(abspath
$$(<D
)/..
/..
/..
/tools
/build
/ClmCompiler
) \
330 $$(if
$$(CLM_TYPE
),--config_file
$$(lastword
$$^
) $3,$$(if
$3,$3,$$(CLMCOMPDEFFLAGS
))) \
331 $(CLMCOMPEXTFLAGS
) $$< $$@
$$(call wlan_copy_to_gen
,$$@
,$2))
333 vpath
%.GEN
$(subst $(abspath
$2),$(abspath
$2/$(WLAN_GenBaseDir
)),$1) $(sort $(patsubst %/,%,$(dir $(wildcard $(subst $(abspath
$2),$(abspath
$2/$(WLAN_GenBaseDir
)),$(dir $1))*/*.GEN
))))
334 $1/%: %.GEN
; cp
-pv
$$< $$@
336 clm_compiled
: $1/wlc_clm_data
$4.c
337 clm_clean
:: ; $$(RM
) $1/wlc_clm_data
$4.c
338 CLM_DATA_FILES
+= $1/wlc_clm_data
$4.c
342 ################################################################
344 endif # _WLAN_COMMON_MK