build: Put object files into build/ folder

Instead of building in the source tree, put most object
files into the build/ folder at the root, and put each
thing that's being built into a separate folder.

This then allows us to build hostapd and wpa_supplicant
(or other combinations) without "make clean" inbetween.

For the tests keep the objects in place for now (and to
do that, add the build rule) so that we don't have to
rewrite all of that with $(call BUILDOBJS,...) which is
just noise there.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
This commit is contained in:
Johannes Berg 2020-09-18 11:49:53 +02:00 committed by Jouni Malinen
parent 0464d5d5d6
commit 722138cd25
26 changed files with 136 additions and 82 deletions

1
.gitignore vendored
View File

@ -34,3 +34,4 @@ wlantest/wlantest
wlantest/wlantest_cli
**/parallel-vm.log
tags
build/

View File

@ -7,9 +7,9 @@ CFLAGS += -I../src
CFLAGS += -I../src/utils
OBJS_both += ../src/utils/libutils.a
OBJS_both += ../src/crypto/libcrypto.a
OBJS_both += ../src/tls/libtls.a
EAP_LIBS += ../src/utils/libutils.a
EAP_LIBS += ../src/crypto/libcrypto.a
EAP_LIBS += ../src/tls/libtls.a
OBJS_both += ../src/eap_common/eap_peap_common.o
OBJS_both += ../src/eap_common/eap_psk_common.o
@ -83,8 +83,12 @@ CFLAGS += -DEAP_SERVER
OBJS_lib=$(OBJS_both) $(OBJS_peer) $(OBJS_server)
_OBJS_VAR := OBJS_lib
include ../src/objs.mk
OBJS_ex = eap_example.o eap_example_peer.o eap_example_server.o
_OBJS_VAR := OBJS_ex
include ../src/objs.mk
../src/utils/libutils.a:
@ -99,8 +103,8 @@ OBJS_ex = eap_example.o eap_example_peer.o eap_example_server.o
ifneq ($(CONFIG_SOLIB), yes)
LIBEAP = libeap.a
libeap.a: $(OBJS_lib)
$(AR) crT libeap.a $(OBJS_lib)
libeap.a: $(EAP_LIBS) $(OBJS_lib)
$(AR) crT libeap.a $^
$(RANLIB) libeap.a
else
@ -108,8 +112,8 @@ CFLAGS += -fPIC -DPIC
LDFLAGS += -shared
LIBEAP = libeap.so
libeap.so: $(OBJS_lib)
$(LDO) $(LDFLAGS) $(OBJS_lib) -o $(LIBEAP)
libeap.so: $(EAP_LIBS) $(OBJS_lib)
$(LDO) $(LDFLAGS) $^ -o $(LIBEAP)
endif

View File

@ -1272,6 +1272,9 @@ install: $(addprefix $(DESTDIR)$(BINDIR)/,$(ALL))
BCHECK=../src/drivers/build.hostapd
_OBJS_VAR := OBJS
include ../src/objs.mk
hostapd: $(BCHECK) $(OBJS)
$(Q)$(CC) $(LDFLAGS) -o hostapd $(OBJS) $(LIBS)
@$(E) " LD " $@
@ -1279,6 +1282,10 @@ hostapd: $(BCHECK) $(OBJS)
ifdef CONFIG_WPA_TRACE
OBJS_c += ../src/utils/trace.o
endif
_OBJS_VAR := OBJS_c
include ../src/objs.mk
hostapd_cli: $(OBJS_c)
$(Q)$(CC) $(LDFLAGS) -o hostapd_cli $(OBJS_c) $(LIBS_c)
@$(E) " LD " $@
@ -1335,6 +1342,13 @@ SOBJS += ../src/crypto/sha256-kdf.o
SOBJS += ../src/crypto/sha384-kdf.o
SOBJS += ../src/crypto/sha512-kdf.o
_OBJS_VAR := NOBJS
include ../src/objs.mk
_OBJS_VAR := HOBJS
include ../src/objs.mk
_OBJS_VAR := SOBJS
include ../src/objs.mk
nt_password_hash: $(NOBJS)
$(Q)$(CC) $(LDFLAGS) -o nt_password_hash $(NOBJS) $(LIBS_n)
@$(E) " LD " $@
@ -1347,15 +1361,13 @@ sae_pk_gen: $(SOBJS)
$(Q)$(CC) $(LDFLAGS) -o sae_pk_gen $(SOBJS) $(LIBS_s)
@$(E) " LD " $@
.PHONY: lcov-html
lcov-html:
lcov -c -d .. > lcov.info
lcov -c -d $(BUILDDIR) > lcov.info
genhtml lcov.info --output-directory lcov-html
clean: common-clean
rm -f core *~ *.o nt_password_hash hlr_auc_gw
rm -f core *~ nt_password_hash hlr_auc_gw
rm -f sae_pk_gen
rm -f *.d *.gcno *.gcda *.gcov
rm -f lcov.info
rm -rf lcov-html
-include $(OBJS:%.o=%.d)

