Skip to content

Instantly share code, notes, and snippets.

@klange
Created March 1, 2023 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klange/4f712b43273344e85a78c0b4fecd8a2a to your computer and use it in GitHub Desktop.
Save klange/4f712b43273344e85a78c0b4fecd8a2a to your computer and use it in GitHub Desktop.
diff --git a/Makefile b/Makefile
index b23bf18..3fc2adc 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,10 @@ KRKMODS = $(wildcard modules/*.krk modules/*/*.krk modules/*/*/*.krk)
all: ${TARGET} ${MODULES} ${TOOLS} ${GENMODS}
+ifneq ($(shell tools/can-floor-without-libm.sh $(CC)),yes)
+ LDLIBS += -lm
+endif
+
ifeq (,$(findstring mingw,$(CC)))
CFLAGS += -pthread
LDLIBS += -ldl -lpthread
diff --git a/tools/can-floor-without-libm.sh b/tools/can-floor-without-libm.sh
new file mode 100755
index 0000000..fc989da
--- /dev/null
+++ b/tools/can-floor-without-libm.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+($1 -o /dev/null -x c - 2>/dev/null && echo "yes" || echo "no") <<END
+#include <stdio.h>
+#include <stdlib.h>
+int main(int argc, char * argv[]) {
+ return printf("%f", __builtin_floor(strtod(argv[1],NULL)));
+}
+END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment