[PATCH v3 7/9] build: put object files into build/ folder

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Johannes Berg <johannes.berg@xxxxxxxxx>

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.

Signed-off-by: Johannes Berg <johannes.berg@xxxxxxxxx>
---
 .gitignore              |  1 +
 hostapd/Makefile        | 17 ++++++++++++-----
 hs20/client/Makefile    | 13 ++-----------
 hs20/server/Makefile    |  9 ++-------
 src/ap/Makefile         |  3 +--
 src/build.rules         | 40 ++++++++++++++++++++++++++++++++--------
 src/common/Makefile     |  3 +--
 src/crypto/Makefile     |  3 +--
 src/eap_common/Makefile |  3 +--
 src/eap_peer/Makefile   |  3 +--
 src/eap_server/Makefile |  3 +--
 src/eapol_auth/Makefile |  3 +--
 src/eapol_supp/Makefile |  3 +--
 src/l2_packet/Makefile  |  3 +--
 src/p2p/Makefile        |  3 +--
 src/radius/Makefile     |  3 +--
 src/rsn_supp/Makefile   |  3 +--
 src/tls/Makefile        |  3 +--
 src/utils/Makefile      |  3 +--
 src/wps/Makefile        |  3 +--
 wlantest/Makefile       |  7 ++++---
 wpa_supplicant/Makefile | 25 +++++++++++++++++--------
 22 files changed, 85 insertions(+), 72 deletions(-)

diff --git a/.gitignore b/.gitignore
index e057b54ea1e6..52a77fc01b9e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,4 @@ wlantest/wlantest
 wlantest/wlantest_cli
 **/parallel-vm.log
 tags
+build/
diff --git a/hostapd/Makefile b/hostapd/Makefile
index ac83730e9621..4c59ca77a243 100644
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
@@ -1272,6 +1272,8 @@ install: $(addprefix $(DESTDIR)$(BINDIR)/,$(ALL))
 
 BCHECK=../src/drivers/build.hostapd
 
+$(call BUILDOBJS,OBJS)
+
 hostapd: $(BCHECK) $(OBJS)
 	$(Q)$(CC) $(LDFLAGS) -o hostapd $(OBJS) $(LIBS)
 	@$(E) "  LD " $@
@@ -1279,6 +1281,9 @@ hostapd: $(BCHECK) $(OBJS)
 ifdef CONFIG_WPA_TRACE
 OBJS_c += ../src/utils/trace.o
 endif
+
+$(call BUILDOBJS,OBJS_c)
+
 hostapd_cli: $(OBJS_c)
 	$(Q)$(CC) $(LDFLAGS) -o hostapd_cli $(OBJS_c) $(LIBS_c)
 	@$(E) "  LD " $@
@@ -1335,6 +1340,10 @@ SOBJS += ../src/crypto/sha256-kdf.o
 SOBJS += ../src/crypto/sha384-kdf.o
 SOBJS += ../src/crypto/sha512-kdf.o
 
+$(call BUILDOBJS,NOBJS)
+$(call BUILDOBJS,HOBJS)
+$(call BUILDOBJS,SOBJS)
+
 nt_password_hash: $(NOBJS)
 	$(Q)$(CC) $(LDFLAGS) -o nt_password_hash $(NOBJS) $(LIBS_n)
 	@$(E) "  LD " $@
@@ -1347,15 +1356,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)
diff --git a/hs20/client/Makefile b/hs20/client/Makefile
index cbb1105e186b..1987a51e928f 100644
--- a/hs20/client/Makefile
+++ b/hs20/client/Makefile
@@ -71,19 +71,10 @@ CFLAGS += -DEAP_TLS_OPENSSL
 OBJS += ../../src/crypto/tls_openssl_ocsp.o
 LIBS += -lssl -lcrypto
 
+$(call BUILDOBJS,OBJS)
 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 *~
