From ec840223cac5ab2039610e1dea831ade99fd848c Mon Sep 17 00:00:00 2001
From: Brad Barber <bradb@shore.net>
Date: Sat, 9 Jan 2010 18:00:17 -0500
Subject: [PATCH] Fix tabs in Makefile.txt [mschamschula] Order object files by
 frequency of execution for better locality.

---
 project/libqhull/libqhull.pro                 |  19 +-
 project/libqhullp/libqhullp.pro               |  19 +-
 .../qhull-2003.1/poly.c-gh_gethash.patch      |  23 ++
 src/CMakeLists.txt                            |  19 +-
 src/Changes.txt                               |  16 +-
 src/Makefile.txt                              | 205 +++++++++---------
 6 files changed, 167 insertions(+), 134 deletions(-)
 create mode 100644 project/patch/qhull-2003.1/poly.c-gh_gethash.patch

diff --git a/project/libqhull/libqhull.pro b/project/libqhull/libqhull.pro
index 4a22700..ffe6959 100644
--- a/project/libqhull/libqhull.pro
+++ b/project/libqhull/libqhull.pro
@@ -75,22 +75,23 @@ OTHER_FILES += src/qh-stat.htm
 OTHER_FILES += src/qh-user.htm
 
 # libqhull.pro and libqhullp.pro are the same
-SOURCES += src/geom.c
-SOURCES += src/geom2.c
+# Order object files by frequency of execution.  Small files at end.
+SOURCES += src/rboxlib.c
+SOURCES += src/user.c
 SOURCES += src/global.c
+SOURCES += src/stat.c
 SOURCES += src/io.c
-SOURCES += src/libqhull.c
-SOURCES += src/mem.c
+SOURCES += src/geom2.c
+SOURCES += src/poly2.c
 SOURCES += src/merge.c
+SOURCES += src/libqhull.c
+SOURCES += src/geom.c
 SOURCES += src/poly.c
-SOURCES += src/poly2.c
 SOURCES += src/qset.c
-SOURCES += src/random.c
-SOURCES += src/rboxlib.c
-SOURCES += src/stat.c
-SOURCES += src/user.c
+SOURCES += src/mem.c
 SOURCES += src/usermem.c
 SOURCES += src/userprintf.c
+SOURCES += src/random.c
 HEADERS += src/geom.h
 HEADERS += src/io.h
 HEADERS += src/libqhull.h
diff --git a/project/libqhullp/libqhullp.pro b/project/libqhullp/libqhullp.pro
index 439a1ae..a333500 100644
--- a/project/libqhullp/libqhullp.pro
+++ b/project/libqhullp/libqhullp.pro
@@ -24,22 +24,23 @@ MOC_DIR = ../../tmp/moc
 RCC_DIR = ../../tmp/rcc
 
 # libqhull.pro and libqhullp.pro are the same
-SOURCES += src/geom.c
-SOURCES += src/geom2.c
+# Order object files by frequency of execution.  Small files at end.
+SOURCES += src/rboxlib.c
+SOURCES += src/user.c
 SOURCES += src/global.c
+SOURCES += src/stat.c
 SOURCES += src/io.c
-SOURCES += src/libqhull.c
-SOURCES += src/mem.c
+SOURCES += src/geom2.c
+SOURCES += src/poly2.c
 SOURCES += src/merge.c
+SOURCES += src/libqhull.c
+SOURCES += src/geom.c
 SOURCES += src/poly.c
-SOURCES += src/poly2.c
 SOURCES += src/qset.c
-SOURCES += src/random.c
-SOURCES += src/rboxlib.c
-SOURCES += src/stat.c
-SOURCES += src/user.c
+SOURCES += src/mem.c
 SOURCES += src/usermem.c
 SOURCES += src/userprintf.c
+SOURCES += src/random.c
 HEADERS += src/geom.h
 HEADERS += src/io.h
 HEADERS += src/libqhull.h
