Ticket #12173: flint-2.3.p0.diff.14268

File flint-2.3.p0.diff.14268, 45.9 KB (added by jpflori, 9 years ago)

Spkg diff, for review only. Based on #14268.

Line 
1diff --git a/SPKG.txt b/SPKG.txt
2--- a/SPKG.txt
3+++ b/SPKG.txt
4@@ -2,41 +2,51 @@
5 
6 == Description ==
7 
8-FLINT is a C library for doing number theory, written by William Hart and David Harvey.
9+FLINT is a C library for doing number theory, maintained by William Hart.
10 
11 Website: www.flintlib.org
12 
13 == License ==
14 
15-GPL V2+
16+FLINT is licensed GPL v2+.
17 
18 == SPKG Maintainers ==
19 
20- * Burcin Erocal
21- * Mike Hansen
22- * William Stein
23+ * Fredrik Johansson
24+ * Jean-Pierre Flori
25 
26 == Upstream Contact ==
27 
28- * Bill Hart
29- * Development list for FLINT <flint-devel@lists.sourceforge.net> (moderated)
30+ * flint-devel Gougle Group (http://groups.google.co.uk/group/flint-devel)
31+ * William Hart
32 
33 == Dependencies ==
34 
35- * gmp
36+ * MPIR
37+ * MPFR
38  * NTL
39 
40-== Special Update/Build Instructions ==
41+== Patches ==
42 
43- * We patch the makefile slightly to add 64 bit OSX build support and also change
44-   LIBS such that the NTL interface is linked into the flint library.
45-   This is not an officially supported option because flint is pure C
46-   and the NTL interface requires C++.
47- * Remove the '.svn' directories from upstream ('src/') if present.
48- * Remove the 'src/zn_poly/demo/bernoulli/.DS_Store' file
49+ * dylib.patch: patch configure so that the shared library is called
50+   libflint.dylib on Darwin.
51+ * ulong.patch: replace the #define ulong by a typedef which is compatible
52+   with glibc's <sys/types.h> in -std=gnu99 mode.
53 
54 == Changelog ==
55 
56+=== flint-2.3.p0 (Jean-Pierre Flori, 26 March 2013) ===
57+  * Trac #12173: add dylib.patch to make sure the shared library is called
58+    libflint.dylib on Darwin and port ulong.patch to FLINT 2.3.
59+
60+=== flint-2.3 (Mike Hansen, Fredrik Johansson, Jean-Pierre Flori, May 2012-March 2013) ===
61+  * Trac #12173: Update FLINT to version 2.3.
62+  * Removed obsolete patches.
63+  * Cleanup spkg-install and spkg-check scripts.
64+  * Removed Cygwin hack for libntl.a made useless by #9050.
65+  * Removed now useless patch --binary flag on Cygwin.
66+  * Only build shared library on Cygwin.
67+
68 === flint-1.5.2.p4 (Jeroen Demeyer, 14 March 2013) ===
69   * #14268: ulong.patch: replace the #define ulong by a typedef which
70     is compatible with glibc's <sys/types.h> in -std=gnu99 mode.
71@@ -94,20 +104,20 @@
72  * #9277 Add -m64 flag when building the Flint test suite
73    if SAGE64 is set to "yes". Otherwise it builds 32-bit
74    objects and so the test files are not built, but instead
75-   generating the usual "WRONG ELF CLASS" error.
76- * Remove a couple of lines which call spkg-check from
77-   spkg-install if SAGE_CHECK is set to "yes". Otherwise,
78-   spkg-check gets called twice, which is a waste of time.
79+   generating the usual "WRONG ELF CLASS" error.
80+ * Remove a couple of lines which call spkg-check from
81+   spkg-install if SAGE_CHECK is set to "yes". Otherwise,
82+   spkg-check gets called twice, which is a waste of time.
83    I'm afraid to say it was probably me that put those couple
84-   of lines in a year or two ago, before I realised how
85-   spkg-check was supposed to be called.
86+   of lines in a year or two ago, before I realised how
87+   spkg-check was supposed to be called.
88 
89 === flint-1.5.0.p4 (Jaap Spies, Feb 23th, 2010) ===
90  * #8112 Pass CFLAG64 to FLINT_TUNE if set for a 64 bit build.
91 
92 === flint-1.5.0.p3 (David Kirkby, January  2nd, 2010) ===
93- * #7815 Changed makes and spkg-install so that the flag -m64 got
94-   added with a 64-bit build.
95+ * #7815 Changed makes and spkg-install so that the flag -m64 got
96+   added with a 64-bit build.
97 
98 === flint-1.5.0.p1 (William Stein, September 25th, 2009) ===
99  * Included a cygwin fix that involves naming the library .dll instead of .so.
100@@ -117,12 +127,12 @@
101 
102 === flint-1.3.0p3 (Ondrej Certik, September 20th, 2009) ===
103  *  Move libntl.a out of the way temporarily on CYGWIN (this makes the package
104-    built, because it will link to the .so lib instead)
105+    built, because it will link to the .so lib instead)
106 
107 === flint-1.3.0p2 (David Kirkby, June 30th, 2009) ===
108  *  Change '-a' to '-p' option spkg-install so flint installs
109     on Solaris too. The usual GNUism. Only one byte is changed!
110-
111+
112 === flint-1.3.0 (Nick Alexander, June 9th, 2009) ===
113  * Update to latest upstream FLINT, 1.3.0.
114 
115@@ -173,7 +183,7 @@
116 
117 === flint-1.0.20 (Michael Abshoff, December 23rd, 2008) ===
118  * Upgrade to latest upstream (#4861)
119- * clean up SPKG.txt
120+ * clean up SPKG.txt
121 
122 === flint-1.0.13.p0 (Michael Abshoff, August 18th, 2008) ===
123  * Add 64 bit OSX support
124@@ -193,7 +203,7 @@
125  * Only check major and minor gcc release number, not tiny (fixes #3528)
126 
127 === flint-1.010 (William Stein and Craig Citro, June 30, 2008) ===
128- * upgrade to version 1.0.10
129+ * upgrade to version 1.0.10
130 
131 === flint-1.06.p3 (Michael Abshoff, April 1st, 2008) ===
132  * import shared library versioning for flint (Tim Abbott, #3259)
133diff --git a/patches/dylib.patch b/patches/dylib.patch
134new file mode 100644
135--- /dev/null
136+++ b/patches/dylib.patch
137@@ -0,0 +1,17 @@
138+diff -druN src.orig/configure src/configure
139+--- src.orig/configure 2012-11-09 21:42:47.000000000 +0100
140++++ src/configure      2013-03-06 18:21:03.644037750 +0100
141+@@ -225,12 +225,7 @@
142+ if [ -z "$FLINT_LIB" ]; then
143+    case $OS in
144+       Darwin)
145+-         case $MACHINE in
146+-            *64)
147+-               FLINT_LIB="libflint.dylib64";;
148+-            *)
149+-               FLINT_LIB="libflint.dylib";;
150+-         esac;;
151++         FLINT_LIB="libflint.dylib";;
152+       CYGWIN | MINGW*)
153+          FLINT_LIB="libflint.dll";;
154+       *)
155diff --git a/patches/longlong.patch b/patches/longlong.patch
156deleted file mode 100644
157--- a/patches/longlong.patch
158+++ /dev/null
159@@ -1,50 +0,0 @@
160-diff -ur flint-1.5.2.orig/longlong.h flint-1.5.2/longlong.h
161---- flint-1.5.2.orig/longlong.h        2009-09-23 12:03:27.000000000 +0200
162-+++ flint-1.5.2/longlong.h     2010-11-25 07:00:41.000000000 +0100
163-@@ -411,46 +411,6 @@
164-   __asm__ ("adds\t%1, %4, %5\n\tadc\t%0, %2, %3"                      \
165-          : "=r" (sh), "=&r" (sl)                                      \
166-          : "r" (ah), "rI" (bh), "%r" (al), "rI" (bl) __CLOBBER_CC)
167--#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
168--  do {                                                                        \
169--    if (__builtin_constant_p (al))                                    \
170--      {                                                                       \
171--      if (__builtin_constant_p (ah))                                  \
172--        __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2"                \
173--                 : "=r" (sh), "=&r" (sl)                              \
174--                 : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
175--      else                                                            \
176--        __asm__ ("rsbs\t%1, %5, %4\n\tsbc\t%0, %2, %3"                \
177--                 : "=r" (sh), "=&r" (sl)                              \
178--                 : "r" (ah), "rI" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
179--      }                                                                       \
180--    else if (__builtin_constant_p (ah))                                       \
181--      {                                                                       \
182--      if (__builtin_constant_p (bl))                                  \
183--        __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2"                \
184--                 : "=r" (sh), "=&r" (sl)                              \
185--                 : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
186--      else                                                            \
187--        __asm__ ("rsbs\t%1, %5, %4\n\trsc\t%0, %3, %2"                \
188--                 : "=r" (sh), "=&r" (sl)                              \
189--                 : "rI" (ah), "r" (bh), "rI" (al), "r" (bl) __CLOBBER_CC); \
190--      }                                                                       \
191--    else if (__builtin_constant_p (bl))                                       \
192--      {                                                                       \
193--      if (__builtin_constant_p (bh))                                  \
194--        __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                \
195--                 : "=r" (sh), "=&r" (sl)                              \
196--                 : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
197--      else                                                            \
198--        __asm__ ("subs\t%1, %4, %5\n\trsc\t%0, %3, %2"                \
199--                 : "=r" (sh), "=&r" (sl)                              \
200--                 : "rI" (ah), "r" (bh), "r" (al), "rI" (bl) __CLOBBER_CC); \
201--      }                                                                       \
202--    else /* only bh might be a constant */                            \
203--      __asm__ ("subs\t%1, %4, %5\n\tsbc\t%0, %2, %3"                  \
204--             : "=r" (sh), "=&r" (sl)                                  \
205--             : "r" (ah), "rI" (bh), "r" (al), "rI" (bl) __CLOBBER_CC);\
206--    } while (0)
207- #if 1 || defined (__arm_m__)  /* `M' series has widening multiply support */
208- #define umul_ppmm(xh, xl, a, b) \
209-   __asm__ ("umull %0,%1,%2,%3" : "=&r" (xl), "=&r" (xh) : "r" (a), "r" (b))
210diff --git a/patches/makefile.patch b/patches/makefile.patch
211deleted file mode 100644
212--- a/patches/makefile.patch
213+++ /dev/null
214@@ -1,250 +0,0 @@
215---- src/makefile       2009-09-23 12:03:27.000000000 +0200
216-+++ patches/makefile   2010-01-02 07:00:32.000000000 +0100
217-@@ -1,3 +1,5 @@
218-+# sage depends on the NTL interface, so we include it in the flint library
219-+
220- LIBDIR=$(PREFIX)/lib
221- INCLUDEDIR=$(PREFIX)/include
222- DOCDIR=$(PREFIX)/doc
223-@@ -22,7 +24,8 @@
224-
225- CPP = $(FLINT_CPP)
226-
227--LIBS = -L$(FLINT_GMP_LIB_DIR) $(FLINT_LINK_OPTIONS) -lgmp -lpthread -lm
228-+# add NTL options so that NTL interface links properly
229-+LIBS = -L$(FLINT_GMP_LIB_DIR) -L$(FLINT_NTL_LIB_DIR) $(FLINT_LINK_OPTIONS) -lgmp -lpthread -lntl -lm
230-
231- LIBS2 = -L$(FLINT_GMP_LIB_DIR) -L$(FLINT_NTL_LIB_DIR) $(FLINT_LINK_OPTIONS) -lgmp -lpthread -lntl -lm
232-
233-@@ -66,7 +69,8 @@
234-       theta.h \
235-       zmod_mat.h \
236-       F_mpz.h \
237--      QS/tinyQS.h
238-+      QS/tinyQS.h \
239-+      NTL-interface.h
240-
241- ####### library object files
242-
243-@@ -109,13 +113,14 @@
244-       poly.o \
245-       sieve.o \
246-       linear_algebra.o \
247--      block_lanczos.o
248-+      block_lanczos.o \
249-+      NTL-interface.o
250-
251- QS: mpQS
252-
253- tune: ZmodF_mul-tune mpz_poly-tune
254-
255--test: F_mpz-test mpn_extras-test fmpz_poly-test fmpz-test ZmodF-test ZmodF_poly-test mpz_poly-test ZmodF_mul-test long_extras-test zmod_poly-test zmod_mat-test
256-+test: F_mpz-test mpn_extras-test fmpz_poly-test fmpz-test ZmodF-test ZmodF_poly-test mpz_poly-test ZmodF_mul-test long_extras-test zmod_poly-test zmod_mat-test NTL-interface-test
257-
258- check: test
259-       ./F_mpz-test
260-@@ -139,16 +144,20 @@
261- library: $(FLINT_LIB)
262-
263- libflint.dylib: $(FLINTOBJ)
264--      $(CC) -single_module -fPIC -dynamiclib -o libflint.dylib $(FLINTOBJ) $(LIBS)
265-+      $(CPP) -single_module -fPIC -dynamiclib -o libflint.dylib $(FLINTOBJ) $(LIBS)
266-
267- libflint.dylib64: $(FLINTOBJ)
268--      $(CC) -m64 -single_module -fPIC -dynamiclib -o libflint.dylib $(FLINTOBJ) $(LIBS)
269-+      $(CPP) -m64 -single_module -fPIC -dynamiclib -o libflint.dylib $(FLINTOBJ) $(LIBS)
270-
271- libflint.dll: $(FLINTOBJ)
272--      $(CC) -fPIC -shared -o libflint.dll $(FLINTOBJ) $(LIBS)
273-+      $(CPP) -fPIC -shared -o libflint.dll $(FLINTOBJ) $(LIBS)
274-+
275-+# Since this code uses the C++ compiler as a linker to produce
276-+# a library, the -m64 (or equivalent) option must be provided, as it
277-+# it is in the line above where the target is libflint.dylib64
278-
279- libflint.so: $(FLINTOBJ)
280--      $(CC) -fPIC -shared -o libflint.so $(FLINTOBJ) $(LIBS)
281-+      $(CPP) $(CXXFLAG64) -fPIC -shared -o libflint.so $(FLINTOBJ) $(LIBS)
282-
283- ##### zn_poly object files
284-
285-@@ -345,55 +354,56 @@
286- ####### test program targets
287-
288- mpn_extras-test: mpn_extras-test.o test-support.o $(FLINTOBJ) $(HEADERS)
289--      $(CC) $(CFLAGS) mpn_extras-test.o test-support.o -o mpn_extras-test $(FLINTOBJ) $(LIBS)
290-+      $(CPP) $(CFLAGS) mpn_extras-test.o test-support.o -o mpn_extras-test $(FLINTOBJ) $(LIBS)
291-
292- fmpz_poly-test: fmpz_poly-test.o test-support.o $(FLINTOBJ) $(HEADERS)
293--      $(CC) $(CFLAGS) fmpz_poly-test.o test-support.o -o fmpz_poly-test $(FLINTOBJ) $(LIBS)
294-+      $(CPP) $(CFLAGS) fmpz_poly-test.o test-support.o -o fmpz_poly-test $(FLINTOBJ) $(LIBS)
295-
296- fmpz-test: fmpz-test.o test-support.o $(FLINTOBJ) $(HEADERS)
297--      $(CC) $(CFLAGS) fmpz-test.o test-support.o -o fmpz-test $(FLINTOBJ) $(LIBS)
298-+      $(CPP) $(CFLAGS) fmpz-test.o test-support.o -o fmpz-test $(FLINTOBJ) $(LIBS)
299-
300- F_mpz-test: F_mpz-test.o test-support.o $(FLINTOBJ) $(HEADERS)
301--      $(CC) $(CFLAGS) F_mpz-test.o test-support.o -o F_mpz-test $(FLINTOBJ) $(LIBS)
302-+      $(CPP) $(CFLAGS) F_mpz-test.o test-support.o -o F_mpz-test $(FLINTOBJ) $(LIBS)
303-
304- ZmodF-test: ZmodF-test.o test-support.o $(FLINTOBJ) $(HEADERS)
305--      $(CC) $(CFLAGS) ZmodF-test.o test-support.o -o ZmodF-test $(FLINTOBJ) $(LIBS)
306-+      $(CPP) $(CFLAGS) ZmodF-test.o test-support.o -o ZmodF-test $(FLINTOBJ) $(LIBS)
307-
308- ZmodF_poly-test: ZmodF_poly-test.o test-support.o $(FLINTOBJ) $(HEADERS)
309--      $(CC) $(CFLAGS) ZmodF_poly-test.o test-support.o -o ZmodF_poly-test $(FLINTOBJ) $(LIBS)
310-+      $(CPP) $(CFLAGS) ZmodF_poly-test.o test-support.o -o ZmodF_poly-test $(FLINTOBJ) $(LIBS)
311-
312- mpz_poly-test: mpz_poly-test.o test-support.o $(FLINTOBJ) $(HEADERS)
313--      $(CC) $(CFLAGS) mpz_poly-test.o test-support.o -o mpz_poly-test $(FLINTOBJ) $(LIBS)
314-+      $(CPP) $(CFLAGS) mpz_poly-test.o test-support.o -o mpz_poly-test $(FLINTOBJ) $(LIBS)
315-
316- F_mpz_mat-test: F_mpz_mat-test.o test-support.o $(FLINTOBJ) $(HEADERS)
317--      $(CC) $(CFLAGS) F_mpz_mat-test.o test-support.o -o F_mpz_mat-test $(FLINTOBJ) $(LIBS)
318-+      $(CPP) $(CFLAGS) F_mpz_mat-test.o test-support.o -o F_mpz_mat-test $(FLINTOBJ) $(LIBS)
319-
320- F_mpz_LLL_fast_d-test: F_mpz_LLL_fast_d-test.o test-support.o $(FLINTOBJ) $(HEADERS)
321--      $(CC) $(CFLAGS) F_mpz_LLL_fast_d-test.o test-support.o -o F_mpz_LLL_fast_d-test $(FLINTOBJ) $(LIBS)
322-+      $(CPP) $(CFLAGS) F_mpz_LLL_fast_d-test.o test-support.o -o F_mpz_LLL_fast_d-test $(FLINTOBJ) $(LIBS)
323-       
324- ZmodF_mul-test: ZmodF_mul-test.o test-support.o $(FLINTOBJ) $(HEADERS)
325--      $(CC) $(CFLAGS) ZmodF_mul-test.o test-support.o -o ZmodF_mul-test $(FLINTOBJ) $(LIBS)
326-+      $(CPP) $(CFLAGS) ZmodF_mul-test.o test-support.o -o ZmodF_mul-test $(FLINTOBJ) $(LIBS)
327-
328- long_extras-test: long_extras-test.o test-support.o $(FLINTOBJ)
329--      $(CC) $(CFLAGS) long_extras-test.o test-support.o -o long_extras-test $(FLINTOBJ) $(LIBS)
330-+      $(CPP) $(CFLAGS) long_extras-test.o test-support.o -o long_extras-test $(FLINTOBJ) $(LIBS)
331-
332- packed_vec-test: packed_vec-test.o test-support.o $(FLINTOBJ) $(HEADERS)
333--      $(CC) $(CFLAGS) packed_vec-test.o test-support.o -o packed_vec-test $(FLINTOBJ) $(LIBS)
334-+      $(CPP) $(CFLAGS) packed_vec-test.o test-support.o -o packed_vec-test $(FLINTOBJ) $(LIBS)
335-
336- zmod_poly-test: zmod_poly-test.o test-support.o $(FLINTOBJ) $(HEADERS)
337--      $(CC) $(CFLAGS) zmod_poly-test.o test-support.o -o zmod_poly-test $(FLINTOBJ) $(LIBS)
338-+      $(CPP) $(CFLAGS) zmod_poly-test.o test-support.o -o zmod_poly-test $(FLINTOBJ) $(LIBS)
339-
340- zmod_mat-test: zmod_mat-test.o test-support.o $(FLINTOBJ) $(HEADERS)
341--      $(CC) $(CFLAGS) zmod_mat-test.o test-support.o -o zmod_mat-test $(FLINTOBJ) $(LIBS)
342-+      $(CPP) $(CFLAGS) zmod_mat-test.o test-support.o -o zmod_mat-test $(FLINTOBJ) $(LIBS)
343-
344- F_zmod_mat-test: F_zmod_mat-test.o test-support.o $(FLINTOBJ) $(HEADERS)
345--      $(CC) $(CFLAGS) F_zmod_mat-test.o test-support.o -o F_zmod_mat-test $(FLINTOBJ) $(LIBS)
346-+      $(CPP) $(CFLAGS) F_zmod_mat-test.o test-support.o -o F_zmod_mat-test $(FLINTOBJ) $(LIBS)
347-
348- F_mpz_poly-test: F_mpz_poly-test.o test-support.o $(FLINTOBJ) $(HEADERS)
349--      $(CC) $(CFLAGS) F_mpz_poly-test.o test-support.o -o F_mpz_poly-test $(FLINTOBJ) $(LIBS)
350-+      $(CPP) $(CFLAGS) F_mpz_poly-test.o test-support.o -o F_mpz_poly-test $(FLINTOBJ) $(LIBS)
351-
352-+# NTL interface is linked in the library
353- NTL-interface-test: NTL-interface.o NTL-interface-test.o test-support.o $(FLINTOBJ) $(HEADERS)
354--      $(CPP) $(CFLAGS) NTL-interface-test.o NTL-interface.o test-support.o $(FLINTOBJ) -o NTL-interface-test $(LIBS2)
355-+      $(CPP) $(CFLAGS) NTL-interface-test.o test-support.o $(FLINTOBJ) -o NTL-interface-test $(LIBS2)
356-
357- ####### tuning program object files
358-
359-@@ -489,70 +499,70 @@
360- PROFOBJ = $(FLINTOBJ) profiler.o profiler-main.o
361-
362- fmpz_poly-profile: fmpz_poly-profile.o fmpz_poly-profile-tables.o test-support.o $(PROFOBJ)
363--      $(CC) $(CFLAGS) -o fmpz_poly-profile fmpz_poly-profile.o fmpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
364-+      $(CPP) $(CFLAGS) -o fmpz_poly-profile fmpz_poly-profile.o fmpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
365-
366- F_mpz_poly-profile: F_mpz_poly-profile.o F_mpz_poly-profile-tables.o test-support.o $(PROFOBJ)
367--      $(CC) $(CFLAGS) -o F_mpz_poly-profile F_mpz_poly-profile.o F_mpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
368-+      $(CPP) $(CFLAGS) -o F_mpz_poly-profile F_mpz_poly-profile.o F_mpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
369-
370- mpz_poly-profile: mpz_poly-profile.o mpz_poly-profile-tables.o test-support.o $(PROFOBJ)
371--      $(CC) $(CFLAGS) -o mpz_poly-profile mpz_poly-profile.o mpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
372-+      $(CPP) $(CFLAGS) -o mpz_poly-profile mpz_poly-profile.o mpz_poly-profile-tables.o test-support.o $(PROFOBJ) $(LIBS)
373-
374- ZmodF_mul-profile: ZmodF_mul-profile.o ZmodF_mul-profile-tables.o $(PROFOBJ)
375--      $(CC) $(CFLAGS) -o ZmodF_mul-profile ZmodF_mul-profile.o ZmodF_mul-profile-tables.o $(PROFOBJ) $(LIBS)
376-+      $(CPP) $(CFLAGS) -o ZmodF_mul-profile ZmodF_mul-profile.o ZmodF_mul-profile-tables.o $(PROFOBJ) $(LIBS)
377-
378- ZmodF_poly-profile: ZmodF_poly-profile.o ZmodF_poly-profile-tables.o $(PROFOBJ)
379--      $(CC) $(CFLAGS) -o ZmodF_poly-profile ZmodF_poly-profile.o ZmodF_poly-profile-tables.o $(PROFOBJ) $(LIBS)
380-+      $(CPP) $(CFLAGS) -o ZmodF_poly-profile ZmodF_poly-profile.o ZmodF_poly-profile-tables.o $(PROFOBJ) $(LIBS)
381-
382-
383- kara-profile: kara-profile.c profiler.o test-support.o $(FLINTOBJ)
384--      $(CC) $(CFLAGS) -o kara-profile kara-profile.c profiler.o test-support.o $(FLINTOBJ) $(LIBS)
385-+      $(CPP) $(CFLAGS) -o kara-profile kara-profile.c profiler.o test-support.o $(FLINTOBJ) $(LIBS)
386-
387- NTL-profile: NTL-profile.c test-support.o NTL-profile-tables.o $(PROFOBJ)
388-       $(CPP) $(CFLAGS) -o NTL-profile NTL-profile.c NTL-profile-tables.o test-support.o $(PROFOBJ) $(LIB) -lntl
389-
390- zmod_poly-profile: zmod_poly-profile.o zmod_poly-profile-tables.o $(PROFOBJ)
391--      $(CC) $(CFLAGS) -o zmod_poly-profile zmod_poly.o zmod_poly-profile.o zmod_poly-profile-tables.o $(PROFOBJ) $(LIBS)
392-+      $(CPP) $(CFLAGS) -o zmod_poly-profile zmod_poly.o zmod_poly-profile.o zmod_poly-profile-tables.o $(PROFOBJ) $(LIBS)
393-
394- bernoulli-profile: bernoulli-profile.o bernoulli-profile-tables.o $(PROFOBJ)
395--      $(CC) $(CFLAGS) -o bernoulli-profile zmod_poly.o bernoulli-profile.o bernoulli-profile-tables.o $(PROFOBJ) $(LIBS)
396-+      $(CPP) $(CFLAGS) -o bernoulli-profile zmod_poly.o bernoulli-profile.o bernoulli-profile-tables.o $(PROFOBJ) $(LIBS)
397-
398- ####### example programs
399-
400- delta_qexp.o: delta_qexp.c $(HEADERS)
401--      $(CC) $(CFLAGS) -c delta_qexp.c -o delta_qexp.o
402-+      $(CPP) $(CFLAGS) -c delta_qexp.c -o delta_qexp.o
403-
404- delta_qexp: delta_qexp.o $(FLINTOBJ)
405--      $(CC) $(CFLAGS) -o delta_qexp delta_qexp.o $(FLINTOBJ) $(LIBS)
406-+      $(CPP) $(CFLAGS) -o delta_qexp delta_qexp.o $(FLINTOBJ) $(LIBS)
407-
408- expmod: expmod.c $(FLINTOBJ)
409--      $(CC) $(CFLAGS) -o expmod expmod.c $(FLINTOBJ) $(LIBS)
410-+      $(CPP) $(CFLAGS) -o expmod expmod.c $(FLINTOBJ) $(LIBS)
411-
412- BPTJCubes: BPTJCubes.c $(FLINTOBJ)
413--      $(CC) $(CFLAGS) -o BPTJCubes BPTJCubes.c $(FLINTOBJ) $(LIBS)
414-+      $(CPP) $(CFLAGS) -o BPTJCubes BPTJCubes.c $(FLINTOBJ) $(LIBS)
415-
416- bernoulli.o: bernoulli.c $(HEADERS)
417--      $(CC) $(CFLAGS) -c bernoulli.c -o bernoulli.o
418-+      $(CPP) $(CFLAGS) -c bernoulli.c -o bernoulli.o
419-
420- bernoulli: bernoulli.o $(FLINTOBJ)
421--      $(CC) $(CFLAGS) -o bernoulli bernoulli.o $(FLINTOBJ) $(LIBS)
422-+      $(CPP) $(CFLAGS) -o bernoulli bernoulli.o $(FLINTOBJ) $(LIBS)
423-
424- bernoulli_fmpz.o: bernoulli_fmpz.c $(HEADERS)
425--      $(CC) $(CFLAGS) -c bernoulli_fmpz.c -o bernoulli_fmpz.o
426-+      $(CPP) $(CFLAGS) -c bernoulli_fmpz.c -o bernoulli_fmpz.o
427-
428- bernoulli_fmpz: bernoulli_fmpz.o $(FLINTOBJ)
429--      $(CC) $(CFLAGS) -o bernoulli_fmpz bernoulli_fmpz.o $(FLINTOBJ) $(LIBS)
430-+      $(CPP) $(CFLAGS) -o bernoulli_fmpz bernoulli_fmpz.o $(FLINTOBJ) $(LIBS)
431-
432- bernoulli_zmod.o: bernoulli_zmod.c $(HEADERS)
433--      $(CC) $(CFLAGS) -c bernoulli_zmod.c -o bernoulli_zmod.o
434-+      $(CPP) $(CFLAGS) -c bernoulli_zmod.c -o bernoulli_zmod.o
435-
436- bernoulli_zmod: bernoulli_zmod.o $(FLINTOBJ)
437--      $(CC) $(CFLAGS) -o bernoulli_zmod bernoulli_zmod.o $(FLINTOBJ) $(LIBS)
438-+      $(CPP) $(CFLAGS) -o bernoulli_zmod bernoulli_zmod.o $(FLINTOBJ) $(LIBS)
439-
440- thetaproduct.o: thetaproduct.c $(HEADERS)
441--      $(CC) $(CFLAGS2) $(WITH_ZNPOLY) -c thetaproduct.c -o thetaproduct.o
442-+      $(CPP) $(CFLAGS2) $(WITH_ZNPOLY) -c thetaproduct.c -o thetaproduct.o
443-
444- thetaproduct: thetaproduct.o $(FLINTOBJ)
445--      $(CC) $(CFLAGS2) -o thetaproduct thetaproduct.o $(FLINTOBJ) $(LIBS)
446-+      $(CPP) $(CFLAGS2) -o thetaproduct thetaproduct.o $(FLINTOBJ) $(LIBS)
447-
448- ####### Quadratic sieve
449-
450-@@ -590,12 +600,12 @@
451-       $(CC) $(CFLAGS) -c QS/mp_factor_base.c -o mp_factor_base.o
452-
453- mpQS: QS/mpQS.c QS/mpQS.h QS/tinyQS.h mp_factor_base.o mp_poly.o mp_sieve.o mp_linear_algebra.o mp_lprels.o $(FLINTOBJ)
454--      $(CC) $(CFLAGS) -o mpQS QS/mpQS.c mp_factor_base.o mp_poly.o mp_sieve.o mp_linear_algebra.o mp_lprels.o $(FLINTOBJ) $(LIBS)
455-+      $(CPP) $(CFLAGS) -o mpQS QS/mpQS.c mp_factor_base.o mp_poly.o mp_sieve.o mp_linear_algebra.o mp_lprels.o $(FLINTOBJ) $(LIBS)
456-
457- ####### Integer multiplication timing
458-
459- ZMULOBJ = zn_mod.o misc.o mul_ks.o pack.o mul.o mulmid.o mulmid_ks.o ks_support.o mpn_mulmid.o nuss.o pmf.o pmfvec_fft.o tuning.o mul_fft.o mul_fft_dft.o array.o invert.o zmod_mat.o zmod_poly.o memory-manager.o fmpz.o ZmodF_mul-tuning.o mpz_poly.o mpz_poly-tuning.o fmpz_poly.o ZmodF_poly.o mpz_extras.o profiler.o ZmodF_mul.o ZmodF.o mpn_extras.o F_mpz_mul-timing.o long_extras.o factor_base.o poly.o sieve.o linear_algebra.o block_lanczos.o
460-
461- F_mpz_mul-timing: $(FLINTOBJ)
462--      $(CC) $(CFLAGS) F_mpz_mul-timing.c profiler.o -o Zmul $(FLINTOBJ) $(LIBS)
463-+      $(CPP) $(CFLAGS) F_mpz_mul-timing.c profiler.o -o Zmul $(FLINTOBJ) $(LIBS)
464-
465diff --git a/patches/ulong.patch b/patches/ulong.patch
466--- a/patches/ulong.patch
467+++ b/patches/ulong.patch
468@@ -1,12 +1,552 @@
469-diff -ru src/flint.h b/flint.h
470---- src/flint.h        2012-08-03 11:42:57.000000000 +0200
471-+++ b/flint.h  2013-03-14 14:55:02.997513830 +0100
472-@@ -134,7 +134,7 @@
473+diff -dNru src.orig/fft.h src/fft.h
474+--- src.orig/fft.h     2012-11-09 21:42:47.000000000 +0100
475++++ src/fft.h  2013-03-27 14:12:37.157108221 +0100
476+@@ -37,10 +37,8 @@
477+ #ifndef FFT_H
478+ #define FFT_H
479+
480+-#undef ulong /* interferes with system includes */
481+ #include <stdlib.h>
482+ #include <stdio.h>
483+-#define ulong unsigned long
484+
485+ #include "mpir.h"
486+ #include "flint.h"
487+diff -dNru src.orig/flint.h src/flint.h
488+--- src.orig/flint.h   2012-11-09 21:42:47.000000000 +0100
489++++ src/flint.h        2013-03-27 14:12:50.629106553 +0100
490+@@ -1,4 +1,4 @@
491+-/*=============================================================================
492++ /*=============================================================================
493+
494+     This file is part of FLINT.
495+
496+@@ -46,7 +46,7 @@
497+
498+ extern char version[];
499+
500+-#define ulong unsigned long
501++typedef unsigned long ulong;
502+
503+ void * flint_malloc(size_t size);
504+ void * flint_realloc(void * ptr, size_t size);
505+diff -dNru src.orig/fmpq.h src/fmpq.h
506+--- src.orig/fmpq.h    2012-11-09 21:42:47.000000000 +0100
507++++ src/fmpq.h 2013-03-27 14:12:26.693108610 +0100
508+@@ -27,9 +27,7 @@
509+ #ifndef FMPQ_H
510+ #define FMPQ_H
511+
512+-#undef ulong /* interferes with system includes */
513+ #include <stdio.h>
514+-#define ulong unsigned long
515+
516+ #include <mpir.h>
517+ #include <mpfr.h>
518+diff -dNru src.orig/fmpz/inlines.c src/fmpz/inlines.c
519+--- src.orig/fmpz/inlines.c    2012-11-09 21:42:47.000000000 +0100
520++++ src/fmpz/inlines.c 2013-03-27 14:12:27.173108592 +0100
521+@@ -23,9 +23,7 @@
522+
523+ ******************************************************************************/
524+
525+-#undef ulong /* prevent clash with stdlib */
526+ #include <stdlib.h>
527+-#define ulong unsigned long
528+ #include <mpir.h>
529+ #include "flint.h"
530+ #include "ulong_extras.h"
531+diff -dNru src.orig/fmpz/root.c src/fmpz/root.c
532+--- src.orig/fmpz/root.c       2012-11-09 21:42:47.000000000 +0100
533++++ src/fmpz/root.c    2013-03-27 14:12:28.489108543 +0100
534+@@ -23,9 +23,7 @@
535+
536+ ******************************************************************************/
537+
538+-#undef ulong /* avoid conflict with standard library */
539+ #include <stdlib.h>
540+-#define ulong unsigned long
541+
542+ #include <mpir.h>
543+ #include "flint.h"
544+diff -dNru src.orig/fmpz.h src/fmpz.h
545+--- src.orig/fmpz.h    2012-11-09 21:42:47.000000000 +0100
546++++ src/fmpz.h 2013-03-27 14:12:26.477108617 +0100
547+@@ -26,10 +26,8 @@
548+ #ifndef FMPZ_H
549+ #define FMPZ_H
550+
551+-#undef ulong /* interferes with system includes */
552+ #include <stdlib.h>
553+ #include <stdio.h>
554+-#define ulong unsigned long
555+
556+ #include <mpir.h>
557+
558+diff -dNru src.orig/fmpz_mat.h src/fmpz_mat.h
559+--- src.orig/fmpz_mat.h        2012-11-09 21:42:47.000000000 +0100
560++++ src/fmpz_mat.h     2013-03-27 14:12:34.181108329 +0100
561+@@ -27,9 +27,7 @@
562+ #ifndef FMPZ_MAT_H
563+ #define FMPZ_MAT_H
564+
565+-#undef ulong /* interferes with system includes */
566+ #include <stdio.h>
567+-#define ulong unsigned long
568+
569+ #include <mpir.h>
570+ #include "flint.h"
571+diff -dNru src.orig/fmpz_mod_poly.h src/fmpz_mod_poly.h
572+--- src.orig/fmpz_mod_poly.h   2012-11-09 21:42:47.000000000 +0100
573++++ src/fmpz_mod_poly.h        2013-03-27 14:12:29.981108488 +0100
574+@@ -26,9 +26,7 @@
575+ #ifndef FMPZ_MOD_POLY_H
576+ #define FMPZ_MOD_POLY_H
577+
578+-#undef ulong /* interferes with system includes */
579+ #include <stdio.h>
580+-#define ulong unsigned long
581+
582+ #include <mpir.h>
583+
584+diff -dNru src.orig/fmpz_poly_factor.h src/fmpz_poly_factor.h
585+--- src.orig/fmpz_poly_factor.h        2012-11-09 21:42:47.000000000 +0100
586++++ src/fmpz_poly_factor.h     2013-03-27 14:12:26.505108616 +0100
587+@@ -28,9 +28,7 @@
588+ #ifndef FMPZ_POLY_FACTOR_H
589+ #define FMPZ_POLY_FACTOR_H
590+
591+-#undef ulong /* interferes with system includes */
592+ #include <stdio.h>
593+-#define ulong unsigned long
594+
595+ #include <mpir.h>
596+ #include "flint.h"
597+diff -dNru src.orig/fmpz_poly.h src/fmpz_poly.h
598+--- src.orig/fmpz_poly.h       2012-11-09 21:42:47.000000000 +0100
599++++ src/fmpz_poly.h    2013-03-27 14:12:29.993108484 +0100
600+@@ -29,9 +29,7 @@
601+ #ifndef FMPZ_POLY_H
602+ #define FMPZ_POLY_H
603+
604+-#undef ulong /* interferes with system includes */
605+ #include <stdio.h>
606+-#define ulong unsigned long
607+
608+ #include <mpir.h>
609+ #include "flint.h"
610+diff -dNru src.orig/fmpz_poly_q.h src/fmpz_poly_q.h
611+--- src.orig/fmpz_poly_q.h     2012-11-09 21:42:47.000000000 +0100
612++++ src/fmpz_poly_q.h  2013-03-27 14:12:36.613108240 +0100
613+@@ -26,9 +26,7 @@
614+ #ifndef FMPZ_POLY_Q_H
615+ #define FMPZ_POLY_Q_H
616+
617+-#undef ulong /* interferes with system includes */
618+ #include <stdlib.h>
619+-#define ulong unsigned long
620+
621+ #include "flint.h"
622+ #include "fmpz.h"
623+diff -dNru src.orig/NEWS src/NEWS
624+--- src.orig/NEWS      2012-11-09 21:42:47.000000000 +0100
625++++ src/NEWS   2013-03-27 14:12:26.553108615 +0100
626+@@ -226,7 +226,6 @@
627+ v 1.2.4 -- 4-Apr-09
628 
629- #define FLINT_POL_DIV_1_LENGTH 10
630+    * Defined THREAD to be blank on Apple CC and __thread for thread local storage on other gcc's (where it's defined)
631+-   * #undef ulong in profiler.h where time.h and other system time headers are included (both reported by M. Abshoff)
632 
633--#define ulong unsigned long
634-+typedef unsigned long ulong;
635+ v 1.2.5 -- 18-Apr-09
636 
637- #if FLINT_BITS == 32
638- #define half_ulong uint16_t
639+diff -dNru src.orig/nmod_mat.h src/nmod_mat.h
640+--- src.orig/nmod_mat.h        2012-11-09 21:42:47.000000000 +0100
641++++ src/nmod_mat.h     2013-03-27 14:12:26.457108616 +0100
642+@@ -27,9 +27,7 @@
643+ #ifndef NMOD_MAT_H
644+ #define NMOD_MAT_H
645+
646+-#undef ulong /* interferes with system includes */
647+ #include <stdlib.h>
648+-#define ulong unsigned long
649+
650+ #include <mpir.h>
651+ #include "flint.h"
652+diff -dNru src.orig/nmod_poly.h src/nmod_poly.h
653+--- src.orig/nmod_poly.h       2012-11-09 21:42:47.000000000 +0100
654++++ src/nmod_poly.h    2013-03-27 14:12:29.269108513 +0100
655+@@ -29,9 +29,7 @@
656+ #ifndef NMOD_POLY_H
657+ #define NMOD_POLY_H
658+
659+-#undef ulong /* interferes with system includes */
660+ #include <stdio.h>
661+-#define ulong unsigned long
662+
663+ #include "flint.h"
664+ #include "nmod_vec.h"
665+diff -dNru src.orig/nmod_vec.h src/nmod_vec.h
666+--- src.orig/nmod_vec.h        2012-11-09 21:42:47.000000000 +0100
667++++ src/nmod_vec.h     2013-03-27 14:12:26.537108613 +0100
668+@@ -26,9 +26,7 @@
669+ #ifndef NMOD_VEC_H
670+ #define NMOD_VEC_H
671+
672+-#undef ulong /* interferes with system includes */
673+ #include <stdlib.h>
674+-#define ulong unsigned long
675+
676+ #include <mpir.h>
677+ #include "longlong.h"
678+diff -dNru src.orig/padic.h src/padic.h
679+--- src.orig/padic.h   2012-11-09 21:42:47.000000000 +0100
680++++ src/padic.h        2013-03-27 14:12:20.957108822 +0100
681+@@ -26,10 +26,8 @@
682+ #ifndef PADIC_H
683+ #define PADIC_H
684+
685+-#undef ulong /* interferes with system includes */
686+ #include <stdlib.h>
687+ #include <stdio.h>
688+-#define ulong unsigned long
689+
690+ #include <mpir.h>
691+
692+diff -dNru src.orig/perm.h src/perm.h
693+--- src.orig/perm.h    2012-11-09 21:42:47.000000000 +0100
694++++ src/perm.h 2013-03-27 14:12:30.177108477 +0100
695+@@ -26,10 +26,8 @@
696+ #ifndef PERM_H
697+ #define PERM_H
698+
699+-#undef ulong /* interferes with system includes */
700+ #include <stdlib.h>
701+ #include <stdio.h>
702+-#define ulong unsigned long
703+
704+ #include "flint.h"
705+
706+diff -dNru src.orig/profiler.h src/profiler.h
707+--- src.orig/profiler.h        2012-11-09 21:42:47.000000000 +0100
708++++ src/profiler.h     2013-03-27 14:12:26.493108616 +0100
709+@@ -23,7 +23,6 @@
710+
711+ ******************************************************************************/
712+
713+-#undef ulong /* interferes with system includes, redefined by flint.h below */
714+ #include <time.h>
715+ #include <sys/time.h>
716+ #if defined (__WIN32) && !defined(__CYGWIN__)
717+@@ -49,7 +48,6 @@
718+ #else
719+ #include <sys/resource.h>
720+ #endif
721+-#define ulong unsigned long
722+
723+ #ifndef FLINT_PROFILER_H
724+ #define FLINT_PROFILER_H
725+diff -dNru src.orig/qsieve/block_lanczos.c src/qsieve/block_lanczos.c
726+--- src.orig/qsieve/block_lanczos.c    2012-11-09 21:42:47.000000000 +0100
727++++ src/qsieve/block_lanczos.c 2013-03-27 14:12:30.113108480 +0100
728+@@ -33,11 +33,9 @@
729+ --------------------------------------------------------------------*/
730+
731+
732+-#undef ulong /* avoid clash with stdlib */
733+ #include <string.h>
734+ #include <stdlib.h>
735+ #include <stdio.h>
736+-#define ulong unsigned long
737+
738+ #include <mpir.h>
739+ #include "flint.h"
740+diff -dNru src.orig/qsieve/ll_collect_relations.c src/qsieve/ll_collect_relations.c
741+--- src.orig/qsieve/ll_collect_relations.c     2012-11-09 21:42:47.000000000 +0100
742++++ src/qsieve/ll_collect_relations.c  2013-03-27 14:12:30.145108478 +0100
743+@@ -23,11 +23,9 @@
744+
745+ ******************************************************************************/
746+
747+-#undef ulong /* avoid clash with stdlib */
748+ #include <string.h>
749+ #include <stdlib.h>
750+ #include <stdio.h>
751+-#define ulong unsigned long
752+
753+ #include <mpir.h>
754+ #include "flint.h"
755+diff -dNru src.orig/qsieve/ll_compute_poly_data.c src/qsieve/ll_compute_poly_data.c
756+--- src.orig/qsieve/ll_compute_poly_data.c     2012-11-09 21:42:47.000000000 +0100
757++++ src/qsieve/ll_compute_poly_data.c  2013-03-27 14:12:30.101108483 +0100
758+@@ -23,10 +23,8 @@
759+
760+ ******************************************************************************/
761+
762+-#undef ulong /* avoid clash with stdlib */
763+ #include <stdlib.h>
764+ #include <stdio.h>
765+-#define ulong unsigned long
766+
767+ #include <mpir.h>
768+ #include "flint.h"
769+diff -dNru src.orig/qsieve/ll_factor.c src/qsieve/ll_factor.c
770+--- src.orig/qsieve/ll_factor.c        2012-11-09 21:42:47.000000000 +0100
771++++ src/qsieve/ll_factor.c     2013-03-27 14:12:30.169108478 +0100
772+@@ -23,9 +23,7 @@
773+
774+ ******************************************************************************/
775+
776+-#undef ulong /* avoid clash with stdlib */
777+ #include <stdio.h>
778+-#define ulong unsigned long
779+
780+ #include <mpir.h>
781+ #include "flint.h"
782+diff -dNru src.orig/qsieve/ll_insert_relations.c src/qsieve/ll_insert_relations.c
783+--- src.orig/qsieve/ll_insert_relations.c      2012-11-09 21:42:47.000000000 +0100
784++++ src/qsieve/ll_insert_relations.c   2013-03-27 14:12:30.061108481 +0100
785+@@ -27,10 +27,8 @@
786+
787+ ******************************************************************************/
788+
789+-#undef ulong /* avoid clash with stdlib */
790+ #include <stdlib.h>
791+ #include <stdio.h>
792+-#define ulong unsigned long
793+
794+ #include <mpir.h>
795+ #include "flint.h"
796+diff -dNru src.orig/qsieve/ll_square_root.c src/qsieve/ll_square_root.c
797+--- src.orig/qsieve/ll_square_root.c   2012-11-09 21:42:47.000000000 +0100
798++++ src/qsieve/ll_square_root.c        2013-03-27 14:12:30.121108479 +0100
799+@@ -23,11 +23,9 @@
800+
801+ ******************************************************************************/
802+
803+-#undef ulong /* avoid clash with stdlib */
804+ #include <string.h>
805+ #include <stdlib.h>
806+ #include <stdio.h>
807+-#define ulong unsigned long
808+
809+ #include <mpir.h>
810+ #include "flint.h"
811+diff -dNru src.orig/ulong_extras/compute_primes.c src/ulong_extras/compute_primes.c
812+--- src.orig/ulong_extras/compute_primes.c     2012-11-09 21:42:47.000000000 +0100
813++++ src/ulong_extras/compute_primes.c  2013-03-27 14:12:25.673108648 +0100
814+@@ -25,12 +25,10 @@
815+
816+ ******************************************************************************/
817+
818+-#undef ulong /* prevent clash with standard library */
819+ #include <stdlib.h>
820+ #include <string.h>
821+ #include <stdio.h>
822+ #include <pthread.h>
823+-#define ulong unsigned long
824+ #include <mpir.h>
825+ #include "flint.h"
826+ #include "ulong_extras.h"
827+diff -dNru src.orig/ulong_extras/factor.c src/ulong_extras/factor.c
828+--- src.orig/ulong_extras/factor.c     2012-11-09 21:42:47.000000000 +0100
829++++ src/ulong_extras/factor.c  2013-03-27 14:12:25.497108652 +0100
830+@@ -23,10 +23,8 @@
831+
832+ ******************************************************************************/
833+
834+-#undef ulong /* prevent clash with standard library */
835+ #include <stdlib.h>
836+ #include <stdio.h>
837+-#define ulong unsigned long
838+ #include <mpir.h>
839+ #include "flint.h"
840+ #include "ulong_extras.h"
841+diff -dNru src.orig/ulong_extras/factor_lehman.c src/ulong_extras/factor_lehman.c
842+--- src.orig/ulong_extras/factor_lehman.c      2012-11-09 21:42:47.000000000 +0100
843++++ src/ulong_extras/factor_lehman.c   2013-03-27 14:12:25.697108646 +0100
844+@@ -23,9 +23,7 @@
845+     
846+ ******************************************************************************/
847+
848+-#undef ulong /* prevent clash with standard library */
849+ #include <math.h>
850+-#define ulong unsigned long
851+ #include <mpir.h>
852+ #include "flint.h"
853+ #include "ulong_extras.h"
854+diff -dNru src.orig/ulong_extras/factor_partial.c src/ulong_extras/factor_partial.c
855+--- src.orig/ulong_extras/factor_partial.c     2012-11-09 21:42:47.000000000 +0100
856++++ src/ulong_extras/factor_partial.c  2013-03-27 14:12:25.665108645 +0100
857+@@ -23,10 +23,8 @@
858+
859+ ******************************************************************************/
860+
861+-#undef ulong /* prevent clash with standard library */
862+ #include <stdlib.h>
863+ #include <stdio.h>
864+-#define ulong unsigned long
865+ #include <mpir.h>
866+ #include "flint.h"
867+ #include "ulong_extras.h"
868+diff -dNru src.orig/ulong_extras/factor_power235.c src/ulong_extras/factor_power235.c
869+--- src.orig/ulong_extras/factor_power235.c    2012-11-09 21:42:47.000000000 +0100
870++++ src/ulong_extras/factor_power235.c 2013-03-27 14:12:25.741108643 +0100
871+@@ -24,9 +24,7 @@
872+
873+ ******************************************************************************/
874+
875+-#undef ulong /* prevent clash with standard library */
876+ #include <math.h>
877+-#define ulong unsigned long
878+ #include <mpir.h>
879+ #include "flint.h"
880+ #include "ulong_extras.h"
881+diff -dNru src.orig/ulong_extras/is_perfect_power235.c src/ulong_extras/is_perfect_power235.c
882+--- src.orig/ulong_extras/is_perfect_power235.c        2012-11-09 21:42:47.000000000 +0100
883++++ src/ulong_extras/is_perfect_power235.c     2013-03-27 14:12:25.765108645 +0100
884+@@ -25,9 +25,7 @@
885+ ******************************************************************************/
886+
887+ #include <mpir.h>
888+-#undef ulong /* prevent clash with standard library */
889+ #include <math.h>
890+-#define ulong unsigned long
891+ #include "flint.h"
892+ #include "ulong_extras.h"
893+
894+diff -dNru src.orig/ulong_extras/is_prime_pocklington.c src/ulong_extras/is_prime_pocklington.c
895+--- src.orig/ulong_extras/is_prime_pocklington.c       2012-11-09 21:42:47.000000000 +0100
896++++ src/ulong_extras/is_prime_pocklington.c    2013-03-27 14:12:25.681108647 +0100
897+@@ -25,9 +25,7 @@
898+ ******************************************************************************/
899+
900+ #include <mpir.h>
901+-#undef ulong /* prevent clash with standard library */
902+ #include <stdlib.h>
903+-#define ulong unsigned long
904+ #include "flint.h"
905+ #include "ulong_extras.h"
906+
907+diff -dNru src.orig/ulong_extras/is_prime_pseudosquare.c src/ulong_extras/is_prime_pseudosquare.c
908+--- src.orig/ulong_extras/is_prime_pseudosquare.c      2012-11-09 21:42:47.000000000 +0100
909++++ src/ulong_extras/is_prime_pseudosquare.c   2013-03-27 14:12:26.417108617 +0100
910+@@ -23,10 +23,8 @@
911+   
912+ ******************************************************************************/
913+
914+-#undef ulong /* prevent clash with standard library */
915+ #include <stdlib.h>
916+ #include <stdio.h>
917+-#define ulong unsigned long
918+ #include <mpir.h>
919+ #include "flint.h"
920+ #include "ulong_extras.h"
921+diff -dNru src.orig/ulong_extras/is_square.c src/ulong_extras/is_square.c
922+--- src.orig/ulong_extras/is_square.c  2012-11-09 21:42:47.000000000 +0100
923++++ src/ulong_extras/is_square.c       2013-03-27 14:12:25.789108643 +0100
924+@@ -23,9 +23,7 @@
925+
926+ ******************************************************************************/
927+
928+-#undef ulong /* prevent clash with standard library */
929+ #include <math.h>
930+-#define ulong unsigned long
931+ #include <mpir.h>
932+ #include "flint.h"
933+ #include "ulong_extras.h"
934+diff -dNru src.orig/ulong_extras/nextprime.c src/ulong_extras/nextprime.c
935+--- src.orig/ulong_extras/nextprime.c  2012-11-09 21:42:47.000000000 +0100
936++++ src/ulong_extras/nextprime.c       2013-03-27 14:12:25.717108643 +0100
937+@@ -25,10 +25,8 @@
938+
939+ ******************************************************************************/
940+
941+-#undef ulong /* prevent clash with standard library */
942+ #include <stdio.h>
943+ #include <stdlib.h>
944+-#define ulong unsigned long
945+ #include <mpir.h>
946+ #include "flint.h"
947+ #include "ulong_extras.h"
948+diff -dNru src.orig/ulong_extras/nth_prime.c src/ulong_extras/nth_prime.c
949+--- src.orig/ulong_extras/nth_prime.c  2012-11-09 21:42:47.000000000 +0100
950++++ src/ulong_extras/nth_prime.c       2013-03-27 14:12:25.465108656 +0100
951+@@ -23,10 +23,8 @@
952+
953+ ******************************************************************************/
954+
955+-#undef ulong /* prevent clash with standard library */
956+ #include <stdlib.h>
957+ #include <stdio.h>
958+-#define ulong unsigned long
959+ #include "flint.h"
960+ #include "ulong_extras.h"
961+
962+diff -dNru src.orig/ulong_extras/randprime.c src/ulong_extras/randprime.c
963+--- src.orig/ulong_extras/randprime.c  2012-11-09 21:42:47.000000000 +0100
964++++ src/ulong_extras/randprime.c       2013-03-27 14:12:25.513108653 +0100
965+@@ -25,10 +25,8 @@
966+
967+ ******************************************************************************/
968+
969+-#undef ulong /* prevent clash with standard library */
970+ #include <stdlib.h>
971+ #include <stdio.h>
972+-#define ulong unsigned long
973+ #include "flint.h"
974+ #include "ulong_extras.h"
975+
976+diff -dNru src.orig/ulong_extras/sizeinbase.c src/ulong_extras/sizeinbase.c
977+--- src.orig/ulong_extras/sizeinbase.c 2012-11-09 21:42:47.000000000 +0100
978++++ src/ulong_extras/sizeinbase.c      2013-03-27 14:12:25.601108648 +0100
979+@@ -24,9 +24,7 @@
980+ ******************************************************************************/
981+
982+ #include <mpir.h>
983+-#undef ulong /* prevent clash with standard library */
984+ #include <math.h>
985+-#define ulong unsigned long
986+ #include "flint.h"
987+ #include "ulong_extras.h"
988+
989+diff -dNru src.orig/ulong_extras/sqrt.c src/ulong_extras/sqrt.c
990+--- src.orig/ulong_extras/sqrt.c       2012-11-09 21:42:47.000000000 +0100
991++++ src/ulong_extras/sqrt.c    2013-03-27 14:12:25.457108655 +0100
992+@@ -24,9 +24,7 @@
993+ ******************************************************************************/
994+
995+ #include <mpir.h>
996+-#undef ulong /* prevent clash with standard library */
997+ #include <math.h>
998+-#define ulong unsigned long
999+ #include "flint.h"
1000+ #include "ulong_extras.h"
1001+
1002+diff -dNru src.orig/ulong_extras/sqrtmodn.c src/ulong_extras/sqrtmodn.c
1003+--- src.orig/ulong_extras/sqrtmodn.c   2012-11-09 21:42:47.000000000 +0100
1004++++ src/ulong_extras/sqrtmodn.c        2013-03-27 14:12:25.749108642 +0100
1005+@@ -23,10 +23,8 @@
1006+
1007+ ******************************************************************************/
1008+
1009+-#undef ulong /* prevent clash with standard library */
1010+ #include <stdio.h>
1011+ #include <stdlib.h>
1012+-#define ulong unsigned long
1013+ #include <mpir.h>
1014+ #include "flint.h"
1015+ #include "ulong_extras.h"
1016+diff -dNru src.orig/ulong_extras/sqrtmod_primepow.c src/ulong_extras/sqrtmod_primepow.c
1017+--- src.orig/ulong_extras/sqrtmod_primepow.c   2012-11-09 21:42:47.000000000 +0100
1018++++ src/ulong_extras/sqrtmod_primepow.c        2013-03-27 14:12:25.345108659 +0100
1019+@@ -23,10 +23,8 @@
1020+
1021+ ******************************************************************************/
1022+
1023+-#undef ulong /* prevent clash with standard library */
1024+ #include <stdio.h>
1025+ #include <stdlib.h>
1026+-#define ulong unsigned long
1027+ #include <mpir.h>
1028+ #include "flint.h"
1029+ #include "ulong_extras.h"
1030diff --git a/spkg-check b/spkg-check
1031--- a/spkg-check
1032+++ b/spkg-check
1033@@ -1,62 +1,21 @@
1034 #!/usr/bin/env bash
1035 
1036-echo "*************************************************"
1037-echo "Running test suite. This should take 6-20 minutes"
1038-echo "   Please report all failures to sage-devel      "
1039-echo "*************************************************"
1040+###############################################################################
1041+#
1042+# FLINT Sage check script
1043+#
1044+###############################################################################
1045 
1046-if [ "`uname`" = "Linux" -a "`uname -m`" = "x86_64" ]; then
1047-   FLINT_TUNE="-mtune=opteron -march=opteron -fPIC -funroll-loops "
1048-elif [ "`uname`" = "Darwin" -a "`uname -m`" = "Power Macintosh" ]; then
1049-   FLINT_TUNE=" -fPIC -funroll-loops "
1050-elif [ "`uname -m`" = "ia64" ]; then
1051-   # -funroll-loops crashes the build on itanium under GCC-4.2.1, as reported by
1052-   # Kate Minola.
1053-   FLINT_TUNE=" -fPIC "
1054-else
1055-   FLINT_TUNE=" -fPIC -funroll-loops  "
1056+if [ "$SAGE_LOCAL" = "" ]; then
1057+   echo >&2 "Error: SAGE_LOCAL undefined - exiting..."
1058+   echo >&2 "Maybe run 'sage -sh'?"
1059+   exit 1
1060 fi
1061 
1062-export FLINT_TUNE
1063+cd src
1064+$MAKE check
1065 
1066-if [ "x$SAGE64" = xyes ]; then
1067-   echo "Building a 64-bit version of the Flint test suite"
1068-   FLINT_TUNE=" -fPIC -m64 -funroll-loops"
1069-fi
1070-
1071-FLINT_GMP_INCLUDE_DIR="$SAGE_LOCAL"/include/
1072-FLINT_GMP_LIB_DIR="$SAGE_LOCAL"/lib/
1073-
1074-FLINT_NTL_INCLUDE_DIR="$SAGE_LOCAL"/include
1075-FLINT_NTL_LIB_DIR="$SAGE_LOCAL"/lib/
1076-
1077-# What is QD??
1078-FLINT_QD_LIB_DIR="$SAGE_LOCAL"/include
1079-FLINT_QD_INCLUDE_DIR="$SAGE_LOCAL"/include
1080-
1081-export FLINT_GMP_INCLUDE_DIR
1082-export FLINT_GMP_LIB_DIR
1083-export FLINT_QD_INCLUDE_DIR
1084-export FLINT_QD_LIB_DIR
1085-export FLINT_NTL_INCLUDE_DIR
1086-export FLINT_NTL_LIB_DIR
1087-
1088-###
1089-FLINT_LINK_OPTIONS=""
1090-export FLINT_LINK_OPTIONS
1091-
1092-cd src
1093-
1094-make test
1095 if [ $? -ne 0 ]; then
1096-    echo "Error building the test suite for FLINT"
1097+    echo >&2 "Error: FLINT failed to pass its test suite."
1098     exit 1
1099 fi
1100-
1101-for i in {mpn_extras-test,ZmodF-test,ZmodF_mul-test,ZmodF_poly-test,fmpz-test,fmpz_poly-test,mpz_poly-test,long_extras-test,zmod_poly-test,zmod_mat-test,NTL-interface-test}; do
1102-       ./$i
1103-       if [ $? -ne 0 ]; then
1104-           echo "FLINT test failed: $i"
1105-           exit 1
1106-       fi
1107-done
1108diff --git a/spkg-install b/spkg-install
1109--- a/spkg-install
1110+++ b/spkg-install
1111@@ -1,112 +1,67 @@
1112 #!/usr/bin/env bash
1113 
1114+###############################################################################
1115+#
1116+# FLINT Sage install script
1117+#
1118+###############################################################################
1119+
1120 if [ "$SAGE_LOCAL" = "" ]; then
1121-   echo "SAGE_LOCAL undefined ... exiting";
1122-   echo "Maybe run 'sage -sh'?"
1123+   echo >&2 "Error: SAGE_LOCAL undefined - exiting..."
1124+   echo >&2 "Maybe run 'sage -sh'?"
1125    exit 1
1126 fi
1127 
1128-if [ $UNAME = "CYGWIN" ]; then
1129-   # we'll move the libntl.a temporarily out of the way and move it back at the
1130-   # end of this spkg-install script
1131-   mv $SAGE_LOCAL/lib/libntl.a $SAGE_LOCAL/lib/xxx_libntl.a
1132-fi
1133-
1134-FLINT_TUNE=" -fPIC -funroll-loops "
1135-
1136-if [ -z "$CFLAG64" ] ; then
1137-    CFLAG64=-m64
1138-fi
1139-
1140-if [ -z "$CXXFLAG64" ] ; then
1141-    CXXFLAG64=-m64
1142+if [ "$SAGE64" = "yes" ]; then
1143+    echo "Building a 64-bit version of FLINT."
1144+    ABI="64"; export ABI
1145 fi
1146 
1147-
1148-if [ "x$SAGE64" = xyes ]; then
1149-   FLINT_TUNE="$FLINT_TUNE $CFLAG64"
1150-   export CXXFLAG64
1151+if [ "$SAGE_DEBUG" = "yes" ]; then
1152+    echo "Building a debug version of FLINT."
1153+    CFLAGS="-O0 -g $CFLAGS"; export CFLAGS
1154+    FLINT_TUNE=" $FLINT_TUNE"; export FLINT_TUNE
1155 fi
1156 
1157-export FLINT_TUNE
1158+if [ "$UNAME" = "CYGWIN" ]; then
1159+    echo "Only building a shared version of FLINT on Cygwin."
1160+    FLINT_CONFIGURE="--disable-static $FLINT_CONFIGURE"
1161+fi
1162 
1163-export FLINT_GMP_INCLUDE_DIR="$SAGE_LOCAL"/include/
1164-export FLINT_GMP_LIB_DIR="$SAGE_LOCAL"/lib/
1165-export FLINT_NTL_INCLUDE_DIR="$SAGE_LOCAL"/include
1166-export FLINT_NTL_LIB_DIR="$SAGE_LOCAL"/lib/
1167+cd src
1168 
1169-export FLINT_LINK_OPTIONS=""
1170-
1171-
1172-# Apply all patches
1173-if [ $UNAME = "CYGWIN" ]; then
1174-    PATCH_FLAG=--binary
1175-fi
1176-cd src
1177-echo "Patching Flint"
1178-for p in ../patches/*.patch; do 
1179-    patch $PATCH_FLAG -p1 <"$p"
1180+echo "Patching FLINT."
1181+for patch in ../patches/*.patch; do
1182+    [ -f "$patch" ] || continue
1183+    patch -p1 <"$patch"
1184     if [ $? -ne 0 ]; then
1185-        echo "Applying patch $p failed"
1186+        echo >&2 "Error applying '$patch'"
1187         exit 1
1188     fi
1189-done
1190+done
1191 
1192-# UNIX
1193-if [ $UNAME != "Darwin" ]; then
1194-    $MAKE libflint.so
1195-    if [ $? -ne 0 ]; then
1196-        if [ $UNAME = "CYGWIN" ]; then
1197-           # let's move libntl.a back
1198-           mv $SAGE_LOCAL/lib/xxx_libntl.a $SAGE_LOCAL/lib/libntl.a
1199-        fi
1200-        echo "Error building flint shared library."
1201-        exit 1
1202-    fi
1203-    if [ $UNAME = "CYGWIN" ]; then
1204-       # let's move libntl.a back
1205-       mv $SAGE_LOCAL/lib/xxx_libntl.a $SAGE_LOCAL/lib/libntl.a
1206-       # make both kinds of dynamic libraries available for Windows
1207-       cp -p libflint.so libflint.dll
1208-    fi
1209-    echo "Deleting old FLINT"
1210-    rm -f $SAGE_LOCAL/lib/libflint*
1211-    echo "Installing new library file"
1212-    $CP -p libflint* "$SAGE_LOCAL/lib/"
1213-fi
1214+echo "Configuring FLINT."
1215+./configure --prefix="$SAGE_LOCAL" --with-mpir="$SAGE_LOCAL" \
1216+    --with-mpfr="$SAGE_LOCAL" --with-ntl="$SAGE_LOCAL" $FLINT_CONFIGURE
1217+if [ $? -ne 0 ]; then
1218+    echo >&2 "Error: Failed to configure FLINT."
1219+    exit 1
1220+fi
1221 
1222-# OS X
1223-if [ $UNAME = "Darwin" ]; then
1224-    if [ "$SAGE64" = "yes" ]; then
1225-       $MAKE libflint.dylib64
1226-    else
1227-       $MAKE libflint.dylib
1228-    fi
1229-    if [ ! -f libflint.dylib ]; then
1230-        echo "Failed to build FLINT dylib."
1231-        exit 1
1232-    fi
1233-    echo "Deleting old FLINT"
1234-    rm -f $SAGE_LOCAL/lib/libflint*
1235-    echo "Installing new library file"
1236-    $CP libflint.dylib "$SAGE_LOCAL/lib/"
1237-fi
1238+echo "Building FLINT shared library."
1239+$MAKE
1240+if [ $? -ne 0 ]; then
1241+    echo >&2 "Error: Failed to build FLINT shared library."
1242+    exit 1
1243+fi
1244 
1245+echo "Deleting old FLINT files."
1246+rm -f $SAGE_LOCAL/lib/libflint*
1247+rm -rf $SAGE_LOCAL/include/flint
1248 
1249-# Copy the header files
1250-
1251-rm -rf "$SAGE_LOCAL"/include/FLINT
1252-
1253-for i in {FLINT/,FLINT/zn_poly/src/}; do
1254-       mkdir -p "$SAGE_LOCAL"/include/$i
1255-       if [ $? -ne 0 ]; then
1256-           echo "Error building FLINT"
1257-           exit 1
1258-       fi
1259-
1260-       $CP ${i/FLINT\//}*.h "$SAGE_LOCAL"/include/$i
1261-       if [ $? -ne 0 ]; then
1262-           echo "Error building FLINT"
1263-           exit 1
1264-       fi
1265-done
1266+echo "Installing new FLINT files."
1267+$MAKE install
1268+if [ $? -ne 0 ]; then
1269+    echo >&2 "Error: Failed to install FLINT."
1270+    exit 1
1271+fi