Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
some windows thread functions versus pthread for context API
[simgrid.git] / configure.ac
1
2 ######################
3 ## Setup the autotools
4 ##
5
6 AC_PREREQ(2.59)
7 AC_INIT([simgrid],[3.1.1-cvs],[simgrid-devel@lists.gforge.inria.fr])
8 AC_CONFIG_SRCDIR([include/gras.h])
9 AC_CONFIG_HEADERS([src/gras_config.h])
10 # A CI_PREREQ(2003.01.16) # We need a recent ACI when having sub-modules
11
12 AC_REVISION($Revision$)
13 AC_CANONICAL_TARGET
14 AC_LANG([C])
15
16 AM_INIT_AUTOMAKE(gnu)
17 AC_CONFIG_MACRO_DIR(acmacro) 
18 ACLOCAL="$ACLOCAL -I acmacro"
19 AC_LIBTOOL_WIN32_DLL
20 AC_PROG_LIBTOOL
21
22 ###############
23 ## System checks
24 ##
25 SG_CONFIGURE_PART(System checks...)
26 AC_PROG_CC(xlC gcc cc)
27 AM_SANITY_CHECK
28 AC_PROG_MAKE_SET
29 AC_CHECK_PRINTF_NULL
30 AC_CHECK_VA_COPY
31
32 # Checks for header files.
33 AC_HEADER_STDC
34 AC_HEADER_TIME
35 AC_CHECK_HEADERS([sys/socket.h \
36                   sys/stat.h \
37                   windows.h winsock.h winsock2.h \
38                   sys/time.h \
39                   errno.h unistd.h \
40                   execinfo.h\
41                   signal.h ])
42 AC_CHECK_FUNCS([gettimeofday usleep \
43                 getdtablesize \
44                 sysconf\
45                 readv\
46                 popen\
47                 signal])
48                 
49 # check for a working snprintf (or use xbt/snprintf.c, which comes from http://www.ijs.si/software/snprintf/)
50 AC_FUNC_SNPRINTF
51 # check for asprintf function familly (or request the replacements from xbt/snprintf.c)
52 AC_CHECK_FUNC(  asprintf, :,   AC_DEFINE(NEED_ASPRINTF,  1,  enable the asprintf   replacement))
53 AC_CHECK_FUNC( vasprintf, :,   AC_DEFINE(NEED_VASPRINTF, 1,  enable the vasprintf  replacement))
54 # we don't use those:
55 # A C_CHECK_FUNC( asnprintf, :,   A C_DEFINE(NEED_ASNPRINTF,  1, enable the asnprintf  replacement))
56 # A C_CHECK_FUNC(vasnprintf, :,   A C_DEFINE(NEED_VASNPRINTF, 1, enable the vansprintf replacement))
57
58
59 # Checks for typedefs, structures, and compiler characteristics.
60 AC_C_CONST
61 AC_C_INLINE
62 AC_TYPE_SIZE_T
63
64 ###################################
65 ## SimGrid and GRAS specific checks
66 ##
67
68 SG_CONFIGURE_PART(Checking GRAS architecture signature...)
69 # Check architecture signature begin
70 GRAS_ARCH
71 # Check architecture signature end
72 GRAS_CHECK_STRUCT_COMPACTION
73
74
75 dnl ##
76 dnl ##  CONTEXT IMPLEMENTATION
77 dnl ##
78
79 SG_CONFIGURE_PART([Checking for threads, contexts or assimilated...])
80
81 dnl #
82 dnl #  1. determine possibilities
83 dnl #
84
85 dnl #  check for MCSC method
86 AC_CHECK_MCSC(mcsc=yes, mcsc=no) 
87
88 dnl #  check for pthread method
89 AC_CHECK_HEADERS([pthread.h])
90 AC_CHECK_LIB(pthread,pthread_create,pthread=yes, pthread=no)
91
92 dnl #
93 dnl #  2. make a general decision
94 dnl #
95
96 if test ".$mcsc" = .yes; then
97    mcsc=yes
98 elif test ".$pthread" = .yes; then
99    pthread=yes
100 else
101     ac_header=windows.h
102     as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
103     if test `eval echo '${'$as_ac_Header'}'` = yes; then
104       windows_context=yes
105     else
106       AC_ERROR([no appropriate backend found])
107     fi
108 fi
109
110 dnl #
111 dnl #  3. allow decision to be overridden by user
112 dnl #
113
114 AC_MSG_CHECKING(what kind of backend should we use)
115
116 AC_ARG_WITH(pthread, [  --with-pthread   Use pthread instead of ucontext.],with_context=pthread)
117
118 AC_ARG_WITH(context,
119   [  --with-context=[ucontext/pthread]   Use either (System V) swapcontext or pthread [[default=auto]].],,
120   with_context=auto)
121
122 if test "x$with_context$mcsc" = "xucontextno" ; then 
123   AC_MSG_ERROR([--with-context=ucontext specified but ucontext unusable. Relaunch configure without this argument.], 77)
124 fi
125
126 case $with_context in
127  ucontext) ;;
128  pthread) ;;
129  windows) ;;
130  auto) with_context=ucontext;;
131  *) AC_MSG_ERROR([--with-context must be either ucontext or pthread]) ;;
132 esac
133
134 if test "x$with_context" = "xucontext" ; then
135   if test ".$mcsc" = .yes; then
136     AC_MSG_RESULT(found working ucontext. Great!)
137     AC_DEFINE([USE_UCONTEXT],1,[Define if we use ucontext or not])
138   else
139     if test ".$windows_context" = .yes ; then
140       AC_MSG_RESULT(use windows context portability layer.)
141       with_context=windows
142     else
143       AC_MSG_RESULT([[no working ucontext found. Try pthreads as a fallback]])
144       with_context=pthread
145     fi
146   fi
147 fi
148
149 if test "x$with_context" = "xpthread"; then
150   AC_CHECK_HEADERS([pthread.h])
151   AC_CHECK_LIB(pthread,pthread_create,,
152     [AC_MSG_ERROR([[Cannot find pthreads, no way (try --with-context=ucontext if you haven't already tried).]])])
153   AC_DEFINE([USE_PTHREADS],1,[Define if we use pthreads or not])
154   AC_MSG_RESULT(You have pthreads. Let's use them.)
155 fi
156
157 dnl #
158 dnl #  4. determine a few additional details
159 dnl #
160
161 if test "x$with_context" = "xucontext" ; then
162 dnl #  direction of stack grow
163   AC_CHECK_STACKGROWTH(PTH_STACKGROWTH)
164   if test ".$ac_cv_check_stackgrowth" = ".down"; then
165       PTH_STACK_GROWTH="down"
166   else
167       PTH_STACK_GROWTH="up"
168   fi
169   AC_SUBST(PTH_STACK_GROWTH)
170   
171   AC_CHECK_STACKSETUP(makecontext, pth_skaddr_makecontext, pth_sksize_makecontext)
172 fi
173
174 #########################################
175 ## Check for libraries extra-dependencies
176 ##
177
178 SG_CONFIGURE_PART(Checking extra libraries dependencies...)
179
180 AC_MSG_CHECKING(for csdp)
181 SIMGRID_DEP=""
182 sdp=no
183 AC_CHECK_LIB(sdp,sdp,csdp=yes, csdp=no,-llapack -lblas -lm)
184 if test "x$csdp" = xyes; then 
185   SIMGRID_DEP="$SIMGRID_DEP -lsdp -llapack -lblas -lm"
186   AC_MSG_RESULT(Found working sdp library.)
187   AC_DEFINE(HAVE_SDP, 1, [Indicates whether printf("%s",NULL) works])
188 else
189   AC_MSG_RESULT(Could not find any working sdp library.)
190 fi;
191 AM_CONDITIONAL(HAVE_SDP,test x$csdp != xno)
192
193 AC_SUBST([SIMGRID_DEP])
194
195 GRAS_DEP=""
196 AC_CHECK_LIB(nsl, gethostbyname, [GRAS_DEP="$GRAS_DEP -lnsl"])
197 AC_CHECK_LIB(socket, connect,    [GRAS_DEP="$GRAS_DEP -lsocket"])
198
199 AC_MSG_CHECKING(for extra dependencies of libgras)
200 case $host_os in
201   *mingw* ) GRAS_DEP="$GRAS_DEP -lws2_32" ; SIMGRID_DEP="$SIMGRID_DEP -lws2_32" ;;
202 esac
203            
204 if test "x$GRAS_DEP" = x; then 
205    AC_MSG_RESULT(none)
206 else
207    AC_MSG_RESULT($GRAS_DEP)
208 fi
209 AC_SUBST([GRAS_DEP])
210
211 ##############################################
212 ## Enhance maintainer mode and SUBST variables
213 ## (must be placed after any compilation tests since our overprotective flags
214 ##  let some tests fail)
215
216 # Check whether we are doing a regular build or a GRAMINE (minimal) one
217 # Next line is modified by sed when building gramine source tree
218 gramine_mode=no
219 if test x$gramine_mode = xyes
220 then
221   USE_MAINTAINER_MODE=no
222 fi
223 AM_CONDITIONAL(GRAMINE_MODE,test x$gramine_mode != xno)
224
225
226 AM_MAINTAINER_MODE
227 if test x$USE_MAINTAINER_MODE = xyes 
228 then
229    # Maintainers have no choice ! I'm a BOFH, and I plainly assume. [Mt]
230    enable_compile_warnings=yes   
231 fi
232 SG_COMPILE_FLAGS
233
234 AC_SUBST(CFLAGS)
235 AC_SUBST(CPPFLAGS)
236 AC_SUBST(LDFLAGS)
237 AC_SUBST([abs_builddir])
238 AC_SUBST([abs_srcdir])
239 AC_SUBST([abs_top_builddir])
240 AC_SUBST([abs_top_srcdir])
241
242 #####################
243 ## Check for programs
244 ##
245
246 SG_CONFIGURE_PART(Check for programs...)
247 AC_CHECK_PROG(BASH, bash, `which bash`, /bin/sh)
248 WARNING="This file is generated, do not edit"
249 AC_SUBST(WARNING)
250
251
252 # Can we rebuild the parsers?
253 # We really want flex and refuse other lex. So, the parser is portable and
254 # does not induce extra lib dependency
255 AC_PROG_FLEX(2.5.30)
256                 
257 # Can we rebuild the xml-lexers from the XML specification?
258 # if not, simply touch the flex source files (which are distributed in
259 #  tarballs even if generated by flexml) and hope for the best.
260 AC_CHECK_PROG(FLEXML,flexml,`which flexml`,NOTFOUND)
261 AM_CONDITIONAL(HAVE_FLEXML,test x$FLEXML != xNOTFOUND)
262
263 if test x$USE_MAINTAINER_MODE = xyes 
264 then
265    # Check for doxygen when in maintainer mode since dist* targets fail
266    # without it
267    AC_PATH_PROG(DOXYGEN,doxygen,`which doxygen`)
268    if test x$DOXYGEN = x ; then 
269      AC_MSG_ERROR([doxygen is mandatory in maintainer mode])
270    fi
271 fi
272
273 # Can we extract really usable backtraces? (also need the popen function)
274 AC_PATH_PROG(ADDR2LINE, addr2line)
275 if test x$ADDR2LINE != x ; then
276   AC_DEFINE_UNQUOTED(ADDR2LINE,"$ADDR2LINE",[Path to the addr2line tool])
277 fi
278
279 AC_SUBST(ac_configure_args)
280 # Can we make status line about the compilation result?
281 AC_CHECK_PROG(MD5SUM,md5sum,`which md5sum`)
282 if test x$MD5SUM != xno ; then
283   build_version=`find -name '*.[ch]' |grep -v src/ucontext_stack.h | grep -v src/gras_config.h |\ 
284                  xargs cat| $MD5SUM | sed 's/ .*$//'`
285 else 
286   build_version="no_md5sum_binary"
287 fi
288 build_id="$PACKAGE ver=$VERSION build=$build_version args=\"$ac_configure_args\""
289 AC_SUBST(build_id)
290
291 ###################
292 ## Makes the output
293 ##
294
295
296 #
297 #      examples/gras/chord/Makefile  examples/gras/chord/test_sg examples/gras/chord/test_rl
298 #  src/amok/Makefile
299
300 SG_CONFIGURE_PART(Generating files...)
301
302 # Core of the libraries
303
304 AC_CONFIG_FILES([
305   Makefile
306   include/Makefile
307   src/Makefile
308   src/ucontext_stack.h
309 ])
310
311 # Tools being embeeded in gramine (stub generator)
312 AC_CONFIG_FILES([
313   tools/Makefile
314     tools/gras/Makefile
315 ])
316
317 # GRAMINE_CUT_BEGIN
318
319 # Tools NOT being embeeded in gramine
320 AC_CONFIG_FILES([
321   tools/graspe-slave
322 ],[
323     for file in                                                 \
324      tools/graspe-slave           tools/graspe-master           \
325     ; do                                                        \
326       test -e $file && chmod +x $file;                          \
327     done
328 ])
329
330 # Testsuite
331
332 AC_CONFIG_FILES([  
333   testsuite/Makefile
334   testsuite/run_tests    
335   testsuite/gras/trp_tcp_usage  testsuite/gras/trp_file_usage
336 ],[
337     for file in                                                 \
338      testsuite/run_tests                                        \
339      testsuite/gras/trp_tcp_usage testsuite/gras/trp_file_usage \
340     ; do                                                        \
341       test -e $file && chmod +x $file;                          \
342     done
343 ])
344
345 # Documentation
346 AC_CONFIG_FILES([
347   doc/Makefile
348   doc/Doxyfile
349 ])
350
351 # Examples
352
353 AC_CONFIG_FILES([
354   examples/Makefile 
355     examples/msg/Makefile           examples/msg/run_msg_test
356     examples/simdag/Makefile        examples/simdag/test_simdag
357     examples/gras/Makefile 
358       examples/gras/ping/Makefile   examples/gras/ping/test_sg   examples/gras/ping/test_rl
359       examples/gras/rpc/Makefile    examples/gras/rpc/test_sg    examples/gras/rpc/test_rl
360       examples/gras/timer/Makefile  examples/gras/timer/test_sg  examples/gras/timer/test_rl
361       examples/gras/chrono/Makefile examples/gras/chrono/test_sg examples/gras/chrono/test_rl
362       examples/gras/mutual_exclusion/simple_token/Makefile examples/gras/mutual_exclusion/simple_token/test_sg examples/gras/mutual_exclusion/simple_token/test_rl
363       examples/gras/mmrpc/Makefile  examples/gras/mmrpc/test_sg  examples/gras/mmrpc/test_rl
364       examples/gras/pmm/Makefile    examples/gras/pmm/test_sg    examples/gras/pmm/test_rl
365       examples/gras/all2all/Makefile examples/gras/all2all/test_sg examples/gras/all2all/test_rl
366
367       examples/gras/p2p/Makefile
368       examples/gras/p2p/chord/Makefile examples/gras/p2p/chord/test_sg examples/gras/p2p/chord/test_rl
369       examples/gras/p2p/can/Makefile   examples/gras/p2p/can/test_sg   examples/gras/p2p/can/test_rl
370       
371     examples/amok/Makefile       
372       examples/amok/bandwidth/Makefile examples/amok/bandwidth/test_sg examples/amok/bandwidth/test_rl
373       examples/amok/saturate/Makefile  examples/amok/saturate/test_sg  examples/amok/saturate/test_rl
374 ],[
375     for file in                                                 \
376      \
377      examples/amok/bandwidth/test_sg examples/amok/bandwidth/test_rl \
378      examples/amok/saturate/test_sg  examples/amok/saturate/test_rl \
379      \
380      examples/gras/ping/test_sg   examples/gras/ping/test_rl    \
381      examples/gras/rpc/test_sg    examples/gras/rpc/test_rl     \
382      examples/gras/timer/test_sg  examples/gras/timer/test_rl   \
383      examples/gras/chrono/test_sg examples/gras/chrono/test_rl  \
384      examples/gras/mutual_exclusion/simple_token/test_sg examples/gras/mutual_exclusion/simple_token/test_rl  \
385      examples/gras/mmrpc/test_sg  examples/gras/mmrpc/test_rl   \
386      examples/gras/pmm/test_sg    examples/gras/pmm/test_rl     \
387      examples/gras/all2all/test_sg  examples/gras/all2all/test_rl   \
388      examples/gras/p2p/chord/test_sg examples/gras/p2p/chord/test_rl  \
389      examples/gras/p2p/can/test_sg   examples/gras/p2p/can/test_rl  \
390      examples/msg/run_msg_test                                  \
391      examples/simdag/test_simdag                                \
392     ; do                                                        \
393       test -e $file && chmod +x $file;                          \
394     done
395 ])
396
397 #     examples/gras/chord/test_sg  examples/gras/chord/test_rl   \
398 #    examples/gras/pastry/test_sg   
399
400
401
402 #    examples/gras/saturate/Makefile  examples/gras/saturate/test_sg
403 #    examples/gras/alnem/Makefile     examples/gras/alnem/test_sg
404
405
406 # GRAMINE_CUT_END
407
408 AC_OUTPUT
409
410 echo "
411
412 Configuration of package \`${PACKAGE}' (version ${VERSION}) on $gras_arch_name (=$gras_arch):
413
414         Compiler:        ${CC} (version: ${GCC_VERSION})
415         
416         CFlags:          ${CFLAGS}
417         CPPFlags:        ${CPPFLAGS}
418         LDFlags:         ${LDFLAGS}
419
420         Context backend: ${with_context}
421 "
422
423 if test -e CVS && test x$USE_MAINTAINER_MODE != xyes ; then
424   echo "WARNING:"
425   echo "WARNING: you seem to compile the CVS version without the maintainer mode."
426   echo "WARNING: You may want to enable this by specifying:"
427   echo "WARNING:"
428   echo "WARNING: ./configure --enable-maintainer-mode  $ac_configure_args"
429   echo "WARNING:"
430 fi
431 echo $build_id > stamp.configure
432
433 exit 0;