From: Debian GIS Project <pkg-grass-devel@lists.alioth.debian.org>
Date: Tue, 26 Nov 2013 09:08:12 +0000
Subject: tools-build

Forwarded: https://github.com/TUDelftGeodesy/Doris/pull/5
---
 envisat_tools/Makefile              | 38 ++++++++++++++++++-------------------
 envisat_tools/envisat_dump_HH.c     |  2 +-
 envisat_tools/envisat_dump_VV.c     |  2 +-
 envisat_tools/envisat_dump_data.c   |  2 +-
 envisat_tools/envisat_dump_header.c |  2 +-
 sar_tools/Makefile                  | 38 +++++++++++++++++--------------------
 sar_tools/cpxfiddle.cc              |  2 +-
 sar_tools/rasterheader.cc           |  2 +-
 8 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/envisat_tools/Makefile b/envisat_tools/Makefile
index 9126dff..3aca074 100755
--- a/envisat_tools/Makefile
+++ b/envisat_tools/Makefile
@@ -17,7 +17,7 @@
 ### Check if you agree with the options below (install_dir OK?)
 ### then simply type: "make install"
 SHELL = 	/bin/sh
-CC = 		gcc
+#CC = 		gcc
 #CFLAGS =	-O3
 #CFLAGS =        -m32         # for 64-bit systems, it requires compatibility lib32, no need for epr_api v2.2
 LFLAGS =	-lm
@@ -49,32 +49,32 @@ LIB_SRC = 	epr_api-2.2/src/epr_api.c \
 ### targets ###
 default: 	envisat_dump_header envisat_dump_data envisat_dump_HH envisat_dump_VV  
 ### compile envisat_dump_header program (dumps envisat header info to stdout) ###
-envisat_dump_header:	BEST
-		$(CC) $(CFLAGS) $(LFLAGS) \
+envisat_dump_header:
+		$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
 		-o envisat_dump_header \
-		epr_api-2.2/src/*.o \
-		envisat_dump_header.c
+		envisat_dump_header.c \
+		-lepr_api $(LFLAGS)
 
 ### compile envisat_dump_data program (dumps envisat slc short int data to file) ###
-envisat_dump_data:	BEST
-		$(CC) $(CFLAGS) $(LFLAGS) \
+envisat_dump_data:
+		$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
 		-o envisat_dump_data \
-		epr_api-2.2/src/*.o \
-		envisat_dump_data.c
+		envisat_dump_data.c \
+		-lepr_api $(LFLAGS)
 
 ### compile envisat_dump_data program (dumps envisat slc short int data to file) ###
-envisat_dump_HH:  BEST
-		$(CC) $(CFLAGS) $(LFLAGS) \
+envisat_dump_HH:
+		$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
     -o envisat_dump_HH \
-    epr_api-2.2/src/*.o \
-    envisat_dump_HH.c
+    envisat_dump_HH.c \
+		-lepr_api $(LFLAGS)
 
 ### compile envisat_dump_data program (dumps envisat slc short int data to file) ###
-envisat_dump_VV:  BEST
-		$(CC) $(CFLAGS) $(LFLAGS) \
+envisat_dump_VV:
+		$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) \
     -o envisat_dump_VV \
-    epr_api-2.2/src/*.o \
-    envisat_dump_VV.c
+    envisat_dump_VV.c \
+		-lepr_api $(LFLAGS)
 
 
 
@@ -88,6 +88,7 @@ PROGS =		envisat_dump_header envisat_dump_data envisat_dump_HH envisat_dump_VV
 SCRIPTS =	envisat_dump_header2doris.csh
 install:	$(PROGS) $(SCRIPTS)
 		@echo "installing envisat tools..."
+		mkdir -p $(INSTALL_DIR)
 		cp -f $(PROGS) $(SCRIPTS) $(INSTALL_DIR)/.
 		#if test -d /cygdrive/c/cygwin; then \
                 #  echo "* cygwin detected"; \
@@ -96,7 +97,6 @@ install:	$(PROGS) $(SCRIPTS)
 		#  cp -f envisat_dump_header.exe $(INSTALL_DIR)/.; \
 		#  cp -f envisat_dump_data.exe $(INSTALL_DIR)/.; \
 		#fi;
-		make cleaner;
 		@echo " "
 		@echo "------------------------------------"
 		@echo "FINISHED INSTALLING ENVISAT TOOLS..."
@@ -111,7 +111,7 @@ uninstall:	cleaner
 		@echo " "
 clean:		
 		@echo "cleaning envisat tools..."
-		(cd epr_api-2.2/src/; make clean)
+		#(cd epr_api-2.2/src/; make clean)
 		rm -f *.o
 cleaner:	clean
 		rm -f $(PROGS)
diff --git a/envisat_tools/envisat_dump_HH.c b/envisat_tools/envisat_dump_HH.c
index b496abe..10cb548 100755
--- a/envisat_tools/envisat_dump_HH.c
+++ b/envisat_tools/envisat_dump_HH.c
@@ -12,7 +12,7 @@ THIS program is not really good, but a fast hack for Z.Perksi..
 #include <string.h>
 #include <math.h>
 #include <time.h>
-#include "epr_api-2.2/src/epr_api.h"
+#include <epr_api.h>
 #if defined(WIN32) && defined(_DEBUG)
 #include <crtdbg.h>
 #endif /* if defined(WIN32) && defined(_DEBUG) */
