1e5b75505Sopenharmony_ci.PHONY: all
2e5b75505Sopenharmony_ciall: _all
3e5b75505Sopenharmony_ci
4e5b75505Sopenharmony_ci# disable built-in rules
5e5b75505Sopenharmony_ci.SUFFIXES:
6e5b75505Sopenharmony_ci
7e5b75505Sopenharmony_ci# setup some variables
8e5b75505Sopenharmony_ciROOTDIR := $(dir $(lastword $(MAKEFILE_LIST)))
9e5b75505Sopenharmony_ciROOTDIR := $(dir $(ROOTDIR:%../src/=%))../
10e5b75505Sopenharmony_ciBUILDDIR ?= $(abspath $(ROOTDIR)build)
11e5b75505Sopenharmony_ciBUILDDIR := $(BUILDDIR:%/=%)
12e5b75505Sopenharmony_ciABSROOT := $(abspath $(ROOTDIR))
13e5b75505Sopenharmony_ciifeq ($(origin OUT),command line)
14e5b75505Sopenharmony_ci_PROJ := $(OUT:%/=%)
15e5b75505Sopenharmony_ci_PROJ := $(_PROJ:$(BUILDDIR)/%=%)
16e5b75505Sopenharmony_cielse
17e5b75505Sopenharmony_ci_PROJ := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
18e5b75505Sopenharmony_ci_PROJ := $(_PROJ:$(ABSROOT)/%=%)
19e5b75505Sopenharmony_ciendif
20e5b75505Sopenharmony_ci
21e5b75505Sopenharmony_ciifndef CC
22e5b75505Sopenharmony_ciCC=gcc
23e5b75505Sopenharmony_ciendif
24e5b75505Sopenharmony_ci
25e5b75505Sopenharmony_ciifndef RANLIB
26e5b75505Sopenharmony_ciRANLIB=ranlib
27e5b75505Sopenharmony_ciendif
28e5b75505Sopenharmony_ci
29e5b75505Sopenharmony_ciifndef LDO
30e5b75505Sopenharmony_ciLDO=$(CC)
31e5b75505Sopenharmony_ciendif
32e5b75505Sopenharmony_ci
33e5b75505Sopenharmony_ciifndef CFLAGS
34e5b75505Sopenharmony_ciCFLAGS = -MMD -O2 -Wall -g
35e5b75505Sopenharmony_ciendif
36e5b75505Sopenharmony_ci
37e5b75505Sopenharmony_ciifneq ($(CONFIG_FILE),)
38e5b75505Sopenharmony_ci-include $(CONFIG_FILE)
39e5b75505Sopenharmony_ci
40e5b75505Sopenharmony_ci# export for sub-makefiles
41e5b75505Sopenharmony_ciexport CONFIG_CODE_COVERAGE
42e5b75505Sopenharmony_ci
43e5b75505Sopenharmony_ci.PHONY: verify_config
44e5b75505Sopenharmony_civerify_config:
45e5b75505Sopenharmony_ci	@if [ ! -r $(CONFIG_FILE) ]; then \
46e5b75505Sopenharmony_ci		echo 'Building $(firstword $(ALL)) requires a configuration file'; \
47e5b75505Sopenharmony_ci		echo '(.config). See README for more instructions. You can'; \
48e5b75505Sopenharmony_ci		echo 'run "cp defconfig .config" to create an example'; \
49e5b75505Sopenharmony_ci		echo 'configuration.'; \
50e5b75505Sopenharmony_ci		exit 1; \
51e5b75505Sopenharmony_ci	fi
52e5b75505Sopenharmony_ciVERIFY := verify_config
53e5b75505Sopenharmony_cielse
54e5b75505Sopenharmony_ciVERIFY :=
55e5b75505Sopenharmony_ciendif
56e5b75505Sopenharmony_ci
57e5b75505Sopenharmony_ci# default target
58e5b75505Sopenharmony_ci.PHONY: _all
59e5b75505Sopenharmony_ci_all: $(VERIFY) $(ALL) $(EXTRA_TARGETS)
60e5b75505Sopenharmony_ci
61e5b75505Sopenharmony_ci# continue setup
62e5b75505Sopenharmony_ciCOVSUFFIX := $(if $(CONFIG_CODE_COVERAGE),-cov,)
63e5b75505Sopenharmony_ciPROJ := $(_PROJ)$(COVSUFFIX)
64e5b75505Sopenharmony_ci
65e5b75505Sopenharmony_ciQ=@
66e5b75505Sopenharmony_ciE=echo
67e5b75505Sopenharmony_ciifeq ($(V), 1)
68e5b75505Sopenharmony_ciQ=
69e5b75505Sopenharmony_ciE=true
70e5b75505Sopenharmony_ciendif
71e5b75505Sopenharmony_ciifeq ($(QUIET), 1)
72e5b75505Sopenharmony_ciQ=@
73e5b75505Sopenharmony_ciE=true
74e5b75505Sopenharmony_ciendif
75e5b75505Sopenharmony_ci
76e5b75505Sopenharmony_ciifeq ($(Q),@)
77e5b75505Sopenharmony_ciMAKEFLAGS += --no-print-directory
78e5b75505Sopenharmony_ciendif
79e5b75505Sopenharmony_ci
80e5b75505Sopenharmony_ci_DIRS := $(BUILDDIR)/$(PROJ)
81e5b75505Sopenharmony_ci.PHONY: _make_dirs
82e5b75505Sopenharmony_ci_make_dirs:
83e5b75505Sopenharmony_ci	@mkdir -p $(_DIRS)
84e5b75505Sopenharmony_ci
85e5b75505Sopenharmony_ci$(BUILDDIR)/$(PROJ)/src/%.o: $(ROOTDIR)src/%.c $(CONFIG_FILE) | _make_dirs
86e5b75505Sopenharmony_ci	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
87e5b75505Sopenharmony_ci	@$(E) "  CC " $<
88e5b75505Sopenharmony_ci$(BUILDDIR)/$(PROJ)/%.o: %.c $(CONFIG_FILE) | _make_dirs
89e5b75505Sopenharmony_ci	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
90e5b75505Sopenharmony_ci	@$(E) "  CC " $<
91e5b75505Sopenharmony_ci# for the fuzzing tests
92e5b75505Sopenharmony_ci$(BUILDDIR)/$(PROJ)/wpa_supplicant/%.o: $(ROOTDIR)wpa_supplicant/%.c $(CONFIG_FILE) | _make_dirs
93e5b75505Sopenharmony_ci	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
94e5b75505Sopenharmony_ci	@$(E) "  CC " $<
95e5b75505Sopenharmony_ci
96e5b75505Sopenharmony_ci# libraries - they know how to build themselves
97e5b75505Sopenharmony_ci# (lib_phony so we recurse all the time)
98e5b75505Sopenharmony_ci.PHONY: lib_phony
99e5b75505Sopenharmony_cilib_phony:
100e5b75505Sopenharmony_ci# nothing
101e5b75505Sopenharmony_ci
102e5b75505Sopenharmony_ci$(BUILDDIR)/$(PROJ)/%.a: $(CONFIG_FILE) lib_phony
103e5b75505Sopenharmony_ci	$(Q)$(MAKE) -C $(ROOTDIR)$(dir $(@:$(BUILDDIR)/$(PROJ)/%=%)) OUT=$(abspath $(dir $@))/
104e5b75505Sopenharmony_ci
105e5b75505Sopenharmony_ciBUILDOBJ = $(patsubst %,$(BUILDDIR)/$(PROJ)/%,$(patsubst $(ROOTDIR)%,%,$(1)))
106e5b75505Sopenharmony_ci
107e5b75505Sopenharmony_ci.PHONY: common-clean
108e5b75505Sopenharmony_cicommon-clean:
109e5b75505Sopenharmony_ci	$(Q)rm -rf $(ALL) $(BUILDDIR)/$(PROJ)
110