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