diff --git a/envisat_tools/envisat_dump_VV.c b/envisat_tools/envisat_dump_VV.c
index bb47a05..e983077 100755
--- a/envisat_tools/envisat_dump_VV.c
+++ b/envisat_tools/envisat_dump_VV.c
@@ -12,7 +12,7 @@ THIS program is not really good, but a fast hack for Z.Perksi..
 #include <string.h>
 #include <math.h>
 #include <time.h>
-#include "epr_api-2.2/src/epr_api.h"
+#include <epr_api.h>
 #if defined(WIN32) && defined(_DEBUG)
 #include <crtdbg.h>
 #endif /* if defined(WIN32) && defined(_DEBUG) */
diff --git a/envisat_tools/envisat_dump_data.c b/envisat_tools/envisat_dump_data.c
index 8535e77..1572086 100755
--- a/envisat_tools/envisat_dump_data.c
+++ b/envisat_tools/envisat_dump_data.c
@@ -9,7 +9,7 @@
 #include <string.h>
 #include <math.h>
 #include <time.h>
-#include "epr_api-2.2/src/epr_api.h"
+#include <epr_api.h>
 #if defined(WIN32) && defined(_DEBUG)
 #include <crtdbg.h>
 #endif /* if defined(WIN32) && defined(_DEBUG) */
diff --git a/envisat_tools/envisat_dump_header.c b/envisat_tools/envisat_dump_header.c
index 7e9bce5..15c1376 100755
--- a/envisat_tools/envisat_dump_header.c
+++ b/envisat_tools/envisat_dump_header.c
@@ -11,7 +11,7 @@
 #include <string.h>
 #include <math.h>
 #include <time.h>
-#include "epr_api-2.2/src/epr_api.h"
+#include <epr_api.h>
 #if defined(WIN32) && defined(_DEBUG)
 #include <crtdbg.h>
 #endif /* if defined(WIN32) && defined(_DEBUG) */
diff --git a/sar_tools/Makefile b/sar_tools/Makefile
index fb3e1de..1123551 100644
--- a/sar_tools/Makefile
+++ b/sar_tools/Makefile
@@ -26,8 +26,8 @@ SHELL	=	/bin/sh
 INSTALL_DIR =	/home/dlevelt/src/Doris_s1_git/bin
 
 ### GCC compiler
-CC 	=	g++
-CFLAGS  =       -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE  -D_LARGEFILE64_SOURCE #-m32 to force 32bit on 64bit platform
+#CC 	=	g++
+CFLAGS  +=       -O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE  -D_LARGEFILE64_SOURCE #-m32 to force 32bit on 64bit platform
 
 ### Intel compiler
 #CC	=	icpc
@@ -67,29 +67,29 @@ dummy:
 
 # the utilities.
 bkconvert:	bkconvert.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 wrap:		wrap.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 cpxmult:	cpxmult.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 cpxdiv: 	cpxdiv.o 
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 cpxconj:	cpxconj.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 cpxfiddle:	cpxfiddle.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 flapjack:	flapjack.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 floatmask:	floatmask.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 floatmult:	floatmult.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 readrasterheader:	readrasterheader.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 rasterheader:	rasterheader.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 dateconv:	dateconv.o
-		$(CC) $(CFLAGS) $@.o -o $@
+		$(CXX) $(CFLAGS) $(LDFLAGS) $@.o -o $@
 
 
 ### Install in CB_INSTALL by linking/copying executables ###
@@ -103,15 +103,11 @@ install:	$(PROGS)
 
 ### Use symbolic links at our system, copy to /usr/local/bin on other.
 definstall:	$(PROGS)
-		dir=$(INSTALL_DIR); \
-        	if test ! -d $$dir; then \
-		  echo "Sorry, dir $(INSTALL_DIR) does not exist, exiting..."; exit; fi; \
-		echo Installing in directory: $$dir; \
+		mkdir -p $(INSTALL_DIR)
 		list='$(PROGS) $(SCRIPTS)'; for p in $$list; do \
 		  echo "Installing (copy): $$p"; \
 		  cp -f $$p $(INSTALL_DIR)/$$p; \
 		done
-		$(MAKE) cleaner
 
 ### Use symbolic links at our system, copy to /usr/local/bin on other.
 cbinstall:
@@ -157,8 +153,8 @@ uninstall:	cleaner
 		  echo "* Removed executables in install dir: $(INSTALL_DIR)."; fi;
 
 ### How to make object files ###
-.cc.o:		
-	$(CC) $(CFLAGS) -c -o $(@) $<
+.cc.o:
+	$(CXX) $(CPPFLAGS) $(CFLAGS) -c -o $(@) $<
 
 ### EOF.
 
diff --git a/sar_tools/cpxfiddle.cc b/sar_tools/cpxfiddle.cc
index 97c7702..2e5c84e 100644
--- a/sar_tools/cpxfiddle.cc
+++ b/sar_tools/cpxfiddle.cc
@@ -1665,7 +1665,7 @@ static struct option const long_options[] =
         {
         int i=0;
         char subP[8];
-        while (optarg[i] != '/' && optarg[i] != '\0')
+        while (optarg[i] != '/' && optarg[i] != '\0' && i < 7)
           {
           subP[i] = optarg[i];
           ++i;
diff --git a/sar_tools/rasterheader.cc b/sar_tools/rasterheader.cc
index a566de0..d1714fe 100644
--- a/sar_tools/rasterheader.cc
+++ b/sar_tools/rasterheader.cc
@@ -130,7 +130,7 @@ int main (int argc,char *argv[])
   ofp=fopen("sunrasterheader","w");
   fwrite(header, sizeof(int), 8, ofp);
   fclose(ofp);
-  free(header);
+  // free(header);  // header is a stack variable
   return 0;
 }
 
