Adding Communication aware refinement based strategy called CommAwareRefineLB. Made...
[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 LANGUAGE=""
25 BALANCE="rand"
26 TRACEMODE=""
27 TRACE_OBJ=
28 MEMORY="default"
29 THREAD="default"
30 VERBOSE=""
31 DEBUG_SCRIPT=""
32 SAVE=""
33 PURIFY=""
34 SKIPLINK=""
35 OVERRIDE_CC=""
36 OVERRIDE_CXX=""
37 OVERRIDE_F90=""
38 OVERRIDE_LD=""
39 OVERRIDE_LDXX=""
40 #Generic options, passed to everything
41 OPTS=""
42 #Specific options
43 #charm internal flag, only pass to c and cxx, not f90
44 OPTS_CPP_INTERNAL="-D__CHARMC__=1 "
45 OPTS_CPP=
46 OPTS_LDRO="" 
47 OPTS_CC=""
48 OPTS_CXX="" 
49 OPTS_F90=""
50 OPTS_LD=""  
51 OPTS_LDXX=""
52 OPTS_PIC=""
53 USE_PIC="0"
54
55 CHARMDEBUG=""
56 LINK_PYTHON=""
57 OBJECT=""
58 EXPLICIT_OBJECT="no"
59 EXPLICIT_COMPILATION="no"
60 POST_LANGUAGE=""
61 POST_LIBRARIES=""    
62 PRE_LIBRARIES=""  
63 USE_F90_LIBRARIES="0"  
64 USE_F77_LIBRARIES="0"  
65 F90_MODDIR=
66 AMPIMAIN=""
67 COPYTO=""        
68 MODCOPIES=""        
69 MODULES=""
70 BALANCER=""
71 FILES=""       
72 OBJECTFILES=""  
73 DELETE=""    
74 MAINOBJ=""   
75 GENCPM=""
76 OPTIMIZE_MODE=""
77 PRODUCTION_MODE=""
78 USE_RELIABLE_CC=""
79 USE_FASTEST_CC=""
80 PROG_EXT=""
81 GENDEPENDS="no"
82
83 COPY_CHARMRUN=true
84 USE_BUILD_OPTIONS=0
85
86 COPY_EXIT="true"
87 CHARM_SHARED="0"
88 BUILD_SHARE="0"
89 SWAPGLOBALS="0"
90 TLSGLOBALS="0"
91
92 TAU_MAKEFILE=Make.tau
93 TAU_TRACE_MPI=1
94
95 CMK_CELL=0
96 SPU_USE_CPP=0
97 SPU_EXTRA_LIBS=""
98
99 MPI_INTEROPERATE=""
100
101 ####################################################################
102 #
103 #  Utility routines used below
104 #
105 ###################################################################
106
107 # PrintUsage: prints a helpful command-line usage message and quits
108 # Args: any additional messages
109 printUsage() {
110     printVersion
111     echo 
112     echo "Usage: charmc [ flags ] <files>"
113     echo
114     echo "  flags:"
115     echo "        -o <target> -g -O"
116     echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
117     echo "        -machine <mach> -seq -host -language <lang> "
118     echo "        -balance <mode> -tracemode <mode> -memory <mode>"
119     echo "        -modules <comma-separated list of C++ modules>"
120     echo "        -verbose -save -purify -cp <dest> -gen-cpm <package>"
121     echo "        -use-reliable-cc -use-fastest-cc"
122     echo "        -cc <new cc> -c++ <new CC>  -ld <new ld> -ld++ <new LD>"
123     echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
124     echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
125     echo "        -fmoddir <f90mod path>"
126     echo "        -pg <opt> -build-shared -charm-shared -no-trace-mpi"
127     echo
128     echo "  Cell specific flags:"
129     echo "        -spu-cpp -spu-lib <libname>"
130     echo
131     echo "  Charmc compiles C, C++, f77, f90, Converse, Converse++, Charm, "
132     echo "and Charm++ programs.  The flags generally match those of cc or f77."
133     echo "Version 5.0, Parallel Programming Lab, UIUC, 1999"
134     echo $*
135     exit 1
136 }
137
138 # End blows away the temporary files (unless SAVE is true) and exits
139 # Args: <exit code>
140 End() {
141     if [ -z "$SAVE" ]
142         then
143         for FILE in `echo $FILES`
144         do
145             #BASE=`stripExtention $FILE`
146             TMP=`basename $FILE`".TMP"
147             $RM $TMP.P.C $TMP.cpp $TMP.space $TMP.xlat $TMP.o
148             $RM $TMP.c $TMP.c.0.h $TMP.c.1.h $TMP.c.2.h
149             $RM $TMP.i $TMP.$CMK_CPP_SUFFIX
150         done
151         $RM core $DELETE
152         if test -n "$modInitObj"
153         then
154             [ -n "$VERBOSE" ] && echo $RM $modInitSrc $modInitObj
155             DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
156         fi
157     fi
158     exit $1
159 }
160
161 # Write this error message to stderr
162 # ("1>&2" redirects the echo output to stderr).
163 Warning() {
164         echo "$@" 1>&2
165 }
166
167 # This procedure prints an error message and exits.
168 # Args: written to stderr
169 Abort() {
170         Warning "Fatal Error by charmc in directory "`pwd`
171         Warning "   $@"
172         Warning "charmc exiting..."
173         End 1
174 }
175
176
177 # Instead of an ECHO_CMD variable, I define a procedure Do,
178 # which (possibly) echos, runs, and tests the errors of the given command.
179 # Args: executed as given
180 DoNoErrCheck() {
181         [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
182         eval "$@"
183 }
184
185 Do() {
186         DoNoErrCheck "$@"
187         Do_res=$?
188 # The UNIX result code better be zero, or we die
189         [ $Do_res -eq 0 ] || Abort "Command $@ returned error code $Do_res"
190 }
191
192 # This procedure removes the extention (the ".c" in "./main.c") from
193 # its first argument, and prints the result. Unlike the builtin command
194 # basename, it keeps the directory path.
195 # Args: <name to strip>
196 stripExtention() {
197         se_base=`basename $1`
198 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
199         se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
200         se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
201         echo $se_ret
202 }
203
204 # GetExtention returns the extention on the given file name
205 # or "" if none.  (e.g. "./bob/snack.c" returns ".c")
206 # Args: <name to find extention of>
207 getExtention() {
208 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
209 #        se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
210 #       echo $se_ret
211         se_ret=`echo $1 | sed -e 's/.*\././'`
212         if test "$se_ret" = $1
213         then
214           echo ""
215         else
216           echo $se_ret
217         fi
218 }
219
220 Debugf() {
221         [ -n "$VERBOSE" ] && echo "charmc>" $@
222 }
223
224 Debug() {
225     if [ -n "$DEBUG_SCRIPT" ]
226     then
227         echo 
228         echo "------- Charmc Debugging info: $* -------"
229         echo "CHARMBIN=$CHARMBIN"
230         echo "CHARMINC=$CHARMINC"
231         echo "CHARMLIB=$CHARMLIB"
232         echo "FILES=$FILES"
233         echo "DELETE=$DELETE"
234         echo "OBJECT=$OBJECT"
235         echo "LANGUAGE=$LANGUAGE"
236 #       echo "Working directory="`pwd`
237     fi
238 }
239
240 # Return success if $1 is not in any of the other arguments
241 notInList() {
242         search=$1
243         shift
244         while [ $# -gt 0 ]
245         do
246                 if [ "$search" = "$1" ]
247                 then
248                         # It's already in there-- fail
249                         return 1
250                 fi
251                 shift
252         done
253         # It's missing--succeed
254         return 0
255 }
256
257 # Add arguments to our modules list, avoiding duplicates
258 AddModules() {
259     for M in "$@"
260     do
261       notInList $M $MODULES && MODULES="$MODULES $M"
262     done
263 }
264
265 # Add this word to this list, avoiding duplicates
266 AddList() {
267     ret=""
268     for M in "$@"
269     do
270       notInList $M $ret && ret="$ret $M"
271     done
272     echo $ret
273 }
274
275 # Append the last word to this list, avoiding duplicates
276 # the difference to previous AddList() is that when duplication happens,
277 # only keep the last one, instead of keeping the first one as in AddList()
278 # this helps to solve the multiple -lfoo in the link command. 
279 AppendList() {
280         ret=""
281         search=$1
282         shift
283         while [ $# -gt 0 ] 
284         do
285                 if notInList $search $@
286                 then
287                         ret="$ret $search"
288                 fi
289                 search=$1
290                 shift
291         done
292         echo $ret $search
293 }
294
295
296 # TEMP_BASE is appended with this script's process ID (PID),
297 # so multiple charmcs can run in parallel without overwriting
298 # each other's temporary files.
299 TEMP_BASE="/tmp/charmc_tmp.$$"
300
301 # Try to find CHARMBIN by looking in directory where charmc is
302 findCharmBin() {
303 if [ -z "$CHARMBIN" ]
304 then
305         SCRIPT=$1
306         CHARMBIN=`dirname $SCRIPT`
307 #       CHARMBIN=`cd $CHARMBIN; pwd`
308 # NOTE: this script no longer tries to follow soft links
309 # to find the "original" charmc-- if this is bad, 
310 # translate these lines to Bourne shell from C shell:
311 # -------------------- Begin C Shell ------------------------->
312 #    if ($SCRIPT:h != $SCRIPT:t) then
313 #        cd $SCRIPT:h
314 #        set SCRIPT=$SCRIPT:t
315 #    else
316 #        foreach dir ($path)
317 #            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
318 #                cd $dir
319 #                break
320 #            endif
321 #        end
322 #    endif
323 #    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
324 #        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
325 #        if ($SCRIPT:h != $SCRIPT:t) then
326 #            cd $SCRIPT:h
327 #            set SCRIPT=$SCRIPT:t
328 #        endif
329 #    end
330 #    set CHARMBIN=`pwd`
331 # <------------------ End C Shell -----------------------------
332 fi
333 }
334
335 printVersion()
336 {
337         findCharmBin $0
338         version=`cat $CHARMBIN/../include/VERSION`
339         echo Charm++ Version $version
340 }
341
342
343 ##############################################################################
344 #
345 # The following section identifies CHARMBIN, the charm binary-directory.
346 #
347 ##############################################################################
348
349 ORIGDIR=`pwd`
350
351 # Try to find CHARMBIN by looking in directory where charmc is
352
353 findCharmBin $0
354
355 UNAME=`uname -s`
356 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
357 if [ "$FIRST_THREE" = "CYG" -o "$UNAME" = "Interix" ]
358 then
359 # Running on a windows system-- append .exe to file names
360         PROG_EXT=".exe"
361 fi
362
363 CHARMLIB="$CHARMBIN/../lib"
364 CHARMINC="$CHARMBIN/../include"
365 CHARMLIBSO=
366 if test -d "$CHARMBIN/../lib_so" 
367 then
368   CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
369   #getting absolute path is harder than thought because of symbolic links and ..
370   #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
371   #csh is ok too if it exists 
372   test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
373   test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
374   test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
375 fi
376
377 ##############################################################################
378 #
379 # Parse the arguments
380 #
381 # Don't do any analysis in here, just the parsing.
382 #
383 ##############################################################################
384
385 [ $# -eq 0 ] && printUsage "Error: No arguments given."
386
387 processArgs() {
388 while [ ! $# -eq 0 ]
389 do
390         arg="$1"
391         shift
392
393         case "$arg" in
394         "-V")
395                 printVersion
396                 exit 0
397                 ;;
398
399         "-machine")
400                 MACHTYPE="$1"
401                 shift
402                 ;;
403
404         "-seq")
405                 SEQUENTIAL=true
406                 ;;
407
408         "-host")
409                 NATIVE=true
410                 ;;
411
412         "-language")
413                 # Parse out some fake languages (that are actually modules)
414                 case "$1" in
415                 "ampi") AddModules tcharmmain ampi ;;
416                 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ;;
417                 "armci") AddModules tcharmmain armci ;;
418                 "armcif") AddModules tcharmmain armci ; USE_F90_LIBRARIES="1" ;;
419                 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
420                 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
421                 "ParFUM_TOPS") AddModules tcharmmain ParFUM ParFUM_TOPS ; AMPIMAIN="ParFUMmain";;
422     "ParFUM") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain";;
423     "ParFUMf") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain"; USE_F90_LIBRARIES="1" ;;
424                 "mblock") AddModules tcharmmain mblock ;;
425                 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
426                 *) 
427                         LANGUAGE="$1"
428                         POST_LANGUAGE=1
429                         ;;
430                 esac
431                 shift
432                 ;;
433
434         "-debug")
435                 # Requested support from charmdebug: add some modules and libraries
436                 CHARMDEBUG=1
437                 MEMORY="charmdebug"
438                 ;;
439
440         "-module"|"-modules")
441                 AddModules `echo $1 | sed -e 's/,/ /g'`
442                 shift
443                 ;;
444
445         "-balancer")
446 #                test -n "$BALANCER" && Abort "More than one -balancer specified!"
447                 BALANCER="$BALANCER $1"
448                 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
449                 AddModules $mod
450                 shift
451                 ;;
452
453         "-balance")
454                 BALANCE="$1"
455                 shift
456                 ;;
457
458         "-queue")
459                 Warning "Warning: -queue currently being ignored."
460                 shift
461                 ;;
462
463         "-memory")
464                 MEMORY="$1"
465                 shift
466                 ;;
467
468         "-thread")
469                 THREAD="$1"
470                 shift
471                 ;;
472
473         "-tracemode")
474                 TRACEMODE_NEW=`AddList $TRACEMODE $1`
475                 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
476                 then
477                         Warning "Warning: Duplicate tracemode $1 ignored"
478                 else
479                         TRACEMODE=$TRACEMODE_NEW
480                 fi
481                 shift
482                 ;;
483         "-no-trace-mpi")
484                 TAU_TRACE_MPI=0
485                 ;;
486         
487         "-swapglobal"|"-swapglobals")
488                 SWAPGLOBALS="1"
489                 USE_PIC="1"
490                 ;;
491
492         "-copyglobal"|"-copyglobals")
493                 SWAPGLOBALS="2"
494                 USE_PIC="1"
495                 ;;
496
497         "-tlsglobal"|"-tlsglobals")
498                 TLSGLOBALS="1"
499                 OPTS_CC="$OPTS_CC -mno-tls-direct-seg-refs"
500                 OPTS_CXX="$OPTS_CXX -mno-tls-direct-seg-refs"
501                 OPTS_F90="$OPTS_F90 -mno-tls-direct-seg-refs"
502                 OPTS_LD="$OPTS_LD -static -Wl,--allow-multiple-definition"
503                 OPTS_LDXX="$OPTS_LDXX -static -Wl,--allow-multiple-definition"
504                 ;;
505
506         "-verbose")
507                 echo "Verbose mode set"
508                 VERBOSE=true
509                 ;;
510
511         "-spu-cpp")
512                 SPU_USE_CPP=1
513                 ;;
514
515         "-spu-lib")
516                 SPU_EXTRA_LIBS="$SPU_EXTRA_LIBS -l$1"
517                 shift
518                 ;;
519
520         "-intrinsic")
521                 XI_INTERNAL=true
522                 ;;
523
524         "-debug-script")
525                 echo "Will give excessive charmc debugging output..."
526                 DEBUG_SCRIPT=true
527                 ;;
528
529         "-save")
530                 SAVE=true
531                 ;;
532
533         "-purify")
534                 PURIFY=true
535                 ;;
536
537         "-use-reliable-cc")
538                 USE_RELIABLE_CC=1
539                 ;;
540
541         "-use-fastest-cc")
542                 USE_FASTEST_CC=1
543                 ;;
544
545         "-cc")
546                 OVERRIDE_CC="$1"
547                 shift
548                 ;;
549
550         "-c++")
551                 OVERRIDE_CXX="$1"
552                 shift
553                 ;;
554
555         "-f90")
556                 OVERRIDE_F90="$1"
557                 shift
558                 ;;
559
560         "-ld")
561                 OVERRIDE_LD="$1"
562                 shift
563                 ;;
564
565         "-ld++")
566                 OVERRIDE_LDXX="$1"
567                 shift
568                 ;;
569
570         "-cpp-option")
571                 OPTS_CPP="$OPTS_CPP $1"
572                 shift
573                 ;;
574
575         "-ldro-option")
576                 OPTS_LDRO="$OPTS_LDRO $1"
577                 shift
578                 ;;
579
580         "-cc-option")
581                 OPTS_CC="$OPTS_CC $1"
582                 shift
583                 ;;
584
585         "-c++-option")
586                 OPTS_CXX="$OPTS_CXX $1"
587                 shift
588                 ;;
589
590         "-f90-option")
591                 OPTS_F90="$OPTS_F90 $1"
592                 shift
593                 ;;
594
595         "-ld-option")
596                 OPTS_LD="$OPTS_LD $1"
597                 shift
598                 ;;
599
600         "-ld++-option")
601                 OPTS_LDXX="$OPTS_LDXX $1"
602                 shift
603                 ;;
604
605         "-rpath")
606                 OPTS_LDXX="$OPTS_LDXX -rpath $1"
607                 shift
608                 ;;
609         
610         "-fortran"|"-flib"|"-flibs")
611                 USE_F90_LIBRARIES="1" 
612                 ;;
613         "-f77")
614                 USE_F77="1" 
615                 ;;
616         "-fortran77"|"-f77lib"|"-f77libs")
617                 USE_F77_LIBRARIES="1" 
618                 ;;
619         "-E")
620 # Run preprocessor only
621                 PREPROCESS="yes"
622                 SKIPLINK="yes"
623                 OPTS="$OPTS $arg"
624                 ;;
625         "-preprocess")
626 # Run preprocessor as an extra step, continue after preprocessing
627                 PREPROCESS="yes"
628                 ;;
629         "-P"|"-S")
630 # Run preprocessor/assembler only
631                 SKIPLINK="yes"
632                 OPTS="$OPTS $arg"
633                 ;;
634         "-M")
635                 SKIPLINK="yes"
636                 OPTS="$OPTS $arg"
637                 GENDEPENDS="yes"
638                 ;;
639         "-default-to-aout")
640                 if [ "$EXPLICIT_OBJECT $EXPLICIT_COMPILATION" = "no no" ]
641                 then
642                       OBJECT="a.out"
643                 fi
644                 ;;
645         "-c")
646                 if [ "$EXPLICIT_OBJECT" = "no" ]
647                 then
648                       OBJECT=""
649                 fi
650                 EXPLICIT_COMPILATION="yes"
651                 ;;
652
653         "-o")
654                 EXPLICIT_OBJECT="yes"
655                 OBJECT=$1
656                 shift
657                 ;;
658
659         "-cp")
660                 COPYTO="$1"
661                 shift
662                 ;;
663
664         "-cpmod")
665                 MODCOPIES="$1 $MODCOPIES"
666                 shift
667                 ;;
668
669         "-gen-cpm")
670                 GENCPM="$GENCPM $1"
671                 shift
672                 ;;
673
674         -I)
675                 OPTS_CPP="$OPTS_CPP -I$1"
676                 shift
677                 ;;
678
679         -D*|-I*)
680                 if echo "$arg" | grep ' '  > /dev/null 2>/dev/null 
681                 then
682                   OPTS_CPP="$OPTS_CPP "\"$arg\"
683                 else
684                   OPTS_CPP="$OPTS_CPP $arg"
685                 fi
686                 ;;
687
688         -Werror)
689                 WERROR="1"
690                 ;;
691
692         -Wno-error)
693                 WERROR="0"
694                 ;;
695
696         -LANG*)
697                 Warning "passing unrecognized option $arg to all compilers and linkers"
698                 OPTS="$OPTS $arg"
699                 ;;
700         -shared|-G)
701                 BUILD_SHARE="1"
702                 ;;
703         -L*|-shared|-G)
704                 OPTS_LD="$OPTS_LD $arg"
705                 ;;
706         -charm-shared|-cs)
707                 CHARM_SHARED="1"
708                 ;;
709         -build-shared)
710                 # used internally when building Charm++ to create lib_so
711                 BUILD_SHARE="1"
712                 ;;
713         -no-build-shared)
714                 # used internally not to build Charm++ lib_so
715                 BUILD_SHARE="0"
716                 ;;
717         "-optimize")
718                 OPTIMIZE_MODE=true
719                 ;;
720
721         "-no-optimize")
722                 OPTIMIZE_MODE=false
723                 ;;
724
725         "-production")
726                 PRODUCTION_MODE=true
727                 ;;
728         "-no-production")
729                 PRODUCTION_MODE=false
730                 ;;
731         
732         "-pg"|"-g"|-W*|-O*)
733                 OPTS="$OPTS $arg"
734                 ;;
735
736         "-fmoddir")
737                 F90_MODDIR="$F90_MODDIR $1"
738                 shift
739                 ;;
740
741         -l*|*.a)
742                 if [ -n "$POST_LANGUAGE" ]
743                 then
744                         POST_LIBRARIES=`AppendList $POST_LIBRARIES $arg`
745                 else
746                         PRE_LIBRARIES=`AppendList $PRE_LIBRARIES $arg`
747                 fi
748                 ;;
749
750         -s)
751                 OPTS_LD="$OPTS_LD   $arg"
752                 ;;
753         -no-charmrun)
754                 COPY_CHARMRUN=false
755                 ;;
756         -use-build-options)
757                 USE_BUILD_OPTIONS=1
758                 ;;
759         -h|--help)
760                 printUsage
761                 ;;
762         -f90main)
763                 F90_MAIN=1
764                 ;;
765         -nof90main)
766                 F90_MAIN=
767                 ;;
768         -mpi)
769                 MPI_INTEROPERATE="yes"
770                 ;;
771         -*|+*)
772 #               Warning "passing unrecognized option $arg to all compilers and linkers"
773                 OPTS="$OPTS  $arg"
774                 ;;
775         *.*)
776                 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
777                 FILES="$FILES $arg"
778                 ;;
779 # Default
780         *)
781 #               printUsage  "Error: Unrecognized argument $arg"
782 #               Warning "passing unrecognized option $arg to all compilers and linkers"
783                 OPTS="$OPTS  $arg"
784                 ;;
785         esac
786 done
787 }
788
789 trap 'End 1' 2
790
791 # Process original command-line arguments
792 eval processArgs "$@"
793
794
795 ##############################################################################
796 #
797 # Load module dependencies.
798 #
799 ##############################################################################
800
801 Debug "About to read machine config script"
802 Debug "Read config script, setting defaults..."
803
804 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
805 . $CHARMINC/conv-config.sh $CHARMINC
806
807 Debug "Setting vars..."
808
809 if [ "$USE_BUILD_OPTIONS" = "1" ]  
810 then
811         [ -n "$VERBOSE" ] && echo "Charmc applying build time options: $BUILDOPTS"
812         OPTS="$OPTS $BUILDOPTS"
813 fi
814
815 # If we are debugging, add "-g -O0" to the C/C++ flags
816 if [ -n "$CHARMDEBUG" ]; then
817        if [ -n "$CMK_BUILD_PYTHON" ]; then
818                 AddModules PythonCCS charmdebug_python
819                 POST_LIBRARIES=`AddList $POST_LIBRARIES -lpython${CMK_BUILD_PYTHON}`
820         fi
821         OPTS_CPP="$OPTS_CPP -O0 -g"
822 fi
823
824 if [ -z "$NATIVE" -a -n "$UGNI_CFLAGS" ]
825 then
826     linkopt=`env | grep  "HUGETLB[0-9]*[MKG]_POST_LINK_OPTS" 2> /dev/null`
827     test -z "$linkopt" && POST_LIBRARIES=`AddList $POST_LIBRARIES $CHARMLIB/cray_tlbhack.o`
828 fi
829
830 PROCESSED_MODULES=""
831
832 if [ "$WERROR" = "1" ]
833 then
834     OPTS="$OPTS $CMK_WARNINGS_ARE_ERRORS"
835 fi
836
837 # Look up and add the dependencies for module $1
838 findModuleDep() {
839         M=$1
840         notInList $M $PROCESSED_MODULES || return
841         PROCESSED_MODULES="$PROCESSED_MODULES $M"
842         PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
843 # HACK: add modules to both ends of library list, to avoid
844 #  undefined symbol CkRegisterMainModule when it's in a module file.
845         POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
846         if [ "$M" = "PythonCCS" ]
847             then
848             LINK_PYTHON=1
849         fi
850
851         dep=""
852 # fixme: should search everything in the -L library paths:
853         for dir in `echo . $CHARMLIB`
854         do
855                 d="$dir/libmodule$M.dep"
856                 [ -r "$d" ] && dep=$d
857         done
858         if [ -r "$dep" ]
859         then
860                 # Add the module dependencies in this file
861                 # Debugf "Adding module" $M "dependencies from" $dep
862                 deps=`cat $dep`
863                 Debugf "Module" $M "adds dependencies:" $deps
864                 processArgs $deps
865         fi
866 }
867
868 # Repeat the module-dependency search until we find no
869 #  new modules:
870 START_MODULES=""
871 while [ "$START_MODULES" != "$MODULES" ]
872 do
873         Debugf "----------- Module dependency search ------------"
874         START_MODULES="$MODULES"
875         for m in $MODULES
876         do
877                 findModuleDep $m
878         done
879 done
880
881 Debugf "----------- Module dependency search complete ------------"
882
883
884
885 ##############################################################################
886 #
887 # Load machine-specific configuration data, then handle overrides to it.
888 #
889 ##############################################################################
890
891
892 if [ x"$CMK_NO_BUILD_SHARED" = "xfalse" ]
893 then
894         BUILD_SHARE="1"
895 fi
896
897 if [ "$BUILD_SHARE" = "1" ]
898 then
899         if [ x"$CMK_NO_BUILD_SHARED" = "xtrue" -o -z "$CHARMLIBSO" ]
900         then
901                 BUILD_SHARE="0"
902         else
903                 USE_PIC="1"
904         fi
905 fi
906
907 OPTS_PIC="$CMK_PIC"
908 if [ "$USE_PIC" = "1" ]
909 then
910        OPTS_CC="$OPTS_CC $OPTS_PIC"
911        OPTS_CXX="$OPTS_CXX $OPTS_PIC"
912        OPTS_F90="$OPTS_F90 $OPTS_PIC"
913        OPTS_LD="$OPTS_LD $OPTS_PIC"
914 fi
915
916 if [ "$BUILD_SHARE" = "1" ]
917 then
918         # ignore BUILD_SHARE if the target is not .a or .so
919         case "$OBJECT" in
920         *.a|*.so|*.so.*|*.sl|*.dylib)
921                 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
922                 ;;
923         *)      
924                 BUILD_SHARE="0"
925                 ;;
926         esac
927 fi
928
929 if [ -n "$OVERRIDE_CC" ]
930 then
931     CMK_CC="$OVERRIDE_CC"
932 fi
933 Debug "set 2"
934 if [ -n "$OVERRIDE_CXX" ]
935 then
936     CMK_CXX="$OVERRIDE_CXX"
937 fi
938
939 if [ -n "$OVERRIDE_F90" ]
940 then
941     CMK_CF90="$OVERRIDE_F90"
942 fi
943
944 if [ -n "$OVERRIDE_LD" ]
945 then
946     CMK_LD="$OVERRIDE_LD"
947 fi
948
949 if [ -n "$OVERRIDE_LDXX" ]
950 then
951     CMK_LDXX="$OVERRIDE_LDXX"
952 fi
953
954 if [ -n "$USE_RELIABLE_CC" ]
955 then
956         CMK_CC="$CMK_CC_RELIABLE"
957 fi
958
959 if [ -n "$USE_FASTEST_CC" ]
960 then
961     CMK_CC="$CMK_CC_FASTEST"
962 fi
963
964 if [ -n "$USE_F77" ]
965 then
966     CMK_CF90=$CMK_CF77
967     CMK_CF90_FIXED=$CMK_CF77
968     CMK_F90LIBS=$CMK_F77LIBS
969 fi
970
971 if [ -n "$CMK_F90_MODINC" ]
972 then
973     CMK_CF90_MODINC="$CMK_F90_MODINC"
974 else
975     CMK_CF90_MODINC="-M"
976 fi
977
978 if [ -n "$F90_MODDIR" ]
979 then
980     for dir in $F90_MODDIR
981     do
982       OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
983     done
984 fi
985
986 if [ -n "$CMK_F90_USE_MODDIR" ]
987 then
988     CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC$CHARMINC "
989 fi
990
991 if [ -n "$SEQUENTIAL" ]
992 then
993     CMK_CC="$CMK_SEQ_CC -DCMK_SEQUENTIAL=1 "
994     CMK_LD="$CMK_SEQ_LD"
995     CMK_CXX="$CMK_SEQ_CXX -DCMK_SEQUENTIAL=1 " 
996     CMK_CF90="$CMK_SEQ_F90 " 
997     CMK_LDXX="$CMK_SEQ_LDXX" 
998     CMK_AR="$CMK_SEQ_AR"
999     CMK_RANLIB="$CMK_SEQ_RANLIB"
1000 fi
1001
1002 if [ -n "$NATIVE" ]
1003 then
1004     CMK_CC="$CMK_NATIVE_CC " 
1005     CMK_LD="$CMK_NATIVE_LD" 
1006     CMK_CXX="$CMK_NATIVE_CXX " 
1007     CMK_LDXX="$CMK_NATIVE_LDXX" 
1008 fi
1009
1010 if [ -n "$PREPROCESS" ]
1011 then
1012     CMK_CF90=$CMK_FPP
1013 fi
1014
1015 if [ -n "$PURIFY" ]
1016 then
1017     CMK_LD="purify $CMK_LD"
1018     CMK_LDXX="purify $CMK_LDXX"
1019 fi
1020
1021 Debug "set 4"
1022 if [ "$OPTIMIZE_MODE" = "true" ]
1023 then
1024     OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
1025     OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
1026     OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
1027     OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
1028     OPTS_LDXX="$CMK_CXX_OPTIMIZE $OPTS_LDXX"
1029 fi
1030
1031 # Pick up per-architecture production mode settings
1032 if [ "$PRODUCTION_MODE" = "true" ]
1033 then
1034     OPTS_CC="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_CC"
1035     OPTS_CXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_CXX"
1036     OPTS_F90="$CMK_PRODUCTION $CMK_F90_PRODUCTION $OPTS_F90"
1037     OPTS_LD="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_LD"
1038     OPTS_LDXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_LDXX"
1039 fi
1040
1041 if [ -n "$XI_INTERNAL" ]
1042 then
1043     CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
1044 fi
1045
1046 if [ "$GENDEPENDS" = "yes" ]
1047 then
1048     CMK_XIOPTS="$CMK_XIOPTS -M"
1049 fi
1050
1051 if test "$CMK_WITH_TAU" = "true"
1052 then
1053   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1054   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1055   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1056   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS` 
1057   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1058   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1059   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1060
1061   rm -f _make.tau.tmp
1062 fi
1063
1064 #Add generic options to the compiler- and linker-options
1065 OPTS_CC="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CC"
1066 OPTS_CXX="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CXX"
1067 OPTS_F90="$OPTS $OPTS_F90"
1068 OPTS_LD="$OPTS $OPTS_LD"
1069 # OPTS_LDXX gets OPTS from OPTS_LD
1070
1071 if [ -n "$F90_MAIN" ] 
1072 then
1073 # for_main needs to be placed at beginning
1074         CMK_LD="$CMK_LD $CMK_F90MAINLIBS"
1075         CMK_LDXX="$CMK_LDXX $CMK_F90MAINLIBS"
1076 fi
1077
1078 # There's really no analog for this in the Bourne shell: 
1079 #  -------- C Shell ------> onintr failure
1080 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
1081
1082 ##############################################################################
1083 #
1084 # Check for valid choice of LANGUAGE
1085 #
1086 ##############################################################################
1087 Debug "Checking language..."
1088
1089 if [ -z "$LANGUAGE" ]
1090 then
1091     LANGUAGE="charm++"
1092     [ -n "$SEQUENTIAL" ] && LANGUAGE=c
1093 fi
1094
1095 case "$LANGUAGE" in
1096 "c"|"C"|"c++"|"C++")
1097         [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
1098         ;;
1099 esac
1100
1101 # update charm to bgcharm
1102 if [ "$LANGUAGE" = "charm++" -a -n "$CMK_BIGSIM" ]
1103 then
1104         LANGUAGE="bgcharm++"
1105 fi
1106 if [ "$LANGUAGE" = "converse++" -a -n "$CMK_BIGSIM" ]
1107 then
1108         LANGUAGE="bgconverse++"
1109 fi
1110 if [ "$LANGUAGE" = "bgcharm++" ]
1111 then
1112         TRACEMODE=`AddList $TRACEMODE bluegene`
1113 fi
1114
1115 ########################################################################
1116 #
1117 # We've parsed and verified the command-line parameters.
1118 # Now we prepare routines to clean up and exit.
1119 # None of these routines ever returns-- they all just exit.
1120 #
1121 ########################################################################
1122
1123
1124 Copyobj() {
1125         if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ] 
1126         then
1127                 [ -d $COPYTO ] && COPYTO="$COPYTO/"
1128                 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
1129                         Warning "Appending $PROG_EXT to object file name"
1130                         OBJECT="$OBJECT$PROG_EXT"
1131                 fi
1132                 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO 
1133                 Do $CP $OBJECT $COPYTO
1134         fi
1135         test -n "$COPY_EXIT" && Success
1136 }
1137
1138 Copymod() {
1139         for COPY in `echo $MODCOPIES`
1140         do
1141                 if [ "a$COPY" != "a$OBJECT" ] 
1142                 then
1143                         [ -d $COPY ] && COPY="$COPY/"
1144                         if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
1145                           OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
1146                         fi
1147                         if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
1148                           Warning "Appending .$CMK_MOD_EXT to object file name"
1149                           OBJECT="$OBJECT.$CMK_MOD_EXT"
1150                         fi
1151                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
1152                         Do $CP $OBJECT $COPY
1153                 fi
1154         done
1155         Success
1156 }
1157
1158 Success() {
1159         End 0
1160 }
1161
1162
1163 ##############################################################################
1164 #
1165 # Preprocess the GEN-CPM files
1166 #
1167 ##############################################################################
1168
1169 Debug "Preprocessing GEN-CPM files"
1170
1171 for FILE in `echo $GENCPM`
1172 do
1173 # This used to be "$FILE:r", which strips the extention
1174         BASE=`stripExtention $FILE`
1175         TMP=`basename $FILE`".TMP"
1176         DELETE="$DELETE $TMP.c $TMP.i"
1177         DoNoErrCheck $RM $BASE.cpm.h $TMP.c
1178         Do touch $BASE.cpm.h
1179         Do $LN -f -s $FILE $TMP.c
1180         Do $CMK_CPP_C -I$CHARMINC $OPTS_CC $OPTS_CPP $TMP.c > $TMP.i
1181         Do $CHARMBIN/conv-cpm $TMP.i $BASE.cpm.h
1182 done
1183
1184 ##############################################################################
1185 #
1186 # Compile all specified files
1187 #
1188 # All temporary files named *.TMP.* for easy cleanup.
1189 #
1190 ##############################################################################
1191
1192 Debug "About to compile..."
1193
1194 numFiles=`echo $FILES | wc -w`
1195 for FILE in `echo $FILES`
1196 do
1197         BASE=`stripExtention \`basename $FILE\``
1198         TMP=`basename $FILE`".TMP"
1199         FILE_EXT=`getExtention $FILE`
1200         BASEO="$BASE.o"
1201         DESTO="-o $BASEO"
1202
1203         # in case of: charmc -o object.o -c foo.c,
1204         # avoid foo.c => remove foo.o => foo.o => object.o,
1205         # instead generate object.o directly.
1206         # remove and generate foo.o may be dangerous in parallel make 
1207         # for example in the case of compiling several objs from one 
1208         # same c file such as memory.c.
1209         if [ $numFiles = 1 -a -n "$OBJECT" ]
1210         then
1211                 OBJ_EXT=`getExtention $OBJECT`
1212                 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
1213                 then
1214                     BASEO=$OBJECT
1215                     DESTO="-o $OBJECT"
1216                 fi
1217         fi
1218
1219 #       if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".co" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1220 #       then
1221         case "$FILE_EXT" in
1222         .c|.s|.C|.cc|.cxx|.cpp|.c++|.cu|.f|.F|.f90|.F90)
1223                 [ $VERBOSE ] && echo "Compiling $FILE"
1224                 DoNoErrCheck $RM $BASEO $BASE.f.o
1225         esac
1226 #       fi
1227         if [ ! -z "$SKIPLINK" ] 
1228         then
1229                 DESTO=""
1230         fi
1231         NU_OBJ=""
1232         case "$FILE" in
1233         *.ci)
1234                 XIOPTS=$CMK_XIOPTS
1235                 test "$LANGUAGE" = "f90charm" && XIOPTS="$XIOPTS -f90"
1236                 if [ -n "$PREPROCESS" ]
1237                 then
1238                   Do $CMK_CPP_CHARM $OPTS_CPP $FILE | Do $CHARMBIN/charmxi $XIOPTS
1239                 else
1240                   Do $CHARMBIN/charmxi $XIOPTS $FILE
1241                 fi
1242                 ;;
1243         *.c|*.s)
1244                 Do $CMK_CC -I$CHARMINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE $DESTO
1245                 NU_OBJ=$BASEO
1246                 ;;
1247         bglmachine.C)
1248                 Do $CMK_GCXX -I$CHARMINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE $DESTO
1249                 NU_OBJ=$BASEO
1250                 ;;
1251         *.C|*.cc|*.cxx|*.cpp|*.c++|*.cu)
1252                 Do $CMK_CXX -I$CHARMINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE $DESTO
1253                 NU_OBJ=$BASEO
1254                 ;;
1255         *.f|*.F)
1256                 test -z "$CMK_CF90_FIXED" && Abort "No F90 compiler (CMK_CF90_FIXED) defined"
1257                 Do $CMK_CF90_FIXED -I$CHARMINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1258                 NU_OBJ=$BASEO
1259                 ;;
1260         *.f90|*.F90)
1261                 test -z "$CMK_CF90" && Abort "No F90 compiler (CMK_CF90) defined"
1262                 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1263                 Do $CMK_CF90 -I$CHARMINC $OPTS_CPP $OPTS_F90 $FILE $DESTO
1264                 NU_OBJ=$BASEO
1265                 ;;
1266         *.fc|*.FC)
1267                 Abort "I'm not yet smart enough to compile $FILE"
1268                 ;;
1269         *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
1270                 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1271                 OBJECTFILES="$OBJECTFILES $FILE"
1272                 ;;
1273         *.M|*.mod)
1274                 OBJECT="$BASE"
1275                 Copymod
1276                 Success
1277                 ;;
1278         *)
1279                 Abort "file with unrecognized extension $FILE"
1280         esac
1281 # Handle new object files
1282         if [ -n "$NU_OBJ" -a -n "$OBJECT" ] 
1283         then
1284                 if [ "$OBJECT" != "$BASEO" ]
1285                 then
1286                         DELETE="$DELETE $NU_OBJ"
1287                 fi
1288                 OBJECTFILES="$OBJECTFILES $NU_OBJ"
1289         fi
1290 done
1291
1292 ##############################################################################
1293 #
1294 #                        POSSIBLY, SKIP LINK-STEP
1295 #
1296 # 1. No $OBJECT may be specified at all --- its just a compilation.
1297 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1298 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1299 # 4. Language may be sequential.  Do a quick and easy linkage.
1300 #
1301 #               in any of these cases, the full link step is skipped.
1302 #
1303 ##############################################################################
1304
1305 MakeSO() {
1306         Debugf "Running ldro..."
1307         DoNoErrCheck $RM $OBJECT
1308         # convert to absolute path if required
1309         if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1310         then
1311         dir=`dirname $OBJECT`
1312         fname=`basename $OBJECT`
1313         dir=`cd $dir; pwd`
1314         OBJECT=$dir/$fname
1315         fi
1316         Warning "Warning: creating $OBJECT "
1317         if test "$MAKE_LDXX" = "1"
1318         then
1319           soCmd="$CMK_LDXX -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $PRE_LIBRARIES $POST_LIBRARIES $CMK_LD_SHARED_LIBS"
1320         else
1321           soCmd="$CMK_LD -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $PRE_LIBRARIES $POST_LIBRARIES $CMK_LD_SHARED_LIBS"
1322         fi
1323         DoNoErrCheck $soCmd
1324         Do_res=$?
1325         if [ $Do_res -ne 0 ] 
1326         then
1327         echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1328         echo "!!  Failed to compile Charm++ shared library. You can disable shared  !!"
1329         echo "!!  lib compilation by providing --no-build-shared build option like: !!"
1330         echo "!!     ./build charm++ net-linux --no-build-shared -O                 !!"
1331         echo "!!  or reexecute this charmc command with --no-build-shared compile option        !!"
1332         echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1333         Abort "Command $soCmd returned error code $Do_res"
1334         fi
1335         Copyobj
1336 }
1337
1338 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ] 
1339 then
1340 # We have no target object, or are playing preprocessor tricks-- just end
1341         Debugf "No target object-- finished"
1342         Success
1343 fi
1344
1345 Debug "About to link..."
1346
1347 case "$OBJECT" in
1348 *.o)
1349         Debugf "Converting $FILES to $OBJECTFILES"
1350         nFiles=`echo $FILES | wc -w`
1351         nObj=`echo $OBJECTFILES | wc -w`
1352 # One source file, one .o: just move the .o
1353         if [ $OBJECT != $OBJECTFILES ]
1354         then
1355                 Debugf "Moving .o to destination"
1356                 DoNoErrCheck $RM $OBJECT
1357                 Do $MV $OBJECTFILES $OBJECT
1358         fi
1359         Copyobj
1360         ;;
1361 *.so|*.so.*|*.sl|*.dylib)
1362 # Make shared library
1363         # if no build share is set, exit normally.
1364         if [ "$BUILD_SHARE" = 0 ]
1365         then
1366                 echo "Warning: building shared library is skipped, possibly due to not supported, check configuration files."
1367                 End 0
1368         elif [ "$CHARM_SHARED" = "0" ]
1369         then
1370                 MakeSO
1371         fi
1372         ;;
1373 *.a)
1374 # Make regular (.a, non-shared) library
1375         # in case building charm so, build .so under lib_so as well # Gengbin
1376         if [ "$BUILD_SHARE" = "1" ]
1377         then
1378           COPY_EXIT=""
1379           OBJECT_SAVE=$OBJECT
1380           COPYTO_SAVE=$COPYTO
1381           if [ -z "$COPYTO" ]
1382           then
1383             DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
1384             OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
1385           else
1386             COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
1387             DESTDIR=$COPYTO
1388           fi
1389           OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
1390           [ -f $DESTDIR/.charmso ] && MakeSO
1391           COPYTO=$COPYTO_SAVE
1392           OBJECT=$OBJECT_SAVE
1393           COPY_EXIT="true"
1394         fi
1395         # build normal .a
1396         DoNoErrCheck $RM $OBJECT
1397         Do $CMK_AR $OBJECT $OBJECTFILES
1398         Do $CMK_RANLIB $OBJECT
1399         Copyobj
1400         ;;
1401 esac
1402 # If the above case returns, we're not creating a .o or .a file,
1403 # so linking is needed.
1404
1405 ############ Determine the language and libraries ##########
1406
1407 # Parse out the real languages
1408 case "$LANGUAGE" in
1409 "charm++f")
1410         LANGUAGE="charm++"
1411         USE_F90_LIBRARIES="1"
1412         ;;
1413 "f90charm")
1414         PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm -lckf"
1415         POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1416         ;;
1417 "bluegene"|"bigsim")
1418         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs"
1419         ;;
1420 "ckbluegene")
1421         POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1422         ;;
1423 "bgcharm++")
1424         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs -lconv-bluegene-stub"
1425         ;;
1426 "bgconverse++")
1427         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bigsim -lconv-bigsim-logs"
1428         ;;
1429 esac
1430
1431 # DMK - ACCEL SUPPORT - If this is a cell build, add the spe code object to POST_LIBRARIES
1432 if [ $CMK_CELL -eq 1 ]
1433 then
1434
1435   if [ "$LANGUAGE" == "converse++" ]
1436   then
1437     # Include a "do nothing" register_accel_spe_funcs() function
1438     POST_LIBRARIES="$POST_LIBRARIES -lnoAccelStub"
1439   fi
1440
1441   if [ "$LANGUAGE" == "charm++" ]
1442   then
1443
1444     if [ $SPU_USE_CPP -eq 1 ]
1445     then
1446         SPU_COMPILER=$CMK_SPU_CXX
1447         SPU_LINKER=$CMK_SPU_LDXX
1448     else
1449         SPU_COMPILER=$CMK_SPU_CC
1450         SPU_LINKER=$CMK_SPU_LD
1451     fi
1452
1453     # Make the spe object file to be included
1454     Do $SPU_COMPILER -c -I$CHARMINC -o main__funcLookup__.genSPECode.o main__funcLookup__.genSPECode.c -DCMK_CELL_SPE=1
1455     Do $SPU_LINKER -L$CHARMLIB -o main__funcLookup__.genSPECode main__funcLookup__.genSPECode.o $CMK_SPERT_LIBS $SPU_EXTRA_LIBS
1456     Do $CMK_PPU_EMBEDSPU spert_main main__funcLookup__.genSPECode main__funcLookup__.genSPECode.ppe.o
1457
1458     # Include the spe object file for linking into main executable
1459     POST_LIBRARIES="$POST_LIBRARIES main__funcLookup__.genSPECode.ppe.o"
1460
1461   fi
1462 fi
1463
1464 if [ "$AMPIMAIN" != "" ]
1465 then
1466         OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1467 fi
1468
1469 if [ "$SWAPGLOBALS" = "1" ]
1470 then
1471         swapo="$CHARMLIB/libglobal-swap.o"
1472         if [ ! -r "$swapo" -o ! -s "$swapo" ]
1473         then
1474                 echo "Global-swapping library $swapo missing--"
1475                 echo "  Is -swapglobals supported on this machine?"
1476                 exit 1
1477         else
1478                 OBJECTFILES="$swapo $OBJECTFILES"
1479         fi
1480 fi
1481 if [ "$SWAPGLOBALS" = "2" ]
1482 then
1483         swapo="$CHARMLIB/libglobal-copy.o"
1484         if [ ! -r "$swapo" -o ! -s "$swapo" ]
1485         then
1486                 echo "Global-copying library $swapo missing--"
1487                 echo "  Is -copyglobals supported on this machine?"
1488                 exit 1
1489         else
1490                 OBJECTFILES="$swapo $OBJECTFILES $CHARMLIB/loadsym.o"
1491         fi
1492 fi
1493
1494 if [ $USE_F77_LIBRARIES = "1" ]
1495 then
1496         POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1497 fi
1498
1499 if [ $USE_F90_LIBRARIES = "1" ]
1500 then
1501         if [ ! -r $CHARMLIB/libconv-utilf.a ]
1502         then
1503                 echo "Fortran support library $CHARMLIB/libconv-utilf.a missing"
1504                 echo "Is your Fortran compiler working?"
1505                 exit 1
1506         fi
1507         
1508         POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1509         if [ -z "$SEQUENTIAL" -a ! -z "$CMK_F90OBJS" ] 
1510         then
1511           for f90obj in $CMK_F90OBJS
1512           do
1513             OBJECTFILES="$OBJECTFILES $CHARMLIB/$f90obj"
1514           done
1515         fi
1516 fi
1517
1518 if [ "$MPI_INTEROPERATE" != "" ]
1519 then
1520         OBJECTFILES="$CHARMLIB/mpi-mainmodule.o $OBJECTFILES"
1521 fi
1522
1523 # check if we're linking a sequential object
1524 case "$LANGUAGE" in
1525 "c"|"C"|"f90"|"f77")
1526         if [ -n "$NATIVE" ]
1527         then
1528           Do $CMK_NATIVE_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1529                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1530         else
1531           Do $CMK_SEQ_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1532                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1533         fi
1534         Copyobj
1535         ;;
1536 "c++"|"C++")
1537         if [ -n "$NATIVE" ]
1538         then
1539           Do $CMK_NATIVE_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1540                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1541         else
1542           Do $CMK_SEQ_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1543                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1544         fi
1545         Copyobj
1546         ;;
1547 esac
1548
1549 ##############################################################################
1550 #
1551 # Some quick consistency checks prior to full link-step
1552 #
1553 # Check for valid choice of TRACEMODE
1554 # Check for valid choice of BALANCE
1555 # Check for compatibility among BALANCE and TRACEMODE
1556 #
1557 ##############################################################################
1558
1559 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1560
1561 # Check for valid choice of TRACEMODE
1562
1563 # [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed.  Is Charm++ built properly?"
1564
1565 if [ x"$TRACEMODE" != x ]
1566 then
1567 for trace in $TRACEMODE; do
1568 [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
1569 TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1570 done
1571 TRACE_OBJ="$TRACE_OBJ $CMK_LIBZ"
1572 fi
1573
1574 if test x$LANGUAGE = x"bgcharm++"
1575 then 
1576     BALANCE=bluegene
1577 fi
1578
1579 BAL_EXT=`getExtention $BALANCE`
1580 if [ -z "$BAL_EXT" ]
1581 then
1582 # Balance has no extention-- is a library reference
1583     BAL_OBJ="$CHARMLIB/libldb-$BALANCE.o"
1584 else
1585 # Balance has some extention-- must be a .o or .a file
1586     BAL_OBJ="$BALANCE"
1587 fi
1588
1589 Debug "Finished with BAL_OBJ=$BAL_OBJ, TRACEMODE=$TRACEMODE..."
1590
1591 if [ ! -r "$BAL_OBJ" ]
1592 then
1593         if [ "$BALANCE" = "$BAL_OBJ" ]
1594         then
1595                 Abort "Could not find load balancer object $BAL_OBJ"
1596         else
1597                 (cd $CHARMLIB ; ls -al libldb-*)
1598                 Abort "Unknown load balancer $BALANCE / $BAL_OBJ"
1599         fi
1600 fi
1601
1602
1603 # Check for valid choice of MEMORY
1604
1605 MEM_OBJ="$CHARMLIB/libmemory-$MEMORY.o"
1606
1607 if [ ! -r $MEM_OBJ -o ! -s $MEM_OBJ ] 
1608 then
1609   (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1610   Abort "charmc : No such memory mode $MEMORY"
1611 fi
1612
1613 # For memory wrapping around the OS allocator, need to add also the wrapper object
1614 case $MEMORY in
1615   os-*)
1616   MEM_OBJ=$MEM_OBJ" $CHARMLIB/libmemory-os-wrapper.o"
1617   ;;
1618 esac
1619
1620 # Check for valid choice of THREAD
1621
1622 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1623 then
1624   THREAD=$CMK_LD_SHARED_THREAD
1625 fi
1626 if [ "$TLSGLOBALS"  = "1" ]
1627 then
1628     # make sure we don't add an extra -tls
1629   if ! echo $THREAD | grep '\-tls$' > /dev/null 2> /dev/null
1630   then
1631     THREAD=${THREAD}-tls
1632   fi
1633 fi
1634 THREAD_OBJ="$CHARMLIB/libthreads-$THREAD.o"
1635
1636 if [ ! -r $THREAD_OBJ -o ! -s $THREAD_OBJ ] 
1637 then
1638   (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1639   Abort "charmc : No such thread mode $THREAD"
1640 fi
1641
1642 ################# Build the module initialization function ##################
1643 modInitName="moduleinit$$"
1644 modInitSrc="$modInitName.C"
1645 modInitObj="$modInitName.o"
1646 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
1647
1648 for module in $MODULES; do
1649     echo "extern void _register$module(void);" >> $modInitSrc
1650 done
1651 for trace in $TRACEMODE; do
1652     if test $trace = "summary" 
1653     then
1654       echo "  extern void _registerTraceSummary();" >> $modInitSrc
1655     elif test $trace = "projections"
1656     then
1657       echo "  extern void _registerTraceProjections();" >> $modInitSrc
1658     elif test $trace = "simple"
1659     then
1660       echo "  extern void _registerTraceSimple();" >> $modInitSrc
1661     elif test $trace = "Tau"
1662     then
1663       echo "  extern void _registerTraceTau();" >> $modInitSrc
1664     elif test $trace = "utilization" 
1665     then 
1666       echo "  extern void _registerTraceUtilization();" >> $modInitSrc 
1667     elif test $trace = "controlPoints"
1668     then
1669       echo "  extern void _registerTraceControlPoints();" >> $modInitSrc
1670     elif test $trace = "all"
1671     then
1672       echo "  extern void _registerTraceProjections();" >> $modInitSrc
1673       echo "  extern void _registerTraceSummary();" >> $modInitSrc
1674     fi
1675 done
1676 if test -n "$BALANCER"
1677 then
1678     echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
1679 fi
1680 echo "void _registerExternalModules(char **argv) {" >> $modInitSrc
1681 for module in $MODULES; do
1682     [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
1683     echo "  _register$module();" >> $modInitSrc
1684 done
1685 for trace in $TRACEMODE; do
1686     if test $trace = "summary"
1687     then
1688       echo "  _registerTraceSummary();" >> $modInitSrc
1689     elif test $trace = "projections"
1690     then
1691       echo "  _registerTraceProjections();" >> $modInitSrc
1692     elif test $trace = "Tau"
1693     then
1694       TRACE_WITH_TAU=1
1695       echo "  _registerTraceTau();" >> $modInitSrc
1696     elif test $trace = "simple"
1697     then
1698       echo "  _registerTraceSimple();" >> $modInitSrc
1699     elif test $trace = "utilization" 
1700     then 
1701       echo "  _registerTraceUtilization();" >>  $modInitSrc 
1702     elif test $trace = "controlPoints"
1703     then
1704       echo "  _registerTraceControlPoints();" >> $modInitSrc
1705     elif test $trace = "all"
1706     then
1707       echo "  _registerTraceProjections();" >> $modInitSrc
1708       echo "  _registerTraceSummary();" >> $modInitSrc
1709     fi
1710 done
1711 if test -n "$BALANCER"
1712 then
1713     [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
1714     for deflb in $BALANCER
1715     do
1716       echo "  LBDefaultCreate(\"$deflb\");" >> $modInitSrc
1717     done
1718 fi
1719 echo "}" >> $modInitSrc
1720
1721 # creating projections
1722 echo "void _createTraces(char **argv) {" >> $modInitSrc
1723 for trace in $TRACEMODE; do
1724     [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
1725     echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
1726     echo "_createTrace$trace(argv);" >> $modInitSrc
1727 done
1728 echo "}" >> $modInitSrc
1729
1730 Do $CMK_CXX $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $modInitSrc -o $modInitObj
1731
1732 ###############################################################################
1733 #
1734 #                               Finally, LINK
1735 #
1736 ###############################################################################
1737
1738 Debug "About to perform final link..."
1739
1740 MAKE_LDXX="0"
1741 MAKE_LD="0"
1742
1743 CORE_LIBS="-lconv-core -lconv-util $TRACE_OBJ "
1744
1745 # get TAU stub makefile variables
1746 if test "$CMK_WITH_TAU" = "true"
1747 then
1748   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1749   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1750   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1751   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS` 
1752   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1753   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1754   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1755
1756   rm -f _make.tau.tmp
1757 fi
1758 # done getting TAU variables
1759
1760 case "$LANGUAGE" in
1761 "f90charm")
1762         MAKE_LDXX="1"
1763         MIDDLE_LIBS="-lck -lconv-cplus-y $CORE_LIBS "
1764         CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1765         if [ "$TAU_TRACE_MPI" = "1" ]
1766         then
1767                 TAU_LIBS="$TAU_MPI_FLIBS $TAU_LIBS"
1768         else
1769                 TAU_LIBS="$TAU_LIBS"
1770         fi
1771         ;;
1772 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1773         MAKE_LDXX="1"
1774         MIDDLE_LIBS="-lck -lconv-cplus-y $CORE_LIBS "
1775         CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1776         if [ "$TAU_TRACE_MPI" = "1" ]
1777         then
1778                 TAU_LIBS="$TAU_MPI_LIBS $TAU_LIBS"
1779         else
1780                 TAU_LIBS="$TAU_LIBS"
1781         fi
1782         ;;
1783 "converse")
1784         MAKE_LD="1"
1785         MIDDLE_LIBS="-lconv-cplus-n $CORE_LIBS -ltrace-converse "
1786         CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1787         ;;
1788 "converse++"|"bluegene"|"bigsim"|"bgconverse++")
1789         MAKE_LDXX="1"
1790         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-cplus-y $CORE_LIBS -ltrace-converse "
1791         CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1792         ;;
1793 *)
1794         Abort "Unrecognized choice of language $LANGUAGE"
1795         ;;
1796 esac
1797
1798 if [ "$BUILD_SHARE" = "0" ]
1799 then
1800         MIDDLE_LIBS="$MEM_OBJ $THREAD_OBJ $MIDDLE_LIBS"
1801 fi
1802
1803 if [ "$CHARM_SHARED" = "1" ]
1804 then
1805   [ -z "$CHARMLIBSO" ] &&  Abort "Charm++ lib_so directory not found!"
1806   # build user executable/shared lib linking with charm .so
1807   OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1808   if [ "$BUILD_SHARE" = "1" ]
1809   then
1810     LANG_LIBS="-L$CHARMLIBSO $OBJECTFILES $PRE_LIBRARIES"
1811   else
1812     LANG_LIBS="-L$CHARMLIBSO $BAL_OBJ $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1813   fi
1814 else
1815   LANG_LIBS="-L$CHARMLIB -I$CHARMINC $BAL_OBJ $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1816 fi
1817 if [ "$TRACE_WITH_TAU" = 1 ]
1818 then
1819         echo "Linking with the TAU libraries: $TAU_LIBS"
1820         ALL_LIBS="$LANG_LIBS $MIDDLE_LIBS $CMK_LIBS $POST_LIBRARIES $CMK_SYSLIBS $TAU_LIBS"
1821 else
1822         ALL_LIBS="$LANG_LIBS $MIDDLE_LIBS $CMK_LIBS $POST_LIBRARIES $CMK_SYSLIBS"
1823 fi
1824 Debugf "All libraries are: $ALL_LIBS"
1825
1826 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
1827 then
1828   # build an applicaiton .so linking with charm .so
1829   OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
1830   Debugf "Running ldro..."
1831   DoNoErrCheck $RM $OBJECT
1832   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
1833   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
1834   Copyobj
1835 else
1836 # Make a regular executable: call the appropriate linker
1837   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
1838   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
1839 fi
1840
1841 ########################################################################
1842 #
1843 # Copy conv-host to user directory if it is present in installation.
1844 #
1845 ########################################################################
1846
1847 if test "$COPY_CHARMRUN" = "true"
1848 then
1849   targ=charmrun$CMK_POST_EXE
1850   [ ! -x $CHARMBIN/$targ -a -n "$CMK_POST_EXE" ] && targ=charmrun
1851   convhost=conv-host$CMK_POST_EXE
1852
1853   if [ -x $CHARMBIN/$targ ]
1854   then
1855         DoNoErrCheck $RM $targ
1856         Do $CP $CHARMBIN/$targ $targ
1857   fi
1858 fi
1859
1860 [ -z "$SAVE" ] && DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
1861
1862 Copyobj
1863
1864