diff --git a/hs20/server/Makefile b/hs20/server/Makefile
index 24b81cd8a28a..d02ce4850c39 100644
--- a/hs20/server/Makefile
+++ b/hs20/server/Makefile
@@ -33,14 +33,9 @@ CFLAGS += $(shell xml2-config --cflags)
 LIBS += $(shell xml2-config --libs)
 OBJS += ../../src/utils/xml_libxml2.o
 
+$(call BUILDOBJS,OBJS)
 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 *~
diff --git a/src/ap/Makefile b/src/ap/Makefile
index 805181d00c12..c381ab785385 100644
--- a/src/ap/Makefile
+++ b/src/ap/Makefile
@@ -65,7 +65,6 @@ LIB_OBJS= \
 	wps_hostapd.o \
 	x_snoop.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libap.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/build.rules b/src/build.rules
index d5967df96b52..d5ce75900411 100644
--- a/src/build.rules
+++ b/src/build.rules
@@ -3,8 +3,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 $(PWD))
+ABSROOT := $(abspath $(ROOTDIR))
+_PROJ := $(_PROJ:$(ABSROOT)/%=%)
 
 ifndef CC
 CC=gcc
@@ -25,6 +30,9 @@ endif
 ifneq ($(CONFIG_FILE),)
 -include $(CONFIG_FILE)
 
+# export for sub-makefiles
+export CONFIG_CODE_COVERAGE
+
 verify_config:
 	@if [ ! -r $(CONFIG_FILE) ]; then \
 		echo 'Building $(firstword $(ALL)) requires a configuration file'; \
@@ -41,6 +49,10 @@ endif
 # default target
 _all: $(VERIFY) $(ALL) $(EXTRA_TARGETS)
 
+# continue setup
+COVSUFFIX := $(if $(CONFIG_CODE_COVERAGE),-cov,)
+PROJ := $(_PROJ)$(COVSUFFIX)
+
 Q=@
 E=echo
 ifeq ($(V), 1)
@@ -56,17 +68,29 @@ ifeq ($(Q),@)
 MAKEFLAGS += --no-print-directory
 endif
 
-ifdef CONFIG_CODE_COVERAGE
-%.o: %.c
+_DIRS =
+$(BUILDDIR):
+	mkdir -p $(BUILDDIR)
+.PHONY: _make_dirs
+_make_dirs:
+	@mkdir -p $(_DIRS)
+
+$(BUILDDIR)/$(PROJ)/src/%.o: $(ROOTDIR)src/%.c | _make_dirs
+	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
 	@$(E) "  CC " $<
-	$(Q)cd $(dir $@); $(CC) -c -o $(notdir $@) $(CFLAGS) $(notdir $<)
-else
-%.o: %.c
+$(BUILDDIR)/$(PROJ)/%.o: %.c | _make_dirs
 	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
 	@$(E) "  CC " $<
-endif
+
+BUILDOBJ = $(patsubst %,$(BUILDDIR)/$(PROJ)/%,$(patsubst $(ROOTDIR)%,%,$(1)))
+
+define BUILDOBJS =
+$(eval $(1) := $$(call BUILDOBJ,$($(1))))
+$(eval -include $($(1):%.o=%.d))
+$(eval _DIRS += $(dir $($(1))))
+endef
 
 .PHONY: common-clean
 common-clean:
 	$(Q)$(MAKE) -C $(ROOTDIR)/src clean
-	$(Q)rm -f $(ALL)
+	$(Q)rm -rf $(ALL) $(BUILDDIR)/$(PROJ)
diff --git a/src/common/Makefile b/src/common/Makefile
index eeb69f0d4ff3..f369f8191d99 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -19,7 +19,6 @@ LIB_OBJS= \
 	sae.o \
 	wpa_common.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libcommon.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/crypto/Makefile b/src/crypto/Makefile
index 94eac66fa955..cab74cd244fc 100644
--- a/src/crypto/Makefile
+++ b/src/crypto/Makefile
@@ -66,7 +66,6 @@ LIB_OBJS += random.o
 endif
 
 
+$(call BUILDOBJS,LIB_OBJS)
 libcrypto.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/eap_common/Makefile b/src/eap_common/Makefile
