This patch contains the differences between the upstream tarball and
the sources actually used for building the package.

Option single-debian-patch is used as the changes are tracked in git.
--- mongrel2-1.9.1.orig/Makefile
+++ mongrel2-1.9.1/Makefile
@@ -1,12 +1,12 @@
-CFLAGS=-g -O2 -Wall -Wextra -Isrc -Isrc/polarssl/include -pthread -rdynamic -DNDEBUG $(OPTFLAGS) -D_FILE_OFFSET_BITS=64
-LIBS=-lzmq -ldl -lsqlite3 $(OPTLIBS)
+CFLAGS+=-g -O2 -Wall -Wextra -idirafter "src" -pthread -rdynamic -DNDEBUG $(OPTFLAGS) -D_FILE_OFFSET_BITS=64
+LIBS=-lzmq -ldl -lsqlite3 -lpolarssl $(OPTLIBS)
 PREFIX?=/usr/local
 
 get_objs = $(addsuffix .o,$(basename $(wildcard $(1))))
 
 ASM=$(wildcard src/**/*.S src/*.S)
 RAGEL_TARGETS=src/state.c src/http11/http11_parser.c
-SOURCES=$(wildcard src/polarssl/library/*.c src/**/*.c src/*.c) $(RAGEL_TARGETS)
+SOURCES=$(wildcard src/**/*.c src/*.c) $(RAGEL_TARGETS)
 OBJECTS=$(patsubst %.c,%.o,${SOURCES}) $(patsubst %.S,%.o,${ASM})
 OBJECTS_EXTERNAL+=$(call get_objs,src/polarssl/library/*.c)
 OBJECTS_NOEXT=$(filter-out ${OBJECTS_EXTERNAL},${OBJECTS})
@@ -15,28 +15,28 @@ LIB_OBJ=$(filter-out src/mongrel2.o,${OB
 TEST_SRC=$(wildcard tests/*_tests.c)
 TESTS=$(patsubst %.c,%,${TEST_SRC})
 MAKEOPTS=OPTFLAGS="${NOEXTCFLAGS} ${OPTFLAGS}" OPTLIBS="${OPTLIBS}" LIBS="${LIBS}" DESTDIR="${DESTDIR}" PREFIX="${PREFIX}"
-ifdef $($(shell sh init.sh))
-endif
+#ifdef $($(shell sh init.sh))
+#endif
 
 all: bin/mongrel2 tests m2sh procer
 
-dev: CFLAGS=-g -Wall -Isrc -Wall -Wextra $(OPTFLAGS) -D_FILE_OFFSET_BITS=64
+dev: CFLAGS=-g -Wall -idirafter "src" -Wall -Wextra $(OPTFLAGS) -D_FILE_OFFSET_BITS=64
 dev: all
 
 ${OBJECTS_NOEXT}: CFLAGS += ${NOEXTCFLAGS}
 
-src/polarssl/include/polarssl/config.h: src/polarssl_config.h
-	cp src/polarssl_config.h src/polarssl/include/polarssl/config.h
+#src/polarssl/include/polarssl/config.h: src/polarssl_config.h
+#	cp src/polarssl_config.h src/polarssl/include/polarssl/config.h
 
 bin/mongrel2: build/libm2.a src/mongrel2.o
-	$(CC) $(CFLAGS) src/mongrel2.o -o $@ $< $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) src/mongrel2.o -o $@ $< $(LIBS)
 
 build/libm2.a: CFLAGS += -fPIC
 build/libm2.a: build ${LIB_OBJ}
 	ar rcs $@ ${LIB_OBJ}
 	ranlib $@
 
-build: src/polarssl/include/polarssl/config.h
+build:
 	@mkdir -p build
 	@mkdir -p bin
 
@@ -46,6 +46,7 @@ clean:
 	rm -f tests/test.pid 
 	rm -f tests/tests.log 
 	rm -f tests/empty.sqlite 
+	rm -f tests/request_payloads.txt
 	rm -f tools/lemon/lemon
 	rm -f tools/m2sh/tests/tests.log 
 	find . -name "*.gc*" -exec rm {} \;
--- mongrel2-1.9.1.orig/tools/procer/Makefile
+++ mongrel2-1.9.1/tools/procer/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-DNDEBUG -pthread -g -I../../src -Wall $(OPTFLAGS)
+CFLAGS+=-DNDEBUG -pthread -g -I../../src -Wall $(OPTFLAGS)
 PREFIX?=/usr/local
 LIBS?=-lzmq 
 SOURCES=$(wildcard *.c)
@@ -8,7 +8,7 @@ all: procer
 
 
 procer: ../../build/libm2.a ${OBJECTS}
-	gcc $(OPTFLAGS) $(OPTLIBS) -o $@ ${OBJECTS} ../../build/libm2.a ${LIBS}
+	gcc $(LDFLAGS) $(OPTFLAGS) $(OPTLIBS) -o $@ ${OBJECTS} ../../build/libm2.a ${LIBS}
 
 clean:
 	rm -f *.o procer
--- mongrel2-1.9.1.orig/tools/filters/Makefile
+++ mongrel2-1.9.1/tools/filters/Makefile
@@ -1,6 +1,6 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/polarssl/include $(OPTFLAGS) -g -fPIC -shared -nostartfiles -L../../build
-LDFLAGS=$(OPTLIBS)
+CFLAGS+=-idirafter ../../src $(OPTFLAGS) -g -fPIC -shared -nostartfiles -L../../build
+LDFLAGS+=$(OPTLIBS)
 
 all: null.so rewrite.so sendfile.so
 
--- mongrel2-1.9.1.orig/tools/m2sh/Makefile
+++ mongrel2-1.9.1/tools/m2sh/Makefile
@@ -1,4 +1,4 @@
-CFLAGS=-DNDEBUG -DNO_LINENOS -pthread -g -I../../src -Isrc -Wall $(OPTFLAGS)
+CFLAGS+=-DNDEBUG -DNO_LINENOS -pthread -g -I../../src -Isrc -Wall $(OPTFLAGS)
 LIBS=-lzmq -lsqlite3 ../../build/libm2.a $(OPTLIBS)
 
 PREFIX?=/usr/local
@@ -24,10 +24,10 @@ build/libm2sh.a: ${LIB_OBJ}
 
 build/m2sh: ../lemon/lemon ../../build/libm2.a ${OBJECTS}
 	mkdir -p build
-	$(CC) $(CFLAGS) -o build/m2sh ${OBJECTS} ../../build/libm2.a $(LIBS)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o build/m2sh ${OBJECTS} ../../build/libm2.a $(LIBS)
 
 ../lemon/lemon: ../lemon/lemon.c
-	$(CC) -O2 ../lemon/lemon.c -o ../lemon/lemon
+	$(CC) $(CFLAGS) $(LDFLAGS) ../lemon/lemon.c -o ../lemon/lemon
 
 tests: build/libm2sh.a ${TESTS}
 	sh ./tests/runtests.sh
--- mongrel2-1.9.1.orig/tools/config_modules/Makefile
+++ mongrel2-1.9.1/tools/config_modules/Makefile
@@ -1,6 +1,6 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/polarssl/include $(OPTFLAGS) -fPIC -shared -nostartfiles -L../../build
-LDFLAGS=$(OPTLIBS)
+CFLAGS+=-idirafter ../../src $(OPTFLAGS) -fPIC -shared -nostartfiles -L../../build
+LDFLAGS+=$(OPTLIBS)
 
 MONGO_SRC = mongo-c-driver/src/bson.c \
             mongo-c-driver/src/encoding.c \
--- mongrel2-1.9.1.orig/tests/filters/Makefile
+++ mongrel2-1.9.1/tests/filters/Makefile
@@ -1,6 +1,6 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/polarssl/include $(OPTFLAGS) -fPIC -shared -nostartfiles -L../../build
-LDFLAGS=$(OPTLIBS)
+CFLAGS+=-idirafter ../../src $(OPTFLAGS) -fPIC -shared -nostartfiles -L../../build
+LDFLAGS+=$(OPTLIBS)
 
 all: test_filter.so test_filter_a.so test_filter_b.so test_filter_c.so
 
--- mongrel2-1.9.1.orig/src/bsd_specific.c
+++ mongrel2-1.9.1/src/bsd_specific.c
@@ -45,7 +45,7 @@
 /**
  * BSD version of sendfile, which is OSX and FreeBSD mostly.
  */
-int bsd_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
+int my_bsd_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
     off_t my_count = count;
     int rc;
 
@@ -79,7 +79,7 @@ extern int fdsend(int fd, void *buf, int
 
 /** For the BSDs without sendfile like open and net.**/
 
-int bsd_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
+int my_bsd_sendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
    char buf[BSD_SENDFILE_BUF_SIZE];
    int ret = -1;
    off_t orig_offset = 0;
--- mongrel2-1.9.1.orig/src/io.c
+++ mongrel2-1.9.1/src/io.c
@@ -41,8 +41,8 @@
 #include "register.h"
 #include "mem/halloc.h"
 #include "dbg.h"
-#include "polarssl/havege.h"
-#include "polarssl/ssl.h"
+#include <polarssl/havege.h>
+#include <polarssl/ssl.h>
 #include "task/task.h"
 #include "adt/darray.h"
 
--- mongrel2-1.9.1.orig/src/io.h
+++ mongrel2-1.9.1/src/io.h
@@ -97,7 +97,7 @@ int IOBuf_stream_file(IOBuf *buf, int fd
 #define IOBuf_fd(I) ((I)->fd)
 
 #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
-#define IOBuf_sendfile bsd_sendfile
+#define IOBuf_sendfile my_bsd_sendfile
 #else
 #define IOBuf_sendfile sendfile
 #endif
--- mongrel2-1.9.1.orig/src/task/taskimpl.h
+++ mongrel2-1.9.1/src/task/taskimpl.h
@@ -104,7 +104,7 @@ extern pid_t rfork_thread(int, void*, in
 #    include "sparc-ucontext.h"
 #endif
 
-#if defined(__arm__)
+#if 0 && defined(__arm__)
 int getmcontext(mcontext_t*);
 void setmcontext(const mcontext_t*);
 #define    setcontext(u)    setmcontext((void *)&((u)->uc_mcontext.arm_r0))
--- mongrel2-1.9.1.orig/src/task/asm.S
+++ mongrel2-1.9.1/src/task/asm.S
@@ -34,7 +34,7 @@
 #endif
 #endif
 
-#if defined(__linux__) && defined(__arm__)
+#if 0 && defined(__linux__) && defined(__arm__)
 #define NEEDARMCONTEXT 1
 #define SET setmcontext
 #define GET getmcontext
--- mongrel2-1.9.1.orig/src/task/context.c
+++ mongrel2-1.9.1/src/task/context.c
@@ -30,7 +30,7 @@
 #endif
 #endif
 
-#if defined(__linux__) && defined(__arm__)
+#if 0 && defined(__linux__) && defined(__arm__)
 #define NEEDSWAPCONTEXT
 #define NEEDARMMAKECONTEXT
 #endif
@@ -119,4 +119,3 @@ int swapcontext(ucontext_t *oucp, const
     return 0;
 }
 #endif
-
--- mongrel2-1.9.1.orig/src/adt/radixmap.c
+++ mongrel2-1.9.1/src/adt/radixmap.c
@@ -6,13 +6,20 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <mem/halloc.h>
+#include <endian.h>
 #include "adt/radixmap.h"
 #include "dbg.h"
 
 // undefine this to run the more correct but slower sort
 #define FAST_OPS
 
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 #define ByteOf(x,y) (((uint8_t *)x)[(y)])
+#elif __BYTE_ORDER == __BIG_ENDIAN
+#define ByteOf(x,y) (((uint8_t *)x)[3-(y)])
+#else
+#error unknown byte order
+#endif
 
 static inline void radix_sort(short offset, uint64_t N, uint64_t *source, uint64_t *dest)
 {
