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