--- a/bin/Makefile
+++ b/bin/Makefile
@@ -17,7 +17,8 @@ PROGRAM = pg_repack
 REPACK_VERSION = $(shell grep '"version":' ../META.json | head -1 \
 	| sed -e 's/[ 	]*"version":[ 	]*"\(.*\)",/\1/')
 
-PG_CPPFLAGS = -I$(libpq_srcdir) -DREPACK_VERSION=$(REPACK_VERSION)
+# look in /usr/include/postgresql/internal before the server headers
+PG_CPPFLAGS = -I/usr/include/postgresql/internal -I$(libpq_srcdir) -DREPACK_VERSION=$(REPACK_VERSION)
 
 ifdef DEBUG_REPACK
 PG_CPPFLAGS += -DDEBUG_REPACK
@@ -32,4 +33,4 @@ include $(PGXS)
 # remove dependency on libxml2, libxslt, and libpam.
 # XXX: find a better way to make sure we are linking with libraries
 # from pg_config which we actually need.
-LIBS := $(filter-out -ledit -lgssapi_krb5 -lpam -lselinux -lxml2 -lxslt, $(LIBS))
+LIBS := -lpgport -lpgcommon