diff --git a/project/patch/qhull-2003.1/poly.c-gh_gethash.patch b/project/patch/qhull-2003.1/poly.c-gh_gethash.patch
new file mode 100644
index 0000000..5f686f5
--- /dev/null
+++ b/project/patch/qhull-2003.1/poly.c-gh_gethash.patch
@@ -0,0 +1,23 @@
+--- a/qhull-2003.1/src/poly.c
++++ b/qhull-2003.1/src/poly.c
+@@ -403,6 +403,7 @@ unsigned qh_gethash (int hashsize, setT *set, int size, int firstindex, void *sk
+   void **elemp= SETelemaddr_(set, firstindex, void);
+   ptr_intT hash = 0, elem;
+   int i;
++  unsigned result;
+ 
+   switch (size-firstindex) {
+   case 1:
+@@ -441,7 +442,8 @@ unsigned qh_gethash (int hashsize, setT *set, int size, int firstindex, void *sk
+     }while(*elemp);
+     break;
+   }
+-  hash %= (ptr_intT) hashsize;
+-  /* hash= 0; for debugging purposes */
+-  return hash;
++  result= (unsigned)hash;
++  result %= (unsigned)hashsize;
++  /* result= 0; for debugging purposes */
++  return result;
+ } /* gethash */
+ 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index bcae8d4..62216e8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,23 +1,24 @@
 project(qhull_lib)
 
+# Order object files by frequency of execution.  Small files at end.
 set(
     qhull_src
-        geom.c
-        geom2.c
+        rboxlib.c
+        user.c
         global.c
+        stat.c
         io.c
-        libqhull.c
-        mem.c
+        geom2.c
+        poly2.c
         merge.c
+        libqhull.c
+        geom.c
         poly.c
-        poly2.c
         qset.c
-        random.c
-        rboxlib.c
-        stat.c
-        user.c
+        mem.c
         usermem.c
         userprintf.c
+        random.c
 )
 
 file(GLOB qhull_hdr *.h)
diff --git a/src/Changes.txt b/src/Changes.txt
index b714103..bbc75a4 100644
--- a/src/Changes.txt
+++ b/src/Changes.txt
@@ -95,15 +95,17 @@ To do
  - review all FIXUP [^0-9]
  - Number the FIXUPS
  - clean up warnings for libqhullcpp
+ - get copy of unused and news
  
 Need help
- - ConvexHull is a submodule to git.  How to get rid of?
- - Set up configure and debian build.  If possible, please keep qhull-2010.1/ clean
-   http://savannah.nongnu.org/cvs/?group=qhull
-   Please use qhull-2010.1/project/ for build-related files 
- - Set up CMake for cpp
+ - Remove ConvexHull from git.  It appears to be a submodule.
+ - Set up debian build.  
+   Branch 'debian' is from http://savannah.nongnu.org/cvs/?group=qhull
+   Please keep files in config/ or project/debian/
+   project/debian needs updating for its new location (two levels down)
+ - Add CMakeLists.txt for qhullcpp, user_eg3, cpp/, and cpp/road
  - The C++ interface needs work.  Give it a try and make it better.
- - Verify -fno-strict-aliasing is needed for gcc 4.1, 4.2, and 4.3 (q_test segfaults)
+ - Verify -fno-strict-aliasing needed for gcc 4.1, 4.2, and 4.3 (qset segfault)
 
 qhull 2010.1 2010/01/09
  - Patched qh_gethash.  See project/patch/qhull-2003.1 with patched poly.c and patch.
@@ -115,6 +117,8 @@ qhull 2010.1 2010/01/09
    Cost of qh_QHpointer: [2003, msvc] 8% time 2% space, [2010, gcc] 4% time 4% space
  - user.h requires <time.h> for CLOCKS_PER_SEC
  - Add CMakeLists.txt [kwilliams]
