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.11.0.orig/Makefile
+++ mongrel2-1.11.0/Makefile
@@ -1,18 +1,18 @@
-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 -lmbedtls -lmbedx509 -lmbedcrypto $(OPTLIBS)
 PREFIX?=/usr/local
 
-get_objs = $(addsuffix .o,$(basename $(wildcard $(1))))
+get_objs = $(addsuffix .o,$(basename $(sort $(wildcard $(1)))))
 
-ASM=$(wildcard src/**/*.S src/*.S)
+ASM=$(sort $(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=$(sort $(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_NOEXT=$(filter-out ${OBJECTS_EXTERNAL},${OBJECTS})
 LIB_SRC=$(filter-out src/mongrel2.c,${SOURCES})
 LIB_OBJ=$(filter-out src/mongrel2.o,${OBJECTS})
-TEST_SRC=$(wildcard tests/*_tests.c)
+TEST_SRC=$(sort $(wildcard tests/*_tests.c))
 TESTS=$(patsubst %.c,%,${TEST_SRC})
 MAKEOPTS=OPTFLAGS="${NOEXTCFLAGS} ${OPTFLAGS}" OPTLIBS="${OPTLIBS}" LIBS="${LIBS}" DESTDIR="${DESTDIR}" PREFIX="${PREFIX}"
 
@@ -22,20 +22,20 @@ 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/mbedtls 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 "mbedtls; init and update git submodule" 1>&2;		\
+#	    git submodule init && git submodule update;				\
+#	fi ))
+#endif
 
 all: builddirs 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/mbedtls/config.h
+${OBJECTS}: /usr/include/mbedtls/config.h
 
 # 
 # CFLAGS_DEFS: The $(CC) flags required to obtain C pre-processor #defines, per:
@@ -62,20 +62,20 @@ CFLAGS_DEFS=-dM -E -x c 	# clang, gcc, H
 #     required, and generate a new src/mbedtls_config.patch.X.Y.Z using:
 # 
 #         git diff -- include/mbedtls/config.h > ../mbedtls_config.patch.X.Y.Z
-FORCE:
-src/mbedtls/include/mbedtls/config.h: src/mbedtls/include/mbedtls/version.h FORCE
-	@MBEDTLS_VERSION=$$( $(CC) $(CFLAGS_DEFS) $<				\
-	    | sed -n -e 's/^.*MBEDTLS_VERSION_STRING[\t ]*"\([^"]*\)".*/\1/p' ); \
-	if $(CC) $(CFLAGS_DEFS) $@ | grep -q MBEDTLS_HAVEGE_C; then		\
-	    echo "mbedtls $${MBEDTLS_VERSION}; already configured";		\
-	else									\
-	    echo "mbedtls $${MBEDTLS_VERSION}; defining MBEDTLS_HAVEGE_C...";\
-	    MBEDTLS_PATCH=src/mbedtls_config.patch.$${MBEDTLS_VERSION};	\
-	    if ! patch -d src/mbedtls -p 1 < $${MBEDTLS_PATCH}; then		\
-		echo "*** Failed to apply $${MBEDTLS_PATCH}";			\
-		exit 1;								\
-	    fi;									\
-	fi
+#FORCE:
+#src/mbedtls/include/mbedtls/config.h: src/mbedtls/include/mbedtls/version.h FORCE
+#	@MBEDTLS_VERSION=$$( $(CC) $(CFLAGS_DEFS) $<				\
+#	    | sed -n -e 's/^.*MBEDTLS_VERSION_STRING[\t ]*"\([^"]*\)".*/\1/p' ); \
+#	if $(CC) $(CFLAGS_DEFS) $@ | grep -q MBEDTLS_HAVEGE_C; then		\
+#	    echo "mbedtls $${MBEDTLS_VERSION}; already configured";		\
+#	else									\
+#	    echo "mbedtls $${MBEDTLS_VERSION}; defining MBEDTLS_HAVEGE_C...";\
+#	    MBEDTLS_PATCH=src/mbedtls_config.patch.$${MBEDTLS_VERSION};	\
+#	    if ! patch -d src/mbedtls -p 1 < $${MBEDTLS_PATCH}; then		\
+#		echo "*** Failed to apply $${MBEDTLS_PATCH}";			\
+#		exit 1;								\
+#	    fi;									\
+#	fi
 
 .PHONY: builddirs
 builddirs:
@@ -83,7 +83,7 @@ builddirs:
 	@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}
@@ -96,11 +96,12 @@ 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 
 	rm -rf release-scripts/output
 	find . \( -name "*.gcno" -o -name "*.gcda" \) -exec rm {} \;
-	if test -e .git; then git -C src/mbedtls checkout include/mbedtls/config.h; fi
+#	if test -e .git; then git -C src/mbedtls checkout include/mbedtls/config.h; fi
 	${MAKE} -C tools/m2sh OPTLIB=${OPTLIB} clean
 	${MAKE} -C tools/filters OPTLIB=${OPTLIB} clean
 	${MAKE} -C tests/filters OPTLIB=${OPTLIB} clean
@@ -129,7 +130,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
@@ -179,7 +180,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.11.0.orig/src/adt/radixmap.c
+++ mongrel2-1.11.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.11.0.orig/src/bsd_specific.c
+++ mongrel2-1.11.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.11.0.orig/src/dir.c
+++ mongrel2-1.11.0/src/dir.c
@@ -324,6 +324,7 @@ static inline char *url_decode(const cha
   return res;
 }
 
