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