View File

@ -71,19 +71,11 @@ CFLAGS += -DEAP_TLS_OPENSSL
OBJS += ../../src/crypto/tls_openssl_ocsp.o
LIBS += -lssl -lcrypto
_OBJS_VAR := OBJS
include ../../src/objs.mk
hs20-osu-client: $(OBJS)
$(Q)$(LDO) $(LDFLAGS) -o hs20-osu-client $(OBJS) $(LIBS)
@$(E) " LD " $@
clean: common-clean
rm -f core *~ *.o *.d
rm -f ../../src/utils/*.o
rm -f ../../src/utils/*.d
rm -f ../../src/common/*.o
rm -f ../../src/common/*.d
rm -f ../../src/crypto/*.o
rm -f ../../src/crypto/*.d
rm -f ../../src/wps/*.o
rm -f ../../src/wps/*.d
-include $(OBJS:%.o=%.d)
rm -f core *~

View File

@ -33,14 +33,10 @@ CFLAGS += $(shell xml2-config --cflags)
LIBS += $(shell xml2-config --libs)
OBJS += ../../src/utils/xml_libxml2.o
_OBJS_VAR := OBJS
include ../../src/objs.mk
hs20_spp_server: $(OBJS)
$(LDO) $(LDFLAGS) -o hs20_spp_server $(OBJS) $(LIBS)
clean: common-clean
rm -f core *~ *.o *.d
rm -f ../../src/utils/*.o
rm -f ../../src/utils/*.d
rm -f ../../src/crypto/*.o
rm -f ../../src/crypto/*.d
-include $(OBJS:%.o=%.d)
rm -f core *~

View File

@ -24,10 +24,11 @@ LLIBS = -lrt
OBJS_ex = radius_example.o
_OBJS_VAR := OBJS_ex
include ../src/objs.mk
radius_example: $(OBJS_ex) $(LIBS)
$(LDO) $(LDFLAGS) -o radius_example $(OBJS_ex) $(LIBS) $(LLIBS)
clean: common-clean
rm -f core *~ *.o *.d
-include $(OBJS:%.o=%.d)

View File

@ -65,7 +65,7 @@ LIB_OBJS= \
wps_hostapd.o \
x_snoop.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libap.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -4,8 +4,13 @@ all: _all
# disable built-in rules
.SUFFIXES:
# setup some variables
ROOTDIR := $(dir $(lastword $(MAKEFILE_LIST)))
ROOTDIR := $(dir $(ROOTDIR:%/=%))
ROOTDIR := $(dir $(ROOTDIR:%../src/=%))../
BUILDDIR := $(ROOTDIR)build
_PROJ := $(abspath $(dir $(firstword $(MAKEFILE_LIST))))
ABSROOT := $(abspath $(ROOTDIR))
_PROJ := $(_PROJ:$(ABSROOT)/%=%)
ifndef CC
CC=gcc
@ -26,6 +31,9 @@ endif
ifneq ($(CONFIG_FILE),)
-include $(CONFIG_FILE)
# export for sub-makefiles
export CONFIG_CODE_COVERAGE
.PHONY: verify_config
verify_config:
@if [ ! -r $(CONFIG_FILE) ]; then \
@ -44,6 +52,10 @@ endif
.PHONY: _all
_all: $(VERIFY) $(ALL) $(EXTRA_TARGETS)
# continue setup
COVSUFFIX := $(if $(CONFIG_CODE_COVERAGE),-cov,)
PROJ := $(_PROJ)$(COVSUFFIX)
Q=@
E=echo
ifeq ($(V), 1)
@ -59,17 +71,21 @@ ifeq ($(Q),@)
MAKEFLAGS += --no-print-directory
endif
ifdef CONFIG_CODE_COVERAGE
%.o: %.c
@$(E) " CC " $<
$(Q)cd $(dir $@); $(CC) -c -o $(notdir $@) $(CFLAGS) $(notdir $<)
else
%.o: %.c
_DIRS := $(BUILDDIR)/$(PROJ)
.PHONY: _make_dirs
_make_dirs:
@mkdir -p $(_DIRS)
$(BUILDDIR)/$(PROJ)/src/%.o: $(ROOTDIR)src/%.c | _make_dirs
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
@$(E) " CC " $<
endif
$(BUILDDIR)/$(PROJ)/%.o: %.c | _make_dirs
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
@$(E) " CC " $<
BUILDOBJ = $(patsubst %,$(BUILDDIR)/$(PROJ)/%,$(patsubst $(ROOTDIR)%,%,$(1)))
.PHONY: common-clean
common-clean:
$(Q)$(MAKE) -C $(ROOTDIR)/src clean
$(Q)rm -f $(ALL)
$(Q)rm -rf $(ALL) $(BUILDDIR)/$(PROJ)

View File

@ -19,7 +19,7 @@ LIB_OBJS= \
sae.o \
wpa_common.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libcommon.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -66,7 +66,7 @@ LIB_OBJS += random.o
endif
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libcrypto.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -23,7 +23,7 @@ LIB_OBJS= \
eap_wsc_common.o \
ikev2_common.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libeap_common.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -15,7 +15,7 @@ LIB_OBJS= \
eap.o \
eap_methods.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libeap_peer.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -13,7 +13,7 @@ LIB_OBJS= \
eap_server_identity.o \
eap_server_methods.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libeap_server.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -8,7 +8,7 @@ install:
LIB_OBJS = eapol_auth_sm.o eapol_auth_dump.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libeapol_auth.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -10,7 +10,7 @@ CFLAGS += -DIEEE8021X_EAPOL
LIB_OBJS = eapol_supp_sm.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libeapol_supp.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -8,7 +8,7 @@ install:
LIB_OBJS = l2_packet_linux.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libl2_packet.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

3
src/objs.mk Normal file
View File

@ -0,0 +1,3 @@
$(_OBJS_VAR) := $(call BUILDOBJ,$($(_OBJS_VAR)))
-include $($(_OBJS_VAR):%.o=%.d)
_DIRS += $(dir $($(_OBJS_VAR)))

View File

@ -21,7 +21,7 @@ LIB_OBJS= \
p2p_sd.o \
p2p_utils.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libp2p.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -14,7 +14,7 @@ LIB_OBJS= \
radius_das.o \
radius_server.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libradius.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -19,7 +19,7 @@ LIB_OBJS= \
wpa.o \
wpa_ie.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
librsn_supp.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -31,7 +31,7 @@ LIB_OBJS= \
x509v3.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libtls.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -34,7 +34,7 @@ LIB_OBJS += edit.o
#LIB_OBJS += pcsc_funcs.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libutils.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -33,7 +33,7 @@ LIB_OBJS= \
wps_upnp_ssdp.o \
wps_upnp_web.o
_OBJS_VAR := LIB_OBJS
include ../objs.mk
libwps.a: $(LIB_OBJS)
$(AR) crT $@ $?
-include $(OBJS:%.o=%.d)

View File

@ -5,6 +5,13 @@ ALL=test-base64 test-md4 test-milenage \
include ../src/build.rules
# for now, keep building in this folder, otherwise we need to
# put each object for each test into a separate variable and
# then do the objs.mk dance for it ...
%.o: %.c
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
@$(E) " CC " $<
ifdef LIBFUZZER
CC=clang
CFLAGS = -MMD -O2 -Wall -g

View File

@ -71,6 +71,12 @@ TOBJS += gcmp.o
OBJS_cli = wlantest_cli.o
_OBJS_VAR := OBJS
include ../src/objs.mk
_OBJS_VAR := TOBJS
include ../src/objs.mk
_OBJS_VAR := OBJS_cli
include ../src/objs.mk
wlantest: $(OBJS) $(OWN_LIBS)
$(LDO) $(LDFLAGS) -o wlantest $(OBJS) $(OWN_LIBS) $(LIBS)
@ -82,6 +88,4 @@ test_vectors: $(TOBJS) $(OWN_LIBS)
$(LDO) $(LDFLAGS) -o test_vectors $(TOBJS) $(OWN_LIBS) $(LIBS)
clean: common-clean
rm -f core *~ *.o *.d
-include $(OBJS:%.o=%.d)
rm -f core *~

View File

@ -1860,28 +1860,40 @@ dynamic_eap_methods: $(EAPDYN)
BCHECK=../src/drivers/build.wpa_supplicant
_OBJS_VAR := OBJS_priv
include ../src/objs.mk
wpa_priv: $(BCHECK) $(OBJS_priv)
$(Q)$(LDO) $(LDFLAGS) -o wpa_priv $(OBJS_priv) $(LIBS)
@$(E) " LD " $@
$(OBJS_c) $(OBJS_t) $(OBJS_t2) $(OBJS) $(BCHECK) $(EXTRA_progs): .config
_OBJS_VAR := OBJS
include ../src/objs.mk
wpa_supplicant: $(BCHECK) $(OBJS) $(EXTRA_progs)
$(Q)$(LDO) $(LDFLAGS) -o wpa_supplicant $(OBJS) $(LIBS) $(EXTRALIBS)
@$(E) " LD " $@
_OBJS_VAR := OBJS_t
include ../src/objs.mk
eapol_test: $(OBJS_t)
$(Q)$(LDO) $(LDFLAGS) -o eapol_test $(OBJS_t) $(LIBS)
@$(E) " LD " $@
_OBJS_VAR := OBJS_t2
include ../src/objs.mk
preauth_test: $(OBJS_t2)
$(Q)$(LDO) $(LDFLAGS) -o preauth_test $(OBJS_t2) $(LIBS)
@$(E) " LD " $@
_OBJS_VAR := OBJS_p
include ../src/objs.mk
wpa_passphrase: $(OBJS_p)
$(Q)$(LDO) $(LDFLAGS) -o wpa_passphrase $(OBJS_p) $(LIBS_p) $(LIBS)
@$(E) " LD " $@
_OBJS_VAR := OBJS_c
include ../src/objs.mk
wpa_cli: $(OBJS_c)
$(Q)$(LDO) $(LDFLAGS) -o wpa_cli $(OBJS_c) $(LIBS_c)
@$(E) " LD " $@
@ -1895,6 +1907,8 @@ LIBCTRLSO += ../src/utils/os_$(CONFIG_OS).c
LIBCTRLSO += ../src/utils/common.c
LIBCTRLSO += ../src/utils/wpa_debug.c
_OBJS_VAR := LIBCTRL
include ../src/objs.mk
libwpa_client.a: $(LIBCTRL)
$(Q)rm -f $@
$(Q)$(AR) crs $@ $?
@ -1904,14 +1918,19 @@ libwpa_client.so: $(LIBCTRLSO)
@$(E) " CC $@ ($^)"
$(Q)$(CC) $(LDFLAGS) -o $@ $(CFLAGS) -shared -fPIC $^
libwpa_test1: libwpa_test.o libwpa_client.a
$(Q)$(LDO) $(LDFLAGS) -o libwpa_test1 libwpa_test.o libwpa_client.a $(LIBS_c)
OBJS_wpatest := libwpa_test.o
_OBJS_VAR := OBJS_wpatest
include ../src/objs.mk
libwpa_test1: $(OBJS_wpatest) libwpa_client.a
$(Q)$(LDO) $(LDFLAGS) -o libwpa_test1 $(OBJS_wpatest) libwpa_client.a $(LIBS_c)
@$(E) " LD " $@
libwpa_test2: libwpa_test.o libwpa_client.so
$(Q)$(LDO) $(LDFLAGS) -o libwpa_test2 libwpa_test.o -L. -lwpa_client $(LIBS_c)
libwpa_test2: $(OBJS_wpatest) libwpa_client.so
$(Q)$(LDO) $(LDFLAGS) -o libwpa_test2 $(OBJS_wpatest) -L. -lwpa_client $(LIBS_c)
@$(E) " LD " $@
_OBJS_VAR := OBJS_nfc
include ../src/objs.mk
nfc_pw_token: $(OBJS_nfc)
$(Q)$(LDO) $(LDFLAGS) -o nfc_pw_token $(OBJS_nfc) $(LIBS)
@$(E) " LD " $@
@ -1989,8 +2008,9 @@ FIPSLD=$(FIPSDIR)/bin/fipsld
fips:
$(MAKE) CC=$(FIPSLD) FIPSLD_CC="$(CC)"
lcov-html: wpa_supplicant.gcda
lcov -c -d .. > lcov.info
.PHONY: lcov-html
lcov-html: $(call BUILDOBJ,wpa_supplicant.gcda)
lcov -c -d $(BUILDDIR) > lcov.info
genhtml lcov.info --output-directory lcov-html
clean: common-clean
@ -2005,5 +2025,3 @@ clean: common-clean
rm -f libwpa_client.a
rm -f libwpa_client.so
rm -f libwpa_test1 libwpa_test2
-include $(OBJS:%.o=%.d)