fixed bug for override:
[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
53 OBJECT=""
54 POST_LANGUAGE=""
55 POST_LIBRARIES=""    
56 PRE_LIBRARIES=""  
57 USE_F90_LIBRARIES="0"  
58 USE_F77_LIBRARIES="0"  
59 F90_MODDIR=
60 AMPIMAIN=""
61 COPYTO=""        
62 MODCOPIES=""        
63 MODULES=""
64 BALANCER=""
65 FILES=""       
66 OBJECTFILES=""  
67 DELETE=""    
68 MAINOBJ=""   
69 GENCPM=""
70 OPTIMIZE_MODE=""
71 USE_RELIABLE_CC=""
72 USE_FASTEST_CC=""
73 PROG_EXT=""
74
75 COPY_CHARMRUN=true
76
77 COPY_EXIT="true"
78 CHARM_SHARED="0"
79 BUILD_SHARE="1"
80 SWAPGLOBALS="0"
81
82 ####################################################################
83 #
84 #  Utility routines used below
85 #
86 ###################################################################
87
88 # PrintUsage: prints a helpful command-line usage message and quits
89 # Args: any additional messages
90 printUsage() {
91     printVersion
92     echo 
93     echo "Usage: charmc [ flags ] <files>"
94     echo
95     echo "  flags:"
96     echo "        -o <target> -g -O"
97     echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
98     echo "        -machine <mach> -seq -host -langage <lang> "
99     echo "        -balance <mode> -tracemode <mode> -memory <mode>"
100     echo "        -modules <comma-separated list of C++ modules>"
101     echo "        -verbose -save -purify -cp <dest> -gen-cpm <package>"
102     echo "        -use-reliable-cc -use-fastest-cc"
103     echo "        -cc <new cc> -c++ <new CC>  -ld <new ld> -ld++ <new LD>"
104     echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
105     echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
106     echo "        -fmoddir <f90mod path>"
107     echo "        -pg <opt> -build-shared -charm-shared"
108     echo
109     echo "  Charmc compiles C, C++, f77, f90, Converse, Converse++, Charm, "
110     echo "and Charm++ programs.  The flags generally match those of cc or f77."
111     echo "Version 5.0, Parallel Programming Lab, UIUC, 1999"
112     echo $*
113     exit 1
114 }
115
116 # End blows away the temporary files (unless SAVE is true) and exits
117 # Args: <exit code>
118 End() {
119     if [ -z "$SAVE" ]
120         then
121         for FILE in `echo $FILES`
122         do
123                         BASE=`stripExtention $FILE`
124                         TMP=`basename $FILE`".TMP"
125             $RM $TMP.P.C $TMP.cpp $TMP.space $TMP.xlat $TMP.o
126             $RM $TMP.c $TMP.c.0.h $TMP.c.1.h $TMP.c.2.h
127             $RM $TMP.i $TMP.$CMK_CPP_SUFFIX
128         done
129         $RM core $DELETE
130     fi
131     exit $1
132 }
133
134 # Write this error message to stderr
135 # ("1>&2" redirects the echo output to stderr).
136 Warning() {
137         echo "$@" 1>&2
138 }
139
140 # This procedure prints an error message and exits.
141 # Args: written to stderr
142 Abort() {
143         Warning "Fatal Error by charmc in directory "`pwd`
144         Warning "   $@"
145         Warning "charmc exiting..."
146         End 1
147 }
148
149
150 # Instead of an ECHO_CMD variable, I define a procedure Do,
151 # which (possibly) echos, runs, and tests the errors of the given command.
152 # Args: executed as given
153 DoNoErrCheck() {
154         [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
155         "$@"
156 }
157 Do() {
158         DoNoErrCheck "$@"
159         Do_res=$?
160 # The UNIX result code better be zero, or we die
161         [ $Do_res -eq 0 ] || Abort "Command $@ returned error code $Do_res"
162 }
163
164 # This procedure removes the extention (the ".c" in "./main.c") from
165 # its first argument, and prints the result. Unlike the builtin command
166 # basename, it keeps the directory path.
167 # Args: <name to strip>
168 stripExtention() {
169         se_base=`echo $1 | awk -F/ '{print $NF}'`
170         se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
171         se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
172         echo $se_ret
173 }
174
175 # GetExtention returns the extention on the given file name
176 # or "" if none.  (e.g. "./bob/snack.c" returns ".c")
177 # Args: <name to find extention of>
178 getExtention() {
179         se_base=`echo $1 | awk -F/ '{print $NF}'`
180         se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
181         echo $se_ret
182 }
183
184 Debugf() {
185         [ -n "$VERBOSE" ] && echo "charmc>" $@
186 }
187
188 Debug() {
189     if [ -n "$DEBUG_SCRIPT" ]
190     then
191         echo 
192         echo "------- Charmc Debugging info: $* -------"
193         echo "CHARMBIN=$CHARMBIN"
194         echo "CHARMINC=$CHARMINC"
195         echo "CHARMLIB=$CHARMLIB"
196         echo "FILES=$FILES"
197         echo "DELETE=$DELETE"
198         echo "OBJECT=$OBJECT"
199         echo "LANGUAGE=$LANGUAGE"
200 #       echo "Working directory="`pwd`
201     fi
202 }
203
204 # Return success if $1 is not in any of the other arguments
205 notInList() {
206         search=$1
207         shift
208         while [ $# -gt 0 ]
209         do
210                 if [ "$search" = "$1" ]
211                 then
212                         # It's already in there-- fail
213                         return 1
214                 fi
215                 shift
216         done
217         # It's missing--succeed
218         return 0
219 }
220
221 # Add arguments to our modules list, avoiding duplicates
222 AddModules() {
223     for M in "$@"
224     do
225       notInList $M $MODULES && MODULES="$MODULES $M"
226     done
227 }
228
229 # Add this word to this list, avoiding duplicates
230 AddList() {
231     ret=""
232     for M in "$@"
233     do
234       notInList $M $ret && ret="$ret $M"
235     done
236     echo $ret
237 }
238
239 # Append the last word to this list, avoiding duplicates
240 # the difference to previous AddList() is that when duplication happens,
241 # only keep the last one, instead of keeping the first one as in AddList()
242 # this helps to solve the multiple -lfoo in the link command. 
243 AppendList() {
244         ret=""
245         search=$1
246         shift
247         while [ $# -gt 0 ] 
248         do
249                 if notInList $search $@
250                 then
251                         ret="$ret $search"
252                 fi
253                 search=$1
254                 shift
255         done
256         echo $ret $search
257 }
258
259
260
261 # TEMP_BASE is appended with this script's process ID (PID),
262 # so multiple charmcs can run in parallel without overwriting
263 # each other's temporary files.
264 TEMP_BASE="/tmp/charmc_tmp.$$"
265
266 # Try to find CHARMBIN by looking in directory where charmc is
267 findCharmBin() {
268 if [ -z "$CHARMBIN" ]
269 then
270         SCRIPT=$1
271         CHARMBIN=`dirname $SCRIPT`
272 #       CHARMBIN=`cd $CHARMBIN; pwd`
273 # NOTE: this script no longer tries to follow soft links
274 # to find the "original" charmc-- if this is bad, 
275 # translate these lines to Bourne shell from C shell:
276 # -------------------- Begin C Shell ------------------------->
277 #    if ($SCRIPT:h != $SCRIPT:t) then
278 #        cd $SCRIPT:h
279 #        set SCRIPT=$SCRIPT:t
280 #    else
281 #        foreach dir ($path)
282 #            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
283 #                cd $dir
284 #                break
285 #            endif
286 #        end
287 #    endif
288 #    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
289 #        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
290 #        if ($SCRIPT:h != $SCRIPT:t) then
291 #            cd $SCRIPT:h
292 #            set SCRIPT=$SCRIPT:t
293 #        endif
294 #    end
295 #    set CHARMBIN=`pwd`
296 # <------------------ End C Shell -----------------------------
297 fi
298 }
299
300 printVersion()
301 {
302         findCharmBin $0
303         version=`cat $CHARMBIN/../include/VERSION`
304         echo Charm++ Version $version
305 }
306
307 ##############################################################################
308 #
309 # Parse the arguments
310 #
311 # Don't do any analysis in here, just the parsing.
312 #
313 ##############################################################################
314
315 [ $# -eq 0 ] && printUsage "Error: No arguments given."
316
317 processArgs() {
318 while [ ! $# -eq 0 ]
319 do
320         arg="$1"
321         shift
322
323         case "$arg" in
324         "-V")
325                 printVersion
326                 exit 0
327                 ;;
328
329         "-machine")
330                 MACHTYPE="$1"
331                 shift
332                 ;;
333
334         "-seq")
335                 SEQUENTIAL=true
336                 ;;
337
338         "-host")
339                 NATIVE=true
340                 ;;
341
342         "-language")
343                 # Parse out some fake languages (that are actually modules)
344                 case "$1" in
345                 "ampi") AddModules tcharmmain ampi ;;
346                 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ;;
347                 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
348                 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
349                 "mblock") AddModules tcharmmain mblock ;;
350                 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
351                 *) 
352                         LANGUAGE="$1"
353                         POST_LANGUAGE=1
354                         ;;
355                 esac
356                 shift
357                 ;;
358
359         "-module"|"-modules")
360                 AddModules `echo $1 | sed -e 's/,/ /g'`
361                 shift
362                 ;;
363
364         "-balancer")
365 #                test -n "$BALANCER" && Abort "More than one -balancer specified!"
366                 BALANCER="$BALANCER $1"
367                 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
368                 AddModules $mod
369                 shift
370                 ;;
371
372         "-balance")
373                 BALANCE="$1"
374                 shift
375                 ;;
376
377         "-queue")
378                 Warning "Warning: -queue currently being ignored."
379                 shift
380                 ;;
381
382         "-memory")
383                 MEMORY="$1"
384                 shift
385                 ;;
386
387         "-thread")
388                 THREAD="$1"
389                 shift
390                 ;;
391
392         "-tracemode")
393                 TRACEMODE_NEW=`AddList $TRACEMODE $1`
394                 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
395                 then
396                         Warning "Warning: Duplicate tracemode $1 ignored"
397                 else
398                         TRACEMODE=$TRACEMODE_NEW
399                 fi
400                 shift
401                 ;;
402         
403         "-swapglobal"|"-swapglobals")
404                 SWAPGLOBALS="1"
405                 # fixme: -fpic is only for gcc-- should wait until we read config script
406                 OPTS_CC="$OPTS_CC -fpic"
407                 OPTS_CXX="$OPTS_CXX -fpic"
408                 OPTS_F90="$OPTS_F90 -fpic"
409                 OPTS_LD="$OPTS_LD -fpic"
410                 ;;
411
412         "-verbose")
413                 echo "Verbose mode set"
414                 VERBOSE=true
415                 ;;
416
417         "-intrinsic")
418                 XI_INTERNAL=true
419                 ;;
420
421         "-debug-script")
422                 echo "Will give excessive charmc debugging output..."
423                 DEBUG_SCRIPT=true
424                 ;;
425
426         "-save")
427                 SAVE=true
428                 ;;
429
430         "-purify")
431                 PURIFY=true
432                 ;;
433
434         "-use-reliable-cc")
435                 USE_RELIABLE_CC=1
436                 ;;
437
438         "-use-fastest-cc")
439                 USE_FASTEST_CC=1
440                 ;;
441
442         "-cc")
443                 OVERRIDE_CC="$1"
444                 shift
445                 ;;
446
447         "-c++")
448                 OVERRIDE_CXX="$1"
449                 shift
450                 ;;
451
452         "-f90")
453                 OVERRIDE_F90="$1"
454                 shift
455                 ;;
456
457         "-ld")
458                 OVERRIDE_LD="$1"
459                 shift
460                 ;;
461
462         "-ld++")
463                 OVERRIDE_LDXX="$1"
464                 shift
465                 ;;
466
467         "-cpp-option")
468                 OPTS_CPP="$OPTS_CPP $1"
469                 shift
470                 ;;
471
472         "-ldro-option")
473                 OPTS_LDRO="$OPTS_LDRO $1"
474                 shift
475                 ;;
476
477         "-cc-option")
478                 OPTS_CC="$OPTS_CC $1"
479                 shift
480                 ;;
481
482         "-c++-option")
483                 OPTS_CXX="$OPTS_CXX $1"
484                 shift
485                 ;;
486
487         "-f90-option")
488                 OPTS_F90="$OPTS_F90 $1"
489                 shift
490                 ;;
491
492         "-ld-option")
493                 OPTS_LD="$OPTS_LD $1"
494                 shift
495                 ;;
496
497         "-ld++-option")
498                 OPTS_LDXX="$OPTS_LDXX $1"
499                 shift
500                 ;;
501
502         "-rpath")
503                 OPTS_LDXX="$OPTS_LDXX -rpath $1"
504                 shift
505                 ;;
506         
507         "-fortran"|"-flib"|"-flibs")
508                 USE_F90_LIBRARIES="1" 
509                 ;;
510         "-f77")
511                 USE_F77="1" 
512                 ;;
513         "-fortran77"|"-f77lib"|"-f77libs")
514                 USE_F77_LIBRARIES="1" 
515                 ;;
516         "-M"|"-E"|"-P"|"-S")
517 # Run preprocessor/assembler only
518                 SKIPLINK="yes"
519                 OPTS="$OPTS $arg"
520                 ;;
521         "-c")
522 # This is ignored.
523                 ;;
524
525         "-o")
526                 OBJECT=$1
527                 shift
528                 ;;
529
530         "-cp")
531                 COPYTO="$1"
532                 shift
533                 ;;
534
535         "-cpmod")
536                 MODCOPIES="$1 $MODCOPIES"
537                 shift
538                 ;;
539
540         "-gen-cpm")
541                 GENCPM="$GENCPM $1"
542                 shift
543                 ;;
544
545         -D*|-I*)
546                 OPTS_CPP="$OPTS_CPP $arg"
547                 ;;
548
549         -LANG*)
550                 Warning "passing unrecognized option $arg to all compilers and linkers"
551                 OPTS="$OPTS $arg"
552                 ;;
553         -shared|-G)
554                 BUILD_SHARE="1"
555                 ;;
556         -L*|-shared|-G)
557                 OPTS_LD="$OPTS_LD $arg"
558                 ;;
559         -charm-shared|-cs)
560                 CHARM_SHARED="1"
561                 ;;
562         -build-shared|-bs)
563                 # used internally when building Charm++ to create lib_so
564                 # obsolete, do nothing since BUILD_SHARE is on by default
565                 ;;
566         -no-build-shared|-nobs)
567                 # used internally not to build Charm++ lib_so
568                 BUILD_SHARE="0"
569                 ;;
570         "-O")
571                 OPTIMIZE_MODE=true
572                 ;;
573
574         "-NO")
575                 OPTIMIZE_MODE=false
576                 ;;
577         
578         "-pg"|"-g"|-W*|-O*)
579                 OPTS="$OPTS $arg"
580                 ;;
581
582         "-fmoddir")
583                 F90_MODDIR="$F90_MODDIR $1"
584                 shift
585                 ;;
586
587         -l*|*.a)
588                 if [ -n "$POST_LANGUAGE" ]
589                 then
590                         POST_LIBRARIES=`AppendList $POST_LIBRARIES $arg`
591                 else
592                         PRE_LIBRARIES=`AppendList $PRE_LIBRARIES $arg`
593                 fi
594                 ;;
595
596         -s)
597                 OPTS_LD="$OPTS_LD   $arg"
598                 ;;
599         -no-charmrun)
600                 COPY_CHARMRUN=false
601                 ;;
602         -h|--help)
603                 printUsage
604                 ;;
605         -*|+*)
606 #               Warning "passing unrecognized option $arg to all compilers and linkers"
607                 OPTS="$OPTS  $arg"
608                 ;;
609         *.*)
610                 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
611                 FILES="$FILES $arg"
612                 ;;
613 # Default
614         *)
615 #               printUsage  "Error: Unrecognized argument $arg"
616 #               Warning "passing unrecognized option $arg to all compilers and linkers"
617                 OPTS="$OPTS  $arg"
618                 ;;
619         esac
620 done
621 }
622
623
624 # Process original command-line arguments
625 processArgs "$@"
626
627
628 ##############################################################################
629 #
630 # The following section identifies CHARMBIN, the charm binary-directory.
631 #
632 ##############################################################################
633
634 ORIGDIR=`pwd`
635
636 # Try to find CHARMBIN by looking in directory where charmc is
637
638 findCharmBin $0
639
640 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
641 if [ "$FIRST_THREE" = "CYG" ]
642 then
643 # Running on a windows system-- append .exe to file names
644         PROG_EXT=".exe"
645 fi
646
647 CHARMLIB="$CHARMBIN/../lib"
648 CHARMINC="$CHARMBIN/../include"
649 CHARMLIBSO=
650 if test -d "$CHARMBIN/../lib_so" 
651 then
652   CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
653   #getting absolute path is harder than thought because of symbolic links and ..
654   #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
655   #csh is ok too if it exists 
656   test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
657   test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
658   test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
659 fi
660
661
662
663 ##############################################################################
664 #
665 # Load module dependencies.
666 #
667 ##############################################################################
668
669 PROCESSED_MODULES=""
670
671 # Look up and add the dependencies for module $1
672 findModuleDep() {
673         M=$1
674         notInList $M $PROCESSED_MODULES || return
675         PROCESSED_MODULES="$PROCESSED_MODULES $M"
676         PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
677 # HACK: add modules to both ends of library list, to avoid
678 #  undefined symbol CkRegisterMainModule when it's in a module file.
679         POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
680         
681         dep=""
682 # fixme: should search everything in the -L library paths:
683         for dir in `echo . $CHARMLIB`
684         do
685                 d="$dir/libmodule$M.dep"
686                 [ -r "$d" ] && dep=$d
687         done
688         if [ -r "$dep" ]
689         then
690                 # Add the module dependencies in this file
691                 # Debugf "Adding module" $M "dependencies from" $dep
692                 deps=`cat $dep`
693                 Debugf "Module" $M "adds dependencies:" $deps
694                 processArgs $deps
695         fi
696 }
697
698 # Repeat the module-dependency search until we find no
699 #  new modules:
700 START_MODULES=""
701 while [ "$START_MODULES" != "$MODULES" ]
702 do
703         Debugf "----------- Module dependency search ------------"
704         START_MODULES="$MODULES"
705         for m in $MODULES
706         do
707                 findModuleDep $m
708         done
709 done
710
711 Debugf "----------- Module dependency search complete ------------"
712
713
714
715 ##############################################################################
716 #
717 # Load machine-specific configuration data, then handle overrides to it.
718 #
719 ##############################################################################
720
721
722 Debug "About to read machine config script"
723 Debug "Read config script, setting defaults..."
724
725 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
726 . $CHARMINC/conv-config.sh $CHARMINC
727
728 Debug "Setting vars..."
729
730 if [ "$BUILD_SHARE" = "1" ]
731 then
732         if [ -n "$CMK_NO_BUILD_SHARED" -o -z "$CHARMLIBSO" ]
733         then
734                 BUILD_SHARE="0"
735         fi
736 fi
737
738 if [ "$BUILD_SHARE" = "1" ]
739 then
740         # ignore BUILD_SHARE if the target is not .a or .so
741         case "$OBJECT" in
742         *.a|*.so|*.sl|*.dylib)
743                 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
744                 ;;
745         *)      
746                 BUILD_SHARE="0"
747                 ;;
748         esac
749 fi
750
751 if [ -n "$OVERRIDE_CC" ]
752 then
753     CMK_CC="$OVERRIDE_CC"
754 fi
755 Debug "set 2"
756 if [ -n "$OVERRIDE_CXX" ]
757 then
758     CMK_CXX="$OVERRIDE_CXX"
759 fi
760
761 if [ -n "$OVERRIDE_F90" ]
762 then
763     CMK_CF90="$OVERRIDE_F90"
764 fi
765
766 if [ -n "$OVERRIDE_LD" ]
767 then
768     CMK_LD="$OVERRIDE_LD"
769 fi
770
771 if [ -n "$OVERRIDE_LDXX" ]
772 then
773     CMK_LDXX="$OVERRIDE_LDXX"
774 fi
775
776 if [ -n "$USE_RELIABLE_CC" ]
777 then
778         CMK_CC="$CMK_CC_RELIABLE"
779 fi
780
781 if [ -n "$USE_FASTEST_CC" ]
782 then
783     CMK_CC="$CMK_CC_FASTEST"
784 fi
785
786 if [ -n "$USE_F77" ]
787 then
788     CMK_CF90=$CMK_CF77
789     CMK_CF90_FIXED=$CMK_CF77
790     CMK_F90LIBS=$CMK_F77LIBS
791 fi
792
793 if [ -n "$CMK_F90_MODINC" ]
794 then
795     CMK_CF90_MODINC="$CMK_F90_MODINC"
796 else
797     CMK_CF90_MODINC="-M"
798 fi
799
800 if [ -n "$F90_MODDIR" ]
801 then
802     for dir in $F90_MODDIR
803     do
804       OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
805     done
806 fi
807
808 if [ -n "$CMK_F90_USE_MODDIR" ]
809 then
810     CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC$CHARMINC "
811 fi
812
813 if [ -n "$SEQUENTIAL" ]
814 then
815     CMK_CC="$CMK_SEQ_CC -DCMK_SEQUENTIAL=1 "
816     CMK_LD="$CMK_SEQ_LD"
817     CMK_CXX="$CMK_SEQ_CXX -DCMK_SEQUENTIAL=1 " 
818     CMK_CF90="$CMK_SEQ_F90 " 
819     CMK_LDXX="$CMK_SEQ_LDXX" 
820     CMK_AR="$CMK_SEQ_AR"
821     CMK_RANLIB="$CMK_SEQ_RANLIB"
822 fi
823
824 if [ -n "$NATIVE" ]
825 then
826     CMK_CC="$CMK_NATIVE_CC " 
827     CMK_LD="$CMK_NATIVE_LD" 
828     CMK_CXX="$CMK_NATIVE_CXX " 
829     CMK_LDXX="$CMK_NATIVE_LDXX" 
830 fi
831
832 if [ -n "$PURIFY" ]
833 then
834     CMK_LD="purify $CMK_LD"
835     CMK_LDXX="purify $CMK_LDXX"
836 fi
837
838 Debug "set 4"
839 if [ -n "$OPTIMIZE_MODE" ]
840 then
841     OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
842     OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
843     OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
844     OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
845     OPTS_LDXX="$CMK_CXX_OPTIMIZE $OPTS_LDXX"
846 fi
847
848 if [ -n "$XI_INTERNAL" ]
849 then
850     CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
851 fi
852
853 #Add generic options to the compiler- and linker-options
854 OPTS_CC="$OPTS $OPTS_CC"
855 OPTS_CXX="$OPTS $OPTS_CXX"
856 OPTS_F90="$OPTS $OPTS_F90"
857 OPTS_LD="$OPTS $OPTS_LD"
858 # OPTS_LDXX gets OPTS from OPTS_LD
859
860 # There's really no analog for this in the Bourne shell: 
861 #  -------- C Shell ------> onintr failure
862 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
863
864 ##############################################################################
865 #
866 # Check for valid choice of LANGUAGE
867 #
868 ##############################################################################
869 Debug "Checking language..."
870
871 if [ -z "$LANGUAGE" ]
872 then
873     LANGUAGE="charm++"
874     [ -n "$SEQUENTIAL" ] && LANGUAGE=c
875 fi
876
877 case "$LANGUAGE" in
878 "c"|"C"|"c++"|"C++")
879         [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
880         ;;
881 esac
882
883 # update charm to bgcharm
884 if [ "$LANGUAGE" = "charm++" -a -n "$CMK_BLUEGENE" ]
885 then
886         LANGUAGE="bgcharm++"
887 fi
888 if [ "$LANGUAGE" = "converse++" -a -n "$CMK_BLUEGENE" ]
889 then
890         LANGUAGE="bgconverse++"
891 fi
892 if [ "$LANGUAGE" = "bgcharm++" ]
893 then
894         TRACEMODE=`AddList $TRACEMODE bluegene`
895 fi
896
897 ########################################################################
898 #
899 # We've parsed and verified the command-line parameters.
900 # Now we prepare routines to clean up and exit.
901 # None of these routines ever returns-- they all just exit.
902 #
903 ########################################################################
904
905
906 Copyobj() {
907         if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ] 
908         then
909                 [ -d $COPYTO ] && COPYTO="$COPYTO/"
910                 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
911                         Warning "Appending $PROG_EXT to object file name"
912                         OBJECT="$OBJECT$PROG_EXT"
913                 fi
914                 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO 
915                 Do $CP $OBJECT $COPYTO
916         fi
917         test -n "$COPY_EXIT" && Success
918 }
919
920 Copymod() {
921         for COPY in `echo $MODCOPIES`
922         do
923                 if [ "a$COPY" != "a$OBJECT" ] 
924                 then
925                         [ -d $COPY ] && COPY="$COPY/"
926                         if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
927                           OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
928                         fi
929                         if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
930                           Warning "Appending .$CMK_MOD_EXT to object file name"
931                           OBJECT="$OBJECT.$CMK_MOD_EXT"
932                         fi
933                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
934                         Do $CP $OBJECT $COPY
935                 fi
936         done
937         Success
938 }
939
940 Success() {
941         End 0
942 }
943
944
945 ##############################################################################
946 #
947 # Preprocess the GEN-CPM files
948 #
949 ##############################################################################
950
951 Debug "Preprocessing GEN-CPM files"
952
953 for FILE in `echo $GENCPM`
954 do
955 # This used to be "$FILE:r", which strips the extention
956         BASE=`stripExtention $FILE`
957         TMP=`basename $FILE`".TMP"
958         DELETE="$DELETE $TMP.c $TMP.i"
959         DoNoErrCheck $RM $BASE.cpm.h $TMP.c
960         Do touch $BASE.cpm.h
961         Do $LN -f -s $FILE $TMP.c
962         Do $CMK_CPP_C -I$CHARMINC $OPTS_CC $OPTS_CPP $TMP.c > $TMP.i
963         Do $CHARMBIN/conv-cpm $TMP.i $BASE.cpm.h
964 done
965
966 ##############################################################################
967 #
968 # Compile all specified files
969 #
970 # All temporary files named *.TMP.* for easy cleanup.
971 #
972 ##############################################################################
973
974 Debug "About to compile..."
975
976 for FILE in `echo $FILES`
977 do
978         BASE=`stripExtention \`basename $FILE\``
979         TMP=`basename $FILE`".TMP"
980         FILE_EXT=`getExtention $FILE`
981         BASEO="$BASE.o"
982         DESTO="-o $BASEO"
983
984         # in case of: charmc -o object.o -c foo.c,
985         # avoid foo.c => remove foo.o => foo.o => object.o,
986         # instead generate object.o directly.
987         # remove and generate foo.o may be dangerous in parallel make 
988         # for example in the case of compiling several objs from one 
989         # same c file such as memory.c.
990         numFiles=`echo $FILES | wc -w`
991         if [ $numFiles = 1 -a -n "$OBJECT" ]
992         then
993                 OBJ_EXT=`getExtention $OBJECT`
994                 if [ "$OBJ_EXT" = '.o' ]
995                 then
996                     BASEO=$OBJECT
997                     DESTO="-o $OBJECT"
998                 fi
999         fi
1000
1001         if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1002         then
1003                 [ $VERBOSE ] && echo "Compiling $FILE"
1004                 DoNoErrCheck $RM $BASEO $BASE.f.o
1005         fi
1006         if [ ! -z "$SKIPLINK" ] 
1007         then
1008                 DESTO=""
1009         fi
1010         NU_OBJ=""
1011         case "$FILE" in
1012         *.ci)
1013                 if [ "$LANGUAGE" = "f90charm" ]
1014                 then
1015                     Do $CHARMBIN/charmxi -f90 $CMK_XIOPTS $FILE
1016                 else
1017                     Do $CHARMBIN/charmxi $CMK_XIOPTS $FILE
1018                 fi
1019                 ;;
1020         *.c|*.s)
1021                 Do $CMK_CC -I$CHARMINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE $DESTO
1022                 NU_OBJ=$BASEO
1023                 ;;
1024         *.C|*.cc|*.cxx|*.cpp|*.c++)
1025                 Do $CMK_CXX -I$CHARMINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE $DESTO
1026                 NU_OBJ=$BASEO
1027                 ;;
1028         *.f|*.F)
1029                 Do $CMK_CF90_FIXED -I$CHARMINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1030                 NU_OBJ=$BASEO
1031                 ;;
1032         *.f90|*.F90)
1033                 Do $CMK_CF90 -I$CHARMINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1034                 NU_OBJ=$BASEO
1035                 ;;
1036         *.fc|*.FC)
1037                 Abort "I'm not yet smart enough to compile $FILE"
1038                 ;;
1039         *.o|*.so|*.sl|*.a|*.dylib)
1040                 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1041                 OBJECTFILES="$OBJECTFILES $FILE"
1042                 ;;
1043         *.M|*.mod)
1044                 OBJECT="$BASE"
1045                 Copymod
1046                 Success
1047                 ;;
1048         *)
1049                 Abort "file with unrecognized extension $FILE"
1050         esac
1051 # Handle new object files
1052         if [ -n "$NU_OBJ" -a -n "$OBJECT" ] 
1053         then
1054                 if [ "$OBJECT" != "$BASEO" ]
1055                 then
1056                         DELETE="$DELETE $NU_OBJ"
1057                 fi
1058                 OBJECTFILES="$OBJECTFILES $NU_OBJ"
1059         fi
1060 done
1061
1062 ##############################################################################
1063 #
1064 #                        POSSIBLY, SKIP LINK-STEP
1065 #
1066 # 1. No $OBJECT may be specified at all --- its just a compilation.
1067 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1068 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1069 # 4. Language may be sequential.  Do a quick and easy linkage.
1070 #
1071 #               in any of these cases, the full link step is skipped.
1072 #
1073 ##############################################################################
1074
1075 MakeSO() {
1076         Debugf "Running ldro..."
1077         DoNoErrCheck $RM $OBJECT
1078         # convert to absolute path if required
1079         if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1080         then
1081         dir=`dirname $OBJECT`
1082         fname=`basename $OBJECT`
1083         dir=`cd $dir; pwd`
1084         OBJECT=$dir/$fname
1085         fi
1086         Warning "Warning: creating $OBJECT "
1087         soCmd="$CMK_LD -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $PRE_LIBRARIES $POST_LIBRARIES $CMK_LD_SHARED_LIBS"
1088         DoNoErrCheck $soCmd
1089         Do_res=$?
1090         if [ $Do_res -ne 0 ] 
1091         then
1092         echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1093         echo "!!  Failed to compile Charm++ shared library. You can disable shared  !!"
1094         echo "!!  lib compilation by providing --no-build-shared build option like: !!"
1095         echo "!!     ./build charm++ net-linux --no-build-shared -O                 !!"
1096         echo "!!  or reexecute this charmc command with -nobs compile option        !!"
1097         echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1098         Abort "Command $soCmd returned error code $Do_res"
1099         fi
1100         Copyobj
1101 }
1102
1103 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ] 
1104 then
1105 # We have no target object, or are playing preprocessor tricks-- just end
1106         Debugf "No target object-- finished"
1107         Success
1108 fi
1109
1110 Debug "About to link..."
1111
1112 case "$OBJECT" in
1113 *.o)
1114         Debugf "Converting $FILES to $OBJECTFILES"
1115         nFiles=`echo $FILES | wc -w`
1116         nObj=`echo $OBJECTFILES | wc -w`
1117 # One source file, one .o: just move the .o
1118         if [ $OBJECT != $OBJECTFILES ]
1119         then
1120                 Debugf "Moving .o to destination"
1121                 DoNoErrCheck $RM $OBJECT
1122                 Do $MV $OBJECTFILES $OBJECT
1123         fi
1124         Copyobj
1125         ;;
1126 *.so|*.sl|*.dylib)
1127 # Make shared library
1128         # if no build share is set, exit normally.
1129         if [ "$BUILD_SHARE" = 0 ]
1130         then
1131                 End 0
1132         elif [ "$CHARM_SHARED" = "0" ]
1133         then
1134                 MakeSO
1135         fi
1136         ;;
1137 *.a)
1138 # Make regular (.a, non-shared) library
1139         # in case building charm so, build .so under lib_so as well # Gengbin
1140         if [ "$BUILD_SHARE" = "1" ]
1141         then
1142           COPY_EXIT=""
1143           OBJECT_SAVE=$OBJECT
1144           COPYTO_SAVE=$COPYTO
1145           if [ -z "$COPYTO" ]
1146           then
1147             DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
1148             OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
1149           else
1150             COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
1151             DESTDIR=$COPYTO
1152           fi
1153           OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
1154           [ -f $DESTDIR/.charmso ] && MakeSO
1155           COPYTO=$COPYTO_SAVE
1156           OBJECT=$OBJECT_SAVE
1157           COPY_EXIT="true"
1158         fi
1159         # build normal .a
1160         DoNoErrCheck $RM $OBJECT
1161         Do $CMK_AR $OBJECT $OBJECTFILES
1162         Do $CMK_RANLIB $OBJECT
1163         Copyobj
1164         ;;
1165 esac
1166 # If the above case returns, we're not creating a .o or .a file,
1167 # so linking is needed.
1168
1169 ############ Determine the language and libraries ##########
1170
1171 # Parse out the real languages
1172 case "$LANGUAGE" in
1173 "charm++f")
1174         LANGUAGE="charm++"
1175         USE_F90_LIBRARIES="1"
1176         ;;
1177 "f90charm")
1178         PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm "
1179         POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1180         ;;
1181 "bluegene")
1182         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bluegene -lconv-bluegene-logs"
1183         ;;
1184 "ckbluegene")
1185         POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1186         ;;
1187 "bgcharm++")
1188         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bluegene -lconv-bluegene-logs -lconv-bluegene-stub"
1189         ;;
1190 "bgconverse++")
1191         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bluegene -lconv-bluegene-logs"
1192         ;;
1193 esac
1194
1195 if [ "$AMPIMAIN" != "" ]
1196 then
1197         OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1198 fi
1199
1200 if [ "$SWAPGLOBALS" = "1" ]
1201 then
1202         swapo="$CHARMLIB/libglobal-swap.o"
1203         if [ ! -r "$swapo" -o ! -s "$swapo" ]
1204         then
1205                 echo "Global-swapping library $swapo missing--"
1206                 echo "  Is -swapglobals supported on this machine?"
1207                 exit 1
1208         else
1209                 OBJECTFILES="$swapo $OBJECTFILES"
1210         fi
1211 fi
1212
1213 if [ $USE_F77_LIBRARIES = "1" ]
1214 then
1215         POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1216 fi
1217
1218 if [ $USE_F90_LIBRARIES = "1" ]
1219 then
1220         if [ ! -r $CHARMLIB/libconv-utilf.a ]
1221         then
1222                 echo "Fortran support library $CHARMLIB/libconv-utilf.a missing"
1223                 echo "Is your Fortran compiler working?"
1224                 exit 1
1225         fi
1226         
1227         POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1228         if [ -z "$SEQUENTIAL" -a ! -z "$CMK_F90OBJS" ] 
1229         then
1230           for f90obj in $CMK_F90OBJS
1231           do
1232             OBJECTFILES="$OBJECTFILES $CHARMLIB/$f90obj"
1233           done
1234         fi
1235 fi
1236
1237 # check if we're linking a sequential object
1238 case "$LANGUAGE" in
1239 "c"|"C"|"f90"|"f77")
1240         if [ -n "$NATIVE" ]
1241         then
1242           Do $CMK_NATIVE_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1243                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1244         else
1245           Do $CMK_SEQ_LD $OPTS_LD -o $OBJECT $OBJECTFILES \
1246                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1247         fi
1248         Copyobj
1249         ;;
1250 "c++"|"C++")
1251         if [ -n "$NATIVE" ]
1252         then
1253           Do $CMK_NATIVE_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1254                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
1255         else
1256           Do $CMK_SEQ_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES \
1257                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
1258         fi
1259         Copyobj
1260         ;;
1261 esac
1262
1263 ##############################################################################
1264 #
1265 # Some quick consistency checks prior to full link-step
1266 #
1267 # Check for valid choice of TRACEMODE
1268 # Check for valid choice of BALANCE
1269 # Check for compatibility among BALANCE and TRACEMODE
1270 #
1271 ##############################################################################
1272
1273 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1274
1275 # Check for valid choice of TRACEMODE
1276
1277 [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed.  Is Charm++ built properly?"
1278
1279 if [ x"$TRACEMODE" != x ]
1280 then
1281 for trace in $TRACEMODE; do
1282 [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
1283 TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1284 done
1285 fi
1286
1287 if test x$LANGUAGE = x"bgcharm++"
1288 then 
1289     BALANCE=bluegene
1290 fi
1291
1292 BAL_EXT=`getExtention $BALANCE`
1293 if [ -z "$BAL_EXT" ]
1294 then
1295 # Balance has no extention-- is a library reference
1296     BAL_OBJ="$CHARMLIB/libldb-$BALANCE.o"
1297 else
1298 # Balance has some extention-- must be a .o or .a file
1299     BAL_OBJ="$BALANCE"
1300 fi
1301
1302 Debug "Finished with BAL_OBJ=$BAL_OBJ, TRACEMODE=$TRACEMODE..."
1303
1304 if [ ! -r "$BAL_OBJ" ]
1305 then
1306         if [ "$BALANCE" = "$BAL_OBJ" ]
1307         then
1308                 Abort "Could not find load balancer object $BAL_OBJ"
1309         else
1310                 (cd $CHARMLIB ; ls -al libldb-*)
1311                 Abort "Unknown load balancer $BALANCE / $BAL_OBJ"
1312         fi
1313 fi
1314
1315
1316 # Check for valid choice of MEMORY
1317
1318 MEM_OBJ="$CHARMLIB/libmemory-$MEMORY.o"
1319
1320 if [ ! -r $MEM_OBJ -o ! -s $MEM_OBJ ] 
1321 then
1322   (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1323   Abort "charmc : No such memory mode $MEMORY"
1324 fi
1325
1326 # Check for valid choice of THREAD
1327
1328 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1329 then
1330   THREAD=$CMK_LD_SHARED_THREAD
1331 fi
1332 THREAD_OBJ="$CHARMLIB/libthreads-$THREAD.o"
1333
1334 if [ ! -r $THREAD_OBJ -o ! -s $THREAD_OBJ ] 
1335 then
1336   (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
1337   Abort "charmc : No such thread mode $THREAD"
1338 fi
1339
1340 ################# Build the module initialization function ##################
1341 modInitName="moduleinit$$"
1342 modInitSrc="$modInitName.C"
1343 modInitObj="$modInitName.o"
1344 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
1345
1346 for module in $MODULES; do
1347     echo "extern void _register$module(void);" >> $modInitSrc
1348 done
1349 for trace in $TRACEMODE; do
1350     if test $trace = "summary" || test $trace = "all"
1351     then
1352       echo "  extern void _registerTraceSummary();" >> $modInitSrc
1353     fi
1354 done
1355 if test -n "$BALANCER"
1356 then
1357     echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
1358 fi
1359 echo "void _registerExternalModules(char **argv) {" >> $modInitSrc
1360 for module in $MODULES; do
1361     [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
1362     echo "  _register$module();" >> $modInitSrc
1363 done
1364 for trace in $TRACEMODE; do
1365     if test $trace = "summary" || test $trace = "all"
1366     then
1367       echo "  _registerTraceSummary();" >> $modInitSrc
1368     fi
1369 done
1370 if test -n "$BALANCER"
1371 then
1372     [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
1373     for deflb in $BALANCER
1374     do
1375       echo "  LBDefaultCreate(\"$deflb\");" >> $modInitSrc
1376     done
1377 fi
1378 echo "}" >> $modInitSrc
1379
1380 # creating projections
1381 echo "void _createTraces(char **argv) {" >> $modInitSrc
1382 for trace in $TRACEMODE; do
1383     [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
1384     echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
1385     echo "_createTrace$trace(argv);" >> $modInitSrc
1386 done
1387 echo "}" >> $modInitSrc
1388
1389 Do $CMK_CXX $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $modInitSrc -o $modInitObj
1390
1391 ###############################################################################
1392 #
1393 #                               Finally, LINK
1394 #
1395 ###############################################################################
1396
1397 Debug "About to perform final link..."
1398
1399 MAKE_LDXX="0"
1400 MAKE_LD="0"
1401
1402 CORE_LIBS="-lconv-core -lconv-util $TRACE_OBJ "
1403
1404 case "$LANGUAGE" in
1405 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1406         MAKE_LDXX="1"
1407         MIDDLE_LIBS="-lck -lconv-cplus-y $CORE_LIBS -lm"
1408         ;;
1409 "converse")
1410         MAKE_LD="1"
1411         MIDDLE_LIBS="-lconv-cplus-n $CORE_LIBS -ltrace-converse -lm"
1412         ;;
1413 "converse++"|"bluegene"|"bgconverse++")
1414         MAKE_LDXX="1"
1415         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-cplus-y $CORE_LIBS -ltrace-converse -lm"
1416         ;;
1417 *)
1418         Abort "Unrecognized choice of language $LANGUAGE"
1419         ;;
1420 esac
1421
1422 if [ "$BUILD_SHARE" = "0" ]
1423 then
1424         MIDDLE_LIBS="$MEM_OBJ $THREAD_OBJ $MIDDLE_LIBS"
1425 fi
1426
1427 if [ "$CHARM_SHARED" = "1" ]
1428 then
1429   [ -z "$CHARMLIBSO" ] &&  Abort "Charm++ lib_so directory not found!"
1430   # build user executable/shared lib linking with charm .so
1431   OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1432   if [ "$BUILD_SHARE" = "1" ]
1433   then
1434     LANG_LIBS="-L$CHARMLIBSO $OBJECTFILES $PRE_LIBRARIES"
1435   else
1436     LANG_LIBS="-L$CHARMLIBSO $BAL_OBJ $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1437   fi
1438 else
1439   LANG_LIBS="-L$CHARMLIB -I$CHARMINC $BAL_OBJ $OBJECTFILES $modInitObj $PRE_LIBRARIES"
1440 fi
1441 ALL_LIBS="$LANG_LIBS $MIDDLE_LIBS $CMK_LIBS $POST_LIBRARIES"
1442
1443 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
1444 then
1445   # build an applicaiton .so linking with charm .so
1446   OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
1447   Debugf "Running ldro..."
1448   DoNoErrCheck $RM $OBJECT
1449   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
1450   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
1451   Copyobj
1452 else
1453 # Make a regular executable: call the appropriate linker
1454   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $OPTS_LD $OPTS_LDXX -o $OBJECT $ALL_LIBS
1455   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $OPTS_LD -o $OBJECT $ALL_LIBS
1456 fi
1457
1458 ########################################################################
1459 #
1460 # Copy conv-host to user directory if it is present in installation.
1461 #
1462 ########################################################################
1463
1464 if test "$COPY_CHARMRUN" = "true"
1465 then
1466 targ=charmrun$CMK_POST_EXE
1467 convhost=conv-host$CMK_POST_EXE
1468
1469 if [ -x $CHARMBIN/$targ ]
1470 then
1471         DoNoErrCheck $RM $targ
1472         Do $CP $CHARMBIN/$targ $targ
1473 fi
1474 fi
1475
1476 DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
1477
1478 Copyobj
1479
1480