+#ifdef PATH_MAX
 static inline int normalize_path(bstring target)
 {
     ballocmin(target, PATH_MAX);
@@ -348,6 +349,28 @@ static inline int normalize_path(bstring
 error:
     return -1;
 }
+#else
+static inline int normalize_path(bstring target)
+{
+    char *path_buf = malloc(blength(target));
+    check_mem(path_buf);
+
+    url_decode((const char *)(bdata(target)), path_buf);
+    bassigncstr(target, path_buf);
+    free(path_buf);
+
+    char *normalized = realpath((const char *)(bdata(target)), NULL);
+    check_debug(normalized, "Failed to normalize path: %s", bdata(target));
+
+    bassigncstr(target, normalized);
+    free(normalized);
+
+    return 0;
+
+error:
+    return -1;
+}
+#endif
 
 static inline int Dir_lazy_normalize_base(Dir *dir)
 {
--- mongrel2-1.11.0.orig/src/io.h
+++ mongrel2-1.11.0/src/io.h
@@ -105,7 +105,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.11.0.orig/src/mongrel2.c
+++ mongrel2-1.11.0/src/mongrel2.c
@@ -382,6 +382,7 @@ void reload_task(void *data)
             if(rotate_logs()) {
                 log_err("Error rotating logs!");
             }
+            RELOAD = 0;
         } else {
             log_info("Shutdown requested, goodbye.");
             break;
--- mongrel2-1.11.0.orig/src/task/context.c
+++ mongrel2-1.11.0/src/task/context.c
@@ -94,4 +94,3 @@ int swapcontext(ucontext_t *oucp, const
     return 0;
 }
 #endif
-
--- mongrel2-1.11.0.orig/src/unixy.c
+++ mongrel2-1.11.0/src/unixy.c
@@ -215,20 +215,3 @@ error:
     return -1;
 }
 
-
-bstring Unixy_getcwd()
-{
-    char *wd = calloc(PATH_MAX + 1, 1);
-    bstring dir = NULL;
-
-    check(getcwd(wd, PATH_MAX-1), "Could not get current working directory.");
-    wd[PATH_MAX] = '\0';
-
-    dir = bfromcstr(wd);
-
-error:
-    // fall through
-    free(wd);
-    return dir;
-}
-
--- mongrel2-1.11.0.orig/src/unixy.h
+++ mongrel2-1.11.0/src/unixy.h
@@ -46,8 +46,6 @@ int Unixy_in_chroot();
 
 int Unixy_drop_priv(bstring path);
 
-bstring Unixy_getcwd();
-
 int Unixy_pid_file(bstring path);
 
 int Unixy_daemonize(int dochdir);
--- mongrel2-1.11.0.orig/tests/filters/Makefile
+++ mongrel2-1.11.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.11.0.orig/tests/unixy_tests.c
+++ mongrel2-1.11.0/tests/unixy_tests.c
@@ -3,20 +3,9 @@
 #include <unistd.h>
 #include <sys/types.h>
 
-char *test_Unixy_getcwd()
-{
-    bstring dir = Unixy_getcwd();
-    mu_assert(dir != NULL, "getcwd failed.");
-    debug("CWD is: %s", bdata(dir));
-
-    bdestroy(dir);
-    return NULL;
-}
-
 char *test_Unixy_chroot_fails()
 {
-    bstring dir = Unixy_getcwd();
-    mu_assert(dir != NULL, "can't getcwd in chroot test.");
+    bstring dir = bfromcstr(".");
 
     int rc = Unixy_chroot(dir);
     mu_assert(rc == -1, "We shouldn't be able to chroot unless running as root.");
@@ -28,8 +17,7 @@ char *test_Unixy_chroot_fails()
 
 char *test_Unixy_drop_priv_fails()
 {
-    bstring dir = Unixy_getcwd();
-    mu_assert(dir != NULL, "can't getcwd in chroot test.");
+    bstring dir = bfromcstr(".");
 
     Unixy_drop_priv(dir);
     // the results of this are so variable we can't check it
@@ -61,9 +49,10 @@ char *test_Unixy_pid_file()
 char * all_tests() {
     mu_suite_start();
 
-    mu_run_test(test_Unixy_getcwd);
     if(getuid() != 0) {
+#ifndef __gnu_hurd__
         mu_run_test(test_Unixy_chroot_fails);
+#endif
         mu_run_test(test_Unixy_drop_priv_fails);
     }
     mu_run_test(test_Unixy_pid_file);
--- mongrel2-1.11.0.orig/tools/config_modules/Makefile
+++ mongrel2-1.11.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.11.0.orig/tools/filters/Makefile
+++ mongrel2-1.11.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.11.0.orig/tools/m2sh/Makefile
+++ mongrel2-1.11.0/tools/m2sh/Makefile
@@ -1,10 +1,10 @@
-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
-SOURCES=$(wildcard src/*.c src/**/*.c)
+SOURCES=$(sort $(wildcard src/*.c src/**/*.c))
 OBJECTS=$(patsubst %.c,%.o,${SOURCES})
-TEST_SRC=$(wildcard tests/*.c)
+TEST_SRC=$(sort $(wildcard tests/*.c))
 TESTS=$(patsubst %.c,%,${TEST_SRC})
 LIB_SRC=$(filter-out src/m2sh.c,${SOURCES})
 LIB_OBJ=$(filter-out src/m2sh.o,${OBJECTS})
@@ -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.11.0.orig/tools/procer/Makefile
+++ mongrel2-1.11.0/tools/procer/Makefile
@@ -1,14 +1,14 @@
-CFLAGS=-DNDEBUG -pthread -g -I../../src -Wall $(OPTFLAGS)
+CFLAGS+=-DNDEBUG -pthread -g -I../../src -Wall $(OPTFLAGS)
 PREFIX?=/usr/local
 LIBS?=-lzmq 
-SOURCES=$(wildcard *.c)
+SOURCES=$(sort $(wildcard *.c))
 OBJECTS=$(patsubst %.c,%.o,${SOURCES})
 
 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
