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.10.0.orig/Makefile
+++ mongrel2-1.10.0/Makefile
@@ -1,14 +1,14 @@
-CFLAGS=-g -O2 -Wall -Wextra -Isrc -Isrc/mbedtls/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/mbedtls/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/mbedtls/library/*.c)
+OBJECTS_EXTERNAL+=$(call get_objs,src/polarssl/library/*.c)
 OBJECTS_NOEXT=$(filter-out ${OBJECTS_EXTERNAL},${OBJECTS})
 LIB_SRC=$(filter-out src/mongrel2.c,${SOURCES})
 LIB_OBJ=$(filter-out src/mongrel2.o,${OBJECTS})
@@ -16,26 +16,25 @@ TEST_SRC=$(wildcard tests/*_tests.c)
 TESTS=$(patsubst %.c,%,${TEST_SRC})
 MAKEOPTS=OPTFLAGS="${NOEXTCFLAGS} ${OPTFLAGS}" OPTLIBS="${OPTLIBS}" LIBS="${LIBS}" DESTDIR="${DESTDIR}" PREFIX="${PREFIX}"
 
-# Prepare mbedtls git submodule
+# Prepare PolarSSL git submodule
 # 
-# - Perform src/mbedtls submodule init and update, if necessary.  This is executed
+# - Perform src/polarssl submodule init and update, if necessary.  This is executed
 #   upon every make invocation, and must be done before the SOURCES variable, above
-#   is lazily evaluated, or none of the src/mbedtls source files will be found
+#   is lazily evaluated, or none of the src/polarssl source files will be found
 
-ifdef $($(shell									\
-	if git submodule status | grep '^-'; then				\
-	    echo "mbedtls; 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: builddirs bin/mongrel2 tests m2sh procer
+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}
-${OBJECTS}: src/mbedtls/include/polarssl/config.h
 
 # 
 # CFLAGS_DEFS: The $(CC) flags required to obtain C pre-processor #defines, per:
@@ -53,53 +52,54 @@ ${OBJECTS}: src/mbedtls/include/polarssl
 #CFLAGS_DEFS=-qshowmacros -E	# IBM XL C
 CFLAGS_DEFS=-dM -E -x c 	# clang, gcc, HP C, Intel icc
 
-# Configure mbedtls
+# Configure PolarSSL
 # 
-# - check for required src/mbedtls/include/polarssl/config.h definitions
+# - check for required src/polarssl/include/polarssl/config.h definitions
 #   and patch using version-appropriate src/polarssl_config.patch.#.#.# file:
-#   - If desired mbedtls version is not yet supported, git checkout the
-#     new src/mbedtls/ version X.Y.Z, edit its include/polarssl/config.h as
+#   - If desired PolarSSL version is not yet supported, git checkout the
+#     new src/polarssl/ version X.Y.Z, edit its include/polarssl/config.h as
 #     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/mbedtls/include/polarssl/config.h: src/mbedtls/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 "mbedtls $${POLARSSL_VERSION}; already configured";		\
-	else									\
-	    echo "mbedtls $${POLARSSL_VERSION}; defining POLARSSL_HAVEGE_C...";\
-	    POLARSSL_PATCH=src/polarssl_config.patch.$${POLARSSL_VERSION};	\
-	    if ! patch -d src/mbedtls -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
 
-.PHONY: builddirs
-builddirs:
-	@mkdir -p build
-	@mkdir -p bin
 
 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: ${LIB_OBJ}
+build/libm2.a: build ${LIB_OBJ}
 	ar rcs $@ ${LIB_OBJ}
 	ranlib $@
 
+build:
+	@mkdir -p build
+	@mkdir -p bin
+
 clean:
 	rm -rf build bin lib ${OBJECTS} ${TESTS} tests/config.sqlite
 	rm -f tests/perf.log 
 	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 {} \;
-	if test -e .git; then git -C src/mbedtls checkout include/polarssl/config.h; fi
+#	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
@@ -116,7 +116,7 @@ pristine: clean
 	rm -f run/*
 	${MAKE} -C tools/m2sh pristine
 	${MAKE} -C tools/procer pristine
-	git submodule deinit -f src/mbedtls
+	git submodule deinit -f src/polarssl
 
 .PHONY: tests
 tests: tests/config.sqlite ${TESTS} test_filters filters config_modules
@@ -128,7 +128,7 @@ tests/config.sqlite: src/config/config.s
 	sqlite3 $@ < src/config/mimetypes.sql
 
 $(TESTS): %: %.c build/libm2.a
-	$(CC) $(CFLAGS) -o $@ $< build/libm2.a $(LIBS)
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< build/libm2.a $(LIBS)
 
 src/state.c: src/state.rl src/state_machine.rl
 src/http11/http11_parser.c: src/http11/http11_parser.rl
@@ -178,7 +178,7 @@ strace:
 	VALGRIND="strace" ${MAKE}
 
 %.o: %.S
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
 
 coverage: NOEXTCFLAGS += -fprofile-arcs -ftest-coverage
 coverage: LIBS += -lgcov
--- mongrel2-1.10.0.orig/src/adt/radixmap.c
+++ mongrel2-1.10.0/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)
 {
--- mongrel2-1.10.0.orig/src/bsd_specific.c
+++ mongrel2-1.10.0/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.10.0.orig/src/io.c
+++ mongrel2-1.10.0/src/io.c
@@ -43,7 +43,7 @@
 #include "register.h"
 #include "mem/halloc.h"
 #include "dbg.h"
-#include "polarssl/ssl.h"
+#include <polarssl/ssl.h>
 #include "task/task.h"
 #include "adt/darray.h"
 
--- mongrel2-1.10.0.orig/src/io.h
+++ mongrel2-1.10.0/src/io.h
@@ -101,7 +101,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.10.0.orig/src/task/context.c
+++ mongrel2-1.10.0/src/task/context.c
@@ -94,4 +94,3 @@ int swapcontext(ucontext_t *oucp, const
     return 0;
 }
 #endif
-
--- mongrel2-1.10.0.orig/tests/filters/Makefile
+++ mongrel2-1.10.0/tests/filters/Makefile
@@ -1,12 +1,12 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/mbedtls/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
 
 
 %.so : %.c ../../build/libm2.a
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
 
 clean:
 	rm -f *.so
--- mongrel2-1.10.0.orig/tools/config_modules/Makefile
+++ mongrel2-1.10.0/tools/config_modules/Makefile
@@ -1,6 +1,6 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/mbedtls/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 \
@@ -22,11 +22,11 @@ fetch_mongo_c_driver:
 mongodb.so: CFLAGS += $(MONGO_CFLAGS)
 mongodb.so: fetch_mongo_c_driver
 mongodb.so: mongodb.c
-	$(CC) $(CFLAGS) -c $(MONGO_SRC)
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(MONGO_SRC)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< bson.o encoding.o gridfs.o md5.o mongo.o env_posix.o numbers.o ../../build/libm2.a
 
 %.so : %.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
 
 clean:
 	rm -f *.o *.so
--- mongrel2-1.10.0.orig/tools/filters/Makefile
+++ mongrel2-1.10.0/tools/filters/Makefile
@@ -1,12 +1,12 @@
 PREFIX?=/usr/local
-CFLAGS=-I../../src -I../../src/mbedtls/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
 
 
 %.so : %.c
-	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< ../../build/libm2.a
 
 clean:
 	rm -f *.so
--- mongrel2-1.10.0.orig/tools/m2sh/Makefile
+++ mongrel2-1.10.0/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) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o build/m2sh ${OBJECTS} ../../build/libm2.a $(LIBS)
 
 ../lemon/lemon: ../lemon/lemon.c
-	$(CC) -O2 ../lemon/lemon.c -o ../lemon/lemon
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) ../lemon/lemon.c -o ../lemon/lemon
 
 tests: build/libm2sh.a ${TESTS}
 	sh ./tests/runtests.sh
@@ -39,7 +39,7 @@ tests: build/libm2sh.a ${TESTS}
 	ragel -G2 $<
 
 $(TESTS): %: %.c build/libm2sh.a
-	$(CC) $(CFLAGS) -o $@ $< build/libm2sh.a ../../build/libm2.a $(LIBS)
+	$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $< build/libm2sh.a ../../build/libm2.a $(LIBS)
 
 ../../build/libm2.a:
 	cd ../.. && make clean all
--- mongrel2-1.10.0.orig/tools/procer/Makefile
+++ mongrel2-1.10.0/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