index 7d6777babf4f..7af4da005320 100644
--- a/src/eap_common/Makefile
+++ b/src/eap_common/Makefile
@@ -23,7 +23,6 @@ LIB_OBJS= \
 	eap_wsc_common.o \
 	ikev2_common.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libeap_common.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/eap_peer/Makefile b/src/eap_peer/Makefile
index 282b89696e5c..80e13e5f548e 100644
--- a/src/eap_peer/Makefile
+++ b/src/eap_peer/Makefile
@@ -15,7 +15,6 @@ LIB_OBJS= \
 	eap.o \
 	eap_methods.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libeap_peer.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/eap_server/Makefile b/src/eap_server/Makefile
index 4ece9aa67b35..bce3d9ce8d28 100644
--- a/src/eap_server/Makefile
+++ b/src/eap_server/Makefile
@@ -13,7 +13,6 @@ LIB_OBJS= \
 	eap_server_identity.o \
 	eap_server_methods.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libeap_server.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/eapol_auth/Makefile b/src/eapol_auth/Makefile
index 0175a19d940e..da61c9395a97 100644
--- a/src/eapol_auth/Makefile
+++ b/src/eapol_auth/Makefile
@@ -8,7 +8,6 @@ install:
 
 LIB_OBJS = eapol_auth_sm.o eapol_auth_dump.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libeapol_auth.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/eapol_supp/Makefile b/src/eapol_supp/Makefile
index c98280b469b7..2f87e8f682e2 100644
--- a/src/eapol_supp/Makefile
+++ b/src/eapol_supp/Makefile
@@ -10,7 +10,6 @@ CFLAGS += -DIEEE8021X_EAPOL
 
 LIB_OBJS = eapol_supp_sm.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libeapol_supp.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/l2_packet/Makefile b/src/l2_packet/Makefile
index 20f229511e9c..bd8d83d63354 100644
--- a/src/l2_packet/Makefile
+++ b/src/l2_packet/Makefile
@@ -8,7 +8,6 @@ install:
 
 LIB_OBJS = l2_packet_linux.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libl2_packet.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/p2p/Makefile b/src/p2p/Makefile
index 174cf6f6f7f4..9a8846dc1c82 100644
--- a/src/p2p/Makefile
+++ b/src/p2p/Makefile
@@ -21,7 +21,6 @@ LIB_OBJS= \
 	p2p_sd.o \
 	p2p_utils.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libp2p.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/radius/Makefile b/src/radius/Makefile
index dbe9a9a9fa71..1ca6e88065c7 100644
--- a/src/radius/Makefile
+++ b/src/radius/Makefile
@@ -14,7 +14,6 @@ LIB_OBJS= \
 	radius_das.o \
 	radius_server.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libradius.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/rsn_supp/Makefile b/src/rsn_supp/Makefile
index 255cb73a7505..fb3bac53ba9c 100644
--- a/src/rsn_supp/Makefile
+++ b/src/rsn_supp/Makefile
@@ -19,7 +19,6 @@ LIB_OBJS= \
 	wpa.o \
 	wpa_ie.o
 
+$(call BUILDOBJS,LIB_OBJS)
 librsn_supp.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/tls/Makefile b/src/tls/Makefile
index 0a36cf9e4530..db6f9a93a8d7 100644
--- a/src/tls/Makefile
+++ b/src/tls/Makefile
@@ -31,7 +31,6 @@ LIB_OBJS= \
 	x509v3.o
 
 
+$(call BUILDOBJS,LIB_OBJS)
 libtls.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/utils/Makefile b/src/utils/Makefile
index 29fb1295d726..1b987e489962 100644
--- a/src/utils/Makefile
+++ b/src/utils/Makefile
@@ -34,7 +34,6 @@ LIB_OBJS += edit.o
 
 #LIB_OBJS += pcsc_funcs.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libutils.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/src/wps/Makefile b/src/wps/Makefile
