Makefile: Configure optional library selection

The makefile currently automatically detects if certain libraries are
present and links with them directly.  We don't necessarily want this so
add variables to force these libraries off even if they exist on the
rootfs.

BUG=none
TEST=Build with USE_ZLIB=no and USE_AIO=no and inspect the build output
to confirm that the defines are not set and the libraries are not linked
in.

Change-Id: If9bb80e918d8e51f4f30cfa8e384bc7f3fec59d8
Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/430074
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/Makefile b/Makefile
index eeb54a4..d07f2bb 100644
--- a/Makefile
+++ b/Makefile
@@ -250,26 +250,33 @@
 	endif
 endif
 
-ifeq ($(call try-build,$(SOURCE_ZLIB),$(CFLAGS),$(LDFLAGS) -lz),y)
-	CFLAGS_DYNOPT	+= -DCONFIG_HAS_ZLIB
-	LIBS_DYNOPT	+= -lz
-else
-	NOTFOUND	+= zlib
-endif
-ifeq ($(call try-build,$(SOURCE_ZLIB),$(CFLAGS),$(LDFLAGS) -lz -static),y)
-	CFLAGS_STATOPT	+= -DCONFIG_HAS_ZLIB
-	LIBS_STATOPT	+= -lz
+# Define USE_ZLIB=no to disable zlib.
+ifneq ($(USE_ZLIB),no)
+	ifeq ($(call try-build,$(SOURCE_ZLIB),$(CFLAGS),$(LDFLAGS) -lz),y)
+		CFLAGS_DYNOPT	+= -DCONFIG_HAS_ZLIB
+		LIBS_DYNOPT	+= -lz
+	else
+		NOTFOUND	+= zlib
+	endif
+
+	ifeq ($(call try-build,$(SOURCE_ZLIB),$(CFLAGS),$(LDFLAGS) -lz -static),y)
+		CFLAGS_STATOPT	+= -DCONFIG_HAS_ZLIB
+		LIBS_STATOPT	+= -lz
+	endif
 endif
 
-ifeq ($(call try-build,$(SOURCE_AIO),$(CFLAGS),$(LDFLAGS) -laio),y)
-	CFLAGS_DYNOPT	+= -DCONFIG_HAS_AIO
-	LIBS_DYNOPT	+= -laio
-else
-	NOTFOUND	+= aio
-endif
-ifeq ($(call try-build,$(SOURCE_AIO),$(CFLAGS),$(LDFLAGS) -laio -static),y)
-	CFLAGS_STATOPT	+= -DCONFIG_HAS_AIO
-	LIBS_STATOPT	+= -laio
+# Define USE_AIO=no to disable libaio.
+ifneq ($(USE_AIO),no)
+	ifeq ($(call try-build,$(SOURCE_AIO),$(CFLAGS),$(LDFLAGS) -laio),y)
+		CFLAGS_DYNOPT	+= -DCONFIG_HAS_AIO
+		LIBS_DYNOPT	+= -laio
+	else
+		NOTFOUND	+= aio
+	endif
+	ifeq ($(call try-build,$(SOURCE_AIO),$(CFLAGS),$(LDFLAGS) -laio -static),y)
+		CFLAGS_STATOPT	+= -DCONFIG_HAS_AIO
+		LIBS_STATOPT	+= -laio
+	endif
 endif
 
 ifeq ($(LTO),1)