diff --git a/src/ap/Makefile b/src/ap/Makefile
index 54e48a0dd032..805181d00c12 100644
--- a/src/ap/Makefile
+++ b/src/ap/Makefile
@@ -1,12 +1,10 @@
-all: libap.a
+ALL=libap.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libap.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DHOSTAPD
 CFLAGS += -DNEED_AP_MLME
diff --git a/src/common/Makefile b/src/common/Makefile
index ccb280e9019c..eeb69f0d4ff3 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -1,12 +1,10 @@
-all: libcommon.a
+ALL=libcommon.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libcommon.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DCONFIG_IEEE80211R
 CFLAGS += -DCONFIG_HS20
diff --git a/src/crypto/Makefile b/src/crypto/Makefile
index c40e95566104..94eac66fa955 100644
--- a/src/crypto/Makefile
+++ b/src/crypto/Makefile
@@ -1,14 +1,11 @@
-all: libcrypto.a
+ALL=libcrypto.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libcrypto.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
 
-include ../lib.rules
-
 CFLAGS += -DCONFIG_CRYPTO_INTERNAL
 CFLAGS += -DCONFIG_TLS_INTERNAL_CLIENT
 CFLAGS += -DCONFIG_TLS_INTERNAL_SERVER
diff --git a/src/eap_common/Makefile b/src/eap_common/Makefile
index f00b438c6188..7d6777babf4f 100644
--- a/src/eap_common/Makefile
+++ b/src/eap_common/Makefile
@@ -1,12 +1,10 @@
-all: libeap_common.a
+ALL=libeap_common.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libeap_common.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 LIB_OBJS= \
 	chap.o \
diff --git a/src/eap_peer/Makefile b/src/eap_peer/Makefile
index 6531ccd5dac0..282b89696e5c 100644
--- a/src/eap_peer/Makefile
+++ b/src/eap_peer/Makefile
@@ -1,7 +1,6 @@
-all: libeap_peer.a
+ALL=libeap_peer.a
 
-clean:
-	rm -f *~ *.o *.so *.d *.gcno *.gcda *.gcov libeap_peer.a
+include ../lib.rules
 
 install:
 	if ls *.so >/dev/null 2>&1; then \
@@ -9,7 +8,6 @@ install:
 		cp *.so $(DESTDIR)$(LIBDIR)/wpa_supplicant \
 	; fi
 
-include ../lib.rules
 
 CFLAGS += -DIEEE8021X_EAPOL
 
diff --git a/src/eap_server/Makefile b/src/eap_server/Makefile
index 1172b72466d2..4ece9aa67b35 100644
--- a/src/eap_server/Makefile
+++ b/src/eap_server/Makefile
@@ -1,12 +1,10 @@
-all: libeap_server.a
+ALL=libeap_server.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libeap_server.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DCONFIG_HS20
 
diff --git a/src/eapol_auth/Makefile b/src/eapol_auth/Makefile
index 7b927a127731..0175a19d940e 100644
--- a/src/eapol_auth/Makefile
+++ b/src/eapol_auth/Makefile
@@ -1,12 +1,10 @@
-all: libeapol_auth.a
+ALL=libeapol_auth.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libeapol_auth.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 LIB_OBJS = eapol_auth_sm.o eapol_auth_dump.o
 
diff --git a/src/eapol_supp/Makefile b/src/eapol_supp/Makefile
index 80db9d48689e..c98280b469b7 100644
--- a/src/eapol_supp/Makefile
+++ b/src/eapol_supp/Makefile
@@ -1,12 +1,10 @@
-all: libeapol_supp.a
+ALL=libeapol_supp.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libeapol_supp.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DIEEE8021X_EAPOL
 
diff --git a/src/l2_packet/Makefile b/src/l2_packet/Makefile
index 47925b790c74..20f229511e9c 100644
--- a/src/l2_packet/Makefile
+++ b/src/l2_packet/Makefile
@@ -1,12 +1,10 @@
-all: libl2_packet.a
+ALL=libl2_packet.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libl2_packet.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 LIB_OBJS = l2_packet_linux.o
 
