Browse code

adding configure.ac

Ben Bolstad authored on 19/06/2025 23:00:43
Showing 2 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,142 @@
1
+dnl
2
+dnl Configuration things for preprocessCore
3
+dnl
4
+
5
+
6
+AC_INIT("DESCRIPTION")
7
+
8
+dnl
9
+dnl Are things (still) the same ?
10
+dnl (taken from the 'writing R extensions manual')
11
+
12
+dnl Now find the compiler and compiler flags to use
13
+: ${R_HOME=`R RHOME`}
14
+if test -z "${R_HOME}"; then
15
+       echo "could not determine R_HOME"
16
+       exit 1
17
+fi
18
+CC=`"${R_HOME}/bin/R" CMD config CC`
19
+CPP=`"${R_HOME}/bin/R" CMD config CPP`
20
+CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS`
21
+CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS`
22
+AC_PROG_CC
23
+AC_PROG_CPP
24
+
25
+
26
+AC_LANG(C)
27
+
28
+# Checks for libraries.
29
+use_pthreads=no
30
+AC_SEARCH_LIBS([pthread_create], [pthread],
31
+  [use_pthreads=yes])
32
+
33
+# Checks for header files.
34
+AC_HEADER_STDC
35
+AC_CHECK_HEADERS([stdlib.h])
36
+
37
+if test "x${have_pthreads}" = xyes; then
38
+  AC_CHECK_HEADERS([pthread.h], [],
39
+    [use_pthreads=no])
40
+fi
41
+
42
+
43
+AC_MSG_CHECKING([if PTHREAD_STACK_MIN is defined])
44
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([
45
+	#include <pthread.h>
46
+	#include <limits.h>
47
+
48
+      int main () {size_t stacksize = PTHREAD_STACK_MIN + 0x4000;
49
+}     	  
50
+    ])],[use_pthread_stack_min=yes], [use_pthread_stack_min=no])
51
+AC_MSG_RESULT($use_pthread_stack_min)
52
+
53
+if test "x$use_pthread_stack_min" = xno; then
54
+	use_pthreads=no
55
+fi
56
+
57
+
58
+AC_MSG_CHECKING([if __pthread_get_minstack can be used])
59
+AC_RUN_IFELSE([AC_LANG_SOURCE([
60
+	#include <pthread.h>
61
+	#include <limits.h> 
62
+	#include <dlfcn.h>
63
+
64
+
65
+	typedef size_t (*GetMinStack)(const pthread_attr_t *attr);
66
+
67
+	GetMinStack _get_minstack_func = NULL;
68
+
69
+	static void get_minstack_init() {
70
+  		_get_minstack_func =
71
+        (GetMinStack)dlsym(RTLD_DEFAULT, "__pthread_get_minstack");
72
+	}
73
+
74
+	
75
+    int main () {
76
+		get_minstack_init();
77
+		if (_get_minstack_func == NULL){
78
+			return 1;
79
+		} else {
80
+			return 0;
81
+		}
82
+	}
83
+
84
+    ])],[use_pthread_get_minstack=yes], [use_pthread_get_minstack=no])
85
+AC_MSG_RESULT($use_pthread_get_minstack)
86
+
87
+
88
+
89
+# AC_MSG_CHECKING([if R is using flexiblas])
90
+# BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
91
+# if echo "${BLAS_LIBS}" | grep flexiblas > /dev/null; then
92
+#    AC_MSG_RESULT([flexiblas found. preprocessCore specific threading will be disabled])
93
+#    use_pthreads=no
94
+# else
95
+#     AC_MSG_RESULT([flexiblas not found. preprocessCore threading will not be disabled])
96
+# fi
97
+
98
+
99
+dnl AC_MSG_CHECKING([if R is using openblasp])
100
+dnl BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
101
+dnl if echo "${BLAS_LIBS}" | grep openblasp > /dev/null; then
102
+dnl     AC_MSG_RESULT([openblasp found. preprocessCore specific threading will be disabled])
103
+dnl     use_pthreads=yes
104
+dnl else
105
+dnl     AC_MSG_RESULT([openblasp not found. preprocessCore threading will not be disabled])
106
+dnl fi
107
+
108
+
109
+
110
+
111
+AC_ARG_ENABLE([threading],
112
+	AS_HELP_STRING([--disable-threading],[Disable threading]))
113
+
114
+
115
+
116
+AS_IF([test "x$enable_threading" != "xno" ],[
117
+	    if test "x${use_pthreads}" = "xno"; then
118
+	       AC_MSG_NOTICE(------------------------------------------)
119
+	       AC_MSG_NOTICE( Unable to find pthreads on this system.  )
120
+	       AC_MSG_NOTICE( Building a single-threaded version.      )
121
+	       AC_MSG_NOTICE(------------------------------------------)
122
+	    fi
123
+
124
+
125
+	    if test "x${use_pthreads}" = "xyes"; then
126
+  	       AC_MSG_NOTICE(Enabling threading for preprocessCore)
127
+  	       AC_DEFINE(USE_PTHREADS, 1)
128
+		   if test "x${use_pthread_get_minstack}" = "xyes"; then
129
+		   	AC_MSG_NOTICE(Using __pthread_get_minstack)
130
+			AC_DEFINE(INFER_MIN_STACKSIZE,1)
131
+
132
+	    fi
133
+	    ],
134
+	    [
135
+	    AC_MSG_NOTICE(Disabling threading for preprocessCore)
136
+	    ])
137
+
138
+
139
+
140
+
141
+
142
+AC_OUTPUT(src/Makevars)
... ...
@@ -80,30 +80,30 @@ AC_RUN_IFELSE([AC_LANG_SOURCE([
80 80
 			return 0;
81 81
 		}
82 82
 	}
83
-	
83
+
84 84
     ])],[use_pthread_get_minstack=yes], [use_pthread_get_minstack=no])
