From: Brad King <brad.king@kitware.com>
Date: Mon, 18 Jun 2012 14:18:32 -0400
Subject: [PATCH 3/3] Support source-to-object compilation in a DESTDIR

If environment variable 'gtm_destdir' is set, treat it as a prefix to be
removed from any source file paths contained inside it.  This will allow
sources to be compiled in a DESTDIR for packaging such that the object
files will find their sources in the final install prefix after
distribution.
---
 sr_unix/obj_source.c |   13 +++++++++++++
 1 file changed, 13 insertions(+)

--- fis-gtm-V6.0-003.orig/sr_unix/obj_source.c
+++ fis-gtm-V6.0-003/sr_unix/obj_source.c
@@ -1,3 +1,5 @@
+#include "gtm_stdlib.h"
+#include "gtm_string.h"
 #include "mdef.h"
 
 #include "obj_source.h"
@@ -8,5 +10,16 @@
 struct obj_source get_obj_source(void)
 {
 	struct obj_source sn = {source_file_name, source_name_len};
+	char* gtm_destdir = getenv("gtm_destdir");
+	if(gtm_destdir)
+	{
+		/* Strip the destdir prefix from sources inside it.  */
+		size_t const ddlen = strlen(gtm_destdir);
+		if(strncmp(sn.name, gtm_destdir, ddlen) == 0)
+		{
+			sn.name += ddlen;
+			sn.len -= ddlen;
+		}
+	}
 	return sn;
 }