diff --git a/src/lib.rules b/src/lib.rules
index a46315442d2a..81b895967e01 100644
--- a/src/lib.rules
+++ b/src/lib.rules
@@ -1,10 +1,5 @@
-ifndef CC
-CC=gcc
-endif
-
-ifndef CFLAGS
-CFLAGS = -MMD -O2 -Wall -g
-endif
+LIB_RULES := $(lastword $(MAKEFILE_LIST))
+include $(dir $(LIB_RULES))build.rules
 
 ifdef TEST_FUZZ
 CFLAGS += -DCONFIG_NO_RANDOM_POOL
@@ -14,18 +9,5 @@ endif
 CFLAGS += $(FUZZ_CFLAGS)
 CFLAGS += -I.. -I../utils
 
-
-Q=@
-E=echo
-ifeq ($(V), 1)
-Q=
-E=true
-endif
-ifeq ($(QUIET), 1)
-Q=@
-E=true
-endif
-
-%.o: %.c
-	$(Q)$(CC) -c -o $@ $(CFLAGS) $<
-	@$(E) "  CC " $<
+clean:
+	$(Q)rm -f *~ *.o *.d *.gcno *.gcda *.gcov $(ALL)
diff --git a/src/p2p/Makefile b/src/p2p/Makefile
index 5587fcf281d3..174cf6f6f7f4 100644
--- a/src/p2p/Makefile
+++ b/src/p2p/Makefile
@@ -1,12 +1,10 @@
-all: libp2p.a
+ALL=libp2p.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libp2p.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DCONFIG_WIFI_DISPLAY
 CFLAGS += -DCONFIG_WPS_NFC
diff --git a/src/radius/Makefile b/src/radius/Makefile
index 3ad4751dfbfe..dbe9a9a9fa71 100644
--- a/src/radius/Makefile
+++ b/src/radius/Makefile
@@ -1,14 +1,11 @@
-all: libradius.a
+ALL=libradius.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libradius.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
 
-include ../lib.rules
-
 CFLAGS += -DCONFIG_IPV6
 
 LIB_OBJS= \
diff --git a/src/rsn_supp/Makefile b/src/rsn_supp/Makefile
index eea0efba96e6..255cb73a7505 100644
--- a/src/rsn_supp/Makefile
+++ b/src/rsn_supp/Makefile
@@ -1,12 +1,10 @@
-all: librsn_supp.a
+ALL=librsn_supp.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov librsn_supp.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DCONFIG_IEEE80211R
 CFLAGS += -DCONFIG_TDLS
diff --git a/src/tls/Makefile b/src/tls/Makefile
index 52a890a157d2..0a36cf9e4530 100644
--- a/src/tls/Makefile
+++ b/src/tls/Makefile
@@ -1,14 +1,11 @@
-all: libtls.a
+ALL=libtls.a
 
-clean:
-	rm -f *~ *.o *.d libtls.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
 
-include ../lib.rules
-
 CFLAGS += -DCONFIG_INTERNAL_LIBTOMMATH
 CFLAGS += -DCONFIG_CRYPTO_INTERNAL
 CFLAGS += -DCONFIG_TLSV11
diff --git a/src/utils/Makefile b/src/utils/Makefile
index 1ee2bee67f6b..29fb1295d726 100644
--- a/src/utils/Makefile
+++ b/src/utils/Makefile
@@ -1,14 +1,11 @@
-all: libutils.a
+ALL=libutils.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libutils.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
 
-include ../lib.rules
-
 #CFLAGS += -DWPA_TRACE
 CFLAGS += -DCONFIG_IPV6
 CFLAGS += -DCONFIG_DEBUG_FILE
diff --git a/src/wps/Makefile b/src/wps/Makefile
index 4806fe8dadf7..811b62977be8 100644
--- a/src/wps/Makefile
+++ b/src/wps/Makefile
@@ -1,12 +1,10 @@
-all: libwps.a
+ALL=libwps.a
 
-clean:
-	rm -f *~ *.o *.d *.gcno *.gcda *.gcov libwps.a
+include ../lib.rules
 
 install:
 	@echo Nothing to be made.
 
-include ../lib.rules
 
 CFLAGS += -DCONFIG_P2P
 CFLAGS += -DCONFIG_WPS_OOB
