AMPI: Add fsglobals (filesystem) and pipglobals (Process-in-Process) privatization...
[charm.git] / src / scripts / charmc
1 #!/bin/sh
2 ##############################################################################
3 # charmc: Compiler for Converse/Charm/Charm++ programs
4 #
5 # Converted to Bourne Shell by Orion Sky Lawlor, 10/21/1999
6 #
7 # Initialize the main controlling variables, setup error handler
8 # ALL variables used by this script should be initialized here.
9 #
10 ##############################################################################
11
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"
20
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 USE_PIC="0"
55 USE_PIE='0'
56
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=""
92
93 COPY_CHARMRUN=true
94 USE_BUILD_OPTIONS=0
95
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 AMPI_FUNCPTR_SHIM='0'
103 PRINT_BUILDING_BLOCKS=""
104 NOABORT=""
105
106 TAU_MAKEFILE=Make.tau
107 TAU_TRACE_MPI=1
108
109 CMK_CELL=0
110 SPU_USE_CPP=0
111 SPU_EXTRA_LIBS=""
112
113 MPI_INTEROPERATE=""
114 NO_MAIN_MODULE=""
115 NO_MAIN=""
116 CUSTOM_PARTITION=""
117 PREPROCESS_CI="yes"
118 INPUT_GIVEN=""
119
120 ####################################################################
121 #
122 #  Utility routines used below
123 #
124 ###################################################################
125
126 # PrintUsage: prints a helpful command-line usage message and quits
127 # Args: any additional messages
128 printUsage() {
129     printVersion
130     echo 
131     echo "Usage: charmc [ flags ] <files>"
132     echo
133     echo "  flags:"
134     echo "        -o <target> -g -O"
135     echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
136     echo "        -machine <mach> -seq -host -language <lang> -pg <opt>"
137     echo "        -balance <mode> -tracemode <mode> -memory <mode>"
138     echo "        -modules <comma-separated list of C++ modules> -thread"
139     echo "        -debug-script -count-tokens -default-to-aout -E -S -M"
140     echo "        -verbose -save -purify -cp <dest> -cpmod -gen-cpm <pkg>"
141     echo "        -swapglobals -tlsglobals -roseomptlsglobals"
142     echo "        -use-reliable-cc -use-fastest-cc -use-new-std"
143     echo "        -cc <new cc> -c++ <new CC> -ld <new ld> -ld++ <new LD>"
144     echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
145     echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
146     echo "        -f90 <new f90> -f90-option <opt> -fmoddir <f90mod path>"
147     echo "        -flibs -rpath <path> -custom-part -touch-on-failure"
148     echo "        -mpi -openmp -no-trace-mpi -build-shared -charm-shared"
149     echo "        -no-charmrun -no-preprocess-ci -nomain-module -nomain"
150     echo "        -nof90main -f90main"
151     echo
152     echo "  Charmc compiles C, C++, f77, f90, AMPI, Converse, Converse++, Charm, "
153     echo "and Charm++ programs.  The flags generally match those of cc or f77."
154     echo "  Other options that are not listed here will be passed directly to the"
155     echo "underlying compiler and/or linker."
156     echo "Parallel Programming Lab, UIUC, 2019."
157     echo $*
158     exit 1
159 }
160
161 # End blows away the temporary files (unless SAVE is true) and exits
162 # Args: <exit code>
163 End() {
164     if [ -z "$SAVE" ]
165         then
166         for FILE in `echo $FILES`
167         do
168             #BASE=`stripExtention $FILE`
169             MYTMP=`basename $FILE`".TMP"
170             $RM $MYTMP.P.C $MYTMP.cpp $MYTMP.space $MYTMP.xlat $MYTMP.o
171             $RM $MYTMP.c $MYTMP.c.0.h $MYTMP.c.1.h $MYTMP.c.2.h
172             $RM $MYTMP.i $MYTMP.$CMK_CPP_SUFFIX
173         done
174         $RM core $DELETE
175         if [ -z "$SKIP_MODULEINIT" -a -n "$modInitObj" ]
176         then
177             [ -n "$VERBOSE" ] && echo $RM $modInitSrc $modInitObj
178             DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
179         fi
180     fi
181     exit $1
182 }
183
184 # Write this error message to stderr
185 # ("1>&2" redirects the echo output to stderr).
186 Warning() {
187         echo "$@" 1>&2
188 }
189
190 # This procedure prints an error message and exits.
191 # Args: written to stderr
192 Abort() {
193         Warning "Fatal Error by charmc in directory "`pwd`
194         Warning "   $@"
195         Warning "charmc exiting..."
196         End 1
197 }
198
199
200 # Instead of an ECHO_CMD variable, I define a procedure Do,
201 # which (possibly) echos, runs, and tests the errors of the given command.
202 # Args: executed as given
203 DoNoErrCheck() {
204         [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
205         eval "$@"
206 }
207
208 Do() {
209         DoNoErrCheck "$@"
210         Do_res=$?
211 # The UNIX result code better be zero, or we die
212         [ $Do_res -eq 0 -o -n "$NOABORT" ] || Abort "Command $@ returned error code $Do_res"
213 }
214
215 # This procedure removes the extention (the ".c" in "./main.c") from
216 # its first argument, and prints the result. Unlike the builtin command
217 # basename, it keeps the directory path.
218 # Args: <name to strip>
219 stripExtention() {
220         se_base=`basename $1`
221 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
222         se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
223         se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
224         echo $se_ret
225 }
226
227 # GetExtention returns the extention on the given file name
228 # or "" if none.  (e.g. "./bob/snack.c" returns ".c")
229 # Args: <name to find extention of>
230 getExtention() {
231 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
232 #        se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
233 #       echo $se_ret
234         se_ret=`echo $1 | sed -e 's/.*\././'`
235         if test "$se_ret" = $1
236         then
237           echo ""
238         else
239           echo $se_ret
240         fi
241 }
242
243 Debugf() {
244         [ -n "$VERBOSE" ] && echo "charmc>" $@
245 }
246
247 Debug() {
248     if [ -n "$DEBUG_SCRIPT" ]
249     then
250         echo 
251         echo "------- Charmc Debugging info: $* -------"
252         echo "CHARMBIN=$CHARMBIN"
253         echo "CHARMINC=$CHARMINC"
254         echo "CHARMLIB=$CHARMLIB"
255         echo "FILES=$FILES"
256         echo "DELETE=$DELETE"
257         echo "OBJECT=$OBJECT"
258         echo "LANGUAGE=$LANGUAGE"
259         echo "PARADIGM=$PARADIGM"
260 #       echo "Working directory="`pwd`
261     fi
262 }
263
264 # Return success if $1 is not in any of the other arguments
265 notInList() {
266         search=$1
267         shift
268         while [ $# -gt 0 ]
269         do
270                 if [ "$search" = "$1" ]
271                 then
272                         # It's already in there-- fail
273                         return 1
274                 fi
275                 shift
276         done
277         # It's missing--succeed
278         return 0
279 }
280
281 # Add arguments to our modules list, avoiding duplicates
282 AddModules() {
283     for M in "$@"
284     do
285       notInList $M $MODULES && MODULES="$MODULES $M"
286     done
287 }
288
289 # Add this word to this list, avoiding duplicates
290 AddList() {
291     ret=""
292     while [ $# -gt 1 ]
293     do
294         ret="$ret $1"
295         shift
296     done
297     if notInList $1 $ret
298     then
299         ret="$ret $1"
300     fi
301     echo $ret
302 }
303
304 # Drop the first argument anywhere it appears in the subsequent list
305 DropList() {
306     drop="$1"
307     shift
308
309     ret=""
310     while [ $# -gt 1 ]
311     do
312         if [ "$1" != "$drop" ]; then
313             ret="$ret $1"
314         fi
315         shift
316     done
317
318     echo $ret
319 }
320
321 # TEMP_BASE is appended with this script's process ID (PID),
322 # so multiple charmcs can run in parallel without overwriting
323 # each other's temporary files.
324 TEMP_BASE="/tmp/charmc_tmp.$$"
325
326 # Try to find CHARMBIN by looking in directory where charmc is
327 findCharmBin() {
328 if [ -z "$CHARMBIN" ]
329 then
330         SCRIPT=$1
331         CHARMBIN=`dirname $SCRIPT`
332 #       CHARMBIN=`cd $CHARMBIN; pwd`
333 # NOTE: this script no longer tries to follow soft links
334 # to find the "original" charmc-- if this is bad, 
335 # translate these lines to Bourne shell from C shell:
336 # -------------------- Begin C Shell ------------------------->
337 #    if ($SCRIPT:h != $SCRIPT:t) then
338 #        cd $SCRIPT:h
339 #        set SCRIPT=$SCRIPT:t
340 #    else
341 #        foreach dir ($path)
342 #            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
343 #                cd $dir
344 #                break
345 #            endif
346 #        end
347 #    endif
348 #    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
349 #        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
350 #        if ($SCRIPT:h != $SCRIPT:t) then
351 #            cd $SCRIPT:h
352 #            set SCRIPT=$SCRIPT:t
353 #        endif
354 #    end
355 #    set CHARMBIN=`pwd`
356 # <------------------ End C Shell -----------------------------
357 fi
358 }
359
360 printVersion()
361 {
362         findCharmBin $0
363         version=`cat $CHARMBIN/../include/VERSION`
364         echo Charm++ Version $version
365 }
366
367
368 ##############################################################################
369 #
370 # The following section identifies CHARMBIN, the charm binary-directory.
371 #
372 ##############################################################################
373
374 ORIGDIR=`pwd`
375
376 # Try to find CHARMBIN by looking in directory where charmc is
377
378 findCharmBin $0
379
380 UNAME=`uname -s`
381 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
382 if [ "$FIRST_THREE" = "CYG" -o "$UNAME" = "Interix" ]
383 then
384 # Running on a windows system-- append .exe to file names
385         PROG_EXT=".exe"
386 fi
387
388 CHARMLIB="$CHARMBIN/../lib"
389 CHARMINC="$CHARMBIN/../include"
390 CHARMLIBSO=
391 if test -d "$CHARMBIN/../lib_so" 
392 then
393   CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
394   #getting absolute path is harder than thought because of symbolic links and ..
395   #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
396   #csh is ok too if it exists 
397   test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
398   test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
399   test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
400 fi
401
402 ##############################################################################
403 #
404 # Parse the arguments
405 #
406 # Don't do any analysis in here, just the parsing.
407 #
408 ##############################################################################
409
410 [ $# -eq 0 ] && printUsage "Error: No arguments given."
411
412 processArgs() {
413 while [ ! $# -eq 0 ]
414 do
415         arg="$1"
416         shift
417
418         case "$arg" in
419         "-V")
420                 printVersion
421                 exit 0
422                 ;;
423
424         "-machine")
425                 MACHTYPE="$1"
426                 shift
427                 ;;
428
429         "-seq")
430                 SEQUENTIAL=true
431                 ;;
432
433         "-host")
434                 NATIVE=true
435                 ;;
436
437         "-standalone")
438                 STANDALONE="true"
439                 SKIP_MODULEINIT="yes"
440                 ;;
441
442         "-language")
443                 # Parse out some fake languages (that are actually modules)
444                 case "$1" in
445                 "ampi") AddModules tcharmmain ampi ; AMPI="1" ;;
446                 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ; AMPIF="1" ;;
447                 "armci") AddModules tcharmmain armci ;;
448                 "armcif") AddModules tcharmmain armci ; USE_F90_LIBRARIES="1" ;;
449                 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
450                 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
451                 "ParFUM_TOPS") AddModules tcharmmain ParFUM ParFUM_TOPS ; AMPIMAIN="ParFUMmain";;
452     "ParFUM") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain";;
453     "ParFUMf") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain"; USE_F90_LIBRARIES="1" ;;
454                 "mblock") AddModules tcharmmain mblock ;;
455                 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
456
457                 "charm"|"charm++"|"charm++f"|"f90charm"|"converse"|"converse++"|"bgcharm++"|"bgconverse++"|"bluegene"|"ckbluegene"|"bigsim")
458                         PARADIGM="$1"
459                         POST_LANGUAGE=1
460                         ;;
461
462                 *) 
463                         LANGUAGE="$1"
464                         POST_LANGUAGE=1
465                         ;;
466                 esac
467                 shift
468                 ;;
469
470         "-debug")
471                 # Requested support from charmdebug: add some modules and libraries
472                 CHARMDEBUG=1
473                 MEMORY="charmdebug"
474                 ;;
475
476         "-module"|"-modules")
477                 AddModules `echo $1 | sed -e 's/,/ /g'`
478                 INPUT_GIVEN="1"
479                 shift
480                 ;;
481
482         "-balancer")
483 #                test -n "$BALANCER" && Abort "More than one -balancer specified!"
484                 BALANCER="$BALANCER $1"
485                 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
486                 AddModules $mod
487                 shift
488                 ;;
489
490         "-balance")
491                 BALANCE="$1"
492                 shift
493                 ;;
494
495         "-queue")
496                 Warning "Warning: -queue currently being ignored."
497                 shift
498                 ;;
499
500         "-memory")
501                 MEMORY="$1"
502                 shift
503                 ;;
504
505         "-thread")
506                 THREAD="$1"
507                 shift
508                 ;;
509
510         "-tracemode")
511                 TRACEMODE_NEW=`AddList $TRACEMODE $1`
512                 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
513                 then
514                         Warning "Warning: Duplicate tracemode $1 ignored"
515                 else
516                         TRACEMODE=$TRACEMODE_NEW
517                 fi
518                 shift
519                 ;;
520         "-no-trace-mpi")
521                 TAU_TRACE_MPI=0
522                 ;;
523         
524         "-swapglobal"|"-swapglobals")
525                 SWAPGLOBALS="1"
526                 USE_PIC="1"
527                 ;;
528
529         "-tlsglobal"|"-tlsglobals")
530                 TLSGLOBALS="1"
531                 ;;
532
533         "-roseomptlsglobals")
534                 ROSE_OMP_TLS_GLOBALS="yes"
535                 ;;
536
537         "-ampi-funcptr-shim")
538                 AMPI_FUNCPTR_SHIM='1'
539                 USE_PIE='1'
540                 ;;
541
542         "-verbose")
543                 echo "Verbose mode set"
544                 VERBOSE=true
545                 ;;
546
547         "-spu-cpp")
548                 SPU_USE_CPP=1
549                 ;;
550
551         "-spu-lib")
552                 SPU_EXTRA_LIBS="$SPU_EXTRA_LIBS -l$1"
553                 shift
554                 ;;
555
556         "-intrinsic")
557                 XI_INTERNAL=true
558                 ;;
559
560         "-debug-script")
561                 echo "Will give excessive charmc debugging output..."
562                 DEBUG_SCRIPT=true
563                 ;;
564
565         "-save")
566                 SAVE=true
567                 ;;
568
569         "-purify")
570                 PURIFY=true
571                 ;;
572
573         "-use-reliable-cc")
574                 USE_RELIABLE_CC=1
575                 ;;
576
577         "-use-fastest-cc")
578                 USE_FASTEST_CC=1
579                 ;;
580
581         "-cc")
582                 OVERRIDE_CC="$1"
583                 shift
584                 ;;
585
586         "-c++")
587                 OVERRIDE_CXX="$1"
588                 shift
589                 ;;
590
591         "-f90")
592                 OVERRIDE_F90="$1"
593                 shift
594                 ;;
595
596         "-ld")
597                 OVERRIDE_LD="$1"
598                 shift
599                 ;;
600
601         "-ld++")
602                 OVERRIDE_LDXX="$1"
603                 shift
604                 ;;
605
606         "-cpp-option")
607                 OPTS_CPP="$OPTS_CPP $1"
608                 shift
609                 ;;
610
611         "-ldro-option")
612                 OPTS_LDRO="$OPTS_LDRO $1"
613                 shift
614                 ;;
615
616         "-cc-option")
617                 OPTS_CC="$OPTS_CC $1"
618                 shift
619                 ;;
620
621         "-c++-option")
622                 OPTS_CXX="$OPTS_CXX $1"
623                 shift
624                 ;;
625
626         "-f90-option")
627                 OPTS_F90="$OPTS_F90 $1"
628                 shift
629                 ;;
630
631         "-ld-option"|"-ld++-option")
632                 OPTS_LD="$OPTS_LD $1"
633                 shift
634                 ;;
635
636         "-rpath")
637                 OPTS_LD="$OPTS_LD -rpath $1"
638                 shift
639                 ;;
640
641         "-rpath-origin")
642                 RPATH_ORIGIN="yes"
643                 ;;
644         
645         "-fortran"|"-flib"|"-flibs")
646                 USE_F90_LIBRARIES="1" 
647                 ;;
648         "-f77")
649                 USE_F77="1" 
650                 ;;
651         "-fortran77"|"-f77lib"|"-f77libs")
652                 USE_F77_LIBRARIES="1" 
653                 ;;
654         "-E")
655 # Run preprocessor only
656                 PREPROCESS="yes"
657                 SKIPLINK="yes"
658                 OPTS="$OPTS $arg"
659                 ;;
660         "-preprocess")
661 # Run preprocessor as an extra step, continue after preprocessing
662                 PREPROCESS="yes"
663                 ;;
664         "-no-preprocess-ci")
665 # Turn off the preprocessor for ci files
666                 PREPROCESS_CI="no"
667                 ;;
668         "-P"|"-S")
669 # Run preprocessor/assembler only
670                 SKIPLINK="yes"
671                 OPTS="$OPTS $arg"
672                 ;;
673 #------ Dependency generation ---------
674         "-M" | "-MM" | "-MMD" | "-MG")
675                 SKIPLINK="yes"
676                 OPTS="$OPTS $arg"
677                 GENDEPENDS="yes"
678                 ;;
679         "-MF" | "-MT" | "-MQ" | "-MD")  #-MP will pass through automatically
680                 OPTS="$OPTS $arg $1"
681                 shift
682                 ;;
683 #--------------------------------------
684     "-count-tokens")
685                 OPTS="$OPTS $arg"
686         COUNTTOKENS="yes"
687         ;;
688         "-default-to-aout")
689                 if [ "$EXPLICIT_OBJECT $EXPLICIT_COMPILATION" = "no no" ]
690                 then
691                       OBJECT="a.out"
692                 fi
693                 ;;
694         -print-prog-name=*)
695                 echo $arg | cut -d'=' -f2
696                 exit 0
697                 ;;
698         "-c")
699                 if [ "$EXPLICIT_OBJECT" = "no" ]
700                 then
701                       OBJECT=""
702                 fi
703                 EXPLICIT_COMPILATION="yes"
704                 ;;
705
706         "-o")
707                 EXPLICIT_OBJECT="yes"
708                 OBJECT=$1
709                 shift
710                 ;;
711
712         "-cp")
713                 COPYTO="$1"
714                 shift
715                 ;;
716
717         "-cpmod")
718                 MODCOPIES="$1 $MODCOPIES"
719                 shift
720                 ;;
721
722         "-gen-cpm")
723                 GENCPM="$GENCPM $1"
724                 shift
725                 ;;
726
727         -I)
728                 OPTS_CPP="$OPTS_CPP -I$1"
729                 shift
730                 ;;
731
732         -D*|-I*)
733                 if echo "$arg" | grep ' '  > /dev/null 2>/dev/null 
734                 then
735                   OPTS_CPP="$OPTS_CPP "\"$arg\"
736                 else
737                   OPTS_CPP="$OPTS_CPP $arg"
738                 fi
739                 ;;
740
741         -Werror)
742                 WERROR="1"
743                 ;;
744
745         -Wno-error)
746                 WERROR="0"
747                 ;;
748
749         "-use-new-std")
750         USE_NEW_STD="1"
751                 ;;
752
753         "-no-use-new-std")
754                 USE_NEW_STD="0"
755                 ;;
756
757         -LANG*)
758                 Warning "passing unrecognized option $arg to all compilers and linkers"
759                 OPTS="$OPTS $arg"
760                 ;;
761         -shared|-G)
762                 BUILD_SHARE="1"
763                 ;;
764         -L*|-shared|-G) # note that this is not executed if $arg == -shared|-G, due to the case above; might be a bug
765                 OPTS_LD="$OPTS_LD $arg"
766                 ;;
767         -charm-shared|-cs)
768                 CHARM_SHARED="1"
769                 ;;
770         -build-shared)
771                 # used internally when building Charm++ to create lib_so
772                 BUILD_SHARE="1"
773                 ;;
774         -no-build-shared)
775                 # used internally not to build Charm++ lib_so
776                 BUILD_SHARE="0"
777                 ;;
778         "-optimize")
779                 OPTIMIZE_MODE=true
780                 ;;
781
782         "-no-optimize")
783                 OPTIMIZE_MODE=false
784                 ;;
785
786         "-production")
787                 PRODUCTION_MODE=true
788                 ;;
789         "-no-production")
790                 PRODUCTION_MODE=false
791                 ;;
792
793         -Wl,*)
794                 POST_LIBRARIES="$POST_LIBRARIES $arg"
795                 ;;
796         
797         "-pg"|"-g"|-W*|-O*)
798                 OPTS="$OPTS $arg"
799                 ;;
800
801         "-fmoddir")
802                 F90_MODDIR="$F90_MODDIR $1"
803                 shift
804                 ;;
805
806         -l*|*.a|*.so|*.so.*|*.dylib)
807                 if [ -n "$POST_LANGUAGE" ]
808                 then
809                         POST_LIBRARIES="$POST_LIBRARIES $arg"
810                 else
811                         PRE_LIBRARIES="$PRE_LIBRARIES $arg"
812                 fi
813                 INPUT_GIVEN="1"
814                 ;;
815
816         "-whole-archive")
817                 LINK_WHOLE_ARCHIVE=true
818                 ;;
819
820         "-c++stl")
821                 LINK_CXX_STL=true
822                 ;;
823
824         -s)
825                 OPTS_LD="$OPTS_LD   $arg"
826                 ;;
827         -no-charmrun)
828                 COPY_CHARMRUN=false
829                 ;;
830         -use-build-options)
831                 USE_BUILD_OPTIONS=1
832                 ;;
833         -h|--help)
834                 printUsage
835                 ;;
836         -f90main)
837                 F90_MAIN=1
838                 ;;
839         -nof90main)
840                 F90_MAIN=
841                 ;;
842         -mpi)
843                 MPI_INTEROPERATE="yes"
844                 NO_MAIN="yes"
845                 ;;
846         -nomain-module)
847                 NO_MAIN_MODULE="yes"
848                 ;;
849         -nomain)
850                 NO_MAIN="yes"
851                 ;;
852         -custom-part)
853                 CUSTOM_PARTITION="yes"
854                 ;;
855
856         -fopenmp|-openmp)
857                 USE_OPENMP="yes"
858                 ;;
859
860         -skip-module-init)
861                 SKIP_MODULEINIT="yes"
862                 ;;
863
864         -print-building-blocks)
865                 PRINT_BUILDING_BLOCKS="yes"
866                 SKIP_MODULEINIT="yes"
867                 ;;
868
869         -touch-on-failure)
870                 NOABORT="yes"
871                 ;;
872
873         -clear-input)
874                 INPUT_GIVEN=''
875                 FILES=''
876                 PRE_LIBRARIES=''
877                 POST_LIBRARIES=''
878                 ;;
879
880         -*|+*)
881 #               Warning "passing unrecognized option $arg to all compilers and linkers"
882                 OPTS="$OPTS  $arg"
883                 ;;
884         *.*)
885                 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
886                 FILES="$FILES $arg"
887                 INPUT_GIVEN="1"
888                 ;;
889 # Default
890         *)
891 #               printUsage  "Error: Unrecognized argument $arg"
892 #               Warning "passing unrecognized option $arg to all compilers and linkers"
893                 OPTS="$OPTS  $arg"
894                 ;;
895         esac
896 done
897 }
898
899 trap 'End 1' 2
900
901 # Process original command-line arguments
902 eval processArgs "$@"
903
904 # Do not skip linking if user explicitly specified an output file
905 # This allows generating dependencies while compiling
906 if [ "$GENDEPENDS" = "yes" -a "$EXPLICIT_OBJECT" = "yes" ]; then
907         SKIPLINK=""
908 fi
909
910 USER_POST_LIBRARIES="$POST_LIBRARIES"
911 USER_PRE_LIBRARIES="$PRE_LIBRARIES"
912
913 # Construct list of object files
914 numFiles=`echo $FILES | wc -w`
915 for FILE in $FILES
916 do
917
918         case "$FILE" in
919         *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
920                 OBJECTFILES="$OBJECTFILES $FILE"
921                 ;;
922         *.c|*.s|*.S|*.C|*.cc|*.cxx|*.cpp|*.c++|*.cu|*.f|*.F|*.f77|*.F77|*.f90|*.F90|*.fpp|*.FPP)
923                 BASE=`stripExtention \`basename $FILE\``
924                 BASEO="$BASE.o"
925
926                 if [ $numFiles = 1 -a -n "$OBJECT" ]
927                 then
928                         OBJ_EXT=`getExtention $OBJECT`
929                         if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
930                         then
931                                 BASEO=$OBJECT
932                         fi
933                 fi
934
935                 # Handle new object files
936                 if [ -n "$BASEO" -a -n "$OBJECT" ]
937                 then
938                         if [ "$OBJECT" != "$BASEO" ]
939                         then
940                                 DELETE="$DELETE $BASEO"
941                         fi
942                         OBJECTFILES="$OBJECTFILES $BASEO"
943                 fi
944                 ;;
945         esac
946 done
947
948
949 ##############################################################################
950 #
951 # Load module dependencies.
952 #
953 ##############################################################################
954
955 Debug "About to read machine config script"
956 Debug "Read config script, setting defaults..."
957
958 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
959 . $CHARMINC/conv-config.sh $CHARMINC
960
961 Debug "Setting vars..."
962
963 if [ "$USE_BUILD_OPTIONS" = "1" ]  
964 then
965         [ -n "$VERBOSE" ] && echo "Charmc applying build time options: $BUILDOPTS"
966         OPTS="$OPTS $BUILDOPTS"
967 fi
968
969 # If we are debugging, add "-g -O0" to the C/C++ flags
970 if [ -n "$CHARMDEBUG" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]; then
971        if [ -n "$CMK_BUILD_PYTHON" ]; then
972                 AddModules PythonCCS charmdebug_python
973                 POST_LIBRARIES=`AddList $POST_LIBRARIES -lpython${CMK_BUILD_PYTHON}`
974         fi
975         OPTS_CPP="$OPTS_CPP -O0 -g"
976 fi
977
978 # The purpose of the -rpath-origin option is for the resulting binary to have
979 # the literal text '$ORIGIN' in the RPATH field of its ELF header, essentially
980 # saying that it is okay for the binary to look in the same directory as itself
981 # for the shared objects it needs. Unfortunately, POSIX shells will interpret
982 # this text as a variable instead of passing in the string itself, requiring
983 # the string to be escaped.
984 # Additionally, some platforms do not need any special parameters.
985 if [ -n "$RPATH_ORIGIN" -a "$CMK_MACOSX" != "1" -a "$CMK_COMPILER" != "msvc" ]; then
986   OPTS_LD="$OPTS_LD '-Wl,-rpath,\$ORIGIN'"
987 fi
988
989 PROCESSED_MODULES=""
990
991 if [ "$WERROR" = "1" ]
992 then
993     OPTS="$OPTS $CMK_WARNINGS_ARE_ERRORS"
994 fi
995
996 # If the user has asked for the latest language standards (C11 or CPP11)
997 if [ "$USE_NEW_STD" = "1" ]
998 then
999     # and if configure confirmed that the underlying compiler knows abt C11, enable it
1000     if [ "$CMK_COMPILER_KNOWS_C11" = "1" ]
1001     then
1002         OPTS_CC="$OPTS $CMK_ENABLE_C11"
1003     fi
1004 fi
1005
1006 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
1007 then
1008     USE_OPENMP="yes"
1009     TLSGLOBALS="1"
1010
1011     if [ ! -x "$CMK_ROSE_OMP_TOOL" ]
1012     then
1013         Abort "The environment variable CMK_ROSE_OMP_TOOL must contain the path to a built binary of the ROSE OpenMP variable privatization tool"
1014     fi
1015 fi
1016
1017 if [ "$USE_OPENMP" = "yes" -o "$CMK_OMP" = "1" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]
1018 then
1019     if [ "$CMK_HAS_OPENMP" != "1" ]
1020     then
1021       echo "Error: OpenMP is unavailable!"
1022       exit 1
1023     fi
1024     [ -n "$VERBOSE" ] && echo OpenMP support enabled
1025     OPTS_CC="$OPTS_CC $CMK_C_OPENMP"
1026     OPTS_CXX="$OPTS_CXX $CMK_C_OPENMP"
1027     OPTS_F90="$OPTS_F90 $CMK_F_OPENMP"
1028     OPTS_LD="$OPTS_LD $CMK_LD_OPENMP"
1029 else
1030     [ -n "$VERBOSE" ] && echo OpenMP support not enabled
1031 fi
1032
1033 if [ "$TLSGLOBALS" = "1" ]
1034 then
1035     TLSGLOBALS_OPTS='-ftls-model=initial-exec'
1036     [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" = '1' ] && TLSGLOBALS_OPTS="$TLSGLOBALS_OPTS -mno-tls-direct-seg-refs"
1037     OPTS_CC="$OPTS_CC $TLSGLOBALS_OPTS"
1038     OPTS_CXX="$OPTS_CXX $TLSGLOBALS_OPTS"
1039     OPTS_F90="$OPTS_F90 $TLSGLOBALS_OPTS"
1040 fi
1041
1042 if [ "$AMPI_FUNCPTR_SHIM" = '1' ]
1043 then
1044     OPTS_CC="$OPTS_CC -DAMPI_USE_FUNCPTR"
1045     OPTS_CXX="$OPTS_CXX -DAMPI_USE_FUNCPTR"
1046 fi
1047
1048 # Look up and add the dependencies for module $1
1049 findModuleDep() {
1050         M=$1
1051         notInList $M $PROCESSED_MODULES || return
1052         PROCESSED_MODULES="$PROCESSED_MODULES $M"
1053         #PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
1054         PRE_LIBRARIES=`AddList -lmodule$M $PRE_LIBRARIES`
1055 # HACK: add modules to both ends of library list, to avoid
1056 #  undefined symbol CkRegisterMainModule when it's in a module file.
1057         POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
1058         if [ "$M" = "PythonCCS" ]
1059             then
1060             LINK_PYTHON=1
1061         fi
1062
1063         dep=""
1064 # fixme: should search everything in the -L library paths:
1065         for dir in `echo . $CHARMLIB`
1066         do
1067                 d="$dir/libmodule$M.dep"
1068                 [ -r "$d" ] && dep=$d
1069         done
1070         if [ -r "$dep" ]
1071         then
1072                 # Add the module dependencies in this file
1073                 # Debugf "Adding module" $M "dependencies from" $dep
1074                 deps=`cat $dep`
1075                 Debugf "Module" $M "adds dependencies:" $deps
1076                 processArgs $deps
1077         fi
1078 }
1079
1080 # Repeat the module-dependency search until we find no
1081 #  new modules:
1082 START_MODULES=""
1083 while [ "$START_MODULES" != "$MODULES" ]
1084 do
1085         Debugf "----------- Module dependency search ------------"
1086         START_MODULES="$MODULES"
1087         for m in $MODULES
1088         do
1089                 findModuleDep $m
1090         done
1091 done
1092
1093 Debugf "----------- Module dependency search complete ------------"
1094
1095
1096
1097 ##############################################################################
1098 #
1099 # Load machine-specific configuration data, then handle overrides to it.
1100 #
1101 ##############################################################################
1102
1103
1104 if [ x"$CMK_NO_BUILD_SHARED" = "xfalse" ]
1105 then
1106         BUILD_SHARE="1"
1107 fi
1108
1109 if [ "$BUILD_SHARE" = "1" ]
1110 then
1111         USE_PIC="1"
1112 fi
1113
1114 if [ "$USE_PIC" = "1" ]
1115 then
1116        OPTS_CC="$OPTS_CC $CMK_PIC"
1117        OPTS_CXX="$OPTS_CXX $CMK_PIC"
1118        OPTS_F90="$OPTS_F90 $CMK_PIC"
1119        OPTS_LD="$OPTS_LD $CMK_PIC"
1120 fi
1121
1122 if [ "$USE_PIE" = "1" ]
1123 then
1124        OPTS_CC="$OPTS_CC $CMK_PIE"
1125        OPTS_CXX="$OPTS_CXX $CMK_PIE"
1126        OPTS_F90="$OPTS_F90 $CMK_PIE"
1127        OPTS_LD="$OPTS_LD $CMK_PIE"
1128 fi
1129
1130 if [ "$BUILD_SHARE" = "1" ]
1131 then
1132         # ignore BUILD_SHARE if the target is not .a or .so
1133         case "$OBJECT" in
1134         *.a|*.so|*.so.*|*.sl|*.dylib)
1135                 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO"
1136                 [ -n "$CHARMLIBSO" ] && OPTS_LD="$OPTS_LD -L$CHARMLIBSO"
1137                 ;;
1138         *)      
1139                 BUILD_SHARE="0"
1140                 ;;
1141         esac
1142 fi
1143
1144 if [ -n "$OVERRIDE_CC" ]
1145 then
1146     CMK_CC="$OVERRIDE_CC"
1147 fi
1148 Debug "set 2"
1149 if [ -n "$OVERRIDE_CXX" ]
1150 then
1151     CMK_CXX="$OVERRIDE_CXX"
1152 fi
1153
1154 if [ -n "$OVERRIDE_F90" ]
1155 then
1156     CMK_CF90="$OVERRIDE_F90"
1157 fi
1158
1159 if [ -n "$OVERRIDE_LD" ]
1160 then
1161     CMK_LD="$OVERRIDE_LD"
1162 fi
1163
1164 if [ -n "$OVERRIDE_LDXX" ]
1165 then
1166     CMK_LDXX="$OVERRIDE_LDXX"
1167 fi
1168
1169 if [ -n "$USE_RELIABLE_CC" ]
1170 then
1171         CMK_CC="$CMK_CC_RELIABLE"
1172 fi
1173
1174 if [ -n "$USE_FASTEST_CC" ]
1175 then
1176     CMK_CC="$CMK_CC_FASTEST"
1177 fi
1178
1179 if [ -n "$USE_F77" ]
1180 then
1181     CMK_CF90=$CMK_CF77
1182     CMK_CF90_FIXED=$CMK_CF77
1183     CMK_F90LIBS=$CMK_F77LIBS
1184 fi
1185
1186 if [ -n "$CMK_F90_MODINC" ]
1187 then
1188     CMK_CF90_MODINC="$CMK_F90_MODINC"
1189 else
1190     CMK_CF90_MODINC="-M"
1191 fi
1192
1193 if [ -n "$F90_MODDIR" ]
1194 then
1195     for dir in $F90_MODDIR
1196     do
1197       OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
1198     done
1199 fi
1200
1201 if [ -n "$CMK_F90_USE_MODDIR" ]
1202 then
1203     CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC $CHARMINC $CMK_SYSINC"
1204 fi
1205
1206 if [ -n "$SEQUENTIAL" ]
1207 then
1208     CMK_CC="$CMK_SEQ_CC"
1209     CMK_LD="$CMK_SEQ_LD"
1210     CMK_CXX="$CMK_SEQ_CXX"
1211     CMK_CF90="$CMK_SEQ_F90 " 
1212     CMK_LDXX="$CMK_SEQ_LDXX" 
1213     CMK_AR="$CMK_SEQ_AR"
1214     CMK_RANLIB="$CMK_SEQ_RANLIB"
1215
1216     CMK_CC_FLAGS="$CMK_SEQ_CC_FLAGS -DCMK_SEQUENTIAL=1"
1217     CMK_LD_FLAGS="$CMK_SEQ_LD_FLAGS"
1218     CMK_CXX_FLAGS="$CMK_SEQ_CXX_FLAGS -DCMK_SEQUENTIAL=1"
1219     CMK_LDXX_FLAGS="$CMK_SEQ_LDXX_FLAGS"
1220 fi
1221
1222 if [ -n "$NATIVE" ]
1223 then
1224     CMK_CC="$CMK_NATIVE_CC " 
1225     CMK_LD="$CMK_NATIVE_LD" 
1226     CMK_CXX="$CMK_NATIVE_CXX " 
1227     CMK_LDXX="$CMK_NATIVE_LDXX" 
1228
1229     CMK_CC_FLAGS="$CMK_NATIVE_CC_FLAGS"
1230     CMK_LD_FLAGS="$CMK_NATIVE_LD_FLAGS"
1231     CMK_CXX_FLAGS="$CMK_NATIVE_CXX_FLAGS"
1232     CMK_LDXX_FLAGS="$CMK_NATIVE_LDXX_FLAGS"
1233 fi
1234
1235 if [ -n "$PREPROCESS" ]
1236 then
1237     CMK_CF90=$CMK_FPP
1238 fi
1239
1240 if [ -n "$PURIFY" ]
1241 then
1242     CMK_LD="purify $CMK_LD"
1243     CMK_LDXX="purify $CMK_LDXX"
1244 fi
1245
1246 Debug "set 4"
1247 if [ "$OPTIMIZE_MODE" = "true" ]
1248 then
1249     OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
1250     OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
1251     OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
1252     OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
1253 fi
1254
1255 # Pick up per-architecture production mode settings
1256 if [ "$PRODUCTION_MODE" = "true" ]
1257 then
1258     OPTS_CC="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_CC"
1259     OPTS_CXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_CXX"
1260     OPTS_F90="$CMK_PRODUCTION $CMK_F90_PRODUCTION $OPTS_F90"
1261     OPTS_LD="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_LD"
1262 fi
1263
1264 if [ -n "$XI_INTERNAL" ]
1265 then
1266     CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
1267 fi
1268
1269 if [ "$GENDEPENDS" = "yes" ]
1270 then
1271     CMK_XIOPTS="$CMK_XIOPTS -M"
1272 fi
1273
1274 if [ "$COUNTTOKENS" = "yes" ]
1275 then
1276     CMK_XIOPTS="$CMK_XIOPTS -count-tokens"
1277 fi
1278
1279 if test "$CMK_WITH_TAU" = "true"
1280 then
1281   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1282   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1283   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1284   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS` 
1285   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1286   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1287   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1288
1289   rm -f _make.tau.tmp
1290 fi
1291
1292 #Add generic options to the compiler- and linker-options
1293 OPTS_CC="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CC"
1294 OPTS_CXX="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CXX"
1295 OPTS_F90="$OPTS $OPTS_F90"
1296 OPTS_LD="$OPTS $OPTS_LD"
1297
1298 # There's really no analog for this in the Bourne shell: 
1299 #  -------- C Shell ------> onintr failure
1300 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
1301
1302 ##############################################################################
1303 #
1304 # Check for valid choice of LANGUAGE
1305 #
1306 ##############################################################################
1307 Debug "Checking language..."
1308
1309 [ -z "$LANGUAGE" -a -n "$SEQUENTIAL" ] && LANGUAGE='c++'
1310 [ -z "$PARADIGM" -a -n "$LANGUAGE" ] && PARADIGM="$LANGUAGE"
1311 [ -z "$PARADIGM" ] && PARADIGM="charm++"
1312
1313 case "$LANGUAGE" in
1314 "c"|"C"|"c++"|"C++")
1315         [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
1316         ;;
1317 esac
1318
1319 # update charm to bgcharm
1320 [ "$PARADIGM" = "charm++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgcharm++"
1321 [ "$PARADIGM" = "converse++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgconverse++"
1322
1323 [ "$PARADIGM" = "bgcharm++" ] && TRACEMODE=`AddList $TRACEMODE bluegene`
1324
1325 if [ $USE_F77_LIBRARIES = "1" ]
1326 then
1327         POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1328 fi
1329
1330 if [ $USE_F90_LIBRARIES = "1" ]
1331 then
1332
1333         if [ ! -r $CHARMLIB/libconv-utilf.a ]
1334         then
1335                 Abort "Error: Fortran support library $CHARMLIB/libconv-utilf.a missing. Is your Fortran compiler working?"
1336         fi
1337
1338         POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1339 fi
1340
1341 # GEN-CPM options
1342 if [ "$CMK_COMPILER" = "bgclang" ]
1343 then
1344   OPTS_CC_GENCPM="-x c "  # -x c is only applied for the preprocessing of the GEN-CPM files on BG/Q
1345 fi
1346
1347 OPTS_CC_GENCPM="$OPTS_CC $OPTS_CC_GENCPM"
1348
1349 ############ Determine the language and libraries ##########
1350
1351 # Parse out the real languages
1352 case "$PARADIGM" in
1353 "charm++f")
1354         PARADIGM="charm++"
1355         USE_F90_LIBRARIES="1"
1356         ;;
1357 "f90charm")
1358         PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm -lckf"
1359         POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1360         ;;
1361 "bluegene"|"bigsim")
1362         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs"
1363         ;;
1364 "ckbluegene")
1365         POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1366         ;;
1367 "bgcharm++")
1368         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs -lconv-bluegene-stub"
1369         ;;
1370 "bgconverse++")
1371         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bigsim -lconv-bigsim-logs"
1372         ;;
1373 esac
1374
1375 # DMK - ACCEL SUPPORT - If this is a cell build, add the spe code object to POST_LIBRARIES
1376 if [ $CMK_CELL -eq 1 ]
1377 then
1378
1379   if [ "$PARADIGM" = "converse++" ]
1380   then
1381     # Include a "do nothing" register_accel_spe_funcs() function
1382     POST_LIBRARIES="$POST_LIBRARIES -lnoAccelStub"
1383   fi
1384
1385   if [ "$PARADIGM" = "charm++" ]
1386   then
1387
1388     if [ $SPU_USE_CPP -eq 1 ]
1389     then
1390         SPU_COMPILER=$CMK_SPU_CXX
1391         SPU_LINKER=$CMK_SPU_LDXX
1392     else
1393         SPU_COMPILER=$CMK_SPU_CC
1394         SPU_LINKER=$CMK_SPU_LD
1395     fi
1396
1397     # Include the spe object file for linking into main executable
1398     POST_LIBRARIES="$POST_LIBRARIES main__funcLookup__.genSPECode.ppe.o"
1399
1400   fi
1401 fi
1402
1403 if [ "$AMPIMAIN" != "" ]
1404 then
1405         OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1406 fi
1407
1408 if [ -n "$AMPI" ]
1409 then
1410   CMK_SYSINC="-I$CHARMINC/ampi $CMK_SYSINC"
1411 fi
1412
1413 if [ "$TLSGLOBALS" = "1" ]
1414 then
1415     if [ "$CMK_GDIR" = "uth" ]
1416     then
1417       echo "Error: -tlsglobals is not supported with the uth machine layer."
1418       exit 1
1419     fi
1420     if [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" != '1' ] && [ "$CMK_COMPILER" != 'clang' -o "$CMK_MACOSX" != '1' ]
1421     then
1422       echo "Warning: -tlsglobals may not work with compilers that do not recognize -mno-tls-direct-seg-refs."
1423     fi
1424     if [ "$CMK_HAS_ELF_H" != '1' -a "$CMK_MACOSX" != '1' ]
1425     then
1426       echo "Warning: -tlsglobals requires elf.h"
1427     fi
1428 fi
1429
1430 if [ "$SWAPGLOBALS" = "1" ]
1431 then
1432         if [ "$CMK_HAS_ELF_H" != "1" ]
1433         then
1434                 echo "Error: -swapglobals requires elf.h"
1435                 exit 1
1436         fi
1437
1438         LD_VERSION_TEXT=`$CMK_LD -Wl,--version,-v 2>/dev/null`
1439         if ! `printf "$LD_VERSION_TEXT" | grep -q 'GNU ld'`
1440         then
1441                 echo "Warning: -swapglobals may not work with linkers other than GNU ld."
1442         else
1443                 LD_VERSION=`printf "$LD_VERSION_TEXT" | grep -Eo 'GNU ld (\([^)]*\) )?(version )?[-0-9._a-zA-Z]+' | awk '{print $NF}'`
1444                 LD_VERSION_MAJOR=`printf $LD_VERSION | cut -d. -f1`
1445                 LD_VERSION_MINOR=`printf $LD_VERSION | cut -d. -f2 | cut -d- -f1`
1446                 if [ "$LD_VERSION_MAJOR" -gt 2 ] || [ "$LD_VERSION_MAJOR" -eq 2 -a "$LD_VERSION_MINOR" -gt 23 ]
1447                 then
1448                         echo "Warning: -swapglobals may not work with GNU ld >= 2.24."
1449                         echo "For some versions, an experimental patch is available:"
1450                         echo 'https://charm.cs.illinois.edu/gerrit/gitweb?p=libbfd-patches.git;a=tree;f=swapglobals'
1451                 fi
1452         fi
1453
1454         if [ "$CMK_SMP" = "1" ]
1455         then
1456                 echo "Error: -swapglobals is not supported on SMP builds of Charm++/AMPI"
1457                 exit 1
1458         else
1459                 swapo="$CHARMLIB/libglobal-swap.a"
1460                 if [ ! -r "$swapo" -o ! -s "$swapo" ]
1461                 then
1462                         echo "Error: global-swapping library $swapo missing--"
1463                         echo "  Is -swapglobals supported on this machine?"
1464                         exit 1
1465                 else
1466                         MIDDLE_LIBS="-lglobal-swap $MIDDLE_LIBS"
1467                 fi
1468         fi
1469 fi
1470 if [ "$SWAPGLOBALS" = "2" ]
1471 then
1472         echo "-copyglobals option is no longer supported by Charm++/AMPI"
1473         exit 1
1474 fi
1475
1476
1477 # dummy main module
1478 if [ "$MPI_INTEROPERATE" != "" -a "$NO_MAIN_MODULE" = "" ]
1479 then
1480         POST_LIBRARIES="-lmpi-mainmodule $POST_LIBRARIES"
1481 fi
1482
1483 ##############################################################################
1484 #
1485 # Some quick consistency checks in preparation for full link-step
1486 #
1487 # Check for valid choice of TRACEMODE
1488 # Check for valid choice of BALANCE
1489 # Check for compatibility among BALANCE and TRACEMODE
1490 #
1491 ##############################################################################
1492
1493 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1494
1495 # Check for valid choice of TRACEMODE
1496
1497 if [ x"$TRACEMODE" != x ]
1498 then
1499 for trace in $TRACEMODE; do
1500     case "$PARADIGM" in
1501         "converse"|"converse++"|"bgconverse++"|"bigsim"|"bluegene")
1502             if [ "$trace" != "counter" ]; then
1503                 Warning "Tracemode $trace isn't supported in Converse-level programs; Dropping it"
1504                 TRACEMODE=`DropList $trace $TRACEMODE`
1505                 continue
1506             fi
1507             ;;
1508         *)
1509             ;;
1510     esac
1511
1512     TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1513 done
1514
1515 fi
1516
1517 if test x$PARADIGM = x"bgcharm++"
1518 then
1519     BALANCE=bluegene
1520 fi
1521
1522 Debug "Finished with TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1523
1524 BAL_OBJ="-lldb-$BALANCE -lconv-ldb"
1525
1526 # Check for valid choice of MEMORY
1527
1528 # Set the default expansions of unprefixed variants
1529 case "$MEMORY" in
1530   'verbose'|'paranoid'|'leak'|'isomalloc')
1531     MEMORY="os-$MEMORY"
1532     ;;
1533   charmdebug*)
1534     MEMORY="gnu-$MEMORY"
1535     ;;
1536 esac
1537
1538 # Isomalloc does not work on BGQ or Windows:
1539 if [ "$CMK_BLUEGENEQ" = "1" -o "$CMK_COMPILER" = "msvc" ] && [ "$MEMORY" = "${MEMORY%isomalloc}isomalloc" ]
1540 then
1541   Abort "Error: Isomalloc is not supported on BlueGene/Q or Windows."
1542 fi
1543
1544 MEM_OBJ="-lmemory-${MEMORY}"
1545
1546 # For memory wrapping around the OS allocator, need to add also the wrapper object
1547 case $MEMORY in
1548   os-*)
1549      MEM_OBJ=$MEM_OBJ" -lmemory-os-wrapper"
1550   ;;
1551 esac
1552
1553 # Check for valid choice of THREAD
1554
1555 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1556 then
1557   THREAD=$CMK_LD_SHARED_THREAD
1558 fi
1559 if [ "$TLSGLOBALS"  = "1" ]
1560 then
1561   THREAD=${THREAD%-tls}-tls
1562 fi
1563
1564 THREAD_OBJ="-lthreads-${THREAD}"
1565
1566
1567 # Module name
1568
1569 modInitName="moduleinit$$"
1570 modInitSrc="$modInitName.C"
1571 modInitObj="$modInitName.o"
1572
1573
1574 ##############################################################################
1575 #
1576 # Final link step variables
1577 #
1578 ##############################################################################
1579
1580 MAKE_LDXX="0"
1581 MAKE_LD="0"
1582
1583 CORE_LIBS="-lconv-core -ltmgr -lconv-util -lconv-partition $TRACE_OBJ $CMK_HWLOC_LIBS"
1584
1585 # get TAU stub makefile variables
1586 if test "$CMK_WITH_TAU" = "true"
1587 then
1588   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1589   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1590   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1591   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1592   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1593   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1594   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1595
1596   rm -f _make.tau.tmp
1597 fi
1598 # done getting TAU variables
1599
1600 if [ "$BUILD_SHARE" = "0" ]
1601 then
1602        MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1603 fi
1604
1605 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1606
1607 case "$PARADIGM" in
1608 "f90charm")
1609         MAKE_LDXX="1"
1610         MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1611         if [ -z "$NO_MAIN" ]
1612         then
1613                 MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1614                 F90_MAIN="1"
1615         fi
1616         if [ "$TAU_TRACE_MPI" = "1" ]
1617         then
1618                 TAU_LIBS="$TAU_MPI_FLIBS $TAU_LIBS"
1619         else
1620                 TAU_LIBS="$TAU_LIBS"
1621         fi
1622         ;;
1623 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1624         MAKE_LDXX="1"
1625         MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1626         if [ -z "$NO_MAIN" ]
1627         then
1628                 if [ -n "$AMPIF" ]
1629                 then
1630                         MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1631                         F90_MAIN="1"
1632                 elif [ -z "$AMPIMAIN" ]
1633                 then
1634                         MIDDLE_LIBS="-lckmain $MIDDLE_LIBS"
1635                 fi
1636         fi
1637         if [ "$TAU_TRACE_MPI" = "1" ]
1638         then
1639                 TAU_LIBS="$TAU_MPI_LIBS $TAU_LIBS"
1640         else
1641                 TAU_LIBS="$TAU_LIBS"
1642         fi
1643         ;;
1644 "converse"|"converse++"|"bgconverse++"|"bluegene"|"bigsim")
1645         MAKE_LDXX="1"
1646         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-machine $CORE_LIBS -ltrace-converse "
1647         ;;
1648 "c"|"C"|"c++"|"C++"|"f90"|"f77")
1649   ;;
1650 *)
1651         Abort "Unrecognized choice of language $LANGUAGE / paradigm $PARADIGM"
1652         ;;
1653 esac
1654
1655 if [ "$BUILD_SHARE" = "0" ]
1656 then
1657         MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1658 fi
1659
1660 if [ "$CHARM_SHARED" = "1" ]
1661 then
1662   [ -z "$CHARMLIBSO" ] &&  Abort "Charm++ lib_so directory not found!"
1663   # build user executable/shared lib linking with charm .so
1664   OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1665   LANG_LIBS="-L$CHARMLIBSO"
1666 else
1667   LANG_LIBS="-L$CHARMLIB"
1668 fi
1669
1670 if [ -z "$STANDALONE" ]
1671 then
1672   ALL_LIBS="$LANG_LIBS $PRE_LIBRARIES $MIDDLE_LIBS $BAL_OBJ $CMK_LIBS $POST_LIBRARIES"
1673   case "$PARADIGM" in
1674   "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1675     ALL_LIBS="$ALL_LIBS -lmoduleNDMeshStreamer -lmodulecompletion"
1676     ;;
1677   esac
1678 else
1679   ALL_LIBS="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
1680 fi
1681
1682 if [ -n "$LINK_WHOLE_ARCHIVE" ]
1683 then
1684   ALL_LIBS="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $ALL_LIBS $LDXX_WHOLE_ARCHIVE_POST $CMK_SYSLIBS"
1685 else
1686   ALL_LIBS="$ALL_LIBS $CMK_SYSLIBS"
1687 fi
1688
1689 if [ "$BUILD_SHARE" = "0" ]
1690 then
1691   ALL_LIBS="$ALL_LIBS $CHARMLIB/conv-static.o"
1692 fi
1693
1694 if [ -n "$LINK_CXX_STL" ]
1695 then
1696   ALL_LIBS="$ALL_LIBS -lstdc++"
1697 fi
1698
1699 if [ "$TRACE_WITH_TAU" = 1 ]
1700 then
1701         echo "Linking with the TAU libraries: $TAU_LIBS"
1702         ALL_LIBS="$ALL_LIBS $TAU_LIBS"
1703 fi
1704 Debugf "All libraries are: $ALL_LIBS"
1705
1706 # preserve this variable in its state here for use later
1707 CHARM_ALL_LIBS="$ALL_LIBS"
1708 if [ "$BUILD_SHARE" = "1" -o -n "$SKIP_MODULEINIT" ]
1709 then
1710   ALL_LIBS="$OBJECTFILES $ALL_LIBS"
1711 else
1712   ALL_LIBS="$OBJECTFILES $modInitObj $ALL_LIBS"
1713 fi
1714
1715 if [ -n "$F90_MAIN" ]
1716 then
1717 # for_main needs to be placed at beginning
1718         CMK_LD_FLAGS="$CMK_F90MAINLIBS $CMK_LD_FLAGS"
1719         CMK_LDXX_FLAGS="$CMK_F90MAINLIBS $CMK_LDXX_FLAGS"
1720 fi
1721
1722 if [ -n "$F90_MAIN" -o "$USE_F90_LIBRARIES" = '1' ]
1723 then
1724   if [ "$CMK_CAN_LINK_FORTRAN" != '1' ]
1725   then
1726     echo "Error: Configure testing was unable to link a Fortran program."
1727     exit 1
1728   fi
1729 fi
1730
1731 ########################################################################
1732 #
1733 # Finalize command parameters
1734 #
1735 ########################################################################
1736
1737 CHARM_CPP_C="$CMK_CPP_C"
1738 CHARM_CC="$CMK_CC"
1739 CHARM_CXX="$CMK_CXX"
1740 CHARM_LD="$CMK_LD"
1741 CHARM_LDXX="$CMK_LDXX"
1742
1743 CHARM_CPP_C_FLAGS="$CMK_CPP_C_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CC_GENCPM $OPTS_CPP"
1744 CHARM_CC_FLAGS="$CMK_CC_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC"
1745 CHARM_CXX_FLAGS="$CMK_CXX_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX"
1746 CHARM_LD_FLAGS="$CMK_LD_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1747 CHARM_LDXX_FLAGS="$CMK_LDXX_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1748
1749
1750 ########################################################################
1751 #
1752 # Print command building blocks and quit, if specified
1753 #
1754 ########################################################################
1755
1756 if [ -n "$PRINT_BUILDING_BLOCKS" ]
1757 then
1758         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
1759         do
1760                 eval "echo $i=\\'\${$i}\\'"
1761         done
1762         exit 0
1763 fi
1764
1765
1766 ########################################################################
1767 #
1768 # We've parsed and verified the command-line parameters.
1769 # Now we prepare routines to clean up and exit.
1770 # None of these routines ever returns-- they all just exit.
1771 #
1772 ########################################################################
1773
1774
1775 Copyobj() {
1776         if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ] 
1777         then
1778                 [ -d $COPYTO ] && COPYTO="$COPYTO/"
1779                 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
1780                         Warning "Appending $PROG_EXT to object file name"
1781                         OBJECT="$OBJECT$PROG_EXT"
1782                 fi
1783                 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO 
1784                 Do $CP $OBJECT $COPYTO
1785         fi
1786         test -n "$COPY_EXIT" && Success
1787 }
1788
1789 Copymod() {
1790         for COPY in `echo $MODCOPIES`
1791         do
1792                 if [ "a$COPY" != "a$OBJECT" ] 
1793                 then
1794                         [ -d $COPY ] && COPY="$COPY/"
1795                         if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
1796                           OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
1797                         fi
1798                         if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
1799                           Warning "Appending .$CMK_MOD_EXT to object file name"
1800                           OBJECT="$OBJECT.$CMK_MOD_EXT"
1801                         fi
1802                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
1803                         Do $CP $OBJECT $COPY
1804                 fi
1805         done
1806         Success
1807 }
1808
1809 Success() {
1810         End 0
1811 }
1812
1813
1814 ##############################################################################
1815 #
1816 # Preprocess the GEN-CPM files
1817 #
1818 ##############################################################################
1819
1820 Debug "Preprocessing GEN-CPM files"
1821
1822 for FILE in `echo $GENCPM`
1823 do
1824 # This used to be "$FILE:r", which strips the extention
1825         BASE=`stripExtention $FILE`
1826         MYTMP=`basename $FILE`".TMP"
1827         DELETE="$DELETE $MYTMP.c $MYTMP.i"
1828         DoNoErrCheck $RM $BASE.cpm.h $MYTMP.c
1829         Do touch $BASE.cpm.h
1830         Do $LN -f -s $FILE $MYTMP.c
1831         Do $CHARM_CPP_C $CHARM_CPP_C_FLAGS $MYTMP.c > $MYTMP.i
1832         Do $CHARMBIN/conv-cpm $MYTMP.i $BASE.cpm.h
1833 done
1834
1835 ##############################################################################
1836 #
1837 # Compile all specified files
1838 #
1839 # All temporary files named *.TMP.* for easy cleanup.
1840 #
1841 ##############################################################################
1842
1843 Debug "About to compile..."
1844
1845 for FILE in $FILES
1846 do
1847         BASE=`stripExtention \`basename $FILE\``
1848         MYTMP=`basename $FILE`".TMP"
1849         FILE_EXT=`getExtention $FILE`
1850         BASEO="$BASE.o"
1851         DESTO="-o $BASEO"
1852
1853         # in case of: charmc -o object.o -c foo.c,
1854         # avoid foo.c => remove foo.o => foo.o => object.o,
1855         # instead generate object.o directly.
1856         # remove and generate foo.o may be dangerous in parallel make 
1857         # for example in the case of compiling several objs from one 
1858         # same c file such as memory.C.
1859         if [ $numFiles = 1 -a -n "$OBJECT" ]
1860         then
1861                 OBJ_EXT=`getExtention $OBJECT`
1862                 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
1863                 then
1864                         BASEO=$OBJECT
1865                         DESTO="-o $OBJECT"
1866                 fi
1867         fi
1868
1869 #       if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".co" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1870 #       then
1871         case "$FILE_EXT" in
1872         .c|.s|.S|.C|.cc|.cxx|.cpp|.c++|.cu|.f|.F|.f90|.F90|.fpp|.FPP|.f77|.F77)
1873                 [ $VERBOSE ] && echo "Compiling $FILE"
1874                 DoNoErrCheck $RM $BASEO `stripExtention $BASEO`.f.o
1875         esac
1876 #       fi
1877         if [ ! -z "$SKIPLINK" ] 
1878         then
1879                 DESTO=""
1880         fi
1881
1882         if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
1883         then
1884             case "$FILE" in
1885                 *.c)
1886                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE
1887                     FILE="rose_$FILE"
1888                     ;;
1889                 *.C|*.cc|*.cxx|*.cpp|*.c++)
1890                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE
1891                     FILE="rose_$FILE"
1892                     ;;
1893                 *.f|*.F|*.f77|*.F77)
1894                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE
1895                     FILE="rose_$FILE"
1896                     ;;
1897                 *.f90|*.F90|*.fpp|*.FPP)
1898                     test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1899                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE
1900                     FILE="rose_$FILE"
1901                     ;;
1902             esac
1903         fi
1904
1905         case "$FILE" in
1906         *.ci)
1907                 XIOPTS=$CMK_XIOPTS
1908                 test "$PARADIGM" = "f90charm" && XIOPTS="$XIOPTS -f90"
1909                 if [ "$PREPROCESS_CI" = "yes" ]
1910                 then
1911                   Do $CMK_CPP_CHARM $OPTS_CPP $FILE | Do $CHARMBIN/charmxi $XIOPTS -orig-file $FILE
1912                 else
1913                   Do $CHARMBIN/charmxi $XIOPTS $FILE
1914                 fi
1915                 ;;
1916         *.c|*.s|*.S)
1917                 Do $CHARM_CC $CHARM_CC_FLAGS -c $FILE $DESTO
1918                 if [ "$Do_res" -ne 0 ]
1919                 then
1920                     touch $BASEO
1921                 fi
1922                 ;;
1923         *.C|*.cc|*.cxx|*.cpp|*.c++|*.cu)
1924                 if [ -n "$NATIVE" ]
1925                 then
1926                     Do $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP -c $FILE $DESTO
1927                 else
1928                     Do $CHARM_CXX $CHARM_CXX_FLAGS -c $FILE $DESTO
1929                 fi
1930                 if [ "$Do_res" -ne 0 ]
1931                 then
1932                     touch $BASEO
1933                 fi
1934                 ;;
1935         *.f|*.F|*.f77|*.F77)
1936                 test -z "$CMK_CF90_FIXED" && Abort "No F90 compiler (CMK_CF90_FIXED) defined"
1937                 Do $CMK_CF90_FIXED -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1938                 if [ "$Do_res" -ne 0 ]
1939                 then
1940                     touch $BASEO
1941                 fi
1942                 ;;
1943         *.f90|*.F90|*.fpp|*.FPP)
1944                 test -z "$CMK_CF90" && Abort "No F90 compiler (CMK_CF90) defined"
1945                 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1946                 Do $CMK_CF90 -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE $DESTO
1947                 if [ "$Do_res" -ne 0 ]
1948                 then
1949                     touch $BASEO
1950                 fi
1951                 ;;
1952         *.fc|*.FC)
1953                 Abort "I'm not yet smart enough to compile $FILE"
1954                 ;;
1955         *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
1956                 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1957                 ;;
1958         *.M|*.mod)
1959                 OBJECT="$BASE"
1960                 Copymod
1961                 Success
1962                 ;;
1963         *)
1964                 Abort "file with unrecognized extension $FILE"
1965         esac
1966 done
1967
1968 ##############################################################################
1969 #
1970 #                        POSSIBLY, SKIP LINK-STEP
1971 #
1972 # 1. No $OBJECT may be specified at all --- its just a compilation.
1973 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1974 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1975 # 4. Language may be sequential.  Do a quick and easy linkage.
1976 #
1977 #               in any of these cases, the full link step is skipped.
1978 #
1979 ##############################################################################
1980
1981 MakeSO() {
1982         Debugf "Running ldro..."
1983         DoNoErrCheck $RM $OBJECT
1984         # convert to absolute path if required
1985         if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1986         then
1987         dir=`dirname $OBJECT`
1988         fname=`basename $OBJECT`
1989         dir=`cd $dir; pwd`
1990         OBJECT=$dir/$fname
1991         fi
1992         if test "$MAKE_LD" = '1'
1993         then
1994           soTool="$CMK_LD $CMK_LD_FLAGS"
1995         else
1996           soTool="$CMK_LDXX $CMK_LDXX_FLAGS"
1997         fi
1998         if [ -n "$STANDALONE" ]
1999         then
2000           soLibs="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
2001         else
2002           soLibs="$PRE_LIBRARIES $POST_LIBRARIES"
2003           [ "$CMK_MACOSX" = "1" ] && OPTS_LD="$OPTS_LD -Wl,-install_name,$CHARMLIBSO/$fname"
2004         fi
2005         if [ -n "$LINK_WHOLE_ARCHIVE" ]
2006         then
2007           soLibs="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $soLibs $LDXX_WHOLE_ARCHIVE_POST"
2008         fi
2009         soLibs="$soLibs $CMK_SYSLIBS"
2010         if [ -n "$LINK_CXX_STL" ]
2011         then
2012           soLibs="$soLibs -lstdc++"
2013         fi
2014         soCmd="$soTool $CMK_LIBDIR -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $soLibs $CMK_LD_SHARED_LIBS"
2015         DoNoErrCheck $soCmd
2016         Do_res=$?
2017         if [ $Do_res -ne 0 ]
2018         then
2019             if [ -n "$NOABORT" ]
2020             then
2021                 touch $OBJECT
2022             else
2023                 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2024                 echo "!!  Failed to compile Charm++ shared library. You can disable shared   !!"
2025                 echo "!!  lib compilation by providing --no-build-shared build option like:  !!"
2026                 echo "!!     ./build charm++ netlrts-linux --no-build-shared -O              !!"
2027                 echo "!!  or reexecute this charmc command with the --no-build-shared option !!"
2028                 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2029                 Abort "Command $soCmd returned error code $Do_res"
2030             fi
2031         fi
2032         Copyobj
2033 }
2034
2035 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ] 
2036 then
2037 # We have no target object, or are playing preprocessor tricks-- just end
2038         Debugf "No target object-- finished"
2039         Success
2040 fi
2041
2042 Debug "About to link..."
2043
2044 if [ "$INPUT_GIVEN" != "1" ]
2045 then
2046     Abort "Trying to link, but no object files or library archives were specified"
2047 fi
2048
2049 # if interoperate dont create the library now, wait to collect all info
2050 if [ "$MPI_INTEROPERATE" = "" ]
2051 then
2052 case "$OBJECT" in
2053 *.o)
2054         Debugf "Converting $FILES to $OBJECTFILES"
2055         nFiles=`echo $FILES | wc -w`
2056         nObj=`echo $OBJECTFILES | wc -w`
2057 # One source file, one .o: just move the .o
2058         if [ $OBJECT != $OBJECTFILES ]
2059         then
2060                 Debugf "Moving .o to destination"
2061                 DoNoErrCheck $RM $OBJECT
2062                 Do $MV $OBJECTFILES $OBJECT
2063         fi
2064         Copyobj
2065         ;;
2066 *.so|*.so.*|*.sl|*.dylib)
2067 # Make shared library
2068         # If building shared is not supported and this object is not standalone, exit.
2069         if [ "$BUILD_SHARE" = 0 -a -z "$STANDALONE" ]
2070         then
2071                 Warning "Warning: building shared library is not supported, recompile charm++ with '--build-shared'."
2072                 End 1
2073         elif [ "$CHARM_SHARED" = "0" ]
2074         then
2075                 MakeSO
2076         fi
2077         ;;
2078 *.a)
2079 # Make regular (.a, non-shared) library
2080         # in case building charm so, build .so under lib_so as well # Gengbin
2081         if [ "$BUILD_SHARE" = "1" ]
2082         then
2083           COPY_EXIT=""
2084           OBJECT_SAVE=$OBJECT
2085           COPYTO_SAVE=$COPYTO
2086           if [ -z "$COPYTO" ]
2087           then
2088             DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
2089             OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
2090           else
2091             COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
2092             DESTDIR=$COPYTO
2093           fi
2094           OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
2095           [ -f $DESTDIR/.charmso ] && MakeSO
2096           COPYTO=$COPYTO_SAVE
2097           OBJECT=$OBJECT_SAVE
2098           COPY_EXIT="true"
2099         fi
2100         # build normal .a
2101         DoNoErrCheck $RM $OBJECT
2102         Do $CMK_AR $OBJECT $OBJECTFILES
2103         Do $CMK_RANLIB $OBJECT
2104         Copyobj
2105         ;;
2106 esac
2107 fi
2108 # If the above case returns, we're not creating a .o or .a file,
2109 # so linking is needed.
2110
2111 if [ $CMK_CELL -eq 1 ]
2112 then
2113
2114   if [ "$PARADIGM" = "charm++" ]
2115   then
2116
2117     # Make the spe object file to be included
2118     Do $SPU_COMPILER -c -I$CHARMINC $CMK_SYSINC -o main__funcLookup__.genSPECode.o main__funcLookup__.genSPECode.c -DCMK_CELL_SPE=1
2119     Do $SPU_LINKER -L$CHARMLIB -o main__funcLookup__.genSPECode main__funcLookup__.genSPECode.o $CMK_SPERT_LIBS $SPU_EXTRA_LIBS
2120     Do $CMK_PPU_EMBEDSPU spert_main main__funcLookup__.genSPECode main__funcLookup__.genSPECode.ppe.o
2121
2122   fi
2123 fi
2124
2125 # check if we're linking a sequential object
2126 case "$LANGUAGE" in
2127 "c"|"C"|"f90"|"f77")
2128         if [ -n "$NATIVE" ]
2129         then
2130           Do $CMK_NATIVE_LD $CMK_NATIVE_LD_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2131                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2132         else
2133           Do $CMK_SEQ_LD $CMK_SEQ_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2134                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2135         fi
2136         Copyobj
2137         ;;
2138 "c++"|"C++")
2139         if [ -n "$NATIVE" ]
2140         then
2141           Do $CMK_NATIVE_LDXX $CMK_NATIVE_LDXX_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2142                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2143         else
2144           Do $CMK_SEQ_LDXX $CMK_SEQ_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2145                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2146         fi
2147         Copyobj
2148         ;;
2149 esac
2150
2151
2152 ##############################################################################
2153 #
2154 # Confirm that TRACEMODE, BALANCE, MEMORY, THREAD exist
2155 #
2156 ##############################################################################
2157
2158 # [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed.  Is Charm++ built properly?"
2159
2160 if [ x"$TRACEMODE" != x ]
2161 then
2162 for trace in $TRACEMODE; do
2163     [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
2164 done
2165 fi
2166
2167 BAL_EXT=`getExtention $BALANCE`
2168 if [ -z "$BAL_EXT" ]; then
2169   # Balance has no extension-- is a library reference
2170   if [ -f "${CHARMLIB}/libldb-$BALANCE.a" ]; then
2171     BAL_OBJ_FILE="${CHARMLIB}/libldb-$BALANCE.a"
2172   else
2173     BAL_OBJ_FILE="${CHARMLIBSO}/libldb-$BALANCE.so"
2174   fi
2175 else
2176   # Balance has some extension-- must be a .o or .a file
2177   BAL_OBJ_FILE="$BALANCE"
2178 fi
2179
2180 if [ ! -r "$BAL_OBJ_FILE" ]
2181 then
2182         if [ "$BALANCE" = "$BAL_OBJ_FILE" ]
2183         then
2184                 Abort "Could not find load balancer object $BAL_OBJ_FILE"
2185         else
2186                 (cd $CHARMLIB ; ls -al libldb-*)
2187                 Abort "Unknown load balancer $BALANCE / $BAL_OBJ_FILE"
2188         fi
2189 fi
2190
2191 if [ -f "${CHARMLIB}/libmemory-${MEMORY}.a" ]; then
2192   MEM_OBJ_FILE="${CHARMLIB}/libmemory-${MEMORY}.a"
2193 else
2194   MEM_OBJ_FILE="${CHARMLIBSO}/libmemory-${MEMORY}.so"
2195 fi
2196
2197 if [ ! -r $MEM_OBJ_FILE -o ! -s $MEM_OBJ_FILE ]
2198 then
2199   (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2200   Abort "charmc : No such memory mode $MEMORY"
2201 fi
2202
2203 if [ -f "${CHARMLIB}/libthreads-${THREAD}.a" ]; then
2204   THREAD_OBJ_FILE="${CHARMLIB}/libthreads-${THREAD}.a"
2205 else
2206   THREAD_OBJ_FILE="${CHARMLIBSO}/libthreads-${THREAD}.so"
2207 fi
2208
2209 if [ ! -r $THREAD_OBJ_FILE -o ! -s $THREAD_OBJ_FILE ]
2210 then
2211   (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2212   Abort "charmc : No such thread mode $THREAD"
2213 fi
2214
2215
2216 ################# Build the module initialization function ##################
2217
2218 if [ -z "$SKIP_MODULEINIT" ]
2219 then
2220     DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2221
2222     for module in $MODULES; do
2223         echo "extern void _register$module(void);" >> $modInitSrc
2224     done
2225     for trace in $TRACEMODE; do
2226         if test $trace = "summary"
2227         then
2228           echo "  extern void _registerTraceSummary();" >> $modInitSrc
2229         elif test $trace = "projections"
2230         then
2231           echo "  extern void _registerTraceProjections();" >> $modInitSrc
2232         elif test $trace = "simple"
2233         then
2234           echo "  extern void _registerTraceSimple();" >> $modInitSrc
2235         elif test $trace = "Tau"
2236         then
2237           echo "  extern void _registerTraceTau();" >> $modInitSrc
2238         elif test $trace = "utilization"
2239         then
2240           echo "  extern void _registerTraceUtilization();" >> $modInitSrc
2241         elif test $trace = "controlPoints"
2242         then
2243           echo "  extern void _registerTraceControlPoints();" >> $modInitSrc
2244         elif test $trace = "perfReport"
2245         then
2246           Do $CP $CHARMBIN/fuzzytree.txt fuzzytree.txt
2247           Do $CP $CHARMBIN/tree.txt tree.txt
2248           echo "  extern void _registerTraceAutoPerf();" >> $modInitSrc
2249
2250         elif test $trace = "all"
2251         then
2252           echo "  extern void _registerTraceProjections();" >> $modInitSrc
2253           echo "  extern void _registerTraceControlPoints();" >> $modInitSrc
2254           echo "  extern void _registerTraceSummary();" >> $modInitSrc
2255         fi
2256     done
2257     if test -n "$BALANCER"
2258     then
2259         echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
2260     fi
2261     echo "void _registerExternalModules(char **argv) { (void)argv;" >> $modInitSrc
2262     for module in $MODULES; do
2263         [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
2264         echo "  _register$module();" >> $modInitSrc
2265     done
2266     for trace in $TRACEMODE; do
2267         if test $trace = "summary"
2268         then
2269           echo "  _registerTraceSummary();" >> $modInitSrc
2270         elif test $trace = "projections"
2271         then
2272           echo "  _registerTraceProjections();" >> $modInitSrc
2273         elif test $trace = "Tau"
2274         then
2275           TRACE_WITH_TAU=1
2276           echo "  _registerTraceTau();" >> $modInitSrc
2277         elif test $trace = "simple"
2278         then
2279           echo "  _registerTraceSimple();" >> $modInitSrc
2280         elif test $trace = "utilization"
2281         then
2282           echo "  _registerTraceUtilization();" >>  $modInitSrc
2283         elif test $trace = "controlPoints"
2284         then
2285           echo "  _registerTraceControlPoints();" >> $modInitSrc
2286         elif test $trace = "perfReport"
2287         then
2288           echo "  _registerTraceAutoPerf();" >> $modInitSrc
2289         elif test $trace = "all"
2290         then
2291           echo "  _registerTraceProjections();" >> $modInitSrc
2292           echo "  _registerTraceControlPoints();" >> $modInitSrc
2293           echo "  _registerTraceSummary();" >> $modInitSrc
2294         fi
2295     done
2296     if test -n "$BALANCER"
2297     then
2298         [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
2299         for deflb in $BALANCER
2300         do
2301           echo "  LBDefaultCreate(\"$deflb\");" >> $modInitSrc
2302         done
2303     fi
2304     echo "}" >> $modInitSrc
2305
2306     # creating projections
2307     echo "void _createTraces(char **argv) { (void)argv;" >> $modInitSrc
2308     for trace in $TRACEMODE; do
2309         [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
2310         echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
2311         echo "_createTrace$trace(argv);" >> $modInitSrc
2312     done
2313     echo "}" >> $modInitSrc
2314
2315     Do $CHARM_CXX $CHARM_CXX_FLAGS -c $modInitSrc -o $modInitObj
2316 fi
2317
2318 ###############################################################################
2319 #
2320 #                               Finally, LINK
2321 #
2322 ###############################################################################
2323
2324 Debug "About to perform final link..."
2325
2326 #currently only support creation of .a
2327 if [ "$MPI_INTEROPERATE" != "" ]
2328 then
2329 case "$OBJECT" in
2330 *.a)
2331         # in case building charm so, build .so under lib_so as well # Gengbin
2332         DoNoErrCheck $RM $OBJECT
2333         if [ -z "$SKIP_MODULEINIT" ]
2334         then
2335                 echo "$CMK_AR $OBJECT $OBJECTFILES $modInitObj"
2336                 Do $CMK_AR $OBJECT $OBJECTFILES $modInitObj
2337         fi
2338         Do $CMK_RANLIB $OBJECT
2339         echo "export CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\"" > ./charm_all_libs.sh
2340         echo "CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\""
2341         Copyobj
2342         ;;
2343 *.so|*.so.*|*.sl|*.dylib)
2344         echo "Warning: building shared library failed; for interoperation build
2345         static library."
2346         End 0
2347         ;;
2348 esac
2349 fi
2350
2351 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
2352 then
2353   # build an application .so linking with charm .so
2354   OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
2355   Debugf "Running ldro..."
2356   DoNoErrCheck $RM $OBJECT
2357   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2358   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2359   Copyobj
2360 else
2361 # Make a regular executable: call the appropriate linker
2362   [ "$MAKE_LDXX" = "1" ] && Do $CHARM_LDXX $CHARM_LDXX_FLAGS -o $OBJECT
2363   [ "$MAKE_LD" = "1" ] && Do $CHARM_LD $CHARM_LD_FLAGS -o $OBJECT
2364 fi
2365
2366 ########################################################################
2367 #
2368 # Copy conv-host to user directory if it is present in installation.
2369 #
2370 ########################################################################
2371
2372 if test "$COPY_CHARMRUN" = "true"
2373 then
2374   targ=charmrun$CMK_POST_EXE
2375   [ ! -x $CHARMBIN/$targ -a -n "$CMK_POST_EXE" ] && targ=charmrun
2376   convhost=conv-host$CMK_POST_EXE
2377
2378   if [ -x $CHARMBIN/$targ ]
2379   then
2380         DoNoErrCheck $RM $targ
2381         DoNoErrCheck $CP $CHARMBIN/$targ $targ 2> /dev/null
2382   fi
2383 fi
2384
2385 [ -z "$SKIP_MODULEINIT" -a -z "$SAVE" ] && DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2386
2387 Copyobj