Avoid building user-driven-interop example on non-LRTS layers
[charm.git] / src / scripts / configure.ac
blobd0099c38fe42b0296033e8f8705b268d2e30612e
1 # Decimal representation of Charm++ release line and API revision
2 # Increment the last 2 digits when making an API change
3 # Increase the first three after branching for a release
5 AC_INIT(Charm++, 60900, [charm@cs.illinois.edu], charm, [http://charm.cs.illinois.edu/])
7 AC_CONFIG_SRCDIR(./Makefile)
9 AC_CONFIG_HEADER(conv-autoconfig.h)
11 AC_CONFIG_COMMANDS([config-cleanup],
12                    [sed -i -e 's:^#define\s\+PACKAGE://&:' conv-autoconfig.h])
14 get_full_command_name()
16     if test "$(basename "$*")" != "$*"; then
17         echo "$(cd "$(dirname "$*")" && pwd)/$(basename "$*")"
18     else
19         echo "$*"
20     fi
23 ConvSh='../tmp/conv-mach-opt.sh'
24 ConvMak='../tmp/conv-mach-opt.mak'
26 #clean up conv-mach-opt.sh
27 sed -e '/Option added by configure/d' "$ConvSh" | sed -e '/^$/d' > conv-mach-opt.sh.clean
28 cp -f conv-mach-opt.sh.clean   "$ConvSh"
29 rm -f conv-mach-opt.sh.clean
31 #clean up conv-mach-opt.mak
32 sed -e '/Option added by configure/d' "$ConvMak" | sed -e '/^$/d' > conv-mach-opt.mak.clean
33 cp -f conv-mach-opt.mak.clean   "$ConvMak"
34 rm -f conv-mach-opt.mak.clean
36 CHARMINC="."
37 CHARMBIN="../bin"
38 test -r ./conv-config.sh && . ./conv-config.sh
40 echo AC_PACKAGE_VERSION > ../include/VERSION
41 AC_DEFINE_UNQUOTED([CHARM_VERSION], AC_PACKAGE_VERSION, [Charm++ Release/API version number])
43 charmout="charmconfig.out"
44 /bin/rm -rf $charmout
45 MAKEFILE_EXT=Make.extlib
47 Echo() {
48         echo $* 
49         echo $* >> $charmout
52 # add into conv-mach-opt.sh
53 # add_flag $1 $2
54 # $2 is description
55 add_flag() {
56         key=$1
57         key="${key%%=*}"
58         last=`grep -w "$key" "$ConvSh" 2>/dev/null | tail -1 | sed -e 's/ *#.*$//'`
59         skip=0
60         if test -n "$last" -a  "$last" = "$1" 
61         then
62           skip=1
63         fi
64         if test $skip = 0
65         then
66           cat >> "$ConvSh" << EOT
68 $1   # Option added by configure script's $2 section
69 EOT
70         fi
73 # remove_flag $1
74 remove_flag() {
75      sed -e '/^'"$1"'=/d' "$ConvSh" > tmp.$$
76      cp tmp.$$ "$ConvSh"
77      /bin/rm -f tmp.$$
80 # add into conv-mach-opt.mak
81 # add_make_flag $1 $2
82 # $2 is description
83 add_make_flag() {
84         key=$1
85         key="${key%%=*}"
86         key="${key%%:*}"
87         last=`grep -w "$key" "$ConvMak" 2>/dev/null | tail -1 | sed -e 's/ *#.*$//'`
88         skip=0
89         if test -n "$last" -a  "$last" = "$1"
90         then
91           skip=1
92         fi
93         if test $skip = 0
94         then
95           # The lack of whitespace around $1 here is necessary.
96           cat >> "$ConvMak" << EOT
98 $1# Option added by configure script's $2 section
99 EOT
100         fi
103 # remove_make_flag $1
104 remove_make_flag() {
105      sed -e '/^'"$1"'=/d' "$ConvMak" > tmp.$$
106      cp tmp.$$ "$ConvMak"
107      /bin/rm -f tmp.$$
110 add_flag "OPTS_CC='$OPTS_CC'"   'Pass through user-provided C compiler options'
111 add_flag "OPTS_CXX='$OPTS_CXX'" 'Pass through user-provided C++ compiler options'
112 add_make_flag "CMK_COMPILER:=$CMK_COMPILER" 'basic setup'
113 add_make_flag "CMK_SMP:=$CMK_SMP" 'basic setup'
114 add_make_flag "CMK_SHARED_SUF:=$CMK_SHARED_SUF" 'basic setup'
115 add_make_flag "CMK_NO_PARTITIONS:=$CMK_NO_PARTITIONS" 'basic setup'
116 add_make_flag "CMK_BLUEGENEQ:=$CMK_BLUEGENEQ" 'basic setup'
117 add_make_flag "CMK_MULTICORE:=$CMK_MULTICORE" 'basic setup'
118 add_make_flag "CMK_USE_LRTS:=$CMK_USE_LRTS" 'basic setup'
119 add_make_flag "BUILD_CUDA:=$BUILD_CUDA" 'basic setup'
121 # enable/disable error checking
122 AC_ARG_ENABLE([error-checking],
123             [AS_HELP_STRING([--enable-error-checking],
124               [enable error checking])], ,
125             [enable_error_checking=yes])
127 if test "$enable_error_checking" = "no"
128 then
129   Echo "Error checking is disabled" 
130   AC_DEFINE_UNQUOTED(CMK_ERROR_CHECKING, 0, [disable error checking])
131   add_flag 'OPTS_CC="$OPTS_CC -U_FORTIFY_SOURCE"' 'error checking'
132   add_flag 'OPTS_CXX="$OPTS_CXX -U_FORTIFY_SOURCE"' 'error checking'
133 else
134   Echo "Error checking is enabled" 
135   AC_DEFINE_UNQUOTED(CMK_ERROR_CHECKING, 1, [enable error checking])
138 # enable/disable AMPI error checking
139 AC_ARG_ENABLE([ampi-error-checking],
140             [AS_HELP_STRING([--enable-ampi-error-checking],
141               [enable AMPI error checking])], ,
142             [enable_ampi_error_checking=yes])
144 if test "$enable_ampi_error_checking" = "no"
145 then
146   Echo "AMPI error checking is disabled"
147   AC_DEFINE_UNQUOTED(AMPI_ERROR_CHECKING, 0, [disable ampi error checking])
148 else
149   Echo "AMPI error checking is enabled"
150   AC_DEFINE_UNQUOTED(AMPI_ERROR_CHECKING, 1, [enable ampi error checking])
153 # enable/disable statistics collection
154 AC_ARG_ENABLE([stats],
155             [AS_HELP_STRING([--enable-stats],
156               [enable statistics collection])], ,
157             [enable_stats=yes])
159 if test "$enable_stats" = "no"
160 then
161   Echo "Statistics collection is disabled" 
162   AC_DEFINE_UNQUOTED(CMK_WITH_STATS, 0, [disable statistics collection])
163 else
164   Echo "Statistics collection is enabled" 
165   AC_DEFINE_UNQUOTED(CMK_WITH_STATS, 1, [enable statistics collection])
168 # check enable/disable
169 AC_ARG_ENABLE([tracing],
170             [AS_HELP_STRING([--enable-tracing],
171               [enable tracing modules])], ,
172             [enable_tracing=yes])
174 if test "$enable_tracing" = "no"
175 then
176   Echo "Charm tracing is disabled"
177   AC_DEFINE_UNQUOTED(CMK_TRACE_ENABLED, 0, [disable tracing])
178   add_flag CMK_TRACE_ENABLED=0
179   add_make_flag 'CMK_TRACE_ENABLED:=0' 'tracing'
180 else
181   Echo "Charm tracing is enabled"
182   AC_DEFINE_UNQUOTED(CMK_TRACE_ENABLED, 1, [enable tracing])
183   add_flag CMK_TRACE_ENABLED=1
184   add_make_flag 'CMK_TRACE_ENABLED:=1' 'tracing'
187 AC_ARG_ENABLE([tracing-commthread],
188             [AS_HELP_STRING([--enable-tracing-commthread],
189               [enable tracing communication thread])], ,
190             [enable_tracing_commthread=no])
192 if test "$enable_tracing_commthread" = "yes"
193 then
194   Echo "Charm tracing communication thread is enabled"
195   AC_DEFINE_UNQUOTED(CMK_SMP_TRACE_COMMTHREAD, 1, [enable tracing comm thread])
196 else
197   Echo "Charm tracing communication thread is disabled"
198   AC_DEFINE_UNQUOTED(CMK_SMP_TRACE_COMMTHREAD, 0, [disable tracing comm thread])
202 # enable task queue
203 AC_ARG_ENABLE([task_queue],
204             [AS_HELP_STRING([--enable-task-queue],
205               [enable task queue])],
206             [enable_task_queue=$enableval],
207             [enable_task_queue=no])
209 if test "$enable_task_queue" = "no"
210 then
211   Echo "Task Queue is disabled"
212   AC_DEFINE_UNQUOTED(CMK_TASKQUEUE, 0, [disable task queue])
213 else
214   Echo "Task Queue is enabled"
215   AC_DEFINE_UNQUOTED(CMK_TASKQUEUE, 1, [enable task queue])
218 # enable drone mode
219 AC_ARG_ENABLE([drone_mode],
220             [AS_HELP_STRING([--enable-drone-mode],
221               [enable drone mode])],
222             [enable_drone_mode=$enableval],
223             [enable_drone_mode=no])
225 if test "$enable_drone_mode" = "no"
226 then
227   Echo "Drone mode is disabled"
228   AC_DEFINE_UNQUOTED(CMK_DRONE_MODE, 0, [disable drone mode])
229 else
230   Echo "Drone mode is enabled"
231   AC_DEFINE_UNQUOTED(CMK_DRONE_MODE, 1, [enable drone mode])
234 AC_ARG_ENABLE([charmdebug],
235             [AS_HELP_STRING([--enable-charmdebug],
236               [enable charmDebug])], ,
237             [enable_charmdebug=yes])
239 if test "$enable_charmdebug" = "no" -o "$CMK_CCS_AVAILABLE" = '0'
240 then
241   Echo "CharmDebug is disabled" 
242   AC_DEFINE_UNQUOTED(CMK_CHARMDEBUG, 0, [disable charmdebug])
243   add_flag CMK_CHARMDEBUG=0
244   add_make_flag 'CMK_CHARMDEBUG:=0'
245 else
246   Echo "CharmDebug is enabled" 
247   AC_DEFINE_UNQUOTED(CMK_CHARMDEBUG, 1, [enable charmdebug])
248   add_flag CMK_CHARMDEBUG=1
249   add_make_flag 'CMK_CHARMDEBUG:=1'
252 AC_ARG_ENABLE([replay],
253             [AS_HELP_STRING([--enable-replay],
254               [enable record/replay])],
255             [enable_replay=$enableval],
256             [enable_replay=yes])
258 if test "$enable_replay" = "no"
259 then
260   Echo "Charm record/replay is disabled"
261   AC_DEFINE_UNQUOTED(CMK_REPLAYSYSTEM, 0, [disable replay])
262 else
263   Echo "Charm record/replay is enabled"
266 AC_ARG_ENABLE([ccs],
267             [AS_HELP_STRING([--enable-ccs],
268               [enable CCS])], ,
269             [enable_ccs=yes])
271 if test "$enable_ccs" = "no" -o "$CMK_CCS_AVAILABLE" = '0'
272 then
273   Echo "CCS is disabled" 
274   AC_DEFINE_UNQUOTED(CMK_CCS_AVAILABLE, 0, [disable ccs])
275 else
276   Echo "CCS is enabled" 
277   AC_DEFINE_UNQUOTED(CMK_CCS_AVAILABLE, 1, [enable ccs])
280 AC_ARG_ENABLE([controlpoint],
281             [AS_HELP_STRING([--enable-controlpoint],
282               [enable control point])],
283             [enable_controlpoint=$enableval],
284             [enable_controlpoint=yes])
286 if test "$enable_controlpoint" = "yes"
287 then
288   Echo "Charm control point is enabled"
289   AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 1, [enable controlpoint])
290 else
291   Echo "Charm control point is disabled"
292   AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 0, [disable controlpoint])
295 AC_ARG_ENABLE([lbuserdata],
296             [AS_HELP_STRING([--enable-lbuserdata],
297               [enable LB user data])],
298             [enable_lbuserdata=$enableval],
299             [enable_lbuserdata=no])
301 if test "$enable_lbuserdata" = "yes"
302 then
303   Echo "Charm LB user data is enabled"
304   AC_DEFINE_UNQUOTED(CMK_LB_USER_DATA, 1, [enable lb user data])
305 else
306   Echo "Charm LB user data  is disabled"
307   AC_DEFINE_UNQUOTED(CMK_LB_USER_DATA, 0, [disable lb user data])
310 AC_ARG_ENABLE([lockless-queue],
311             [AS_HELP_STRING([--enable-lockless-queue],
312               [enable lockless queue for PE local and node queue])],
313             [enable_lockless_queue=$enableval],
314             [enable_lockless_queue=no])
316 if test "$enable_lockless_queue" = "no"
317 then
318   Echo "Lockless queue for PE local and node queue is disabled"
319   AC_DEFINE_UNQUOTED(CMK_LOCKLESS_QUEUE, 0, [disable lockless queue for pe/node queue])
320 else
321   Echo "Lockless queue for PE local and node queue is enabled"
322   AC_DEFINE_UNQUOTED(CMK_LOCKLESS_QUEUE, 1, [enable lockless queue for pe/node queue])
326 AC_ARG_ENABLE([shrinkexpand],
327             [AS_HELP_STRING([--enable-shrinkexpand],
328               [enable malleable jobs / shrink expand])],
329             [enable_shrinkexpand=$enableval],
330             [enable_shrinkexpand=no])
332 if test "$enable_shrinkexpand" = "yes"
333 then
334   if test "$enable_ccs" = "no"
335   then
336     Echo "CCS cannot be disabled when enabling shrink-expand"
337     test_finish 1
338   else
339     Echo "Charm shrink expand is enabled - Controlpoint is disabled."
340     AC_DEFINE_UNQUOTED(CMK_SHRINK_EXPAND, 1, [enable shrinkexpand])
341     AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 0, [disable controlpoint])
342   fi
343 else
344   Echo "Charm shrink expand is disabled"
345   AC_DEFINE_UNQUOTED(CMK_SHRINK_EXPAND, 0, [disable shrinkexpand])
348 AC_ARG_ENABLE([charmpy],
349             [AS_HELP_STRING([--enable-charmpy],
350               [enable charm4py support])],
351             [enable_charmpy=$enableval],
352             [enable_charmpy=no])
354 if test "$enable_charmpy" = "yes"
355 then
356   Echo "charm4py support is enabled"
357   AC_DEFINE_UNQUOTED(CMK_CHARMPY, 1, [enable charmpy])
358 else
359   Echo "charm4py support is disabled"
360   AC_DEFINE_UNQUOTED(CMK_CHARMPY, 0, [disable charmpy])
363 AC_ARG_WITH([numa],
364             [AS_HELP_STRING([--with-numa],
365               [support memory affinity with NUMA])],
366             [],
367             [with_numa=no])
369 WITH_NUMA=no
370 if test "$with_numa" = "yes"
371 then
372   Echo "Charm NUMA support is builtin"
373   WITH_NUMA=yes
376 AC_ARG_WITH([lbtime-type],
377             [AS_HELP_STRING([--with-lbtime-type=type],
378                             [load balancing timer type])],
379             [], [with_lbtime_type=double])
381 if test "$with_lbtime_type" = "float" -o "$with_lbtime_type" = "double"
382 then
383   Echo "Setting load balancing timer type as '$with_lbtime_type'"
384   AC_DEFINE_UNQUOTED(CMK_LBTIME_TYPE, $with_lbtime_type, [Setting load balancing timer type])
385 else
386   Echo "Invalid type specified for load balancing timer type"
387   test_finish 1
390 AC_DEFINE_UNQUOTED(CMK_LBID_64BIT, 1, [enable 64 bit LB ID])
392 AC_DEFINE_UNQUOTED(CMK_CKSECTIONINFO_STL, 1, [enable STL CkSectionInfo])
394 AC_ARG_WITH([qlogic],
395             [AS_HELP_STRING([--with-qlogic],
396               [QLogic based Infiniband])],[with_qlogic=yes],
397             [with_qlogic=no])
399 if test "$with_qlogic" = "no"
400 then
401   AC_DEFINE_UNQUOTED(QLOGIC, 0, [disable qlogic])
402 else
403   Echo "QLogic based Infiniband"
404   AC_DEFINE_UNQUOTED(QLOGIC, 1, [enable qlogic])
408 AC_MSG_CHECKING(machine name)
409 version=`pwd | awk -F/ '{print $(NF-1)}'`
410 base_version="$CMK_VDIR"
411 AC_DEFINE_UNQUOTED(CMK_MACHINE_NAME, "$version",[machine name])
412 AC_MSG_RESULT($version)
413 AC_SUBST(base_version)
415 t="test.cpp"
416 tc="test.c"
418 # test result passed in $1
419 # If the test suceeded, print $3 and set "pass"/clear "fail"
420 # If the test failed, print $2 and clear "pass"/set "fail"
421 test_result() {
422         if test $1 -eq 0
423         then
424                 AC_MSG_RESULT("$3")
425                 pass="1"
426                 fail="0"
427         else
428                 AC_MSG_RESULT("$4")
429                 pass="0"
430                 fail="1"
431 # For debugging the configure script, just "export autoconf_debug=1"
432 #  to get this verbose data on any failed tests:
433                 if test ! -z "$autoconf_debug"
434                 then
435                         echo "------- test script for $2 failed:"
436                         cat out
437                         echo "------- the test program was:"
438                         cat $t
439                         echo "-------"
440                 fi
441         fi
444 # Test: tries to compile C file $t (described by $1).
445 #  If successful, prints $2 and sets $pass/clears $fail
446 #  If failure, prints $3 and sets $pass/clears $fail
447 #  additional arguments to c++ compiler are passed as $4
448 test_cc() {
449         AC_MSG_CHECKING("$1")
450         echo "### $1" >> $charmout
451         cat $tc >> $charmout
452         echo $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 >> $charmout
453         $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 > out 2>&1
454         test_result $? "$1" "$2" "$3"
455         strictpass=$pass
456         strictfail=$fail
457         if test $pass -eq 1
458         then 
459           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
460           then 
461             strictpass="0" && strictfail="1"
462           fi
463         fi
464         cat out >> $charmout
465         /bin/rm -f out
468 # Test: tries to compile C++ file $t (described by $1).
469 #  If successful, prints $2 and sets $pass/clears $fail
470 #  If failure, prints $3 and sets $pass/clears $fail
471 #  additional arguments to c++ compiler are passed as $4
472 test_cxx() {
473         AC_MSG_CHECKING("$1")
474         echo "### $1" >> $charmout
475         cat $t >> $charmout
476         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
477         $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 > out 2>&1
478         test_result $? "$1" "$2" "$3"
479         strictpass=$pass
480         strictfail=$fail
481         if test $pass -eq 1
482         then 
483           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
484           then 
485             strictpass="0" && strictfail="1"
486           fi
487         fi
488         cat out >> $charmout
489         /bin/rm -f out
492 # Test: tries to compile C++ file $t (described by $1) using native compiler.
493 #  If successful, prints $2 and sets $pass/clears $fail
494 #  If failure, prints $3 and sets $pass/clears $fail
495 #  additional arguments to c++ compiler are passed as $4
496 test_native_cxx() {
497         AC_MSG_CHECKING("$1")
498         echo "### $1" >> $charmout
499         cat $t >> $charmout
500         echo $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
501         $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 > out 2>&1
502         test_result $? "$1" "$2" "$3"
503         strictpass=$pass
504         strictfail=$fail
505         if test $pass -eq 1
506         then
507           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
508           then
509             strictpass="0" && strictfail="1"
510           fi
511         fi
512         cat out >> $charmout
513         /bin/rm -f out
516 # Testlink: tries to compile and link a C++ file $t (described by $1).
517 #  If successful, prints $2 and sets $pass/clears $fail
518 #  If failure, prints $3 and sets $pass/clears $fail
519 #  additional arguments to c++ compiler are passed as $4
520 test_link() {
521         AC_MSG_CHECKING("$1")
522         echo "### $1" >> $charmout
523         cat $t >> $charmout
524         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
525         $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 > out 2>&1
526         if test $? -ne 0
527         then
528           test_result 1 "$1" "$2" "$3"
529         else
530           echo $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 $5 >> $charmout
531           $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 $5 >> out 2>&1
532           ret=$?
533           test ! -x testlink && ret=1
534           test_result $ret "$1" "$2" "$3"
535         fi
536         strictpass=$pass
537         strictfail=$fail
538         if test $pass -eq 1
539         then 
540           if cat out | grep -i "warn" > /dev/null 2>&1
541           then 
542             strictpass="0" && strictfail="1"
543           fi
544         fi
545         cat out >> $charmout
546         /bin/rm -f out
549 # Testlinkc: tries to compile and link a C file $t (described by $1).
550 #  If successful, prints $2 and sets $pass/clears $fail
551 #  If failure, prints $3 and sets $pass/clears $fail
552 #  additional arguments to c++ compiler are passed as $4
553 test_linkc() {
554         AC_MSG_CHECKING("$1")
555         echo "### $1" >> $charmout
556         cat $tc >> $charmout
557         echo $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 >> $charmout
558         $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 > out 2>&1
559         if test $? -ne 0
560         then
561           test_result 1 "$1" "$2" "$3"
562         else
563           echo $CMK_LD $CMK_LD_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 >> $charmout
564           $CMK_LD $CMK_LD_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 >> out 2>&1
565           test_result $? "$1" "$2" "$3"
566         fi
567         strictpass=$pass
568         strictfail=$fail
569         if test $pass -eq 1
570         then 
571           if cat out | grep -i "warn" > /dev/null 2>&1
572           then 
573             strictpass="0" && strictfail="1"
574           fi
575         fi
576         cat out >> $charmout
577         /bin/rm -f out
580 # test_linkso $1 $2 $3 $4, where
581 # $1: debug msg
582 # $2: yes msg
583 # $3: no msg
584 # $4: extra link option
585 test_linkso() {
586         AC_MSG_CHECKING("$1")
587         echo $1 >> $charmout
588         cat $t >> $charmout
589         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX $CMK_PIC -c $t -o test.o $4 >> $charmout
590         $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $CMK_PIC $t -o test.o $4 > out 2>&1
591         if test $? = 1
592         then
593           test_result 1 "$1" "$2" "$3"
594         else
595           echo $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD $CMK_LD_SHARED $CMK_SYSLIBS test.o -o testlink.$CMK_SHARED_SUF $4 >> $charmout
596           $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD $CMK_LD_SHARED $CMK_SYSLIBS test.o -o testlink.$CMK_SHARED_SUF $4 > out 2>&1
597           test_result $? "$1" "$2" "$3"
598         fi
599         cat out >> $charmout
600         /bin/rm -f out testlink.$CMK_SHARED_SUF
603 test_finish() {
604         rm -f $t $tc testlink test.o    > /dev/null 2>&1
605         /bin/rm -f out
606         test $1 -eq 1 && echo "*** Please find detailed output in tmp/charmconfig.out ***"
607         exit $1
610 # detect certain architectures
611 if cat /proc/cpuinfo 2>/dev/null | grep 'POWER7'  > /dev/null
612 then
613   AC_DEFINE_UNQUOTED(CMK_POWER7, 1, [whether is power7])
616 # detect OS
617 OSNAME=`uname -s`
618 if test $OSNAME = "Linux"
619 then
620   AC_DEFINE_UNQUOTED(CMK_OS_IS_LINUX, 1, [OS is Linux])
621 else
622   AC_DEFINE_UNQUOTED(CMK_OS_IS_LINUX, 0, [OS is Linux])
625 # test cp -p
626 AC_MSG_CHECKING("cp command as")
627 CP="cp -p"
628 touch test_file
629 if ! $CP test_file test_file.cp 2>err
630 then
631   CP="cp"
633 rm -f test_file test_file.cp
634 AC_MSG_RESULT($CP)
635 add_flag CP=\""$CP"\" "cp command"
638 cat > $t <<EOT
639 #include <stdio.h>
640 void foo(void) {
641         printf("Hello, world!\n");
645 if test "$CMK_BUILD_CRAY" = "1"
646 then
647 #echo "Test for known incompatible compiler versions"
649  if test "$CRAY_CC_VERSION" = "8.1.4"
650  then
651         echo "CCE 8.1.4 produces incorrect Charm++ code"
652         echo "Please use a newer version of the CCE compiler"
653         echo "e.g. module load cce/8.1.7"
654         test_finish 1
655  fi
658 #echo "set C++ compiler as: $CMK_CXX $OPTS_CXX $OPTS"
659 AC_MSG_CHECKING("C++ compiler as")
660 AC_MSG_RESULT("$CMK_CXX $OPTS_CXX")
661 test_cxx "whether C++ compiler works" "ok" "no" ""
662 if test $fail -eq 1
663 then
664         echo "Cannot compile C++ programs with $CMK_CXX"
665         echo " (check your charm++ version)"
666         test_finish 1
669 cat > $t <<EOT
670 #include <stdio.h>
671 int main() {
672         printf("Hello, world!\n");
673         return 0;
676 #echo "set C++ linker as: $CMK_LDXX $OPTS_LD"
677 AC_MSG_CHECKING("C++ linker as")
678 AC_MSG_RESULT("$CMK_LDXX $OPTS_LD")
679 test_link "whether linker works" "ok" "no" ""
680 if test $fail -eq 1
681 then
682         echo "Cannot link C++ programs with $CMK_LDXX"
683         echo " (check your charm++ version)"
684         test_finish 1
687 AC_MSG_CHECKING("Native C++ compiler as")
688 AC_MSG_RESULT("$CMK_NATIVE_CXX")
689 AC_MSG_CHECKING("Sequential C++ compiler as")
690 AC_MSG_RESULT("$CMK_SEQ_CXX")
692 if echo "$CMK_CC" | grep -E "gcc|clang|icc" > /dev/null 2> /dev/null
693 then
694   test_link "whether compiler accept -fno-stack-protector" "ok" "no" "-fno-stack-protector"
695   if test $strictpass -eq 1
696   then
697         add_flag OPTS_CC='"$OPTS_CC -fno-stack-protector"' "stack-protection disabling"
698         add_flag OPTS_CXX='"$OPTS_CXX -fno-stack-protector"' "stack-protection disabling"
699   fi
702 #### check if C++ compiler will accept C++11 features without warning ####
703 cat > $t <<EOT
704 // Check for Intel compiler incompatibility with the active g++/libstdc++ by
705 // including an arbitrary standard library header (cf bug #1560)
706 #include <map>
708 // Check for an excessively old g++/libstdc++ that can't handle features we use
709 #include <memory>
710 #include <vector>
711 std::unique_ptr<int> i;
713 class CkMigrateMessage;
715 struct base {
716   base(void) { }
717   base(CkMigrateMessage *) { }
720 template <class Parent>
721 struct CBaseT1 : Parent {
722   std::vector<int> v; // check for C++11's shrink_to_fit()
724   CBaseT1(void) :Parent()  { v.shrink_to_fit(); }
725   CBaseT1(CkMigrateMessage *m) :Parent(m) { }
726   CBaseT1(CBaseT1&& rhs) :Parent() { }
728   template <typename... Args>
729     CBaseT1(Args... args) : Parent(args...) { }
732 template struct CBaseT1<base>;
734 got_cpp11=""
735 test_cxx "whether C++ compiler supports C++11 without flags" "yes" "no" ""
736 if test $strictpass -eq 1
737 then
738   got_cpp11="true"
739 else
740 # Flags for g++/clang++/icpc/xlC++, pgCC, and CrayCC respectively
741 for i in "-std=c++11" "--c++11" "-h std=c++11"; do
742     test_cxx "whether C++ compiler supports C++11 with '$i'" "yes" "no" "$i"
743     if test $strictpass -eq 1
744     then
745       add_flag "$(echo OPTS_CXX=\"\$OPTS_CXX $i\")" "Enable C++11 support"
746       OPTS_CXX="$OPTS_CXX $i"
747       got_cpp11="true"
748       break
749     fi
750 done
753 if test -z $got_cpp11
754 then
755   echo "Charm++ requires C++11 support, but doesn't know the flag to enable it"
756   echo
757   echo "For Intel's compiler please see"
758   echo "https://github.com/UIUC-PPL/charm/issues/1560"
759   echo "about making a suitable version of gcc/g++/libstdc++ available"
760   echo
761   echo "For Blue Gene/Q please use the Clang compiler"
762   test_finish 1
765 test_native_cxx "whether native C++ compiler supports C++11 without flags" "yes" "no" ""
766 if test $strictpass -ne 1
767 then
768   # Flags for g++/clang++/icpc/xlC++, pgCC, and CrayCC respectively
769   for i in "-std=c++11" "--c++11" "-h std=c++11"; do
770     test_native_cxx "whether C++ compiler supports C++11 with '$i'" "yes" "no" "$i"
771     if test $strictpass -eq 1
772     then
773       add_flag "$(echo CMK_NATIVE_CXX_FLAGS=\"\$CMK_NATIVE_CXX_FLAGS $i\")" "Enable C++11 support"
774       break
775     fi
776 done
779 # Workaround for bug #1045 appearing in GCC >6.x
780 test_cxx "whether C++ compiler accepts -fno-lifetime-dse" "yes" "no" "-fno-lifetime-dse"
781 if test $strictpass -eq 1
782 then
783     add_flag "$(echo OPTS_CXX=\"\$OPTS_CXX -fno-lifetime-dse\")" "Disable 'Lifetime DSE' optimization to work around bug #1045 in GCC >6.x"
784     OPTS_CXX="$OPTS_CXX -fno-lifetime-dse"
787 # Test for a flag tlsglobals sometimes depends on
788 test_cxx "whether C++ compiler accepts -mno-tls-direct-seg-refs" "yes" "no" "-mno-tls-direct-seg-refs"
789 if test $strictpass -eq 1
790 then
791     add_flag 'CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS="1"' "tlsglobals"
794 # Determine compiler/linker flags to build libcharm.so for charm4py
795 if test "$enable_charmpy" = "yes"
796 then
798   cat > $t <<EOT
799 int main() { return 0; }
802   test_cxx "whether C++ compiler accepts --no-as-needed" "yes" "no" "--no-as-needed"
803   if test $strictpass -eq 1
804   then
805       add_flag "$(echo CXX_NO_AS_NEEDED=\"--no-as-needed\")" "--no-as-needed flag necessary for compilers that default to linking with --as-needed"
806   fi
808   got_opt_whole_archive=""
809   # Flags for g++/clang++/icpc, Apple-LLVM respectively
810   for i in "-Wl,--whole-archive -Wl,--no-whole-archive" "-Wl,-all_load"; do
811       test_link "whether linker supports '$i'" "yes" "no" "" "$i"
812       if test $strictpass -eq 1
813       then
814         got_opt_whole_archive="true"
815         IFS=' ' read LDXX_WHOLE_ARCHIVE_PRE LDXX_WHOLE_ARCHIVE_POST <<< $i
816         add_flag "$(echo LDXX_WHOLE_ARCHIVE_PRE=\"$LDXX_WHOLE_ARCHIVE_PRE\")" "Flags to link whole archives into libcharm.so"
817         add_flag "$(echo LDXX_WHOLE_ARCHIVE_POST=\"$LDXX_WHOLE_ARCHIVE_POST\")" "Flags to link whole archives into libcharm.so"
818         break
819       fi
820   done
822   if test -z $got_opt_whole_archive
823   then
824     echo "Don't know how to build libcharm.so for Charm4py"
825     test_finish 1
826   fi
829 # Figure out if the user has asked to enable the latest language standards
830 USER_ASKED_FOR_NEW_STD=`echo "$BUILDOPTS" | grep "\-use-new-std" | wc -l`
832 # If the user has asked for the newer standards, check if the compilers know about them
833 if test $USER_ASKED_FOR_NEW_STD -ge 1
834 then
836 #### check if c compiler supports c11 compilation flags ####
837 cat > $tc <<EOT
838 #include <stdio.h>
840 int foo()
842   return 0;
845 test_cc "whether c compiler knows of the c11 standard" "ok" "no" "$CMK_ENABLE_C11"
846 AC_DEFINE_UNQUOTED(CMK_COMPILER_KNOWS_C11, $pass, [whether c compiler knows of the c11 standard] )
847 if test $pass -eq 1
848 then
849         # Record results for charmc's future use
850         add_flag 'CMK_COMPILER_KNOWS_C11="1"' "c11"
851         # For the rest of configure, append this to compilation flags
852         OPTS_CC="$CMK_ENABLE_C11 $OPTS_CC"
854 fi # endif USER_ASKED_FOR_NEW_STD
856 # Perform the tests
858 AC_ARG_WITH([refnum-type],
859             [AS_HELP_STRING([--with-refnum-type=type],
860                             [size of the envelope refnum field])],
861             [], [with_refnum_type=no])
863 if test "$with_refnum_type" = "no" -o "$with_refnum_type" = "short"
864 then
865   Echo "Setting charm++ envelope refnum field to unsigned short"
866   AC_DEFINE_UNQUOTED(CMK_REFNUM_TYPE, unsigned short, [envelope refnum field set to UShort])
867 elif test "$with_refnum_type" = "int"
868 then
869   Echo "Setting charm++ envelope refnum field to unsigned int"
870   AC_DEFINE_UNQUOTED(CMK_REFNUM_TYPE, unsigned int, [envelope refnum field set to UInt])
871 else
872   Echo "Invalid size specified for refnum field"
873   test_finish 1
877 AC_ARG_WITH([prio-type],
878             [AS_HELP_STRING([--with-prio-type=type],
879                             [size of expected message priorities])],
880             [], [with_prio_type=bitvec])
882 if test "$with_prio_type" = "char" -o "$with_prio_type" = "short" -o "$with_prio_type" = "int" -o "$with_prio_type" = "long" -o "$with_prio_type" = "float" -o "$with_prio_type" = "double"
883 then
884   Echo "Configuring support for message priorities of sizeof type $with_prio_type"
885   AC_DEFINE_UNQUOTED(CMK_USE_STL_MSGQ, 1, [whether charm scheduler should use an STL-based msg q])
886   AC_DEFINE_UNQUOTED(CMK_MSG_PRIO_TYPE, $with_prio_type, [expected message priorities are sizeof $with_prio_type])
887 elif test "$with_prio_type" = "bitvec"
888 then
889   Echo "Configuring support for message priorities of arbitrary size (bitvectors)"
890   AC_DEFINE_UNQUOTED(CMK_USE_STL_MSGQ, 0, [whether charm scheduler should use an STL-based msg q])
891   AC_DEFINE_UNQUOTED(CMK_MSG_PRIO_TYPE, $with_prio_type, [expected message priorities are arbitrarily sized])
892 else
893   Echo "Invalid size ($with_prio_type) specified for message priorities. Can only accept char, short, int, long, float, double and bitvec"
894   test_finish 1
897 # enable/disable randomized scheduler queue
898 AC_ARG_ENABLE([randomized-msgq],
899             [AS_HELP_STRING([--enable-randomized-msgq],
900               [enable a randomized msg queue (for debugging etc)])], ,
901             [enable_randomized_msgq=no])
903 if test "$enable_randomized_msgq" = "yes" -a "$with_prio_type" != "bitvec"
904 then
905   Echo "The charm message queue will be randomized (and will not respect priorities)"
906   AC_DEFINE_UNQUOTED(CMK_RANDOMIZED_MSGQ, 1, [enable the randomized msgq in the scheduler])
907 else
908   AC_DEFINE_UNQUOTED(CMK_RANDOMIZED_MSGQ, 0, [disable the randomized msgq in the scheduler])
909   if test "$enable_randomized_msgq" = "yes"
910   then
911     Echo 'A randomized message queue is only available when --with-prio-type != bitvec.'
912     Echo "Specify prio-type to be a data type long enough to hold the message priorities in your application"
913     Echo "for example: --with-prio-type=int (or short / long etc)."
914     test_finish 1
915   fi
918 AC_ARG_WITH([mempool-cutoff],
919             [AS_HELP_STRING([--with-mempool-cutoff=N],
920                             [exponent of the maximum power of two to use for bin sizes in the mempool])],
921             [], [with_mempool_cutoff=26])
923 if test "$((6 < $with_mempool_cutoff && $with_mempool_cutoff < 32))" = '1'
924 then
925   Echo "Using mempool cutoff... 2^$with_mempool_cutoff"
926   AC_DEFINE_UNQUOTED(CMK_MEMPOOL_CUTOFFNUM, $((with_mempool_cutoff - 6)), [mempool cutoff])
927 else
928   Echo "Invalid number ($with_mempool_cutoff) specified for mempool cutoff. Valid range: 7 <= N <= 31"
929   test_finish 1
932 # enable mpich tests
933 AC_ARG_ENABLE([ampi-mpich-tests],
934             [AS_HELP_STRING([--enable-ampi-mpich-tests],
935             [enable mpich tests for ampi])],
936             [enable_ampi_mpich_tests=yes],
937             [enable_ampi_mpich_tests=no])
939 if test "$enable_ampi_mpich_tests" = "yes"
940 then
941   AC_DEFINE([AMPI_ERRHANDLER_RETURN], [1], [enable ampi fatal error return])
942   add_make_flag "BUILD_MPICH_TESTS:=true" 'mpich tests setup'
943 else
944   AC_DEFINE([AMPI_ERRHANDLER_RETURN], [0], [disable ampi fatal error return])
947 #### Check if compiler is 64 bit ####
948 cat > $t <<EOT
949 #include <stdio.h>
951 int foo()
953 int x[[(int)(sizeof(void *) - 7)]]={0};
954 return x[[0]];
957 test_cxx "whether compiler generates code for 64-bit" "yes" "no" ""
958 AC_DEFINE_UNQUOTED(CMK_SIZET_64BIT, $strictpass, [whether size_t 64bit])
959 in64bit=$strictpass
961 ### Check if compiler supports std::is_constructible<> ###
962 cat > $t <<EOT
963 #include <type_traits>
965 struct s {
966        s(int a) { }
969 bool foo()
971   return std::is_constructible<s, int>::value;
974 test_cxx "whether compiler supports std::is_constructible" "yes" "no" ""
975 AC_DEFINE_UNQUOTED(CMK_HAS_IS_CONSTRUCTIBLE, $strictpass, [whether compiler supports std::is_constructible])
977 ### Check if compiler supports std::alignment_of<> ###
978 cat > $t <<EOT
979 #include <type_traits>
981 int foo()
983   return std::alignment_of<int>::value;
986 test_cxx "whether compiler supports std::alignment_of" "yes" "no" ""
987 AC_DEFINE_UNQUOTED(CMK_HAS_ALIGNMENT_OF, $strictpass, [whether compiler supports std::alignment_of])
989 ### Check if compiler implements regex ###
990 cat > $t <<EOT
991 #include <regex>
992 void foo()
994 #if __cplusplus >= 201103L &&                             \
995     (!defined(__GLIBCXX__) || (__cplusplus >= 201402L) || \
996         (defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \
997          defined(_GLIBCXX_REGEX_STATE_LIMIT)           || \
998              (defined(_GLIBCXX_RELEASE)                && \
999              _GLIBCXX_RELEASE > 4)))
1000 // compiler has regex support, continue
1001 #else
1002 // force compilation to fail
1003 static_assert(false, "compiler has no regex implementation");
1004 #endif
1007 test_cxx "whether compiler implements regex" "yes" "no" ""
1008 AC_DEFINE_UNQUOTED(CMK_HAS_REGEX, $pass, [whether compiler implements regex])
1010 #### test if has values.h ####
1011 cat > $t <<EOT
1012 #include <values.h>
1013 int main() { 
1014   double d = MAXDOUBLE;
1015   return 0;
1018 test_cxx "whether has values.h " "yes" "no" ""
1019 AC_DEFINE_UNQUOTED(CMK_HAS_VALUES_H, $pass, [whether has values.h])
1021 #### test if has stdint.h ####
1022 cat > $t <<EOT
1023 #include <stdint.h>
1024 int main() { 
1025   return 0;
1028 test_cxx "whether has stdint.h " "yes" "no" ""
1029 AC_DEFINE_UNQUOTED(CMK_HAS_STDINT_H, $pass, [whether has stdint.h])
1031 #### test if has malloc.h ####
1032 cat > $t <<EOT
1033 #include <malloc.h>
1034 int main() { 
1035   return 0;
1038 test_cxx "whether has malloc.h " "yes" "no" ""
1039 AC_DEFINE_UNQUOTED(CMK_HAS_MALLOC_H, $pass, [whether has malloc.h])
1041 #### test if has alloca.h ####
1042 cat > $t <<EOT
1043 #include <alloca.h>
1044 int main() {
1045   double *s=(double *)alloca(sizeof(double));
1046   *s=1.0;
1047   return 0;
1050 test_cxx "whether has alloca.h " "yes" "no" ""
1051 AC_DEFINE_UNQUOTED(CMK_HAS_ALLOCA_H, $pass, [whether has alloca.h])
1053 #### test if has regex.h ####
1054 cat > $t <<EOT
1055 #include <regex.h>
1056 int main() {
1057   regex_t re;
1058   regcomp(&re, ".*MOD.*", REG_EXTENDED|REG_NOSUB);
1059   return 0;
1062 test_cxx "whether has regex.h " "yes" "no" ""
1063 AC_DEFINE_UNQUOTED(CMK_HAS_REGEX_H, $pass, [whether has regex.h])
1065 #### Check long long ####
1066 cat > $t <<EOT
1067 #include <stdlib.h>
1068 long long foo(void) { return 17; }
1070 test_cxx "whether long long works" "yes" "no" ""
1071 AC_DEFINE_UNQUOTED(CMK_LONG_LONG_DEFINED, $pass, [whether long long works])
1073 #### Check __int64 ####
1074 cat > $t <<EOT
1075 #include <stdlib.h>
1076 __int64 foo(void) { return 17; }
1078 test_cxx "whether __int64 works" "yes" "no" ""
1079 AC_DEFINE_UNQUOTED([CMK___int64_DEFINED], $pass, [whether __int64 works])
1082 CMK_HAS_INT16=0
1084 #### Check __int128 ####
1085 cat > $t <<EOT
1086 #include <stdlib.h>
1087 int foo(void) {
1088   __int128   a;
1089   int x[[(int)(sizeof(__int128) - 15)]]={0};
1090   return x[[0]];
1093 test_cxx "whether __int128 (128-bit integer) works" "yes" "no" ""
1094 AC_DEFINE_UNQUOTED([CMK___int128_DEFINED], $pass, [whether __int128 works])
1095 if test $pass -eq 1
1096 then
1097   CMK_HAS_INT16=1
1098   add_flag CMK_HAS_INT16=1
1101 #### Check __int128_t ####
1102 cat > $t <<EOT
1103 #include <stdlib.h>
1104 int foo(void) {
1105   __int128_t   a;
1106   __uint128_t   b;
1107   a = a + a;
1108   int x[[(int)(sizeof(__int128_t) - 15)]]={0};
1109   return x[[0]];
1112 test_cxx "whether __int128_t (128-bit integer) works" "yes" "no" ""
1113 AC_DEFINE_UNQUOTED([CMK___int128_t_DEFINED], $pass, [whether __int128_t works])
1114 if test $pass -eq 1
1115 then
1116   CMK_HAS_INT16=1
1117   add_flag CMK_HAS_INT16=1
1120 #### Summarize *int128* ####
1122 AC_DEFINE_UNQUOTED([CMK_HAS_INT16], $CMK_HAS_INT16, [whether any 128-bit integer works])
1125 ### Check if we have C++11 <atomic> ###
1126 cat > $t <<EOT
1127 #include <atomic>
1128 int main(int argc, char** argv) { 
1129   return 0;
1132 test_cxx "whether C++ library has <atomic> " "yes" "no" ""
1133 AC_DEFINE_UNQUOTED(CMK_HAS_CXX11_ATOMIC, $pass, [whether C++ library has <atomic>])
1135 if test $pass -ne 1
1136 then
1137 ### Check if we have pre-C++11 <cstdatomic> ###
1138 cat > $t <<EOT
1139 #include <cstdatomic>
1140 int main(int argc, char** argv) { 
1141   return 0;
1144 test_cxx "whether C++ library has <cstdatomic> " "yes" "no" ""
1145 AC_DEFINE_UNQUOTED(CMK_HAS_CXX0X_CSTDATOMIC, $pass, [whether C++ library has <cstdatomic>])
1148 if test $pass -ne 1 -a "$CMK_COMPILER" != "bgxlc"
1149 then
1150         echo "Charm++ requires C++11 atomic support"
1151         test_finish 1
1154 #### Check long double ####
1155 cat > $t <<EOT
1156 #include <stdlib.h>
1157 long double foo(void) { return 17.0; }
1159 test_cxx "whether long double works" "yes" "no" ""
1160 AC_DEFINE_UNQUOTED(CMK_LONG_DOUBLE_DEFINED, $strictpass, [whether long double works])
1162 #### Check ucontext and FPU pointer ####
1163 cat > $t <<EOT
1164 #include <ucontext.h>
1165 struct _libc_fpstate   fpstate;
1166 fpregset_t *fp;
1167 int main() {
1168   ucontext_t context;
1169   context.uc_mcontext.fpregs = 0;
1172 test_cxx "whether ucontext has FPU pointer" "yes" "no" ""
1173 AC_DEFINE_UNQUOTED(CMK_CONTEXT_FPU_POINTER, $pass, [whether ucontext has pointer])
1175 if test $pass -eq 1
1176 then
1177 cat > $t <<EOT
1178 #include <ucontext.h>
1180 int main()
1182   ucontext_t context;
1183   context.uc_mcontext.uc_regs = 0;
1186 test_cxx "whether ucontext uses uc_regs" "yes" "no" ""
1187 AC_DEFINE_UNQUOTED(CMK_CONTEXT_FPU_POINTER_UCREGS, $pass, [whether ucontext uses uc_regs union])
1190 cat > $t <<EOT
1191 #include <ucontext.h>
1192 vrregset_t *v_regs;
1193 ucontext_t  uc;
1195 void foo()
1197   vrregset_t *ptr = uc.uc_mcontext.v_regs;
1200 test_cxx "whether ucontext has pointer (v_regs) of vector type" "yes" "no" ""
1201 AC_DEFINE_UNQUOTED(CMK_CONTEXT_V_REGS, $pass, [whether ucontext has pointer (v_regs) of vector type])
1203 #### Check ucontext and FPU pointer ####
1204 cat > $t <<EOT
1205 #include <infiniband/verbs.h>
1206 void test()
1208     struct ibv_context    *context;
1209     int ibPort;
1210     struct ibv_port_attr attr;
1211     if (ibv_query_port(context, ibPort, &attr) != 0) return;
1212     if (attr.link_layer == IBV_LINK_LAYER_INFINIBAND)  return;
1215 test_cxx "whether ibverbs ibv_port_attr has link_layer field" "yes" "no" ""
1216 AC_DEFINE_UNQUOTED(CMK_IBV_PORT_ATTR_HAS_LINK_LAYER, $pass, [whether ibv_port_attr has link_layer field])
1219 ###################### C++ Compiler Features #####################
1221 #### check C inline ####
1222 cat > $tc <<EOT
1223 inline static int foo()
1225   return 1;
1228 test_cc "whether inline works in C" "yes" "no" ""
1229 AC_DEFINE_UNQUOTED(CMK_C_INLINE, $strictpass, [whether C inline works in C])
1231 #### check if signed char is same as char ####
1232 cat > $t <<EOT
1233 #include <stdlib.h>
1234 class er {
1235  protected:
1236    void operator()(char &v,const char *desc=NULL) {};
1237    void operator()(signed char &v,const char *desc=NULL) {};
1240 test_cxx "whether C++ signed char and char differ" "yes" "no" ""
1241 AC_DEFINE_UNQUOTED(CMK_SIGNEDCHAR_DIFF_CHAR, $pass, [whether C++ signed char and char differ])
1243 #### check if typeinfo exists and works #####
1244 cat > $t <<EOT
1245 #include <typeinfo>
1246 const char *foo(void) {
1247         int x;
1248         return typeid(x).name();
1251 test_cxx "whether typeinfo/typeid works" "ok" "no" ""
1252 AC_DEFINE_UNQUOTED(CMK_HAS_TYPEINFO, $pass, [whether typeinfo/typeid works])
1254 #### check if iterator_traits is defined #####
1255 cat > $t <<EOT
1256 #include <iterator>
1258 template <typename T> // T models Input Iterator
1259 typename std::iterator_traits<T>::value_type accumulate(T first, T last)
1261       typename std::iterator_traits<T>::value_type result = 0;
1262       while(first != last)
1263             result += *first++;
1264       return result;
1267 test_cxx "whether std::iterator_traits is defined" "ok" "no" ""
1268 AC_DEFINE_UNQUOTED(CMK_HAS_ITERATOR_TRAITS, $pass, [whether iterator_traits works])
1270 #### check if std::distance is defined #####
1271 cat > $t <<EOT
1272 #include <vector>
1273 #include <iterator>
1275 int foo()
1277   std::vector<int> tree;
1278   return std::distance(tree.begin(), tree.end());
1281 test_cxx "whether std::distance is defined" "ok" "no" ""
1282 AC_DEFINE_UNQUOTED(CMK_HAS_STD_DISTANCE, $pass, [whether std::distance works])
1284 #### check if std::inserter is defined #####
1285 cat > $t <<EOT
1286 #include <list>
1287 #include <iterator>
1289 void foo()
1291   using namespace std;
1292   list<int> L;
1293   inserter ( L, L.end ( ) ) = 500;
1296 test_cxx "whether std::inserter is defined" "ok" "no" ""
1297 AC_DEFINE_UNQUOTED(CMK_HAS_STD_INSERTER, $pass, [whether std::inserter works])
1299 #### check if C++17's std::void_t is defined #####
1300 cat > $t <<EOT
1301 #include <type_traits>
1303 template<typename T, typename = std::void_t<>>
1304 struct has_pup_member : std::false_type {};
1307 test_cxx "whether std::void_t is defined" "ok" "no" ""
1308 AC_DEFINE_UNQUOTED(CMK_HAS_STD_VOID_T, $pass, [whether std::void_t works])
1310 ####### Check support for features added by the new C11 and CPP11 standards ########
1312 #### test if we can have multiple delete like this ####
1313 cat > $t <<EOT
1314 class foo {
1315 public:
1316   void operator delete(void*p){};
1317   void operator delete(void*p,int*){};
1320 test_cxx "whether operator delete can be overloaded in same class" "ok" "no" ""
1321 AC_DEFINE_UNQUOTED(CMK_MULTIPLE_DELETE, $strictpass, [whether operator delete can be overloaded in same class])
1323 #### test if offsetof exists ####
1324 cat > $t <<EOT
1325 #include <stddef.h>
1327 struct FooType {
1328         int f1;
1329         int f2;
1330         double f3;
1333 void foo()
1335   int off = offsetof(FooType, f2);
1338 test_cxx "whether offsetof is defined" "yes" "no" ""
1339 AC_DEFINE_UNQUOTED(CMK_HAS_OFFSETOF, $pass, [whether offsetof exists])
1341 #### test if we can use gcc x86 assembly like this ####
1342 cat > $t <<EOT
1343 double foo(void)
1345   unsigned long long int v=0;
1346   int *lo=0+(int *)&v;
1347   int *hi=1+(int *)&v;
1348   __asm__ __volatile__(
1349       "rdtsc; movl %%edx,%0; movl %%eax,%1"
1350       : /* output  */ "=m" (*hi), "=m" (*lo)
1351       : /* input */
1352       : /* trashes */ "%edx", "%eax"
1353   );
1354   return v;
1357 test_cxx "whether GCC x86 assembly works" "yes" "no" ""
1358 AC_DEFINE_UNQUOTED(CMK_GCC_X86_ASM, $strictpass, [Allows gcc x86 assembly.])
1360 #### test if we can use gcc x86 assembly like this ####
1361 if test $strictpass = 1
1362 then
1363 cat > $t <<EOT
1364 int foo(void)
1366   int x;
1367   asm("lock incl %0" :: "m" (x));
1368   asm("lock decl %0" :: "m" (x));
1369   return x;
1372 test_cxx "whether GCC x86 assembly for atomic increment works" "yes" "no" ""
1373 AC_DEFINE_UNQUOTED(CMK_GCC_X86_ASM_ATOMICINCREMENT, $strictpass, [Allows gcc x86 assembly for atomic increment.])
1376 #### test if we can use asm eieio assembly like this ####
1377 cat > $t <<EOT
1378 double foo(void)
1380         unsigned long long int x;
1381         asm volatile("eieio" ::: "memory");
1382         return x;
1385 test_cxx "whether asm eieio assembly works" "yes" "no" ""
1386 AC_DEFINE_UNQUOTED(CMK_PPC_ASM, $strictpass, [Allows asm eieio assembly.])
1390 #### test if we can use __thread ####
1391 cat > $t <<EOT
1392 __thread unsigned long long int x;
1393 static __thread  int y;
1394 void foo(void)
1396         x = 1;
1397         y = 1;
1400 test_cxx "whether __thread (Thread Local Storage) is supported" "yes" "no" ""
1401 AC_DEFINE_UNQUOTED(CMK_HAS_TLS_VARIABLES, $strictpass, [Allows __thread.])
1403 #### check __sync_add_and_fetch ####
1404 cat > $tc <<EOT
1405 #include <stdio.h>
1406 int main()
1408   int t=1;
1409   __sync_add_and_fetch(&t, 1);
1410   return 1;
1413 test_linkc "whether synchronization primitives (__sync_add_and_fetch) works in C" "yes" "no" ""
1414 AC_DEFINE_UNQUOTED(CMK_C_SYNC_ADD_AND_FETCH_PRIMITIVE, $pass, [whether sync_add_and_fetch primitive works in C])
1416 #### check __sync_synchronize ####
1417 cat > $tc <<EOT
1418 #include <stdio.h>
1419 int main()
1421   __sync_synchronize();
1425 test_linkc "whether synchronization primitives (__sync_synchronize) works in C" "yes" "no" ""
1427 AC_DEFINE_UNQUOTED(CMK_C_SYNC_SYNCHRONIZE_PRIMITIVE, $pass, [whether sync_synchronize primitives works in C])
1430 ### test for __executable_start ###
1432 cat > $tc <<EOT
1433 extern int __executable_start;
1434 int main()
1436   return __executable_start;
1439 test_linkc "whether has __executable_start" "yes" "no" ""
1440 AC_DEFINE_UNQUOTED([CMK_HAS_EXECUTABLE_START], $pass, [whether has __executable_start])
1442 ### test if switching TLS register ###
1443 if test $in64bit = 1
1444 then
1445 cat > $t <<EOT
1446 void switchTLS() {
1447   void * m1, * m2;
1448   asm volatile ("movq %%fs:0x0, %0\n\t"
1449                 "movq %1, %%fs:0x0\n\t"
1450                 : "=&r"(m1)
1451                 : "r"(m2));
1454 test_cxx "whether switching TLS register (64-bit) is supported" "yes" "no" ""
1455 AC_DEFINE_UNQUOTED(CMK_TLS_SWITCHING_X86_64, $strictpass, [Allows switching TLS on x86_64.])
1456 else
1457 cat > $t <<EOT
1458 void switchTLS() {
1459   void * m1, * m2;
1460   asm volatile ("movl %%gs:0x0, %0\n\t"
1461                 "movl %1, %%gs:0x0\n\t"
1462                 : "=&r"(m1)
1463                 : "r"(m2));
1466 test_cxx "whether switching TLS register (32-bit) is supported" "yes" "no" ""
1467 AC_DEFINE_UNQUOTED(CMK_TLS_SWITCHING_X86, $strictpass, [Allows switching TLS on x86.])
1470 ### test for dl_iterate_phdr ###
1472 cat > $tc <<EOT
1473 #ifndef _GNU_SOURCE
1474 # define _GNU_SOURCE
1475 #endif
1476 #ifndef __USE_GNU
1477 # define __USE_GNU
1478 #endif
1479 #include <link.h>
1480 #include <stddef.h>
1481 static int callback(struct dl_phdr_info* info, size_t size, void* data)
1483   return 0;
1485 int main()
1487   dl_iterate_phdr(callback, NULL);
1488   return 0;
1491 test_linkc "whether has dl_iterate_phdr" "yes" "no" ""
1492 AC_DEFINE_UNQUOTED([CMK_HAS_DL_ITERATE_PHDR], $pass, [whether has dl_iterate_phdr])
1495 ### test for __malloc_hook ###
1497 cat > $tc <<EOT
1498 extern int __malloc_hook;
1499 int main()
1501   return __malloc_hook;
1504 test_linkc "whether has __malloc_hook" "yes" "no" ""
1505 AC_DEFINE_UNQUOTED([CMK_HAS_MALLOC_HOOK], $pass, [whether has __malloc_hook])
1506 add_make_flag "CMK_HAS_MALLOC_HOOK:=$pass" 'whether has __malloc_hook'
1509 #### test if we can build OFI ####
1510 if test "$CMK_BUILD_OFI" = 1
1511 then
1512 cat > $tc <<EOT
1513 #include <rdma/fabric.h>
1514 int main(int argc, char **argv)
1516   struct fi_info *providers;
1517   int ret = fi_getinfo(FI_VERSION(1,0), NULL, NULL, 0ULL, NULL, &providers);
1518   return 0;
1521 test_cc "whether build on OFI" "yes" "no" "-lfabric"
1522 AC_DEFINE_UNQUOTED(CMK_BUILD_ON_OFI, $strictpass, [build OFI.])
1523 BUILD_OFI=$strictpass
1525 if test $BUILD_OFI -eq 0
1526 then
1527   echo "Error: Unable to compile OFI"
1528   test_finish 1
1529 else
1530   test_linkc "whether -lfabric" "ok" "no" "-lfabric"
1531   if test $pass -eq 0
1532   then
1533     #test for psm incompatibility
1534     PSM_COMPAT_DIR=/usr/lib64/psm2-compat
1535     if test -d $PSM_COMPAT_DIR
1536     then
1537       add_flag CMK_LIBDIR='"$CMK_LIBDIR -Wl,-rpath=/usr/lib64/psm2-compat"' "psm2-compat lib"
1538       CMK_LIBDIR="$CMK_LIBDIR -Wl,-rpath=/usr/lib64/psm2-compat"
1539       test_linkc "whether -lfabric after adding psm2-compatible library" "ok" "no" "-lfabric"
1540       if test $pass -eq 0
1541       then
1542         echo "Error: -lfabric not found or not working. Pass '--basedir=/path/to/dir/' if -lfabric is located in a different directory"
1543         test_finish 1
1544       fi
1545     else
1546       echo "Error: -lfabric not working, $PSM_COMPAT_DIR not found"
1547       echo "Pass '--basedir=/path/to/dir/' if -lfabric is located in a different directory"
1548       test_finish 1
1549     fi
1550   fi
1555 #### test if we can build MPI ####
1556 if test "$CMK_BUILD_MPI" = 1
1557 then
1559 cat > $tc <<EOT
1560 #include "mpi.h"
1561 int main(int argc, char **argv)
1563   MPI_Init(&argc, &argv);
1564   return 0;
1567 mv -f ../include/mpi.h ../include/mpi.h.bak 2>/dev/null
1568 test_cc "whether build on MPI" "yes" "no" ""
1569 AC_DEFINE_UNQUOTED(CMK_BUILD_ON_MPI, $strictpass, [build MPI.])
1570 BUILD_MPI=$strictpass
1572 if test $BUILD_MPI -eq 0
1573 then
1574   echo "Error: Cannot compile an MPI program"
1575   test_finish 1
1578 if test $BUILD_MPI -eq 1
1579 then
1580   test_linkc "whether need to specify MPI library" "no" "yes" ""
1581   if test $pass -ne 1
1582   then
1583     if test -z "$CMK_MPI_LIB"
1584     then
1585       test_linkc "whether -lmpich" "ok" "no" "-lmpich"
1586       if test $pass -eq 1
1587       then
1588         add_flag CMK_SYSLIBS='"$CMK_SYSLIBS -lmpich"' "mpi lib"
1589       else
1590         test_linkc "whether -lmpi" "ok" "no" "-lmpi"
1591         if test $pass -eq 1
1592         then
1593                 add_flag CMK_SYSLIBS='"$CMK_SYSLIBS -lmpi"' "mpi lib"
1594         else
1595                 echo "Error: Cannot find MPI library"
1596                 test_finish 1
1597         fi
1598       fi
1599     else
1600       add_flag CMK_SYSLIBS='"$CMK_SYSLIBS $CMK_MPI_LIB"' "mpi lib"
1601     fi
1602   fi
1605 if test "$BUILD_MPI" = "1"
1606 then
1607 cat > $t <<EOT
1608 #include "mpi.h"
1609 int main(int argc, char **argv)
1611   int thread_level, provided;
1612   thread_level = MPI_THREAD_FUNNELED;
1613   MPI_Init_thread(&argc, &argv, thread_level, &provided);
1616 test_cxx "whether MPI_Init_thread is supported" "yes" "no" ""
1617 AC_DEFINE_UNQUOTED(CMK_MPI_INIT_THREAD, $strictpass, [Allows MPI_Init_thread.])
1619 mv -f ../include/mpi.h.bak ../include/mpi.h 2>/dev/null
1623 if test "$BUILD_MPI" = "1"
1624 then
1626 cat > $t <<EOT
1627 #include <stdio.h>
1628 #include <mpi.h>
1630 int main (int argc, char** argv) {
1631   return 0;
1634 test_cxx "whether macro conflicts occurs due to C++ MPI bindings" "no" "yes" ""
1635 AC_DEFINE_UNQUOTED(CMK_CXX_MPI_BINDINGS, $strictpass, [Disables conflicting macros.])
1639 ################### Syscalls and Libraries ###################
1641 #### test for getrusage with RUSAGE_THREAD ###
1642 cat > $tc <<EOT
1643 #ifndef _GNU_SOURCE
1644 # define _GNU_SOURCE
1645 #endif
1646 #ifndef __USE_GNU
1647 # define __USE_GNU
1648 #endif
1649 #include <sys/time.h>
1650 #include <sys/resource.h>
1651 int main() {
1652   struct rusage usage;
1653   getrusage(RUSAGE_THREAD, &usage);
1654   return 0;
1657 test_linkc "whether getrusage accepts RUSAGE_THREAD" "yes" "no" ""
1658 AC_DEFINE_UNQUOTED(CMK_HAS_RUSAGE_THREAD, $pass, [whether getrusage accepts RUSAGE_THREAD])
1660 #### test for asctime ###
1662 cat > $tc <<EOT
1663 #include <time.h>
1664 int main() {
1665   struct tm *local;
1666   time_t t;
1667   t = time(NULL);
1668   local = localtime(&t);
1669   asctime(local);
1670   return 0;
1673 test_linkc "whether has asctime" "yes" "no" ""
1674 AC_DEFINE_UNQUOTED(CMK_HAS_ASCTIME, $pass, [whether has asctime])
1676 #### test for log2 ###
1677 cat > $t <<EOT
1678 #include <math.h>
1679 int main() {
1680   int i = log2(10);
1681   return 0;
1684 test_link "whether has log2" "yes" "no" ""
1685 AC_DEFINE_UNQUOTED(CMK_HAS_LOG2, $pass, [whether has log2])
1687 #### test for sqrtf ###
1688 cat > $t <<EOT
1689 #include <math.h>
1690 int main() {
1691   float i = sqrtf((float)10.0);
1692   return 0;
1695 test_link "whether has sqrtf" "yes" "no" ""
1696 AC_DEFINE_UNQUOTED(CMK_HAS_SQRTF, $pass, [whether has sqrtf])
1698 #### test for fabsf ###
1699 cat > $t <<EOT
1700 #include <math.h>
1701 int main() {
1702   float i = fabsf((float)10.0);
1703   return 0;
1706 test_link "whether has fabsf" "yes" "no" ""
1707 AC_DEFINE_UNQUOTED(CMK_HAS_FABSF, $pass, [whether has fabsf])
1709 #### test for mkstemp ###
1710 cat > $t <<EOT
1711 #include <stdlib.h>
1712 #include <string.h>
1713 int main() {
1714   char fname[[128]];
1715   strcpy(fname, "/tmp/fdXXX.XXX");
1716   mkstemp(fname);
1717   return 0;
1720 test_link "whether has mkstemp" "yes" "no" ""
1721 AC_DEFINE_UNQUOTED(CMK_USE_MKSTEMP, $pass, [whether has mkstemp])
1723 #### test for system ###
1724 cat > $t <<EOT
1725 #include <stdlib.h>
1726 int main() {
1727   system("/bin/ls");
1728   return 0;
1731 test_link "whether has system" "yes" "no" ""
1732 AC_DEFINE_UNQUOTED(CMK_HAS_SYSTEM, $pass, [whether has system])
1734 #### test for sync() ###
1735 cat > $t <<EOT
1736 #include <unistd.h>
1737 int main() {
1738   sync();
1739   return 0;
1742 test_link "whether has sync()" "yes" "no" ""
1743 AC_DEFINE_UNQUOTED(CMK_HAS_SYNC_FUNC, $pass, [whether has sync])
1745 #### test for fsync() ###
1746 cat > $t <<EOT
1747 #include <unistd.h>
1748 int main() {
1749   fsync(0);
1750   return 0;
1753 test_link "whether has fsync()" "yes" "no" ""
1754 AC_DEFINE_UNQUOTED(CMK_HAS_FSYNC_FUNC, $pass, [whether has fsync])
1756 #### test for fdatasync() ###
1757 cat > $t <<EOT
1758 #include <unistd.h>
1759 int main() {
1760   fdatasync(0);
1761   return 0;
1764 test_link "whether has fdatasync()" "yes" "no" ""
1765 AC_DEFINE_UNQUOTED(CMK_HAS_FDATASYNC_FUNC, $pass, [whether has fdatasync])
1767 #### test for sbrk ###
1768 cat > $t <<EOT
1769 #include <unistd.h>
1770 int main() {
1771   void *ptr  = sbrk(0); 
1774 test_link "whether has sbrk" "yes" "no" ""
1775 AC_DEFINE_UNQUOTED(CMK_HAS_SBRK, $pass, [whether has sbrk])
1777 #### test for _setjmp/_longjmp ###
1778 cat > $t <<EOT
1779 #include <setjmp.h>
1780 int main() {
1781   jmp_buf buf;
1782   _setjmp(buf);
1783   _longjmp(buf, 0);
1786 test_link "whether has _setjmp/_longjmp" "yes" "no" ""
1787 AC_DEFINE_UNQUOTED(CMK_HAS_UNDERSCORE_SETJMP, $pass, [whether has _setjmp/_longjmp])
1789 #### test for mstats ###
1790 cat > $t <<EOT
1791 #include <malloc.h>
1792 int main() {
1793   struct mstats ms = mstats();
1796 test_link "whether has mstats" "yes" "no" ""
1797 AC_DEFINE_UNQUOTED(CMK_HAS_MSTATS, $pass, [whether has mstats])
1799 #### test for mallinfo ###
1800 cat > $t <<EOT
1801 #include <malloc.h>
1802 int main() {
1803   struct mallinfo mi = mallinfo();
1806 test_link "whether has mallinfo" "yes" "no" ""
1807 AC_DEFINE_UNQUOTED(CMK_HAS_MALLINFO, $pass, [whether has mallinfo])
1809 #### test for __morecore ###
1810 cat > $t <<EOT
1811 #include <cstddef>
1812 int main() {
1813   extern void *(*__morecore)(ptrdiff_t);
1814   __morecore(0);
1815   return 0;
1818 test_link "whether expects __morecore symbol" "yes" "no" ""
1819 AC_DEFINE_UNQUOTED(CMK_EXPECTS_MORECORE, $pass, [whether expects __morecore symbol])
1821 #### test for popen ###
1822 cat > $t <<EOT
1823 #include <stdio.h>
1824 int main() {
1825   FILE *p = popen("/bin/ps", "r");
1826   pclose(p);
1829 test_link "whether has popen" "yes" "no" ""
1830 AC_DEFINE_UNQUOTED(CMK_HAS_POPEN, $pass, [whether has popen])
1832 #### test for poll ###
1833 cat > $t <<EOT
1834 #include <poll.h>
1835 void foo(void) { 
1836   struct pollfd pos[[3]];
1837   poll(pos, 1, 1);
1840 test_cxx "whether has poll" "yes" "no" ""
1841 AC_DEFINE_UNQUOTED(CMK_USE_POLL, $pass, [whether the poll syscall exists])
1843 #### check if getpagesize exists ####
1844 cat > $tc <<EOT
1845 #include <unistd.h>
1847 int main(int argc, char **argv) {
1848     int s = getpagesize();
1851 test_linkc "whether has getpagesize" "yes" "no" ""
1852 AC_DEFINE_UNQUOTED(CMK_HAS_GETPAGESIZE, $pass, [whether getpagesize exists])
1854 #### check if getpid exists ####
1855 cat > $tc <<EOT
1856 #include <sys/types.h>
1857 #include <unistd.h>
1859 int main(int argc, char **argv) {
1860     pid_t pid = getpid();
1863 test_linkc "whether has getpid" "yes" "no" ""
1864 AC_DEFINE_UNQUOTED(CMK_HAS_GETPID, $pass, [whether getpid exists])
1866 #### check if kill exists ####
1867 cat > $tc <<EOT
1868 #include <sys/types.h>
1869 #include <unistd.h>
1870 #include <signal.h>
1872 int main(int argc, char**argv) 
1874     pid_t pid = getpid();
1875     kill(pid, 9);
1878 test_linkc "whether has kill" "yes" "no" ""
1879 AC_DEFINE_UNQUOTED(CMK_HAS_KILL, $pass, [whether kill exists])
1881 #### test for setpriority ###
1882 cat > $t <<EOT
1883 #include <sys/time.h>
1884 #include <sys/resource.h>
1885 void foo(void) { 
1886   setpriority(PRIO_PROCESS, 0, 0);
1889 test_cxx "whether has setpriority" "yes" "no" ""
1890 AC_DEFINE_UNQUOTED(CMK_HAS_SETPRIORITY, $pass, [whether the setpriority exists])
1892 #### test for system ###
1893 cat > $t <<EOT
1894 #include "ckdll_system.C"
1896 test_cxx "whether to use signal-safe system() " "yes" "no" ""
1897 AC_DEFINE_UNQUOTED(CMK_SIGSAFE_SYSTEM, $pass, [whether to use signal-safe system()])
1899 ### test sched_setaffinity ####
1900 cat > $tc <<EOT
1901 #define _GNU_SOURCE
1902 #include <sched.h>
1904 int main()
1906   cpu_set_t cpuset;
1907   CPU_ZERO(&cpuset);
1908   CPU_SET(0, &cpuset);
1909   if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0) {
1910     return -1;
1911   }
1912   return 0;
1915 test_linkc "whether sched_setaffinity call exists" "yes" "no" ""
1916 AC_DEFINE_UNQUOTED(CMK_HAS_SETAFFINITY, $pass, [whether the sched_setaffinity() exists])
1918 ### test pthread_setaffinity_np ####
1919 cat > $tc <<EOT
1920 #include <stdlib.h>
1921 #include <stdio.h>
1922 #include <unistd.h>
1923 #include <pthread.h>
1925 int main()
1927   unsigned long mask = 0xffffffff;
1928   unsigned int len = sizeof(mask);
1930   if (pthread_setaffinity_np(pthread_self(), len, &mask) < 0) {
1931     return -1;
1932   }
1933   return 0;
1936 test_linkc "whether pthread_setaffinity_np call exists" "yes" "no" "-lpthread"
1937 AC_DEFINE_UNQUOTED(CMK_HAS_PTHREAD_SETAFFINITY, $pass, [whether the pthread_setaffinity_np() exists])
1939 ### test pthread_spin_lock ####
1940 cat > $tc <<EOT
1941 #include <stdlib.h>
1942 #include <stdio.h>
1943 #include <unistd.h>
1944 #include <pthread.h>
1946 int main()
1948   pthread_spinlock_t  lock;
1950   pthread_spin_init(&lock, 0);
1952   pthread_spin_lock(&lock);
1954   return 0;
1957 test_linkc "whether pthread_spin_lock exists" "yes" "no" "-lpthread"
1958 AC_DEFINE_UNQUOTED(CMK_HAS_SPINLOCK, $pass, [whether the pthread_spin_lock exists])
1960 ### check libnuma on Linux ####
1961 if test "$WITH_NUMA" = "yes"
1962 then
1963 cat > $tc <<EOT
1964 #include <stdlib.h>
1965 #include <stdio.h>
1966 #include <linux/mempolicy.h>
1967 #include <numaif.h>
1968 #include <numa.h>
1970 int main()
1972   if (get_mempolicy(NULL, NULL, 0, 0, 0) == 0) return 0;
1973   return -1;
1976 test_linkc "whether libnuma exists" "yes" "no" "-lnuma"
1977 AC_DEFINE_UNQUOTED(CMK_HAS_NUMACTRL, $pass, [whether NUMA control related functions exist])
1978 if test $pass -eq 1
1979 then
1980         add_flag 'CMK_SYSLIBS="$CMK_SYSLIBS -lnuma"' "libnuma"
1984 #### check bindprocessors on AIX ####
1985 cat > $tc <<EOT
1986 #include <stdlib.h>
1987 #include <stdio.h>
1988 #include <unistd.h>
1990 #include <sys/processor.h>
1992 int main()
1994   int retValue = 0;
1995   int pid;
1996   pid = getpid();
1997   if (bindprocessor(BINDPROCESS, pid, 0) == -1) return -1;
1998   return 0;
2001 test_linkc "whether bindprocessor call exists" "yes" "no" ""
2002 AC_DEFINE_UNQUOTED(CMK_HAS_BINDPROCESSOR, $pass, [whether the bindprocessor()
2003 exists])
2006 #### check if dlopen works ####
2007 skip_dl=0
2008 # for bproc, ignore -ldl
2009 test -n "$CMK_BPROC" && skip_dl=1
2010 test -n "$CMK_NO_DL" && skip_dl=1
2011 dl_opt='-ldl'
2012 #workaround for pgcc 4.0, -ldl crash linking, so use -Wl,-ldl to skip the prelinker.
2013 case "$CMK_CXX" in
2014 pgCC*) dl_opt='-Wl,-ldl' ;;
2015 esac
2017 if test $skip_dl -eq 0 
2018 then
2020 cat > $t <<EOT
2021 #include "ckdll_dlopen.C"
2022 int main() {
2023         CkDll dll("foo.so");
2024         return 0;
2027 test_link "whether dlopen links without $dl_opt" "yes" "no" ""
2028 noldl=$pass
2029 test_link "whether dlopen links with $dl_opt" "yes" "no" "$dl_opt"
2030 if test $pass -eq 1
2031 then 
2032 #dlopen requires -ldl: add it to our link line
2033         add_flag CMK_LIBS='"$CMK_LIBS '$dl_opt'"' "dlopen"
2036 if test $pass -eq 1 -o $noldl -eq 1
2037 then
2038 # One version or another of dlopen worked: compile it in
2039         AC_DEFINE_UNQUOTED(CMK_DLL_USE_DLOPEN, 1, [dlopen])
2042 cat > $tc <<EOT
2043 #ifndef _GNU_SOURCE
2044 # define _GNU_SOURCE
2045 #endif
2046 #ifndef __USE_GNU
2047 # define __USE_GNU
2048 #endif
2049 #include <dlfcn.h>
2050 #include <stddef.h>
2051 int main()
2053   return dlsym(RTLD_DEFAULT, "main") != NULL;
2056 test_cc "whether has RTLD_DEFAULT" "yes" "no" ""
2057 AC_DEFINE_UNQUOTED(CMK_HAS_RTLD_DEFAULT, $pass, [whether has RTLD_DEFAULT])
2059 cat > $tc <<EOT
2060 #ifndef _GNU_SOURCE
2061 # define _GNU_SOURCE
2062 #endif
2063 #ifndef __USE_GNU
2064 # define __USE_GNU
2065 #endif
2066 #include <dlfcn.h>
2067 #include <stddef.h>
2068 int main()
2070   return dlsym(RTLD_NEXT, "main") != NULL;
2073 test_cc "whether has RTLD_NEXT" "yes" "no" ""
2074 AC_DEFINE_UNQUOTED(CMK_HAS_RTLD_NEXT, $pass, [whether has RTLD_NEXT])
2076 ### test gethostname ####
2077 cat > $tc <<EOT
2078 #ifdef _WIN32
2079 #include <Winsock2.h>
2080 #else
2081 #include <stdlib.h>
2082 #include <stdio.h>
2083 #include <unistd.h>
2084 #endif
2086 int main()
2088   char hostname[[1000]];
2089   gethostname(hostname, 999);
2090   return 0;
2093 test_cc "whether gethostname call exists" "yes" "no" ""
2094 AC_DEFINE_UNQUOTED(CMK_HAS_GETHOSTNAME, $pass, [whether gethostname() exists])
2096 #### check if getProcAddress works ####
2097 cat > $t <<EOT
2098 #include "ckdll_win32.C"
2100 test_cxx "whether getProcAddress works" "yes" "no" ""
2101 AC_DEFINE_UNQUOTED(CMK_DLL_USE_WIN32, $pass, [whether getProcAddress works])
2103 fi    # end of skip_dl
2105 #### check if socklen_t exists ####
2106 cat > $t <<EOT
2107 #include <sys/types.h>
2108 #include <sys/socket.h>
2110 void foo(void) {
2111         int i;
2112         socklen_t s=sizeof(i);
2115 test_cxx "whether has socklen_t" "yes" "no" ""
2116 AC_DEFINE_UNQUOTED(CMK_HAS_SOCKLEN, $pass, [whether has socklen_t])
2118 ### test getifaddrs ####
2119 cat > $tc <<EOT
2120 #include <netinet/in.h> /* for sockaddr_in */
2121 #include <ifaddrs.h> /* for getifaddrs */
2122 #include <net/if.h> /* for IFF_RUNNING */
2124 int main()
2126   struct ifaddrs *interfaces=0;
2127   if( getifaddrs(&interfaces) == 0 ) {
2128         struct ifaddrs *interface;
2129         for( interface=interfaces; interface; interface=interface->ifa_next ) {
2130             if( (interface->ifa_flags & IFF_UP) && ! (interface->ifa_flags & IFF_LOOPBACK) ) {
2131                 const struct sockaddr_in *addr = (const struct sockaddr_in*)interface->ifa_addr;
2132                 if( addr && addr->sin_family==AF_INET ) {
2133                     break;
2134                 }
2135             }
2136         }
2137         freeifaddrs(interfaces);
2138   }
2141 test_linkc "whether getifaddrs call exists" "yes" "no" ""
2142 AC_DEFINE_UNQUOTED(CMK_HAS_GETIFADDRS, $pass, [whether getifaddrs() exists])
2144 #### check if mmap exists ####
2145 cat > $t <<EOT
2146 #include <sys/types.h>
2147 #include <sys/mman.h>
2149 void *foo(void *a,int l,int fd) {
2150         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2151                  MAP_FIXED+MAP_PRIVATE,fd,0);
2154 test_cxx "whether the mmap() syscall exists" "yes" "no" ""
2155 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP, $pass, [whether the mmap() syscall exists])
2156 add_flag "CMK_HAS_MMAP=$pass"
2157 add_make_flag "CMK_HAS_MMAP:=$pass"
2159 #### check if mmap accepts MAP_ANON ####
2160 cat > $t <<EOT
2161 #include <sys/types.h>
2162 #include <sys/mman.h>
2164 void *foo(void *a,int l) {
2165         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2166                 MAP_FIXED+MAP_PRIVATE+MAP_ANON,-1,0);
2169 test_cxx "whether mmap() accepts MAP_ANON" "yes" "no" ""
2170 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP_ANON, $pass, [whether mmap() accepts MAP_ANON])
2172 #### check if mmap accepts MAP_NORESERVE ####
2173 cat > $t <<EOT
2174 #include <sys/types.h>
2175 #include <sys/mman.h>
2177 void *foo(void *a,int l) {
2178         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2179                 MAP_FIXED+MAP_PRIVATE+MAP_NORESERVE,-1,0);
2182 test_cxx "whether mmap() accepts MAP_NORESERVE" "yes" "no" ""
2183 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP_NORESERVE, $pass, [whether mmap() accepts MAP_NORESERVE])
2185 #### check if get_myaddress exists ####
2186 cat > $t <<EOT
2187 #include <rpc/rpc.h>
2189 void foo(void *a) {
2190     get_myaddress((struct sockaddr_in*)a);
2193 test_cxx "whether has get_myaddress" "yes" "no" ""
2194 AC_DEFINE_UNQUOTED(CMK_HAS_GET_MYADDRESS, $pass, [whether has get_myaddress])
2196 #### check if mprotect exists ####
2197 cat > $t <<EOT
2198 #include <stdio.h>
2199 #include <sys/mman.h>
2201 void foo(void *a,int l,int fd) {
2202      void *pg = NULL;
2203      size_t pagesize = 4096;
2204      mprotect(pg, pagesize, PROT_READ | PROT_WRITE);
2207 test_cxx "whether has mprotect" "yes" "no" ""
2208 AC_DEFINE_UNQUOTED(CMK_HAS_MPROTECT, $pass, [whether has mprotect])
2210 #### check if support for SHM through CMA exists ####
2211 cat > $t <<EOT
2212 #define _GNU_SOURCE
2213 #include <sys/uio.h>
2214 #include <errno.h>
2215 int main() {
2216   pid_t pid;
2217   struct iovec *local, *remote;
2218   int nread = process_vm_readv(pid, local, 1, remote, 1, 0);
2219   nread = process_vm_writev(pid, local, 1, remote, 1, 0);
2220   return errno;
2223 test_link "whether has support for shm transport using Cross Memory Attach" "yes" "no" ""
2224 AC_DEFINE_UNQUOTED(CMK_HAS_CMA, $pass, [whether supports cma])
2226 #### check if -rdynamic works ####
2227 cat > $t <<EOT
2228 int main() {
2229   return 0;
2232 TRACE_LINK_FLAG=''
2233 CAN_EXPORT_SYMBOLS='0'
2234 for i in '-rdynamic' '-Wl,--export-dynamic'; do
2235   test_link "whether has $i" "yes" "no" "$i"
2236   if test "$strictpass" = '1'; then
2237     TRACE_LINK_FLAG="$i"
2238     CAN_EXPORT_SYMBOLS='1'
2239     break
2240   fi
2241 done
2243 if test "$CAN_EXPORT_SYMBOLS" = '1'; then
2244   add_flag 'CMK_LD="$CMK_LD '$TRACE_LINK_FLAG'"' "exporting program symbols to shared objects"
2245   add_flag 'CMK_LDXX="$CMK_LDXX '$TRACE_LINK_FLAG'"' "exporting program symbols to shared objects"
2248 #### check if glibc backtrace exists ####
2249 cat > $t <<EOT
2250 #include "cmibacktrace.c"
2252 int main() {
2253         int nLevels=1;
2254         void *stack;
2255         CmiBacktraceRecord(&stack,0,&nLevels);
2256         return 0;
2259 test_link "whether glibc backtrace works" "yes" "no" "-DCMK_USE_BACKTRACE=1 $TRACE_LINK_FLAG"
2260 AC_DEFINE_UNQUOTED(CMK_USE_BACKTRACE, $pass, [whether glibc backtrace works])
2262 #### test sleep ####
2263 cat > $t <<EOT
2264 #include <unistd.h>
2265 int main() {
2266   sleep(1);
2267   return 0;
2270 test_cxx "whether has sleep " "yes" "no" ""
2271 AC_DEFINE_UNQUOTED(CMK_HAS_SLEEP, $pass, [whether has sleep])
2273 #### test usleep ####
2274 cat > $t <<EOT
2275 #include <unistd.h>
2276 int main() {
2277   usleep(100);
2278   return 0;
2281 test_cxx "whether has usleep " "yes" "no" ""
2282 AC_DEFINE_UNQUOTED(CMK_HAS_USLEEP, $pass, [whether has usleep])
2284 #### test personality() and ADDR_NO_RANDOMIZE ####
2285 # Only works on modern Linux systems
2286 cat > $t <<EOT
2287 #include <sys/personality.h>
2288 int main() {
2289     int orig_persona = personality(0xffffffff);
2290     personality(orig_persona | ADDR_NO_RANDOMIZE);
2291     return 0;
2294 test_cxx "whether personality() and ADDR_NO_RANDOMIZE exist" "yes" "no" ""
2295 AC_DEFINE_UNQUOTED(CMK_HAS_ADDR_NO_RANDOMIZE, $pass, [whether personality() and ADDR_NO_RANDOMIZE exist])
2298 # enable/disable zlib
2299 AC_ARG_ENABLE([zlib],
2300             [AS_HELP_STRING([--enable-zlib],
2301               [enable zlib support])],
2302             [enable_zlib=$enableval],
2303             [enable_zlib=yes])
2305 #### test if has zlib ####
2306 # bproc doesnot like -lz in any case
2307 if test -z "$CMK_BPROC" && test "$enable_zlib" = "yes"
2308 then
2310 cat > $t <<EOT
2311 #include <zlib.h>
2312 int main() { 
2313   gzFile f = gzopen("/tmp/x","r");
2314   gzprintf(f, "test...\n");
2315   gzclose(f);
2316   return 0;
2319 test_link "whether has zlib" "yes" "no" "-lz"
2320 AC_DEFINE_UNQUOTED(CMK_USE_ZLIB, $pass, [whether has zlib])
2321 if test $pass -eq 1
2322 then 
2323         add_flag 'CMK_SYSLIBS="$CMK_SYSLIBS -lz"' "zlib"
2328 #### test if has elf.h ####
2329 cat > $t <<EOT
2330 #include <elf.h>
2331 typedef Elf32_Addr ELF_TYPE_Addr;
2332 int main() { 
2335 test_cxx "whether has elf.h " "yes" "no" ""
2336 AC_DEFINE_UNQUOTED([CMK_HAS_ELF_H], $pass, [whether has elf.h])
2337 if test $pass -eq 1
2338 then
2339         add_flag "CMK_HAS_ELF_H='1'" "elf.h"
2342 #### test if has Multiprocessing.h for apple ####
2343 cat > $t <<EOT
2344 #include <Carbon/Carbon.h>
2345 #include <Multiprocessing.h>
2346 int main() {
2347   int a = MPProcessorsScheduled();
2350 test_cxx "whether has Multiprocessing.h for Apple " "yes" "no" ""
2351 AC_DEFINE_UNQUOTED([CMK_HAS_MULTIPROCESSING_H], $pass, [whether has Multiprocessing.h])
2353 #### test if "ntohl" is available ####
2354 cat > $t <<EOT
2355 #if defined(_WIN32) || defined(__MINGW_H)
2356 #include <winsock.h>
2357 #else
2358 #include <stdint.h>
2359 #include <arpa/inet.h>
2360 #include <netinet/in.h>
2361 #endif
2363 int main() {
2364   int i = 100;
2365   i = ntohl(i);
2366   return 0;
2369 test_cc "whether ntohl is available" "yes" "no" ""
2370 AC_DEFINE_UNQUOTED(CMK_HAS_NTOHL, $pass, [whether ntohl is available])
2372 ### test for libjpeg ####
2373 cat > $t <<EOT
2374 #include <stdio.h>
2375 #include <stdlib.h>
2376 #include "jpeglib.h"
2378 int main()
2380   struct jpeg_compress_struct cinfo;
2381   jpeg_create_compress(&cinfo);
2382   return 0;
2385 test_link "whether has libjpeg" "yes" "no" "-ljpeg"
2386 AC_DEFINE_UNQUOTED(CMK_USE_LIBJPEG, $pass, [whether has libjpeg])
2387 if test $pass -eq 1
2388 then
2389         add_flag 'CMK_LIBJPEG="-ljpeg"' "libjpeg"
2390         add_make_flag 'CMK_LIBJPEG:=-ljpeg' 'libjpeg'
2393 #### check if PAPI exists ####
2394 if test -n "$CMK_USE_PAPI"
2395 then
2396 cat > $t <<EOT
2397 #include <stdio.h>
2398 #include <papi.h>
2399                                                                                 
2400 int main() {
2401     if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) return 1;
2402     return 0;
2405 test_link "whether PAPI exists" "yes" "no" "-lpapi"
2406 AC_DEFINE_UNQUOTED(CMK_HAS_COUNTER_PAPI, $pass, [whether PAPI exists])
2407 if test "$enable_tracing" = "no"
2408 then
2409         echo "Error: Cannot build papi version when tracing is disabled, build with --enable-tracing"
2410         test_finish 1
2411 elif test $fail -eq 1
2412 then
2413         echo "Error: Cannot find papi library"
2414         test_finish 1
2415 else
2416         add_flag 'CMK_LIBS="$CMK_LIBS -lpapi"' "papi"
2420 #### test if Python headers are installed ####
2421 PYTHON_VERSION=`python -V 2>&1 | awk {'print $2'} | awk -F. {'print $1"."$2'}`
2422 cat > $t <<EOT
2423 #include "python${PYTHON_VERSION}/Python.h"
2424 #include "python${PYTHON_VERSION}/compile.h"
2425 #include "python${PYTHON_VERSION}/eval.h"
2426 #include "python${PYTHON_VERSION}/node.h"
2428 int main() {
2429     Py_Initialize();
2430     PyEval_InitThreads();
2431     struct _node* programNode = PyParser_SimpleParseString("return 1\n",Py_file_input);
2432     PyCodeObject *program = PyNode_Compile(programNode, "");
2435 test_link "whether Python is installed" "yes" "no" "-lpython$PYTHON_VERSION -lpthread -lutil -ldl"
2436 AC_DEFINE_UNQUOTED(CMK_HAS_PYTHON, $pass, [whether Python is installed])
2437 AC_DEFINE_UNQUOTED(CMK_PYTHON_VERSION, ${PYTHON_VERSION}, [Python version])
2438 if test $pass -eq 1
2439 then
2440         add_flag "CMK_BUILD_PYTHON=$PYTHON_VERSION" "python"
2441         add_make_flag "CMK_BUILD_PYTHON:=$PYTHON_VERSION" 'python'
2444 ## Cray specific test
2445 if test "$CMK_BUILD_CRAY" = "1"
2446 then
2447 #echo "Test for known incompatible compiler versions"
2449  if test "$CRAY_CC_VERSION" = "8.1.4"
2450  then
2451         echo "CCE 8.1.4 produces incorrect Charm++ code"
2452         echo "Please use a newer version of the CCE compiler"
2453         echo "e.g. module load cce/8.1.7"
2454         test_finish 1
2455  fi
2457 #### test if Cray node topology will work ####
2458 cat > $tc <<EOT
2459 #include <pmi.h>
2461 int main() {
2462     int nid;
2463     PMI_Get_nid(0, &nid);
2465     return 0;
2468 test_linkc "whether PMI_Get_nid exists" "yes" "no" "$CMK_CRAY_LIBS"
2469 AC_DEFINE_UNQUOTED(CMK_HAS_PMI_GET_NID, $pass, [whether PMI_Get_nid exists])
2471 #### test if Cray mesh topology will work ####
2472 cat > $tc <<EOT
2473 #include <rca_lib.h>
2475 int main() {
2476     rca_mesh_coord_t xyz;
2477     rca_get_meshcoord(0, &xyz);
2479     return 0;
2482 test_linkc "whether Cray rca library is available" "yes" "no" "$CRAY_RCA_POST_LINK_OPTS -lrca"
2483 AC_DEFINE_UNQUOTED(CMK_HAS_RCALIB, $pass, [whether Cray rca library is available])
2485 #### test if Cray mesh dimension query function will work ####
2486 cat > $tc <<EOT
2487 #include <rca_lib.h>
2489 int main() {
2490     rca_mesh_coord_t xyz;
2491     rca_get_max_dimension(&xyz);
2493     return 0;
2496 test_linkc "whether Cray rca_has get_max_dimension" "yes" "no" "$CRAY_RCA_POST_LINK_OPTS -lrca"
2497 AC_DEFINE_UNQUOTED(CMK_HAS_RCA_MAX_DIMENSION, $pass, [whether Cray rca has rca_get_max_dimension])
2499 #### query Cray machine max NID if get_max_dimension not exist ####
2501 if test $pass -eq 0
2502 then
2503 cmd=`which xtprocadmin 2>/dev/null`
2504 if test -n "$cmd"
2505 then
2506     #maxnid=`xtprocadmin  | tail -1  | awk '{print $1}'`
2507     # workaround for hopper
2508     (export SHELL=/bin/csh; xtprocadmin >& t.$$)
2509     maxnid=`cat t.$$  | tail -1  | awk '{print $1}'`
2510     /bin/rm -f t.$$
2511     AC_MSG_CHECKING(Cray machine maxnid)
2512     AC_MSG_RESULT("$maxnid")
2513     if test -n "$maxnid"
2514     then
2515     AC_DEFINE_UNQUOTED(CMK_CRAY_MAXNID, $maxnid, [Cray MAXNID])
2516     fi
2523 #### query Cray machine supports BANDWIDTH_INJECTION controls####
2525 if test "$CMK_BUILD_MPI" = "1"
2526 then
2527 echo "BALANCED_INJECTION test disabled on MPI"
2528 elif test "$GNI_CRAYXC" = "1"
2529 then
2530 echo "BALANCED_INJECTION test disabled on Aries network"
2531 else
2532 cat > $tc <<EOT
2533 #include <stdint.h>
2534 #include <gni_pub.h>
2536 int main() {
2537     gni_bi_desc_t gni_bi_desc;
2538     uint32_t gni_device_id = 0;
2539     gni_return_t gni_rc = GNI_GetBIConfig(gni_device_id, &gni_bi_desc);
2540     if (gni_rc == GNI_RC_SUCCESS) {
2541     }
2542     return 0;
2545 test_linkc "whether GNI_GetBIConfig exists" "yes" "no" "$CMK_CRAY_LIBS"
2546 AC_DEFINE_UNQUOTED(CMK_BALANCED_INJECTION_API, $pass, [whether Cray gni_pub has GNI_GetBIConfig])
2547 fi # end of BIConfig test
2550 fi  # end of Cray specific test
2552 #### test if it can build shared library ####
2553 cat > $t <<EOT
2554 #include "stdlib.h"
2555 extern int foo();
2556 int foo1() { 
2557   void * t= malloc(2);
2558   foo();
2559   return 0;
2562 test_linkso "whether can build shared library" "yes" "no" ""
2563 if test $pass -eq 0
2564 then 
2565         add_flag 'CMK_NO_BUILD_SHARED="true"' "build-shared"
2566         add_make_flag 'CMK_NO_BUILD_SHARED:=true' 'build-shared'
2567         CMK_NO_BUILD_SHARED='true'
2568 else
2569         BUILD_SHARED=1
2570         if test "$BUILD_MPI" = "1"
2571         then
2572 cat > $t <<EOT
2573 #include "stdlib.h"
2574 #include "mpi.h"
2575 extern int foo();
2576 int foo(int argc, char ** argv) {
2577   void * t= malloc(2);
2578   foo();
2579   MPI_Init(&argc, &argv);
2580   return 0;
2583                 test_linkso "whether can build shared library with MPI" "yes" "no" ""
2584                 BUILD_SHARED=$pass
2585         fi
2586         if test $BUILD_SHARED -eq 0
2587         then
2588                 add_flag 'CMK_NO_BUILD_SHARED="true"' "build-shared"
2589                 add_make_flag 'CMK_NO_BUILD_SHARED:=true' 'build-shared'
2590                 CMK_NO_BUILD_SHARED='true'
2591         fi
2594 #### test the version number of bproc ####
2595 if test -n "$CMK_BPROC"
2596 then
2597 cat > $t <<EOT
2598 #include <stdio.h>
2599 #include <sys/bproc.h>
2600 int main()
2602   struct bproc_version_t vers;
2603   bproc_version(&vers);
2604   printf("%s\n", vers.version_string);
2607 test_link "whether bproc compiles" "yes" "no" "-lbproc"
2608 if test $pass -eq 1
2609 then 
2610 AC_MSG_CHECKING("bproc version")
2611 bproc_ver=`./testlink`
2612 if test x$bproc_ver = x
2613 then
2614 test_result 0 "bproc version" "ERROR" ""
2615 test_finish 1
2616 else
2617 test_result 0 "bproc version" "$bproc_ver" ""
2619 bproc_ver=`echo $bproc_ver | cut -d'.' -f1`
2620 AC_DEFINE_UNQUOTED(CMK_BPROC_VERSION, $bproc_ver, [bproc version])
2624 #### test the if command sync exists ####
2625 AC_CHECK_PROG(SYNC, sync, sync )
2626 if test -n "$SYNC"
2627 then
2628 AC_DEFINE_UNQUOTED(CMK_HAS_SYNC, 1, [sync program])
2631 ################## Fortran #########################
2633 #echo "set F77 compiler as: $CMK_CF77"
2634 AC_MSG_CHECKING("F77 compiler as")
2635 AC_MSG_RESULT("$CMK_CF77")
2637 AC_MSG_CHECKING("whether Fortran 77 compiler works")
2638 ### test fortran 77 compiler ###
2639 cat > conftest.f <<EOF
2640       SUBROUTINE FOO_foo
2641       END
2643 $CMK_CF77 -c conftest.f > /dev/null 2> /dev/null
2644 if test ! -r conftest.o
2645 then
2646   AC_MSG_RESULT("no")
2647 else
2648   AC_MSG_RESULT("yes")
2651 ### test fortran 90 compiler ###
2652 #echo "set F90 compiler as: $CMK_CF90"
2653 AC_MSG_CHECKING("F90 compiler as")
2654 AC_MSG_RESULT("$CMK_CF90")
2656 AC_MSG_CHECKING("whether Fortran 90 compiler works")
2657 cat > conftest2.f90 <<EOF
2658       SUBROUTINE FOO_foo
2659       END
2661 $CMK_CF90 -c conftest2.f90 > /dev/null 2> /dev/null
2662 if test ! -r conftest2.o
2663 then
2664   AC_MSG_RESULT("no")
2665 else
2666   AC_MSG_RESULT("yes")
2667   mv -f conftest2.o conftest.o
2668   USE_FORTRAN90=1
2671 ### check fortran name mangling
2672 AC_MSG_CHECKING(subroutine name used by Fortran 90 compiler)
2674 if test -r conftest.o
2675 then
2676   AC_CACHE_VAL(_cv_fortran_postfix,
2678   NAME=`$CMK_NM conftest.o | grep "foo_foo__"`
2679   if test "$NAME" != ""
2680   then
2681     _cv_fortran_postfix=TWOSCORE
2682     AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_TWOSCORE, 1, [TWOSCORE])
2683   else
2684     NAME=`$CMK_NM conftest.o | grep "foo_foo_"`
2685     if test "$NAME" != ""
2686     then
2687       _cv_fortran_postfix=ONESCORE
2688       AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_ONESCORE, 1, [ONESCORE])
2689     else
2690       NAME=`$CMK_NM conftest.o | grep "foo_foo"`
2691       if test "$NAME" != ""
2692       then
2693         _cv_fortran_postfix=NOSCORE
2694         AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_NOSCORE, 1, [NOSCORE])
2695       else
2696         NAME=`$CMK_NM conftest.o | grep "FOO_FOO"`
2697         if test "$NAME" != ""
2698         then
2699           _cv_fortran_postfix=ALLCAPS
2700           AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_ALLCAPS, 1, [ALLCAPS])
2701         else
2702           echo "#################################################"
2703           echo "FORTRAN compiler generated name not supported yet"
2704           echo "#################################################"
2705         fi
2706       fi
2707     fi
2708   fi
2709   rm -f conftest.f conftest.o
2710   )
2711   AC_MSG_RESULT($_cv_fortran_postfix)
2712 else
2713   AC_MSG_RESULT("Fortran compiler not working")
2716 ### check module name ###
2718 if test "$USE_FORTRAN90" = 1
2719 then
2720   cat > conftest.f90 <<EOF
2721       MODULE testmod
2722         interface 
2723           function fpup_issizing(p)
2724           INTEGER :: p
2725           logical fpup_issizing
2726           end function
2727         end interface
2728       END MODULE
2730   AC_MSG_CHECKING(Fortran 90 mod name is capital)
2731   $CMK_CF90 -c conftest.f90 > /dev/null 2> /dev/null
2732   name=`ls TESTMOD.* 2>/dev/null`
2733   if test -n "$name"
2734   then
2735         AC_MSG_RESULT("yes")
2736         add_flag 'CMK_MOD_NAME_ALLCAPS=1' "mod name capital"
2737   else
2738         AC_MSG_RESULT("no")
2739         name=`ls testmod.* 2>/dev/null`
2740   fi
2741   if test -n "$name"
2742   then
2743         AC_MSG_CHECKING(Fortran 90 mod name extension)
2744         ext=`echo $name | sed -e 's/^[[^.]]*\.//'`
2745         add_flag 'CMK_MOD_EXT="'$ext'"' "mod name extension"
2746         AC_MSG_RESULT("$ext")
2747         /bin/rm -f $name
2748   fi
2749   /bin/rm -f conftest.f90
2752 ### test if the C++ linker succeeds with a Fortran entry point ##
2754 cat > conftest.f90 <<EOF
2755       PROGRAM empty
2756       END PROGRAM
2758 test_link_fortran_main() {
2759   AC_MSG_CHECKING("$1")
2760   echo "### $1" >> $charmout
2761   cat conftest.f90 >> $charmout
2762   echo $CMK_CF90 -c conftest.f90 -o test.o $4 >> $charmout
2763   $CMK_CF90 -c conftest.f90 -o test.o $4 > out 2>&1
2764   if test $? -ne 0
2765   then
2766     test_result 1 "$1" "$2" "$3"
2767   else
2768     echo $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $CMK_F90LIBS $CMK_F90MAINLIBS $4 $5 >> $charmout
2769     $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $CMK_F90LIBS $CMK_F90MAINLIBS $4 $5 >> out 2>&1
2770     ret=$?
2771     test ! -x testlink && ret=1
2772     test_result $ret "$1" "$2" "$3"
2773   fi
2774   cat out >> $charmout
2776 test_link_fortran_main "whether the C++ linker succeeds with a Fortran entry point" "yes" "no" ""
2777 /bin/rm -f conftest.f90 test.o testlink out
2778 if test $pass -eq 1
2779 then
2780   add_flag "CMK_CAN_LINK_FORTRAN='1'" "Fortran"
2783 ### check for OpenMP availability ###
2784 cat > $tc <<EOT
2785 #include <stdio.h>
2786 #include <omp.h>
2788 int main(void)
2790   int iam = 0, np = 1;
2792   #pragma omp parallel default(shared) private(iam, np)
2793   {
2794     np = omp_get_num_threads();
2795     iam = omp_get_thread_num();
2796     printf("Hello from thread %d of %d\n", iam, np);
2797   }
2799   return 0;
2802 test_linkc "whether OpenMP is supported" "yes" "no" "$CMK_C_OPENMP"
2803 if test $pass -eq 1
2804 then
2805         add_flag "CMK_HAS_OPENMP='1'" "OpenMP"
2808 ### check for Lustre FS availability ###
2809 cat > $tc <<EOT
2810 #include <stdio.h>
2811 #include <lustre/lustreapi.h>
2812 #include <lustre/lustre_user.h>
2814 int main() {
2815   llapi_printf(LLAPI_MSG_NORMAL, "Lustre FS is available");
2816   return 0;
2819 test_linkc "whether has lustre fs" "yes" "no" "-llustreapi"
2820 AC_DEFINE_UNQUOTED(CMK_HAS_LUSTREFS, $pass, [whether has lustrefs])
2821 if test $pass -eq 1
2822 then
2823   add_make_flag 'CMK_LUSTREAPI:=-llustreapi' "lustreapi"
2824 else
2825   add_make_flag 'CMK_LUSTREAPI:=' "lustreapi"
2829 # for hwloc
2830 eval "`./charmc -print-building-blocks $OPTS`"
2831 export CC="$(get_full_command_name "$CMK_SEQ_CC")"
2832 export CXX="$(get_full_command_name "$CMK_SEQ_CXX")"
2833 export CC_FOR_BUILD="$(get_full_command_name "$CMK_NATIVE_CC")"
2834 AC_SUBST(CC_FOR_BUILD)
2835 export HWLOC_FLAGS="$CHARM_CC_FLAGS"
2836 export CFLAGS="$CMK_SEQ_CC_FLAGS"
2837 export AR="$(get_full_command_name "${CMK_SEQ_AR%% *}")"
2838 enable_embedded_mode='yes'
2839 enable_static='yes'
2840 if test "$CMK_NO_BUILD_SHARED" = 'false'
2841 then
2842   enable_shared='yes'
2843   export am_libhwloc_embedded_la_rpath="-rpath $CHARMLIBSO"
2844 else
2845   enable_shared='no'
2846   export am_libhwloc_embedded_la_rpath=''
2848 AC_SUBST(am_libhwloc_embedded_la_rpath)
2849 enable_libnuma='no'
2850 enable_pci='no'
2851 enable_libudev='no'
2852 enable_libxml2='no'
2853 enable_visibility='no'
2854 enable_nvml='no'
2855 . hwloc/VERSION
2856 export libhwloc_so_version
2857 AC_SUBST(libhwloc_so_version)
2859 echo "Configuring hwloc:"
2860 AC_CONFIG_AUX_DIR(hwloc/config)
2861 AC_CANONICAL_TARGET
2862 AC_USE_SYSTEM_EXTENSIONS
2863 LT_INIT
2865 AM_INIT_AUTOMAKE([no-define])
2867 AC_CONFIG_MACRO_DIR(hwloc/config)
2868 HWLOC_SET_SYMBOL_PREFIX([cmi_])
2869 HWLOC_SETUP_CORE([hwloc], [happy=yes], [happy=no])
2870 HWLOC_DO_AM_CONDITIONALS
2871 add_flag 'CMK_HWLOC_LIBS="-lhwloc_embedded '"$HWLOC_EMBEDDED_LIBS"'"' "hwloc"
2873 AC_OUTPUT