Fix parallel build of examples/charm++/user-driven-interop
[charm.git] / src / scripts / charmc
blob54771c280724d604970d88e11ef47b2992911e15
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 STANDALONE=""
25 LANGUAGE=""
26 PARADIGM=""
27 BALANCE="rand"
28 TRACEMODE=""
29 TRACE_OBJ=
30 MEMORY="default"
31 THREAD="default"
32 VERBOSE=""
33 DEBUG_SCRIPT=""
34 SAVE=""
35 PURIFY=""
36 SKIPLINK=""
37 OVERRIDE_CC=""
38 OVERRIDE_CXX=""
39 OVERRIDE_F90=""
40 OVERRIDE_LD=""
41 OVERRIDE_LDXX=""
42 #Generic options, passed to everything
43 OPTS=""
44 #Specific options
45 #charm internal flag, only pass to c and cxx, not f90
46 OPTS_CPP_INTERNAL="-D__CHARMC__=1"
47 OPTS_CPP=
48 OPTS_LDRO=""
49 OPTS_CC=""
50 OPTS_CC_GENCPM=""
51 OPTS_CXX=""
52 OPTS_F90=""
53 OPTS_LD=""
54 OPTS_PIC=""
55 USE_PIC="0"
57 CHARMDEBUG=""
58 LINK_PYTHON=""
59 OBJECT=""
60 EXPLICIT_OBJECT="no"
61 EXPLICIT_COMPILATION="no"
62 POST_LANGUAGE=""
63 POST_LIBRARIES=""
64 PRE_LIBRARIES=""
65 USE_F90_LIBRARIES="0"
66 USE_F77_LIBRARIES="0"
67 F90_MODDIR=
68 AMPIMAIN=""
69 AMPI=""
70 AMPIF=""
71 COPYTO=""
72 MODCOPIES=""
73 MODULES=""
74 BALANCER=""
75 FILES=""
76 OBJECTFILES=""
77 DELETE=""
78 MAINOBJ=""
79 GENCPM=""
80 OPTIMIZE_MODE=""
81 PRODUCTION_MODE=""
82 USE_RELIABLE_CC=""
83 USE_FASTEST_CC=""
84 PROG_EXT=""
85 GENDEPENDS="no"
86 COUNTTOKENS="no"
87 USE_OPENMP="no"
88 SKIP_MODULEINIT=""
89 RPATH_ORIGIN=""
90 LINK_WHOLE_ARCHIVE=""
91 LINK_CXX_STL=""
93 COPY_CHARMRUN=true
94 USE_BUILD_OPTIONS=0
96 COPY_EXIT="true"
97 CHARM_SHARED="0"
98 BUILD_SHARE="0"
99 SWAPGLOBALS="0"
100 TLSGLOBALS="0"
101 ROSE_OMP_TLS_GLOBALS="no"
102 PRINT_BUILDING_BLOCKS=""
103 NOABORT=""
105 TAU_MAKEFILE=Make.tau
106 TAU_TRACE_MPI=1
108 CMK_CELL=0
109 SPU_USE_CPP=0
110 SPU_EXTRA_LIBS=""
112 MPI_INTEROPERATE=""
113 NO_MAIN_MODULE=""
114 NO_MAIN=""
115 CUSTOM_PARTITION=""
116 PREPROCESS_CI="yes"
117 INPUT_GIVEN=""
119 ####################################################################
121 # Utility routines used below
123 ###################################################################
125 # PrintUsage: prints a helpful command-line usage message and quits
126 # Args: any additional messages
127 printUsage() {
128 printVersion
129 echo
130 echo "Usage: charmc [ flags ] <files>"
131 echo
132 echo " flags:"
133 echo " -o <target> -g -O"
134 echo " -D<define> -I<include path> -L<lib path> -l<library> -s"
135 echo " -machine <mach> -seq -host -language <lang> -pg <opt>"
136 echo " -balance <mode> -tracemode <mode> -memory <mode>"
137 echo " -modules <comma-separated list of C++ modules> -thread"
138 echo " -debug-script -count-tokens -default-to-aout -E -S -M"
139 echo " -verbose -save -purify -cp <dest> -cpmod -gen-cpm <pkg>"
140 echo " -swapglobals -tlsglobals -roseomptlsglobals"
141 echo " -use-reliable-cc -use-fastest-cc -use-new-std"
142 echo " -cc <new cc> -c++ <new CC> -ld <new ld> -ld++ <new LD>"
143 echo " -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
144 echo " -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
145 echo " -f90 <new f90> -f90-option <opt> -fmoddir <f90mod path>"
146 echo " -flibs -rpath <path> -custom-part -touch-on-failure"
147 echo " -mpi -openmp -no-trace-mpi -build-shared -charm-shared"
148 echo " -no-charmrun -no-preprocess-ci -nomain-module -nomain"
149 echo " -nof90main -f90main"
150 echo
151 echo " Charmc compiles C, C++, f77, f90, AMPI, Converse, Converse++, Charm, "
152 echo "and Charm++ programs. The flags generally match those of cc or f77."
153 echo " Other options that are not listed here will be passed directly to the"
154 echo "underlying compiler and/or linker."
155 echo "Parallel Programming Lab, UIUC, 2019."
156 echo $*
157 exit 1
160 # End blows away the temporary files (unless SAVE is true) and exits
161 # Args: <exit code>
162 End() {
163 if [ -z "$SAVE" ]
164 then
165 for FILE in `echo $FILES`
167 #BASE=`stripExtention $FILE`
168 MYTMP=`basename $FILE`".TMP"
169 $RM $MYTMP.P.C $MYTMP.cpp $MYTMP.space $MYTMP.xlat $MYTMP.o
170 $RM $MYTMP.c $MYTMP.c.0.h $MYTMP.c.1.h $MYTMP.c.2.h
171 $RM $MYTMP.i $MYTMP.$CMK_CPP_SUFFIX
172 done
173 $RM core $DELETE
174 if [ -z "$SKIP_MODULEINIT" -a -n "$modInitObj" ]
175 then
176 [ -n "$VERBOSE" ] && echo $RM $modInitSrc $modInitObj
177 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
180 exit $1
183 # Write this error message to stderr
184 # ("1>&2" redirects the echo output to stderr).
185 Warning() {
186 echo "$@" 1>&2
189 # This procedure prints an error message and exits.
190 # Args: written to stderr
191 Abort() {
192 Warning "Fatal Error by charmc in directory "`pwd`
193 Warning " $@"
194 Warning "charmc exiting..."
195 End 1
199 # Instead of an ECHO_CMD variable, I define a procedure Do,
200 # which (possibly) echos, runs, and tests the errors of the given command.
201 # Args: executed as given
202 DoNoErrCheck() {
203 [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
204 eval "$@"
207 Do() {
208 DoNoErrCheck "$@"
209 Do_res=$?
210 # The UNIX result code better be zero, or we die
211 [ $Do_res -eq 0 -o -n "$NOABORT" ] || Abort "Command $@ returned error code $Do_res"
214 # This procedure removes the extention (the ".c" in "./main.c") from
215 # its first argument, and prints the result. Unlike the builtin command
216 # basename, it keeps the directory path.
217 # Args: <name to strip>
218 stripExtention() {
219 se_base=`basename $1`
220 # se_base=`echo $1 | awk -F/ '{print $NF}'`
221 se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
222 se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
223 echo $se_ret
226 # GetExtention returns the extention on the given file name
227 # or "" if none. (e.g. "./bob/snack.c" returns ".c")
228 # Args: <name to find extention of>
229 getExtention() {
230 # se_base=`echo $1 | awk -F/ '{print $NF}'`
231 # se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
232 # echo $se_ret
233 se_ret=`echo $1 | sed -e 's/.*\././'`
234 if test "$se_ret" = $1
235 then
236 echo ""
237 else
238 echo $se_ret
242 Debugf() {
243 [ -n "$VERBOSE" ] && echo "charmc>" $@
246 Debug() {
247 if [ -n "$DEBUG_SCRIPT" ]
248 then
249 echo
250 echo "------- Charmc Debugging info: $* -------"
251 echo "CHARMBIN=$CHARMBIN"
252 echo "CHARMINC=$CHARMINC"
253 echo "CHARMLIB=$CHARMLIB"
254 echo "FILES=$FILES"
255 echo "DELETE=$DELETE"
256 echo "OBJECT=$OBJECT"
257 echo "LANGUAGE=$LANGUAGE"
258 echo "PARADIGM=$PARADIGM"
259 # echo "Working directory="`pwd`
263 # Return success if $1 is not in any of the other arguments
264 notInList() {
265 search=$1
266 shift
267 while [ $# -gt 0 ]
269 if [ "$search" = "$1" ]
270 then
271 # It's already in there-- fail
272 return 1
274 shift
275 done
276 # It's missing--succeed
277 return 0
280 # Add arguments to our modules list, avoiding duplicates
281 AddModules() {
282 for M in "$@"
284 notInList $M $MODULES && MODULES="$MODULES $M"
285 done
288 # Add this word to this list, avoiding duplicates
289 AddList() {
290 ret=""
291 while [ $# -gt 1 ]
293 ret="$ret $1"
294 shift
295 done
296 if notInList $1 $ret
297 then
298 ret="$ret $1"
300 echo $ret
303 # Drop the first argument anywhere it appears in the subsequent list
304 DropList() {
305 drop="$1"
306 shift
308 ret=""
309 while [ $# -gt 1 ]
311 if [ "$1" != "$drop" ]; then
312 ret="$ret $1"
314 shift
315 done
317 echo $ret
320 # TEMP_BASE is appended with this script's process ID (PID),
321 # so multiple charmcs can run in parallel without overwriting
322 # each other's temporary files.
323 TEMP_BASE="/tmp/charmc_tmp.$$"
325 # Try to find CHARMBIN by looking in directory where charmc is
326 findCharmBin() {
327 if [ -z "$CHARMBIN" ]
328 then
329 SCRIPT=$1
330 CHARMBIN=`dirname $SCRIPT`
331 # CHARMBIN=`cd $CHARMBIN; pwd`
332 # NOTE: this script no longer tries to follow soft links
333 # to find the "original" charmc-- if this is bad,
334 # translate these lines to Bourne shell from C shell:
335 # -------------------- Begin C Shell ------------------------->
336 # if ($SCRIPT:h != $SCRIPT:t) then
337 # cd $SCRIPT:h
338 # set SCRIPT=$SCRIPT:t
339 # else
340 # foreach dir ($path)
341 # if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
342 # cd $dir
343 # break
344 # endif
345 # end
346 # endif
347 # while (x`find $SCRIPT -type l -print` == x$SCRIPT)
348 # set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
349 # if ($SCRIPT:h != $SCRIPT:t) then
350 # cd $SCRIPT:h
351 # set SCRIPT=$SCRIPT:t
352 # endif
353 # end
354 # set CHARMBIN=`pwd`
355 # <------------------ End C Shell -----------------------------
359 printVersion()
361 findCharmBin $0
362 version=`cat $CHARMBIN/../include/VERSION`
363 echo Charm++ Version $version
367 ##############################################################################
369 # The following section identifies CHARMBIN, the charm binary-directory.
371 ##############################################################################
373 ORIGDIR=`pwd`
375 # Try to find CHARMBIN by looking in directory where charmc is
377 findCharmBin $0
379 UNAME=`uname -s`
380 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
381 if [ "$FIRST_THREE" = "CYG" -o "$UNAME" = "Interix" ]
382 then
383 # Running on a windows system-- append .exe to file names
384 PROG_EXT=".exe"
387 CHARMLIB="$CHARMBIN/../lib"
388 CHARMINC="$CHARMBIN/../include"
389 CHARMLIBSO=
390 if test -d "$CHARMBIN/../lib_so"
391 then
392 CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
393 #getting absolute path is harder than thought because of symbolic links and ..
394 #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
395 #csh is ok too if it exists
396 test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
397 test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
398 test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
401 ##############################################################################
403 # Parse the arguments
405 # Don't do any analysis in here, just the parsing.
407 ##############################################################################
409 [ $# -eq 0 ] && printUsage "Error: No arguments given."
411 processArgs() {
412 while [ ! $# -eq 0 ]
414 arg="$1"
415 shift
417 case "$arg" in
418 "-V")
419 printVersion
420 exit 0
423 "-machine")
424 MACHTYPE="$1"
425 shift
428 "-seq")
429 SEQUENTIAL=true
432 "-host")
433 NATIVE=true
436 "-standalone")
437 STANDALONE="true"
438 SKIP_MODULEINIT="yes"
441 "-language")
442 # Parse out some fake languages (that are actually modules)
443 case "$1" in
444 "ampi") AddModules tcharmmain ampi ; AMPI="1" ;;
445 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ; AMPIF="1" ;;
446 "armci") AddModules tcharmmain armci ;;
447 "armcif") AddModules tcharmmain armci ; USE_F90_LIBRARIES="1" ;;
448 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
449 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
450 "ParFUM_TOPS") AddModules tcharmmain ParFUM ParFUM_TOPS ; AMPIMAIN="ParFUMmain";;
451 "ParFUM") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain";;
452 "ParFUMf") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain"; USE_F90_LIBRARIES="1" ;;
453 "mblock") AddModules tcharmmain mblock ;;
454 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
456 "charm"|"charm++"|"charm++f"|"f90charm"|"converse"|"converse++"|"bgcharm++"|"bgconverse++"|"bluegene"|"ckbluegene"|"bigsim")
457 PARADIGM="$1"
458 POST_LANGUAGE=1
462 LANGUAGE="$1"
463 POST_LANGUAGE=1
465 esac
466 shift
469 "-debug")
470 # Requested support from charmdebug: add some modules and libraries
471 CHARMDEBUG=1
472 MEMORY="charmdebug"
475 "-module"|"-modules")
476 AddModules `echo $1 | sed -e 's/,/ /g'`
477 INPUT_GIVEN="1"
478 shift
481 "-balancer")
482 # test -n "$BALANCER" && Abort "More than one -balancer specified!"
483 BALANCER="$BALANCER $1"
484 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
485 AddModules $mod
486 shift
489 "-balance")
490 BALANCE="$1"
491 shift
494 "-queue")
495 Warning "Warning: -queue currently being ignored."
496 shift
499 "-memory")
500 MEMORY="$1"
501 shift
504 "-thread")
505 THREAD="$1"
506 shift
509 "-tracemode")
510 TRACEMODE_NEW=`AddList $TRACEMODE $1`
511 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
512 then
513 Warning "Warning: Duplicate tracemode $1 ignored"
514 else
515 TRACEMODE=$TRACEMODE_NEW
517 shift
519 "-no-trace-mpi")
520 TAU_TRACE_MPI=0
523 "-swapglobal"|"-swapglobals")
524 SWAPGLOBALS="1"
525 USE_PIC="1"
528 "-tlsglobal"|"-tlsglobals")
529 TLSGLOBALS="1"
532 "-roseomptlsglobals")
533 ROSE_OMP_TLS_GLOBALS="yes"
536 "-verbose")
537 echo "Verbose mode set"
538 VERBOSE=true
541 "-spu-cpp")
542 SPU_USE_CPP=1
545 "-spu-lib")
546 SPU_EXTRA_LIBS="$SPU_EXTRA_LIBS -l$1"
547 shift
550 "-intrinsic")
551 XI_INTERNAL=true
554 "-debug-script")
555 echo "Will give excessive charmc debugging output..."
556 DEBUG_SCRIPT=true
559 "-save")
560 SAVE=true
563 "-purify")
564 PURIFY=true
567 "-use-reliable-cc")
568 USE_RELIABLE_CC=1
571 "-use-fastest-cc")
572 USE_FASTEST_CC=1
575 "-cc")
576 OVERRIDE_CC="$1"
577 shift
580 "-c++")
581 OVERRIDE_CXX="$1"
582 shift
585 "-f90")
586 OVERRIDE_F90="$1"
587 shift
590 "-ld")
591 OVERRIDE_LD="$1"
592 shift
595 "-ld++")
596 OVERRIDE_LDXX="$1"
597 shift
600 "-cpp-option")
601 OPTS_CPP="$OPTS_CPP $1"
602 shift
605 "-ldro-option")
606 OPTS_LDRO="$OPTS_LDRO $1"
607 shift
610 "-cc-option")
611 OPTS_CC="$OPTS_CC $1"
612 shift
615 "-c++-option")
616 OPTS_CXX="$OPTS_CXX $1"
617 shift
620 "-f90-option")
621 OPTS_F90="$OPTS_F90 $1"
622 shift
625 "-ld-option"|"-ld++-option")
626 OPTS_LD="$OPTS_LD $1"
627 shift
630 "-rpath")
631 OPTS_LD="$OPTS_LD -rpath $1"
632 shift
635 "-rpath-origin")
636 RPATH_ORIGIN="yes"
639 "-fortran"|"-flib"|"-flibs")
640 USE_F90_LIBRARIES="1"
642 "-f77")
643 USE_F77="1"
645 "-fortran77"|"-f77lib"|"-f77libs")
646 USE_F77_LIBRARIES="1"
648 "-E")
649 # Run preprocessor only
650 PREPROCESS="yes"
651 SKIPLINK="yes"
652 OPTS="$OPTS $arg"
654 "-preprocess")
655 # Run preprocessor as an extra step, continue after preprocessing
656 PREPROCESS="yes"
658 "-no-preprocess-ci")
659 # Turn off the preprocessor for ci files
660 PREPROCESS_CI="no"
662 "-P"|"-S")
663 # Run preprocessor/assembler only
664 SKIPLINK="yes"
665 OPTS="$OPTS $arg"
667 #------ Dependency generation ---------
668 "-M" | "-MM" | "-MMD" | "-MG")
669 SKIPLINK="yes"
670 OPTS="$OPTS $arg"
671 GENDEPENDS="yes"
673 "-MF" | "-MT" | "-MQ" | "-MD") #-MP will pass through automatically
674 OPTS="$OPTS $arg $1"
675 shift
677 #--------------------------------------
678 "-count-tokens")
679 OPTS="$OPTS $arg"
680 COUNTTOKENS="yes"
682 "-default-to-aout")
683 if [ "$EXPLICIT_OBJECT $EXPLICIT_COMPILATION" = "no no" ]
684 then
685 OBJECT="a.out"
688 -print-prog-name=*)
689 echo $arg | cut -d'=' -f2
690 exit 0
692 "-c")
693 if [ "$EXPLICIT_OBJECT" = "no" ]
694 then
695 OBJECT=""
697 EXPLICIT_COMPILATION="yes"
700 "-o")
701 EXPLICIT_OBJECT="yes"
702 OBJECT=$1
703 shift
706 "-cp")
707 COPYTO="$1"
708 shift
711 "-cpmod")
712 MODCOPIES="$1 $MODCOPIES"
713 shift
716 "-gen-cpm")
717 GENCPM="$GENCPM $1"
718 shift
722 OPTS_CPP="$OPTS_CPP -I$1"
723 shift
726 -D*|-I*)
727 if echo "$arg" | grep ' ' > /dev/null 2>/dev/null
728 then
729 OPTS_CPP="$OPTS_CPP "\"$arg\"
730 else
731 OPTS_CPP="$OPTS_CPP $arg"
735 -Werror)
736 WERROR="1"
739 -Wno-error)
740 WERROR="0"
743 "-use-new-std")
744 USE_NEW_STD="1"
747 "-no-use-new-std")
748 USE_NEW_STD="0"
751 -LANG*)
752 Warning "passing unrecognized option $arg to all compilers and linkers"
753 OPTS="$OPTS $arg"
755 -shared|-G)
756 BUILD_SHARE="1"
758 -L*|-shared|-G) # note that this is not executed if $arg == -shared|-G, due to the case above; might be a bug
759 OPTS_LD="$OPTS_LD $arg"
761 -charm-shared|-cs)
762 CHARM_SHARED="1"
764 -build-shared)
765 # used internally when building Charm++ to create lib_so
766 BUILD_SHARE="1"
768 -no-build-shared)
769 # used internally not to build Charm++ lib_so
770 BUILD_SHARE="0"
772 "-optimize")
773 OPTIMIZE_MODE=true
776 "-no-optimize")
777 OPTIMIZE_MODE=false
780 "-production")
781 PRODUCTION_MODE=true
783 "-no-production")
784 PRODUCTION_MODE=false
787 -Wl,*)
788 POST_LIBRARIES="$POST_LIBRARIES $arg"
791 "-pg"|"-g"|-W*|-O*)
792 OPTS="$OPTS $arg"
795 "-fmoddir")
796 F90_MODDIR="$F90_MODDIR $1"
797 shift
800 -l*|*.a|*.so|*.so.*|*.dylib)
801 if [ -n "$POST_LANGUAGE" ]
802 then
803 POST_LIBRARIES="$POST_LIBRARIES $arg"
804 else
805 PRE_LIBRARIES="$PRE_LIBRARIES $arg"
807 INPUT_GIVEN="1"
810 "-whole-archive")
811 LINK_WHOLE_ARCHIVE=true
814 "-c++stl")
815 LINK_CXX_STL=true
819 OPTS_LD="$OPTS_LD $arg"
821 -no-charmrun)
822 COPY_CHARMRUN=false
824 -use-build-options)
825 USE_BUILD_OPTIONS=1
827 -h|--help)
828 printUsage
830 -f90main)
831 F90_MAIN=1
833 -nof90main)
834 F90_MAIN=
836 -mpi)
837 MPI_INTEROPERATE="yes"
838 NO_MAIN="yes"
840 -nomain-module)
841 NO_MAIN_MODULE="yes"
843 -nomain)
844 NO_MAIN="yes"
846 -custom-part)
847 CUSTOM_PARTITION="yes"
850 -fopenmp|-openmp)
851 USE_OPENMP="yes"
854 -skip-module-init)
855 SKIP_MODULEINIT="yes"
858 -print-building-blocks)
859 PRINT_BUILDING_BLOCKS="yes"
860 SKIP_MODULEINIT="yes"
863 -touch-on-failure)
864 NOABORT="yes"
867 -*|+*)
868 # Warning "passing unrecognized option $arg to all compilers and linkers"
869 OPTS="$OPTS $arg"
871 *.*)
872 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
873 FILES="$FILES $arg"
874 INPUT_GIVEN="1"
876 # Default
878 # printUsage "Error: Unrecognized argument $arg"
879 # Warning "passing unrecognized option $arg to all compilers and linkers"
880 OPTS="$OPTS $arg"
882 esac
883 done
886 trap 'End 1' 2
888 # Process original command-line arguments
889 eval processArgs "$@"
891 # Do not skip linking if user explicitly specified an output file
892 # This allows generating dependencies while compiling
893 if [ "$GENDEPENDS" = "yes" -a "$EXPLICIT_OBJECT" = "yes" ]; then
894 SKIPLINK=""
897 USER_POST_LIBRARIES="$POST_LIBRARIES"
898 USER_PRE_LIBRARIES="$PRE_LIBRARIES"
900 # Construct list of object files
901 numFiles=`echo $FILES | wc -w`
902 for FILE in $FILES
905 case "$FILE" in
906 *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
907 OBJECTFILES="$OBJECTFILES $FILE"
909 *.c|*.s|*.S|*.C|*.cc|*.cxx|*.cpp|*.c++|*.cu|*.f|*.F|*.f77|*.F77|*.f90|*.F90|*.fpp|*.FPP)
910 BASE=`stripExtention \`basename $FILE\``
911 BASEO="$BASE.o"
913 if [ $numFiles = 1 -a -n "$OBJECT" ]
914 then
915 OBJ_EXT=`getExtention $OBJECT`
916 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
917 then
918 BASEO=$OBJECT
922 # Handle new object files
923 if [ -n "$BASEO" -a -n "$OBJECT" ]
924 then
925 if [ "$OBJECT" != "$BASEO" ]
926 then
927 DELETE="$DELETE $BASEO"
929 OBJECTFILES="$OBJECTFILES $BASEO"
932 esac
933 done
936 ##############################################################################
938 # Load module dependencies.
940 ##############################################################################
942 Debug "About to read machine config script"
943 Debug "Read config script, setting defaults..."
945 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
946 . $CHARMINC/conv-config.sh $CHARMINC
948 Debug "Setting vars..."
950 if [ "$USE_BUILD_OPTIONS" = "1" ]
951 then
952 [ -n "$VERBOSE" ] && echo "Charmc applying build time options: $BUILDOPTS"
953 OPTS="$OPTS $BUILDOPTS"
956 # If we are debugging, add "-g -O0" to the C/C++ flags
957 if [ -n "$CHARMDEBUG" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]; then
958 if [ -n "$CMK_BUILD_PYTHON" ]; then
959 AddModules PythonCCS charmdebug_python
960 POST_LIBRARIES=`AddList $POST_LIBRARIES -lpython${CMK_BUILD_PYTHON}`
962 OPTS_CPP="$OPTS_CPP -O0 -g"
965 # The purpose of the -rpath-origin option is for the resulting binary to have
966 # the literal text '$ORIGIN' in the RPATH field of its ELF header, essentially
967 # saying that it is okay for the binary to look in the same directory as itself
968 # for the shared objects it needs. Unfortunately, POSIX shells will interpret
969 # this text as a variable instead of passing in the string itself, requiring
970 # the string to be escaped.
971 # Additionally, some platforms do not need any special parameters.
972 if [ -n "$RPATH_ORIGIN" -a "$CMK_MACOSX" != "1" -a "$CMK_COMPILER" != "msvc" ]; then
973 OPTS_LD="$OPTS_LD '-Wl,-rpath,\$ORIGIN'"
976 PROCESSED_MODULES=""
978 if [ "$WERROR" = "1" ]
979 then
980 OPTS="$OPTS $CMK_WARNINGS_ARE_ERRORS"
983 # If the user has asked for the latest language standards (C11 or CPP11)
984 if [ "$USE_NEW_STD" = "1" ]
985 then
986 # and if configure confirmed that the underlying compiler knows abt C11, enable it
987 if [ "$CMK_COMPILER_KNOWS_C11" = "1" ]
988 then
989 OPTS_CC="$OPTS $CMK_ENABLE_C11"
993 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
994 then
995 USE_OPENMP="yes"
996 TLSGLOBALS="1"
998 if [ ! -x "$CMK_ROSE_OMP_TOOL" ]
999 then
1000 Abort "The environment variable CMK_ROSE_OMP_TOOL must contain the path to a built binary of the ROSE OpenMP variable privatization tool"
1004 if [ "$USE_OPENMP" = "yes" -o "$CMK_OMP" = "1" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]
1005 then
1006 if [ "$CMK_HAS_OPENMP" != "1" ]
1007 then
1008 echo "Error: OpenMP is unavailable!"
1009 exit 1
1011 [ -n "$VERBOSE" ] && echo OpenMP support enabled
1012 OPTS_CC="$OPTS_CC $CMK_C_OPENMP"
1013 OPTS_CXX="$OPTS_CXX $CMK_C_OPENMP"
1014 OPTS_F90="$OPTS_F90 $CMK_F_OPENMP"
1015 OPTS_LD="$OPTS_LD $CMK_LD_OPENMP"
1016 else
1017 [ -n "$VERBOSE" ] && echo OpenMP support not enabled
1020 if [ "$TLSGLOBALS" = "1" ]
1021 then
1022 TLSGLOBALS_OPTS='-ftls-model=initial-exec'
1023 [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" = '1' ] && TLSGLOBALS_OPTS="$TLSGLOBALS_OPTS -mno-tls-direct-seg-refs"
1024 OPTS_CC="$OPTS_CC $TLSGLOBALS_OPTS"
1025 OPTS_CXX="$OPTS_CXX $TLSGLOBALS_OPTS"
1026 OPTS_F90="$OPTS_F90 $TLSGLOBALS_OPTS"
1029 # Look up and add the dependencies for module $1
1030 findModuleDep() {
1031 M=$1
1032 notInList $M $PROCESSED_MODULES || return
1033 PROCESSED_MODULES="$PROCESSED_MODULES $M"
1034 #PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
1035 PRE_LIBRARIES=`AddList -lmodule$M $PRE_LIBRARIES`
1036 # HACK: add modules to both ends of library list, to avoid
1037 # undefined symbol CkRegisterMainModule when it's in a module file.
1038 POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
1039 if [ "$M" = "PythonCCS" ]
1040 then
1041 LINK_PYTHON=1
1044 dep=""
1045 # fixme: should search everything in the -L library paths:
1046 for dir in `echo . $CHARMLIB`
1048 d="$dir/libmodule$M.dep"
1049 [ -r "$d" ] && dep=$d
1050 done
1051 if [ -r "$dep" ]
1052 then
1053 # Add the module dependencies in this file
1054 # Debugf "Adding module" $M "dependencies from" $dep
1055 deps=`cat $dep`
1056 Debugf "Module" $M "adds dependencies:" $deps
1057 processArgs $deps
1061 # Repeat the module-dependency search until we find no
1062 # new modules:
1063 START_MODULES=""
1064 while [ "$START_MODULES" != "$MODULES" ]
1066 Debugf "----------- Module dependency search ------------"
1067 START_MODULES="$MODULES"
1068 for m in $MODULES
1070 findModuleDep $m
1071 done
1072 done
1074 Debugf "----------- Module dependency search complete ------------"
1078 ##############################################################################
1080 # Load machine-specific configuration data, then handle overrides to it.
1082 ##############################################################################
1085 if [ x"$CMK_NO_BUILD_SHARED" = "xfalse" ]
1086 then
1087 BUILD_SHARE="1"
1090 if [ "$BUILD_SHARE" = "1" ]
1091 then
1092 USE_PIC="1"
1095 OPTS_PIC="$CMK_PIC"
1096 if [ "$USE_PIC" = "1" ]
1097 then
1098 OPTS_CC="$OPTS_CC $OPTS_PIC"
1099 OPTS_CXX="$OPTS_CXX $OPTS_PIC"
1100 OPTS_F90="$OPTS_F90 $OPTS_PIC"
1101 OPTS_LD="$OPTS_LD $OPTS_PIC"
1104 if [ "$BUILD_SHARE" = "1" ]
1105 then
1106 # ignore BUILD_SHARE if the target is not .a or .so
1107 case "$OBJECT" in
1108 *.a|*.so|*.so.*|*.sl|*.dylib)
1109 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO"
1110 [ -n "$CHARMLIBSO" ] && OPTS_LD="$OPTS_LD -L$CHARMLIBSO"
1113 BUILD_SHARE="0"
1115 esac
1118 if [ -n "$OVERRIDE_CC" ]
1119 then
1120 CMK_CC="$OVERRIDE_CC"
1122 Debug "set 2"
1123 if [ -n "$OVERRIDE_CXX" ]
1124 then
1125 CMK_CXX="$OVERRIDE_CXX"
1128 if [ -n "$OVERRIDE_F90" ]
1129 then
1130 CMK_CF90="$OVERRIDE_F90"
1133 if [ -n "$OVERRIDE_LD" ]
1134 then
1135 CMK_LD="$OVERRIDE_LD"
1138 if [ -n "$OVERRIDE_LDXX" ]
1139 then
1140 CMK_LDXX="$OVERRIDE_LDXX"
1143 if [ -n "$USE_RELIABLE_CC" ]
1144 then
1145 CMK_CC="$CMK_CC_RELIABLE"
1148 if [ -n "$USE_FASTEST_CC" ]
1149 then
1150 CMK_CC="$CMK_CC_FASTEST"
1153 if [ -n "$USE_F77" ]
1154 then
1155 CMK_CF90=$CMK_CF77
1156 CMK_CF90_FIXED=$CMK_CF77
1157 CMK_F90LIBS=$CMK_F77LIBS
1160 if [ -n "$CMK_F90_MODINC" ]
1161 then
1162 CMK_CF90_MODINC="$CMK_F90_MODINC"
1163 else
1164 CMK_CF90_MODINC="-M"
1167 if [ -n "$F90_MODDIR" ]
1168 then
1169 for dir in $F90_MODDIR
1171 OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
1172 done
1175 if [ -n "$CMK_F90_USE_MODDIR" ]
1176 then
1177 CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC $CHARMINC $CMK_SYSINC"
1180 if [ -n "$SEQUENTIAL" ]
1181 then
1182 CMK_CC="$CMK_SEQ_CC"
1183 CMK_LD="$CMK_SEQ_LD"
1184 CMK_CXX="$CMK_SEQ_CXX"
1185 CMK_CF90="$CMK_SEQ_F90 "
1186 CMK_LDXX="$CMK_SEQ_LDXX"
1187 CMK_AR="$CMK_SEQ_AR"
1188 CMK_RANLIB="$CMK_SEQ_RANLIB"
1190 CMK_CC_FLAGS="$CMK_SEQ_CC_FLAGS -DCMK_SEQUENTIAL=1"
1191 CMK_LD_FLAGS="$CMK_SEQ_LD_FLAGS"
1192 CMK_CXX_FLAGS="$CMK_SEQ_CXX_FLAGS -DCMK_SEQUENTIAL=1"
1193 CMK_LDXX_FLAGS="$CMK_SEQ_LDXX_FLAGS"
1196 if [ -n "$NATIVE" ]
1197 then
1198 CMK_CC="$CMK_NATIVE_CC "
1199 CMK_LD="$CMK_NATIVE_LD"
1200 CMK_CXX="$CMK_NATIVE_CXX "
1201 CMK_LDXX="$CMK_NATIVE_LDXX"
1203 CMK_CC_FLAGS="$CMK_NATIVE_CC_FLAGS"
1204 CMK_LD_FLAGS="$CMK_NATIVE_LD_FLAGS"
1205 CMK_CXX_FLAGS="$CMK_NATIVE_CXX_FLAGS"
1206 CMK_LDXX_FLAGS="$CMK_NATIVE_LDXX_FLAGS"
1209 if [ -n "$PREPROCESS" ]
1210 then
1211 CMK_CF90=$CMK_FPP
1214 if [ -n "$PURIFY" ]
1215 then
1216 CMK_LD="purify $CMK_LD"
1217 CMK_LDXX="purify $CMK_LDXX"
1220 Debug "set 4"
1221 if [ "$OPTIMIZE_MODE" = "true" ]
1222 then
1223 OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
1224 OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
1225 OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
1226 OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
1229 # Pick up per-architecture production mode settings
1230 if [ "$PRODUCTION_MODE" = "true" ]
1231 then
1232 OPTS_CC="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_CC"
1233 OPTS_CXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_CXX"
1234 OPTS_F90="$CMK_PRODUCTION $CMK_F90_PRODUCTION $OPTS_F90"
1235 OPTS_LD="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_LD"
1238 if [ -n "$XI_INTERNAL" ]
1239 then
1240 CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
1243 if [ "$GENDEPENDS" = "yes" ]
1244 then
1245 CMK_XIOPTS="$CMK_XIOPTS -M"
1248 if [ "$COUNTTOKENS" = "yes" ]
1249 then
1250 CMK_XIOPTS="$CMK_XIOPTS -count-tokens"
1253 if test "$CMK_WITH_TAU" = "true"
1254 then
1255 echo "include $TAU_MAKEFILE" > _make.tau.tmp
1256 echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1257 TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1258 TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1259 TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1260 TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1261 TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1263 rm -f _make.tau.tmp
1266 #Add generic options to the compiler- and linker-options
1267 OPTS_CC="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CC"
1268 OPTS_CXX="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CXX"
1269 OPTS_F90="$OPTS $OPTS_F90"
1270 OPTS_LD="$OPTS $OPTS_LD"
1272 # There's really no analog for this in the Bourne shell:
1273 # -------- C Shell ------> onintr failure
1274 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
1276 ##############################################################################
1278 # Check for valid choice of LANGUAGE
1280 ##############################################################################
1281 Debug "Checking language..."
1283 [ -z "$LANGUAGE" -a -n "$SEQUENTIAL" ] && LANGUAGE=c
1284 [ -z "$PARADIGM" -a -n "$LANGUAGE" ] && PARADIGM="$LANGUAGE"
1285 [ -z "$PARADIGM" ] && PARADIGM="charm++"
1287 case "$LANGUAGE" in
1288 "c"|"C"|"c++"|"C++")
1289 [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
1291 esac
1293 # update charm to bgcharm
1294 [ "$PARADIGM" = "charm++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgcharm++"
1295 [ "$PARADIGM" = "converse++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgconverse++"
1297 [ "$PARADIGM" = "bgcharm++" ] && TRACEMODE=`AddList $TRACEMODE bluegene`
1299 if [ $USE_F77_LIBRARIES = "1" ]
1300 then
1301 POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1304 if [ $USE_F90_LIBRARIES = "1" ]
1305 then
1307 if [ ! -r $CHARMLIB/libconv-utilf.a ]
1308 then
1309 Abort "Error: Fortran support library $CHARMLIB/libconv-utilf.a missing. Is your Fortran compiler working?"
1312 POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1315 # GEN-CPM options
1316 if [ "$CMK_COMPILER" = "bgclang" ]
1317 then
1318 OPTS_CC_GENCPM="-x c " # -x c is only applied for the preprocessing of the GEN-CPM files on BG/Q
1321 OPTS_CC_GENCPM="$OPTS_CC $OPTS_CC_GENCPM"
1323 ############ Determine the language and libraries ##########
1325 # Parse out the real languages
1326 case "$PARADIGM" in
1327 "charm++f")
1328 PARADIGM="charm++"
1329 USE_F90_LIBRARIES="1"
1331 "f90charm")
1332 PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm -lckf"
1333 POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1335 "bluegene"|"bigsim")
1336 PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs"
1338 "ckbluegene")
1339 POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1341 "bgcharm++")
1342 PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs -lconv-bluegene-stub"
1344 "bgconverse++")
1345 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bigsim -lconv-bigsim-logs"
1347 esac
1349 # DMK - ACCEL SUPPORT - If this is a cell build, add the spe code object to POST_LIBRARIES
1350 if [ $CMK_CELL -eq 1 ]
1351 then
1353 if [ "$PARADIGM" = "converse++" ]
1354 then
1355 # Include a "do nothing" register_accel_spe_funcs() function
1356 POST_LIBRARIES="$POST_LIBRARIES -lnoAccelStub"
1359 if [ "$PARADIGM" = "charm++" ]
1360 then
1362 if [ $SPU_USE_CPP -eq 1 ]
1363 then
1364 SPU_COMPILER=$CMK_SPU_CXX
1365 SPU_LINKER=$CMK_SPU_LDXX
1366 else
1367 SPU_COMPILER=$CMK_SPU_CC
1368 SPU_LINKER=$CMK_SPU_LD
1371 # Include the spe object file for linking into main executable
1372 POST_LIBRARIES="$POST_LIBRARIES main__funcLookup__.genSPECode.ppe.o"
1377 if [ "$AMPIMAIN" != "" ]
1378 then
1379 OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1382 if [ -n "$AMPI" ]
1383 then
1384 CMK_SYSINC="-I$CHARMINC/ampi $CMK_SYSINC"
1387 if [ "$TLSGLOBALS" = "1" ]
1388 then
1389 if [ "$CMK_GDIR" = "uth" ]
1390 then
1391 echo "Error: -tlsglobals is not supported with the uth machine layer."
1392 exit 1
1394 if [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" != '1' ] && [ "$CMK_COMPILER" != 'clang' -o "$CMK_MACOSX" != '1' ]
1395 then
1396 echo "Warning: -tlsglobals may not work with compilers that do not recognize -mno-tls-direct-seg-refs."
1398 if [ "$CMK_HAS_ELF_H" != '1' -a "$CMK_MACOSX" != '1' ]
1399 then
1400 echo "Warning: -tlsglobals requires elf.h"
1404 if [ "$SWAPGLOBALS" = "1" ]
1405 then
1406 if [ "$CMK_HAS_ELF_H" != "1" ]
1407 then
1408 echo "Error: -swapglobals requires elf.h"
1409 exit 1
1412 LD_VERSION_TEXT=`$CMK_LD -Wl,--version,-v 2>/dev/null`
1413 if ! `printf "$LD_VERSION_TEXT" | grep -q 'GNU ld'`
1414 then
1415 echo "Warning: -swapglobals may not work with linkers other than GNU ld."
1416 else
1417 LD_VERSION=`printf "$LD_VERSION_TEXT" | grep -Eo 'GNU ld (\([^)]*\) )?(version )?[-0-9._a-zA-Z]+' | awk '{print $NF}'`
1418 LD_VERSION_MAJOR=`printf $LD_VERSION | cut -d. -f1`
1419 LD_VERSION_MINOR=`printf $LD_VERSION | cut -d. -f2 | cut -d- -f1`
1420 if [ "$LD_VERSION_MAJOR" -gt 2 ] || [ "$LD_VERSION_MAJOR" -eq 2 -a "$LD_VERSION_MINOR" -gt 23 ]
1421 then
1422 echo "Warning: -swapglobals may not work with GNU ld >= 2.24."
1423 echo "For some versions, an experimental patch is available:"
1424 echo 'https://charm.cs.illinois.edu/gerrit/gitweb?p=libbfd-patches.git;a=tree;f=swapglobals'
1428 if [ "$CMK_SMP" = "1" ]
1429 then
1430 echo "Error: -swapglobals is not supported on SMP builds of Charm++/AMPI"
1431 exit 1
1432 else
1433 swapo="$CHARMLIB/libglobal-swap.a"
1434 if [ ! -r "$swapo" -o ! -s "$swapo" ]
1435 then
1436 echo "Error: global-swapping library $swapo missing--"
1437 echo " Is -swapglobals supported on this machine?"
1438 exit 1
1439 else
1440 MIDDLE_LIBS="-lglobal-swap $MIDDLE_LIBS"
1444 if [ "$SWAPGLOBALS" = "2" ]
1445 then
1446 echo "-copyglobals option is no longer supported by Charm++/AMPI"
1447 exit 1
1451 # dummy main module
1452 if [ "$MPI_INTEROPERATE" != "" -a "$NO_MAIN_MODULE" = "" ]
1453 then
1454 POST_LIBRARIES="-lmpi-mainmodule $POST_LIBRARIES"
1457 ##############################################################################
1459 # Some quick consistency checks in preparation for full link-step
1461 # Check for valid choice of TRACEMODE
1462 # Check for valid choice of BALANCE
1463 # Check for compatibility among BALANCE and TRACEMODE
1465 ##############################################################################
1467 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1469 # Check for valid choice of TRACEMODE
1471 if [ x"$TRACEMODE" != x ]
1472 then
1473 for trace in $TRACEMODE; do
1474 case "$PARADIGM" in
1475 "converse"|"converse++"|"bgconverse++"|"bigsim"|"bluegene")
1476 if [ "$trace" != "counter" ]; then
1477 Warning "Tracemode $trace isn't supported in Converse-level programs; Dropping it"
1478 TRACEMODE=`DropList $trace $TRACEMODE`
1479 continue
1484 esac
1486 TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1487 done
1491 if test x$PARADIGM = x"bgcharm++"
1492 then
1493 BALANCE=bluegene
1496 Debug "Finished with TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1498 BAL_OBJ="-lldb-$BALANCE -lconv-ldb"
1500 # Check for valid choice of MEMORY
1502 # Set the default expansions of unprefixed variants
1503 case "$MEMORY" in
1504 'verbose'|'paranoid'|'leak'|'isomalloc')
1505 MEMORY="os-$MEMORY"
1507 charmdebug*)
1508 MEMORY="gnu-$MEMORY"
1510 esac
1512 # Isomalloc does not work on BGQ or Windows:
1513 if [ "$CMK_BLUEGENEQ" = "1" -o "$CMK_COMPILER" = "msvc" ] && [ "$MEMORY" = "${MEMORY%isomalloc}isomalloc" ]
1514 then
1515 Abort "Error: Isomalloc is not supported on BlueGene/Q or Windows."
1518 MEM_OBJ="-lmemory-${MEMORY}"
1520 # For memory wrapping around the OS allocator, need to add also the wrapper object
1521 case $MEMORY in
1522 os-*)
1523 MEM_OBJ=$MEM_OBJ" -lmemory-os-wrapper"
1525 esac
1527 # Check for valid choice of THREAD
1529 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1530 then
1531 THREAD=$CMK_LD_SHARED_THREAD
1533 if [ "$TLSGLOBALS" = "1" ]
1534 then
1535 THREAD=${THREAD%-tls}-tls
1538 THREAD_OBJ="-lthreads-${THREAD}"
1541 # Module name
1543 modInitName="moduleinit$$"
1544 modInitSrc="$modInitName.C"
1545 modInitObj="$modInitName.o"
1548 ##############################################################################
1550 # Final link step variables
1552 ##############################################################################
1554 MAKE_LDXX="0"
1555 MAKE_LD="0"
1557 CORE_LIBS="-lconv-core -ltmgr -lconv-util -lconv-partition $TRACE_OBJ $CMK_HWLOC_LIBS"
1559 # get TAU stub makefile variables
1560 if test "$CMK_WITH_TAU" = "true"
1561 then
1562 echo "include $TAU_MAKEFILE" > _make.tau.tmp
1563 echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1564 TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1565 TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1566 TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1567 TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1568 TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1570 rm -f _make.tau.tmp
1572 # done getting TAU variables
1574 if [ "$BUILD_SHARE" = "0" ]
1575 then
1576 MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1579 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1581 case "$PARADIGM" in
1582 "f90charm")
1583 MAKE_LDXX="1"
1584 MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1585 if [ -z "$NO_MAIN" ]
1586 then
1587 MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1588 F90_MAIN="1"
1590 if [ "$TAU_TRACE_MPI" = "1" ]
1591 then
1592 TAU_LIBS="$TAU_MPI_FLIBS $TAU_LIBS"
1593 else
1594 TAU_LIBS="$TAU_LIBS"
1597 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1598 MAKE_LDXX="1"
1599 MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1600 if [ -z "$NO_MAIN" ]
1601 then
1602 if [ -n "$AMPIF" ]
1603 then
1604 MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1605 F90_MAIN="1"
1606 elif [ -z "$AMPIMAIN" ]
1607 then
1608 MIDDLE_LIBS="-lckmain $MIDDLE_LIBS"
1611 if [ "$TAU_TRACE_MPI" = "1" ]
1612 then
1613 TAU_LIBS="$TAU_MPI_LIBS $TAU_LIBS"
1614 else
1615 TAU_LIBS="$TAU_LIBS"
1618 "converse")
1619 MAKE_LD="1"
1620 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-machine $CORE_LIBS -ltrace-converse "
1622 "converse++"|"bgconverse++"|"bluegene"|"bigsim")
1623 MAKE_LDXX="1"
1624 MIDDLE_LIBS="$MIDDLE_LIBS -lconv-machine $CORE_LIBS -ltrace-converse "
1626 "c"|"C"|"c++"|"C++"|"f90"|"f77")
1629 Abort "Unrecognized choice of language $LANGUAGE / paradigm $PARADIGM"
1631 esac
1633 if [ "$BUILD_SHARE" = "0" ]
1634 then
1635 MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1638 if [ "$CHARM_SHARED" = "1" ]
1639 then
1640 [ -z "$CHARMLIBSO" ] && Abort "Charm++ lib_so directory not found!"
1641 # build user executable/shared lib linking with charm .so
1642 OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1643 LANG_LIBS="-L$CHARMLIBSO"
1644 else
1645 LANG_LIBS="-L$CHARMLIB"
1648 if [ -z "$STANDALONE" ]
1649 then
1650 ALL_LIBS="$LANG_LIBS $PRE_LIBRARIES $MIDDLE_LIBS $BAL_OBJ $CMK_LIBS $POST_LIBRARIES"
1651 case "$PARADIGM" in
1652 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1653 ALL_LIBS="$ALL_LIBS -lmoduleNDMeshStreamer -lmodulecompletion"
1655 esac
1656 else
1657 ALL_LIBS="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
1660 if [ -n "$LINK_WHOLE_ARCHIVE" ]
1661 then
1662 ALL_LIBS="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $ALL_LIBS $LDXX_WHOLE_ARCHIVE_POST $CMK_SYSLIBS"
1663 else
1664 ALL_LIBS="$ALL_LIBS $CMK_SYSLIBS"
1667 if [ "$BUILD_SHARE" = "0" ]
1668 then
1669 ALL_LIBS="$ALL_LIBS $CHARMLIB/conv-static.o"
1672 if [ -n "$LINK_CXX_STL" ]
1673 then
1674 ALL_LIBS="$ALL_LIBS -lstdc++"
1677 if [ "$TRACE_WITH_TAU" = 1 ]
1678 then
1679 echo "Linking with the TAU libraries: $TAU_LIBS"
1680 ALL_LIBS="$ALL_LIBS $TAU_LIBS"
1682 Debugf "All libraries are: $ALL_LIBS"
1684 # preserve this variable in its state here for use later
1685 CHARM_ALL_LIBS="$ALL_LIBS"
1686 if [ "$BUILD_SHARE" = "1" -o -n "$SKIP_MODULEINIT" ]
1687 then
1688 ALL_LIBS="$OBJECTFILES $ALL_LIBS"
1689 else
1690 ALL_LIBS="$OBJECTFILES $modInitObj $ALL_LIBS"
1693 if [ -n "$F90_MAIN" ]
1694 then
1695 # for_main needs to be placed at beginning
1696 CMK_LD_FLAGS="$CMK_F90MAINLIBS $CMK_LD_FLAGS"
1697 CMK_LDXX_FLAGS="$CMK_F90MAINLIBS $CMK_LDXX_FLAGS"
1700 if [ -n "$F90_MAIN" -o "$USE_F90_LIBRARIES" = '1' ]
1701 then
1702 if [ "$CMK_CAN_LINK_FORTRAN" != '1' ]
1703 then
1704 echo "Error: Configure testing was unable to link a Fortran program."
1705 exit 1
1709 ########################################################################
1711 # Finalize command parameters
1713 ########################################################################
1715 CHARM_CPP_C="$CMK_CPP_C"
1716 CHARM_CC="$CMK_CC"
1717 CHARM_CXX="$CMK_CXX"
1718 CHARM_LD="$CMK_LD"
1719 CHARM_LDXX="$CMK_LDXX"
1721 CHARM_CPP_C_FLAGS="$CMK_CPP_C_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CC_GENCPM $OPTS_CPP"
1722 CHARM_CC_FLAGS="$CMK_CC_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC"
1723 CHARM_CXX_FLAGS="$CMK_CXX_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX"
1724 CHARM_LD_FLAGS="$CMK_LD_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1725 CHARM_LDXX_FLAGS="$CMK_LDXX_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1728 ########################################################################
1730 # Print command building blocks and quit, if specified
1732 ########################################################################
1734 if [ -n "$PRINT_BUILDING_BLOCKS" ]
1735 then
1736 for i in CHARM_CC CHARM_CXX CHARM_LD CHARM_LDXX CHARM_CC_FLAGS CHARM_CXX_FLAGS CHARM_LD_FLAGS CHARM_LDXX_FLAGS CHARMBIN CHARMINC CHARMLIB CHARMLIBSO
1738 eval "echo $i=\\'\${$i}\\'"
1739 done
1740 exit 0
1744 ########################################################################
1746 # We've parsed and verified the command-line parameters.
1747 # Now we prepare routines to clean up and exit.
1748 # None of these routines ever returns-- they all just exit.
1750 ########################################################################
1753 Copyobj() {
1754 if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ]
1755 then
1756 [ -d $COPYTO ] && COPYTO="$COPYTO/"
1757 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
1758 Warning "Appending $PROG_EXT to object file name"
1759 OBJECT="$OBJECT$PROG_EXT"
1761 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO
1762 Do $CP $OBJECT $COPYTO
1764 test -n "$COPY_EXIT" && Success
1767 Copymod() {
1768 for COPY in `echo $MODCOPIES`
1770 if [ "a$COPY" != "a$OBJECT" ]
1771 then
1772 [ -d $COPY ] && COPY="$COPY/"
1773 if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
1774 OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
1776 if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
1777 Warning "Appending .$CMK_MOD_EXT to object file name"
1778 OBJECT="$OBJECT.$CMK_MOD_EXT"
1780 [ ! -d $COPY ] && DoNoErrCheck $RM $COPY
1781 Do $CP $OBJECT $COPY
1783 done
1784 Success
1787 Success() {
1788 End 0
1792 ##############################################################################
1794 # Preprocess the GEN-CPM files
1796 ##############################################################################
1798 Debug "Preprocessing GEN-CPM files"
1800 for FILE in `echo $GENCPM`
1802 # This used to be "$FILE:r", which strips the extention
1803 BASE=`stripExtention $FILE`
1804 MYTMP=`basename $FILE`".TMP"
1805 DELETE="$DELETE $MYTMP.c $MYTMP.i"
1806 DoNoErrCheck $RM $BASE.cpm.h $MYTMP.c
1807 Do touch $BASE.cpm.h
1808 Do $LN -f -s $FILE $MYTMP.c
1809 Do $CHARM_CPP_C $CHARM_CPP_C_FLAGS $MYTMP.c > $MYTMP.i
1810 Do $CHARMBIN/conv-cpm $MYTMP.i $BASE.cpm.h
1811 done
1813 ##############################################################################
1815 # Compile all specified files
1817 # All temporary files named *.TMP.* for easy cleanup.
1819 ##############################################################################
1821 Debug "About to compile..."
1823 for FILE in $FILES
1825 BASE=`stripExtention \`basename $FILE\``
1826 MYTMP=`basename $FILE`".TMP"
1827 FILE_EXT=`getExtention $FILE`
1828 BASEO="$BASE.o"
1829 DESTO="-o $BASEO"
1831 # in case of: charmc -o object.o -c foo.c,
1832 # avoid foo.c => remove foo.o => foo.o => object.o,
1833 # instead generate object.o directly.
1834 # remove and generate foo.o may be dangerous in parallel make
1835 # for example in the case of compiling several objs from one
1836 # same c file such as memory.C.
1837 if [ $numFiles = 1 -a -n "$OBJECT" ]
1838 then
1839 OBJ_EXT=`getExtention $OBJECT`
1840 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
1841 then
1842 BASEO=$OBJECT
1843 DESTO="-o $OBJECT"
1847 # if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".co" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1848 # then
1849 case "$FILE_EXT" in
1850 .c|.s|.S|.C|.cc|.cxx|.cpp|.c++|.cu|.f|.F|.f90|.F90|.fpp|.FPP|.f77|.F77)
1851 [ $VERBOSE ] && echo "Compiling $FILE"
1852 DoNoErrCheck $RM $BASEO `stripExtention $BASEO`.f.o
1853 esac
1854 # fi
1855 if [ ! -z "$SKIPLINK" ]
1856 then
1857 DESTO=""
1860 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
1861 then
1862 case "$FILE" in
1863 *.c)
1864 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE
1865 FILE="rose_$FILE"
1867 *.C|*.cc|*.cxx|*.cpp|*.c++)
1868 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE
1869 FILE="rose_$FILE"
1871 *.f|*.F|*.f77|*.F77)
1872 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE
1873 FILE="rose_$FILE"
1875 *.f90|*.F90|*.fpp|*.FPP)
1876 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1877 Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE
1878 FILE="rose_$FILE"
1880 esac
1883 case "$FILE" in
1884 *.ci)
1885 XIOPTS=$CMK_XIOPTS
1886 test "$PARADIGM" = "f90charm" && XIOPTS="$XIOPTS -f90"
1887 if [ "$PREPROCESS_CI" = "yes" ]
1888 then
1889 Do $CMK_CPP_CHARM $OPTS_CPP $FILE | Do $CHARMBIN/charmxi $XIOPTS -orig-file $FILE
1890 else
1891 Do $CHARMBIN/charmxi $XIOPTS $FILE
1894 *.c|*.s|*.S)
1895 Do $CHARM_CC $CHARM_CC_FLAGS -c $FILE $DESTO
1896 if [ "$Do_res" -ne 0 ]
1897 then
1898 touch $BASEO
1901 *.C|*.cc|*.cxx|*.cpp|*.c++|*.cu)
1902 if [ -n "$NATIVE" ]
1903 then
1904 Do $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP -c $FILE $DESTO
1905 else
1906 Do $CHARM_CXX $CHARM_CXX_FLAGS -c $FILE $DESTO
1908 if [ "$Do_res" -ne 0 ]
1909 then
1910 touch $BASEO
1913 *.f|*.F|*.f77|*.F77)
1914 test -z "$CMK_CF90_FIXED" && Abort "No F90 compiler (CMK_CF90_FIXED) defined"
1915 Do $CMK_CF90_FIXED -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1916 if [ "$Do_res" -ne 0 ]
1917 then
1918 touch $BASEO
1921 *.f90|*.F90|*.fpp|*.FPP)
1922 test -z "$CMK_CF90" && Abort "No F90 compiler (CMK_CF90) defined"
1923 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1924 Do $CMK_CF90 -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE $DESTO
1925 if [ "$Do_res" -ne 0 ]
1926 then
1927 touch $BASEO
1930 *.fc|*.FC)
1931 Abort "I'm not yet smart enough to compile $FILE"
1933 *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
1934 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1936 *.M|*.mod)
1937 OBJECT="$BASE"
1938 Copymod
1939 Success
1942 Abort "file with unrecognized extension $FILE"
1943 esac
1944 done
1946 ##############################################################################
1948 # POSSIBLY, SKIP LINK-STEP
1950 # 1. No $OBJECT may be specified at all --- its just a compilation.
1951 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1952 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1953 # 4. Language may be sequential. Do a quick and easy linkage.
1955 # in any of these cases, the full link step is skipped.
1957 ##############################################################################
1959 MakeSO() {
1960 Debugf "Running ldro..."
1961 DoNoErrCheck $RM $OBJECT
1962 # convert to absolute path if required
1963 if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1964 then
1965 dir=`dirname $OBJECT`
1966 fname=`basename $OBJECT`
1967 dir=`cd $dir; pwd`
1968 OBJECT=$dir/$fname
1970 if test "$MAKE_LDXX" = "1"
1971 then
1972 soTool="$CMK_LDXX $CMK_LDXX_FLAGS"
1973 else
1974 soTool="$CMK_LD $CMK_LD_FLAGS"
1976 if [ -n "$STANDALONE" ]
1977 then
1978 soLibs="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
1979 else
1980 soLibs="$PRE_LIBRARIES $POST_LIBRARIES"
1981 [ "$CMK_MACOSX" = "1" ] && OPTS_LD="$OPTS_LD -Wl,-install_name,$CHARMLIBSO/$fname"
1983 if [ -n "$LINK_WHOLE_ARCHIVE" ]
1984 then
1985 soLibs="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $soLibs $LDXX_WHOLE_ARCHIVE_POST"
1987 soLibs="$soLibs $CMK_SYSLIBS"
1988 if [ -n "$LINK_CXX_STL" ]
1989 then
1990 soLibs="$soLibs -lstdc++"
1992 soCmd="$soTool $CMK_LIBDIR -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $soLibs $CMK_LD_SHARED_LIBS"
1993 DoNoErrCheck $soCmd
1994 Do_res=$?
1995 if [ $Do_res -ne 0 ]
1996 then
1997 if [ -n "$NOABORT" ]
1998 then
1999 touch $OBJECT
2000 else
2001 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2002 echo "!! Failed to compile Charm++ shared library. You can disable shared !!"
2003 echo "!! lib compilation by providing --no-build-shared build option like: !!"
2004 echo "!! ./build charm++ netlrts-linux --no-build-shared -O !!"
2005 echo "!! or reexecute this charmc command with the --no-build-shared option !!"
2006 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2007 Abort "Command $soCmd returned error code $Do_res"
2010 Copyobj
2013 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ]
2014 then
2015 # We have no target object, or are playing preprocessor tricks-- just end
2016 Debugf "No target object-- finished"
2017 Success
2020 Debug "About to link..."
2022 if [ "$INPUT_GIVEN" != "1" ]
2023 then
2024 Abort "Trying to link, but no object files or library archives were specified"
2027 # if interoperate dont create the library now, wait to collect all info
2028 if [ "$MPI_INTEROPERATE" = "" ]
2029 then
2030 case "$OBJECT" in
2031 *.o)
2032 Debugf "Converting $FILES to $OBJECTFILES"
2033 nFiles=`echo $FILES | wc -w`
2034 nObj=`echo $OBJECTFILES | wc -w`
2035 # One source file, one .o: just move the .o
2036 if [ $OBJECT != $OBJECTFILES ]
2037 then
2038 Debugf "Moving .o to destination"
2039 DoNoErrCheck $RM $OBJECT
2040 Do $MV $OBJECTFILES $OBJECT
2042 Copyobj
2044 *.so|*.so.*|*.sl|*.dylib)
2045 # Make shared library
2046 # If building shared is not supported and this object is not standalone, exit.
2047 if [ "$BUILD_SHARE" = 0 -a -z "$STANDALONE" ]
2048 then
2049 Warning "Warning: building shared library is not supported, recompile charm++ with '--build-shared'."
2050 End 1
2051 elif [ "$CHARM_SHARED" = "0" ]
2052 then
2053 MakeSO
2056 *.a)
2057 # Make regular (.a, non-shared) library
2058 # in case building charm so, build .so under lib_so as well # Gengbin
2059 if [ "$BUILD_SHARE" = "1" ]
2060 then
2061 COPY_EXIT=""
2062 OBJECT_SAVE=$OBJECT
2063 COPYTO_SAVE=$COPYTO
2064 if [ -z "$COPYTO" ]
2065 then
2066 DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
2067 OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
2068 else
2069 COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
2070 DESTDIR=$COPYTO
2072 OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
2073 [ -f $DESTDIR/.charmso ] && MakeSO
2074 COPYTO=$COPYTO_SAVE
2075 OBJECT=$OBJECT_SAVE
2076 COPY_EXIT="true"
2078 # build normal .a
2079 DoNoErrCheck $RM $OBJECT
2080 Do $CMK_AR $OBJECT $OBJECTFILES
2081 Do $CMK_RANLIB $OBJECT
2082 Copyobj
2084 esac
2086 # If the above case returns, we're not creating a .o or .a file,
2087 # so linking is needed.
2089 if [ $CMK_CELL -eq 1 ]
2090 then
2092 if [ "$PARADIGM" = "charm++" ]
2093 then
2095 # Make the spe object file to be included
2096 Do $SPU_COMPILER -c -I$CHARMINC $CMK_SYSINC -o main__funcLookup__.genSPECode.o main__funcLookup__.genSPECode.c -DCMK_CELL_SPE=1
2097 Do $SPU_LINKER -L$CHARMLIB -o main__funcLookup__.genSPECode main__funcLookup__.genSPECode.o $CMK_SPERT_LIBS $SPU_EXTRA_LIBS
2098 Do $CMK_PPU_EMBEDSPU spert_main main__funcLookup__.genSPECode main__funcLookup__.genSPECode.ppe.o
2103 # check if we're linking a sequential object
2104 case "$LANGUAGE" in
2105 "c"|"C"|"f90"|"f77")
2106 if [ -n "$NATIVE" ]
2107 then
2108 Do $CMK_NATIVE_LD $CMK_NATIVE_LD_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2109 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2110 else
2111 Do $CMK_SEQ_LD $CMK_SEQ_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2112 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2114 Copyobj
2116 "c++"|"C++")
2117 if [ -n "$NATIVE" ]
2118 then
2119 Do $CMK_NATIVE_LDXX $CMK_NATIVE_LDXX_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2120 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2121 else
2122 Do $CMK_SEQ_LDXX $CMK_SEQ_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2123 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2125 Copyobj
2127 esac
2130 ##############################################################################
2132 # Confirm that TRACEMODE, BALANCE, MEMORY, THREAD exist
2134 ##############################################################################
2136 # [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed. Is Charm++ built properly?"
2138 if [ x"$TRACEMODE" != x ]
2139 then
2140 for trace in $TRACEMODE; do
2141 [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
2142 done
2145 BAL_EXT=`getExtention $BALANCE`
2146 if [ -z "$BAL_EXT" ]; then
2147 # Balance has no extension-- is a library reference
2148 if [ -f "${CHARMLIB}/libldb-$BALANCE.a" ]; then
2149 BAL_OBJ_FILE="${CHARMLIB}/libldb-$BALANCE.a"
2150 else
2151 BAL_OBJ_FILE="${CHARMLIBSO}/libldb-$BALANCE.so"
2153 else
2154 # Balance has some extension-- must be a .o or .a file
2155 BAL_OBJ_FILE="$BALANCE"
2158 if [ ! -r "$BAL_OBJ_FILE" ]
2159 then
2160 if [ "$BALANCE" = "$BAL_OBJ_FILE" ]
2161 then
2162 Abort "Could not find load balancer object $BAL_OBJ_FILE"
2163 else
2164 (cd $CHARMLIB ; ls -al libldb-*)
2165 Abort "Unknown load balancer $BALANCE / $BAL_OBJ_FILE"
2169 if [ -f "${CHARMLIB}/libmemory-${MEMORY}.a" ]; then
2170 MEM_OBJ_FILE="${CHARMLIB}/libmemory-${MEMORY}.a"
2171 else
2172 MEM_OBJ_FILE="${CHARMLIBSO}/libmemory-${MEMORY}.so"
2175 if [ ! -r $MEM_OBJ_FILE -o ! -s $MEM_OBJ_FILE ]
2176 then
2177 (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2178 Abort "charmc : No such memory mode $MEMORY"
2181 if [ -f "${CHARMLIB}/libthreads-${THREAD}.a" ]; then
2182 THREAD_OBJ_FILE="${CHARMLIB}/libthreads-${THREAD}.a"
2183 else
2184 THREAD_OBJ_FILE="${CHARMLIBSO}/libthreads-${THREAD}.so"
2187 if [ ! -r $THREAD_OBJ_FILE -o ! -s $THREAD_OBJ_FILE ]
2188 then
2189 (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2190 Abort "charmc : No such thread mode $THREAD"
2194 ################# Build the module initialization function ##################
2196 if [ -z "$SKIP_MODULEINIT" ]
2197 then
2198 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2200 for module in $MODULES; do
2201 echo "extern void _register$module(void);" >> $modInitSrc
2202 done
2203 for trace in $TRACEMODE; do
2204 if test $trace = "summary"
2205 then
2206 echo " extern void _registerTraceSummary();" >> $modInitSrc
2207 elif test $trace = "projections"
2208 then
2209 echo " extern void _registerTraceProjections();" >> $modInitSrc
2210 elif test $trace = "simple"
2211 then
2212 echo " extern void _registerTraceSimple();" >> $modInitSrc
2213 elif test $trace = "Tau"
2214 then
2215 echo " extern void _registerTraceTau();" >> $modInitSrc
2216 elif test $trace = "utilization"
2217 then
2218 echo " extern void _registerTraceUtilization();" >> $modInitSrc
2219 elif test $trace = "controlPoints"
2220 then
2221 echo " extern void _registerTraceControlPoints();" >> $modInitSrc
2222 elif test $trace = "perfReport"
2223 then
2224 Do $CP $CHARMBIN/fuzzytree.txt fuzzytree.txt
2225 Do $CP $CHARMBIN/tree.txt tree.txt
2226 echo " extern void _registerTraceAutoPerf();" >> $modInitSrc
2228 elif test $trace = "all"
2229 then
2230 echo " extern void _registerTraceProjections();" >> $modInitSrc
2231 echo " extern void _registerTraceControlPoints();" >> $modInitSrc
2232 echo " extern void _registerTraceSummary();" >> $modInitSrc
2234 done
2235 if test -n "$BALANCER"
2236 then
2237 echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
2239 echo "void _registerExternalModules(char **argv) { (void)argv;" >> $modInitSrc
2240 for module in $MODULES; do
2241 [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
2242 echo " _register$module();" >> $modInitSrc
2243 done
2244 for trace in $TRACEMODE; do
2245 if test $trace = "summary"
2246 then
2247 echo " _registerTraceSummary();" >> $modInitSrc
2248 elif test $trace = "projections"
2249 then
2250 echo " _registerTraceProjections();" >> $modInitSrc
2251 elif test $trace = "Tau"
2252 then
2253 TRACE_WITH_TAU=1
2254 echo " _registerTraceTau();" >> $modInitSrc
2255 elif test $trace = "simple"
2256 then
2257 echo " _registerTraceSimple();" >> $modInitSrc
2258 elif test $trace = "utilization"
2259 then
2260 echo " _registerTraceUtilization();" >> $modInitSrc
2261 elif test $trace = "controlPoints"
2262 then
2263 echo " _registerTraceControlPoints();" >> $modInitSrc
2264 elif test $trace = "perfReport"
2265 then
2266 echo " _registerTraceAutoPerf();" >> $modInitSrc
2267 elif test $trace = "all"
2268 then
2269 echo " _registerTraceProjections();" >> $modInitSrc
2270 echo " _registerTraceControlPoints();" >> $modInitSrc
2271 echo " _registerTraceSummary();" >> $modInitSrc
2273 done
2274 if test -n "$BALANCER"
2275 then
2276 [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
2277 for deflb in $BALANCER
2279 echo " LBDefaultCreate(\"$deflb\");" >> $modInitSrc
2280 done
2282 echo "}" >> $modInitSrc
2284 # creating projections
2285 echo "void _createTraces(char **argv) { (void)argv;" >> $modInitSrc
2286 for trace in $TRACEMODE; do
2287 [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
2288 echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
2289 echo "_createTrace$trace(argv);" >> $modInitSrc
2290 done
2291 echo "}" >> $modInitSrc
2293 Do $CHARM_CXX $CHARM_CXX_FLAGS -c $modInitSrc -o $modInitObj
2296 ###############################################################################
2298 # Finally, LINK
2300 ###############################################################################
2302 Debug "About to perform final link..."
2304 #currently only support creation of .a
2305 if [ "$MPI_INTEROPERATE" != "" ]
2306 then
2307 case "$OBJECT" in
2308 *.a)
2309 # in case building charm so, build .so under lib_so as well # Gengbin
2310 DoNoErrCheck $RM $OBJECT
2311 if [ -z "$SKIP_MODULEINIT" ]
2312 then
2313 echo "$CMK_AR $OBJECT $OBJECTFILES $modInitObj"
2314 Do $CMK_AR $OBJECT $OBJECTFILES $modInitObj
2316 Do $CMK_RANLIB $OBJECT
2317 echo "export CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\"" > ./charm_all_libs.sh
2318 echo "CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\""
2319 Copyobj
2321 *.so|*.so.*|*.sl|*.dylib)
2322 echo "Warning: building shared library failed; for interoperation build
2323 static library."
2324 End 0
2326 esac
2329 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
2330 then
2331 # build an application .so linking with charm .so
2332 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
2333 Debugf "Running ldro..."
2334 DoNoErrCheck $RM $OBJECT
2335 [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2336 [ "$MAKE_LD" = "1" ] && Do $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2337 Copyobj
2338 else
2339 # Make a regular executable: call the appropriate linker
2340 [ "$MAKE_LDXX" = "1" ] && Do $CHARM_LDXX $CHARM_LDXX_FLAGS -o $OBJECT
2341 [ "$MAKE_LD" = "1" ] && Do $CHARM_LD $CHARM_LD_FLAGS -o $OBJECT
2344 ########################################################################
2346 # Copy conv-host to user directory if it is present in installation.
2348 ########################################################################
2350 if test "$COPY_CHARMRUN" = "true"
2351 then
2352 targ=charmrun$CMK_POST_EXE
2353 [ ! -x $CHARMBIN/$targ -a -n "$CMK_POST_EXE" ] && targ=charmrun
2354 convhost=conv-host$CMK_POST_EXE
2356 if [ -x $CHARMBIN/$targ ]
2357 then
2358 DoNoErrCheck $RM $targ
2359 DoNoErrCheck $CP $CHARMBIN/$targ $targ 2> /dev/null
2363 [ -z "$SKIP_MODULEINIT" -a -z "$SAVE" ] && DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2365 Copyobj