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