Added bluegene emulator sources and test programs.
[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"
16 MV="mv"
17 LN="ln"
18 WC="wc"
19 SED="sed"
20
21 MACHTYPE=""
22 SEQUENTIAL=""
23 LANGUAGE=""
24 BALANCE=""
25 MEMORY=""
26 TRACEMODE=""
27 VERBOSE=""
28 DEBUG_SCRIPT=""
29 SAVE=""
30 PURIFY=""
31 OVERRIDE_CC=""
32 OVERRIDE_CXX=""
33 OVERRIDE_F90=""
34 OVERRIDE_LD=""
35 OVERRIDE_LDXX=""
36 #Generic options, passed to everything
37 OPTS=""
38 #Compiler-only options
39 OPTSC=""
40 #Linker-only options
41 OPTSL=""
42 #Specific options
43 OPTS_CPP=""
44 OPTS_LDRO="" 
45 OPTS_CC=""
46 OPTS_CXX="" 
47 OPTS_F90=""
48 OPTS_LD=""  
49 OPTS_LDXX=""
50
51 OBJECT=""
52 POST_LANGUAGE=""
53 POST_LIBRARIES=""    
54 PRE_LIBRARIES=""    
55 COPIES=""        
56 MODCOPIES=""        
57 FILES=""       
58 OBJECTFILES=""  
59 DELETE=""    
60 MAINOBJ=""   
61 GENCPM=""
62 OPTIMIZE_MODE=""
63 USE_RELIABLE_CC=""
64 USE_FASTEST_CC=""
65 PROG_EXT=""
66
67 ####################################################################
68 #
69 #  Utility routines used below
70 #
71 ###################################################################
72
73 # PrintUsage: prints a helpful command-line usage message and quits
74 # Args: any additional messages
75 printUsage() {
76     echo "Usage: charmc [ flags ] <files>"
77     echo
78     echo "  flags:"
79     echo "        -o <target> -g -O"
80     echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
81     echo "        -machine <mach> -seq -langage <lang> -balance"
82     echo "        -tracemode <mode> -verbose -save -purify -cp"
83     echo "        -use-reliable-cc -use-fastest-cc -gen-cpm <new gen>"
84     echo "        -cc <new cc> -c++ <new CC>  -ld <new ld> -ld++ <new LD>"
85     echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
86     echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
87     echo "        -pg <opt>"
88     echo
89     echo "  Charmc compiles C, C++, f77, f90, Converse, Converse++, Charm, "
90     echo "and Charm++ programs.  The flags generally match those of cc or f77."
91     echo "Version 5.0, Parallel Programming Lab, UIUC, 1999"
92     echo $*
93     exit 1
94 }
95
96 # End blows away the temporary files (unless SAVE is true) and exits
97 # Args: <exit code>
98 End() {
99     if [ -z "$SAVE" ]
100         then
101         for FILE in `echo $FILES`
102         do
103                         BASE=`stripExtention $FILE`
104                         TMP=`basename $FILE`".TMP"
105             $RM $TMP.P.C $TMP.cpp $TMP.space $TMP.xlat $TMP.o
106             $RM $TMP.c $TMP.c.0.h $TMP.c.1.h $TMP.c.2.h
107             $RM $TMP.i $TMP.$CMK_CPP_SUFFIX
108         done
109         $RM core $DELETE
110     fi
111     exit $1
112 }
113
114 # This procedure prints an error message and exits.
115 # ("1>&2" redirects the echo output to stderr).
116 # Args: written to stderr
117 Abort() {
118         echo "Fatal Error by charmc in directory "`pwd` 1>&2
119         echo "   $*" 1>&2
120         echo "charmc exiting..." 1>&2
121         End 1
122 }
123
124 # Instead of an ECHO_CMD variable, I define a procedure Do,
125 # which (possibly) echos, runs, and tests the errors of the given command.
126 # Args: executed as given
127 DoNoErrCheck() {
128         [ -n "$VERBOSE" ] && echo "charmc: Executing $*" 1>&2
129         $*
130 }
131 Do() {
132         DoNoErrCheck $*
133         Do_res=$?
134 # The UNIX result code better be zero, or we die
135         [ $Do_res -eq 0 ] || Abort "Command $* returned error code $Do_res"
136 }
137
138 # This procedure removes the extention (the ".c" in "./main.c") from
139 # its first argument, and prints the result. Unlike the builtin command
140 # basename, it keeps the directory path.
141 # Args: <name to strip>
142 stripExtention() {
143         se_base=`echo $1 | awk -F/ '{print $NF}'`
144         se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
145         se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
146         echo $se_ret
147 }
148
149 # GetExtention returns the extention on the given file name
150 # or "" if none.  (e.g. "./bob/snack.c" returns ".c")
151 # Args: <name to find extention of>
152 getExtention() {
153         se_base=`echo $1 | awk -F/ '{print $NF}'`
154         se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
155         echo $se_ret
156 }
157
158 Debug() {
159     if [ -n "$DEBUG_SCRIPT" ]
160     then
161         echo 
162         echo "------- Charmc Debugging info: $* -------"
163 #       echo "CHARMBIN=$CHARMBIN"
164 #       echo "CHARMINC=$CHARMINC"
165 #       echo "CHARMLIB=$CHARMLIB"
166 #       echo "FILES=$FILES"
167 #       echo "DELETE=$DELETE"
168 #       echo "OBJECT=$OBJECT"
169 #       echo "LANGUAGE=$LANGUAGE"
170 #       echo "Working directory="`pwd`
171     fi
172 }
173
174 # TEMP_BASE is appended with this script's process ID (PID),
175 # so multiple charmcs can run in parallel without overwriting
176 # each other's temporary files.
177 TEMP_BASE="/tmp/charmc_tmp.$$"
178
179 ##############################################################################
180 #
181 # Parse the arguments
182 #
183 # Don't do any analysis in here, just the parsing.
184 #
185 ##############################################################################
186
187 [ $# -eq 0 ] && printUsage "Error: No arguments given."
188
189 while [ ! $# -eq 0 ]
190 do
191         arg="$1"
192         shift
193
194         case "$arg" in
195         "-machine")
196                 MACHTYPE="$1"
197                 shift
198                 ;;
199
200         "-seq")
201                 SEQUENTIAL=true
202                 ;;
203
204         "-language")
205                 LANGUAGE="$1"
206                 POST_LANGUAGE=1
207                 shift
208                 ;;
209
210         "-balance")
211                 BALANCE="$1"
212                 shift
213                 ;;
214
215         "-queue")
216                 echo "Warning: -queue currently being ignored."
217                 shift
218                 ;;
219
220         "-memory")
221                 echo "Warning: -memory currently being ignored."
222                 shift
223                 ;;
224
225         "-tracemode")
226                 TRACEMODE="$1"
227                 shift
228                 ;;
229
230         "-verbose")
231                 echo "Verbose mode set"
232                 VERBOSE=true
233                 ;;
234
235         "-debug-script")
236                 echo "Will give excessive charmc debugging output..."
237                 DEBUG_SCRIPT=true
238                 ;;
239
240         "-save")
241                 SAVE=true
242                 ;;
243
244         "-purify")
245                 PURIFY=true
246                 ;;
247
248         "-use-reliable-cc")
249                 USE_RELIABLE_CC=1
250                 ;;
251
252         "-use-fastest-cc")
253                 USE_FASTEST_CC=1
254                 ;;
255
256         "-cc")
257                 OVERRIDE_CC="$1"
258                 shift
259                 ;;
260
261         "-c++")
262                 OVERRIDE_CXX="$1"
263                 shift
264                 ;;
265
266         "-f90")
267                 OVERRIDE_F90="$1"
268                 shift
269                 ;;
270
271         "-ld")
272                 OVERRIDE_LD="$1"
273                 shift
274                 ;;
275
276         "-ld++")
277                 OVERRIDE_LDXX="$1"
278                 shift
279                 ;;
280
281         "-cpp-option")
282                 OPTS_CPP="$OPTS_CPP $1"
283                 shift
284                 ;;
285
286         "-ldro-option")
287                 OPTS_LDRO="$OPTS_LDRO $1"
288                 shift
289                 ;;
290
291         "-cc-option")
292                 OPTS_CC="$OPTS_CC $1"
293                 shift
294                 ;;
295
296         "-c++-option")
297                 OPTS_CXX="$OPTS_CXX $1"
298                 shift
299                 ;;
300
301         "-f90-option")
302                 OPTS_F90="$OPTS_F90 $1"
303                 shift
304                 ;;
305
306         "-ld-option")
307                 OPTS_LD="$OPTS_LD $1"
308                 shift
309                 ;;
310
311         "-ld++-option")
312                 OPTS_LDXX="$OPTS_LDXX $1"
313                 shift
314                 ;;
315
316         "-rpath")
317                 OPTS_LDXX="$OPTS_LDXX -rpath $1"
318                 shift
319                 ;;
320
321         "-c")
322 # This is ignored.
323                 ;;
324
325         "-o")
326                 OBJECT=$1
327                 shift
328                 ;;
329
330         "-cp")
331                 COPIES="$1 $COPIES"
332                 shift
333                 ;;
334
335         "-cpmod")
336                 MODCOPIES="$1 $MODCOPIES"
337                 shift
338                 ;;
339
340         "-gen-cpm")
341                 GENCPM="$GENCPM $1"
342                 shift
343                 ;;
344
345         -D*|-I*)
346                 OPTSC="$OPTSC $arg"
347                 ;;
348
349         -LANG*)
350                 echo "passing unrecognized option $arg to all compilers and linkers"
351                 OPTSC="$OPTSC  $arg"
352                 ;;
353         -L*)
354                 OPTSL="$OPTSL $arg"
355                 ;;
356
357         "-pg"|"-g")
358                 OPTS="$OPTS $arg"
359                 ;;
360
361         "-O")
362                 OPTIMIZE_MODE=true
363                 ;;
364
365         -O*)
366                 OPTS="$OPTS $arg"
367                 ;;
368
369         "-NO")
370                 OPTIMIZE_MODE=false
371                 ;;
372
373         -l*)
374                 if [ -n "$POST_LANGUAGE" ]
375                 then
376                         POST_LIBRARIES="$POST_LIBRARIES $arg"
377                 else
378                         PRE_LIBRARIES="$PRE_LIBRARIES $arg"
379                 fi
380                 ;;
381
382         -s)
383                 OPTSL="$OPTSL   $arg"
384                 ;;
385
386         -h|--help)
387                 printUsage
388                 ;;
389         -*|+*)
390                 echo "passing unrecognized option $arg to all compilers and linkers"
391                 OPTS="$OPTS  $arg"
392                 ;;
393         *.*)
394                 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
395                 FILES="$FILES $arg"
396                 ;;
397 # Default
398         *)
399                 printUsage  "Error: Unrecognized argument $arg"
400                 ;;
401         esac
402 done
403
404 ##############################################################################
405 #
406 # The following section identifies CHARMBIN, the charm binary-directory.
407 #
408 ##############################################################################
409
410 ORIGDIR=`pwd`
411
412 # Try to find CHARMBIN by looking in directory where charmc is
413
414 if [ -z "$CHARMBIN" ]
415 then
416         SCRIPT=$0
417         CHARMBIN=`dirname $SCRIPT`
418         cd $CHARMBIN
419         CHARMBIN=`pwd`
420 # NOTE: this script no longer tries to follow soft links
421 # to find the "original" charmc-- if this is bad, 
422 # translate these lines to Bourne shell from C shell:
423 # -------------------- Begin C Shell ------------------------->
424 #    if ($SCRIPT:h != $SCRIPT:t) then
425 #        cd $SCRIPT:h
426 #        set SCRIPT=$SCRIPT:t
427 #    else
428 #        foreach dir ($path)
429 #            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
430 #                cd $dir
431 #                break
432 #            endif
433 #        end
434 #    endif
435 #    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
436 #        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
437 #        if ($SCRIPT:h != $SCRIPT:t) then
438 #            cd $SCRIPT:h
439 #            set SCRIPT=$SCRIPT:t
440 #        endif
441 #    end
442 #    set CHARMBIN=`pwd`
443 # <------------------ End C Shell -----------------------------
444 fi
445
446 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
447 if [ "$FIRST_THREE" = "CYG" ]
448 then
449 # Running on a windows system-- append .exe to file names
450         PROG_EXT=".exe"
451 fi
452
453 if [ -n "$MACHTYPE" ]
454 then
455     if [ -d $CHARMBIN/../../$MACHTYPE/bin ]
456     then
457                 cd $CHARMBIN/../../$MACHTYPE/bin
458                 CHARMBIN=`pwd`
459     else
460         Abort "there is no installed charm for $MACHTYPE in $CHARMBIN"
461     fi
462 fi
463
464 if [ -z "$CHARMLIB" ]
465 then
466         cd $CHARMBIN/../lib
467         CHARMLIB=`pwd`
468 fi
469 if [ -z "$CHARMINC" ]
470 then
471         cd $CHARMBIN/../include
472         CHARMINC=`pwd`
473 fi
474
475 cd $ORIGDIR
476
477 ##############################################################################
478 #
479 # Load machine-specific configuration data, then handle overrides to it.
480 #
481 ##############################################################################
482
483 if [ ! -r $CHARMINC/conv-mach.sh ]
484 then
485         Abort "Can't find conv-mach.sh in $CHARMINC directory."
486 fi
487
488 Debug "About to read machine config script"
489 . $CHARMINC/conv-mach.sh
490
491 Debug "Read config script, setting vars..."
492
493 if [ -n "$USE_RELIABLE_CC" ]
494 then
495         CMK_CC="$CMK_CC_RELIABLE"
496 fi
497
498 if [ -n "$USE_FASTEST_CC" ]
499 then
500     CMK_CC="$CMK_CC_FASTEST"
501 fi
502
503 if [ -n "$CMK_F90_USE_MODDIR" ]
504 then
505     CMK_CF90="$CMK_CF90 -M$CHARMINC "
506 fi
507
508 if [ -n "$SEQUENTIAL" ]
509 then
510     CMK_CC="$CMK_SEQ_CC -DCMK_SEQUENTIAL=1 "
511     CMK_LD="$CMK_SEQ_LD"
512     CMK_CXX="$CMK_SEQ_CXX -DCMK_SEQUENTIAL=1 " 
513     CMK_F90="$CMK_SEQ_F90 -DCMK_SEQUENTIAL=1 " 
514     CMK_LDXX="$CMK_SEQ_LDXX" 
515     if [ -n "$CMK_SEQ_AR" ]
516     then
517       CMK_AR="$CMK_SEQ_AR"
518     fi
519     if [ -n "$CMK_SEQ_RANLIB" ]
520     then
521       CMK_RANLIB="$CMK_SEQ_RANLIB"
522     fi
523 fi
524
525 if [ -n "$OVERRIDE_CC" ]
526 then
527     CMK_CC="$OVERRIDE_CC $CMK_CC "
528 fi
529 Debug "set 2"
530 if [ -n "$OVERRIDE_CXX" ]
531 then
532     CMK_CXX="$OVERRIDE_CXX $CMK_CXX "
533 fi
534
535 if [ -n "$OVERRIDE_F90" ]
536 then
537     CMK_F90="$OVERRIDE_F90 $CMK_F90 "
538 fi
539
540 if [ -n "$OVERRIDE_LD" ]
541 then
542     CMK_LD="$OVERRIDE_LD $CMK_LD"
543 fi
544
545 if [ -n "$PURIFY" ]
546 then
547     CMK_LD="purify $CMK_LD"
548     CMK_LDXX="purify $CMK_LDXX"
549 fi
550
551 if [ -n "$OVERRIDE_LDXX" ]
552 then
553     CMK_LDXX="$OVERRIDE_LDXX $CMK_LDXX"
554 fi
555
556 Debug "set 4"
557 if [ -n "$OPTIMIZE_MODE" ]
558 then
559     OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
560     OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
561     OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
562     OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
563     OPTS_LDXX="$CMK_CXX_OPTIMIZE $OPTS_LDXX"
564 fi
565
566 #Add generic options to the compiler- and linker-options
567 OPTSC="$OPTS $OPTSC"
568 OPTSL="$OPTS $OPTSL"
569
570 # There's really no analog for this in the Bourne shell: 
571 #  -------- C Shell ------> onintr failure
572 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
573
574 ##############################################################################
575 #
576 # Check for valid choice of LANGUAGE
577 #
578 ##############################################################################
579 Debug "Checking language..."
580
581 if [ -z "$LANGUAGE" ]
582 then
583     LANGUAGE="charm++"
584     [ -n "$SEQUENTIAL" ] && LANGUAGE=c
585 fi
586
587 case "$LANGUAGE" in
588 "c"|"C"|"c++"|"C++")
589         [ -z "$SEQUENTIAL" ] && Abort "Language $LANGUAGE is for sequential programs"
590         ;;
591 "charm"|"charm++"|"converse"|"converse++"|"idl")
592         [ -z "$SEQUENTIAL" ] || Abort "Language $LANGUAGE is for parallel programs"
593         ;;
594 "fem"|"femf"|"ampi"|"ampif"|"f90charm"|"bluegene")
595         [ -z "$SEQUENTIAL" ] || Abort "Language $LANGUAGE is for parallel programs"
596         ;;
597 *)
598         Abort "Unrecognized choice of language $LANGUAGE"
599         ;;
600 esac
601
602 ########################################################################
603 #
604 # We've parsed and verified the command-line parameters.
605 # Now we prepare routines to clean up and exit.
606 # None of these routines ever returns-- they all just exit.
607 #
608 ########################################################################
609
610
611 Copyobj() {
612         for COPY in `echo $COPIES`
613         do
614                 if [ "a$COPY" != "a$OBJECT" ] 
615                 then
616                         [ -d $COPY ] && COPY="$COPY/"
617                         if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
618                                 echo "Appending $PROG_EXT to object file name"
619                                 OBJECT="$OBJECT$PROG_EXT"
620                         fi
621                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
622                         Do $CP $OBJECT $COPY
623                 fi
624         done
625         Success
626 }
627
628 Copymod() {
629         for COPY in `echo $MODCOPIES`
630         do
631                 if [ "a$COPY" != "a$OBJECT" ] 
632                 then
633                         [ -d $COPY ] && COPY="$COPY/"
634                         if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
635                           OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
636                         fi
637                         if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
638                           echo "Appending .$CMK_MOD_EXT to object file name"
639                           OBJECT="$OBJECT.$CMK_MOD_EXT"
640                         fi
641                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
642                         Do $CP $OBJECT $COPY
643                 fi
644         done
645         Success
646 }
647
648 Success() {
649         End 0
650 }
651
652
653 ##############################################################################
654 #
655 # Preprocess the GEN-CPM files
656 #
657 ##############################################################################
658
659 Debug "Preprocessing GEN-CPM files"
660
661 for FILE in `echo $GENCPM`
662 do
663 # This used to be "$FILE:r", which strips the extention
664         BASE=`stripExtention $FILE`
665         TMP=`basename $FILE`".TMP"
666         DELETE="$DELETE $TMP.c $TMP.i"
667         DoNoErrCheck $RM $BASE.cpm.h $TMP.c
668         Do touch $BASE.cpm.h
669         Do $LN -f -s $FILE $TMP.c
670         Do $CMK_CPP_C $OPTSC $OPTS_CPP -I$CHARMINC $TMP.c > $TMP.i
671         Do $CHARMBIN/conv-cpm $TMP.i $BASE.cpm.h
672 done
673
674 ##############################################################################
675 #
676 # Compile all specified files
677 #
678 # All temporary files named *.TMP.* for easy cleanup.
679 #
680 ##############################################################################
681
682 Debug "About to compile..."
683
684 for FILE in `echo $FILES`
685 do
686         BASE=`stripExtention $FILE`
687         TMP=`basename $FILE`".TMP"
688         FILE_EXT=`getExtention $FILE`
689         if [ "$FILE_EXT" != ".o" ]
690         then
691                 [ $VERBOSE ] && echo "Compiling $FILE"
692                 DoNoErrCheck $RM $BASE.o $BASE.f.o
693         fi
694         NU_OBJ=""
695         case "$FILE" in
696         *.ci)
697                 if [ "$LANGUAGE" = "f90charm" ]
698                 then
699                     Do $CHARMBIN/charmxi -f90 $CMK_XIOPTS $BASE.ci
700                 else
701                     Do $CHARMBIN/charmxi $CMK_XIOPTS $BASE.ci
702                 fi
703                 ;;
704         *.idl)
705                 Do $CHARMBIN/charmidl $BASE.idl
706                 ;;
707         *.sdag)
708                 Do $CHARMBIN/sdagx $BASE.sdag
709                 ;;
710         *.c|*.s)
711                 Do $CMK_CC $OPTSC $OPTS_CC -I$CHARMINC -c $FILE -o $BASE.o
712                 NU_OBJ=$BASE.o
713                 ;;
714         *.C|*.cc|*.cxx|*.cpp|*.c++)
715                 Do $CMK_CXX $OPTSC $OPTS_CXX -I$CHARMINC -c $FILE -o $BASE.o
716                 NU_OBJ=$BASE.o
717                 ;;
718         *.f|*.F)
719                 Do $CMK_CF90 $OPTSC $OPTS_F90 -freeform -I$CHARMINC -c $FILE -o $BASE.o
720                 NU_OBJ=$BASE.o
721                 ;;
722         *.f90|*.F90)
723                 Do $CMK_CF90 $OPTSC $OPTS_F90 -I$CHARMINC -c $FILE -o $BASE.o
724                 ;;
725         *.fc|*.FC)
726                 Abort "I'm not yet smart enough to compile $FILE"
727                 ;;
728         *.o|*.a)
729                 OBJECTFILES="$OBJECTFILES $FILE"
730                 ;;
731         *.M|*.mod)
732                 OBJECT="$BASE"
733                 Copymod
734                 Success
735                 ;;
736         *)
737                 Abort "file with unrecognized extension $FILE"
738         esac
739 # Handle new object files
740         if [ -n "$NU_OBJ" -a -n "$OBJECT" ] 
741         then
742                 if [ "$OBJECT" != "$BASE.o" ]
743                 then
744                         DELETE="$DELETE $NU_OBJ"
745                 fi
746                 OBJECTFILES="$OBJECTFILES $NU_OBJ"
747         fi
748 done
749
750 ##############################################################################
751 #
752 #                        POSSIBLY, SKIP LINK-STEP
753 #
754 # 1. No $OBJECT may be specified at all --- its just a compilation.
755 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
756 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
757 # 4. Language may be sequential.  Do a quick and easy linkage.
758 #
759 #               in any of these cases, the full link step is skipped.
760 #
761 ##############################################################################
762
763 if [ -z "$OBJECT" ] 
764 then
765 # We have no target object-- just end
766         Success
767 fi
768
769 Debug "About to link..."
770
771 case "$OBJECT" in
772 *.o)
773         nFiles=`echo $FILES | wc -w`
774         nObj=`echo $OBJECTFILES | wc -w`
775         if [ $nFiles -eq 1 -a $nObj -eq 1 ] 
776         then
777                 if [ $OBJECT != $OBJECTFILES ]
778                 then
779                         DoNoErrCheck $RM $OBJECT
780                         Do $MV $OBJECTFILES $OBJECT
781                 fi
782         else
783                 DoNoErrCheck $RM $OBJECT
784                 Do $CMK_LDRO $OBJECT $OPTSL $OPTS_LDRO $OBJECTFILES
785         fi
786         Copyobj
787         ;;
788 *.a)
789         DoNoErrCheck $RM $OBJECT
790         Do $CMK_AR $OBJECT $OBJECTFILES
791         Do $CMK_RANLIB $OBJECT
792         Copyobj
793         ;;
794 esac
795 # If the above case returns, we're not creating a .o or .a file--
796 # check if we're linking a sequential object
797
798 case "$LANGUAGE" in
799 "c"|"C"|"f90"|"f77")
800         Do $CMK_SEQ_LD $OPTSL $OPTS_LD -o $OBJECT $OBJECTFILES -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
801         Copyobj
802         ;;
803 "c++"|"C++")
804         Do $CMK_SEQ_LDXX $OPTSL $OPTS_LD -o $OBJECT $OBJECTFILES -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
805         Copyobj
806         ;;
807 esac
808
809 ##############################################################################
810 #
811 # Some quick consistency checks prior to full link-step
812 #
813 # Check for valid choice of TRACEMODE
814 # Check for valid choice of BALANCE
815 # Check for compatibility among BALANCE and TRACEMODE
816 #
817 ##############################################################################
818
819 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
820
821 # Check for valid choice of TRACEMODE
822
823 [ -r $CHARMLIB/libtrace-none.a ] || Abort "trace libraries not installed."
824
825 [ -z "$TRACEMODE" ] && TRACEMODE="none"
826
827 [ ! -r $CHARMLIB/libtrace-$TRACEMODE.a ] && Abort "charmc : No such tracemode $TRACEMODE"
828
829
830 # Check for valid choice of BALANCE
831
832 [ -z "$BALANCE" ] && BALANCE=rand
833
834 if [ "$TRACEMODE" = replay ]
835 then
836         [ "$BALANCE" != replay ] && echo "Ignoring -balance $BALANCE, incompatible with -tracemode replay"
837     BALANCE=replay
838 fi
839
840 BAL_EXT=`getExtention $BALANCE`
841 if [ -z "$BAL_EXT" ]
842 then
843 # Balance has no extention-- is a library reference
844     BAL_OBJ="$CHARMLIB/libldb-$BALANCE.o"
845 else
846 # Balance has some extention-- must be a .o or .a file
847     BAL_OBJ="$BALANCE"
848 fi
849
850 Debug "Finished with BAL_OBJ=$BAL_OBJ, TRACEMODE=$TRACEMODE..."
851
852 if [ ! -r "$BAL_OBJ" ]
853 then
854         if [ "$BALANCE" = "$BAL_OBJ" ]
855         then
856                 Abort "Could not find load balancer object $BAL_OBJ"
857         else
858                 (cd $CHARMLIB ; ls -al libldb-*)
859                 Abort "Unknown load balancer $BALANCE / $BAL_OBJ"
860         fi
861 fi
862
863 ###############################################################################
864 #
865 #                               Finally, LINK
866 #
867 ###############################################################################
868
869 Debug "About to perform final link..."
870
871 case "$LANGUAGE" in
872 "ampi")
873         PRE_LIBRARIES="$PRE_LIBRARIES -lampi -lddt "
874         POST_LIBRARIES="$POST_LIBRARIES -lmetis"
875         ;;
876 "ampif")
877         PRE_LIBRARIES="$PRE_LIBRARIES -lampif -lddt -lconv-utilf "
878         POST_LIBRARIES="$POST_LIBRARIES -lmetis $CMK_F90LIBS"
879         if [ ! -z "$CMK_F90OBJS" ] 
880         then
881           for f90obj in $CMK_F90OBJS
882           do
883             OBJECTFILES="$OBJECTFILES $CHARMLIB/$f90obj"
884           done
885         fi
886         ;;
887 "fem")
888         PRE_LIBRARIES="$PRE_LIBRARIES -lfem -lddt "
889         POST_LIBRARIES="$POST_LIBRARIES -lmetis "
890         ;;
891 "femf")
892         PRE_LIBRARIES="$PRE_LIBRARIES -lfemf -lddt -lconv-utilf"
893         POST_LIBRARIES="$POST_LIBRARIES -lmetis $CMK_F90LIBS"
894         if [ ! -z "$CMK_F90OBJS" ] 
895         then
896           for f90obj in $CMK_F90OBJS
897           do
898             OBJECTFILES="$OBJECTFILES $CHARMLIB/$f90obj"
899           done
900         fi
901         ;;
902 "f90charm")
903         PRE_LIBRARIES="$PRE_LIBRARIES lib/libmain.a "
904         POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
905         if [ ! -z "$CMK_F90OBJS" ] 
906         then
907           for f90obj in $CMK_F90OBJS
908           do
909             OBJECTFILES="$OBJECTFILES $CHARMLIB/$f90obj"
910           done
911         fi
912         ;;
913 "bluegene")
914         POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
915         ;;
916 esac
917
918 LANG_LIBS="-L$CHARMLIB -I$CHARMINC $BAL_OBJ $OBJECTFILES $PRE_LIBRARIES -lck $POST_LIBRARIES"
919 CORE_LIBS="-lconv-core -lconv-util -ltrace-$TRACEMODE"
920
921 case "$LANGUAGE" in
922 "charm"|"charm++")
923         Do $CMK_LDXX $OPTSL $OPTS_LDXX -o $OBJECT \
924                 $LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
925         ;;
926 "f90charm")
927         Do $CMK_LDXX $OPTSL $OPTS_LDXX -o $OBJECT \
928                 $LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
929         ;;
930 "idl")
931         Do $CMK_LDXX $OPTSL $OPTS_LDXX -o $OBJECT \
932                 $LANG_LIBS -lconv-cplus-y $CORE_LIBS -lidl -lm $CMK_LIBS
933         ;;
934 "ampi"|"ampif"|"fem"|"femf"|"bluegene")
935         Do $CMK_LDXX $OPTSL $OPTS_LDXX -o $OBJECT \
936                 $LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
937         ;;
938 "converse")
939         Do $CMK_LD $OPTSL $OPTS_LD -o $OBJECT \
940                 $LANG_LIBS -lconv-cplus-n $CORE_LIBS -lm $CMK_LIBS
941         ;;
942 "converse++")
943         Do $CMK_LDXX $OPTSL $OPTS_LDXX -o $OBJECT \
944                 $LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
945         ;;
946 esac
947
948 ########################################################################
949 #
950 # Copy conv-host to user directory if it is present in installation.
951 #
952 ########################################################################
953
954 targ=charmrun$CMK_POST_EXE
955 convhost=conv-host$CMK_POST_EXE
956
957 if [ -x $CHARMBIN/$targ ]
958 then
959         DoNoErrCheck $RM $targ
960         Do $CP $CHARMBIN/$targ $targ
961         [ ! -f $convhost ] && Do $LN -f -s $targ $convhost
962 fi
963
964 Copyobj
965