+ - Order object files by frequency of execution for better locality.
+ - Fix tabs in Makefile.txt [mschamschula]
  
 qhull 2010.1 2010/01/07
  - Assign type to qh.old_qhstat and memT.tempstack [amorilia]
diff --git a/src/Makefile.txt b/src/Makefile.txt
index 6f8fe29..62a3a89 100644
--- a/src/Makefile.txt
+++ b/src/Makefile.txt
@@ -2,7 +2,7 @@
 #
 #       see README.txt
 #       the Unix distribution contains a configure Makefile
-#
+#       
 #       make           to produce qhull qconvex qdelaunay qhalf qvoronoi rbox
 #       make qvoronoi  to produce qvoronoi (etc.)
 #       make qhullx    to produce qhull qconvex etc.  w/o using libqhull.a
@@ -16,24 +16,26 @@
 #       make clean     to remove object files and core
 #       make cleanall  to remove all generated files
 #
-#       PRINTMAN --  command for printing manual pages
-#       PRINTC --  command for printing C files
-#       BINDIR -- directory where to copy executables
-#       MANDIR -- directory where to copy manual pages
-#       CC --     ANSI C or C++ compiler
-#       CCOPTS1 - options used to compile .c files
-#       CCOPTS2 -- options used to link .o files
+#       PRINTMAN --    command for printing manual pages
+#       PRINTC --      command for printing C files
+#       BINDIR --      directory where to copy executables
+#       MANDIR --      directory where to copy manual pages
+#       CC --          ANSI C or C++ compiler
+#       CCOPTS1 -      options used to compile .c files
+#       CCOPTS2 --     options used to link .o files
 #
-#       CFILES -- .c files for printing
-#       HFILES -- .h files for printing
-#       DFILES -- documentation files
-#       MFILES -- man pages and html files
-#       TFILES -- .txt versions of html html files
-#       FILES -- all other files
-#       OBJS -- specifies the object files of libqhull.a
+#       CFILES --      .c files for printing
+#       HFILES --      .h files for printing
+#       DFILES --       documentation files
+#       MFILES --      man pages and html files
+#       TFILES --      .txt versions of html html files
+#       FILES --       all other files
+#       OBJS --        specifies the object files of libqhull.a
 #
-BINDIR  = /usr/local/bin
-MANDIR  = /usr/local/man/man1
+# Do not replace tabs with spaces.  Needed by 'make' for build rules
+
+BINDIR	= /usr/local/bin
+MANDIR	= /usr/local/man/man1
 
 # if you do not have enscript, try a2ps or just use lpr.  The files are text.
 PRINTMAN = enscript -2rl
@@ -42,9 +44,9 @@ PRINTC = enscript -2r
 # PRINTC = lpr
 
 #for Gnu's gcc compiler -O2 for optimization, -g for debugging, -Wall for check
-#
-CC     = gcc
-CCOPTS1 = -O2 -ansi 
+#   -fno-strict-aliasing not needed for gcc 4.4+ (segfault in qset.c)
+CC  = gcc
+CCOPTS1 = -O2 -ansi -fno-strict-aliasing 
 
 # for Sun's cc compiler, -fast or O2 for optimization, -g for debugging, -Xc for ANSI
 #CC = cc
@@ -61,133 +63,134 @@ CCOPTS1 = -O2 -ansi
 # for loader, ld
 CCOPTS2 = $(CCOPTS1)
 
-# OBJS in execution frequency order.  CFILES after libqhull.c are alphabetical
-OBJS = user.o global.o random.o stat.o io.o geom2.o poly2.o \
-       merge.o geom.o poly.o qset.o mem.o libqhull.o usermem.o userprintf.o \
-       rboxlib.o
+# OBJS ordered by frequency of execution with small files at end.  Better locality.
+OBJS = rboxlib.o user.o global.o stat.o io.o geom2.o poly2.o merge.o \
+       libqhull.o geom.o poly.o qset.o mem.o usermem.o userprintf.o random.o
 
