#!/bin/bash
# This script installs the page fault test
###SHELLPACK preamble pft-install 0.12x
GIT_LOCATION=https://github.com/gormanm/pft
MIRROR_LOCATION="$WEBROOT/pft/$TARFILE"

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK git_fetch pft-${VERSION}.tar.gz pft-${VERSION}-installed

install-depends libnuma-devel

# Patch it if necessary
pushd $SHELLPACK_SOURCES/pft-${VERSION}-installed
if [ ! -e /usr/include/numa.h ]; then
	echo WARNING: PFT REQUIRES NUMA.H AND IT IS NOT AVAILABLE
	echo WORKING AROUND, BUT MAY NOT BEHAVE AS EXPECTED
echo "
diff --git a/Makefile b/Makefile
index bd88168..2c87f71 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ CFLAGS  = \$(COPT) \$(DEFS) \$(INCLS) \$(ECFLAGS)
 
 LDOPTS	= #-dnon_shared
 # comment out '-lnuma' for platforms w/o libnuma -- laptops?
-LDLIBS	= -lpthread -lrt -lnuma
+LDLIBS	= -lpthread -lrt
 LDFLAGS = \$(CMODE) \$(LDOPTS) \$(ELDFLAGS)
 
 HDRS    =
@@ -32,7 +32,7 @@ OBJS    = pft.o
 EXTRAHDRS =
 
 # Include 'numa_stubs.o' for platforms w/o libnuma -- laptops?
-EXTRAOBJS = /usr/include/numa.h /usr/include/numaif.h
+EXTRAOBJS = 
 
 PROGS	= pft
 
diff --git a/numa_stubs.h b/numa_stubs.h
new file mode 100644
index 0000000..e2aa947
--- /dev/null
+++ b/numa_stubs.h
@@ -0,0 +1,32 @@
+#ifndef __NUMA_STUBS_H
+#define __NUMA_STUBS_H
+
+static inline int numa_bitmask_isbitset(const void *bmp, unsigned int n)
+{
+	return 1;
+}
+
+static inline void *numa_allocate_cpumask(void)
+{
+	return NULL;
+}
+
+static inline int numa_sched_getaffinity(pid_t pid, void *mask)
+{
+	return 0;
+}
+
+static inline int numa_num_task_cpus(void)
+{
+	return 32;
+}
+
+#define MPOL_PREFERRED 0
+static inline int mbind(void *addr, unsigned long len, int mode,
+		unsigned long *nodemask, unsigned long maxnode,
+		unsigned flags)
+{
+	return 0;
+}
+
+#endif
diff --git a/pft.c b/pft.c
index 2ea0986..5544803 100644
--- a/pft.c
+++ b/pft.c
@@ -26,8 +26,6 @@
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <numa.h>
-#include <numaif.h>
 #include <pthread.h>
 #include <sched.h>
 #include <stdarg.h>
@@ -38,6 +36,7 @@
 #include <unistd.h>
 
 #include \"version.h\"
+#include \"numa_stubs.h\"
 
 #if defined(USE_RUSAGE_THREAD) && !defined(RUSAGE_THREAD)
 #define RUSAGE_THREAD 1
" | patch -p1 || exit -1
fi

###SHELLPACK make

echo pft installed successfully
