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.2.orig/Makefile
+++ mongrel2-1.9.2/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})
@@ -22,16 +22,16 @@ MAKEOPTS=OPTFLAGS="${NOEXTCFLAGS} ${OPTF
 #   upon every make invocation, and must be done before the SOURCES variable, above
 #   is lazily evaluated, or none of the src/polarssl source files will be found
 
-ifdef $($(shell									\
-	if git submodule status | grep '^-'; then				\
-	    echo "PolarSSL; init and update git submodule" 1>&2;		\
-	    git submodule init && git submodule update;				\
-	fi ))
-endif
+#ifdef $($(shell									\
+#	if git submodule status | grep '^-'; then				\
+#	    echo "PolarSSL; init and update git submodule" 1>&2;		\
+#	    git submodule init && git submodule update;				\
+#	fi ))
+#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}
@@ -61,31 +61,31 @@ CFLAGS_DEFS=-dM -E -x c 	# clang, gcc, H
 #     required, and generate a new src/polarssl_config.patch.X.Y.Z using:
 # 
 #         git diff -- include/polarssl/config.h > ../polarssl_config.patch.X.Y.Z
-FORCE:
-src/polarssl/include/polarssl/config.h: src/polarssl/include/polarssl/version.h FORCE
-	@POLARSSL_VERSION=$$( $(CC) $(CFLAGS_DEFS) $<				\
-	    | sed -n -e 's/^.*POLARSSL_VERSION_STRING[\t ]*"\([^"]*\)".*/\1/p' ); \
-	if $(CC) $(CFLAGS_DEFS) $@ | grep -q POLARSSL_HAVEGE_C; then		\
-	    echo "PolarSSL $${POLARSSL_VERSION}; already configured";		\
-	else									\
-	    echo "PolarSSL $${POLARSSL_VERSION}; defining POLARSSL_HAVEGE_C...";\
-	    POLARSSL_PATCH=src/polarssl_config.patch.$${POLARSSL_VERSION};	\
-	    if ! patch -d src/polarssl -p 1 < $${POLARSSL_PATCH}; then		\
-		echo "*** Failed to apply $${POLARSSL_PATCH}";			\
-		exit 1;								\
-	    fi;									\
-	fi
+#FORCE:
+#src/polarssl/include/polarssl/config.h: src/polarssl/include/polarssl/version.h FORCE
+#	@POLARSSL_VERSION=$$( $(CC) $(CFLAGS_DEFS) $<				\
+#	    | sed -n -e 's/^.*POLARSSL_VERSION_STRING[\t ]*"\([^"]*\)".*/\1/p' ); \
+#	if $(CC) $(CFLAGS_DEFS) $@ | grep -q POLARSSL_HAVEGE_C; then		\
+#	    echo "PolarSSL $${POLARSSL_VERSION}; already configured";		\
+#	else									\
+#	    echo "PolarSSL $${POLARSSL_VERSION}; defining POLARSSL_HAVEGE_C...";\
+#	    POLARSSL_PATCH=src/polarssl_config.patch.$${POLARSSL_VERSION};	\
+#	    if ! patch -d src/polarssl -p 1 < $${POLARSSL_PATCH}; then		\
+#		echo "*** Failed to apply $${POLARSSL_PATCH}";			\
+#		exit 1;								\
+#	    fi;									\
+#	fi
 
 
 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
 
@@ -95,10 +95,11 @@ 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 "*.gcno" -o -name "*.gcda" \) -exec rm {} \;
-	git -C src/polarssl checkout include/polarssl/config.h
+#	git -C src/polarssl checkout include/polarssl/config.h
 	${MAKE} -C tools/m2sh OPTLIB=${OPTLIB} clean
 	${MAKE} -C tools/filters OPTLIB=${OPTLIB} clean
 	${MAKE} -C tests/filters OPTLIB=${OPTLIB} clean
--- mongrel2-1.9.2.orig/tools/procer/Makefile
+++ mongrel2-1.9.2/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}
-	$(CC) $(OPTFLAGS) $(OPTLIBS) -o $@ ${OBJECTS} ../../build/libm2.a ${LIBS}
+	$(CC) $(LDFLAGS) $(OPTFLAGS) $(OPTLIBS) -o $@ ${OBJECTS} ../../build/libm2.a ${LIBS}
 
 clean:
 	rm -f *.o procer
--- mongrel2-1.9.2.orig/tools/filters/Makefile
+++ mongrel2-1.9.2/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.2.orig/tools/m2sh/Makefile
+++ mongrel2-1.9.2/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.2.orig/tools/config_modules/Makefile
+++ mongrel2-1.9.2/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.2.orig/tests/filters/Makefile
+++ mongrel2-1.9.2/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.2.orig/src/bsd_specific.c
+++ mongrel2-1.9.2/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.2.orig/src/io.c
+++ mongrel2-1.9.2/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.2.orig/src/io.h
+++ mongrel2-1.9.2/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.2.orig/src/task/context.c
+++ mongrel2-1.9.2/src/task/context.c
@@ -94,4 +94,3 @@ int swapcontext(ucontext_t *oucp, const
     return 0;
 }
 #endif
-
--- mongrel2-1.9.2.orig/src/adt/radixmap.c
+++ mongrel2-1.9.2/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)
 {