+# CFILES ordered alphabetically after libqhull.c 
 CFILES= unix.c libqhull.c geom.c geom2.c global.c io.c mem.c merge.c poly.c \
-        poly2.c random.c qset.c stat.c user.c qconvex.c qdelaun.c qhalf.c qvoronoi.c usermem.c userprintf.c rboxlib.c
+		poly2.c random.c qset.c stat.c user.c qconvex.c qdelaun.c qhalf.c qvoronoi.c usermem.c userprintf.c rboxlib.c
 HFILES= user.h libqhull.h qhull_a.h geom.h io.h mem.h merge.h poly.h random.h qset.h stat.h
 TXTFILES= ../Announce.txt ../REGISTER.txt ../COPYING.txt ../README.txt Changes.txt
 DOCFILES= ../html/rbox.txt ../html/qhull.txt
-FILES=  Makefile rbox.c user_eg.c ../eg/q_test ../eg/q_egtest ../eg/q_eg
+FILES=	Makefile rbox.c user_eg.c ../eg/q_test ../eg/q_egtest ../eg/q_eg
 HTMFILES= qhull.man rbox.man qh-code.htm qh-optg.htm qh-optt.htm qh-optp.htm \
-        index.htm qh-quick.htm qh-impre.htm qh-eg.htm \
-        qh-optc.htm qh-opto.htm qh-optf.htm qh-optq.htm \
-            qh-c.htm qh-faq.htm qhull.htm qconvex.htm qdelaun.htm \
-                qh-geom.htm qh-globa.htm qh-io.htm qh-mem.htm qh-merge.htm \
-                qh-poly.htm qh-qhull.htm qh-set.htm qh-stat.htm qh-user.htm \
-                qdelau_f.htm qhalf.htm qvoronoi.htm qvoron_f.htm rbox.htm 
+		index.htm qh-quick.htm qh-impre.htm qh-eg.htm \
+		qh-optc.htm qh-opto.htm qh-optf.htm qh-optq.htm \
+		qh-c.htm qh-faq.htm qhull.htm qconvex.htm qdelaun.htm \
+		qh-geom.htm qh-globa.htm qh-io.htm qh-mem.htm qh-merge.htm \
+		qh-poly.htm qh-qhull.htm qh-set.htm qh-stat.htm qh-user.htm \
+		qdelau_f.htm qhalf.htm qvoronoi.htm qvoron_f.htm rbox.htm 
 
 all: rbox qconvex qdelaunay qhalf qvoronoi qhull
 
-unix.o:   libqhull.h user.h mem.h
-qconvex.o:   libqhull.h user.h mem.h
-qdelaun.o:   libqhull.h user.h mem.h
-qhalf.o:   libqhull.h user.h mem.h
-qvoronoi.o:   libqhull.h user.h mem.h
-libqhull.o:  $(HFILES)
-geom.o:   $(HFILES)
-geom2.o:  $(HFILES)
-global.o: $(HFILES)
-io.o:     $(HFILES)
-mem.o:    mem.h 
-merge.o:  $(HFILES)
-poly.o:   $(HFILES)
-poly2.o:  $(HFILES)
-random.o: libqhull.h random.h
-qset.o:   qset.h mem.h 
-stat.o:   $(HFILES)
-user.o:   $(HFILES)
+unix.o:	    libqhull.h user.h mem.h
+qconvex.o:  libqhull.h user.h mem.h
+qdelaun.o:  libqhull.h user.h mem.h
+qhalf.o:    libqhull.h user.h mem.h
+qvoronoi.o: libqhull.h user.h mem.h
+libqhull.o: $(HFILES)
+geom.o:	    $(HFILES)
+geom2.o:    $(HFILES)
+global.o:   $(HFILES)
+io.o:	    $(HFILES)
+mem.o:	    mem.h 
+merge.o:    $(HFILES)
+poly.o:	    $(HFILES)
+poly2.o:    $(HFILES)
+random.o:   libqhull.h random.h
+qset.o:	    qset.h mem.h 
+stat.o:	    $(HFILES)
+user.o:	    $(HFILES)
 
 .c.o:
