Update README and charmc year from 2018 to 2019
[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 STANDALONE=""
25 LANGUAGE=""
26 PARADIGM=""
27 BALANCE="rand"
28 TRACEMODE=""
29 TRACE_OBJ=
30 MEMORY="default"
31 THREAD="default"
32 VERBOSE=""
33 DEBUG_SCRIPT=""
34 SAVE=""
35 PURIFY=""
36 SKIPLINK=""
37 OVERRIDE_CC=""
38 OVERRIDE_CXX=""
39 OVERRIDE_F90=""
40 OVERRIDE_LD=""
41 OVERRIDE_LDXX=""
42 #Generic options, passed to everything
43 OPTS=""
44 #Specific options
45 #charm internal flag, only pass to c and cxx, not f90
46 OPTS_CPP_INTERNAL="-D__CHARMC__=1"
47 OPTS_CPP=
48 OPTS_LDRO="" 
49 OPTS_CC=""
50 OPTS_CC_GENCPM=""
51 OPTS_CXX="" 
52 OPTS_F90=""
53 OPTS_LD=""  
54 OPTS_PIC=""
55 USE_PIC="0"
56
57 CHARMDEBUG=""
58 LINK_PYTHON=""
59 OBJECT=""
60 EXPLICIT_OBJECT="no"
61 EXPLICIT_COMPILATION="no"
62 POST_LANGUAGE=""
63 POST_LIBRARIES=""    
64 PRE_LIBRARIES=""  
65 USE_F90_LIBRARIES="0"  
66 USE_F77_LIBRARIES="0"  
67 F90_MODDIR=
68 AMPIMAIN=""
69 AMPIF=""
70 COPYTO=""        
71 MODCOPIES=""        
72 MODULES=""
73 BALANCER=""
74 FILES=""       
75 OBJECTFILES=""  
76 DELETE=""    
77 MAINOBJ=""   
78 GENCPM=""
79 OPTIMIZE_MODE=""
80 PRODUCTION_MODE=""
81 USE_RELIABLE_CC=""
82 USE_FASTEST_CC=""
83 PROG_EXT=""
84 GENDEPENDS="no"
85 COUNTTOKENS="no"
86 USE_OPENMP="no"
87 SKIP_MODULEINIT=""
88 RPATH_ORIGIN=""
89 LINK_WHOLE_ARCHIVE=""
90 LINK_CXX_STL=""
91
92 COPY_CHARMRUN=true
93 USE_BUILD_OPTIONS=0
94
95 COPY_EXIT="true"
96 CHARM_SHARED="0"
97 BUILD_SHARE="0"
98 SWAPGLOBALS="0"
99 TLSGLOBALS="0"
100 ROSE_OMP_TLS_GLOBALS="no"
101 PRINT_BUILDING_BLOCKS=""
102 NOABORT=""
103
104 TAU_MAKEFILE=Make.tau
105 TAU_TRACE_MPI=1
106
107 CMK_CELL=0
108 SPU_USE_CPP=0
109 SPU_EXTRA_LIBS=""
110
111 MPI_INTEROPERATE=""
112 NO_MAIN_MODULE=""
113 NO_MAIN=""
114 CUSTOM_PARTITION=""
115 PREPROCESS_CI="yes"
116 INPUT_GIVEN=""
117
118 ####################################################################
119 #
120 #  Utility routines used below
121 #
122 ###################################################################
123
124 # PrintUsage: prints a helpful command-line usage message and quits
125 # Args: any additional messages
126 printUsage() {
127     printVersion
128     echo 
129     echo "Usage: charmc [ flags ] <files>"
130     echo
131     echo "  flags:"
132     echo "        -o <target> -g -O"
133     echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
134     echo "        -machine <mach> -seq -host -language <lang> -pg <opt>"
135     echo "        -balance <mode> -tracemode <mode> -memory <mode>"
136     echo "        -modules <comma-separated list of C++ modules> -thread"
137     echo "        -debug-script -count-tokens -default-to-aout -E -S -M"
138     echo "        -verbose -save -purify -cp <dest> -cpmod -gen-cpm <pkg>"
139     echo "        -swapglobals -tlsglobals -roseomptlsglobals"
140     echo "        -use-reliable-cc -use-fastest-cc -use-new-std"
141     echo "        -cc <new cc> -c++ <new CC> -ld <new ld> -ld++ <new LD>"
142     echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
143     echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
144     echo "        -f90 <new f90> -f90-option <opt> -fmoddir <f90mod path>"
145     echo "        -flibs -rpath <path> -custom-part -touch-on-failure"
146     echo "        -mpi -openmp -no-trace-mpi -build-shared -charm-shared"
147     echo "        -no-charmrun -no-preprocess-ci -nomain-module -nomain"
148     echo "        -nof90main -f90main"
149     echo
150     echo "  Charmc compiles C, C++, f77, f90, AMPI, Converse, Converse++, Charm, "
151     echo "and Charm++ programs.  The flags generally match those of cc or f77."
152     echo "  Other options that are not listed here will be passed directly to the"
153     echo "underlying compiler and/or linker."
154     echo "Parallel Programming Lab, UIUC, 2019."
155     echo $*
156     exit 1
157 }
158
159 # End blows away the temporary files (unless SAVE is true) and exits
160 # Args: <exit code>
161 End() {
162     if [ -z "$SAVE" ]
163         then
164         for FILE in `echo $FILES`
165         do
166             #BASE=`stripExtention $FILE`
167             MYTMP=`basename $FILE`".TMP"
168             $RM $MYTMP.P.C $MYTMP.cpp $MYTMP.space $MYTMP.xlat $MYTMP.o
169             $RM $MYTMP.c $MYTMP.c.0.h $MYTMP.c.1.h $MYTMP.c.2.h
170             $RM $MYTMP.i $MYTMP.$CMK_CPP_SUFFIX
171         done
172         $RM core $DELETE
173         if [ -z "$SKIP_MODULEINIT" -a -n "$modInitObj" ]
174         then
175             [ -n "$VERBOSE" ] && echo $RM $modInitSrc $modInitObj
176             DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
177         fi
178     fi
179     exit $1
180 }
181
182 # Write this error message to stderr
183 # ("1>&2" redirects the echo output to stderr).
184 Warning() {
185         echo "$@" 1>&2
186 }
187
188 # This procedure prints an error message and exits.
189 # Args: written to stderr
190 Abort() {
191         Warning "Fatal Error by charmc in directory "`pwd`
192         Warning "   $@"
193         Warning "charmc exiting..."
194         End 1
195 }
196
197
198 # Instead of an ECHO_CMD variable, I define a procedure Do,
199 # which (possibly) echos, runs, and tests the errors of the given command.
200 # Args: executed as given
201 DoNoErrCheck() {
202         [ -n "$VERBOSE" ] && echo "charmc: Executing $@" 1>&2
203         eval "$@"
204 }
205
206 Do() {
207         DoNoErrCheck "$@"
208         Do_res=$?
209 # The UNIX result code better be zero, or we die
210         [ $Do_res -eq 0 -o -n "$NOABORT" ] || Abort "Command $@ returned error code $Do_res"
211 }
212
213 # This procedure removes the extention (the ".c" in "./main.c") from
214 # its first argument, and prints the result. Unlike the builtin command
215 # basename, it keeps the directory path.
216 # Args: <name to strip>
217 stripExtention() {
218         se_base=`basename $1`
219 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
220         se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
221         se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
222         echo $se_ret
223 }
224
225 # GetExtention returns the extention on the given file name
226 # or "" if none.  (e.g. "./bob/snack.c" returns ".c")
227 # Args: <name to find extention of>
228 getExtention() {
229 #       se_base=`echo $1 | awk -F/ '{print $NF}'`
230 #        se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
231 #       echo $se_ret
232         se_ret=`echo $1 | sed -e 's/.*\././'`
233         if test "$se_ret" = $1
234         then
235           echo ""
236         else
237           echo $se_ret
238         fi
239 }
240
241 Debugf() {
242         [ -n "$VERBOSE" ] && echo "charmc>" $@
243 }
244
245 Debug() {
246     if [ -n "$DEBUG_SCRIPT" ]
247     then
248         echo 
249         echo "------- Charmc Debugging info: $* -------"
250         echo "CHARMBIN=$CHARMBIN"
251         echo "CHARMINC=$CHARMINC"
252         echo "CHARMLIB=$CHARMLIB"
253         echo "FILES=$FILES"
254         echo "DELETE=$DELETE"
255         echo "OBJECT=$OBJECT"
256         echo "LANGUAGE=$LANGUAGE"
257         echo "PARADIGM=$PARADIGM"
258 #       echo "Working directory="`pwd`
259     fi
260 }
261
262 # Return success if $1 is not in any of the other arguments
263 notInList() {
264         search=$1
265         shift
266         while [ $# -gt 0 ]
267         do
268                 if [ "$search" = "$1" ]
269                 then
270                         # It's already in there-- fail
271                         return 1
272                 fi
273                 shift
274         done
275         # It's missing--succeed
276         return 0
277 }
278
279 # Add arguments to our modules list, avoiding duplicates
280 AddModules() {
281     for M in "$@"
282     do
283       notInList $M $MODULES && MODULES="$MODULES $M"
284     done
285 }
286
287 # Add this word to this list, avoiding duplicates
288 AddList() {
289     ret=""
290     while [ $# -gt 1 ]
291     do
292         ret="$ret $1"
293         shift
294     done
295     if notInList $1 $ret
296     then
297         ret="$ret $1"
298     fi
299     echo $ret
300 }
301
302 # Drop the first argument anywhere it appears in the subsequent list
303 DropList() {
304     drop="$1"
305     shift
306
307     ret=""
308     while [ $# -gt 1 ]
309     do
310         if [ "$1" != "$drop" ]; then
311             ret="$ret $1"
312         fi
313         shift
314     done
315
316     echo $ret
317 }
318
319 # TEMP_BASE is appended with this script's process ID (PID),
320 # so multiple charmcs can run in parallel without overwriting
321 # each other's temporary files.
322 TEMP_BASE="/tmp/charmc_tmp.$$"
323
324 # Try to find CHARMBIN by looking in directory where charmc is
325 findCharmBin() {
326 if [ -z "$CHARMBIN" ]
327 then
328         SCRIPT=$1
329         CHARMBIN=`dirname $SCRIPT`
330 #       CHARMBIN=`cd $CHARMBIN; pwd`
331 # NOTE: this script no longer tries to follow soft links
332 # to find the "original" charmc-- if this is bad, 
333 # translate these lines to Bourne shell from C shell:
334 # -------------------- Begin C Shell ------------------------->
335 #    if ($SCRIPT:h != $SCRIPT:t) then
336 #        cd $SCRIPT:h
337 #        set SCRIPT=$SCRIPT:t
338 #    else
339 #        foreach dir ($path)
340 #            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
341 #                cd $dir
342 #                break
343 #            endif
344 #        end
345 #    endif
346 #    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
347 #        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
348 #        if ($SCRIPT:h != $SCRIPT:t) then
349 #            cd $SCRIPT:h
350 #            set SCRIPT=$SCRIPT:t
351 #        endif
352 #    end
353 #    set CHARMBIN=`pwd`
354 # <------------------ End C Shell -----------------------------
355 fi
356 }
357
358 printVersion()
359 {
360         findCharmBin $0
361         version=`cat $CHARMBIN/../include/VERSION`
362         echo Charm++ Version $version
363 }
364
365
366 ##############################################################################
367 #
368 # The following section identifies CHARMBIN, the charm binary-directory.
369 #
370 ##############################################################################
371
372 ORIGDIR=`pwd`
373
374 # Try to find CHARMBIN by looking in directory where charmc is
375
376 findCharmBin $0
377
378 UNAME=`uname -s`
379 FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
380 if [ "$FIRST_THREE" = "CYG" -o "$UNAME" = "Interix" ]
381 then
382 # Running on a windows system-- append .exe to file names
383         PROG_EXT=".exe"
384 fi
385
386 CHARMLIB="$CHARMBIN/../lib"
387 CHARMINC="$CHARMBIN/../include"
388 CHARMLIBSO=
389 if test -d "$CHARMBIN/../lib_so" 
390 then
391   CHARMLIBSO=`cd $CHARMBIN/../lib_so 2>/dev/null && pwd`
392   #getting absolute path is harder than thought because of symbolic links and ..
393   #ksh needs cd -P to resolve werid symbolic links, however -P is not portable
394   #csh is ok too if it exists 
395   test -z "$CHARMLIBSO" && CHARMLIBSO=`cd -P $CHARMBIN/../lib_so 2>/dev/null && pwd`
396   test -z "$CHARMLIBSO" && CHARMLIBSO=`csh -c "cd $CHARMBIN/../lib_so >& /dev/null && pwd"`
397   test -z "$CHARMLIBSO" && echo "$CHARMBIN/../lib_so: not found" && exit 1
398 fi
399
400 ##############################################################################
401 #
402 # Parse the arguments
403 #
404 # Don't do any analysis in here, just the parsing.
405 #
406 ##############################################################################
407
408 [ $# -eq 0 ] && printUsage "Error: No arguments given."
409
410 processArgs() {
411 while [ ! $# -eq 0 ]
412 do
413         arg="$1"
414         shift
415
416         case "$arg" in
417         "-V")
418                 printVersion
419                 exit 0
420                 ;;
421
422         "-machine")
423                 MACHTYPE="$1"
424                 shift
425                 ;;
426
427         "-seq")
428                 SEQUENTIAL=true
429                 ;;
430
431         "-host")
432                 NATIVE=true
433                 ;;
434
435         "-standalone")
436                 STANDALONE="true"
437                 SKIP_MODULEINIT="yes"
438                 ;;
439
440         "-language")
441                 # Parse out some fake languages (that are actually modules)
442                 case "$1" in
443                 "ampi") AddModules tcharmmain ampi ;;
444                 "ampif") AddModules tcharmmain ampif ; USE_F90_LIBRARIES="1" ; AMPIF="1" ;;
445                 "armci") AddModules tcharmmain armci ;;
446                 "armcif") AddModules tcharmmain armci ; USE_F90_LIBRARIES="1" ;;
447                 "fem") AddModules tcharmmain fem ; AMPIMAIN="femmain";;
448                 "femf") AddModules tcharmmain fem ; AMPIMAIN="femmain"; USE_F90_LIBRARIES="1" ;;
449                 "ParFUM_TOPS") AddModules tcharmmain ParFUM ParFUM_TOPS ; AMPIMAIN="ParFUMmain";;
450     "ParFUM") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain";;
451     "ParFUMf") AddModules tcharmmain ParFUM ; AMPIMAIN="ParFUMmain"; USE_F90_LIBRARIES="1" ;;
452                 "mblock") AddModules tcharmmain mblock ;;
453                 "mblockf") AddModules tcharmmain mblock ; USE_F90_LIBRARIES="1" ;;
454
455                 "charm"|"charm++"|"charm++f"|"f90charm"|"converse"|"converse++"|"bgcharm++"|"bgconverse++"|"bluegene"|"ckbluegene"|"bigsim")
456                         PARADIGM="$1"
457                         POST_LANGUAGE=1
458                         ;;
459
460                 *) 
461                         LANGUAGE="$1"
462                         POST_LANGUAGE=1
463                         ;;
464                 esac
465                 shift
466                 ;;
467
468         "-debug")
469                 # Requested support from charmdebug: add some modules and libraries
470                 CHARMDEBUG=1
471                 MEMORY="charmdebug"
472                 ;;
473
474         "-module"|"-modules")
475                 AddModules `echo $1 | sed -e 's/,/ /g'`
476                 INPUT_GIVEN="1"
477                 shift
478                 ;;
479
480         "-balancer")
481 #                test -n "$BALANCER" && Abort "More than one -balancer specified!"
482                 BALANCER="$BALANCER $1"
483                 mod=`echo $1| sed -e 's/:/ /' -e 's/,/ /g'`
484                 AddModules $mod
485                 shift
486                 ;;
487
488         "-balance")
489                 BALANCE="$1"
490                 shift
491                 ;;
492
493         "-queue")
494                 Warning "Warning: -queue currently being ignored."
495                 shift
496                 ;;
497
498         "-memory")
499                 MEMORY="$1"
500                 shift
501                 ;;
502
503         "-thread")
504                 THREAD="$1"
505                 shift
506                 ;;
507
508         "-tracemode")
509                 TRACEMODE_NEW=`AddList $TRACEMODE $1`
510                 if [ "$TRACEMODE_NEW" = "$TRACEMODE" ]
511                 then
512                         Warning "Warning: Duplicate tracemode $1 ignored"
513                 else
514                         TRACEMODE=$TRACEMODE_NEW
515                 fi
516                 shift
517                 ;;
518         "-no-trace-mpi")
519                 TAU_TRACE_MPI=0
520                 ;;
521         
522         "-swapglobal"|"-swapglobals")
523                 SWAPGLOBALS="1"
524                 USE_PIC="1"
525                 ;;
526
527         "-tlsglobal"|"-tlsglobals")
528                 TLSGLOBALS="1"
529                 ;;
530
531         "-roseomptlsglobals")
532                 ROSE_OMP_TLS_GLOBALS="yes"
533                 ;;
534
535         "-verbose")
536                 echo "Verbose mode set"
537                 VERBOSE=true
538                 ;;
539
540         "-spu-cpp")
541                 SPU_USE_CPP=1
542                 ;;
543
544         "-spu-lib")
545                 SPU_EXTRA_LIBS="$SPU_EXTRA_LIBS -l$1"
546                 shift
547                 ;;
548
549         "-intrinsic")
550                 XI_INTERNAL=true
551                 ;;
552
553         "-debug-script")
554                 echo "Will give excessive charmc debugging output..."
555                 DEBUG_SCRIPT=true
556                 ;;
557
558         "-save")
559                 SAVE=true
560                 ;;
561
562         "-purify")
563                 PURIFY=true
564                 ;;
565
566         "-use-reliable-cc")
567                 USE_RELIABLE_CC=1
568                 ;;
569
570         "-use-fastest-cc")
571                 USE_FASTEST_CC=1
572                 ;;
573
574         "-cc")
575                 OVERRIDE_CC="$1"
576                 shift
577                 ;;
578
579         "-c++")
580                 OVERRIDE_CXX="$1"
581                 shift
582                 ;;
583
584         "-f90")
585                 OVERRIDE_F90="$1"
586                 shift
587                 ;;
588
589         "-ld")
590                 OVERRIDE_LD="$1"
591                 shift
592                 ;;
593
594         "-ld++")
595                 OVERRIDE_LDXX="$1"
596                 shift
597                 ;;
598
599         "-cpp-option")
600                 OPTS_CPP="$OPTS_CPP $1"
601                 shift
602                 ;;
603
604         "-ldro-option")
605                 OPTS_LDRO="$OPTS_LDRO $1"
606                 shift
607                 ;;
608
609         "-cc-option")
610                 OPTS_CC="$OPTS_CC $1"
611                 shift
612                 ;;
613
614         "-c++-option")
615                 OPTS_CXX="$OPTS_CXX $1"
616                 shift
617                 ;;
618
619         "-f90-option")
620                 OPTS_F90="$OPTS_F90 $1"
621                 shift
622                 ;;
623
624         "-ld-option"|"-ld++-option")
625                 OPTS_LD="$OPTS_LD $1"
626                 shift
627                 ;;
628
629         "-rpath")
630                 OPTS_LD="$OPTS_LD -rpath $1"
631                 shift
632                 ;;
633
634         "-rpath-origin")
635                 RPATH_ORIGIN="yes"
636                 ;;
637         
638         "-fortran"|"-flib"|"-flibs")
639                 USE_F90_LIBRARIES="1" 
640                 ;;
641         "-f77")
642                 USE_F77="1" 
643                 ;;
644         "-fortran77"|"-f77lib"|"-f77libs")
645                 USE_F77_LIBRARIES="1" 
646                 ;;
647         "-E")
648 # Run preprocessor only
649                 PREPROCESS="yes"
650                 SKIPLINK="yes"
651                 OPTS="$OPTS $arg"
652                 ;;
653         "-preprocess")
654 # Run preprocessor as an extra step, continue after preprocessing
655                 PREPROCESS="yes"
656                 ;;
657         "-no-preprocess-ci")
658 # Turn off the preprocessor for ci files
659                 PREPROCESS_CI="no"
660                 ;;
661         "-P"|"-S")
662 # Run preprocessor/assembler only
663                 SKIPLINK="yes"
664                 OPTS="$OPTS $arg"
665                 ;;
666 #------ Dependency generation ---------
667         "-M" | "-MM" | "-MMD" | "-MG")
668                 SKIPLINK="yes"
669                 OPTS="$OPTS $arg"
670                 GENDEPENDS="yes"
671                 ;;
672         "-MF" | "-MT" | "-MQ" | "-MD")  #-MP will pass through automatically
673                 OPTS="$OPTS $arg $1"
674                 shift
675                 ;;
676 #--------------------------------------
677     "-count-tokens")
678                 OPTS="$OPTS $arg"
679         COUNTTOKENS="yes"
680         ;;
681         "-default-to-aout")
682                 if [ "$EXPLICIT_OBJECT $EXPLICIT_COMPILATION" = "no no" ]
683                 then
684                       OBJECT="a.out"
685                 fi
686                 ;;
687         -print-prog-name=*)
688                 echo $arg | cut -d'=' -f2
689                 exit 0
690                 ;;
691         "-c")
692                 if [ "$EXPLICIT_OBJECT" = "no" ]
693                 then
694                       OBJECT=""
695                 fi
696                 EXPLICIT_COMPILATION="yes"
697                 ;;
698
699         "-o")
700                 EXPLICIT_OBJECT="yes"
701                 OBJECT=$1
702                 shift
703                 ;;
704
705         "-cp")
706                 COPYTO="$1"
707                 shift
708                 ;;
709
710         "-cpmod")
711                 MODCOPIES="$1 $MODCOPIES"
712                 shift
713                 ;;
714
715         "-gen-cpm")
716                 GENCPM="$GENCPM $1"
717                 shift
718                 ;;
719
720         -I)
721                 OPTS_CPP="$OPTS_CPP -I$1"
722                 shift
723                 ;;
724
725         -D*|-I*)
726                 if echo "$arg" | grep ' '  > /dev/null 2>/dev/null 
727                 then
728                   OPTS_CPP="$OPTS_CPP "\"$arg\"
729                 else
730                   OPTS_CPP="$OPTS_CPP $arg"
731                 fi
732                 ;;
733
734         -Werror)
735                 WERROR="1"
736                 ;;
737
738         -Wno-error)
739                 WERROR="0"
740                 ;;
741
742         "-use-new-std")
743         USE_NEW_STD="1"
744                 ;;
745
746         "-no-use-new-std")
747                 USE_NEW_STD="0"
748                 ;;
749
750         -LANG*)
751                 Warning "passing unrecognized option $arg to all compilers and linkers"
752                 OPTS="$OPTS $arg"
753                 ;;
754         -shared|-G)
755                 BUILD_SHARE="1"
756                 ;;
757         -L*|-shared|-G) # note that this is not executed if $arg == -shared|-G, due to the case above; might be a bug
758                 OPTS_LD="$OPTS_LD $arg"
759                 ;;
760         -charm-shared|-cs)
761                 CHARM_SHARED="1"
762                 ;;
763         -build-shared)
764                 # used internally when building Charm++ to create lib_so
765                 BUILD_SHARE="1"
766                 ;;
767         -no-build-shared)
768                 # used internally not to build Charm++ lib_so
769                 BUILD_SHARE="0"
770                 ;;
771         "-optimize")
772                 OPTIMIZE_MODE=true
773                 ;;
774
775         "-no-optimize")
776                 OPTIMIZE_MODE=false
777                 ;;
778
779         "-production")
780                 PRODUCTION_MODE=true
781                 ;;
782         "-no-production")
783                 PRODUCTION_MODE=false
784                 ;;
785
786         -Wl,*)
787                 POST_LIBRARIES="$POST_LIBRARIES $arg"
788                 ;;
789         
790         "-pg"|"-g"|-W*|-O*)
791                 OPTS="$OPTS $arg"
792                 ;;
793
794         "-fmoddir")
795                 F90_MODDIR="$F90_MODDIR $1"
796                 shift
797                 ;;
798
799         -l*|*.a|*.so|*.so.*|*.dylib)
800                 if [ -n "$POST_LANGUAGE" ]
801                 then
802                         POST_LIBRARIES="$POST_LIBRARIES $arg"
803                 else
804                         PRE_LIBRARIES="$PRE_LIBRARIES $arg"
805                 fi
806                 INPUT_GIVEN="1"
807                 ;;
808
809         "-whole-archive")
810                 LINK_WHOLE_ARCHIVE=true
811                 ;;
812
813         "-c++stl")
814                 LINK_CXX_STL=true
815                 ;;
816
817         -s)
818                 OPTS_LD="$OPTS_LD   $arg"
819                 ;;
820         -no-charmrun)
821                 COPY_CHARMRUN=false
822                 ;;
823         -use-build-options)
824                 USE_BUILD_OPTIONS=1
825                 ;;
826         -h|--help)
827                 printUsage
828                 ;;
829         -f90main)
830                 F90_MAIN=1
831                 ;;
832         -nof90main)
833                 F90_MAIN=
834                 ;;
835         -mpi)
836                 MPI_INTEROPERATE="yes"
837                 NO_MAIN="yes"
838                 ;;
839         -nomain-module)
840                 NO_MAIN_MODULE="yes"
841                 ;;
842         -nomain)
843                 NO_MAIN="yes"
844                 ;;
845         -custom-part)
846                 CUSTOM_PARTITION="yes"
847                 ;;
848
849         -fopenmp|-openmp)
850                 USE_OPENMP="yes"
851                 ;;
852
853         -skip-module-init)
854                 SKIP_MODULEINIT="yes"
855                 ;;
856
857         -print-building-blocks)
858                 PRINT_BUILDING_BLOCKS="yes"
859                 SKIP_MODULEINIT="yes"
860                 ;;
861
862         -touch-on-failure)
863                 NOABORT="yes"
864                 ;;
865
866         -*|+*)
867 #               Warning "passing unrecognized option $arg to all compilers and linkers"
868                 OPTS="$OPTS  $arg"
869                 ;;
870         *.*)
871                 [ -n "$VERBOSE" ] && echo "Adding file $arg..."
872                 FILES="$FILES $arg"
873                 INPUT_GIVEN="1"
874                 ;;
875 # Default
876         *)
877 #               printUsage  "Error: Unrecognized argument $arg"
878 #               Warning "passing unrecognized option $arg to all compilers and linkers"
879                 OPTS="$OPTS  $arg"
880                 ;;
881         esac
882 done
883 }
884
885 trap 'End 1' 2
886
887 # Process original command-line arguments
888 eval processArgs "$@"
889
890 # Do not skip linking if user explicitly specified an output file
891 # This allows generating dependencies while compiling
892 if [ "$GENDEPENDS" = "yes" -a "$EXPLICIT_OBJECT" = "yes" ]; then
893         SKIPLINK=""
894 fi
895
896 USER_POST_LIBRARIES="$POST_LIBRARIES"
897 USER_PRE_LIBRARIES="$PRE_LIBRARIES"
898
899 # Construct list of object files
900 numFiles=`echo $FILES | wc -w`
901 for FILE in $FILES
902 do
903
904         case "$FILE" in
905         *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
906                 OBJECTFILES="$OBJECTFILES $FILE"
907                 ;;
908         *.c|*.s|*.S|*.C|*.cc|*.cxx|*.cpp|*.c++|*.cu|*.f|*.F|*.f77|*.F77|*.f90|*.F90|*.fpp|*.FPP)
909                 BASE=`stripExtention \`basename $FILE\``
910                 BASEO="$BASE.o"
911
912                 if [ $numFiles = 1 -a -n "$OBJECT" ]
913                 then
914                         OBJ_EXT=`getExtention $OBJECT`
915                         if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
916                         then
917                                 BASEO=$OBJECT
918                         fi
919                 fi
920
921                 # Handle new object files
922                 if [ -n "$BASEO" -a -n "$OBJECT" ]
923                 then
924                         if [ "$OBJECT" != "$BASEO" ]
925                         then
926                                 DELETE="$DELETE $BASEO"
927                         fi
928                         OBJECTFILES="$OBJECTFILES $BASEO"
929                 fi
930                 ;;
931         esac
932 done
933
934
935 ##############################################################################
936 #
937 # Load module dependencies.
938 #
939 ##############################################################################
940
941 Debug "About to read machine config script"
942 Debug "Read config script, setting defaults..."
943
944 [ ! -r $CHARMINC/conv-config.sh ] && Abort "Cannot find conv-config.sh in $CHARMINC"
945 . $CHARMINC/conv-config.sh $CHARMINC
946
947 Debug "Setting vars..."
948
949 if [ "$USE_BUILD_OPTIONS" = "1" ]  
950 then
951         [ -n "$VERBOSE" ] && echo "Charmc applying build time options: $BUILDOPTS"
952         OPTS="$OPTS $BUILDOPTS"
953 fi
954
955 # If we are debugging, add "-g -O0" to the C/C++ flags
956 if [ -n "$CHARMDEBUG" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]; then
957        if [ -n "$CMK_BUILD_PYTHON" ]; then
958                 AddModules PythonCCS charmdebug_python
959                 POST_LIBRARIES=`AddList $POST_LIBRARIES -lpython${CMK_BUILD_PYTHON}`
960         fi
961         OPTS_CPP="$OPTS_CPP -O0 -g"
962 fi
963
964 # The purpose of the -rpath-origin option is for the resulting binary to have
965 # the literal text '$ORIGIN' in the RPATH field of its ELF header, essentially
966 # saying that it is okay for the binary to look in the same directory as itself
967 # for the shared objects it needs. Unfortunately, POSIX shells will interpret
968 # this text as a variable instead of passing in the string itself, requiring
969 # the string to be escaped.
970 # Additionally, some platforms do not need any special parameters.
971 if [ -n "$RPATH_ORIGIN" -a "$CMK_MACOSX" != "1" -a "$CMK_COMPILER" != "msvc" ]; then
972   OPTS_LD="$OPTS_LD '-Wl,-rpath,\$ORIGIN'"
973 fi
974
975 PROCESSED_MODULES=""
976
977 if [ "$WERROR" = "1" ]
978 then
979     OPTS="$OPTS $CMK_WARNINGS_ARE_ERRORS"
980 fi
981
982 # If the user has asked for the latest language standards (C11 or CPP11)
983 if [ "$USE_NEW_STD" = "1" ]
984 then
985     # and if configure confirmed that the underlying compiler knows abt C11, enable it
986     if [ "$CMK_COMPILER_KNOWS_C11" = "1" ]
987     then
988         OPTS_CC="$OPTS $CMK_ENABLE_C11"
989     fi
990 fi
991
992 if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
993 then
994     USE_OPENMP="yes"
995     TLSGLOBALS="1"
996
997     if [ ! -x "$CMK_ROSE_OMP_TOOL" ]
998     then
999         Abort "The environment variable CMK_ROSE_OMP_TOOL must contain the path to a built binary of the ROSE OpenMP variable privatization tool"
1000     fi
1001 fi
1002
1003 if [ "$USE_OPENMP" = "yes" -o "$CMK_OMP" = "1" -a -z "$SEQUENTIAL" -a -z "$NATIVE" ]
1004 then
1005     if [ "$CMK_HAS_OPENMP" != "1" ]
1006     then
1007       echo "Error: OpenMP is unavailable!"
1008       exit 1
1009     fi
1010     [ -n "$VERBOSE" ] && echo OpenMP support enabled
1011     OPTS_CC="$OPTS_CC $CMK_C_OPENMP"
1012     OPTS_CXX="$OPTS_CXX $CMK_C_OPENMP"
1013     OPTS_F90="$OPTS_F90 $CMK_F_OPENMP"
1014     OPTS_LD="$OPTS_LD $CMK_LD_OPENMP"
1015 else
1016     [ -n "$VERBOSE" ] && echo OpenMP support not enabled
1017 fi
1018
1019 if [ "$TLSGLOBALS" = "1" ]
1020 then
1021     TLSGLOBALS_OPTS='-ftls-model=initial-exec'
1022     [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" = '1' ] && TLSGLOBALS_OPTS="$TLSGLOBALS_OPTS -mno-tls-direct-seg-refs"
1023     OPTS_CC="$OPTS_CC $TLSGLOBALS_OPTS"
1024     OPTS_CXX="$OPTS_CXX $TLSGLOBALS_OPTS"
1025     OPTS_F90="$OPTS_F90 $TLSGLOBALS_OPTS"
1026 fi
1027
1028 # Look up and add the dependencies for module $1
1029 findModuleDep() {
1030         M=$1
1031         notInList $M $PROCESSED_MODULES || return
1032         PROCESSED_MODULES="$PROCESSED_MODULES $M"
1033         #PRE_LIBRARIES=`AddList $PRE_LIBRARIES -lmodule$M`
1034         PRE_LIBRARIES=`AddList -lmodule$M $PRE_LIBRARIES`
1035 # HACK: add modules to both ends of library list, to avoid
1036 #  undefined symbol CkRegisterMainModule when it's in a module file.
1037         POST_LIBRARIES=`AddList $POST_LIBRARIES -lmodule$M`
1038         if [ "$M" = "PythonCCS" ]
1039             then
1040             LINK_PYTHON=1
1041         fi
1042
1043         dep=""
1044 # fixme: should search everything in the -L library paths:
1045         for dir in `echo . $CHARMLIB`
1046         do
1047                 d="$dir/libmodule$M.dep"
1048                 [ -r "$d" ] && dep=$d
1049         done
1050         if [ -r "$dep" ]
1051         then
1052                 # Add the module dependencies in this file
1053                 # Debugf "Adding module" $M "dependencies from" $dep
1054                 deps=`cat $dep`
1055                 Debugf "Module" $M "adds dependencies:" $deps
1056                 processArgs $deps
1057         fi
1058 }
1059
1060 # Repeat the module-dependency search until we find no
1061 #  new modules:
1062 START_MODULES=""
1063 while [ "$START_MODULES" != "$MODULES" ]
1064 do
1065         Debugf "----------- Module dependency search ------------"
1066         START_MODULES="$MODULES"
1067         for m in $MODULES
1068         do
1069                 findModuleDep $m
1070         done
1071 done
1072
1073 Debugf "----------- Module dependency search complete ------------"
1074
1075
1076
1077 ##############################################################################
1078 #
1079 # Load machine-specific configuration data, then handle overrides to it.
1080 #
1081 ##############################################################################
1082
1083
1084 if [ x"$CMK_NO_BUILD_SHARED" = "xfalse" ]
1085 then
1086         BUILD_SHARE="1"
1087 fi
1088
1089 if [ "$BUILD_SHARE" = "1" ]
1090 then
1091         USE_PIC="1"
1092 fi
1093
1094 OPTS_PIC="$CMK_PIC"
1095 if [ "$USE_PIC" = "1" ]
1096 then
1097        OPTS_CC="$OPTS_CC $OPTS_PIC"
1098        OPTS_CXX="$OPTS_CXX $OPTS_PIC"
1099        OPTS_F90="$OPTS_F90 $OPTS_PIC"
1100        OPTS_LD="$OPTS_LD $OPTS_PIC"
1101 fi
1102
1103 if [ "$BUILD_SHARE" = "1" ]
1104 then
1105         # ignore BUILD_SHARE if the target is not .a or .so
1106         case "$OBJECT" in
1107         *.a|*.so|*.so.*|*.sl|*.dylib)
1108                 OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO"
1109                 [ -n "$CHARMLIBSO" ] && OPTS_LD="$OPTS_LD -L$CHARMLIBSO"
1110                 ;;
1111         *)      
1112                 BUILD_SHARE="0"
1113                 ;;
1114         esac
1115 fi
1116
1117 if [ -n "$OVERRIDE_CC" ]
1118 then
1119     CMK_CC="$OVERRIDE_CC"
1120 fi
1121 Debug "set 2"
1122 if [ -n "$OVERRIDE_CXX" ]
1123 then
1124     CMK_CXX="$OVERRIDE_CXX"
1125 fi
1126
1127 if [ -n "$OVERRIDE_F90" ]
1128 then
1129     CMK_CF90="$OVERRIDE_F90"
1130 fi
1131
1132 if [ -n "$OVERRIDE_LD" ]
1133 then
1134     CMK_LD="$OVERRIDE_LD"
1135 fi
1136
1137 if [ -n "$OVERRIDE_LDXX" ]
1138 then
1139     CMK_LDXX="$OVERRIDE_LDXX"
1140 fi
1141
1142 if [ -n "$USE_RELIABLE_CC" ]
1143 then
1144         CMK_CC="$CMK_CC_RELIABLE"
1145 fi
1146
1147 if [ -n "$USE_FASTEST_CC" ]
1148 then
1149     CMK_CC="$CMK_CC_FASTEST"
1150 fi
1151
1152 if [ -n "$USE_F77" ]
1153 then
1154     CMK_CF90=$CMK_CF77
1155     CMK_CF90_FIXED=$CMK_CF77
1156     CMK_F90LIBS=$CMK_F77LIBS
1157 fi
1158
1159 if [ -n "$CMK_F90_MODINC" ]
1160 then
1161     CMK_CF90_MODINC="$CMK_F90_MODINC"
1162 else
1163     CMK_CF90_MODINC="-M"
1164 fi
1165
1166 if [ -n "$F90_MODDIR" ]
1167 then
1168     for dir in $F90_MODDIR
1169     do
1170       OPTS_F90="$OPTS_F90 $CMK_CF90_MODINC $dir"
1171     done
1172 fi
1173
1174 if [ -n "$CMK_F90_USE_MODDIR" ]
1175 then
1176     CMK_CF90="$CMK_CF90 $CMK_CF90_MODINC $CHARMINC $CMK_SYSINC"
1177 fi
1178
1179 if [ -n "$SEQUENTIAL" ]
1180 then
1181     CMK_CC="$CMK_SEQ_CC"
1182     CMK_LD="$CMK_SEQ_LD"
1183     CMK_CXX="$CMK_SEQ_CXX"
1184     CMK_CF90="$CMK_SEQ_F90 " 
1185     CMK_LDXX="$CMK_SEQ_LDXX" 
1186     CMK_AR="$CMK_SEQ_AR"
1187     CMK_RANLIB="$CMK_SEQ_RANLIB"
1188
1189     CMK_CC_FLAGS="$CMK_SEQ_CC_FLAGS -DCMK_SEQUENTIAL=1"
1190     CMK_LD_FLAGS="$CMK_SEQ_LD_FLAGS"
1191     CMK_CXX_FLAGS="$CMK_SEQ_CXX_FLAGS -DCMK_SEQUENTIAL=1"
1192     CMK_LDXX_FLAGS="$CMK_SEQ_LDXX_FLAGS"
1193 fi
1194
1195 if [ -n "$NATIVE" ]
1196 then
1197     CMK_CC="$CMK_NATIVE_CC " 
1198     CMK_LD="$CMK_NATIVE_LD" 
1199     CMK_CXX="$CMK_NATIVE_CXX " 
1200     CMK_LDXX="$CMK_NATIVE_LDXX" 
1201
1202     CMK_CC_FLAGS="$CMK_NATIVE_CC_FLAGS"
1203     CMK_LD_FLAGS="$CMK_NATIVE_LD_FLAGS"
1204     CMK_CXX_FLAGS="$CMK_NATIVE_CXX_FLAGS"
1205     CMK_LDXX_FLAGS="$CMK_NATIVE_LDXX_FLAGS"
1206 fi
1207
1208 if [ -n "$PREPROCESS" ]
1209 then
1210     CMK_CF90=$CMK_FPP
1211 fi
1212
1213 if [ -n "$PURIFY" ]
1214 then
1215     CMK_LD="purify $CMK_LD"
1216     CMK_LDXX="purify $CMK_LDXX"
1217 fi
1218
1219 Debug "set 4"
1220 if [ "$OPTIMIZE_MODE" = "true" ]
1221 then
1222     OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
1223     OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
1224     OPTS_F90="$CMK_F90_OPTIMIZE $OPTS_F90"
1225     OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
1226 fi
1227
1228 # Pick up per-architecture production mode settings
1229 if [ "$PRODUCTION_MODE" = "true" ]
1230 then
1231     OPTS_CC="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_CC"
1232     OPTS_CXX="$CMK_PRODUCTION $CMK_CXX_PRODUCTION $OPTS_CXX"
1233     OPTS_F90="$CMK_PRODUCTION $CMK_F90_PRODUCTION $OPTS_F90"
1234     OPTS_LD="$CMK_PRODUCTION $CMK_C_PRODUCTION $OPTS_LD"
1235 fi
1236
1237 if [ -n "$XI_INTERNAL" ]
1238 then
1239     CMK_XIOPTS="$CMK_XIOPTS -intrinsic"
1240 fi
1241
1242 if [ "$GENDEPENDS" = "yes" ]
1243 then
1244     CMK_XIOPTS="$CMK_XIOPTS -M"
1245 fi
1246
1247 if [ "$COUNTTOKENS" = "yes" ]
1248 then
1249     CMK_XIOPTS="$CMK_XIOPTS -count-tokens"
1250 fi
1251
1252 if test "$CMK_WITH_TAU" = "true"
1253 then
1254   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1255   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1256   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1257   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS` 
1258   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1259   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1260   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1261
1262   rm -f _make.tau.tmp
1263 fi
1264
1265 #Add generic options to the compiler- and linker-options
1266 OPTS_CC="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CC"
1267 OPTS_CXX="$OPTS $TAU_DEFS $TAU_INCLUDE $OPTS_CXX"
1268 OPTS_F90="$OPTS $OPTS_F90"
1269 OPTS_LD="$OPTS $OPTS_LD"
1270
1271 # There's really no analog for this in the Bourne shell: 
1272 #  -------- C Shell ------> onintr failure
1273 # Luckily, it's irrelevant as long as nobody sends us a ^Z.
1274
1275 ##############################################################################
1276 #
1277 # Check for valid choice of LANGUAGE
1278 #
1279 ##############################################################################
1280 Debug "Checking language..."
1281
1282 [ -z "$LANGUAGE" -a -n "$SEQUENTIAL" ] && LANGUAGE=c
1283 [ -z "$PARADIGM" -a -n "$LANGUAGE" ] && PARADIGM="$LANGUAGE"
1284 [ -z "$PARADIGM" ] && PARADIGM="charm++"
1285
1286 case "$LANGUAGE" in
1287 "c"|"C"|"c++"|"C++")
1288         [ -z "$SEQUENTIAL" -a -z "$NATIVE" ] && Abort "Language $LANGUAGE is for sequential programs"
1289         ;;
1290 esac
1291
1292 # update charm to bgcharm
1293 [ "$PARADIGM" = "charm++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgcharm++"
1294 [ "$PARADIGM" = "converse++" -a -n "$CMK_BIGSIM" ] && PARADIGM="bgconverse++"
1295
1296 [ "$PARADIGM" = "bgcharm++" ] && TRACEMODE=`AddList $TRACEMODE bluegene`
1297
1298 if [ $USE_F77_LIBRARIES = "1" ]
1299 then
1300         POST_LIBRARIES="$POST_LIBRARIES $CMK_F77LIBS"
1301 fi
1302
1303 if [ $USE_F90_LIBRARIES = "1" ]
1304 then
1305
1306         if [ ! -r $CHARMLIB/libconv-utilf.a ]
1307         then
1308                 Abort "Error: Fortran support library $CHARMLIB/libconv-utilf.a missing. Is your Fortran compiler working?"
1309         fi
1310
1311         POST_LIBRARIES="$POST_LIBRARIES -lconv-utilf $CMK_F90LIBS"
1312 fi
1313
1314 # GEN-CPM options
1315 if [ "$CMK_COMPILER" = "bgclang" ]
1316 then
1317   OPTS_CC_GENCPM="-x c "  # -x c is only applied for the preprocessing of the GEN-CPM files on BG/Q
1318 fi
1319
1320 OPTS_CC_GENCPM="$OPTS_CC $OPTS_CC_GENCPM"
1321
1322 ############ Determine the language and libraries ##########
1323
1324 # Parse out the real languages
1325 case "$PARADIGM" in
1326 "charm++f")
1327         PARADIGM="charm++"
1328         USE_F90_LIBRARIES="1"
1329         ;;
1330 "f90charm")
1331         PRE_LIBRARIES="$PRE_LIBRARIES -lf90charm -lckf"
1332         POST_LIBRARIES="$POST_LIBRARIES $CMK_F90LIBS"
1333         ;;
1334 "bluegene"|"bigsim")
1335         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs"
1336         ;;
1337 "ckbluegene")
1338         POST_LIBRARIES="$POST_LIBRARIES -lbluegene"
1339         ;;
1340 "bgcharm++")
1341         PRE_LIBRARIES="$PRE_LIBRARIES -lconv-bigsim -lconv-bigsim-logs -lconv-bluegene-stub"
1342         ;;
1343 "bgconverse++")
1344         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-bigsim -lconv-bigsim-logs"
1345         ;;
1346 esac
1347
1348 # DMK - ACCEL SUPPORT - If this is a cell build, add the spe code object to POST_LIBRARIES
1349 if [ $CMK_CELL -eq 1 ]
1350 then
1351
1352   if [ "$PARADIGM" = "converse++" ]
1353   then
1354     # Include a "do nothing" register_accel_spe_funcs() function
1355     POST_LIBRARIES="$POST_LIBRARIES -lnoAccelStub"
1356   fi
1357
1358   if [ "$PARADIGM" = "charm++" ]
1359   then
1360
1361     if [ $SPU_USE_CPP -eq 1 ]
1362     then
1363         SPU_COMPILER=$CMK_SPU_CXX
1364         SPU_LINKER=$CMK_SPU_LDXX
1365     else
1366         SPU_COMPILER=$CMK_SPU_CC
1367         SPU_LINKER=$CMK_SPU_LD
1368     fi
1369
1370     # Include the spe object file for linking into main executable
1371     POST_LIBRARIES="$POST_LIBRARIES main__funcLookup__.genSPECode.ppe.o"
1372
1373   fi
1374 fi
1375
1376 if [ "$AMPIMAIN" != "" ]
1377 then
1378         OBJECTFILES="$CHARMLIB/lib$AMPIMAIN.o $OBJECTFILES"
1379 fi
1380
1381 if [ "$TLSGLOBALS" = "1" ]
1382 then
1383     if [ "$CMK_GDIR" = "uth" ]
1384     then
1385       echo "Error: -tlsglobals is not supported with the uth machine layer."
1386       exit 1
1387     fi
1388     if [ "$CMK_COMPILER_KNOWS_TLSDIRECTSEGREFS" != '1' ] && [ "$CMK_COMPILER" != 'clang' -o "$CMK_MACOSX" != '1' ]
1389     then
1390       echo "Warning: -tlsglobals may not work with compilers that do not recognize -mno-tls-direct-seg-refs."
1391     fi
1392     if [ "$CMK_HAS_ELF_H" != '1' -a "$CMK_MACOSX" != '1' ]
1393     then
1394       echo "Warning: -tlsglobals requires elf.h"
1395     fi
1396 fi
1397
1398 if [ "$SWAPGLOBALS" = "1" ]
1399 then
1400         if [ "$CMK_HAS_ELF_H" != "1" ]
1401         then
1402                 echo "Error: -swapglobals requires elf.h"
1403                 exit 1
1404         fi
1405
1406         LD_VERSION_TEXT=`$CMK_LD -Wl,--version,-v 2>/dev/null`
1407         if ! `printf "$LD_VERSION_TEXT" | grep -q 'GNU ld'`
1408         then
1409                 echo "Warning: -swapglobals may not work with linkers other than GNU ld."
1410         else
1411                 LD_VERSION=`printf "$LD_VERSION_TEXT" | grep -Eo 'GNU ld (\([^)]*\) )?(version )?[-0-9._a-zA-Z]+' | awk '{print $NF}'`
1412                 LD_VERSION_MAJOR=`printf $LD_VERSION | cut -d. -f1`
1413                 LD_VERSION_MINOR=`printf $LD_VERSION | cut -d. -f2 | cut -d- -f1`
1414                 if [ "$LD_VERSION_MAJOR" -gt 2 ] || [ "$LD_VERSION_MAJOR" -eq 2 -a "$LD_VERSION_MINOR" -gt 23 ]
1415                 then
1416                         echo "Warning: -swapglobals may not work with GNU ld >= 2.24."
1417                         echo "For some versions, an experimental patch is available:"
1418                         echo 'https://charm.cs.illinois.edu/gerrit/gitweb?p=libbfd-patches.git;a=tree;f=swapglobals'
1419                 fi
1420         fi
1421
1422         if [ "$CMK_SMP" = "1" ]
1423         then
1424                 echo "Error: -swapglobals is not supported on SMP builds of Charm++/AMPI"
1425                 exit 1
1426         else
1427                 swapo="$CHARMLIB/libglobal-swap.a"
1428                 if [ ! -r "$swapo" -o ! -s "$swapo" ]
1429                 then
1430                         echo "Error: global-swapping library $swapo missing--"
1431                         echo "  Is -swapglobals supported on this machine?"
1432                         exit 1
1433                 else
1434                         MIDDLE_LIBS="-lglobal-swap $MIDDLE_LIBS"
1435                 fi
1436         fi
1437 fi
1438 if [ "$SWAPGLOBALS" = "2" ]
1439 then
1440         echo "-copyglobals option is no longer supported by Charm++/AMPI"
1441         exit 1
1442 fi
1443
1444
1445 # dummy main module
1446 if [ "$MPI_INTEROPERATE" != "" -a "$NO_MAIN_MODULE" = "" ]
1447 then
1448         POST_LIBRARIES="-lmpi-mainmodule $POST_LIBRARIES"
1449 fi
1450
1451 ##############################################################################
1452 #
1453 # Some quick consistency checks in preparation for full link-step
1454 #
1455 # Check for valid choice of TRACEMODE
1456 # Check for valid choice of BALANCE
1457 # Check for compatibility among BALANCE and TRACEMODE
1458 #
1459 ##############################################################################
1460
1461 Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1462
1463 # Check for valid choice of TRACEMODE
1464
1465 if [ x"$TRACEMODE" != x ]
1466 then
1467 for trace in $TRACEMODE; do
1468     case "$PARADIGM" in
1469         "converse"|"converse++"|"bgconverse++"|"bigsim"|"bluegene")
1470             if [ "$trace" != "counter" ]; then
1471                 Warning "Tracemode $trace isn't supported in Converse-level programs; Dropping it"
1472                 TRACEMODE=`DropList $trace $TRACEMODE`
1473                 continue
1474             fi
1475             ;;
1476         *)
1477             ;;
1478     esac
1479
1480     TRACE_OBJ="$TRACE_OBJ -ltrace-$trace"
1481 done
1482
1483 fi
1484
1485 if test x$PARADIGM = x"bgcharm++"
1486 then
1487     BALANCE=bluegene
1488 fi
1489
1490 Debug "Finished with TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."
1491
1492 BAL_OBJ="-lldb-$BALANCE -lconv-ldb"
1493
1494 # Check for valid choice of MEMORY
1495
1496 # Set the default expansions of unprefixed variants
1497 case "$MEMORY" in
1498   'verbose'|'paranoid'|'leak'|'isomalloc')
1499     MEMORY="os-$MEMORY"
1500     ;;
1501   charmdebug*)
1502     MEMORY="gnu-$MEMORY"
1503     ;;
1504 esac
1505
1506 # Isomalloc does not work on BGQ or Windows:
1507 if [ "$CMK_BLUEGENEQ" = "1" -o "$CMK_COMPILER" = "msvc" ] && [ "$MEMORY" = "${MEMORY%isomalloc}isomalloc" ]
1508 then
1509   Abort "Error: Isomalloc is not supported on BlueGene/Q or Windows."
1510 fi
1511
1512 MEM_OBJ="-lmemory-${MEMORY}"
1513
1514 # For memory wrapping around the OS allocator, need to add also the wrapper object
1515 case $MEMORY in
1516   os-*)
1517      MEM_OBJ=$MEM_OBJ" -lmemory-os-wrapper"
1518   ;;
1519 esac
1520
1521 # Check for valid choice of THREAD
1522
1523 if [ "$CHARM_SHARED" = "1" -a -n "$CMK_LD_SHARED_THREAD" -a "$THREAD" = "default" ]
1524 then
1525   THREAD=$CMK_LD_SHARED_THREAD
1526 fi
1527 if [ "$TLSGLOBALS"  = "1" ]
1528 then
1529   THREAD=${THREAD%-tls}-tls
1530 fi
1531
1532 THREAD_OBJ="-lthreads-${THREAD}"
1533
1534
1535 # Module name
1536
1537 modInitName="moduleinit$$"
1538 modInitSrc="$modInitName.C"
1539 modInitObj="$modInitName.o"
1540
1541
1542 ##############################################################################
1543 #
1544 # Final link step variables
1545 #
1546 ##############################################################################
1547
1548 MAKE_LDXX="0"
1549 MAKE_LD="0"
1550
1551 CORE_LIBS="-lconv-core -ltmgr -lconv-util -lconv-partition $TRACE_OBJ $CMK_HWLOC_LIBS"
1552
1553 # get TAU stub makefile variables
1554 if test "$CMK_WITH_TAU" = "true"
1555 then
1556   echo "include $TAU_MAKEFILE" > _make.tau.tmp
1557   echo "print-%:; @echo \$(\$*)" >> _make.tau.tmp
1558   TAU_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_LIBS`
1559   TAU_MPI_LIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_LIBS`
1560   TAU_MPI_FLIBS=`make --no-print-directory -f _make.tau.tmp print-TAU_MPI_FLIBS`
1561   TAU_DEFS=`make --no-print-directory -f _make.tau.tmp print-TAU_DEFS`
1562   TAU_INCLUDE=`make --no-print-directory -f _make.tau.tmp print-TAU_INCLUDE`
1563
1564   rm -f _make.tau.tmp
1565 fi
1566 # done getting TAU variables
1567
1568 if [ "$BUILD_SHARE" = "0" ]
1569 then
1570        MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1571 fi
1572
1573 CMK_SYSLIBS="$CMK_SYSLIBS -lm"
1574
1575 case "$PARADIGM" in
1576 "f90charm")
1577         MAKE_LDXX="1"
1578         MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1579         if [ -z "$NO_MAIN" ]
1580         then
1581                 MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1582                 F90_MAIN="1"
1583         fi
1584         if [ "$TAU_TRACE_MPI" = "1" ]
1585         then
1586                 TAU_LIBS="$TAU_MPI_FLIBS $TAU_LIBS"
1587         else
1588                 TAU_LIBS="$TAU_LIBS"
1589         fi
1590         ;;
1591 "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1592         MAKE_LDXX="1"
1593         MIDDLE_LIBS="-lck $MIDDLE_LIBS -lconv-machine $CORE_LIBS "
1594         if [ -z "$NO_MAIN" ]
1595         then
1596                 if [ -n "$AMPIF" ]
1597                 then
1598                         MIDDLE_LIBS="-lckmainf $MIDDLE_LIBS"
1599                         F90_MAIN="1"
1600                 elif [ -z "$AMPIMAIN" ]
1601                 then
1602                         MIDDLE_LIBS="-lckmain $MIDDLE_LIBS"
1603                 fi
1604         fi
1605         if [ "$TAU_TRACE_MPI" = "1" ]
1606         then
1607                 TAU_LIBS="$TAU_MPI_LIBS $TAU_LIBS"
1608         else
1609                 TAU_LIBS="$TAU_LIBS"
1610         fi
1611         ;;
1612 "converse")
1613         MAKE_LD="1"
1614         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-machine $CORE_LIBS -ltrace-converse "
1615         ;;
1616 "converse++"|"bgconverse++"|"bluegene"|"bigsim")
1617         MAKE_LDXX="1"
1618         MIDDLE_LIBS="$MIDDLE_LIBS -lconv-machine $CORE_LIBS -ltrace-converse "
1619         ;;
1620 "c"|"C"|"c++"|"C++"|"f90"|"f77")
1621   ;;
1622 *)
1623         Abort "Unrecognized choice of language $LANGUAGE / paradigm $PARADIGM"
1624         ;;
1625 esac
1626
1627 if [ "$BUILD_SHARE" = "0" ]
1628 then
1629         MIDDLE_LIBS="$MIDDLE_LIBS $MEM_OBJ $THREAD_OBJ"
1630 fi
1631
1632 if [ "$CHARM_SHARED" = "1" ]
1633 then
1634   [ -z "$CHARMLIBSO" ] &&  Abort "Charm++ lib_so directory not found!"
1635   # build user executable/shared lib linking with charm .so
1636   OPTS_LD="$OPTS_LD $CMK_LD_LIBRARY_PATH"
1637   LANG_LIBS="-L$CHARMLIBSO"
1638 else
1639   LANG_LIBS="-L$CHARMLIB"
1640 fi
1641
1642 if [ -z "$STANDALONE" ]
1643 then
1644   ALL_LIBS="$LANG_LIBS $PRE_LIBRARIES $MIDDLE_LIBS $BAL_OBJ $CMK_LIBS $POST_LIBRARIES"
1645   case "$PARADIGM" in
1646   "charm"|"charm++"|"f90charm"|"ckbluegene"|"bgcharm++")
1647     ALL_LIBS="$ALL_LIBS -lmoduleNDMeshStreamer -lmodulecompletion"
1648     ;;
1649   esac
1650 else
1651   ALL_LIBS="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
1652 fi
1653
1654 if [ -n "$LINK_WHOLE_ARCHIVE" ]
1655 then
1656   ALL_LIBS="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $ALL_LIBS $LDXX_WHOLE_ARCHIVE_POST $CMK_SYSLIBS"
1657 else
1658   ALL_LIBS="$ALL_LIBS $CMK_SYSLIBS"
1659 fi
1660
1661 if [ "$BUILD_SHARE" = "0" ]
1662 then
1663   ALL_LIBS="$ALL_LIBS $CHARMLIB/conv-static.o"
1664 fi
1665
1666 if [ -n "$LINK_CXX_STL" ]
1667 then
1668   ALL_LIBS="$ALL_LIBS -lstdc++"
1669 fi
1670
1671 if [ "$TRACE_WITH_TAU" = 1 ]
1672 then
1673         echo "Linking with the TAU libraries: $TAU_LIBS"
1674         ALL_LIBS="$ALL_LIBS $TAU_LIBS"
1675 fi
1676 Debugf "All libraries are: $ALL_LIBS"
1677
1678 # preserve this variable in its state here for use later
1679 CHARM_ALL_LIBS="$ALL_LIBS"
1680 if [ "$BUILD_SHARE" = "1" -o -n "$SKIP_MODULEINIT" ]
1681 then
1682   ALL_LIBS="$OBJECTFILES $ALL_LIBS"
1683 else
1684   ALL_LIBS="$OBJECTFILES $modInitObj $ALL_LIBS"
1685 fi
1686
1687 if [ -n "$F90_MAIN" ]
1688 then
1689 # for_main needs to be placed at beginning
1690         CMK_LD_FLAGS="$CMK_F90MAINLIBS $CMK_LD_FLAGS"
1691         CMK_LDXX_FLAGS="$CMK_F90MAINLIBS $CMK_LDXX_FLAGS"
1692 fi
1693
1694 if [ -n "$F90_MAIN" -o "$USE_F90_LIBRARIES" = '1' ]
1695 then
1696   if [ "$CMK_CAN_LINK_FORTRAN" != '1' ]
1697   then
1698     echo "Error: Configure testing was unable to link a Fortran program."
1699     exit 1
1700   fi
1701 fi
1702
1703 ########################################################################
1704 #
1705 # Finalize command parameters
1706 #
1707 ########################################################################
1708
1709 CHARM_CPP_C="$CMK_CPP_C"
1710 CHARM_CC="$CMK_CC"
1711 CHARM_CXX="$CMK_CXX"
1712 CHARM_LD="$CMK_LD"
1713 CHARM_LDXX="$CMK_LDXX"
1714
1715 CHARM_CPP_C_FLAGS="$CMK_CPP_C_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CC_GENCPM $OPTS_CPP"
1716 CHARM_CC_FLAGS="$CMK_CC_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC"
1717 CHARM_CXX_FLAGS="$CMK_CXX_FLAGS -I$CHARMINC $CMK_INCDIR $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX"
1718 CHARM_LD_FLAGS="$CMK_LD_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1719 CHARM_LDXX_FLAGS="$CMK_LDXX_FLAGS $CMK_LINK_BINARY $CMK_LIBDIR $OPTS_LD $ALL_LIBS"
1720
1721
1722 ########################################################################
1723 #
1724 # Print command building blocks and quit, if specified
1725 #
1726 ########################################################################
1727
1728 if [ -n "$PRINT_BUILDING_BLOCKS" ]
1729 then
1730         for i in CHARM_CC CHARM_CXX CHARM_LD CHARM_LDXX CHARM_CC_FLAGS CHARM_CXX_FLAGS CHARM_LD_FLAGS CHARM_LDXX_FLAGS CHARMBIN CHARMINC CHARMLIB CHARMLIBSO
1731         do
1732                 eval "echo $i=\\'\${$i}\\'"
1733         done
1734         exit 0
1735 fi
1736
1737
1738 ########################################################################
1739 #
1740 # We've parsed and verified the command-line parameters.
1741 # Now we prepare routines to clean up and exit.
1742 # None of these routines ever returns-- they all just exit.
1743 #
1744 ########################################################################
1745
1746
1747 Copyobj() {
1748         if [ "a$COPYTO" != "a" -a "a$COPYTO" != "a$OBJECT" ] 
1749         then
1750                 [ -d $COPYTO ] && COPYTO="$COPYTO/"
1751                 if [ "a$PROG_EXT" != "a" -a -r "$OBJECT$PROG_EXT" ] ; then
1752                         Warning "Appending $PROG_EXT to object file name"
1753                         OBJECT="$OBJECT$PROG_EXT"
1754                 fi
1755                 [ ! -d $COPYTO ] && DoNoErrCheck $RM $COPYTO 
1756                 Do $CP $OBJECT $COPYTO
1757         fi
1758         test -n "$COPY_EXIT" && Success
1759 }
1760
1761 Copymod() {
1762         for COPY in `echo $MODCOPIES`
1763         do
1764                 if [ "a$COPY" != "a$OBJECT" ] 
1765                 then
1766                         [ -d $COPY ] && COPY="$COPY/"
1767                         if [ -n "$CMK_MOD_NAME_ALLCAPS" ] ; then
1768                           OBJECT=`echo $OBJECT | tr "a-z" "A-Z"`
1769                         fi
1770                         if [ -r "$OBJECT.$CMK_MOD_EXT" ] ; then
1771                           Warning "Appending .$CMK_MOD_EXT to object file name"
1772                           OBJECT="$OBJECT.$CMK_MOD_EXT"
1773                         fi
1774                         [ ! -d $COPY ] && DoNoErrCheck $RM $COPY 
1775                         Do $CP $OBJECT $COPY
1776                 fi
1777         done
1778         Success
1779 }
1780
1781 Success() {
1782         End 0
1783 }
1784
1785
1786 ##############################################################################
1787 #
1788 # Preprocess the GEN-CPM files
1789 #
1790 ##############################################################################
1791
1792 Debug "Preprocessing GEN-CPM files"
1793
1794 for FILE in `echo $GENCPM`
1795 do
1796 # This used to be "$FILE:r", which strips the extention
1797         BASE=`stripExtention $FILE`
1798         MYTMP=`basename $FILE`".TMP"
1799         DELETE="$DELETE $MYTMP.c $MYTMP.i"
1800         DoNoErrCheck $RM $BASE.cpm.h $MYTMP.c
1801         Do touch $BASE.cpm.h
1802         Do $LN -f -s $FILE $MYTMP.c
1803         Do $CHARM_CPP_C $CHARM_CPP_C_FLAGS $MYTMP.c > $MYTMP.i
1804         Do $CHARMBIN/conv-cpm $MYTMP.i $BASE.cpm.h
1805 done
1806
1807 ##############################################################################
1808 #
1809 # Compile all specified files
1810 #
1811 # All temporary files named *.TMP.* for easy cleanup.
1812 #
1813 ##############################################################################
1814
1815 Debug "About to compile..."
1816
1817 for FILE in $FILES
1818 do
1819         BASE=`stripExtention \`basename $FILE\``
1820         MYTMP=`basename $FILE`".TMP"
1821         FILE_EXT=`getExtention $FILE`
1822         BASEO="$BASE.o"
1823         DESTO="-o $BASEO"
1824
1825         # in case of: charmc -o object.o -c foo.c,
1826         # avoid foo.c => remove foo.o => foo.o => object.o,
1827         # instead generate object.o directly.
1828         # remove and generate foo.o may be dangerous in parallel make 
1829         # for example in the case of compiling several objs from one 
1830         # same c file such as memory.C.
1831         if [ $numFiles = 1 -a -n "$OBJECT" ]
1832         then
1833                 OBJ_EXT=`getExtention $OBJECT`
1834                 if [ "$OBJ_EXT" = '.o' -o "$OBJ_EXT" = '.co' ]
1835                 then
1836                         BASEO=$OBJECT
1837                         DESTO="-o $OBJECT"
1838                 fi
1839         fi
1840
1841 #       if [ "$FILE_EXT" != ".o" -a "$FILE_EXT" != ".co" -a "$FILE_EXT" != ".M" -a "$FILE_EXT" != ".ci" ]
1842 #       then
1843         case "$FILE_EXT" in
1844         .c|.s|.S|.C|.cc|.cxx|.cpp|.c++|.cu|.f|.F|.f90|.F90|.fpp|.FPP|.f77|.F77)
1845                 [ $VERBOSE ] && echo "Compiling $FILE"
1846                 DoNoErrCheck $RM $BASEO `stripExtention $BASEO`.f.o
1847         esac
1848 #       fi
1849         if [ ! -z "$SKIPLINK" ] 
1850         then
1851                 DESTO=""
1852         fi
1853
1854         if [ "$ROSE_OMP_TLS_GLOBALS" = "yes" ]
1855         then
1856             case "$FILE" in
1857                 *.c)
1858                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CC -c $FILE
1859                     FILE="rose_$FILE"
1860                     ;;
1861                 *.C|*.cc|*.cxx|*.cpp|*.c++)
1862                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP $OPTS_CXX -c $FILE
1863                     FILE="rose_$FILE"
1864                     ;;
1865                 *.f|*.F|*.f77|*.F77)
1866                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE
1867                     FILE="rose_$FILE"
1868                     ;;
1869                 *.f90|*.F90|*.fpp|*.FPP)
1870                     test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1871                     Do $CMK_ROSE_OMP_TOOL -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE
1872                     FILE="rose_$FILE"
1873                     ;;
1874             esac
1875         fi
1876
1877         case "$FILE" in
1878         *.ci)
1879                 XIOPTS=$CMK_XIOPTS
1880                 test "$PARADIGM" = "f90charm" && XIOPTS="$XIOPTS -f90"
1881                 if [ "$PREPROCESS_CI" = "yes" ]
1882                 then
1883                   Do $CMK_CPP_CHARM $OPTS_CPP $FILE | Do $CHARMBIN/charmxi $XIOPTS -orig-file $FILE
1884                 else
1885                   Do $CHARMBIN/charmxi $XIOPTS $FILE
1886                 fi
1887                 ;;
1888         *.c|*.s|*.S)
1889                 Do $CHARM_CC $CHARM_CC_FLAGS -c $FILE $DESTO
1890                 if [ "$Do_res" -ne 0 ]
1891                 then
1892                     touch $BASEO
1893                 fi
1894                 ;;
1895         *.C|*.cc|*.cxx|*.cpp|*.c++|*.cu)
1896                 if [ -n "$NATIVE" ]
1897                 then
1898                     Do $CMK_NATIVE_CXX $CMK_NATIVE_CXX_FLAGS -I$CHARMINC $CMK_SYSINC $OPTS_CPP_INTERNAL $OPTS_CPP -c $FILE $DESTO
1899                 else
1900                     Do $CHARM_CXX $CHARM_CXX_FLAGS -c $FILE $DESTO
1901                 fi
1902                 if [ "$Do_res" -ne 0 ]
1903                 then
1904                     touch $BASEO
1905                 fi
1906                 ;;
1907         *.f|*.F|*.f77|*.F77)
1908                 test -z "$CMK_CF90_FIXED" && Abort "No F90 compiler (CMK_CF90_FIXED) defined"
1909                 Do $CMK_CF90_FIXED -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 -c $FILE $DESTO
1910                 if [ "$Do_res" -ne 0 ]
1911                 then
1912                     touch $BASEO
1913                 fi
1914                 ;;
1915         *.f90|*.F90|*.fpp|*.FPP)
1916                 test -z "$CMK_CF90" && Abort "No F90 compiler (CMK_CF90) defined"
1917                 test -z "$PREPROCESS" && OPTS_F90="$OPTS_F90 -c"
1918                 Do $CMK_CF90 -I$CHARMINC $CMK_SYSINC $OPTS_CPP $OPTS_F90 $FILE $DESTO
1919                 if [ "$Do_res" -ne 0 ]
1920                 then
1921                     touch $BASEO
1922                 fi
1923                 ;;
1924         *.fc|*.FC)
1925                 Abort "I'm not yet smart enough to compile $FILE"
1926                 ;;
1927         *.o|*.so|*.so.*|*.sl|*.a|*.dylib|*.co)
1928                 [ ! -s $FILE ] && Abort "$FILE: file not recognized: File truncated"
1929                 ;;
1930         *.M|*.mod)
1931                 OBJECT="$BASE"
1932                 Copymod
1933                 Success
1934                 ;;
1935         *)
1936                 Abort "file with unrecognized extension $FILE"
1937         esac
1938 done
1939
1940 ##############################################################################
1941 #
1942 #                        POSSIBLY, SKIP LINK-STEP
1943 #
1944 # 1. No $OBJECT may be specified at all --- its just a compilation.
1945 # 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
1946 # 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
1947 # 4. Language may be sequential.  Do a quick and easy linkage.
1948 #
1949 #               in any of these cases, the full link step is skipped.
1950 #
1951 ##############################################################################
1952
1953 MakeSO() {
1954         Debugf "Running ldro..."
1955         DoNoErrCheck $RM $OBJECT
1956         # convert to absolute path if required
1957         if test -n "$CMK_LD_SHARED_ABSOLUTE_PATH"
1958         then
1959         dir=`dirname $OBJECT`
1960         fname=`basename $OBJECT`
1961         dir=`cd $dir; pwd`
1962         OBJECT=$dir/$fname
1963         fi
1964         if test "$MAKE_LDXX" = "1"
1965         then
1966           soTool="$CMK_LDXX $CMK_LDXX_FLAGS"
1967         else
1968           soTool="$CMK_LD $CMK_LD_FLAGS"
1969         fi
1970         if [ -n "$STANDALONE" ]
1971         then
1972           soLibs="$USER_PRE_LIBRARIES $USER_POST_LIBRARIES"
1973         else
1974           soLibs="$PRE_LIBRARIES $POST_LIBRARIES"
1975           [ "$CMK_MACOSX" = "1" ] && OPTS_LD="$OPTS_LD -Wl,-install_name,$CHARMLIBSO/$fname"
1976         fi
1977         if [ -n "$LINK_WHOLE_ARCHIVE" ]
1978         then
1979           soLibs="$CXX_NO_AS_NEEDED $LDXX_WHOLE_ARCHIVE_PRE $soLibs $LDXX_WHOLE_ARCHIVE_POST"
1980         fi
1981         soLibs="$soLibs $CMK_SYSLIBS"
1982         if [ -n "$LINK_CXX_STL" ]
1983         then
1984           soLibs="$soLibs -lstdc++"
1985         fi
1986         soCmd="$soTool $CMK_LIBDIR -o $OBJECT $OPTS_LD $OPTS_LDRO $OBJECTFILES $soLibs $CMK_LD_SHARED_LIBS"
1987         DoNoErrCheck $soCmd
1988         Do_res=$?
1989         if [ $Do_res -ne 0 ]
1990         then
1991             if [ -n "$NOABORT" ]
1992             then
1993                 touch $OBJECT
1994             else
1995                 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
1996                 echo "!!  Failed to compile Charm++ shared library. You can disable shared   !!"
1997                 echo "!!  lib compilation by providing --no-build-shared build option like:  !!"
1998                 echo "!!     ./build charm++ netlrts-linux --no-build-shared -O              !!"
1999                 echo "!!  or reexecute this charmc command with the --no-build-shared option !!"
2000                 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
2001                 Abort "Command $soCmd returned error code $Do_res"
2002             fi
2003         fi
2004         Copyobj
2005 }
2006
2007 if [ -z "$OBJECT" -o ! -z "$SKIPLINK" ] 
2008 then
2009 # We have no target object, or are playing preprocessor tricks-- just end
2010         Debugf "No target object-- finished"
2011         Success
2012 fi
2013
2014 Debug "About to link..."
2015
2016 if [ "$INPUT_GIVEN" != "1" ]
2017 then
2018     Abort "Trying to link, but no object files or library archives were specified"
2019 fi
2020
2021 # if interoperate dont create the library now, wait to collect all info
2022 if [ "$MPI_INTEROPERATE" = "" ]
2023 then
2024 case "$OBJECT" in
2025 *.o)
2026         Debugf "Converting $FILES to $OBJECTFILES"
2027         nFiles=`echo $FILES | wc -w`
2028         nObj=`echo $OBJECTFILES | wc -w`
2029 # One source file, one .o: just move the .o
2030         if [ $OBJECT != $OBJECTFILES ]
2031         then
2032                 Debugf "Moving .o to destination"
2033                 DoNoErrCheck $RM $OBJECT
2034                 Do $MV $OBJECTFILES $OBJECT
2035         fi
2036         Copyobj
2037         ;;
2038 *.so|*.so.*|*.sl|*.dylib)
2039 # Make shared library
2040         # If building shared is not supported and this object is not standalone, exit.
2041         if [ "$BUILD_SHARE" = 0 -a -z "$STANDALONE" ]
2042         then
2043                 Warning "Warning: building shared library is not supported, recompile charm++ with '--build-shared'."
2044                 End 1
2045         elif [ "$CHARM_SHARED" = "0" ]
2046         then
2047                 MakeSO
2048         fi
2049         ;;
2050 *.a)
2051 # Make regular (.a, non-shared) library
2052         # in case building charm so, build .so under lib_so as well # Gengbin
2053         if [ "$BUILD_SHARE" = "1" ]
2054         then
2055           COPY_EXIT=""
2056           OBJECT_SAVE=$OBJECT
2057           COPYTO_SAVE=$COPYTO
2058           if [ -z "$COPYTO" ]
2059           then
2060             DESTDIR=`echo $OBJECT | sed -e 's@lib/[^/]*\.a$@lib_so@'`
2061             OBJECT=`echo $OBJECT | sed -e 's@lib/\([^/]*\)\.a$@lib_so/\1.a@'`
2062           else
2063             COPYTO=`echo $COPYTO | sed -e 's@lib[/]*$@lib_so@'`
2064             DESTDIR=$COPYTO
2065           fi
2066           OBJECT=`echo $OBJECT | sed -e 's/\.a$/.'"$CMK_SHARED_SUF"'/'`
2067           [ -f $DESTDIR/.charmso ] && MakeSO
2068           COPYTO=$COPYTO_SAVE
2069           OBJECT=$OBJECT_SAVE
2070           COPY_EXIT="true"
2071         fi
2072         # build normal .a
2073         DoNoErrCheck $RM $OBJECT
2074         Do $CMK_AR $OBJECT $OBJECTFILES
2075         Do $CMK_RANLIB $OBJECT
2076         Copyobj
2077         ;;
2078 esac
2079 fi
2080 # If the above case returns, we're not creating a .o or .a file,
2081 # so linking is needed.
2082
2083 if [ $CMK_CELL -eq 1 ]
2084 then
2085
2086   if [ "$PARADIGM" = "charm++" ]
2087   then
2088
2089     # Make the spe object file to be included
2090     Do $SPU_COMPILER -c -I$CHARMINC $CMK_SYSINC -o main__funcLookup__.genSPECode.o main__funcLookup__.genSPECode.c -DCMK_CELL_SPE=1
2091     Do $SPU_LINKER -L$CHARMLIB -o main__funcLookup__.genSPECode main__funcLookup__.genSPECode.o $CMK_SPERT_LIBS $SPU_EXTRA_LIBS
2092     Do $CMK_PPU_EMBEDSPU spert_main main__funcLookup__.genSPECode main__funcLookup__.genSPECode.ppe.o
2093
2094   fi
2095 fi
2096
2097 # check if we're linking a sequential object
2098 case "$LANGUAGE" in
2099 "c"|"C"|"f90"|"f77")
2100         if [ -n "$NATIVE" ]
2101         then
2102           Do $CMK_NATIVE_LD $CMK_NATIVE_LD_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2103                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2104         else
2105           Do $CMK_SEQ_LD $CMK_SEQ_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2106                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2107         fi
2108         Copyobj
2109         ;;
2110 "c++"|"C++")
2111         if [ -n "$NATIVE" ]
2112         then
2113           Do $CMK_NATIVE_LDXX $CMK_NATIVE_LDXX_FLAGS $OPTS_LD -o $OBJECT $OBJECTFILES \
2114                 -L$CHARMLIB $PRE_LIBRARIES $CMK_NATIVE_LIBS $POST_LIBRARIES
2115         else
2116           Do $CMK_SEQ_LDXX $CMK_SEQ_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $OBJECTFILES \
2117                 -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
2118         fi
2119         Copyobj
2120         ;;
2121 esac
2122
2123
2124 ##############################################################################
2125 #
2126 # Confirm that TRACEMODE, BALANCE, MEMORY, THREAD exist
2127 #
2128 ##############################################################################
2129
2130 # [ -r $CHARMLIB/libtrace-projections.a ] || Abort "trace libraries not installed.  Is Charm++ built properly?"
2131
2132 if [ x"$TRACEMODE" != x ]
2133 then
2134 for trace in $TRACEMODE; do
2135     [ ! -r "$CHARMLIB/libtrace-$trace.a" ] && Abort "charmc : No such tracemode $trace"
2136 done
2137 fi
2138
2139 BAL_EXT=`getExtention $BALANCE`
2140 if [ -z "$BAL_EXT" ]; then
2141   # Balance has no extension-- is a library reference
2142   if [ -f "${CHARMLIB}/libldb-$BALANCE.a" ]; then
2143     BAL_OBJ_FILE="${CHARMLIB}/libldb-$BALANCE.a"
2144   else
2145     BAL_OBJ_FILE="${CHARMLIBSO}/libldb-$BALANCE.so"
2146   fi
2147 else
2148   # Balance has some extension-- must be a .o or .a file
2149   BAL_OBJ_FILE="$BALANCE"
2150 fi
2151
2152 if [ ! -r "$BAL_OBJ_FILE" ]
2153 then
2154         if [ "$BALANCE" = "$BAL_OBJ_FILE" ]
2155         then
2156                 Abort "Could not find load balancer object $BAL_OBJ_FILE"
2157         else
2158                 (cd $CHARMLIB ; ls -al libldb-*)
2159                 Abort "Unknown load balancer $BALANCE / $BAL_OBJ_FILE"
2160         fi
2161 fi
2162
2163 if [ -f "${CHARMLIB}/libmemory-${MEMORY}.a" ]; then
2164   MEM_OBJ_FILE="${CHARMLIB}/libmemory-${MEMORY}.a"
2165 else
2166   MEM_OBJ_FILE="${CHARMLIBSO}/libmemory-${MEMORY}.so"
2167 fi
2168
2169 if [ ! -r $MEM_OBJ_FILE -o ! -s $MEM_OBJ_FILE ]
2170 then
2171   (cd $CHARMLIB ; list=`ls libmemory-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2172   Abort "charmc : No such memory mode $MEMORY"
2173 fi
2174
2175 if [ -f "${CHARMLIB}/libthreads-${THREAD}.a" ]; then
2176   THREAD_OBJ_FILE="${CHARMLIB}/libthreads-${THREAD}.a"
2177 else
2178   THREAD_OBJ_FILE="${CHARMLIBSO}/libthreads-${THREAD}.so"
2179 fi
2180
2181 if [ ! -r $THREAD_OBJ_FILE -o ! -s $THREAD_OBJ_FILE ]
2182 then
2183   (cd $CHARMLIB ; list=`ls libthreads-* 2>/dev/null`; test -n "$list" && for i in $list; do [ -s $i ] && ls -l $i; done )
2184   Abort "charmc : No such thread mode $THREAD"
2185 fi
2186
2187
2188 ################# Build the module initialization function ##################
2189
2190 if [ -z "$SKIP_MODULEINIT" ]
2191 then
2192     DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2193
2194     for module in $MODULES; do
2195         echo "extern void _register$module(void);" >> $modInitSrc
2196     done
2197     for trace in $TRACEMODE; do
2198         if test $trace = "summary"
2199         then
2200           echo "  extern void _registerTraceSummary();" >> $modInitSrc
2201         elif test $trace = "projections"
2202         then
2203           echo "  extern void _registerTraceProjections();" >> $modInitSrc
2204         elif test $trace = "simple"
2205         then
2206           echo "  extern void _registerTraceSimple();" >> $modInitSrc
2207         elif test $trace = "Tau"
2208         then
2209           echo "  extern void _registerTraceTau();" >> $modInitSrc
2210         elif test $trace = "utilization"
2211         then
2212           echo "  extern void _registerTraceUtilization();" >> $modInitSrc
2213         elif test $trace = "controlPoints"
2214         then
2215           echo "  extern void _registerTraceControlPoints();" >> $modInitSrc
2216         elif test $trace = "perfReport"
2217         then
2218           Do $CP $CHARMBIN/fuzzytree.txt fuzzytree.txt
2219           Do $CP $CHARMBIN/tree.txt tree.txt
2220           echo "  extern void _registerTraceAutoPerf();" >> $modInitSrc
2221
2222         elif test $trace = "all"
2223         then
2224           echo "  extern void _registerTraceProjections();" >> $modInitSrc
2225           echo "  extern void _registerTraceControlPoints();" >> $modInitSrc
2226           echo "  extern void _registerTraceSummary();" >> $modInitSrc
2227         fi
2228     done
2229     if test -n "$BALANCER"
2230     then
2231         echo "extern void LBDefaultCreate(const char *);" >> $modInitSrc
2232     fi
2233     echo "void _registerExternalModules(char **argv) { (void)argv;" >> $modInitSrc
2234     for module in $MODULES; do
2235         [ -n "$VERBOSE" ] && echo "Adding registration for module $module"
2236         echo "  _register$module();" >> $modInitSrc
2237     done
2238     for trace in $TRACEMODE; do
2239         if test $trace = "summary"
2240         then
2241           echo "  _registerTraceSummary();" >> $modInitSrc
2242         elif test $trace = "projections"
2243         then
2244           echo "  _registerTraceProjections();" >> $modInitSrc
2245         elif test $trace = "Tau"
2246         then
2247           TRACE_WITH_TAU=1
2248           echo "  _registerTraceTau();" >> $modInitSrc
2249         elif test $trace = "simple"
2250         then
2251           echo "  _registerTraceSimple();" >> $modInitSrc
2252         elif test $trace = "utilization"
2253         then
2254           echo "  _registerTraceUtilization();" >>  $modInitSrc
2255         elif test $trace = "controlPoints"
2256         then
2257           echo "  _registerTraceControlPoints();" >> $modInitSrc
2258         elif test $trace = "perfReport"
2259         then
2260           echo "  _registerTraceAutoPerf();" >> $modInitSrc
2261         elif test $trace = "all"
2262         then
2263           echo "  _registerTraceProjections();" >> $modInitSrc
2264           echo "  _registerTraceControlPoints();" >> $modInitSrc
2265           echo "  _registerTraceSummary();" >> $modInitSrc
2266         fi
2267     done
2268     if test -n "$BALANCER"
2269     then
2270         [ -n "$VERBOSE" ] && echo "Adding load balancer for $BALANCER"
2271         for deflb in $BALANCER
2272         do
2273           echo "  LBDefaultCreate(\"$deflb\");" >> $modInitSrc
2274         done
2275     fi
2276     echo "}" >> $modInitSrc
2277
2278     # creating projections
2279     echo "void _createTraces(char **argv) { (void)argv;" >> $modInitSrc
2280     for trace in $TRACEMODE; do
2281         [ -n "$VERBOSE" ] && echo "Adding registration for trace $trace"
2282         echo "extern void _createTrace$trace(char **argv);" >> $modInitSrc
2283         echo "_createTrace$trace(argv);" >> $modInitSrc
2284     done
2285     echo "}" >> $modInitSrc
2286
2287     Do $CHARM_CXX $CHARM_CXX_FLAGS -c $modInitSrc -o $modInitObj
2288 fi
2289
2290 ###############################################################################
2291 #
2292 #                               Finally, LINK
2293 #
2294 ###############################################################################
2295
2296 Debug "About to perform final link..."
2297
2298 #currently only support creation of .a
2299 if [ "$MPI_INTEROPERATE" != "" ]
2300 then
2301 case "$OBJECT" in
2302 *.a)
2303         # in case building charm so, build .so under lib_so as well # Gengbin
2304         DoNoErrCheck $RM $OBJECT
2305         if [ -z "$SKIP_MODULEINIT" ]
2306         then
2307                 echo "$CMK_AR $OBJECT $OBJECTFILES $modInitObj"
2308                 Do $CMK_AR $OBJECT $OBJECTFILES $modInitObj
2309         fi
2310         Do $CMK_RANLIB $OBJECT
2311         echo "export CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\"" > ./charm_all_libs.sh
2312         echo "CHARM_ALL_LIBS=\"$CHARM_ALL_LIBS\""
2313         Copyobj
2314         ;;
2315 *.so|*.so.*|*.sl|*.dylib)
2316         echo "Warning: building shared library failed; for interoperation build
2317         static library."
2318         End 0
2319         ;;
2320 esac
2321 fi
2322
2323 if [ "$BUILD_SHARE" = "1" -a "$CHARM_SHARED" = "1" ]
2324 then
2325   # build an application .so linking with charm .so
2326   OPTS_LD="$OPTS_LD $CMK_LD_SHARED $OPTS_LDRO -L$CHARMLIBSO"
2327   Debugf "Running ldro..."
2328   DoNoErrCheck $RM $OBJECT
2329   [ "$MAKE_LDXX" = "1" ] && Do $CMK_LDXX $CMK_LDXX_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2330   [ "$MAKE_LD" = "1" ] && Do $CMK_LD $CMK_LD_FLAGS $CMK_LIBDIR $OPTS_LD -o $OBJECT $ALL_LIBS
2331   Copyobj
2332 else
2333 # Make a regular executable: call the appropriate linker
2334   [ "$MAKE_LDXX" = "1" ] && Do $CHARM_LDXX $CHARM_LDXX_FLAGS -o $OBJECT
2335   [ "$MAKE_LD" = "1" ] && Do $CHARM_LD $CHARM_LD_FLAGS -o $OBJECT
2336 fi
2337
2338 ########################################################################
2339 #
2340 # Copy conv-host to user directory if it is present in installation.
2341 #
2342 ########################################################################
2343
2344 if test "$COPY_CHARMRUN" = "true"
2345 then
2346   targ=charmrun$CMK_POST_EXE
2347   [ ! -x $CHARMBIN/$targ -a -n "$CMK_POST_EXE" ] && targ=charmrun
2348   convhost=conv-host$CMK_POST_EXE
2349
2350   if [ -x $CHARMBIN/$targ ]
2351   then
2352         DoNoErrCheck $RM $targ
2353         DoNoErrCheck $CP $CHARMBIN/$targ $targ 2> /dev/null
2354   fi
2355 fi
2356
2357 [ -z "$SKIP_MODULEINIT" -a -z "$SAVE" ] && DoNoErrCheck $RM $modInitSrc $modInitObj > /dev/null 2>&1
2358
2359 Copyobj