ref: 3b9cafa09f783ccadda14d11fc8b73dc496368c0
parent: d9355041a55f281436c59fecaac1e15e4c585f8d
author: Simon Tatham <anakin@pobox.com>
date: Thu Apr 6 03:07:30 EDT 2023
Fall back to <math.h> if <tgmath.h> doesn't work. This fixes a build failure introduced by commit 2e48ce132e011e8 yesterday. When I saw that commit I expected the most likely problem would be in the NestedVM build, which is currently the thing with the most most out-of-date C implementation. And indeed the NestedVM toolchain doesn't have <tgmath.h> - but much more surprisingly, our _Windows_ builds failed too, with a compile error inside <tgmath.h> itself! I haven't looked closely into the problem yet. Our Windows builds are done with clang, which comes with its own <tgmath.h> superseding the standard Windows one. So you'd _hope_ that clang could make sense of its own header! But perhaps the problem is that this is an unusual compile mode and hasn't been tested. My fix is to simply add a cmake check for <tgmath.h> - which doesn't just check the file's existence, it actually tries compiling a file that #includes it, so it will detect 'file exists but is mysteriously broken' just as easily as 'not there at all'. So this makes the builds start working again, precisely on Ben's theory of opportunistically using <tgmath.h> where possible and falling back to <math.h> otherwise. It looks ugly, though! I'm half tempted to make a new header file whose job is to include a standard set of system headers, just so that that nasty #ifdef doesn't have to sit at the top of almost all the source files. But for the moment this at least gets the build working again.
--- a/auxiliary/hat-test.c
+++ b/auxiliary/hat-test.c
@@ -5,7 +5,11 @@
*/
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
--- a/auxiliary/hatgen.c
+++ b/auxiliary/hatgen.c
@@ -16,7 +16,11 @@
*/
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
--- a/blackbox.c
+++ b/blackbox.c
@@ -7,7 +7,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/bridges.c
+++ b/bridges.c
@@ -73,7 +73,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/cmake/setup.cmake
+++ b/cmake/setup.cmake
@@ -47,6 +47,10 @@
if(NOT HAVE_STDINT_H)
add_compile_definitions(NO_STDINT_H)
endif()
+check_include_file(tgmath.h HAVE_TGMATH_H)
+if(NOT HAVE_TGMATH_H)
+ add_compile_definitions(NO_TGMATH_H)
+endif()
# Try to normalise source file pathnames as seen in __FILE__ (e.g.
# assertion failure messages). Partly to avoid bloating the binaries
--- a/cube.c
+++ b/cube.c
@@ -7,7 +7,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/dominosa.c
+++ b/dominosa.c
@@ -48,7 +48,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/drawing.c
+++ b/drawing.c
@@ -27,7 +27,11 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/fifteen.c
+++ b/fifteen.c
@@ -8,7 +8,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/filling.c
+++ b/filling.c
@@ -58,7 +58,11 @@
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
--- a/flip.c
+++ b/flip.c
@@ -9,7 +9,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/flood.c
+++ b/flood.c
@@ -32,7 +32,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/galaxies.c
+++ b/galaxies.c
@@ -80,7 +80,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/grid.c
+++ b/grid.c
@@ -13,7 +13,11 @@
#include <ctype.h>
#include <float.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/gtk.c
+++ b/gtk.c
@@ -13,7 +13,11 @@
#include <stdarg.h>
#include <string.h>
#include <errno.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <unistd.h>
#include <sys/time.h>
--- a/guess.c
+++ b/guess.c
@@ -7,7 +7,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/hat.c
+++ b/hat.c
@@ -12,7 +12,11 @@
*/
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
--- a/inertia.c
+++ b/inertia.c
@@ -12,7 +12,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/keen.c
+++ b/keen.c
@@ -8,7 +8,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "latin.h"
--- a/lightup.c
+++ b/lightup.c
@@ -48,7 +48,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/loopgen.c
+++ b/loopgen.c
@@ -8,7 +8,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/loopy.c
+++ b/loopy.c
@@ -77,7 +77,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/magnets.c
+++ b/magnets.c
@@ -37,7 +37,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/map.c
+++ b/map.c
@@ -15,7 +15,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/mines.c
+++ b/mines.c
@@ -13,7 +13,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "tree234.h"
#include "puzzles.h"
--- a/misc.c
+++ b/misc.c
@@ -3,7 +3,11 @@
*/
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
--- a/mosaic.c
+++ b/mosaic.c
@@ -14,7 +14,11 @@
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
--- a/net.c
+++ b/net.c
@@ -8,7 +8,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/netslide.c
+++ b/netslide.c
@@ -9,7 +9,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/nullgame.c
+++ b/nullgame.c
@@ -16,7 +16,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/pattern.c
+++ b/pattern.c
@@ -8,7 +8,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/pearl.c
+++ b/pearl.c
@@ -36,7 +36,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "grid.h"
--- a/pegs.c
+++ b/pegs.c
@@ -8,7 +8,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/penrose.c
+++ b/penrose.c
@@ -9,7 +9,11 @@
#include <assert.h>
#include <string.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include <stdio.h>
#include "puzzles.h" /* for malloc routines, and PI */
--- a/range.c
+++ b/range.c
@@ -58,7 +58,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/rect.c
+++ b/rect.c
@@ -26,7 +26,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/samegame.c
+++ b/samegame.c
@@ -68,7 +68,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/signpost.c
+++ b/signpost.c
@@ -8,7 +8,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/singles.c
+++ b/singles.c
@@ -58,7 +58,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "latin.h"
--- a/sixteen.c
+++ b/sixteen.c
@@ -10,7 +10,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/slant.c
+++ b/slant.c
@@ -28,7 +28,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/solo.c
+++ b/solo.c
@@ -87,7 +87,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#ifdef STANDALONE_SOLVER
#include <stdarg.h>
--- a/tents.c
+++ b/tents.c
@@ -33,7 +33,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "matching.h"
--- a/towers.c
+++ b/towers.c
@@ -23,7 +23,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "latin.h"
--- a/tracks.c
+++ b/tracks.c
@@ -21,7 +21,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/twiddle.c
+++ b/twiddle.c
@@ -11,7 +11,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/undead.c
+++ b/undead.c
@@ -35,7 +35,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/unequal.c
+++ b/unequal.c
@@ -21,7 +21,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "latin.h" /* contains typedef for digit */
--- a/unfinished/group.c
+++ b/unfinished/group.c
@@ -31,7 +31,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "latin.h"
--- a/unfinished/numgame.c
+++ b/unfinished/numgame.c
@@ -40,7 +40,11 @@
#include <string.h>
#include <limits.h>
#include <assert.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/unfinished/separate.c
+++ b/unfinished/separate.c
@@ -94,7 +94,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/unfinished/slide.c
+++ b/unfinished/slide.c
@@ -32,7 +32,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"
--- a/unfinished/sokoban.c
+++ b/unfinished/sokoban.c
@@ -58,7 +58,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/unruly.c
+++ b/unruly.c
@@ -47,7 +47,11 @@
#include <string.h>
#include <assert.h>
#include <ctype.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
--- a/untangle.c
+++ b/untangle.c
@@ -32,7 +32,11 @@
#include <assert.h>
#include <ctype.h>
#include <limits.h>
-#include <tgmath.h>
+#ifdef NO_TGMATH_H
+# include <math.h>
+#else
+# include <tgmath.h>
+#endif
#include "puzzles.h"
#include "tree234.h"