Add --with-mempool-cutoff=N to build and configure scripts
[charm.git] / src / scripts / configure.ac
blob8d204ff7a2b6bd7deb8e88d329e393d00b649aa1
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 "BUILD_CUDA:=$BUILD_CUDA" 'basic setup'
119 # enable/disable error checking
120 AC_ARG_ENABLE([error-checking],
121             [AS_HELP_STRING([--enable-error-checking],
122               [enable error checking])], ,
123             [enable_error_checking=yes])
125 if test "$enable_error_checking" = "no"
126 then
127   Echo "Error checking is disabled" 
128   AC_DEFINE_UNQUOTED(CMK_ERROR_CHECKING, 0, [disable error checking])
129   add_flag 'OPTS_CC="$OPTS_CC -U_FORTIFY_SOURCE"' 'error checking'
130   add_flag 'OPTS_CXX="$OPTS_CXX -U_FORTIFY_SOURCE"' 'error checking'
131 else
132   Echo "Error checking is enabled" 
133   AC_DEFINE_UNQUOTED(CMK_ERROR_CHECKING, 1, [enable error checking])
136 # enable/disable AMPI error checking
137 AC_ARG_ENABLE([ampi-error-checking],
138             [AS_HELP_STRING([--enable-ampi-error-checking],
139               [enable AMPI error checking])], ,
140             [enable_ampi_error_checking=yes])
142 if test "$enable_ampi_error_checking" = "no"
143 then
144   Echo "AMPI error checking is disabled"
145   AC_DEFINE_UNQUOTED(AMPI_ERROR_CHECKING, 0, [disable ampi error checking])
146 else
147   Echo "AMPI error checking is enabled"
148   AC_DEFINE_UNQUOTED(AMPI_ERROR_CHECKING, 1, [enable ampi error checking])
151 # enable/disable statistics collection
152 AC_ARG_ENABLE([stats],
153             [AS_HELP_STRING([--enable-stats],
154               [enable statistics collection])], ,
155             [enable_stats=yes])
157 if test "$enable_stats" = "no"
158 then
159   Echo "Statistics collection is disabled" 
160   AC_DEFINE_UNQUOTED(CMK_WITH_STATS, 0, [disable statistics collection])
161 else
162   Echo "Statistics collection is enabled" 
163   AC_DEFINE_UNQUOTED(CMK_WITH_STATS, 1, [enable statistics collection])
166 # check enable/disable
167 AC_ARG_ENABLE([tracing],
168             [AS_HELP_STRING([--enable-tracing],
169               [enable tracing modules])], ,
170             [enable_tracing=yes])
172 if test "$enable_tracing" = "no"
173 then
174   Echo "Charm tracing is disabled"
175   AC_DEFINE_UNQUOTED(CMK_TRACE_ENABLED, 0, [disable tracing])
176   add_flag CMK_TRACE_ENABLED=0
177   add_make_flag 'CMK_TRACE_ENABLED:=0' 'tracing'
178 else
179   Echo "Charm tracing is enabled"
180   AC_DEFINE_UNQUOTED(CMK_TRACE_ENABLED, 1, [enable tracing])
181   add_flag CMK_TRACE_ENABLED=1
182   add_make_flag 'CMK_TRACE_ENABLED:=1' 'tracing'
185 AC_ARG_ENABLE([tracing-commthread],
186             [AS_HELP_STRING([--enable-tracing-commthread],
187               [enable tracing communication thread])], ,
188             [enable_tracing_commthread=no])
190 if test "$enable_tracing_commthread" = "yes"
191 then
192   Echo "Charm tracing communication thread is enabled"
193   AC_DEFINE_UNQUOTED(CMK_SMP_TRACE_COMMTHREAD, 1, [enable tracing comm thread])
194 else
195   Echo "Charm tracing communication thread is disabled"
196   AC_DEFINE_UNQUOTED(CMK_SMP_TRACE_COMMTHREAD, 0, [disable tracing comm thread])
200 # enable task queue
201 AC_ARG_ENABLE([task_queue],
202             [AS_HELP_STRING([--enable-task-queue],
203               [enable task queue])],
204             [enable_task_queue=$enableval],
205             [enable_task_queue=no])
207 if test "$enable_task_queue" = "no"
208 then
209   Echo "Task Queue is disabled"
210   AC_DEFINE_UNQUOTED(CMK_TASKQUEUE, 0, [disable task queue])
211 else
212   Echo "Task Queue is enabled"
213   AC_DEFINE_UNQUOTED(CMK_TASKQUEUE, 1, [enable task queue])
216 # enable drone mode
217 AC_ARG_ENABLE([drone_mode],
218             [AS_HELP_STRING([--enable-drone-mode],
219               [enable drone mode])],
220             [enable_drone_mode=$enableval],
221             [enable_drone_mode=no])
223 if test "$enable_drone_mode" = "no"
224 then
225   Echo "Drone mode is disabled"
226   AC_DEFINE_UNQUOTED(CMK_DRONE_MODE, 0, [disable drone mode])
227 else
228   Echo "Drone mode is enabled"
229   AC_DEFINE_UNQUOTED(CMK_DRONE_MODE, 1, [enable drone mode])
232 AC_ARG_ENABLE([charmdebug],
233             [AS_HELP_STRING([--enable-charmdebug],
234               [enable charmDebug])], ,
235             [enable_charmdebug=yes])
237 if test "$enable_charmdebug" = "no" -o "$CMK_CCS_AVAILABLE" = '0'
238 then
239   Echo "CharmDebug is disabled" 
240   AC_DEFINE_UNQUOTED(CMK_CHARMDEBUG, 0, [disable charmdebug])
241   add_flag CMK_CHARMDEBUG=0
242   add_make_flag 'CMK_CHARMDEBUG:=0'
243 else
244   Echo "CharmDebug is enabled" 
245   AC_DEFINE_UNQUOTED(CMK_CHARMDEBUG, 1, [enable charmdebug])
246   add_flag CMK_CHARMDEBUG=1
247   add_make_flag 'CMK_CHARMDEBUG:=1'
250 AC_ARG_ENABLE([replay],
251             [AS_HELP_STRING([--enable-replay],
252               [enable record/replay])],
253             [enable_replay=$enableval],
254             [enable_replay=yes])
256 if test "$enable_replay" = "no"
257 then
258   Echo "Charm record/replay is disabled"
259   AC_DEFINE_UNQUOTED(CMK_REPLAYSYSTEM, 0, [disable replay])
260 else
261   Echo "Charm record/replay is enabled"
264 AC_ARG_ENABLE([ccs],
265             [AS_HELP_STRING([--enable-ccs],
266               [enable CCS])], ,
267             [enable_ccs=yes])
269 if test "$enable_ccs" = "no" -o "$CMK_CCS_AVAILABLE" = '0'
270 then
271   Echo "CCS is disabled" 
272   AC_DEFINE_UNQUOTED(CMK_CCS_AVAILABLE, 0, [disable ccs])
273 else
274   Echo "CCS is enabled" 
275   AC_DEFINE_UNQUOTED(CMK_CCS_AVAILABLE, 1, [enable ccs])
278 AC_ARG_ENABLE([controlpoint],
279             [AS_HELP_STRING([--enable-controlpoint],
280               [enable control point])],
281             [enable_controlpoint=$enableval],
282             [enable_controlpoint=yes])
284 if test "$enable_controlpoint" = "yes"
285 then
286   Echo "Charm control point is enabled"
287   AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 1, [enable controlpoint])
288 else
289   Echo "Charm control point is disabled"
290   AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 0, [disable controlpoint])
293 AC_ARG_ENABLE([lbuserdata],
294             [AS_HELP_STRING([--enable-lbuserdata],
295               [enable LB user data])],
296             [enable_lbuserdata=$enableval],
297             [enable_lbuserdata=no])
299 if test "$enable_lbuserdata" = "yes"
300 then
301   Echo "Charm LB user data is enabled"
302   AC_DEFINE_UNQUOTED(CMK_LB_USER_DATA, 1, [enable lb user data])
303 else
304   Echo "Charm LB user data  is disabled"
305   AC_DEFINE_UNQUOTED(CMK_LB_USER_DATA, 0, [disable lb user data])
308 AC_ARG_ENABLE([lockless-queue],
309             [AS_HELP_STRING([--enable-lockless-queue],
310               [enable lockless queue for PE local and node queue])],
311             [enable_lockless_queue=$enableval],
312             [enable_lockless_queue=no])
314 if test "$enable_lockless_queue" = "no"
315 then
316   Echo "Lockless queue for PE local and node queue is disabled"
317   AC_DEFINE_UNQUOTED(CMK_LOCKLESS_QUEUE, 0, [disable lockless queue for pe/node queue])
318 else
319   Echo "Lockless queue for PE local and node queue is enabled"
320   AC_DEFINE_UNQUOTED(CMK_LOCKLESS_QUEUE, 1, [enable lockless queue for pe/node queue])
324 AC_ARG_ENABLE([shrinkexpand],
325             [AS_HELP_STRING([--enable-shrinkexpand],
326               [enable malleable jobs / shrink expand])],
327             [enable_shrinkexpand=$enableval],
328             [enable_shrinkexpand=no])
330 if test "$enable_shrinkexpand" = "yes"
331 then
332   if test "$enable_ccs" = "no"
333   then
334     Echo "CCS cannot be disabled when enabling shrink-expand"
335     test_finish 1
336   else
337     Echo "Charm shrink expand is enabled - Controlpoint is disabled."
338     AC_DEFINE_UNQUOTED(CMK_SHRINK_EXPAND, 1, [enable shrinkexpand])
339     AC_DEFINE_UNQUOTED(CMK_WITH_CONTROLPOINT, 0, [disable controlpoint])
340   fi
341 else
342   Echo "Charm shrink expand is disabled"
343   AC_DEFINE_UNQUOTED(CMK_SHRINK_EXPAND, 0, [disable shrinkexpand])
346 AC_ARG_ENABLE([charmpy],
347             [AS_HELP_STRING([--enable-charmpy],
348               [enable charm4py support])],
349             [enable_charmpy=$enableval],
350             [enable_charmpy=no])
352 if test "$enable_charmpy" = "yes"
353 then
354   Echo "charm4py support is enabled"
355   AC_DEFINE_UNQUOTED(CMK_CHARMPY, 1, [enable charmpy])
356 else
357   Echo "charm4py support is disabled"
358   AC_DEFINE_UNQUOTED(CMK_CHARMPY, 0, [disable charmpy])
361 AC_ARG_WITH([numa],
362             [AS_HELP_STRING([--with-numa],
363               [support memory affinity with NUMA])],
364             [],
365             [with_numa=no])
367 WITH_NUMA=no
368 if test "$with_numa" = "yes"
369 then
370   Echo "Charm NUMA support is builtin"
371   WITH_NUMA=yes
374 AC_ARG_WITH([lbtime-type],
375             [AS_HELP_STRING([--with-lbtime-type=type],
376                             [load balancing timer type])],
377             [], [with_lbtime_type=double])
379 if test "$with_lbtime_type" = "float" -o "$with_lbtime_type" = "double"
380 then
381   Echo "Setting load balancing timer type as '$with_lbtime_type'"
382   AC_DEFINE_UNQUOTED(CMK_LBTIME_TYPE, $with_lbtime_type, [Setting load balancing timer type])
383 else
384   Echo "Invalid type specified for load balancing timer type"
385   test_finish 1
388 AC_DEFINE_UNQUOTED(CMK_LBID_64BIT, 1, [enable 64 bit LB ID])
390 AC_DEFINE_UNQUOTED(CMK_CKSECTIONINFO_STL, 1, [enable STL CkSectionInfo])
392 AC_ARG_WITH([qlogic],
393             [AS_HELP_STRING([--with-qlogic],
394               [QLogic based Infiniband])],[with_qlogic=yes],
395             [with_qlogic=no])
397 if test "$with_qlogic" = "no"
398 then
399   AC_DEFINE_UNQUOTED(QLOGIC, 0, [disable qlogic])
400 else
401   Echo "QLogic based Infiniband"
402   AC_DEFINE_UNQUOTED(QLOGIC, 1, [enable qlogic])
406 AC_MSG_CHECKING(machine name)
407 version=`pwd | awk -F/ '{print $(NF-1)}'`
408 base_version="$CMK_VDIR"
409 AC_DEFINE_UNQUOTED(CMK_MACHINE_NAME, "$version",[machine name])
410 AC_MSG_RESULT($version)
411 AC_SUBST(base_version)
413 t="test.cpp"
414 tc="test.c"
416 # test result passed in $1
417 # If the test suceeded, print $3 and set "pass"/clear "fail"
418 # If the test failed, print $2 and clear "pass"/set "fail"
419 test_result() {
420         if test $1 -eq 0
421         then
422                 AC_MSG_RESULT("$3")
423                 pass="1"
424                 fail="0"
425         else
426                 AC_MSG_RESULT("$4")
427                 pass="0"
428                 fail="1"
429 # For debugging the configure script, just "export autoconf_debug=1"
430 #  to get this verbose data on any failed tests:
431                 if test ! -z "$autoconf_debug"
432                 then
433                         echo "------- test script for $2 failed:"
434                         cat out
435                         echo "------- the test program was:"
436                         cat $t
437                         echo "-------"
438                 fi
439         fi
442 # Test: tries to compile C file $t (described by $1).
443 #  If successful, prints $2 and sets $pass/clears $fail
444 #  If failure, prints $3 and sets $pass/clears $fail
445 #  additional arguments to c++ compiler are passed as $4
446 test_cc() {
447         AC_MSG_CHECKING("$1")
448         echo "### $1" >> $charmout
449         cat $tc >> $charmout
450         echo $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 >> $charmout
451         $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 > out 2>&1
452         test_result $? "$1" "$2" "$3"
453         strictpass=$pass
454         strictfail=$fail
455         if test $pass -eq 1
456         then 
457           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
458           then 
459             strictpass="0" && strictfail="1"
460           fi
461         fi
462         cat out >> $charmout
463         /bin/rm -f out
466 # Test: tries to compile C++ file $t (described by $1).
467 #  If successful, prints $2 and sets $pass/clears $fail
468 #  If failure, prints $3 and sets $pass/clears $fail
469 #  additional arguments to c++ compiler are passed as $4
470 test_cxx() {
471         AC_MSG_CHECKING("$1")
472         echo "### $1" >> $charmout
473         cat $t >> $charmout
474         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
475         $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 > out 2>&1
476         test_result $? "$1" "$2" "$3"
477         strictpass=$pass
478         strictfail=$fail
479         if test $pass -eq 1
480         then 
481           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
482           then 
483             strictpass="0" && strictfail="1"
484           fi
485         fi
486         cat out >> $charmout
487         /bin/rm -f out
490 # Test: tries to compile C++ file $t (described by $1) using native compiler.
491 #  If successful, prints $2 and sets $pass/clears $fail
492 #  If failure, prints $3 and sets $pass/clears $fail
493 #  additional arguments to c++ compiler are passed as $4
494 test_native_cxx() {
495         AC_MSG_CHECKING("$1")
496         echo "### $1" >> $charmout
497         cat $t >> $charmout
498         echo $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
499         $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
500         test_result $? "$1" "$2" "$3"
501         strictpass=$pass
502         strictfail=$fail
503         if test $pass -eq 1
504         then
505           if grep -i "warn" out > /dev/null 2>&1 || grep -i "(W)" out > /dev/null 2>&1
506           then
507             strictpass="0" && strictfail="1"
508           fi
509         fi
510         cat out >> $charmout
511         /bin/rm -f out
514 # Testlink: tries to compile and link a C++ file $t (described by $1).
515 #  If successful, prints $2 and sets $pass/clears $fail
516 #  If failure, prints $3 and sets $pass/clears $fail
517 #  additional arguments to c++ compiler are passed as $4
518 test_link() {
519         AC_MSG_CHECKING("$1")
520         echo "### $1" >> $charmout
521         cat $t >> $charmout
522         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 >> $charmout
523         $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX -c $t -o test.o $4 > out 2>&1
524         if test $? -ne 0
525         then
526           test_result 1 "$1" "$2" "$3"
527         else
528           echo $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 $5 >> $charmout
529           $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 $5 >> out 2>&1
530           ret=$?
531           test ! -x testlink && ret=1
532           test_result $ret "$1" "$2" "$3"
533         fi
534         strictpass=$pass
535         strictfail=$fail
536         if test $pass -eq 1
537         then 
538           if cat out | grep -i "warn" > /dev/null 2>&1
539           then 
540             strictpass="0" && strictfail="1"
541           fi
542         fi
543         cat out >> $charmout
544         /bin/rm -f out
547 # Testlinkc: tries to compile and link a C file $t (described by $1).
548 #  If successful, prints $2 and sets $pass/clears $fail
549 #  If failure, prints $3 and sets $pass/clears $fail
550 #  additional arguments to c++ compiler are passed as $4
551 test_linkc() {
552         AC_MSG_CHECKING("$1")
553         echo "### $1" >> $charmout
554         cat $tc >> $charmout
555         echo $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 >> $charmout
556         $CMK_CC $CMK_CC_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CC -c $tc -o test.o $4 > out 2>&1
557         if test $? -ne 0
558         then
559           test_result 1 "$1" "$2" "$3"
560         else
561           echo $CMK_LD $CMK_LD_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 >> $charmout
562           $CMK_LD $CMK_LD_FLAGS $CMK_LINK_BINARY -o testlink test.o $CMK_LIBDIR $OPTS_LD $CMK_SYSLIBS $4 >> out 2>&1
563           test_result $? "$1" "$2" "$3"
564         fi
565         strictpass=$pass
566         strictfail=$fail
567         if test $pass -eq 1
568         then 
569           if cat out | grep -i "warn" > /dev/null 2>&1
570           then 
571             strictpass="0" && strictfail="1"
572           fi
573         fi
574         cat out >> $charmout
575         /bin/rm -f out
578 # test_linkso $1 $2 $3 $4, where
579 # $1: debug msg
580 # $2: yes msg
581 # $3: no msg
582 # $4: extra link option
583 test_linkso() {
584         AC_MSG_CHECKING("$1")
585         echo $1 >> $charmout
586         cat $t >> $charmout
587         echo $CMK_CXX $CMK_CXX_FLAGS -I../include -I. $CMK_INCDIR $CMK_SYSINC $OPTS_CXX $CMK_PIC -c $t -o test.o $4 >> $charmout
588         $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
589         if test $? = 1
590         then
591           test_result 1 "$1" "$2" "$3"
592         else
593           echo $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD $CMK_LD_SHARED $CMK_SYSLIBS test.o -o testlink.$CMK_SHARED_SUF $4 >> $charmout
594           $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
595           test_result $? "$1" "$2" "$3"
596         fi
597         cat out >> $charmout
598         /bin/rm -f out testlink.$CMK_SHARED_SUF
601 test_finish() {
602         rm -f $t $tc testlink test.o    > /dev/null 2>&1
603         /bin/rm -f out
604         test $1 -eq 1 && echo "*** Please find detailed output in tmp/charmconfig.out ***"
605         exit $1
608 # detect certain architectures
609 if cat /proc/cpuinfo 2>/dev/null | grep 'POWER7'  > /dev/null
610 then
611   AC_DEFINE_UNQUOTED(CMK_POWER7, 1, [whether is power7])
614 # detect OS
615 OSNAME=`uname -s`
616 if test $OSNAME = "Linux"
617 then
618   AC_DEFINE_UNQUOTED(CMK_OS_IS_LINUX, 1, [OS is Linux])
619 else
620   AC_DEFINE_UNQUOTED(CMK_OS_IS_LINUX, 0, [OS is Linux])
623 # test cp -p
624 AC_MSG_CHECKING("cp command as")
625 CP="cp -p"
626 touch test_file
627 if ! $CP test_file test_file.cp 2>err
628 then
629   CP="cp"
631 rm -f test_file test_file.cp
632 AC_MSG_RESULT($CP)
633 add_flag CP=\""$CP"\" "cp command"
636 cat > $t <<EOT
637 #include <stdio.h>
638 void foo(void) {
639         printf("Hello, world!\n");
643 if test "$CMK_BUILD_CRAY" = "1"
644 then
645 #echo "Test for known incompatible compiler versions"
647  if test "$CRAY_CC_VERSION" = "8.1.4"
648  then
649         echo "CCE 8.1.4 produces incorrect Charm++ code"
650         echo "Please use a newer version of the CCE compiler"
651         echo "e.g. module load cce/8.1.7"
652         test_finish 1
653  fi
656 #echo "set C++ compiler as: $CMK_CXX $OPTS_CXX $OPTS"
657 AC_MSG_CHECKING("C++ compiler as")
658 AC_MSG_RESULT("$CMK_CXX $OPTS_CXX")
659 test_cxx "whether C++ compiler works" "ok" "no" ""
660 if test $fail -eq 1
661 then
662         echo "Cannot compile C++ programs with $CMK_CXX"
663         echo " (check your charm++ version)"
664         test_finish 1
667 cat > $t <<EOT
668 #include <stdio.h>
669 int main() {
670         printf("Hello, world!\n");
671         return 0;
674 #echo "set C++ linker as: $CMK_LDXX $OPTS_LD"
675 AC_MSG_CHECKING("C++ linker as")
676 AC_MSG_RESULT("$CMK_LDXX $OPTS_LD")
677 test_link "whether linker works" "ok" "no" ""
678 if test $fail -eq 1
679 then
680         echo "Cannot link C++ programs with $CMK_LDXX"
681         echo " (check your charm++ version)"
682         test_finish 1
685 AC_MSG_CHECKING("Native C++ compiler as")
686 AC_MSG_RESULT("$CMK_NATIVE_CXX")
687 AC_MSG_CHECKING("Sequential C++ compiler as")
688 AC_MSG_RESULT("$CMK_SEQ_CXX")
690 if echo "$CMK_CC" | grep -E "gcc|clang|icc" > /dev/null 2> /dev/null
691 then
692   test_link "whether compiler accept -fno-stack-protector" "ok" "no" "-fno-stack-protector"
693   if test $strictpass -eq 1
694   then
695         add_flag OPTS_CC='"$OPTS_CC -fno-stack-protector"' "stack-protection disabling"
696         add_flag OPTS_CXX='"$OPTS_CXX -fno-stack-protector"' "stack-protection disabling"
697   fi
700 #### check if C++ compiler will accept C++11 features without warning ####
701 cat > $t <<EOT
702 // Check for Intel compiler incompatibility with the active g++/libstdc++ by
703 // including an arbitrary standard library header (cf bug #1560)
704 #include <map>
706 // Check for an excessively old g++/libstdc++ that can't handle features we use
707 #include <memory>
708 #include <vector>
709 std::unique_ptr<int> i;
711 class CkMigrateMessage;
713 struct base {
714   base(void) { }
715   base(CkMigrateMessage *) { }
718 template <class Parent>
719 struct CBaseT1 : Parent {
720   std::vector<int> v; // check for C++11's shrink_to_fit()
722   CBaseT1(void) :Parent()  { v.shrink_to_fit(); }
723   CBaseT1(CkMigrateMessage *m) :Parent(m) { }
724   CBaseT1(CBaseT1&& rhs) :Parent() { }
726   template <typename... Args>
727     CBaseT1(Args... args) : Parent(args...) { }
730 template struct CBaseT1<base>;
732 got_cpp11=""
733 test_cxx "whether C++ compiler supports C++11 without flags" "yes" "no" ""
734 if test $strictpass -eq 1
735 then
736   got_cpp11="true"
737 else
738 # Flags for g++/clang++/icpc/xlC++, pgCC, and CrayCC respectively
739 for i in "-std=c++11" "--c++11" "-h std=c++11"; do
740     test_cxx "whether C++ compiler supports C++11 with '$i'" "yes" "no" "$i"
741     if test $strictpass -eq 1
742     then
743       add_flag "$(echo OPTS_CXX=\"\$OPTS_CXX $i\")" "Enable C++11 support"
744       OPTS_CXX="$OPTS_CXX $i"
745       got_cpp11="true"
746       break
747     fi
748 done
751 if test -z $got_cpp11
752 then
753   echo "Charm++ requires C++11 support, but doesn't know the flag to enable it"
754   echo
755   echo "For Intel's compiler please see"
756   echo "https://charm.cs.illinois.edu/redmine/issues/1560"
757   echo "about making a suitable version of gcc/g++/libstdc++ available"
758   echo
759   echo "For Blue Gene/Q please use the Clang compiler"
760   test_finish 1
763 test_native_cxx "whether native C++ compiler supports C++11 without flags" "yes" "no" ""
764 if test $strictpass -ne 1
765 then
766   # Flags for g++/clang++/icpc/xlC++, pgCC, and CrayCC respectively
767   for i in "-std=c++11" "--c++11" "-h std=c++11"; do
768     test_native_cxx "whether C++ compiler supports C++11 with '$i'" "yes" "no" "$i"
769     if test $strictpass -eq 1
770     then
771       add_flag "$(echo CMK_NATIVE_CXX_FLAGS=\"\$CMK_NATIVE_CXX_FLAGS $i\")" "Enable C++11 support"
772       break
773     fi
774 done
777 # Workaround for bug #1045 appearing in GCC >6.x
778 test_cxx "whether C++ compiler accepts -fno-lifetime-dse" "yes" "no" "-fno-lifetime-dse"
779 if test $strictpass -eq 1
780 then
781     add_flag "$(echo OPTS_CXX=\"\$OPTS_CXX -fno-lifetime-dse\")" "Disable 'Lifetime DSE' optimization to work around bug #1045 in GCC >6.x"
782     OPTS_CXX="$OPTS_CXX -fno-lifetime-dse"
785 # Determine compiler/linker flags to build libcharm.so for charm4py
786 if test "$enable_charmpy" = "yes"
787 then
789   cat > $t <<EOT
790 int main() { return 0; }
793   test_cxx "whether C++ compiler accepts --no-as-needed" "yes" "no" "--no-as-needed"
794   if test $strictpass -eq 1
795   then
796       add_flag "$(echo CXX_NO_AS_NEEDED=\"--no-as-needed\")" "--no-as-needed flag necessary for compilers that default to linking with --as-needed"
797   fi
799   got_opt_whole_archive=""
800   # Flags for g++/clang++/icpc, Apple-LLVM respectively
801   for i in "-Wl,--whole-archive -Wl,--no-whole-archive" "-Wl,-all_load"; do
802       test_link "whether linker supports '$i'" "yes" "no" "" "$i"
803       if test $strictpass -eq 1
804       then
805         got_opt_whole_archive="true"
806         IFS=' ' read LDXX_WHOLE_ARCHIVE_PRE LDXX_WHOLE_ARCHIVE_POST <<< $i
807         add_flag "$(echo LDXX_WHOLE_ARCHIVE_PRE=\"$LDXX_WHOLE_ARCHIVE_PRE\")" "Flags to link whole archives into libcharm.so"
808         add_flag "$(echo LDXX_WHOLE_ARCHIVE_POST=\"$LDXX_WHOLE_ARCHIVE_POST\")" "Flags to link whole archives into libcharm.so"
809         break
810       fi
811   done
813   if test -z $got_opt_whole_archive
814   then
815     echo "Don't know how to build libcharm.so for Charm4py"
816     test_finish 1
817   fi
820 # Figure out if the user has asked to enable the latest language standards
821 USER_ASKED_FOR_NEW_STD=`echo "$BUILDOPTS" | grep "\-use-new-std" | wc -l`
823 # If the user has asked for the newer standards, check if the compilers know about them
824 if test $USER_ASKED_FOR_NEW_STD -ge 1
825 then
827 #### check if c compiler supports c11 compilation flags ####
828 cat > $tc <<EOT
829 #include <stdio.h>
831 int foo()
833   return 0;
836 test_cc "whether c compiler knows of the c11 standard" "ok" "no" "$CMK_ENABLE_C11"
837 AC_DEFINE_UNQUOTED(CMK_COMPILER_KNOWS_C11, $pass, [whether c compiler knows of the c11 standard] )
838 if test $pass -eq 1
839 then
840         # Record results for charmc's future use
841         add_flag 'CMK_COMPILER_KNOWS_C11="1"' "c11"
842         # For the rest of configure, append this to compilation flags
843         OPTS_CC="$CMK_ENABLE_C11 $OPTS_CC"
845 fi # endif USER_ASKED_FOR_NEW_STD
847 # Perform the tests
849 AC_ARG_WITH([refnum-type],
850             [AS_HELP_STRING([--with-refnum-type=type],
851                             [size of the envelope refnum field])],
852             [], [with_refnum_type=no])
854 if test "$with_refnum_type" = "no" -o "$with_refnum_type" = "short"
855 then
856   Echo "Setting charm++ envelope refnum field to unsigned short"
857   AC_DEFINE_UNQUOTED(CMK_REFNUM_TYPE, unsigned short, [envelope refnum field set to UShort])
858 elif test "$with_refnum_type" = "int"
859 then
860   Echo "Setting charm++ envelope refnum field to unsigned int"
861   AC_DEFINE_UNQUOTED(CMK_REFNUM_TYPE, unsigned int, [envelope refnum field set to UInt])
862 else
863   Echo "Invalid size specified for refnum field"
864   test_finish 1
868 AC_ARG_WITH([prio-type],
869             [AS_HELP_STRING([--with-prio-type=type],
870                             [size of expected message priorities])],
871             [], [with_prio_type=bitvec])
873 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"
874 then
875   Echo "Configuring support for message priorities of sizeof type $with_prio_type"
876   AC_DEFINE_UNQUOTED(CMK_USE_STL_MSGQ, 1, [whether charm scheduler should use an STL-based msg q])
877   AC_DEFINE_UNQUOTED(CMK_MSG_PRIO_TYPE, $with_prio_type, [expected message priorities are sizeof $with_prio_type])
878 elif test "$with_prio_type" = "bitvec"
879 then
880   Echo "Configuring support for message priorities of arbitrary size (bitvectors)"
881   AC_DEFINE_UNQUOTED(CMK_USE_STL_MSGQ, 0, [whether charm scheduler should use an STL-based msg q])
882   AC_DEFINE_UNQUOTED(CMK_MSG_PRIO_TYPE, $with_prio_type, [expected message priorities are arbitrarily sized])
883 else
884   Echo "Invalid size ($with_prio_type) specified for message priorities. Can only accept char, short, int, long, float, double and bitvec"
885   test_finish 1
888 # enable/disable randomized scheduler queue
889 AC_ARG_ENABLE([randomized-msgq],
890             [AS_HELP_STRING([--enable-randomized-msgq],
891               [enable a randomized msg queue (for debugging etc)])], ,
892             [enable_randomized_msgq=no])
894 if test "$enable_randomized_msgq" = "yes" -a "$with_prio_type" != "bitvec"
895 then
896   Echo "The charm message queue will be randomized (and will not respect priorities)"
897   AC_DEFINE_UNQUOTED(CMK_RANDOMIZED_MSGQ, 1, [enable the randomized msgq in the scheduler])
898 else
899   AC_DEFINE_UNQUOTED(CMK_RANDOMIZED_MSGQ, 0, [disable the randomized msgq in the scheduler])
900   if test "$enable_randomized_msgq" = "yes"
901   then
902     Echo 'A randomized message queue is only available when --with-prio-type != bitvec.'
903     Echo "Specify prio-type to be a data type long enough to hold the message priorities in your application"
904     Echo "for example: --with-prio-type=int (or short / long etc)."
905     test_finish 1
906   fi
909 AC_ARG_WITH([mempool-cutoff],
910             [AS_HELP_STRING([--with-mempool-cutoff=N],
911                             [exponent of the maximum power of two to use for bin sizes in the mempool])],
912             [], [with_mempool_cutoff=26])
914 if test "$((6 < $with_mempool_cutoff && $with_mempool_cutoff < 32))" = '1'
915 then
916   Echo "Using mempool cutoff... 2^$with_mempool_cutoff"
917   AC_DEFINE_UNQUOTED(CMK_MEMPOOL_CUTOFFNUM, $((with_mempool_cutoff - 6)), [mempool cutoff])
918 else
919   Echo "Invalid number ($with_mempool_cutoff) specified for mempool cutoff. Valid range: 7 <= N <= 31"
920   test_finish 1
923 #### Check if compiler if 64 bit ####
924 cat > $t <<EOT
925 #include <stdio.h>
927 int foo()
929 int x[[(int)(sizeof(void *) - 7)]]={0};
930 return x[[0]];
933 test_cxx "whether compiler generates code for 64-bit" "yes" "no" ""
934 AC_DEFINE_UNQUOTED(CMK_SIZET_64BIT, $strictpass, [whether size_t 64bit])
935 in64bit=$strictpass
937 ### Check if compiler supports std::is_constructible<> ###
938 cat > $t <<EOT
939 #include <type_traits>
941 struct s {
942        s(int a) { }
945 bool foo()
947   return std::is_constructible<s, int>::value;
950 test_cxx "whether compiler supports std::is_constructible" "yes" "no" ""
951 AC_DEFINE_UNQUOTED(CMK_HAS_IS_CONSTRUCTIBLE, $strictpass, [whether compiler supports std::is_constructible])
953 ### Check if compiler supports std::alignment_of<> ###
954 cat > $t <<EOT
955 #include <type_traits>
957 int foo()
959   return std::alignment_of<int>::value;
962 test_cxx "whether compiler supports std::alignment_of" "yes" "no" ""
963 AC_DEFINE_UNQUOTED(CMK_HAS_ALIGNMENT_OF, $strictpass, [whether compiler supports std::alignment_of])
965 ### Check if compiler implements regex ###
966 cat > $t <<EOT
967 #include <regex>
968 void foo()
970 #if __cplusplus >= 201103L &&                             \
971     (!defined(__GLIBCXX__) || (__cplusplus >= 201402L) || \
972         (defined(_GLIBCXX_REGEX_DFS_QUANTIFIERS_LIMIT) || \
973          defined(_GLIBCXX_REGEX_STATE_LIMIT)           || \
974              (defined(_GLIBCXX_RELEASE)                && \
975              _GLIBCXX_RELEASE > 4)))
976 // compiler has regex support, continue
977 #else
978 // force compilation to fail
979 static_assert(false, "compiler has no regex implementation");
980 #endif
983 test_cxx "whether compiler implements regex" "yes" "no" ""
984 AC_DEFINE_UNQUOTED(CMK_HAS_REGEX, $pass, [whether compiler implements regex])
986 #### test if has values.h ####
987 cat > $t <<EOT
988 #include <values.h>
989 int main() { 
990   double d = MAXDOUBLE;
991   return 0;
994 test_cxx "whether has values.h " "yes" "no" ""
995 AC_DEFINE_UNQUOTED(CMK_HAS_VALUES_H, $pass, [whether has values.h])
997 #### test if has stdint.h ####
998 cat > $t <<EOT
999 #include <stdint.h>
1000 int main() { 
1001   return 0;
1004 test_cxx "whether has stdint.h " "yes" "no" ""
1005 AC_DEFINE_UNQUOTED(CMK_HAS_STDINT_H, $pass, [whether has stdint.h])
1007 #### test if has malloc.h ####
1008 cat > $t <<EOT
1009 #include <malloc.h>
1010 int main() { 
1011   return 0;
1014 test_cxx "whether has malloc.h " "yes" "no" ""
1015 AC_DEFINE_UNQUOTED(CMK_HAS_MALLOC_H, $pass, [whether has malloc.h])
1017 #### test if has alloca.h ####
1018 cat > $t <<EOT
1019 #include <alloca.h>
1020 int main() {
1021   double *s=(double *)alloca(sizeof(double));
1022   *s=1.0;
1023   return 0;
1026 test_cxx "whether has alloca.h " "yes" "no" ""
1027 AC_DEFINE_UNQUOTED(CMK_HAS_ALLOCA_H, $pass, [whether has alloca.h])
1029 #### test if has regex.h ####
1030 cat > $t <<EOT
1031 #include <regex.h>
1032 int main() {
1033   regex_t re;
1034   regcomp(&re, ".*MOD.*", REG_EXTENDED|REG_NOSUB);
1035   return 0;
1038 test_cxx "whether has regex.h " "yes" "no" ""
1039 AC_DEFINE_UNQUOTED(CMK_HAS_REGEX_H, $pass, [whether has regex.h])
1041 #### Check long long ####
1042 cat > $t <<EOT
1043 #include <stdlib.h>
1044 long long foo(void) { return 17; }
1046 test_cxx "whether long long works" "yes" "no" ""
1047 AC_DEFINE_UNQUOTED(CMK_LONG_LONG_DEFINED, $pass, [whether long long works])
1049 #### Check __int64 ####
1050 cat > $t <<EOT
1051 #include <stdlib.h>
1052 __int64 foo(void) { return 17; }
1054 test_cxx "whether __int64 works" "yes" "no" ""
1055 AC_DEFINE_UNQUOTED([CMK___int64_DEFINED], $pass, [whether __int64 works])
1058 CMK_HAS_INT16=0
1060 #### Check __int128 ####
1061 cat > $t <<EOT
1062 #include <stdlib.h>
1063 int foo(void) {
1064   __int128   a;
1065   int x[[(int)(sizeof(__int128) - 15)]]={0};
1066   return x[[0]];
1069 test_cxx "whether __int128 (128-bit integer) works" "yes" "no" ""
1070 AC_DEFINE_UNQUOTED([CMK___int128_DEFINED], $pass, [whether __int128 works])
1071 if test $pass -eq 1
1072 then
1073   CMK_HAS_INT16=1
1074   add_flag CMK_HAS_INT16=1
1077 #### Check __int128_t ####
1078 cat > $t <<EOT
1079 #include <stdlib.h>
1080 int foo(void) {
1081   __int128_t   a;
1082   __uint128_t   b;
1083   a = a + a;
1084   int x[[(int)(sizeof(__int128_t) - 15)]]={0};
1085   return x[[0]];
1088 test_cxx "whether __int128_t (128-bit integer) works" "yes" "no" ""
1089 AC_DEFINE_UNQUOTED([CMK___int128_t_DEFINED], $pass, [whether __int128_t works])
1090 if test $pass -eq 1
1091 then
1092   CMK_HAS_INT16=1
1093   add_flag CMK_HAS_INT16=1
1096 #### Summarize *int128* ####
1098 AC_DEFINE_UNQUOTED([CMK_HAS_INT16], $CMK_HAS_INT16, [whether any 128-bit integer works])
1101 ### Check if we have C++11 <atomic> ###
1102 cat > $t <<EOT
1103 #include <atomic>
1104 int main(int argc, char** argv) { 
1105   return 0;
1108 test_cxx "whether C++ library has <atomic> " "yes" "no" ""
1109 AC_DEFINE_UNQUOTED(CMK_HAS_CXX11_ATOMIC, $pass, [whether C++ library has <atomic>])
1111 if test $pass -ne 1
1112 then
1113 ### Check if we have pre-C++11 <cstdatomic> ###
1114 cat > $t <<EOT
1115 #include <cstdatomic>
1116 int main(int argc, char** argv) { 
1117   return 0;
1120 test_cxx "whether C++ library has <cstdatomic> " "yes" "no" ""
1121 AC_DEFINE_UNQUOTED(CMK_HAS_CXX0X_CSTDATOMIC, $pass, [whether C++ library has <cstdatomic>])
1124 if test $pass -ne 1 -a "$CMK_COMPILER" != "bgxlc"
1125 then
1126         echo "Charm++ requires C++11 atomic support"
1127         test_finish 1
1130 #### Check long double ####
1131 cat > $t <<EOT
1132 #include <stdlib.h>
1133 long double foo(void) { return 17.0; }
1135 test_cxx "whether long double works" "yes" "no" ""
1136 AC_DEFINE_UNQUOTED(CMK_LONG_DOUBLE_DEFINED, $strictpass, [whether long double works])
1138 #### Check ucontext and FPU pointer ####
1139 cat > $t <<EOT
1140 #include <ucontext.h>
1141 struct _libc_fpstate   fpstate;
1142 fpregset_t *fp;
1144 test_cxx "whether ucontext has FPU pointer" "yes" "no" ""
1145 AC_DEFINE_UNQUOTED(CMK_CONTEXT_FPU_POINTER, $pass, [whether ucontext has pointer])
1147 if test $pass -eq 1
1148 then
1149 cat > $t <<EOT
1150 #include <ucontext.h>
1152 int main()
1154   ucontext_t context;
1155   context.uc_mcontext.uc_regs = 0;
1158 test_cxx "whether ucontext uses uc_regs" "yes" "no" ""
1159 AC_DEFINE_UNQUOTED(CMK_CONTEXT_FPU_POINTER_UCREGS, $pass, [whether ucontext uses uc_regs union])
1162 cat > $t <<EOT
1163 #include <ucontext.h>
1164 vrregset_t *v_regs;
1165 ucontext_t  uc;
1167 void foo()
1169   vrregset_t *ptr = uc.uc_mcontext.v_regs;
1172 test_cxx "whether ucontext has pointer (v_regs) of vector type" "yes" "no" ""
1173 AC_DEFINE_UNQUOTED(CMK_CONTEXT_V_REGS, $pass, [whether ucontext has pointer (v_regs) of vector type])
1175 #### Check ucontext and FPU pointer ####
1176 cat > $t <<EOT
1177 #include <infiniband/verbs.h>
1178 void test()
1180     struct ibv_context    *context;
1181     int ibPort;
1182     struct ibv_port_attr attr;
1183     if (ibv_query_port(context, ibPort, &attr) != 0) return;
1184     if (attr.link_layer == IBV_LINK_LAYER_INFINIBAND)  return;
1187 test_cxx "whether ibverbs ibv_port_attr has link_layer field" "yes" "no" ""
1188 AC_DEFINE_UNQUOTED(CMK_IBV_PORT_ATTR_HAS_LINK_LAYER, $pass, [whether ibv_port_attr has link_layer field])
1191 ###################### C++ Compiler Features #####################
1193 #### check C inline ####
1194 cat > $tc <<EOT
1195 inline static int foo()
1197   return 1;
1200 test_cc "whether inline works in C" "yes" "no" ""
1201 AC_DEFINE_UNQUOTED(CMK_C_INLINE, $strictpass, [whether C inline works in C])
1203 #### check if signed char is same as char ####
1204 cat > $t <<EOT
1205 #include <stdlib.h>
1206 class er {
1207  protected:
1208    void operator()(char &v,const char *desc=NULL) {};
1209    void operator()(signed char &v,const char *desc=NULL) {};
1212 test_cxx "whether C++ signed char and char differ" "yes" "no" ""
1213 AC_DEFINE_UNQUOTED(CMK_SIGNEDCHAR_DIFF_CHAR, $pass, [whether C++ signed char and char differ])
1215 #### check if typeinfo exists and works #####
1216 cat > $t <<EOT
1217 #include <typeinfo>
1218 const char *foo(void) {
1219         int x;
1220         return typeid(x).name();
1223 test_cxx "whether typeinfo/typeid works" "ok" "no" ""
1224 AC_DEFINE_UNQUOTED(CMK_HAS_TYPEINFO, $pass, [whether typeinfo/typeid works])
1226 #### check if iterator_traits is defined #####
1227 cat > $t <<EOT
1228 #include <iterator>
1230 template <typename T> // T models Input Iterator
1231 typename std::iterator_traits<T>::value_type accumulate(T first, T last)
1233       typename std::iterator_traits<T>::value_type result = 0;
1234       while(first != last)
1235             result += *first++;
1236       return result;
1239 test_cxx "whether std::iterator_traits is defined" "ok" "no" ""
1240 AC_DEFINE_UNQUOTED(CMK_HAS_ITERATOR_TRAITS, $pass, [whether iterator_traits works])
1242 #### check if std::distance is defined #####
1243 cat > $t <<EOT
1244 #include <vector>
1245 #include <iterator>
1247 int foo()
1249   std::vector<int> tree;
1250   return std::distance(tree.begin(), tree.end());
1253 test_cxx "whether std::distance is defined" "ok" "no" ""
1254 AC_DEFINE_UNQUOTED(CMK_HAS_STD_DISTANCE, $pass, [whether std::distance works])
1256 #### check if std::inserter is defined #####
1257 cat > $t <<EOT
1258 #include <list>
1259 #include <iterator>
1261 void foo()
1263   using namespace std;
1264   list<int> L;
1265   inserter ( L, L.end ( ) ) = 500;
1268 test_cxx "whether std::inserter is defined" "ok" "no" ""
1269 AC_DEFINE_UNQUOTED(CMK_HAS_STD_INSERTER, $pass, [whether std::inserter works])
1271 #### check if C++17's std::void_t is defined #####
1272 cat > $t <<EOT
1273 #include <type_traits>
1275 template<typename T, typename = std::void_t<>>
1276 struct has_pup_member : std::false_type {};
1279 test_cxx "whether std::void_t is defined" "ok" "no" ""
1280 AC_DEFINE_UNQUOTED(CMK_HAS_STD_VOID_T, $pass, [whether std::void_t works])
1282 ####### Check support for features added by the new C11 and CPP11 standards ########
1284 #### test if we can have multiple delete like this ####
1285 cat > $t <<EOT
1286 class foo {
1287 public:
1288   void operator delete(void*p){};
1289   void operator delete(void*p,int*){};
1292 test_cxx "whether operator delete can be overloaded in same class" "ok" "no" ""
1293 AC_DEFINE_UNQUOTED(CMK_MULTIPLE_DELETE, $strictpass, [whether operator delete can be overloaded in same class])
1295 #### test if offsetof exists ####
1296 cat > $t <<EOT
1297 #include <stddef.h>
1299 struct FooType {
1300         int f1;
1301         int f2;
1302         double f3;
1305 void foo()
1307   int off = offsetof(FooType, f2);
1310 test_cxx "whether offsetof is defined" "yes" "no" ""
1311 AC_DEFINE_UNQUOTED(CMK_HAS_OFFSETOF, $pass, [whether offsetof exists])
1313 #### test if we can use gcc x86 assembly like this ####
1314 cat > $t <<EOT
1315 double foo(void)
1317   unsigned long long int v=0;
1318   int *lo=0+(int *)&v;
1319   int *hi=1+(int *)&v;
1320   __asm__ __volatile__(
1321       "rdtsc; movl %%edx,%0; movl %%eax,%1"
1322       : /* output  */ "=m" (*hi), "=m" (*lo)
1323       : /* input */
1324       : /* trashes */ "%edx", "%eax"
1325   );
1326   return v;
1329 test_cxx "whether GCC x86 assembly works" "yes" "no" ""
1330 AC_DEFINE_UNQUOTED(CMK_GCC_X86_ASM, $strictpass, [Allows gcc x86 assembly.])
1332 #### test if we can use gcc x86 assembly like this ####
1333 if test $strictpass = 1
1334 then
1335 cat > $t <<EOT
1336 int foo(void)
1338   int x;
1339   asm("lock incl %0" :: "m" (x));
1340   asm("lock decl %0" :: "m" (x));
1341   return x;
1344 test_cxx "whether GCC x86 assembly for atomic increment works" "yes" "no" ""
1345 AC_DEFINE_UNQUOTED(CMK_GCC_X86_ASM_ATOMICINCREMENT, $strictpass, [Allows gcc x86 assembly for atomic increment.])
1348 #### test if we can use asm eieio assembly like this ####
1349 cat > $t <<EOT
1350 double foo(void)
1352         unsigned long long int x;
1353         asm volatile("eieio" ::: "memory");
1354         return x;
1357 test_cxx "whether asm eieio assembly works" "yes" "no" ""
1358 AC_DEFINE_UNQUOTED(CMK_PPC_ASM, $strictpass, [Allows asm eieio assembly.])
1362 #### test if we can use __thread ####
1363 cat > $t <<EOT
1364 __thread unsigned long long int x;
1365 static __thread  int y;
1366 void foo(void)
1368         x = 1;
1369         y = 1;
1372 test_cxx "whether __thread (Thread Local Storage) is supported" "yes" "no" ""
1373 AC_DEFINE_UNQUOTED(CMK_HAS_TLS_VARIABLES, $strictpass, [Allows __thread.])
1375 #### check __sync_add_and_fetch ####
1376 cat > $tc <<EOT
1377 #include <stdio.h>
1378 int main()
1380   int t=1;
1381   __sync_add_and_fetch(&t, 1);
1382   return 1;
1385 test_linkc "whether synchronization primitives (__sync_add_and_fetch) works in C" "yes" "no" ""
1386 AC_DEFINE_UNQUOTED(CMK_C_SYNC_ADD_AND_FETCH_PRIMITIVE, $pass, [whether sync_add_and_fetch primitive works in C])
1388 #### check __sync_synchronize ####
1389 cat > $tc <<EOT
1390 #include <stdio.h>
1391 int main()
1393   __sync_synchronize();
1397 test_linkc "whether synchronization primitives (__sync_synchronize) works in C" "yes" "no" ""
1399 AC_DEFINE_UNQUOTED(CMK_C_SYNC_SYNCHRONIZE_PRIMITIVE, $pass, [whether sync_synchronize primitives works in C])
1402 ### test for __executable_start ###
1404 cat > $tc <<EOT
1405 extern int __executable_start;
1406 int main()
1408   return __executable_start;
1411 test_linkc "whether has __executable_start" "yes" "no" ""
1412 AC_DEFINE_UNQUOTED([CMK_HAS_EXECUTABLE_START], $pass, [whether has __executable_start])
1414 ### test if switching TLS register ###
1415 if test $in64bit = 1
1416 then
1417 cat > $t <<EOT
1418 #include <elf.h>
1419 #include <stdlib.h>
1420 #include <malloc.h>
1422 void switchTLS() {
1423   Elf64_Addr m1, m2;
1424   asm volatile ("movq %%fs:0x0, %0\n\t"
1425                 "movq %1, %%fs:0x0\n\t"
1426                 : "=r"(m1)
1427                 : "r"(m2));
1430 test_cxx "whether switching TLS register (64-bit) is supported" "yes" "no" ""
1431 AC_DEFINE_UNQUOTED(CMK_TLS_SWITCHING64, $strictpass, [Allows switching TLS 64-bit.])
1432 else
1433 cat > $t <<EOT
1434 #include <elf.h>
1435 #include <stdlib.h>
1436 #include <malloc.h>
1438 void switchTLS() {
1439   Elf32_Addr m1, m2;
1440   asm volatile ("movl %%gs:0x0, %0\n\t"
1441                 "movl %1, %%gs:0x0\n\t"
1442                 : "=r"(m1)
1443                 : "r"(m2));
1446 test_cxx "whether switching TLS register (32-bit) is supported" "yes" "no" ""
1447 AC_DEFINE_UNQUOTED(CMK_TLS_SWITCHING32, $strictpass, [Allows switching TLS in 32-bit.])
1450 ### test for dl_iterate_phdr ###
1452 cat > $tc <<EOT
1453 #ifndef _GNU_SOURCE
1454 # define _GNU_SOURCE
1455 #endif
1456 #ifndef __USE_GNU
1457 # define __USE_GNU
1458 #endif
1459 #include <link.h>
1460 #include <stddef.h>
1461 static int callback(struct dl_phdr_info* info, size_t size, void* data)
1463   return 0;
1465 int main()
1467   dl_iterate_phdr(callback, NULL);
1468   return 0;
1471 test_linkc "whether has dl_iterate_phdr" "yes" "no" ""
1472 AC_DEFINE_UNQUOTED([CMK_HAS_DL_ITERATE_PHDR], $pass, [whether has dl_iterate_phdr])
1475 ### test for __malloc_hook ###
1477 cat > $tc <<EOT
1478 extern int __malloc_hook;
1479 int main()
1481   return __malloc_hook;
1484 test_linkc "whether has __malloc_hook" "yes" "no" ""
1485 AC_DEFINE_UNQUOTED([CMK_HAS_MALLOC_HOOK], $pass, [whether has __malloc_hook])
1486 add_make_flag "CMK_HAS_MALLOC_HOOK:=$pass" 'whether has __malloc_hook'
1489 #### test if we can build OFI ####
1490 if test "$CMK_BUILD_OFI" = 1
1491 then
1492 cat > $tc <<EOT
1493 #include <rdma/fabric.h>
1494 int main(int argc, char **argv)
1496   struct fi_info *providers;
1497   int ret = fi_getinfo(FI_VERSION(1,0), NULL, NULL, 0ULL, NULL, &providers);
1498   return 0;
1501 test_cc "whether build on OFI" "yes" "no" "-lfabric"
1502 AC_DEFINE_UNQUOTED(CMK_BUILD_ON_OFI, $strictpass, [build OFI.])
1503 BUILD_OFI=$strictpass
1505 if test $BUILD_OFI -eq 0
1506 then
1507   echo "Error: Unable to compile OFI"
1508   test_finish 1
1509 else
1510   test_linkc "whether -lfabric" "ok" "no" "-lfabric"
1511   if test $pass -eq 0
1512   then
1513     #test for psm incompatibility
1514     PSM_COMPAT_DIR=/usr/lib64/psm2-compat
1515     if test -d $PSM_COMPAT_DIR
1516     then
1517       add_flag CMK_LIBDIR='"$CMK_LIBDIR -Wl,-rpath=/usr/lib64/psm2-compat"' "psm2-compat lib"
1518       CMK_LIBDIR="$CMK_LIBDIR -Wl,-rpath=/usr/lib64/psm2-compat"
1519       test_linkc "whether -lfabric after adding psm2-compatible library" "ok" "no" "-lfabric"
1520       if test $pass -eq 0
1521       then
1522         echo "Error: -lfabric not found or not working. Pass '--basedir=/path/to/dir/' if -lfabric is located in a different directory"
1523         test_finish 1
1524       fi
1525     else
1526       echo "Error: -lfabric not working, $PSM_COMPAT_DIR not found"
1527       echo "Pass '--basedir=/path/to/dir/' if -lfabric is located in a different directory"
1528       test_finish 1
1529     fi
1530   fi
1535 #### test if we can build MPI ####
1536 if test "$CMK_BUILD_MPI" = 1
1537 then
1539 cat > $tc <<EOT
1540 #include "mpi.h"
1541 int main(int argc, char **argv)
1543   MPI_Init(&argc, &argv);
1544   return 0;
1547 mv -f ../include/mpi.h ../include/mpi.h.bak 2>/dev/null
1548 test_cc "whether build on MPI" "yes" "no" ""
1549 AC_DEFINE_UNQUOTED(CMK_BUILD_ON_MPI, $strictpass, [build MPI.])
1550 BUILD_MPI=$strictpass
1552 if test $BUILD_MPI -eq 0
1553 then
1554   echo "Error: Cannot compile an MPI program"
1555   test_finish 1
1558 if test $BUILD_MPI -eq 1
1559 then
1560   test_linkc "whether need to specify MPI library" "no" "yes" ""
1561   if test $pass -ne 1
1562   then
1563     if test -z "$CMK_MPI_LIB"
1564     then
1565       test_linkc "whether -lmpich" "ok" "no" "-lmpich"
1566       if test $pass -eq 1
1567       then
1568         add_flag CMK_SYSLIBS='"$CMK_SYSLIBS -lmpich"' "mpi lib"
1569       else
1570         test_linkc "whether -lmpi" "ok" "no" "-lmpi"
1571         if test $pass -eq 1
1572         then
1573                 add_flag CMK_SYSLIBS='"$CMK_SYSLIBS -lmpi"' "mpi lib"
1574         else
1575                 echo "Error: Cannot find MPI library"
1576                 test_finish 1
1577         fi
1578       fi
1579     else
1580       add_flag CMK_SYSLIBS='"$CMK_SYSLIBS $CMK_MPI_LIB"' "mpi lib"
1581     fi
1582   fi
1585 if test "$BUILD_MPI" = "1"
1586 then
1587 cat > $t <<EOT
1588 #include "mpi.h"
1589 int main(int argc, char **argv)
1591   int thread_level, provided;
1592   thread_level = MPI_THREAD_FUNNELED;
1593   MPI_Init_thread(&argc, &argv, thread_level, &provided);
1596 test_cxx "whether MPI_Init_thread is supported" "yes" "no" ""
1597 AC_DEFINE_UNQUOTED(CMK_MPI_INIT_THREAD, $strictpass, [Allows MPI_Init_thread.])
1599 mv -f ../include/mpi.h.bak ../include/mpi.h 2>/dev/null
1603 if test "$BUILD_MPI" = "1"
1604 then
1606 cat > $t <<EOT
1607 #include <stdio.h>
1608 #include <mpi.h>
1610 int main (int argc, char** argv) {
1611   return 0;
1614 test_cxx "whether macro conflicts occurs due to C++ MPI bindings" "no" "yes" ""
1615 AC_DEFINE_UNQUOTED(CMK_CXX_MPI_BINDINGS, $strictpass, [Disables conflicting macros.])
1619 ################### Syscalls and Libraries ###################
1621 #### test for getrusage with RUSAGE_THREAD ###
1622 cat > $tc <<EOT
1623 #ifndef _GNU_SOURCE
1624 # define _GNU_SOURCE
1625 #endif
1626 #ifndef __USE_GNU
1627 # define __USE_GNU
1628 #endif
1629 #include <sys/time.h>
1630 #include <sys/resource.h>
1631 int main() {
1632   struct rusage usage;
1633   getrusage(RUSAGE_THREAD, &usage);
1634   return 0;
1637 test_linkc "whether getrusage accepts RUSAGE_THREAD" "yes" "no" ""
1638 AC_DEFINE_UNQUOTED(CMK_HAS_RUSAGE_THREAD, $pass, [whether getrusage accepts RUSAGE_THREAD])
1640 #### test for asctime ###
1642 cat > $tc <<EOT
1643 #include <time.h>
1644 int main() {
1645   struct tm *local;
1646   time_t t;
1647   t = time(NULL);
1648   local = localtime(&t);
1649   asctime(local);
1650   return 0;
1653 test_linkc "whether has asctime" "yes" "no" ""
1654 AC_DEFINE_UNQUOTED(CMK_HAS_ASCTIME, $pass, [whether has asctime])
1656 #### test for log2 ###
1657 cat > $t <<EOT
1658 #include <math.h>
1659 int main() {
1660   int i = log2(10);
1661   return 0;
1664 test_link "whether has log2" "yes" "no" ""
1665 AC_DEFINE_UNQUOTED(CMK_HAS_LOG2, $pass, [whether has log2])
1667 #### test for sqrtf ###
1668 cat > $t <<EOT
1669 #include <math.h>
1670 int main() {
1671   float i = sqrtf((float)10.0);
1672   return 0;
1675 test_link "whether has sqrtf" "yes" "no" ""
1676 AC_DEFINE_UNQUOTED(CMK_HAS_SQRTF, $pass, [whether has sqrtf])
1678 #### test for fabsf ###
1679 cat > $t <<EOT
1680 #include <math.h>
1681 int main() {
1682   float i = fabsf((float)10.0);
1683   return 0;
1686 test_link "whether has fabsf" "yes" "no" ""
1687 AC_DEFINE_UNQUOTED(CMK_HAS_FABSF, $pass, [whether has fabsf])
1689 #### test for mkstemp ###
1690 cat > $t <<EOT
1691 #include <stdlib.h>
1692 #include <string.h>
1693 int main() {
1694   char fname[[128]];
1695   strcpy(fname, "/tmp/fdXXX.XXX");
1696   mkstemp(fname);
1697   return 0;
1700 test_link "whether has mkstemp" "yes" "no" ""
1701 AC_DEFINE_UNQUOTED(CMK_USE_MKSTEMP, $pass, [whether has mkstemp])
1703 #### test for system ###
1704 cat > $t <<EOT
1705 #include <stdlib.h>
1706 int main() {
1707   system("/bin/ls");
1708   return 0;
1711 test_link "whether has system" "yes" "no" ""
1712 AC_DEFINE_UNQUOTED(CMK_HAS_SYSTEM, $pass, [whether has system])
1714 #### test for sync() ###
1715 cat > $t <<EOT
1716 #include <unistd.h>
1717 int main() {
1718   sync();
1719   return 0;
1722 test_link "whether has sync()" "yes" "no" ""
1723 AC_DEFINE_UNQUOTED(CMK_HAS_SYNC_FUNC, $pass, [whether has sync])
1725 #### test for fsync() ###
1726 cat > $t <<EOT
1727 #include <unistd.h>
1728 int main() {
1729   fsync(0);
1730   return 0;
1733 test_link "whether has fsync()" "yes" "no" ""
1734 AC_DEFINE_UNQUOTED(CMK_HAS_FSYNC_FUNC, $pass, [whether has fsync])
1736 #### test for fdatasync() ###
1737 cat > $t <<EOT
1738 #include <unistd.h>
1739 int main() {
1740   fdatasync(0);
1741   return 0;
1744 test_link "whether has fdatasync()" "yes" "no" ""
1745 AC_DEFINE_UNQUOTED(CMK_HAS_FDATASYNC_FUNC, $pass, [whether has fdatasync])
1747 #### test for sbrk ###
1748 cat > $t <<EOT
1749 #include <unistd.h>
1750 int main() {
1751   void *ptr  = sbrk(0); 
1754 test_link "whether has sbrk" "yes" "no" ""
1755 AC_DEFINE_UNQUOTED(CMK_HAS_SBRK, $pass, [whether has sbrk])
1757 #### test for _setjmp/_longjmp ###
1758 cat > $t <<EOT
1759 #include <setjmp.h>
1760 int main() {
1761   jmp_buf buf;
1762   _setjmp(buf);
1763   _longjmp(buf, 0);
1766 test_link "whether has _setjmp/_longjmp" "yes" "no" ""
1767 AC_DEFINE_UNQUOTED(CMK_HAS_UNDERSCORE_SETJMP, $pass, [whether has _setjmp/_longjmp])
1769 #### test for mstats ###
1770 cat > $t <<EOT
1771 #include <malloc.h>
1772 int main() {
1773   struct mstats ms = mstats();
1776 test_link "whether has mstats" "yes" "no" ""
1777 AC_DEFINE_UNQUOTED(CMK_HAS_MSTATS, $pass, [whether has mstats])
1779 #### test for mallinfo ###
1780 cat > $t <<EOT
1781 #include <malloc.h>
1782 int main() {
1783   struct mallinfo mi = mallinfo();
1786 test_link "whether has mallinfo" "yes" "no" ""
1787 AC_DEFINE_UNQUOTED(CMK_HAS_MALLINFO, $pass, [whether has mallinfo])
1789 #### test for __morecore ###
1790 cat > $t <<EOT
1791 #include <cstddef>
1792 int main() {
1793   extern void *(*__morecore)(ptrdiff_t);
1794   __morecore(0);
1795   return 0;
1798 test_link "whether expects __morecore symbol" "yes" "no" ""
1799 AC_DEFINE_UNQUOTED(CMK_EXPECTS_MORECORE, $pass, [whether expects __morecore symbol])
1801 #### test for popen ###
1802 cat > $t <<EOT
1803 #include <stdio.h>
1804 int main() {
1805   FILE *p = popen("/bin/ps", "r");
1806   pclose(p);
1809 test_link "whether has popen" "yes" "no" ""
1810 AC_DEFINE_UNQUOTED(CMK_HAS_POPEN, $pass, [whether has popen])
1812 #### test for poll ###
1813 cat > $t <<EOT
1814 #include <poll.h>
1815 void foo(void) { 
1816   struct pollfd pos[[3]];
1817   poll(pos, 1, 1);
1820 test_cxx "whether has poll" "yes" "no" ""
1821 AC_DEFINE_UNQUOTED(CMK_USE_POLL, $pass, [whether the poll syscall exists])
1823 #### check if getpagesize exists ####
1824 cat > $tc <<EOT
1825 #include <unistd.h>
1827 int main(int argc, char **argv) {
1828     int s = getpagesize();
1831 test_linkc "whether has getpagesize" "yes" "no" ""
1832 AC_DEFINE_UNQUOTED(CMK_HAS_GETPAGESIZE, $pass, [whether getpagesize exists])
1834 #### check if getpid exists ####
1835 cat > $tc <<EOT
1836 #include <sys/types.h>
1837 #include <unistd.h>
1839 int main(int argc, char **argv) {
1840     pid_t pid = getpid();
1843 test_linkc "whether has getpid" "yes" "no" ""
1844 AC_DEFINE_UNQUOTED(CMK_HAS_GETPID, $pass, [whether getpid exists])
1846 #### check if kill exists ####
1847 cat > $tc <<EOT
1848 #include <sys/types.h>
1849 #include <unistd.h>
1850 #include <signal.h>
1852 int main(int argc, char**argv) 
1854     pid_t pid = getpid();
1855     kill(pid, 9);
1858 test_linkc "whether has kill" "yes" "no" ""
1859 AC_DEFINE_UNQUOTED(CMK_HAS_KILL, $pass, [whether kill exists])
1861 #### test for setpriority ###
1862 cat > $t <<EOT
1863 #include <sys/time.h>
1864 #include <sys/resource.h>
1865 void foo(void) { 
1866   setpriority(PRIO_PROCESS, 0, 0);
1869 test_cxx "whether has setpriority" "yes" "no" ""
1870 AC_DEFINE_UNQUOTED(CMK_HAS_SETPRIORITY, $pass, [whether the setpriority exists])
1872 #### test for system ###
1873 cat > $t <<EOT
1874 #include "ckdll_system.C"
1876 test_cxx "whether to use signal-safe system() " "yes" "no" ""
1877 AC_DEFINE_UNQUOTED(CMK_SIGSAFE_SYSTEM, $pass, [whether to use signal-safe system()])
1879 ### test sched_setaffinity ####
1880 cat > $tc <<EOT
1881 #define _GNU_SOURCE
1882 #include <sched.h>
1884 int main()
1886   cpu_set_t cpuset;
1887   CPU_ZERO(&cpuset);
1888   CPU_SET(0, &cpuset);
1889   if (sched_setaffinity(0, sizeof(cpuset), &cpuset) < 0) {
1890     return -1;
1891   }
1892   return 0;
1895 test_linkc "whether sched_setaffinity call exists" "yes" "no" ""
1896 AC_DEFINE_UNQUOTED(CMK_HAS_SETAFFINITY, $pass, [whether the sched_setaffinity() exists])
1898 ### test pthread_setaffinity_np ####
1899 cat > $tc <<EOT
1900 #include <stdlib.h>
1901 #include <stdio.h>
1902 #include <unistd.h>
1903 #include <pthread.h>
1905 int main()
1907   unsigned long mask = 0xffffffff;
1908   unsigned int len = sizeof(mask);
1910   if (pthread_setaffinity_np(pthread_self(), len, &mask) < 0) {
1911     return -1;
1912   }
1913   return 0;
1916 test_linkc "whether pthread_setaffinity_np call exists" "yes" "no" "-lpthread"
1917 AC_DEFINE_UNQUOTED(CMK_HAS_PTHREAD_SETAFFINITY, $pass, [whether the pthread_setaffinity_np() exists])
1919 ### test pthread_spin_lock ####
1920 cat > $tc <<EOT
1921 #include <stdlib.h>
1922 #include <stdio.h>
1923 #include <unistd.h>
1924 #include <pthread.h>
1926 int main()
1928   pthread_spinlock_t  lock;
1930   pthread_spin_init(&lock, 0);
1932   pthread_spin_lock(&lock);
1934   return 0;
1937 test_linkc "whether pthread_spin_lock exists" "yes" "no" "-lpthread"
1938 AC_DEFINE_UNQUOTED(CMK_HAS_SPINLOCK, $pass, [whether the pthread_spin_lock exists])
1940 ### check libnuma on Linux ####
1941 if test "$WITH_NUMA" = "yes"
1942 then
1943 cat > $tc <<EOT
1944 #include <stdlib.h>
1945 #include <stdio.h>
1946 #include <linux/mempolicy.h>
1947 #include <numaif.h>
1948 #include <numa.h>
1950 int main()
1952   if (get_mempolicy(NULL, NULL, 0, 0, 0) == 0) return 0;
1953   return -1;
1956 test_linkc "whether libnuma exists" "yes" "no" "-lnuma"
1957 AC_DEFINE_UNQUOTED(CMK_HAS_NUMACTRL, $pass, [whether NUMA control related functions exist])
1958 if test $pass -eq 1
1959 then
1960         add_flag 'CMK_SYSLIBS="$CMK_SYSLIBS -lnuma"' "libnuma"
1964 #### check bindprocessors on AIX ####
1965 cat > $tc <<EOT
1966 #include <stdlib.h>
1967 #include <stdio.h>
1968 #include <unistd.h>
1970 #include <sys/processor.h>
1972 int main()
1974   int retValue = 0;
1975   int pid;
1976   pid = getpid();
1977   if (bindprocessor(BINDPROCESS, pid, 0) == -1) return -1;
1978   return 0;
1981 test_linkc "whether bindprocessor call exists" "yes" "no" ""
1982 AC_DEFINE_UNQUOTED(CMK_HAS_BINDPROCESSOR, $pass, [whether the bindprocessor()
1983 exists])
1986 #### check if dlopen works ####
1987 skip_dl=0
1988 # for bproc, ignore -ldl
1989 test -n "$CMK_BPROC" && skip_dl=1
1990 test -n "$CMK_NO_DL" && skip_dl=1
1991 dl_opt='-ldl'
1992 #workaround for pgcc 4.0, -ldl crash linking, so use -Wl,-ldl to skip the prelinker.
1993 case "$CMK_CXX" in
1994 pgCC*) dl_opt='-Wl,-ldl' ;;
1995 esac
1997 if test $skip_dl -eq 0 
1998 then
2000 cat > $t <<EOT
2001 #include "ckdll_dlopen.C"
2002 int main() {
2003         CkDll dll("foo.so");
2004         return 0;
2007 test_link "whether dlopen links without $dl_opt" "yes" "no" ""
2008 noldl=$pass
2009 test_link "whether dlopen links with $dl_opt" "yes" "no" "$dl_opt"
2010 if test $pass -eq 1
2011 then 
2012 #dlopen requires -ldl: add it to our link line
2013         add_flag CMK_LIBS='"$CMK_LIBS '$dl_opt'"' "dlopen"
2016 if test $pass -eq 1 -o $noldl -eq 1
2017 then
2018 # One version or another of dlopen worked: compile it in
2019         AC_DEFINE_UNQUOTED(CMK_DLL_USE_DLOPEN, 1, [dlopen])
2022 cat > $tc <<EOT
2023 #ifndef _GNU_SOURCE
2024 # define _GNU_SOURCE
2025 #endif
2026 #ifndef __USE_GNU
2027 # define __USE_GNU
2028 #endif
2029 #include <dlfcn.h>
2030 #include <stddef.h>
2031 int main()
2033   return dlsym(RTLD_DEFAULT, "main") != NULL;
2036 test_cc "whether has RTLD_DEFAULT" "yes" "no" ""
2037 AC_DEFINE_UNQUOTED(CMK_HAS_RTLD_DEFAULT, $pass, [whether has RTLD_DEFAULT])
2039 cat > $tc <<EOT
2040 #ifndef _GNU_SOURCE
2041 # define _GNU_SOURCE
2042 #endif
2043 #ifndef __USE_GNU
2044 # define __USE_GNU
2045 #endif
2046 #include <dlfcn.h>
2047 #include <stddef.h>
2048 int main()
2050   return dlsym(RTLD_NEXT, "main") != NULL;
2053 test_cc "whether has RTLD_NEXT" "yes" "no" ""
2054 AC_DEFINE_UNQUOTED(CMK_HAS_RTLD_NEXT, $pass, [whether has RTLD_NEXT])
2056 ### test gethostname ####
2057 cat > $tc <<EOT
2058 #ifdef _WIN32
2059 #include <Winsock2.h>
2060 #else
2061 #include <stdlib.h>
2062 #include <stdio.h>
2063 #include <unistd.h>
2064 #endif
2066 int main()
2068   char hostname[[1000]];
2069   gethostname(hostname, 999);
2070   return 0;
2073 test_cc "whether gethostname call exists" "yes" "no" ""
2074 AC_DEFINE_UNQUOTED(CMK_HAS_GETHOSTNAME, $pass, [whether gethostname() exists])
2076 #### check if getProcAddress works ####
2077 cat > $t <<EOT
2078 #include "ckdll_win32.C"
2080 test_cxx "whether getProcAddress works" "yes" "no" ""
2081 AC_DEFINE_UNQUOTED(CMK_DLL_USE_WIN32, $pass, [whether getProcAddress works])
2083 fi    # end of skip_dl
2085 #### check if socklen_t exists ####
2086 cat > $t <<EOT
2087 #include <sys/types.h>
2088 #include <sys/socket.h>
2090 void foo(void) {
2091         int i;
2092         socklen_t s=sizeof(i);
2095 test_cxx "whether has socklen_t" "yes" "no" ""
2096 AC_DEFINE_UNQUOTED(CMK_HAS_SOCKLEN, $pass, [whether has socklen_t])
2098 ### test getifaddrs ####
2099 cat > $tc <<EOT
2100 #include <netinet/in.h> /* for sockaddr_in */
2101 #include <ifaddrs.h> /* for getifaddrs */
2102 #include <net/if.h> /* for IFF_RUNNING */
2104 int main()
2106   struct ifaddrs *interfaces=0;
2107   if( getifaddrs(&interfaces) == 0 ) {
2108         struct ifaddrs *interface;
2109         for( interface=interfaces; interface; interface=interface->ifa_next ) {
2110             if( (interface->ifa_flags & IFF_UP) && ! (interface->ifa_flags & IFF_LOOPBACK) ) {
2111                 const struct sockaddr_in *addr = (const struct sockaddr_in*)interface->ifa_addr;
2112                 if( addr && addr->sin_family==AF_INET ) {
2113                     break;
2114                 }
2115             }
2116         }
2117         freeifaddrs(interfaces);
2118   }
2121 test_linkc "whether getifaddrs call exists" "yes" "no" ""
2122 AC_DEFINE_UNQUOTED(CMK_HAS_GETIFADDRS, $pass, [whether getifaddrs() exists])
2124 #### check if mmap exists ####
2125 cat > $t <<EOT
2126 #include <sys/types.h>
2127 #include <sys/mman.h>
2129 void *foo(void *a,int l,int fd) {
2130         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2131                  MAP_FIXED+MAP_PRIVATE,fd,0);
2134 test_cxx "whether the mmap() syscall exists" "yes" "no" ""
2135 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP, $pass, [whether the mmap() syscall exists])
2136 add_flag "CMK_HAS_MMAP=$pass"
2137 add_make_flag "CMK_HAS_MMAP:=$pass"
2139 #### check if mmap accepts MAP_ANON ####
2140 cat > $t <<EOT
2141 #include <sys/types.h>
2142 #include <sys/mman.h>
2144 void *foo(void *a,int l) {
2145         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2146                 MAP_FIXED+MAP_PRIVATE+MAP_ANON,-1,0);
2149 test_cxx "whether mmap() accepts MAP_ANON" "yes" "no" ""
2150 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP_ANON, $pass, [whether mmap() accepts MAP_ANON])
2152 #### check if mmap accepts MAP_NORESERVE ####
2153 cat > $t <<EOT
2154 #include <sys/types.h>
2155 #include <sys/mman.h>
2157 void *foo(void *a,int l) {
2158         return mmap((caddr_t)a,l,PROT_READ+PROT_WRITE,
2159                 MAP_FIXED+MAP_PRIVATE+MAP_NORESERVE,-1,0);
2162 test_cxx "whether mmap() accepts MAP_NORESERVE" "yes" "no" ""
2163 AC_DEFINE_UNQUOTED(CMK_HAS_MMAP_NORESERVE, $pass, [whether mmap() accepts MAP_NORESERVE])
2165 #### check if get_myaddress exists ####
2166 cat > $t <<EOT
2167 #include <rpc/rpc.h>
2169 void foo(void *a) {
2170     get_myaddress((struct sockaddr_in*)a);
2173 test_cxx "whether has get_myaddress" "yes" "no" ""
2174 AC_DEFINE_UNQUOTED(CMK_HAS_GET_MYADDRESS, $pass, [whether has get_myaddress])
2176 #### check if mprotect exists ####
2177 cat > $t <<EOT
2178 #include <stdio.h>
2179 #include <sys/mman.h>
2181 void foo(void *a,int l,int fd) {
2182      void *pg = NULL;
2183      size_t pagesize = 4096;
2184      mprotect(pg, pagesize, PROT_READ | PROT_WRITE);
2187 test_cxx "whether has mprotect" "yes" "no" ""
2188 AC_DEFINE_UNQUOTED(CMK_HAS_MPROTECT, $pass, [whether has mprotect])
2190 #### check if support for SHM through CMA exists ####
2191 cat > $t <<EOT
2192 #define _GNU_SOURCE
2193 #include <sys/uio.h>
2194 #include <errno.h>
2195 int main() {
2196   pid_t pid;
2197   struct iovec *local, *remote;
2198   int nread = process_vm_readv(pid, local, 1, remote, 1, 0);
2199   nread = process_vm_writev(pid, local, 1, remote, 1, 0);
2200   return errno;
2203 test_link "whether has support for shm transport using Cross Memory Attach" "yes" "no" ""
2204 AC_DEFINE_UNQUOTED(CMK_HAS_CMA, $pass, [whether supports cma])
2206 #### check if -rdynamic works ####
2207 cat > $t <<EOT
2208 int main() {
2209   return 0;
2212 TRACE_LINK_FLAG=''
2213 CAN_EXPORT_SYMBOLS='0'
2214 for i in '-rdynamic' '-Wl,--export-dynamic'; do
2215   test_link "whether has $i" "yes" "no" "$i"
2216   if test "$strictpass" = '1'; then
2217     TRACE_LINK_FLAG="$i"
2218     CAN_EXPORT_SYMBOLS='1'
2219     break
2220   fi
2221 done
2223 if test "$CAN_EXPORT_SYMBOLS" = '1'; then
2224   add_flag 'CMK_LD="$CMK_LD '$TRACE_LINK_FLAG'"' "exporting program symbols to shared objects"
2225   add_flag 'CMK_LDXX="$CMK_LDXX '$TRACE_LINK_FLAG'"' "exporting program symbols to shared objects"
2228 #### check if glibc backtrace exists ####
2229 cat > $t <<EOT
2230 #include "cmibacktrace.c"
2232 int main() {
2233         int nLevels=1;
2234         void *stack;
2235         CmiBacktraceRecord(&stack,0,&nLevels);
2236         return 0;
2239 test_link "whether glibc backtrace works" "yes" "no" "-DCMK_USE_BACKTRACE=1 $TRACE_LINK_FLAG"
2240 AC_DEFINE_UNQUOTED(CMK_USE_BACKTRACE, $pass, [whether glibc backtrace works])
2242 #### test sleep ####
2243 cat > $t <<EOT
2244 #include <unistd.h>
2245 int main() {
2246   sleep(1);
2247   return 0;
2250 test_cxx "whether has sleep " "yes" "no" ""
2251 AC_DEFINE_UNQUOTED(CMK_HAS_SLEEP, $pass, [whether has sleep])
2253 #### test usleep ####
2254 cat > $t <<EOT
2255 #include <unistd.h>
2256 int main() {
2257   usleep(100);
2258   return 0;
2261 test_cxx "whether has usleep " "yes" "no" ""
2262 AC_DEFINE_UNQUOTED(CMK_HAS_USLEEP, $pass, [whether has usleep])
2264 #### test personality() and ADDR_NO_RANDOMIZE ####
2265 # Only works on modern Linux systems
2266 cat > $t <<EOT
2267 #include <sys/personality.h>
2268 int main() {
2269     int orig_persona = personality(0xffffffff);
2270     personality(orig_persona | ADDR_NO_RANDOMIZE);
2271     return 0;
2274 test_cxx "whether personality() and ADDR_NO_RANDOMIZE exist" "yes" "no" ""
2275 AC_DEFINE_UNQUOTED(CMK_HAS_ADDR_NO_RANDOMIZE, $pass, [whether personality() and ADDR_NO_RANDOMIZE exist])
2278 # enable/disable zlib
2279 AC_ARG_ENABLE([zlib],
2280             [AS_HELP_STRING([--enable-zlib],
2281               [enable zlib support])],
2282             [enable_zlib=$enableval],
2283             [enable_zlib=yes])
2285 #### test if has zlib ####
2286 # bproc doesnot like -lz in any case
2287 if test -z "$CMK_BPROC" && test "$enable_zlib" = "yes"
2288 then
2290 cat > $t <<EOT
2291 #include <zlib.h>
2292 int main() { 
2293   gzFile f = gzopen("/tmp/x","r");
2294   gzprintf(f, "test...\n");
2295   gzclose(f);
2296   return 0;
2299 test_link "whether has zlib" "yes" "no" "-lz"
2300 AC_DEFINE_UNQUOTED(CMK_USE_ZLIB, $pass, [whether has zlib])
2301 if test $pass -eq 1
2302 then 
2303         add_flag 'CMK_SYSLIBS="$CMK_SYSLIBS -lz"' "zlib"
2308 #### test if has elf.h ####
2309 cat > $t <<EOT
2310 #include <elf.h>
2311 typedef Elf32_Addr ELF_TYPE_Addr;
2312 int main() { 
2315 test_cxx "whether has elf.h " "yes" "no" ""
2316 AC_DEFINE_UNQUOTED([CMK_HAS_ELF_H], $pass, [whether has elf.h])
2317 if test $pass -eq 1
2318 then
2319         add_flag "CMK_HAS_ELF_H='1'" "elf.h"
2322 #### test if has Multiprocessing.h for apple ####
2323 cat > $t <<EOT
2324 #include <Carbon/Carbon.h>
2325 #include <Multiprocessing.h>
2326 int main() {
2327   int a = MPProcessorsScheduled();
2330 test_cxx "whether has Multiprocessing.h for Apple " "yes" "no" ""
2331 AC_DEFINE_UNQUOTED([CMK_HAS_MULTIPROCESSING_H], $pass, [whether has Multiprocessing.h])
2333 #### test if "ntohl" is available ####
2334 cat > $t <<EOT
2335 #if defined(_WIN32) || defined(__MINGW_H)
2336 #include <winsock.h>
2337 #else
2338 #include <stdint.h>
2339 #include <arpa/inet.h>
2340 #include <netinet/in.h>
2341 #endif
2343 int main() {
2344   int i = 100;
2345   i = ntohl(i);
2346   return 0;
2349 test_cc "whether ntohl is available" "yes" "no" ""
2350 AC_DEFINE_UNQUOTED(CMK_HAS_NTOHL, $pass, [whether ntohl is available])
2352 ### test for libjpeg ####
2353 cat > $t <<EOT
2354 #include <stdio.h>
2355 #include <stdlib.h>
2356 #include "jpeglib.h"
2358 int main()
2360   struct jpeg_compress_struct cinfo;
2361   jpeg_create_compress(&cinfo);
2362   return 0;
2365 test_link "whether has libjpeg" "yes" "no" "-ljpeg"
2366 AC_DEFINE_UNQUOTED(CMK_USE_LIBJPEG, $pass, [whether has libjpeg])
2367 if test $pass -eq 1
2368 then
2369         add_flag 'CMK_LIBJPEG="-ljpeg"' "libjpeg"
2370         add_make_flag 'CMK_LIBJPEG:=-ljpeg' 'libjpeg'
2373 #### check if PAPI exists ####
2374 if test -n "$CMK_USE_PAPI"
2375 then
2376 cat > $t <<EOT
2377 #include <stdio.h>
2378 #include <papi.h>
2379                                                                                 
2380 int main() {
2381     if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) return 1;
2382     return 0;
2385 test_link "whether PAPI exists" "yes" "no" "-lpapi"
2386 AC_DEFINE_UNQUOTED(CMK_HAS_COUNTER_PAPI, $pass, [whether PAPI exists])
2387 if test "$enable_tracing" = "no"
2388 then
2389         echo "Error: Cannot build papi version when tracing is disabled, build with --enable-tracing"
2390         test_finish 1
2391 elif test $fail -eq 1
2392 then
2393         echo "Error: Cannot find papi library"
2394         test_finish 1
2395 else
2396         add_flag 'CMK_LIBS="$CMK_LIBS -lpapi"' "papi"
2400 #### test if Python headers are installed ####
2401 PYTHON_VERSION=`python -V 2>&1 | awk {'print $2'} | awk -F. {'print $1"."$2'}`
2402 cat > $t <<EOT
2403 #include "python${PYTHON_VERSION}/Python.h"
2404 #include "python${PYTHON_VERSION}/compile.h"
2405 #include "python${PYTHON_VERSION}/eval.h"
2406 #include "python${PYTHON_VERSION}/node.h"
2408 int main() {
2409     Py_Initialize();
2410     PyEval_InitThreads();
2411     struct _node* programNode = PyParser_SimpleParseString("return 1\n",Py_file_input);
2412     PyCodeObject *program = PyNode_Compile(programNode, "");
2415 test_link "whether Python is installed" "yes" "no" "-lpython$PYTHON_VERSION -lpthread -lutil -ldl"
2416 AC_DEFINE_UNQUOTED(CMK_HAS_PYTHON, $pass, [whether Python is installed])
2417 AC_DEFINE_UNQUOTED(CMK_PYTHON_VERSION, ${PYTHON_VERSION}, [Python version])
2418 if test $pass -eq 1
2419 then
2420         add_flag "CMK_BUILD_PYTHON=$PYTHON_VERSION" "python"
2421         add_make_flag "CMK_BUILD_PYTHON:=$PYTHON_VERSION" 'python'
2424 ## Cray specific test
2425 if test "$CMK_BUILD_CRAY" = "1"
2426 then
2427 #echo "Test for known incompatible compiler versions"
2429  if test "$CRAY_CC_VERSION" = "8.1.4"
2430  then
2431         echo "CCE 8.1.4 produces incorrect Charm++ code"
2432         echo "Please use a newer version of the CCE compiler"
2433         echo "e.g. module load cce/8.1.7"
2434         test_finish 1
2435  fi
2437 #### test if Cray node topology will work ####
2438 cat > $tc <<EOT
2439 #include <pmi.h>
2441 int main() {
2442     int nid;
2443     PMI_Get_nid(0, &nid);
2445     return 0;
2448 test_linkc "whether PMI_Get_nid exists" "yes" "no" "$CMK_CRAY_LIBS"
2449 AC_DEFINE_UNQUOTED(CMK_HAS_PMI_GET_NID, $pass, [whether PMI_Get_nid exists])
2451 #### test if Cray mesh topology will work ####
2452 cat > $tc <<EOT
2453 #include <rca_lib.h>
2455 int main() {
2456     rca_mesh_coord_t xyz;
2457     rca_get_meshcoord(0, &xyz);
2459     return 0;
2462 test_linkc "whether Cray rca library is available" "yes" "no" "$CRAY_RCA_POST_LINK_OPTS -lrca"
2463 AC_DEFINE_UNQUOTED(CMK_HAS_RCALIB, $pass, [whether Cray rca library is available])
2465 #### test if Cray mesh dimension query function will work ####
2466 cat > $tc <<EOT
2467 #include <rca_lib.h>
2469 int main() {
2470     rca_mesh_coord_t xyz;
2471     rca_get_max_dimension(&xyz);
2473     return 0;
2476 test_linkc "whether Cray rca_has get_max_dimension" "yes" "no" "$CRAY_RCA_POST_LINK_OPTS -lrca"
2477 AC_DEFINE_UNQUOTED(CMK_HAS_RCA_MAX_DIMENSION, $pass, [whether Cray rca has rca_get_max_dimension])
2479 #### query Cray machine max NID if get_max_dimension not exist ####
2481 if test $pass -eq 0
2482 then
2483 cmd=`which xtprocadmin 2>/dev/null`
2484 if test -n "$cmd"
2485 then
2486     #maxnid=`xtprocadmin  | tail -1  | awk '{print $1}'`
2487     # workaround for hopper
2488     (export SHELL=/bin/csh; xtprocadmin >& t.$$)
2489     maxnid=`cat t.$$  | tail -1  | awk '{print $1}'`
2490     /bin/rm -f t.$$
2491     AC_MSG_CHECKING(Cray machine maxnid)
2492     AC_MSG_RESULT("$maxnid")
2493     if test -n "$maxnid"
2494     then
2495     AC_DEFINE_UNQUOTED(CMK_CRAY_MAXNID, $maxnid, [Cray MAXNID])
2496     fi
2503 #### query Cray machine supports BANDWIDTH_INJECTION controls####
2505 if test "$CMK_BUILD_MPI" = "1"
2506 then
2507 echo "BALANCED_INJECTION test disabled on MPI"
2508 elif test "$GNI_CRAYXC" = "1"
2509 then
2510 echo "BALANCED_INJECTION test disabled on Aries network"
2511 else
2512 cat > $tc <<EOT
2513 #include <stdint.h>
2514 #include <gni_pub.h>
2516 int main() {
2517     gni_bi_desc_t gni_bi_desc;
2518     uint32_t gni_device_id = 0;
2519     gni_return_t gni_rc = GNI_GetBIConfig(gni_device_id, &gni_bi_desc);
2520     if (gni_rc == GNI_RC_SUCCESS) {
2521     }
2522     return 0;
2525 test_linkc "whether GNI_GetBIConfig exists" "yes" "no" "$CMK_CRAY_LIBS"
2526 AC_DEFINE_UNQUOTED(CMK_BALANCED_INJECTION_API, $pass, [whether Cray gni_pub has GNI_GetBIConfig])
2527 fi # end of BIConfig test
2530 fi  # end of Cray specific test
2532 #### test if it can build shared library ####
2533 cat > $t <<EOT
2534 #include "stdlib.h"
2535 extern int foo();
2536 int foo1() { 
2537   void * t= malloc(2);
2538   foo();
2539   return 0;
2542 test_linkso "whether can build shared library" "yes" "no" ""
2543 if test $pass -eq 0
2544 then 
2545         add_flag 'CMK_NO_BUILD_SHARED="true"' "build-shared"
2546         add_make_flag 'CMK_NO_BUILD_SHARED:=true' 'build-shared'
2547 else
2548         BUILD_SHARED=1
2549         if test "$BUILD_MPI" = "1"
2550         then
2551 cat > $t <<EOT
2552 #include "stdlib.h"
2553 #include "mpi.h"
2554 extern int foo();
2555 int foo(int argc, char ** argv) {
2556   void * t= malloc(2);
2557   foo();
2558   MPI_Init(&argc, &argv);
2559   return 0;
2562                 test_linkso "whether can build shared library with MPI" "yes" "no" ""
2563                 BUILD_SHARED=$pass
2564         fi
2565         if test $BUILD_SHARED -eq 0
2566         then
2567                 add_flag 'CMK_NO_BUILD_SHARED="true"' "build-shared"
2568                 add_make_flag 'CMK_NO_BUILD_SHARED:=true' 'build-shared'
2569         fi
2572 #### test the version number of bproc ####
2573 if test -n "$CMK_BPROC"
2574 then
2575 cat > $t <<EOT
2576 #include <stdio.h>
2577 #include <sys/bproc.h>
2578 int main()
2580   struct bproc_version_t vers;
2581   bproc_version(&vers);
2582   printf("%s\n", vers.version_string);
2585 test_link "whether bproc compiles" "yes" "no" "-lbproc"
2586 if test $pass -eq 1
2587 then 
2588 AC_MSG_CHECKING("bproc version")
2589 bproc_ver=`./testlink`
2590 if test x$bproc_ver = x
2591 then
2592 test_result 0 "bproc version" "ERROR" ""
2593 test_finish 1
2594 else
2595 test_result 0 "bproc version" "$bproc_ver" ""
2597 bproc_ver=`echo $bproc_ver | cut -d'.' -f1`
2598 AC_DEFINE_UNQUOTED(CMK_BPROC_VERSION, $bproc_ver, [bproc version])
2602 #### test the if command sync exists ####
2603 AC_CHECK_PROG(SYNC, sync, sync )
2604 if test -n "$SYNC"
2605 then
2606 AC_DEFINE_UNQUOTED(CMK_HAS_SYNC, 1, [sync program])
2609 ################## Fortran #########################
2611 #echo "set F77 compiler as: $CMK_CF77"
2612 AC_MSG_CHECKING("F77 compiler as")
2613 AC_MSG_RESULT("$CMK_CF77")
2615 AC_MSG_CHECKING("whether Fortran 77 compiler works")
2616 ### test fortran 77 compiler ###
2617 cat > conftest.f <<EOF
2618       SUBROUTINE FOO_foo
2619       END
2621 $CMK_CF77 -c conftest.f > /dev/null 2> /dev/null
2622 if test ! -r conftest.o
2623 then
2624   AC_MSG_RESULT("no")
2625 else
2626   AC_MSG_RESULT("yes")
2629 ### test fortran 90 compiler ###
2630 #echo "set F90 compiler as: $CMK_CF90"
2631 AC_MSG_CHECKING("F90 compiler as")
2632 AC_MSG_RESULT("$CMK_CF90")
2634 AC_MSG_CHECKING("whether Fortran 90 compiler works")
2635 cat > conftest2.f90 <<EOF
2636       SUBROUTINE FOO_foo
2637       END
2639 $CMK_CF90 -c conftest2.f90 > /dev/null 2> /dev/null
2640 if test ! -r conftest2.o
2641 then
2642   AC_MSG_RESULT("no")
2643 else
2644   AC_MSG_RESULT("yes")
2645   mv -f conftest2.o conftest.o
2646   USE_FORTRAN90=1
2649 ### check fortran name mangling
2650 AC_MSG_CHECKING(subroutine name used by Fortran 90 compiler)
2652 if test -r conftest.o
2653 then
2654   AC_CACHE_VAL(_cv_fortran_postfix,
2656   NAME=`$CMK_NM conftest.o | grep "foo_foo__"`
2657   if test "$NAME" != ""
2658   then
2659     _cv_fortran_postfix=TWOSCORE
2660     AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_TWOSCORE, 1, [TWOSCORE])
2661   else
2662     NAME=`$CMK_NM conftest.o | grep "foo_foo_"`
2663     if test "$NAME" != ""
2664     then
2665       _cv_fortran_postfix=ONESCORE
2666       AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_ONESCORE, 1, [ONESCORE])
2667     else
2668       NAME=`$CMK_NM conftest.o | grep "foo_foo"`
2669       if test "$NAME" != ""
2670       then
2671         _cv_fortran_postfix=NOSCORE
2672         AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_NOSCORE, 1, [NOSCORE])
2673       else
2674         NAME=`$CMK_NM conftest.o | grep "FOO_FOO"`
2675         if test "$NAME" != ""
2676         then
2677           _cv_fortran_postfix=ALLCAPS
2678           AC_DEFINE_UNQUOTED(CMK_FORTRAN_USES_ALLCAPS, 1, [ALLCAPS])
2679         else
2680           echo "#################################################"
2681           echo "FORTRAN compiler generated name not supported yet"
2682           echo "#################################################"
2683         fi
2684       fi
2685     fi
2686   fi
2687   rm -f conftest.f conftest.o
2688   )
2689   AC_MSG_RESULT($_cv_fortran_postfix)
2690 else
2691   AC_MSG_RESULT("Fortran compiler not working")
2694 ### check module name ###
2696 if test "$USE_FORTRAN90" = 1
2697 then
2698   cat > conftest.f90 <<EOF
2699       MODULE testmod
2700         interface 
2701           function fpup_issizing(p)
2702           INTEGER :: p
2703           logical fpup_issizing
2704           end function
2705         end interface
2706       END MODULE
2708   AC_MSG_CHECKING(Fortran 90 mod name is capital)
2709   $CMK_CF90 -c conftest.f90 > /dev/null 2> /dev/null
2710   name=`ls TESTMOD.* 2>/dev/null`
2711   if test -n "$name"
2712   then
2713         AC_MSG_RESULT("yes")
2714         add_flag 'CMK_MOD_NAME_ALLCAPS=1' "mod name capital"
2715   else
2716         AC_MSG_RESULT("no")
2717         name=`ls testmod.* 2>/dev/null`
2718   fi
2719   if test -n "$name"
2720   then
2721         AC_MSG_CHECKING(Fortran 90 mod name extension)
2722         ext=`echo $name | sed -e 's/^[[^.]]*\.//'`
2723         add_flag 'CMK_MOD_EXT="'$ext'"' "mod name extension"
2724         AC_MSG_RESULT("$ext")
2725         /bin/rm -f $name
2726   fi
2727   /bin/rm -f conftest.f90
2730 ### test if the C++ linker succeeds with a Fortran entry point ##
2732 cat > conftest.f90 <<EOF
2733       PROGRAM empty
2734       END PROGRAM
2736 test_link_fortran_main() {
2737   AC_MSG_CHECKING("$1")
2738   echo "### $1" >> $charmout
2739   cat conftest.f90 >> $charmout
2740   echo $CMK_CF90 -c conftest.f90 -o test.o $4 >> $charmout
2741   $CMK_CF90 -c conftest.f90 -o test.o $4 > out 2>&1
2742   if test $? -ne 0
2743   then
2744     test_result 1 "$1" "$2" "$3"
2745   else
2746     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
2747     $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
2748     ret=$?
2749     test ! -x testlink && ret=1
2750     test_result $ret "$1" "$2" "$3"
2751   fi
2752   cat out >> $charmout
2754 test_link_fortran_main "whether the C++ linker succeeds with a Fortran entry point" "yes" "no" ""
2755 /bin/rm -f conftest.f90 test.o testlink out
2756 if test $pass -eq 1
2757 then
2758   add_flag "CMK_CAN_LINK_FORTRAN='1'" "Fortran"
2761 ### check for OpenMP availability ###
2762 cat > $tc <<EOT
2763 #include <stdio.h>
2764 #include <omp.h>
2766 int main(void)
2768   int iam = 0, np = 1;
2770   #pragma omp parallel default(shared) private(iam, np)
2771   {
2772     np = omp_get_num_threads();
2773     iam = omp_get_thread_num();
2774     printf("Hello from thread %d of %d\n", iam, np);
2775   }
2777   return 0;
2780 test_linkc "whether OpenMP is supported" "yes" "no" "$CMK_C_OPENMP"
2781 if test $pass -eq 1
2782 then
2783         add_flag "CMK_HAS_OPENMP='1'" "OpenMP"
2786 ### check for Lustre FS availability ###
2787 cat > $tc <<EOT
2788 #include <stdio.h>
2789 #include <lustre/lustreapi.h>
2790 #include <lustre/lustre_user.h>
2792 int main() {
2793   llapi_printf(LLAPI_MSG_NORMAL, "Lustre FS is available");
2794   return 0;
2797 test_linkc "whether has lustre fs" "yes" "no" "-llustreapi"
2798 AC_DEFINE_UNQUOTED(CMK_HAS_LUSTREFS, $pass, [whether has lustrefs])
2799 if test $pass -eq 1
2800 then
2801   add_make_flag 'CMK_LUSTREAPI:=-llustreapi' "lustreapi"
2802 else
2803   add_make_flag 'CMK_LUSTREAPI:=' "lustreapi"
2807 # for hwloc
2808 eval "`./charmc -print-building-blocks $OPTS`"
2809 export CC="$(get_full_command_name "$CMK_SEQ_CC")"
2810 export CXX="$(get_full_command_name "$CMK_SEQ_CXX")"
2811 export CC_FOR_BUILD="$(get_full_command_name "$CMK_NATIVE_CC")"
2812 AC_SUBST(CC_FOR_BUILD)
2813 export HWLOC_FLAGS="$CHARM_CC_FLAGS"
2814 export CFLAGS="$CMK_SEQ_CC_FLAGS"
2815 export AR="$(get_full_command_name "${CMK_SEQ_AR%% *}")"
2816 export am_libhwloc_embedded_la_rpath="-rpath $CHARMLIBSO"
2817 AC_SUBST(am_libhwloc_embedded_la_rpath)
2818 enable_embedded_mode='yes'
2819 enable_static='yes'
2820 enable_shared='yes'
2821 enable_libnuma='no'
2822 enable_pci='no'
2823 enable_libudev='no'
2824 enable_libxml2='no'
2825 enable_visibility='no'
2826 enable_nvml='no'
2827 . hwloc/VERSION
2828 export libhwloc_so_version
2829 AC_SUBST(libhwloc_so_version)
2831 echo "Configuring hwloc:"
2832 AC_CONFIG_AUX_DIR(hwloc/config)
2833 AC_CANONICAL_TARGET
2834 AC_USE_SYSTEM_EXTENSIONS
2835 LT_INIT
2837 AM_INIT_AUTOMAKE([no-define])
2839 AC_CONFIG_MACRO_DIR(hwloc/config)
2840 HWLOC_SET_SYMBOL_PREFIX([cmi_])
2841 HWLOC_SETUP_CORE([hwloc], [happy=yes], [happy=no])
2842 HWLOC_DO_AM_CONDITIONALS
2843 add_flag 'CMK_HWLOC_LIBS="-lhwloc_embedded '"$HWLOC_EMBEDDED_LIBS"'"' "hwloc"
2844 add_flag 'CMK_CC_FLAGS="$CMK_CC_FLAGS '"$HWLOC_EMBEDDED_CFLAGS"'"' 'hwloc'
2845 add_flag 'CMK_CXX_FLAGS="$CMK_CXX_FLAGS '"$HWLOC_EMBEDDED_CFLAGS"'"' 'hwloc'
2847 AC_OUTPUT