85 85
 AC_MSG_RESULT($use_pthread_get_minstack)
86 86
 
87 87
 
88 88
 
89
-AC_MSG_CHECKING([if R is using flexiblas])
90
-BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
91
-if echo "${BLAS_LIBS}" | grep flexiblas > /dev/null; then
92
-    AC_MSG_RESULT([flexiblas found. preprocessCore specific threading will be disabled])
93
-    use_pthreads=no
94
-else
95
-    AC_MSG_RESULT([flexiblas not found. preprocessCore threading will not be disabled])
96
-fi
89
+# AC_MSG_CHECKING([if R is using flexiblas])
90
+# BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
91
+# if echo "${BLAS_LIBS}" | grep flexiblas > /dev/null; then
92
+#    AC_MSG_RESULT([flexiblas found. preprocessCore specific threading will be disabled])
93
+#    use_pthreads=no
94
+# else
95
+#     AC_MSG_RESULT([flexiblas not found. preprocessCore threading will not be disabled])
96
+# fi
97 97
 
98 98
 
99
-AC_MSG_CHECKING([if R is using openblasp])
100
-BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
101
-if echo "${BLAS_LIBS}" | grep openblasp > /dev/null; then
102
-    AC_MSG_RESULT([openblasp found. preprocessCore specific threading will be disabled])
103
-    use_pthreads=no
104
-else
105
-    AC_MSG_RESULT([openblasp not found. preprocessCore threading will not be disabled])
106
-fi
99
+dnl AC_MSG_CHECKING([if R is using openblasp])
100
+dnl BLAS_LIBS=`"${R_HOME}/bin/R" CMD config BLAS_LIBS`
101
+dnl if echo "${BLAS_LIBS}" | grep openblasp > /dev/null; then
102
+dnl     AC_MSG_RESULT([openblasp found. preprocessCore specific threading will be disabled])
103
+dnl     use_pthreads=yes
104
+dnl else
105
+dnl     AC_MSG_RESULT([openblasp not found. preprocessCore threading will not be disabled])
106
+dnl fi
107 107
 
108 108
 
109 109
 
... ...
@@ -125,6 +125,10 @@ AS_IF([test "x$enable_threading" != "xno" ],[
125 125
 	    if test "x${use_pthreads}" = "xyes"; then
126 126
   	       AC_MSG_NOTICE(Enabling threading for preprocessCore)
127 127
   	       AC_DEFINE(USE_PTHREADS, 1)
128
+		   if test "x${use_pthread_get_minstack}" = "xyes"; then
129
+		   	AC_MSG_NOTICE(Using __pthread_get_minstack)
130
+			AC_DEFINE(INFER_MIN_STACKSIZE,1)
131
+
128 132
 	    fi
129 133
 	    ],
130 134
 	    [