Fix hash table usage for XLC
[charm.git] / src / scripts / charmc
blob702d4f2b0f668d2163208defd10b5cc42ce3ba81
1 #!/bin/sh
2 ##############################################################################
3 # charmc: Compiler for Converse/Charm/Charm++ programs
5 # Converted to Bourne Shell by Orion Sky Lawlor, 10/21/1999
7 # Initialize the main controlling variables, setup error handler
8 # ALL variables used by this script should be initialized here.
10 ##############################################################################
12 #Prepare aliases for the external commands we use--
13 # Note that adding /bin/ to everything breaks Cygwin32.
14 RM="rm -f"
15 CP="cp -p"
16 MV="mv"
17 LN="ln"
18 WC="wc"
19 SED="sed"
21 MACHTYPE=""
22 SEQUENTIAL=""
23 NATIVE=""
24 LANGUAGE=""
25 BALANCE="rand"
26 TRACEMODE=""
27 TRACE_OBJ=
28 MEMORY="default"
29 THREAD="default"
30 VERBOSE=""
31 DEBUG_SCRIPT=""
32 SAVE=""
33 PURIFY=""
34 SKIPLINK=""
35 OVERRIDE_CC=""
36 OVERRIDE_CXX=""
37 OVERRIDE_F90=""
38 OVERRIDE_LD=""
39 OVERRIDE_LDXX=""
40 #Generic options, passed to everything
41 OPTS=""
42 #Specific options
43 #charm internal flag, only pass to c and cxx, not f90
44 OPTS_CPP_INTERNAL="-D__CHARMC__=1"
45 OPTS_CPP=
46 OPTS_LDRO=""
47 OPTS_CC=""
48 OPTS_CC_GENCPM=""
49 OPTS_CXX=""
50 OPTS_F90=""
51 OPTS_LD=""
52 OPTS_LDXX=""
53 OPTS_PIC=""
54 USE_PIC="0"
56 CHARMDEBUG=""
57 LINK_PYTHON=""
58 OBJECT=""
59 EXPLICIT_OBJECT="no"
60 EXPLICIT_COMPILATION="no"
61 POST_LANGUAGE=""
62 POST_LIBRARIES=""
63 PRE_LIBRARIES=""
64 USE_F90_LIBRARIES="0"
65 USE_F77_LIBRARIES="0"
66 F90_MODDIR=
67 AMPIMAIN=""
68 COPYTO=""
69 MODCOPIES=""
70 MODULES=""
71 BALANCER=""
72 FILES=""
73 OBJECTFILES=""
74 DELETE=""
75 MAINOBJ=""
76 GENCPM=""
77 OPTIMIZE_MODE=""
78 PRODUCTION_MODE=""
79 USE_RELIABLE_CC=""
80 USE_FASTEST_CC=""
81 PROG_EXT=""
82 GENDEPENDS="no"
83 COUNTTOKENS="no"
84 USE_OPENMP="no"
86 COPY_CHARMRUN=true
87 USE_BUILD_OPTIONS=0
89 COPY_EXIT="true"
90 CHARM_SHARED="0"
91 BUILD_SHARE="0"
92 SWAPGLOBALS="0"
93 TLSGLOBALS="0"
94 ROSE_OMP_TLS_GLOBALS="no"
95 NOABORT=""
97 TAU_MAKEFILE=Make.tau
98 TAU_TRACE_MPI=1
100 CMK_CELL=0
101 SPU_USE_CPP=0
102 SPU_EXTRA_LIBS=""
104 MPI_INTEROPERATE=""
105 NO_MAIN_MODULE=""
106 NO_MAIN=""
107 CUSTOM_PARTITION=""
108 PREPROCESS_CI="yes"
110 ####################################################################
112 # Utility routines used below
114 ###################################################################
116 # PrintUsage: prints a helpful command-line usage message and quits
117 # Args: any additional messages
118 printUsage() {
119 printVersion
120 echo
121 echo "Usage: charmc [ flags ] <files>"
122 echo
123 echo " flags:"
124 echo " -o <target> -g -O"
125 echo " -D<define> -I<include path> -L<lib path> -l<library> -s"
126 echo " -machine <mach> -seq -host -language <lang> -pg <opt>"
127 echo " -balance <mode> -tracemode <mode> -memory <mode>"
128 echo " -modules <comma-separated list of C++ modules> -thread"
129 echo " -debug-script -count-tokens -default-to-aout -E -S -M"
130 echo " -verbose -save -purify -cp <dest> -cpmod -gen-cpm <pkg>"
131 echo " -swapglobals -tlsglobals -roseomptlsglobals"
132 echo " -use-reliable-cc -use-fastest-cc -use-new-std"
133 echo " -cc <new cc> -c++ <new CC> -ld <new ld> -ld++ <new LD>"
134 echo " -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
135 echo " -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
136 echo " -f90 <new f90> -f90-option <opt> -fmoddir <f90mod path>"
137 echo " -flibs -rpath <path> -custom-part -touch-on-failure"
138 echo " -mpi -openmp -no-trace-mpi -build-shared -charm-shared"
139 echo " -no-charmrun -no-preprocess-ci -nomain-module -nomain"
140 echo " -nof90main -f90main"
141 echo
142 echo " Charmc compiles C, C++, f77, f90, AMPI, Converse, Converse++, Charm, "
143 echo "and Charm++ programs. The flags generally match those of cc or f77."
144 echo "Parallel Programming Lab, UIUC, 2017."
145 echo $*
146 exit 1
149 # End blows away the temporary files (unless SAVE is true) and exits
150 # Args: <exit code>
151 End() {
152 if [ -z "$SAVE" ]
153 then
154 for FILE in `echo $FILES`
156 #BASE=`stripExtention $FILE`
157 TMP=`basename $FILE`".TMP"
158 $RM $TMP.P.C $TMP.cpp $TMP.space $TMP.xlat $TMP.o
159 $RM $TMP.c $TMP.c.0.h $TMP.c.1.h $TMP.c.2.h
160 $RM $TMP.i $TMP.$CMK_CPP_SUFFIX
161 done
162 $RM core $DELETE
163 if test -n "$modInitObj"
164 then
165 [ -n "$VERBOSE" ] && echo $RM $modInitSrc $modInitObj
166 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
169 exit $1
172 # Write this error message to stderr
173 # ("1>&2" redirects the echo output to stderr).
174 Warning() {
175 echo "$@" 1>&2
178 # This procedure prints an error message and exits.
179 # Args: written to stderr
180 Abort() {
181 Warning "Fatal Error by charmc in directory "`pwd`
182 Warning " $@"
183 Warning "charmc exiting..."
184 End 1
188 # Instead of an ECHO_CMD variable, I define a procedure Do,
189 # which (possibly) echos, runs, and tests the errors of the given command.
190 # Args: executed as given
191 DoNoErrCheck() {
192 [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
193 eval "$@"
196 Do() {
197 DoNoErrCheck "$@"
198 Do_res=$?
199 # The UNIX result code better be zero, or we die
200 [ $Do_res -eq 0 -o -n "$NOABORT" ] || Abort "Command $@ returned error code $Do_res"
203 # This procedure removes the extention (the ".c" in "./main.c") from
204 # its first argument, and prints the result. Unlike the builtin command
205 # basename, it keeps the directory path.
206 # Args: <name to strip>
207 stripExtention() {
208 se_base=`basename $1`
209 # se_base=`echo $1 | awk -F/ '{print $NF}'`
210 se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
211 se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
212 echo $se_ret
215 # GetExtention returns the extention on the given file name
216 # or "" if none. (e.g. "./bob/snack.c" returns ".c")
217 # Args: <name to find extention of>
218 getExtention() {
219 # se_base=`echo $1 | awk -F/ '{print $NF}'`
220 # se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
221 # echo $se_ret
222 se_ret=`echo $1 | sed -e 's/.*\././'`
223 if test "$se_ret" = $1
224 then
225 echo ""
226 else
227 echo $se_ret
231 Debugf() {
232 [ -n "$VERBOSE" ] && echo "charmc>" $@
235 Debug() {
236 if [ -n "$DEBUG_SCRIPT" ]
237 then
238 echo
239 echo "------- Charmc Debugging info: $* -------"
240 echo "CHARMBIN=$CHARMBIN"
241 echo "CHARMINC=$CHARMINC"
242 echo "CHARMLIB=$CHARMLIB"
243 echo "FILES=$FILES"
244 echo "DELETE=$DELETE"
245 echo "OBJECT=$OBJECT"
246 echo "LANGUAGE=$LANGUAGE"
247 # echo "Working directory="`pwd`
251 # Return success if $1 is not in any of the other arguments
252 notInList() {
253 search=$1
254 shift
255 while [ $# -gt 0 ]
257 if [ "$search" = "$1" ]
258 then
259 # It's already in there-- fail
260 return 1
262 shift
263 done
264 # It's missing--succeed
265 return 0
268 # Add arguments to our modules list, avoiding duplicates
269 AddModules() {
270 for M in "$@"
272 notInList $M $MODULES && MODULES="$MODULES $M"
273 done
276 # Add this word to this list, avoiding duplicates
277 AddList() {
278 ret=""
279 while [ $# -gt 1 ]
281 ret="$ret $1"
282 shift
283 done
284 if notInList $1 $ret
285 then
286 ret="$ret $1"
288 echo $ret
291 # TEMP_BASE is appended with this script's process ID (PID),
292 # so multiple charmcs can run in parallel without overwriting
293 # each other's temporary files.
294 TEMP_BASE="/tmp/charmc_tmp.$$"
296 # Try to find CHARMBIN by looking in directory where charmc is
297 findCharmBin() {
298 if [ -z "$CHARMBIN" ]
299 then
300 SCRIPT=$1
301 CHARMBIN=`dirname $SCRIPT`
302 # CHARMBIN=`cd $CHARMBIN; pwd`
303 # NOTE: this script no longer tries to follow soft links
304 # to find the "original" charmc-- if this is bad,
305 # translate these lines to Bourne shell from C shell:
306 # -------------------- Begin C Shell ------------------------->
307 # if ($SCRIPT:h != $SCRIPT:t) then
308 # cd $SCRIPT:h
309 # set SCRIPT=$SCRIPT:t
310 # else
311 # foreach dir ($path)
312 # if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
313 # cd $dir
314 # break
315 # endif
316 # end
317 # endif
318 # while (x`find $SCRIPT -type l -print` == x$SCRIPT)
319 # set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
320 # if ($SCRIPT:h != $SCRIPT:t) then
321 # cd $SCRIPT:h
322 # set SCRIPT=$SCRIPT:t
323 # endif
324 # end
325 # set CHARMBIN=`pwd`
326 # <------------------ End C Shell -----------------------------
330 printVersion()
332 findCharmBin $0
333 version=`cat $CHARMBIN/../include/VERSION`
334 echo Charm++ Version $version
338 ##############################################################################
340 # The following section identifies CHARMBIN, the charm binary-directory.
342 ##############################################################################
344 ORIGDIR=`pwd`
346 # Try to find CHARMBIN by looking in directory where charmc is
348 findCharmBin $0
350 UNAME=`uname -s`
351 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
352 if [ "$FIRST_THREE" = "CYG" -o "$UNAME" = "Interix" ]
353 then
354 # Running on a windows system-- append .exe to file names
355 PROG_EXT=".exe"
358 CHARMLIB="$CHARMBIN/../lib"
359 CHARMINC="$CHARMBIN/../include"
360 CHARMLIBSO=
361 if test -d "$CHARMBIN/../lib_so"
362 then
363 CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
364 #getting absolute path is harder than thought because of symbolic links and ..
365 #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
366 #csh is ok too if it exists
367 test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
368 test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
369 test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
372 ##############################################################################
374 # Parse the arguments
376 # Don't do any analysis in here, just the parsing.
378 ##############################################################################
380 [ $# -eq 0 ] && printUsage "Error: No arguments given."
382 processArgs() {
383 while [ ! $# -eq 0 ]
385 arg="$1"
386 shift
388 case "$arg" in
389 "-V")
390 printVersion
391 exit 0
394 "-machine")
395 MACHTYPE="$1"
396 shift
399 "-seq")
400 SEQUENTIAL=true
403 "-host")
404 NATIVE=true
407 "-language")
408 # Parse out some fake languages (that are actually modules)
409 case "$1" in
410 "ampi") AddModules tcharmmain ampi ;;
411 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ;;
412 "armci") AddModules tcharmmain armci ;;
413 "armcif") AddModules tcharmmain armci ; USE_F90_LIBRARIES="1" ;;
414 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
415 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
416 "ParFUM_TOPS") AddModules tcharmmain ParFUM ParFUM_TOPS ; AMPIMAIN="ParFUMmain";;
417 "ParFUM") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain";;
418 "ParFUMf") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain"; USE_F90_LIBRARIES="1" ;;
419 "mblock") AddModules tcharmmain mblock ;;
420 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
422 LANGUAGE="$1"
423 POST_LANGUAGE=1
425 esac
426 shift
429 "-debug")
430 # Requested support from charmdebug: add some modules and libraries
431 CHARMDEBUG=1
432 MEMORY="charmdebug"
435 "-module"|"-modules")
436 AddModules `echo $1 | sed -e 's/,/ /g'`
437 shift
440 "-balancer")
441 # test -n "$BALANCER" && Abort "More than one -balancer specified!"
442 BALANCER="$BALANCER $1"
443 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
444 AddModules $mod
445 shift
448 "-balance")
449 BALANCE="$1"
450 shift
453 "-queue")
454 Warning "Warning: -queue currently being ignored."
455 shift
458 "-memory")
459 MEMORY="$1"
460 shift
463 "-thread")
464 THREAD="$1"
465 shift
468 "-tracemode")
469 TRACEMODE_NEW=`AddList $TRACEMODE $1`
470 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
471 then
472 Warning "Warning: Duplicate tracemode $1 ignored"
473 else
474 TRACEMODE=$TRACEMODE_NEW
476 shift
478 "-no-trace-mpi")
479 TAU_TRACE_MPI=0
482 "-swapglobal"|"-swapglobals")
483 SWAPGLOBALS="1"
484 USE_PIC="1"
487 "-tlsglobal"|"-tlsglobals")
488 TLSGLOBALS="1"
491 "-roseomptlsglobals")
492 ROSE_OMP_TLS_GLOBALS="yes"
495 "-verbose")
496 echo "Verbose mode set"
497 VERBOSE=true
500 "-spu-cpp")
501 SPU_USE_CPP=1
504 "-spu-lib")
505 SPU_EXTRA_LIBS="$SPU_EXTRA_LIBS -l$1"
506 shift
509 "-intrinsic")
510 XI_INTERNAL=true
513 "-debug-script")
514 echo "Will give excessive charmc debugging output..."
515 DEBUG_SCRIPT=true
518 "-save")
519 SAVE=true
522 "-purify")
523 PURIFY=true
526 "-use-reliable-cc")
527 USE_RELIABLE_CC=1
530 "-use-fastest-cc")
531 USE_FASTEST_CC=1
534 "-cc")
535 OVERRIDE_CC="$1"
536 shift
539 "-c++")
540 OVERRIDE_CXX="$1"
541 shift
544 "-f90")
545 OVERRIDE_F90="$1"
546 shift
549 "-ld")
550 OVERRIDE_LD="$1"
551 shift
554 "-ld++")
555 OVERRIDE_LDXX="$1"
556 shift
559 "-cpp-option")
560 OPTS_CPP="$OPTS_CPP $1"
561 shift
564 "-ldro-option")
565 OPTS_LDRO="$OPTS_LDRO $1"
566 shift
569 "-cc-option")
570 OPTS_CC="$OPTS_CC $1"
571 shift
574 "-c++-option")
575 OPTS_CXX="$OPTS_CXX $1"
576 shift
579 "-f90-option")
580 OPTS_F90="$OPTS_F90 $1"
581 shift
584 "-ld-option")
585 OPTS_LD="$OPTS_LD $1"
586 shift
589 "-ld++-option")
590 OPTS_LDXX="$OPTS_LDXX $1"
591 shift
594 "-rpath")
595 OPTS_LDXX="$OPTS_LDXX -rpath $1"
596 shift
599 "-fortran"|"-flib"|"-flibs")
600 USE_F90_LIBRARIES="1"
602 "-f77")
603 USE_F77="1"
605 "-fortran77"|"-f77lib"|"-f77libs")
606 USE_F77_LIBRARIES="1"
608 "-E")
609 # Run preprocessor only
610 PREPROCESS="yes"
611 SKIPLINK="yes"
612 OPTS="$OPTS $arg"
614 "-preprocess")
615 # Run preprocessor as an extra step, continue after preprocessing
616 PREPROCESS="yes"
618 "-no-preprocess-ci")
619 # Turn off the preprocessor for ci files
620 PREPROCESS_CI="no"
622 "-P"|"-S")
623 # Run preprocessor/assembler only
624 SKIPLINK="yes"
625 OPTS="$OPTS $arg"
627 "-M")
628 SKIPLINK="yes"
629 OPTS="$OPTS $arg"
630 GENDEPENDS="yes"
632 "-count-tokens")
633 OPTS="$OPTS $arg"
634 COUNTTOKENS="yes"
636 "-default-to-aout")
637 if [ "$EXPLICIT_OBJECT $EXPLICIT_COMPILATION" = "no no" ]
638 then
639 OBJECT="a.out"
642 -print-prog-name=*)
643 echo $arg | cut -d'=' -f2
644 exit 0
646 "-c")
647 if [ "$EXPLICIT_OBJECT" = "no" ]
648 then
649 OBJECT=""
651 EXPLICIT_COMPILATION="yes"
654 "-o")
655 EXPLICIT_OBJECT="yes"
656 OBJECT=$1
657 shift
660 "-cp")
661 COPYTO="$1"
662 shift
665 "-cpmod")
666 MODCOPIES="$1 $MODCOPIES"
667 shift
670 "-gen-cpm")
671 GENCPM="$GENCPM $1"
672 shift
676 OPTS_CPP="$OPTS_CPP -I$1"
677 shift
680 -D*|-I*)
681 if echo "$arg" | grep ' ' > /dev/null 2>/dev/null
682 then
683 OPTS_CPP="$OPTS_CPP "\"$arg\"
684 else
685 OPTS_CPP="$OPTS_CPP $arg"
689 -Werror)
690 WERROR="1"
693 -Wno-error)
694 WERROR="0"
697 "-use-new-std")
698 USE_NEW_STD="1"
701 "-no-use-new-std")
702 USE_NEW_STD="0"
705 -LANG*)
706 Warning "passing unrecognized option $arg to all compilers and linkers"
707 OPTS="$OPTS $arg"
709 -shared|-G)
710 BUILD_SHARE="1"
712 -L*|-shared|-G)
713 OPTS_LD="$OPTS_LD $arg"
715 -charm-shared|-cs)
716 CHARM_SHARED="1"
718 -build-shared)
719 # used internally when building Charm++ to create lib_so
720 BUILD_SHARE="1"
722 -no-build-shared)
723 # used internally not to build Charm++ lib_so
724 BUILD_SHARE="0"
726 "-optimize")
727 OPTIMIZE_MODE=true
730 "-no-optimize")
731 OPTIMIZE_MODE=false
734 "-production")
735 PRODUCTION_MODE=true
737 "-no-production")
738 PRODUCTION_MODE=false
741 -Wl,*)
742 POST_LIBRARIES="$POST_LIBRARIES $arg"
745 "-pg"|"-g"|-W*|-O*)
746 OPTS="$OPTS $arg"
749 "-fmoddir")
750 F90_MODDIR="$F90_MODDIR $1"
751 shift
754 -l*|*.a)
755 if [ -n "$POST_LANGUAGE" ]
756 then
757 POST_LIBRARIES="$POST_LIBRARIES $arg"
758 else
759 PRE_LIBRARIES="$PRE_LIBRARIES $arg"
764 OPTS_LD="$OPTS_LD $arg"
766 -no-charmrun)
767 COPY_CHARMRUN=false
769 -use-build-options)
770 USE_BUILD_OPTIONS=1
772 -h|--help)
773 printUsage
775 -f90main)
776 F90_MAIN=1
778 -nof90main)
779 F90_MAIN=
781 -mpi)
782 MPI_INTEROPERATE="yes"
783 NO_MAIN="yes"
785 -nomain-module)
786 NO_MAIN_MODULE="yes"
788 -nomain)
789 NO_MAIN="yes"
791 -custom-part)
792 CUSTOM_PARTITION="yes"
795 -fopenmp|-openmp)
796 USE_OPENMP="yes"
799 -touch-on-failure)
800 NOABORT="yes"
803 -*|+*)
804 # Warning "passing unrecognized option $arg to all compilers and linkers"
805 OPTS="$OPTS $arg"
807 *.*)
808 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
809 FILES="$FILES $arg"
811 # Default
813 # printUsage "Error: Unrecognized argument $arg"
814 # Warning "passing unrecognized option $arg to all compilers and linkers"
815 OPTS="$OPTS $arg"
817 esac
818 done
821 trap 'End 1' 2
823 # Process original command-line arguments
824 eval processArgs "$@"
827 ##############################################################################
829 # Load module dependencies.
831 ##############################################################################
833 Debug "About to read machine config script"
834 Debug "Read config script, setting defaults..."
836 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
837 . $CHARMINC/conv-config.sh $CHARMINC
839 Debug "Setting vars..."
841 if [ "$USE_BUILD_OPTIONS" = "1" ]
842 then
843 [ -n "$VERBOSE" ] && echo "Charmc applying build time options: $BUILDOPTS"
844 OPTS="$OPTS $BUILDOPTS"
847 # If we are debugging, add "-g -O0" to the C/C++ flags
848 if [ -n "$CHARMDEBUG" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]; then
849 if [ -n "$CMK_BUILD_PYTHON" ]; then
850 AddModules PythonCCS charmdebug_python
851 POST_LIBRARIES=`AddList $POST_LIBRARIES -lpython${CMK_BUILD_PYTHON}`
853 OPTS_CPP="$OPTS_CPP -O0 -g"
856 PROCESSED_MODULES=""
858 if [ "$WERROR" = "1" ]
859 then
860 OPTS="$OPTS $CMK_WARNINGS_ARE_ERRORS"
863 # If the user has asked for the latest language standards (C11 or CPP11)
864 if [ "$USE_NEW_STD" = "1" ]
865 then
866 # and if configure confirmed that the underlying compiler knows abt C11, enable it
867 if [ "$CMK_COMPILER_KNOWS_C11" = "1" ]
868 then
869 OPTS_CC="$OPTS $CMK_ENABLE_C11"
871 # and if configure confirmed that the underlying compiler knows abt CPP11, enable it
872 if [ "$CMK_COMPILER_KNOWS_CPP11" = "1" ]
873 then
874 OPTS_CXX="$OPTS $CMK_ENABLE_CPP11"
878 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
879 then
880 USE_OPENMP="yes"
881 TLSGLOBALS="1"
883 if [ ! -x "$CMK_ROSE_OMP_TOOL" ]
884 then
885 Abort "The environment variable CMK_ROSE_OMP_TOOL must contain the path to a built binary of the ROSE OpenMP variable privatization tool"
889 if [ "$USE_OPENMP" = "yes" ]
890 then
891 [ -n "$VERBOSE" ] && echo OpenMP support enabled
892 OPTS_CC="$OPTS_CC $CMK_C_OPENMP"
893 OPTS_CXX="$OPTS_CXX $CMK_C_OPENMP"
894 OPTS_F90="$OPTS_F90 $CMK_F_OPENMP"
895 OPTS_LD="$OPTS_LD $CMK_LD_OPENMP"
896 OPTS_LDXX="$OPTS_LDXX $CMK_LD_OPENMP"
897 else
898 [ -n "$VERBOSE" ] && echo OpenMP support not enabled
901 if [ "$TLSGLOBALS" = "1" ]
902 then
903 OPTS_CC="$OPTS_CC -mno-tls-direct-seg-refs"
904 OPTS_CXX="$OPTS_CXX -mno-tls-direct-seg-refs"
905 OPTS_F90="$OPTS_F90 -mno-tls-direct-seg-refs"
906 OPTS_LD="$OPTS_LD -static -Wl,--allow-multiple-definition"
907 OPTS_LDXX="$OPTS_LDXX -static -Wl,--allow-multiple-definition"
910 # Look up and add the dependencies for module $1
911 findModuleDep() {
912 M=$1
913 notInList $M $PROCESSED_MODULES || return
914 PROCESSED_MODULES="$PROCESSED_MODULES $M"
915 #PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
916 PRE_LIBRARIES=`AddList -lmodule$M $PRE_LIBRARIES`
917 # HACK: add modules to both ends of library list, to avoid
918 # undefined symbol CkRegisterMainModule when it's in a module file.
919 POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
920 if [ "$M" = "PythonCCS" ]
921 then
922 LINK_PYTHON=1
925 dep=""
926 # fixme: should search everything in the -L library paths:
927 for dir in `echo . $CHARMLIB`
929 d="$dir/libmodule$M.dep"
930 [ -r "$d" ] && dep=$d
931 done
932 if [ -r "$dep" ]
933 then
934 # Add the module dependencies in this file
935 # Debugf "Adding module" $M "dependencies from" $dep
936 deps=`cat $dep`
937 Debugf "Module" $M "adds dependencies:" $deps
938 processArgs $deps
942 # Repeat the module-dependency search until we find no
943 # new modules:
944 START_MODULES=""
945 while [ "$START_MODULES" != "$MODULES" ]
947 Debugf "----------- Module dependency search ------------"
948 START_MODULES="$MODULES"
949 for m in $MODULES
951 findModuleDep $m
952 done
953 done
955 Debugf "----------- Module dependency search complete ------------"
959 ##############################################################################
961 # Load machine-specific configuration data, then handle overrides to it.
963 ##############################################################################
966 if [ x"$CMK_NO_BUILD_SHARED" = "xfalse" ]
967 then
968 BUILD_SHARE="1"
971 if [ "$BUILD_SHARE" = "1" ]
972 then
973 if [ x"$CMK_NO_BUILD_SHARED" = "xtrue" -o -z "$CHARMLIBSO" ]
974 then
975 BUILD_SHARE="0"
976 else
977 USE_PIC="1"
981 OPTS_PIC="$CMK_PIC"
982 if [ "$USE_PIC" = "1" ]
983 then
984 OPTS_CC="$OPTS_CC $OPTS_PIC"
985 OPTS_CXX="$OPTS_CXX $OPTS_PIC"
986 OPTS_F90="$OPTS_F90 $OPTS_PIC"
987 OPTS_LD="$OPTS_LD $OPTS_PIC"
990 if [ "$BUILD_SHARE" = "1" ]
991 then
992 # ignore BUILD_SHARE if the target is not .a or .so
993 case "$OBJECT" in
994 *.a|*.so|*.so.*|*.sl|*.dylib)
995 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
998 BUILD_SHARE="0"
1000 esac
1003 if [ -n "$OVERRIDE_CC" ]
1004 then
1005 CMK_CC="$OVERRIDE_CC"
1007 Debug "set 2"
1008 if [ -n "$OVERRIDE_CXX" ]
1009 then
1010 CMK_CXX="$OVERRIDE_CXX"
1013 if [ -n "$OVERRIDE_F90" ]
1014 then
1015 CMK_CF90="$OVERRIDE_F90"
1018 if [ -n "$OVERRIDE_LD" ]
1019 then
1020 CMK_LD="$OVERRIDE_LD"
1023 if [ -n "$OVERRIDE_LDXX" ]
1024 then
1025 CMK_LDXX="$OVERRIDE_LDXX"
1028 if [ -n "$USE_RELIABLE_CC" ]
1029 then
1030 CMK_CC="$CMK_CC_RELIABLE"
1033 if [ -n "$USE_FASTEST_CC" ]
1034 then
1035 CMK_CC="$CMK_CC_FASTEST"
1038 if [ -n "$USE_F77" ]
1039 then
1040 CMK_CF90=$CMK_CF77
1041 CMK_CF90_FIXED=$CMK_CF77
1042 CMK_F90LIBS=$CMK_F77LIBS
1045 if [ -n "$CMK_F90_MODINC" ]
1046 then
1047 CMK_CF90_MODINC="$CMK_F90_MODINC"
1048 else
1049 CMK_CF90_MODINC="-M"
1052 if [ -n "$F90_MODDIR" ]
1053 then
1054 for dir in $F90_MODDIR
1056 OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
1057 done
1060 if [ -n "$CMK_F90_USE_MODDIR" ]
1061 then
1062 CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC $CHARMINC $CMK_SYSINC"
1065 if [ -n "$SEQUENTIAL" ]
1066 then
1067 CMK_CC="$CMK_SEQ_CC -DCMK_SEQUENTIAL=1 "
1068 CMK_LD="$CMK_SEQ_LD"
1069 CMK_CXX="$CMK_SEQ_CXX -DCMK_SEQUENTIAL=1 "
1070 CMK_CF90="$CMK_SEQ_F90 "
1071 CMK_LDXX="$CMK_SEQ_LDXX"
1072 CMK_AR="$CMK_SEQ_AR"
1073 CMK_RANLIB="$CMK_SEQ_RANLIB"
1076 if [ -n "$NATIVE" ]
1077 then
1078 CMK_CC="$CMK_NATIVE_CC "
1079 CMK_LD="$CMK_NATIVE_LD"
1080 CMK_CXX="$CMK_NATIVE_CXX "
1081 CMK_LDXX="$CMK_NATIVE_LDXX"
1084 if [ -n "$PREPROCESS" ]
1085 then
1086 CMK_CF90=$CMK_FPP
1089 if [ -n "$PURIFY" ]
1090 then
1091 CMK_LD="purify $CMK_LD"
1092 CMK_LDXX="purify $CMK_LDXX"
1095 Debug "set 4"
1096 if [ "$OPTIMIZE_MODE" = "true" ]
1097 then
1098 OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
1099 OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
1100 OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
1101 OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
1102 OPTS_LDXX="$CMK_CXX_OPTIMIZE $OPTS_LDXX"
1105 # Pick up per-architecture production mode settings
1106 if [ "$PRODUCTION_MODE" = "true" ]
1107 then
1108 OPTS_CC="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_CC"
1109 OPTS_CXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_CXX"
1110 OPTS_F90="$CMK_PRODUCTION $CMK_F90_PRODUCTION $OPTS_F90"
1111 OPTS_LD="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_LD"
1112 OPTS_LDXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_LDXX"
1115 if [ -n "$XI_INTERNAL" ]
1116 then
1117 CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
1120 if [ "$GENDEPENDS" = "yes" ]
1121 then
1122 CMK_XIOPTS="$CMK_XIOPTS -M"
1125 if [ "$COUNTTOKENS" = "yes" ]
1126 then
1127 CMK_XIOPTS="$CMK_XIOPTS -count-tokens"
1130 if test "$CMK_WITH_TAU" = "true"
1131 then
1132 echo "include $TAU_MAKEFILE" > _make.tau.tmp
1133 echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1134 TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1135 TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1136 TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1137 TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1138 TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1140 rm -f _make.tau.tmp
1143 #Add generic options to the compiler- and linker-options
1144 OPTS_CC="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CC"
1145 OPTS_CXX="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CXX"
1146 OPTS_F90="$OPTS $OPTS_F90"
1147 OPTS_LD="$OPTS $OPTS_LD"
1148 # OPTS_LDXX gets OPTS from OPTS_LD
1150 if [ -n "$F90_MAIN" ]
1151 then
1152 # for_main needs to be placed at beginning
1153 CMK_LD="$CMK_LD $CMK_F90MAINLIBS"
1154 CMK_LDXX="$CMK_LDXX $CMK_F90MAINLIBS"
1157 # There's really no analog for this in the Bourne shell:
1158 # -------- C Shell ------> onintr failure
1159 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
1161 ##############################################################################
1163 # Check for valid choice of LANGUAGE
1165 ##############################################################################
1166 Debug "Checking language..."
1168 if [ -z "$LANGUAGE" ]
1169 then
1170 LANGUAGE="charm++"
1171 [ -n "$SEQUENTIAL" ] && LANGUAGE=c
1174 case "$LANGUAGE" in
1175 "c"|"C"|"c++"|"C++")
1176 [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
1178 esac
1180 # update charm to bgcharm
1181 if [ "$LANGUAGE" = "charm++" -a -n "$CMK_BIGSIM" ]
1182 then
1183 LANGUAGE="bgcharm++"
1185 if [ "$LANGUAGE" = "converse++" -a -n "$CMK_BIGSIM" ]
1186 then
1187 LANGUAGE="bgconverse++"
1189 if [ "$LANGUAGE" = "bgcharm++" ]
1190 then
1191 TRACEMODE=`AddList $TRACEMODE bluegene`
1194 ########################################################################
1196 # We've parsed and verified the command-line parameters.
1197 # Now we prepare routines to clean up and exit.
1198 # None of these routines ever returns-- they all just exit.
1200 ########################################################################
1203 Copyobj() {
1204 if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ]
1205 then
1206 [ -d $COPYTO ] && COPYTO="$COPYTO/"
1207 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
1208 Warning "Appending $PROG_EXT to object file name"
1209 OBJECT="$OBJECT$PROG_EXT"
1211 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO
1212 Do $CP $OBJECT $COPYTO
1214 test -n "$COPY_EXIT" && Success
1217 Copymod() {
1218 for COPY in `echo $MODCOPIES`
1220 if [ "a$COPY" != "a$OBJECT" ]
1221 then
1222 [ -d $COPY ] && COPY="$COPY/"
1223 if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
1224 OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
1226 if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
1227 Warning "Appending .$CMK_MOD_EXT to object file name"
1228 OBJECT="$OBJECT.$CMK_MOD_EXT"
1230 [ ! -d $COPY ] && DoNoErrCheck $RM $COPY
1231 Do $CP $OBJECT $COPY
1233 done
1234 Success
1237 Success() {
1238 End 0
1242 ##############################################################################
1244 # Preprocess the GEN-CPM files
1246 ##############################################################################
1248 Debug "Preprocessing GEN-CPM files"
1250 if [ "$CMK_USING_BGCLANG" = "1" ]
1251 then
1252 OPTS_CC_GENCPM="-x c " # -x c is only applied for the preprocessing of the GEN-CPM files on BG/Q
1255 OPTS_CC_GENCPM="$OPTS_CC $OPTS_CC_GENCPM"
1256 for FILE in `echo $GENCPM`
1258 # This used to be "$FILE:r", which strips the extention
1259 BASE=`stripExtention $FILE`
1260 TMP=`basename $FILE`".TMP"
1261 DELETE="$DELETE $TMP.c $TMP.i"
1262 DoNoErrCheck $RM $BASE.cpm.h $TMP.c
1263 Do touch $BASE.cpm.h
1264 Do $LN -f -s $FILE $TMP.c
1265 Do $CMK_CPP_C -I$CHARMINC $CMK_SYSINC $OPTS_CC_GENCPM $OPTS_CPP $TMP.c > $TMP.i
1266 Do $CHARMBIN/conv-cpm $TMP.i $BASE.cpm.h
1267 done
1269 ##############################################################################
1271 # Compile all specified files
1273 # All temporary files named *.TMP.* for easy cleanup.
1275 ##############################################################################
1277 Debug "About to compile..."
1279 numFiles=`echo $FILES | wc -w`
1280 for FILE in `echo $FILES`
1282 BASE=`stripExtention \`basename $FILE\``
1283 TMP=`basename $FILE`".TMP"
1284 FILE_EXT=`getExtention $FILE`
1285 BASEO="$BASE.o"
1286 DESTO="-o $BASEO"
1288 # in case of: charmc -o object.o -c foo.c,
1289 # avoid foo.c => remove foo.o => foo.o => object.o,
1290 # instead generate object.o directly.
1291 # remove and generate foo.o may be dangerous in parallel make
1292 # for example in the case of compiling several objs from one
1293 # same c file such as memory.c.
1294 if [ $numFiles = 1 -a -n "$OBJECT" ]
1295 then
1296 OBJ_EXT=`getExtention $OBJECT`
1297 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
1298 then
1299 BASEO=$OBJECT
1300 DESTO="-o $OBJECT"
1304 # if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".co" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1305 # then
1306 case "$FILE_EXT" in
1307 .c|.s|.C|.cc|.cxx|.cpp|.c++|.cu|.f|.F|.f90|.F90|.fpp|.FPP|.f77|.F77)
1308 [ $VERBOSE ] && echo "Compiling $FILE"
1309 DoNoErrCheck $RM $BASEO $BASE.f.o
1310 esac
1311 # fi
1312 if [ ! -z "$SKIPLINK" ]
1313 then
1314 DESTO=""
1316 NU_OBJ=""
1318 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
1319 then
1320 case "$FILE" in
1321 *.c)
1322 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE
1323 FILE="rose_$FILE"
1325 *.C|*.cc|*.cxx|*.cpp|*.c++)
1326 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE
1327 FILE="rose_$FILE"
1329 *.f|*.F|*.f77|*.F77)
1330 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE
1331 FILE="rose_$FILE"
1333 *.f90|*.F90|*.fpp|*.FPP)
1334 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1335 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE
1336 FILE="rose_$FILE"
1338 esac
1341 case "$FILE" in
1342 *.ci)
1343 XIOPTS=$CMK_XIOPTS
1344 test "$LANGUAGE" = "f90charm" && XIOPTS="$XIOPTS -f90"
1345 if [ "$PREPROCESS_CI" = "yes" ]
1346 then
1347 Do $CMK_CPP_CHARM $OPTS_CPP $FILE | Do $CHARMBIN/charmxi $XIOPTS -orig-file $FILE
1348 else
1349 Do $CHARMBIN/charmxi $XIOPTS $FILE
1352 *.c|*.s)
1353 Do $CMK_CC -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE $DESTO
1354 NU_OBJ=$BASEO
1355 if [ "$Do_res" -ne 0 ]
1356 then
1357 touch $BASEO
1360 bglmachine.C)
1361 Do $CMK_GCXX -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE $DESTO
1362 NU_OBJ=$BASEO
1364 *.C|*.cc|*.cxx|*.cpp|*.c++|*.cu)
1365 if [ -n "$NATIVE" ]
1366 then
1367 Do $CMK_NATIVE_CXX -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP -c $FILE $DESTO
1368 else
1369 Do $CMK_CXX -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE $DESTO
1371 NU_OBJ=$BASEO
1372 if [ "$Do_res" -ne 0 ]
1373 then
1374 touch $BASEO
1377 *.f|*.F|*.f77|*.F77)
1378 test -z "$CMK_CF90_FIXED" && Abort "No F90 compiler (CMK_CF90_FIXED) defined"
1379 Do $CMK_CF90_FIXED -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1380 NU_OBJ=$BASEO
1381 if [ "$Do_res" -ne 0 ]
1382 then
1383 touch $BASEO
1386 *.f90|*.F90|*.fpp|*.FPP)
1387 test -z "$CMK_CF90" && Abort "No F90 compiler (CMK_CF90) defined"
1388 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1389 Do $CMK_CF90 -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE $DESTO
1390 NU_OBJ=$BASEO
1391 if [ "$Do_res" -ne 0 ]
1392 then
1393 touch $BASEO
1396 *.fc|*.FC)
1397 Abort "I'm not yet smart enough to compile $FILE"
1399 *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
1400 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1401 OBJECTFILES="$OBJECTFILES $FILE"
1403 *.M|*.mod)
1404 OBJECT="$BASE"
1405 Copymod
1406 Success
1409 Abort "file with unrecognized extension $FILE"
1410 esac
1411 # Handle new object files
1412 if [ -n "$NU_OBJ" -a -n "$OBJECT" ]
1413 then
1414 if [ "$OBJECT" != "$BASEO" ]
1415 then
1416 DELETE="$DELETE $NU_OBJ"
1418 OBJECTFILES="$OBJECTFILES $NU_OBJ"
1420 done
1422 ##############################################################################
1424 # POSSIBLY, SKIP LINK-STEP
1426 # 1. No $OBJECT may be specified at all --- its just a compilation.
1427 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1428 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1429 # 4. Language may be sequential. Do a quick and easy linkage.
1431 # in any of these cases, the full link step is skipped.
1433 ##############################################################################
1435 MakeSO() {
1436 Debugf "Running ldro..."
1437 DoNoErrCheck $RM $OBJECT
1438 # convert to absolute path if required
1439 if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1440 then
1441 dir=`dirname $OBJECT`
1442 fname=`basename $OBJECT`
1443 dir=`cd $dir; pwd`
1444 OBJECT=$dir/$fname
1446 Warning "Warning: creating $OBJECT "
1447 if test "$MAKE_LDXX" = "1"
1448 then
1449 soCmd="$CMK_LDXX -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $PRE_LIBRARIES $POST_LIBRARIES $CMK_LD_SHARED_LIBS"
1450 else
1451 soCmd="$CMK_LD -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $PRE_LIBRARIES $POST_LIBRARIES $CMK_LD_SHARED_LIBS"
1453 DoNoErrCheck $soCmd
1454 Do_res=$?
1455 if [ $Do_res -ne 0 ]
1456 then
1457 if [ -n $NOABORT ]
1458 then
1459 touch $OBJECT
1460 else
1461 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1462 echo "!! Failed to compile Charm++ shared library. You can disable shared !!"
1463 echo "!! lib compilation by providing --no-build-shared build option like: !!"
1464 echo "!! ./build charm++ net-linux --no-build-shared -O !!"
1465 echo "!! or reexecute this charmc command with --no-build-shared compile option !!"
1466 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1467 Abort "Command $soCmd returned error code $Do_res"
1470 Copyobj
1473 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ]
1474 then
1475 # We have no target object, or are playing preprocessor tricks-- just end
1476 Debugf "No target object-- finished"
1477 Success
1480 Debug "About to link..."
1482 # if interoperate dont create the library now, wait to collect all info
1483 if [ "$MPI_INTEROPERATE" = "" ]
1484 then
1485 case "$OBJECT" in
1486 *.o)
1487 Debugf "Converting $FILES to $OBJECTFILES"
1488 nFiles=`echo $FILES | wc -w`
1489 nObj=`echo $OBJECTFILES | wc -w`
1490 # One source file, one .o: just move the .o
1491 if [ $OBJECT != $OBJECTFILES ]
1492 then
1493 Debugf "Moving .o to destination"
1494 DoNoErrCheck $RM $OBJECT
1495 Do $MV $OBJECTFILES $OBJECT
1497 Copyobj
1499 *.so|*.so.*|*.sl|*.dylib)
1500 # Make shared library
1501 # if no build share is set, exit normally.
1502 if [ "$BUILD_SHARE" = 0 ]
1503 then
1504 echo "Warning: building shared library is skipped, possibly due to not supported, check configuration files."
1505 End 0
1506 elif [ "$CHARM_SHARED" = "0" ]
1507 then
1508 MakeSO
1511 *.a)
1512 # Make regular (.a, non-shared) library
1513 # in case building charm so, build .so under lib_so as well # Gengbin
1514 if [ "$BUILD_SHARE" = "1" ]
1515 then
1516 COPY_EXIT=""
1517 OBJECT_SAVE=$OBJECT
1518 COPYTO_SAVE=$COPYTO
1519 if [ -z "$COPYTO" ]
1520 then
1521 DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
1522 OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
1523 else
1524 COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
1525 DESTDIR=$COPYTO
1527 OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
1528 [ -f $DESTDIR/.charmso ] && MakeSO
1529 COPYTO=$COPYTO_SAVE
1530 OBJECT=$OBJECT_SAVE
1531 COPY_EXIT="true"
1533 # build normal .a
1534 DoNoErrCheck $RM $OBJECT
1535 Do $CMK_AR $OBJECT $OBJECTFILES
1536 Do $CMK_RANLIB $OBJECT
1537 Copyobj
1539 esac
1541 # If the above case returns, we're not creating a .o or .a file,
1542 # so linking is needed.
1544 ############ Determine the language and libraries ##########
1546 # Parse out the real languages
1547 case "$LANGUAGE" in
1548 "charm++f")
1549 LANGUAGE="charm++"
1550 USE_F90_LIBRARIES="1"
1552 "f90charm")
1553 PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm -lckf"
1554 POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1556 "bluegene"|"bigsim")
1557 PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs"
1559 "ckbluegene")
1560 POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1562 "bgcharm++")
1563 PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs -lconv-bluegene-stub"
1565 "bgconverse++")
1566 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bigsim -lconv-bigsim-logs"
1568 esac
1570 # DMK - ACCEL SUPPORT - If this is a cell build, add the spe code object to POST_LIBRARIES
1571 if [ $CMK_CELL -eq 1 ]
1572 then
1574 if [ "$LANGUAGE" = "converse++" ]
1575 then
1576 # Include a "do nothing" register_accel_spe_funcs() function
1577 POST_LIBRARIES="$POST_LIBRARIES -lnoAccelStub"
1580 if [ "$LANGUAGE" = "charm++" ]
1581 then
1583 if [ $SPU_USE_CPP -eq 1 ]
1584 then
1585 SPU_COMPILER=$CMK_SPU_CXX
1586 SPU_LINKER=$CMK_SPU_LDXX
1587 else
1588 SPU_COMPILER=$CMK_SPU_CC
1589 SPU_LINKER=$CMK_SPU_LD
1592 # Make the spe object file to be included
1593 Do $SPU_COMPILER -c -I$CHARMINC $CMK_SYSINC -o main__funcLookup__.genSPECode.o main__funcLookup__.genSPECode.c -DCMK_CELL_SPE=1
1594 Do $SPU_LINKER -L$CHARMLIB -o main__funcLookup__.genSPECode main__funcLookup__.genSPECode.o $CMK_SPERT_LIBS $SPU_EXTRA_LIBS
1595 Do $CMK_PPU_EMBEDSPU spert_main main__funcLookup__.genSPECode main__funcLookup__.genSPECode.ppe.o
1597 # Include the spe object file for linking into main executable
1598 POST_LIBRARIES="$POST_LIBRARIES main__funcLookup__.genSPECode.ppe.o"
1603 if [ "$AMPIMAIN" != "" ]
1604 then
1605 OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1608 if [ "$SWAPGLOBALS" = "1" ]
1609 then
1610 swapo="$CHARMLIB/libglobal-swap.a"
1611 if [ ! -r "$swapo" -o ! -s "$swapo" ]
1612 then
1613 echo "Global-swapping library $swapo missing--"
1614 echo " Is -swapglobals supported on this machine?"
1615 exit 1
1616 else
1617 MIDDLE_LIBS="-lglobal-swap $MIDDLE_LIBS"
1620 if [ "$SWAPGLOBALS" = "2" ]
1621 then
1622 echo "-copyglobals option is no longer supported by Charm++/AMPI"
1623 exit 1
1626 if [ $USE_F77_LIBRARIES = "1" ]
1627 then
1628 POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1631 if [ $USE_F90_LIBRARIES = "1" ]
1632 then
1633 if [ ! -r $CHARMLIB/libconv-utilf.a ]
1634 then
1635 echo "Fortran support library $CHARMLIB/libconv-utilf.a missing"
1636 echo "Is your Fortran compiler working?"
1637 exit 1
1640 POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1643 # dummy main module
1644 if [ "$MPI_INTEROPERATE" != "" -a "$NO_MAIN_MODULE" = "" ]
1645 then
1646 POST_LIBRARIES="-lmpi-mainmodule $POST_LIBRARIES"
1649 # check if we're linking a sequential object
1650 case "$LANGUAGE" in
1651 "c"|"C"|"f90"|"f77")
1652 if [ -n "$NATIVE" ]
1653 then
1654 Do $CMK_NATIVE_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1655 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1656 else
1657 Do $CMK_SEQ_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1658 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1660 Copyobj
1662 "c++"|"C++")
1663 if [ -n "$NATIVE" ]
1664 then
1665 Do $CMK_NATIVE_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1666 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1667 else
1668 Do $CMK_SEQ_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1669 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1671 Copyobj
1673 esac
1675 ##############################################################################
1677 # Some quick consistency checks prior to full link-step
1679 # Check for valid choice of TRACEMODE
1680 # Check for valid choice of BALANCE
1681 # Check for compatibility among BALANCE and TRACEMODE
1683 ##############################################################################
1685 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1687 # Check for valid choice of TRACEMODE
1689 # [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed. Is Charm++ built properly?"
1691 if [ x"$TRACEMODE" != x ]
1692 then
1693 for trace in $TRACEMODE; do
1694 [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
1695 TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1696 done
1697 TRACE_OBJ="$TRACE_OBJ $CMK_LIBZ"
1700 if test x$LANGUAGE = x"bgcharm++"
1701 then
1702 BALANCE=bluegene
1705 BAL_EXT=`getExtention $BALANCE`
1706 if [ -z "$BAL_EXT" ]; then
1707 # Balance has no extension-- is a library reference
1708 if [ -f "${CHARMLIB}/libldb-$BALANCE.a" ]; then
1709 BAL_OBJ="${CHARMLIB}/libldb-$BALANCE.a"
1710 else
1711 BAL_OBJ="${CHARMLIBSO}/libldb-$BALANCE.so"
1713 else
1714 # Balance has some extension-- must be a .o or .a file
1715 BAL_OBJ="$BALANCE"
1718 Debug "Finished with BAL_OBJ=$BAL_OBJ, TRACEMODE=$TRACEMODE..."
1720 if [ ! -r "$BAL_OBJ" ]
1721 then
1722 if [ "$BALANCE" = "$BAL_OBJ" ]
1723 then
1724 Abort "Could not find load balancer object $BAL_OBJ"
1725 else
1726 (cd $CHARMLIB ; ls -al libldb-*)
1727 Abort "Unknown load balancer $BALANCE / $BAL_OBJ"
1731 BAL_OBJ="-lldb-$BALANCE -lconv-ldb"
1733 # Check for valid choice of MEMORY
1735 if [ -f "${CHARMLIB}/libmemory-${MEMORY}.a" ]; then
1736 MEM_OBJ="${CHARMLIB}/libmemory-${MEMORY}.a"
1737 else
1738 MEM_OBJ="${CHARMLIBSO}/libmemory-${MEMORY}.so"
1741 if [ ! -r $MEM_OBJ -o ! -s $MEM_OBJ ]
1742 then
1743 (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1744 Abort "charmc : No such memory mode $MEMORY"
1747 MEM_OBJ="-lmemory-${MEMORY}"
1749 # For memory wrapping around the OS allocator, need to add also the wrapper object
1750 case $MEMORY in
1751 os-*)
1752 MEM_OBJ=$MEM_OBJ" -lmemory-os-wrapper"
1754 esac
1756 # Check for valid choice of THREAD
1758 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1759 then
1760 THREAD=$CMK_LD_SHARED_THREAD
1762 if [ "$TLSGLOBALS" = "1" ]
1763 then
1764 # make sure we don't add an extra -tls
1765 if ! echo $THREAD | grep '\-tls$' > /dev/null 2> /dev/null
1766 then
1767 THREAD=${THREAD}-tls
1771 if [ -f "${CHARMLIB}/libthreads-${THREAD}.a" ]; then
1772 THREAD_OBJ="${CHARMLIB}/libthreads-${THREAD}.a"
1773 else
1774 THREAD_OBJ="${CHARMLIBSO}/libthreads-${THREAD}.so"
1777 if [ ! -r $THREAD_OBJ -o ! -s $THREAD_OBJ ]
1778 then
1779 (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1780 Abort "charmc : No such thread mode $THREAD"
1783 THREAD_OBJ="-lthreads-${THREAD}"
1785 ################# Build the module initialization function ##################
1786 modInitName="moduleinit$$"
1787 modInitSrc="$modInitName.C"
1788 modInitObj="$modInitName.o"
1789 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
1791 for module in $MODULES; do
1792 echo "extern void _register$module(void);" >> $modInitSrc
1793 done
1794 for trace in $TRACEMODE; do
1795 if test $trace = "summary"
1796 then
1797 echo " extern void _registerTraceSummary();" >> $modInitSrc
1798 elif test $trace = "projections"
1799 then
1800 echo " extern void _registerTraceProjections();" >> $modInitSrc
1801 elif test $trace = "simple"
1802 then
1803 echo " extern void _registerTraceSimple();" >> $modInitSrc
1804 elif test $trace = "Tau"
1805 then
1806 echo " extern void _registerTraceTau();" >> $modInitSrc
1807 elif test $trace = "utilization"
1808 then
1809 echo " extern void _registerTraceUtilization();" >> $modInitSrc
1810 elif test $trace = "controlPoints"
1811 then
1812 echo " extern void _registerTraceControlPoints();" >> $modInitSrc
1813 elif test $trace = "perfReport"
1814 then
1815 Do $CP $CHARMBIN/fuzzytree.txt fuzzytree.txt
1816 Do $CP $CHARMBIN/tree.txt tree.txt
1817 echo " extern void _registerTraceAutoPerf();" >> $modInitSrc
1819 elif test $trace = "all"
1820 then
1821 echo " extern void _registerTraceProjections();" >> $modInitSrc
1822 echo " extern void _registerTraceControlPoints();" >> $modInitSrc
1823 echo " extern void _registerTraceSummary();" >> $modInitSrc
1825 done
1826 if test -n "$BALANCER"
1827 then
1828 echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
1830 echo "void _registerExternalModules(char **argv) { (void)argv;" >> $modInitSrc
1831 for module in $MODULES; do
1832 [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
1833 echo " _register$module();" >> $modInitSrc
1834 done
1835 for trace in $TRACEMODE; do
1836 if test $trace = "summary"
1837 then
1838 echo " _registerTraceSummary();" >> $modInitSrc
1839 elif test $trace = "projections"
1840 then
1841 echo " _registerTraceProjections();" >> $modInitSrc
1842 elif test $trace = "Tau"
1843 then
1844 TRACE_WITH_TAU=1
1845 echo " _registerTraceTau();" >> $modInitSrc
1846 elif test $trace = "simple"
1847 then
1848 echo " _registerTraceSimple();" >> $modInitSrc
1849 elif test $trace = "utilization"
1850 then
1851 echo " _registerTraceUtilization();" >> $modInitSrc
1852 elif test $trace = "controlPoints"
1853 then
1854 echo " _registerTraceControlPoints();" >> $modInitSrc
1855 elif test $trace = "perfReport"
1856 then
1857 echo " _registerTraceAutoPerf();" >> $modInitSrc
1858 elif test $trace = "all"
1859 then
1860 echo " _registerTraceProjections();" >> $modInitSrc
1861 echo " _registerTraceControlPoints();" >> $modInitSrc
1862 echo " _registerTraceSummary();" >> $modInitSrc
1864 done
1865 if test -n "$BALANCER"
1866 then
1867 [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
1868 for deflb in $BALANCER
1870 echo " LBDefaultCreate(\"$deflb\");" >> $modInitSrc
1871 done
1873 echo "}" >> $modInitSrc
1875 # creating projections
1876 echo "void _createTraces(char **argv) { (void)argv;" >> $modInitSrc
1877 for trace in $TRACEMODE; do
1878 [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
1879 echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
1880 echo "_createTrace$trace(argv);" >> $modInitSrc
1881 done
1882 echo "}" >> $modInitSrc
1884 Do $CMK_CXX $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $modInitSrc -o $modInitObj
1886 ###############################################################################
1888 # Finally, LINK
1890 ###############################################################################
1892 Debug "About to perform final link..."
1894 MAKE_LDXX="0"
1895 MAKE_LD="0"
1897 CORE_LIBS="-lconv-core -ltmgr -lconv-util -lconv-partition $TRACE_OBJ"
1899 # get TAU stub makefile variables
1900 if test "$CMK_WITH_TAU" = "true"
1901 then
1902 echo "include $TAU_MAKEFILE" > _make.tau.tmp
1903 echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1904 TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1905 TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1906 TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1907 TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1908 TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1910 rm -f _make.tau.tmp
1912 # done getting TAU variables
1914 if [ "$BUILD_SHARE" = "0" ]
1915 then
1916 MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1919 case "$LANGUAGE" in
1920 "f90charm")
1921 MAKE_LDXX="1"
1922 MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-cplus-y $CORE_LIBS "
1923 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1924 if [ "$NO_MAIN" = "" ]
1925 then
1926 MIDDLE_LIBS="-lckmain $MIDDLE_LIBS"
1928 if [ "$TAU_TRACE_MPI" = "1" ]
1929 then
1930 TAU_LIBS="$TAU_MPI_FLIBS $TAU_LIBS"
1931 else
1932 TAU_LIBS="$TAU_LIBS"
1935 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1936 MAKE_LDXX="1"
1937 MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-cplus-y $CORE_LIBS "
1938 if [ "$NO_MAIN" = "" ]
1939 then
1940 MIDDLE_LIBS="-lckmain $MIDDLE_LIBS"
1942 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1943 if [ "$TAU_TRACE_MPI" = "1" ]
1944 then
1945 TAU_LIBS="$TAU_MPI_LIBS $TAU_LIBS"
1946 else
1947 TAU_LIBS="$TAU_LIBS"
1950 "converse")
1951 MAKE_LD="1"
1952 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-cplus-n $CORE_LIBS -ltrace-converse "
1953 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1955 "converse++"|"bluegene"|"bigsim"|"bgconverse++")
1956 MAKE_LDXX="1"
1957 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-cplus-y $CORE_LIBS -ltrace-converse "
1958 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1961 Abort "Unrecognized choice of language $LANGUAGE"
1963 esac
1965 if [ "$BUILD_SHARE" = "0" ]
1966 then
1967 MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1970 if [ "$CHARM_SHARED" = "1" ]
1971 then
1972 [ -z "$CHARMLIBSO" ] && Abort "Charm++ lib_so directory not found!"
1973 # build user executable/shared lib linking with charm .so
1974 OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1975 if [ "$BUILD_SHARE" = "1" ]
1976 then
1977 LANG_LIBS="-L$CHARMLIBSO $OBJECTFILES $PRE_LIBRARIES"
1978 else
1979 LANG_LIBS="-L$CHARMLIBSO $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1981 else
1982 # if interoperate, need a lib with moduleinit
1983 if [ "$MPI_INTEROPERATE" != "" ]
1984 then
1985 LANG_LIBS="-L$CHARMLIB -I$CHARMINC $CMK_SYSINC $PRE_LIBRARIES"
1986 else
1987 LANG_LIBS="-L$CHARMLIB -I$CHARMINC $CMK_SYSINC $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1990 if [ "$TRACE_WITH_TAU" = 1 ]
1991 then
1992 echo "Linking with the TAU libraries: $TAU_LIBS"
1993 ALL_LIBS="$LANG_LIBS $MIDDLE_LIBS $BAL_OBJ $CMK_LIBS $POST_LIBRARIES $CMK_SYSLIBS $TAU_LIBS"
1994 else
1995 ALL_LIBS="$LANG_LIBS $MIDDLE_LIBS $BAL_OBJ $CMK_LIBS $POST_LIBRARIES $CMK_SYSLIBS"
1997 Debugf "All libraries are: $ALL_LIBS"
1999 #currently only support creation of .a
2000 if [ "$MPI_INTEROPERATE" != "" ]
2001 then
2002 case "$OBJECT" in
2003 *.a)
2004 # in case building charm so, build .so under lib_so as well # Gengbin
2005 DoNoErrCheck $RM $OBJECT
2006 echo "$CMK_AR $OBJECT $OBJECTFILES $modInitObj"
2007 Do $CMK_AR $OBJECT $OBJECTFILES $modInitObj
2008 Do $CMK_RANLIB $OBJECT
2009 echo "export CHARM_ALL_LIBS=\"$ALL_LIBS\"" > ./charm_all_libs.sh
2010 echo "CHARM_ALL_LIBS=\"$ALL_LIBS\""
2011 Copyobj
2013 *.so|*.so.*|*.sl|*.dylib)
2014 echo "Warning: building shared library failed; for interoperation build
2015 static library."
2016 End 0
2018 esac
2021 if [ "$MPI_INTEROPERATE" != "" ]
2022 then
2023 ALL_LIBS="$OBJECTFILES $modInitObj $ALL_LIBS"
2026 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
2027 then
2028 # build an application .so linking with charm .so
2029 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
2030 Debugf "Running ldro..."
2031 DoNoErrCheck $RM $OBJECT
2032 [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
2033 [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
2034 Copyobj
2035 else
2036 # Make a regular executable: call the appropriate linker
2037 [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
2038 [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
2041 ########################################################################
2043 # Copy conv-host to user directory if it is present in installation.
2045 ########################################################################
2047 if test "$COPY_CHARMRUN" = "true"
2048 then
2049 targ=charmrun$CMK_POST_EXE
2050 [ ! -x $CHARMBIN/$targ -a -n "$CMK_POST_EXE" ] && targ=charmrun
2051 convhost=conv-host$CMK_POST_EXE
2053 if [ -x $CHARMBIN/$targ ]
2054 then
2055 DoNoErrCheck $RM $targ
2056 Do $CP $CHARMBIN/$targ $targ
2060 [ -z "$SAVE" ] && DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2062 Copyobj