index 811b62977be8..e0b664dbab34 100644
--- a/src/wps/Makefile
+++ b/src/wps/Makefile
@@ -33,7 +33,6 @@ LIB_OBJS= \
 	wps_upnp_ssdp.o \
 	wps_upnp_web.o
 
+$(call BUILDOBJS,LIB_OBJS)
 libwps.a: $(LIB_OBJS)
 	$(AR) crT $@ $?
-
--include $(OBJS:%.o=%.d)
diff --git a/wlantest/Makefile b/wlantest/Makefile
index fee80f6f4e2c..8fe7fb7d832f 100644
--- a/wlantest/Makefile
+++ b/wlantest/Makefile
@@ -71,6 +71,9 @@ TOBJS += gcmp.o
 
 OBJS_cli = wlantest_cli.o
 
+$(call BUILDOBJS,OBJS)
+$(call BUILDOBJS,TOBJS)
+$(call BUILDOBJS,OBJS_cli)
 
 wlantest: $(OBJS) $(OWN_LIBS)
 	$(LDO) $(LDFLAGS) -o wlantest $(OBJS) $(OWN_LIBS) $(LIBS)
@@ -82,6 +85,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 *~
diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile
index 8645d908f821..1e99ccfd94f7 100644
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
@@ -1860,28 +1860,34 @@ dynamic_eap_methods: $(EAPDYN)
 
 BCHECK=../src/drivers/build.wpa_supplicant
 
+$(call BUILDOBJS,OBJS_priv)
 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
 
+$(call BUILDOBJS,OBJS)
 wpa_supplicant: $(BCHECK) $(OBJS) $(EXTRA_progs)
 	$(Q)$(LDO) $(LDFLAGS) -o wpa_supplicant $(OBJS) $(LIBS) $(EXTRALIBS)
 	@$(E) "  LD " $@
 
+$(call BUILDOBJS,OBJS_t)
 eapol_test: $(OBJS_t)
 	$(Q)$(LDO) $(LDFLAGS) -o eapol_test $(OBJS_t) $(LIBS)
 	@$(E) "  LD " $@
 
+$(call BUILDOBJS,OBJS_t2)
 preauth_test: $(OBJS_t2)
 	$(Q)$(LDO) $(LDFLAGS) -o preauth_test $(OBJS_t2) $(LIBS)
 	@$(E) "  LD " $@
 
+$(call BUILDOBJS,OBJS_p)
 wpa_passphrase: $(OBJS_p)
 	$(Q)$(LDO) $(LDFLAGS) -o wpa_passphrase $(OBJS_p) $(LIBS_p) $(LIBS)
 	@$(E) "  LD " $@
 
+$(call BUILDOBJS,OBJS_c)
 wpa_cli: $(OBJS_c)
 	$(Q)$(LDO) $(LDFLAGS) -o wpa_cli $(OBJS_c) $(LIBS_c)
 	@$(E) "  LD " $@
@@ -1895,6 +1901,7 @@ LIBCTRLSO += ../src/utils/os_$(CONFIG_OS).c
 LIBCTRLSO += ../src/utils/common.c
 LIBCTRLSO += ../src/utils/wpa_debug.c
 
+$(call BUILDOBJS,LIBCTRL)
 libwpa_client.a: $(LIBCTRL)
 	$(Q)rm -f $@
 	$(Q)$(AR) crs $@ $?
@@ -1904,14 +1911,17 @@ 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
+$(call BUILDOBJS,OBJS_wpatest)
+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 " $@
 
+$(call BUILDOBJS,OBJS_nfc)
 nfc_pw_token: $(OBJS_nfc)
 	$(Q)$(LDO) $(LDFLAGS) -o nfc_pw_token $(OBJS_nfc) $(LIBS)
 	@$(E) "  LD " $@
@@ -1989,8 +1999,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 +2016,3 @@ clean: common-clean
 	rm -f libwpa_client.a
 	rm -f libwpa_client.so
 	rm -f libwpa_test1 libwpa_test2
-
--include $(OBJS:%.o=%.d)
-- 
2.26.2


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux