ca0f40
diff --git a/Makefile b/Makefile
ca0f40
index 51e41f0..573a799 100644
ca0f40
--- a/Makefile
ca0f40
+++ b/Makefile
ca0f40
@@ -25,9 +25,6 @@ NODEPTARGETS=<version.h> <clean>
ca0f40
 
ca0f40
 INSTALL = install
ca0f40
 
ca0f40
-LDFLAGS += -ldl
ca0f40
-CFLAGS ?= -O2 -g
ca0f40
-CFLAGS += -Wall -fPIC
ca0f40
 CPPFLAGS += -D__LIBHUGETLBFS__
ca0f40
 
ca0f40
 ARCH ?= $(shell uname -m | sed -e s/i.86/i386/)
ca0f40
@@ -279,22 +276,22 @@ snapshot: $(VERSION)
ca0f40
 obj32/%.o: %.c
ca0f40
 	@$(VECHO) CC32 $@
ca0f40
 	@mkdir -p obj32
ca0f40
-	$(CC32) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
ca0f40
+	$(CC32) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c $<
ca0f40
 
ca0f40
 obj64/%.o: %.c
ca0f40
 	@$(VECHO) CC64 $@
ca0f40
 	@mkdir -p obj64
ca0f40
-	$(CC64) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
ca0f40
+	$(CC64) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c $<
ca0f40
 
ca0f40
 obj32/%.o: %.S
ca0f40
 	@$(VECHO) AS32 $@
ca0f40
 	@mkdir -p obj32
ca0f40
-	$(CC32) $(CPPFLAGS) -o $@ -c $<
ca0f40
+	$(CC32) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c $<
ca0f40
 
ca0f40
 obj64/%.o: %.S
ca0f40
 	@$(VECHO) AS64 $@
ca0f40
 	@mkdir -p obj64
ca0f40
-	$(CC64) $(CPPFLAGS) -o $@ -c $<
ca0f40
+	$(CC64) $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ -c $<
ca0f40
 
ca0f40
 obj32/libhugetlbfs.a: $(LIBOBJS32)
ca0f40
 	@$(VECHO) AR32 $@
ca0f40
diff --git a/tests/Makefile b/tests/Makefile
ca0f40
index 073df96..508a6ec 100644
ca0f40
--- a/tests/Makefile
ca0f40
+++ b/tests/Makefile
ca0f40
@@ -33,8 +33,8 @@ HELPERS = get_hugetlbfs_path compare_kvers
ca0f40
 HELPER_LIBS = libheapshrink.so
ca0f40
 BADTOOLCHAIN = bad-toolchain.sh
ca0f40
 
ca0f40
-CFLAGS = -O2 -Wall -g
ca0f40
-CPPFLAGS = -I..
ca0f40
+CFLAGS ?= -O2 -Wall -g
ca0f40
+CPPFLAGS += -I..
ca0f40
 STATIC_LIBHUGE = -Wl,--whole-archive -lhugetlbfs -Wl,--no-whole-archive
ca0f40
 STATIC_LDLIBS = -Wl,--no-as-needed -lpthread
ca0f40
 LDLIBS = $(STATIC_LDLIBS) -ldl -lhugetlbfs_privutils