-        $(CC) -c $(CCOPTS1) $<
+	$(CC) -c $(CCOPTS1) $<
 
 clean:
-        rm -f *.o ../core qconvex qdelaunay qhalf qvoronoi qhull libqhull.a \
-            *.exe
+	rm -f *.o ../core qconvex qdelaunay qhalf qvoronoi qhull libqhull.a \
+              *.exe
 
 cleanall: clean
-        rm -f *~ ../rbox ../qhull ../qhalf ../qconvex ../qdelaunay ../qhalf\
-           ../qvoronoi ../user_eg ../user_eg2 ../*.exe >/dev/null
+	rm -f *~ ../rbox ../qhull ../qhalf ../qconvex ../qdelaunay ../qhalf\
+		../qvoronoi ../user_eg ../user_eg2 ../*.exe >/dev/null
 
 doc: 
-        $(PRINTMAN) $(TXTFILES) $(DOCFILES)
+	$(PRINTMAN) $(TXTFILES) $(DOCFILES)
 
-install: all 
-        cp ../qconvex $(BINDIR)/qconvex
-        cp ../qdelaunay $(BINDIR)/qdelaunay
-        cp ../qhalf $(BINDIR)/qhalf
-        cp ../qhull $(BINDIR)/qhull
-        cp ../qvoronoi $(BINDIR)/qvoronoi
-        cp ../rbox $(BINDIR)/rbox
-        cp ../html/qhull.man $(MANDIR)/qhull.1
-        cp ../html/rbox.man $(MANDIR)/rbox.1
+install:  
+	cp ../qconvex $(BINDIR)/qconvex
+	cp ../qdelaunay $(BINDIR)/qdelaunay
+	cp ../qhalf $(BINDIR)/qhalf
+	cp ../qhull $(BINDIR)/qhull
+	cp ../qvoronoi $(BINDIR)/qvoronoi
+	cp ../rbox $(BINDIR)/rbox
+	cp ../html/qhull.man $(MANDIR)/qhull.1
+	cp ../html/rbox.man $(MANDIR)/rbox.1
 
-new:    cleanall all
+new:	cleanall all
 
 printall: doc printh printc printf
 
 printh:
-        $(PRINTC) $(HFILES)
+	$(PRINTC) $(HFILES)
 
 printc:
-        $(PRINTC) $(CFILES)
+	$(PRINTC) $(CFILES)
 
 printf:
-        $(PRINTC) $(FILES) 
+	$(PRINTC) $(FILES) 
 
 libqhull.a: $(OBJS)
-        @echo if 'ar' or 'ranlib' fails, try 'make qhullx'
-        ar r libqhull.a $(OBJS)
-        @echo the next line may need to be removed.
-        -test -x /bin/ranlib -o -x /usr/bin/ranlib && ranlib libqhull.a
+	@echo if 'ar' or 'ranlib' fails, try 'make qhullx'
+	ar -r libqhull.a $(OBJS)
+	@echo the next line may need to be removed.
+	-test -x /bin/ranlib -o -x /usr/bin/ranlib && ranlib libqhull.a
 
-# don't use ../qconvex.  Does not work on Red Hat Linux
+# don't use ../qconvex.	 Does not work on Red Hat Linux
 qconvex: qconvex.o libqhull.a
-        $(CC) -o qconvex $(CCOPTS2) qconvex.o -L. -lqhull -lm 
-        cp qconvex ..
+	$(CC) -o qconvex $(CCOPTS2) qconvex.o -L. -lqhull -lm 
+	cp qconvex ..
 
 qdelaunay: qdelaun.o libqhull.a
-        $(CC) -o qdelaunay $(CCOPTS2) qdelaun.o -L. -lqhull -lm 
-        cp qdelaunay ..
+	$(CC) -o qdelaunay $(CCOPTS2) qdelaun.o -L. -lqhull -lm 
+	cp qdelaunay ..
 
 qhalf: qhalf.o libqhull.a
-        $(CC) -o qhalf $(CCOPTS2) qhalf.o -L. -lqhull -lm 
-        cp qhalf ..
+	$(CC) -o qhalf $(CCOPTS2) qhalf.o -L. -lqhull -lm 
+	cp qhalf ..
 
 qvoronoi: qvoronoi.o libqhull.a
-        $(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o -L. -lqhull -lm 
-        cp qvoronoi ..
+	$(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o -L. -lqhull -lm 
+	cp qvoronoi ..
 
 qhull: unix.o libqhull.a
-        $(CC) -o qhull $(CCOPTS2) unix.o -L. -lqhull -lm 
-        cp qhull ..
-        -chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
-        -cd ..; ./rbox D4 | ./qhull
+	$(CC) -o qhull $(CCOPTS2) unix.o -L. -lqhull -lm 
+	cp qhull ..
+	-chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
+	-cd ..; ./rbox D4 | ./qhull
 
 # compile qhull without using libqhull.a
-qhullx: qconvex.o qdelaun.o qhalf.o qvoronoi.o unix.o $(OBJS)
-        $(CC) -o qconvex $(CCOPTS2) qconvex.o $(OBJS) -lm 
-        $(CC) -o qdelaunay $(CCOPTS2) qdelaun.o $(OBJS) -lm 
-        $(CC) -o qhalf $(CCOPTS2) qhalf.o $(OBJS) -lm 
-        $(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o $(OBJS) -lm 
-        $(CC) -o qhull $(CCOPTS2) unix.o $(OBJS) -lm 
-        cp qconvex qdelaunay qhalf qvoronoi qhull ..
-        -chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
-        -cd ..; ./rbox D4 | ./qhull
+qhullx: qconvex.o qdelaun.o qhalf.o qvoronoi.o unix.o rbox.o $(OBJS)
+	$(CC) -o qconvex $(CCOPTS2) qconvex.o $(OBJS) -lm 
+	$(CC) -o qdelaunay $(CCOPTS2) qdelaun.o $(OBJS) -lm 
+	$(CC) -o qhalf $(CCOPTS2) qhalf.o $(OBJS) -lm 
+	$(CC) -o qvoronoi $(CCOPTS2) qvoronoi.o $(OBJS) -lm 
+	$(CC) -o qhull $(CCOPTS2) unix.o $(OBJS) -lm 
+	$(CC) -o rbox $(CCOPTS2) rbox.o $(OBJS) -lm 
+	cp qconvex qdelaunay qhalf qvoronoi qhull rbox ..
+	-chmod +x ../eg/q_test ../eg/q_eg ../eg/q_egtest
+	-cd ..; ./rbox D4 | ./qhull
 
 rbox: rbox.o libqhull.a
-        $(CC) -o rbox rbox.o -L. -lqhull $(CCOPTS2) -lm
-        cp rbox ..
+	$(CC) -o rbox rbox.o -L. -lqhull $(CCOPTS2) -lm
+	cp rbox ..
 
 user_eg: user_eg.o libqhull.a 
-        $(CC)  -o user_eg $(CCOPTS2) user_eg.o  -L. -lqhull -lm 
-        cp user_eg ..
+	$(CC)  -o user_eg $(CCOPTS2) user_eg.o	-L. -lqhull -lm 
+	cp user_eg ..
 
 user_eg2: user_eg2.o libqhull.a 
-        $(CC)  -o user_eg2 $(CCOPTS2) user_eg2.o  -L. -lqhull -lm 
-        cp user_eg2 ..
+	$(CC)  -o user_eg2 $(CCOPTS2) user_eg2.o  -L. -lqhull -lm 
+	cp user_eg2 ..
 
 # end of Makefile
-- 
GitLab