00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include <stdio.h>
00049 #include <stdlib.h>
00050 #include <strings.h>
00051 #include <unistd.h>
00052 #include <errno.h>
00053 #include <sys/param.h>
00054 #if !defined(_WIN32)
00055 #include <sys/utsname.h>
00056 #include <sys/resource.h>
00057 #endif
00058 #include <sys/time.h>
00059 #include "pathscale_defs.h"
00060
00061 #include "phases.h"
00062 #include "options.h"
00063 #include "lang_defs.h"
00064 #include "option_seen.h"
00065 #include "option_names.h"
00066 #include "string_utils.h"
00067 #include "errors.h"
00068 #include "file_names.h"
00069 #include "file_utils.h"
00070 #include "run.h"
00071 #include "objects.h"
00072 #include "opt_actions.h"
00073 #include "profile_type.h"
00074 #include "lib_phase_dir.h"
00075
00076 int subverbose ;
00077
00078 char *outfile = NULL;
00079 char *prof_file = NULL;
00080 char *fb_file = NULL;
00081 char *internal_fb_file = NULL;
00082 char *opt_file = NULL;
00083 char *fb_xdir = NULL;
00084 char *fb_cdir = NULL;
00085 char *command_line = NULL;
00086 char *fb_phase = NULL;
00087 char *fb_type = NULL;
00088 char *source_file = NULL;
00089 #ifdef KEY
00090 char *coco_setfile = NULL;
00091 #endif
00092
00093 boolean multiple_source_files = FALSE;
00094
00095 boolean keep_mp = FALSE;
00096 boolean keep_list = FALSE;
00097 boolean keep_cif = FALSE;
00098 boolean keep_listing = FALSE;
00099 boolean auto_parallelize = FALSE;
00100 boolean Gen_feedback = FALSE;
00101 boolean Use_feedback = FALSE;
00102 boolean Disable_open_mp = FALSE;
00103 boolean Disable_old_mp = FALSE;
00104 boolean O3_flag = FALSE;
00105 boolean use_cpp = FALSE;
00106 #ifdef KEY
00107 boolean expand_ftpp_macros = TRUE;
00108 #else
00109 boolean expand_ftpp_macros = FALSE;
00110 #endif
00111 int fortran_line_length = 72;
00112 char roundoff=0;
00113 boolean nocpp_flag = FALSE;
00114
00115 char *global_toolroot = NULL;
00116 char *ld_library_path = NULL;
00117 char *ld_libraryn32_path = NULL;
00118 char *orig_program_name = NULL;
00119 char *old_ld_library_path = NULL;
00120 #ifdef TARG_SL
00121 boolean ldscript_file = FALSE;
00122 boolean Long_Long_Support = FALSE;
00123 boolean Float_Point_Support = FALSE;
00124 #endif
00125
00126 extern void turn_down_opt_level (int new_olevel, char *msg);
00127
00128 static string_list_t *ipl_cmds = 0;
00129
00130 static boolean string_md = FALSE;
00131 static boolean string_mmd = FALSE;
00132 extern string_list_t *feedback_files;
00133
00134 #if 0
00135 extern boolean is_replacement_combo (int);
00136 #endif
00137 static void convert_saved_command_line_into_string(void);
00138 static char *make_ii_file_name(char *objname);
00139 static char *make_rii_file_name(char *objname);
00140 static int update_instantiation_info_file(char* ii_file_name, char *sourcefile);
00141 static void write_command_string_into_file(FILE *cmdfile,
00142 char *sourcefile,
00143 int for_ii_file);
00144 static void add_command_line_arg(string_list_t *args, char *sourcefile);
00145
00146 static void do_f90_common_args(string_list_t *args) ;
00147 static void set_f90_source_form(string_list_t *args,boolean set_line_length) ;
00148 #ifdef KEY
00149 static void set_stack_size();
00150 #endif
00151
00152 static phases_t
00153 post_fe_phase (void);
00154
00155 static boolean
00156 previous_mf_exists (string_list_t *list)
00157 {
00158 string_item_t * p;
00159
00160 for (p = list->head; p != NULL; p = p->next) {
00161 if (strcmp (p->name, "-MF") == 0) {
00162 return TRUE;
00163 }
00164 }
00165 return FALSE;
00166 }
00167
00168 static void
00169 remove_previous_mf (string_list_t *list)
00170 {
00171 string_item_t * p;
00172
00173 for (p = list->head; p != NULL; p = p->next) {
00174 if (strcmp (p->name, "-MF") == 0) {
00175 replace_string (list, p->name, "");
00176 replace_string (list, p->next->name, "");
00177 }
00178 }
00179 }
00180
00181 static void
00182 add_implied_string (string_list_t *list, int iflag, int flag, phases_t phase)
00183 {
00184
00185 char *iname = get_current_implied_name();
00186
00187 if (strncmp (iname, "-MF", 3) == 0) {
00188 remove_previous_mf (list);
00189 }
00190
00191 #ifdef KEY
00192
00193 if (phase == P_f_coco) {
00194
00195 char *name = get_option_name(flag);
00196 if (!strncmp(iname, "-D", 2) &&
00197 strncmp(name, "-D", 2))
00198 return;
00199
00200
00201 if (!strncmp(iname, "-O", 2))
00202 return;
00203 }
00204 #endif
00205
00206 if (option_has_blank(iflag))
00207
00208 #ifndef KEY
00209 add_multi_strings(list, iname);
00210 #else
00211
00212 add_multi_strings(list, iname, strncmp(iname, "-MT", 3) == 0);
00213 #endif
00214 else {
00215
00216 if ( strcmp(iname, "-MD") ==0 ) {
00217 if ( string_md == FALSE ) {
00218 add_string(list, "-M");
00219 if (!previous_mf_exists (list)) {
00220 add_string(list, "-MF");
00221
00222
00223
00224
00225
00226
00227 if (outfile)
00228 {
00229 add_string(list, change_suffix(outfile, "d"));
00230 add_string(list, "-MQ");
00231 add_string(list, outfile);
00232 }
00233 else
00234 add_string(list, change_suffix(drop_path(source_file), "d"));
00235 }
00236 string_md = TRUE;
00237 }
00238 else {
00239 string_md = FALSE;
00240 add_string(list, iname);
00241 }
00242 }
00243
00244 else if ( strcmp(iname, "-MMD") ==0 ) {
00245 if ( string_mmd == FALSE ) {
00246 add_string(list, "-MM");
00247 if (!previous_mf_exists (list)) {
00248 add_string(list, "-MF");
00249
00250 if (outfile)
00251 {
00252 add_string(list, change_suffix(outfile, "d"));
00253 add_string(list, "-MQ");
00254 add_string(list, outfile);
00255 }
00256 else
00257 add_string(list, change_suffix(drop_path(source_file), "d"));
00258 }
00259 string_mmd = TRUE;
00260 }
00261 else {
00262 string_mmd = FALSE;
00263 add_string(list, iname);
00264 }
00265 }
00266 else
00267 add_string(list, iname);
00268 }
00269 }
00270
00271 static void
00272 copy_phase_options (string_list_t *phase_list, phases_t phase)
00273 {
00274 int flag;
00275 int iflag;
00276 FOREACH_OPTION_SEEN(flag) {
00277 FOREACH_IMPLIED_OPTION(iflag, flag) {
00278 boolean matches_phase = FALSE;
00279
00280
00281
00282
00283
00284 #ifdef KEY // Hack to filter out -OPT: options to spin_cc1,
00285
00286
00287
00288
00289
00290 if (gnu_major_version == 4 &&
00291 !strcmp("-OPT:", get_option_name(iflag))) {
00292 if (phase == P_spin_cc1 ||
00293 phase == P_spin_cc1plus)
00294 continue;
00295 else if (phase == P_wgen)
00296 matches_phase = TRUE;
00297 else
00298 matches_phase = option_matches_phase(iflag, phase);
00299 } else
00300 #endif
00301 matches_phase = option_matches_phase(iflag, phase);
00302
00303 if (matches_phase
00304 && option_matches_language(flag, source_lang)
00305 && !is_object_option(iflag) )
00306 {
00307
00308
00309 if (option_matches_language(iflag, source_lang)
00310 || (is_matching_phase(get_phase_mask(phase), P_any_cpp)
00311 && option_matches_language(iflag, L_cpp) ) )
00312 {
00313 add_implied_string (phase_list, iflag, flag,
00314 phase);
00315 }
00316 }
00317 }
00318 }
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 static void
00333 add_language_option ( string_list_t *args )
00334 {
00335 switch ( invoked_lang ) {
00336 case L_f77:
00337 add_string ( args, "-LANG:=f77" );
00338 break;
00339 case L_f90:
00340 add_string ( args, "-LANG:=f90" );
00341 break;
00342 case L_cc:
00343 if ( ansi == KR_ANSI ) {
00344 add_string ( args, "-LANG:=kr_c" );
00345 } else {
00346 add_string ( args, "-LANG:=ansi_c" );
00347 }
00348 break;
00349 case L_CC:
00350 add_string ( args, "-LANG:=cplus" );
00351 break;
00352 }
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 static void
00365 add_targ_options ( string_list_t *args )
00366 {
00367
00368 if (target_cpu != NULL) {
00369 char buf[100];
00370 sprintf(buf, "-TARG:processor=%s", target_cpu);
00371 add_string(args, buf);
00372 }
00373
00374 #ifdef TARG_X8664
00375
00376 if (sse2 == TRUE) {
00377 add_string(args, "-TARG:sse2=on");
00378 mmx = TRUE;
00379 sse = TRUE;
00380 } else
00381 add_string(args, "-TARG:sse2=off");
00382
00383 if (mmx == TRUE)
00384 add_string(args, "-TARG:mmx=on");
00385 else
00386 add_string(args, "-TARG:mmx=off");
00387
00388 if (sse == TRUE)
00389 add_string(args, "-TARG:sse=on");
00390 else
00391 add_string(args, "-TARG:sse=off");
00392
00393 if (sse3 == TRUE)
00394 add_string(args, "-TARG:sse3=on");
00395 else
00396 add_string(args, "-TARG:sse3=off");
00397
00398 if (m3dnow == TRUE)
00399 add_string(args, "-TARG:3dnow=on");
00400 else
00401 add_string(args, "-TARG:3dnow=off");
00402
00403 if (sse4a == TRUE)
00404 add_string(args, "-TARG:sse4a=on");
00405 else
00406 add_string(args, "-TARG:sse4a=off");
00407 #endif
00408 }
00409
00410 static char basebuf[4096];
00411
00412 char *driver_basename(char *const s)
00413 {
00414 register char *p;
00415 register char *const t = basebuf;
00416
00417 if (s == NULL || *s == 0) {
00418 return strcpy(t, ".");
00419 } else {
00420 p = strcpy(t, s);
00421 p += strlen(p);
00422 while( p != t && is_dir_separator(*--p) )
00423 *p = '\0';
00424
00425 while( p != t ) {
00426 #if defined(__CYGWIN__) || defined(_WIN32)
00427 if ( p == t + 1 && t[1] == ':' )
00428 return ++p;
00429 #endif
00430 if( is_dir_separator(*--p) )
00431 return ++p;
00432 }
00433 return p;
00434 }
00435 }
00436 static char dirbuf[4096];
00437
00438 char *dirname(char *const s)
00439 {
00440 register char *p;
00441 register char *const t = dirbuf;
00442
00443 if (s == NULL || *s == 0) {
00444 return strcpy(t, ".");
00445 } else {
00446 p = strcpy(t, s);
00447 p += strlen(p);
00448 while( p != t && is_dir_separator(*--p) )
00449 ;
00450
00451 #if defined(__CYGWIN__) || defined(_WIN32)
00452 if ( p == t + 1 && t[1] == ':' ) {
00453 t[2] = 0;
00454 return t;
00455 }
00456 #endif
00457 if ( p == t && is_dir_separator(*p) )
00458 return strcpy(t, "/");
00459
00460 while( p != t ) {
00461 #if defined(__CYGWIN__) || defined(_WIN32)
00462 if ( p == t + 1 && *p == ':' ) {
00463 t[2] = '.';
00464 t[3] = 0;
00465 return t;
00466 }
00467 #endif
00468 if( is_dir_separator(*--p) ) {
00469 if ( p == t )
00470 return strcpy(t, "/");
00471 while ( is_dir_separator (*p) )
00472 p--;
00473 *++p = '\0';
00474 return t;
00475 }
00476 }
00477 return strcpy(t, ".");
00478 }
00479 }
00480
00481
00482 static char *input_source ;
00483
00484 static void add_arg(string_list_t *args, const char *format, ...)
00485 __attribute__((format (printf, 2, 3)));
00486
00487 static void
00488 add_arg(string_list_t *args, const char *format, ...)
00489 {
00490 char *arg;
00491 va_list ap;
00492
00493 va_start(ap, format);
00494
00495 vasprintf(&arg, format, ap);
00496 add_string(args, arg);
00497 free(arg);
00498
00499 va_end(ap);
00500 }
00501
00502
00503
00504 static void
00505 set_library_paths(string_list_t *args)
00506 {
00507 char *root_prefix = directory_path(get_executable_dir());
00508 char *our_path;
00509
00510 if (abi == ABI_N32) {
00511 #ifndef TARG_SL
00512 asprintf(&our_path, "%s/" LIBPATH "/32",
00513 global_toolroot);
00514 #else
00515 asprintf(&our_path, "%s/lib/",root_prefix);
00516 #endif
00517 } else {
00518 asprintf(&our_path, "%s/" LIBPATH, global_toolroot);
00519 }
00520
00521 add_string(args, concat_strings("-L", our_path));
00522
00523 free(our_path);
00524 #ifdef TARG_IA64
00525 our_path = get_phase_dir(P_library);
00526 add_string (args, concat_strings("-L", our_path));
00527
00528 our_path= get_phase_dir(P_alt_library);
00529 add_string (args, concat_strings("-L", our_path));
00530 #endif
00531 }
00532
00533
00534
00535
00536
00537
00538
00539 static char *
00540 fix_name_by_phase (char *name, phases_t phase)
00541 {
00542 char *new_name = name;
00543
00544 if (name != NULL && strcmp(name, "-") == 0) {
00545 switch (phase) {
00546 case P_cpp:
00547 case P_c_cpp:
00548 case P_cplus_cpp:
00549 case P_f_cpp:
00550 case P_f90_cpp:
00551 case P_ratfor:
00552 case P_m4:
00553 case P_gcpp:
00554 case P_gcpp_plus:
00555 break;
00556 default:
00557 switch (source_kind) {
00558 case S_f:
00559 case S_F:
00560 case S_f90:
00561 case S_F90:
00562 new_name = "stdin.f90";
00563 break;
00564 case S_C:
00565 case S_ii:
00566 new_name = "stdin.cc";
00567 break;
00568 case S_s:
00569 case S_S:
00570 new_name = "stdin.s";
00571 break;
00572 case S_c:
00573 default:
00574 new_name = "stdin.c";
00575 break;
00576 }
00577 }
00578 }
00579
00580 return new_name;
00581 }
00582
00583 char *
00584 fix_name_by_lang(char *name)
00585 {
00586 char *new_name = name;
00587
00588 if (name != NULL && strcmp(name, "-") == 0) {
00589 switch (source_lang) {
00590 case L_f77:
00591 case L_f90:
00592 new_name = "stdin.f";
00593 break;
00594 case L_as:
00595 new_name = "stdin.s";
00596 break;
00597 case L_CC:
00598 new_name = "stdin.cc";
00599 break;
00600 default:
00601 new_name = "stdin.c";
00602 }
00603 }
00604 return new_name;
00605 }
00606
00607 static void
00608 add_inc_path(string_list_t *args, const char *fmt, ...)
00609 __attribute__((format (printf, 2, 3)));
00610
00611 static void
00612 add_inc_path(string_list_t *args, const char *fmt, ...)
00613 {
00614 char *path;
00615 va_list ap;
00616
00617 va_start(ap, fmt);
00618 vasprintf(&path, fmt, ap);
00619 if (is_directory(path)) {
00620 add_string(args, "-isystem");
00621 add_string(args, path);
00622 }
00623 free(path);
00624 va_end(ap);
00625 }
00626
00627 boolean platform_is_64bit(void)
00628 {
00629 static boolean _64bit_set;
00630 static boolean _64bit;
00631
00632 if (!_64bit_set) {
00633 #if defined(_WIN32)
00634 _64bit = FALSE;
00635 #else
00636 struct utsname u;
00637
00638 uname(&u);
00639
00640 _64bit = strcmp(u.machine, "x86_64") == 0;
00641 #endif
00642 _64bit_set = TRUE;
00643 }
00644
00645 return _64bit;
00646 }
00647
00648 boolean
00649 target_is_native(void)
00650 {
00651 static boolean native;
00652 static boolean native_set;
00653
00654 if (!native_set) {
00655 if (platform_is_64bit()) {
00656 native = abi != ABI_N32;
00657 } else {
00658 native = abi == ABI_N32;
00659 }
00660
00661 native_set = TRUE;
00662 }
00663
00664 return native;
00665 }
00666
00667
00668
00669
00670
00671 static const char* dynamic_linker
00672 #ifdef TARG_IA64
00673 = "/lib/ld-linux-ia64.so.2"
00674 #endif
00675 ;
00676 static void
00677 specify_dyn_linker (string_list_t *args) {
00678 #ifdef TARG_IA64
00679 if (shared == CALL_SHARED) {
00680 add_string(args, "-dynamic-linker");
00681 add_string(args, (char*)dynamic_linker);
00682 }
00683 #endif
00684 }
00685
00686
00687 static const char* ipa_dynamic_linker
00688 #ifdef TARG_IA64
00689 = "-Wl,/lib/ld-linux-ia64.so.2"
00690 #endif
00691 ;
00692
00693
00694 static void
00695 specify_ipa_dyn_linker (string_list_t *args) {
00696 #ifdef TARG_IA64
00697 if (shared == CALL_SHARED) {
00698 add_string(args, "-Wl,-dynamic-linker");
00699 add_string(args, (char*)ipa_dynamic_linker);
00700 }
00701 #endif
00702 }
00703
00704 #ifdef KEY
00705
00706
00707 static void
00708 add_file_args_first (string_list_t *args, phases_t index)
00709 {
00710 switch (index) {
00711 case P_gcpp:
00712 case P_gcpp_plus:
00713
00714 if (option_was_seen(O_pthread))
00715 add_string(args, "-D_REENTRANT");
00716 #ifdef PSC_TO_OPEN64
00717 if (!option_was_seen(O_no_opencc)) {
00718 add_string(args, "-D__OPEN64__=\"" OPEN64_FULL_VERSION "\"");
00719 add_string(args, "-D__OPENCC__=" OPEN64_MAJOR_VERSION);
00720 add_string(args, "-D__OPENCC_MINOR__=" OPEN64_MINOR_VERSION);
00721 add_string(args, "-D__OPENCC_PATCHLEVEL__=" OPEN64_PATCH_LEVEL);
00722 }
00723 #endif
00724 }
00725 }
00726 #endif
00727
00728 #if defined(TARG_MIPS) && !defined(ARCH_MIPS)
00729 #define MIPS_CROSS_LIB_TOP_DIR "/opt/gentoo-root"
00730 #endif
00731
00732 #ifdef KEY
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742 static void
00743 add_isystem_dirs(string_list_t *args)
00744 {
00745 string_item_t *p;
00746 if (isystem_dirs) {
00747 for (p = isystem_dirs->head; p != NULL; p = p->next) {
00748 add_string(args, p->name);
00749 }
00750 }
00751 }
00752 #endif
00753
00754 static void
00755 add_file_args (string_list_t *args, phases_t index)
00756 {
00757 buffer_t buf;
00758 char *temp;
00759 string_item_t *p;
00760 char *count_file_name;
00761 char *the_file = fix_name_by_phase(source_file, index);
00762
00763
00764
00765 current_phase = P_NONE;
00766 switch (index) {
00767 case P_m4:
00768 add_string(args, the_file);
00769 add_string(args, ">");
00770 input_source = construct_given_name(the_file,"p", keep_flag);
00771 add_string(args, input_source);
00772 break;
00773 case P_ratfor:
00774 if (run_m4) {
00775 input_source = construct_given_name(the_file,"p", keep_flag);
00776 add_string(args, input_source);
00777 } else {
00778 add_string(args, the_file);
00779 }
00780 add_string(args, ">");
00781 input_source = construct_given_name(the_file,"f", TRUE);
00782 add_string(args, input_source);
00783 break;
00784 case P_cpp:
00785 if (source_lang == L_as) {
00786 add_string(args, "-Xdo_linesplice");
00787 add_string(args, "-dollar");
00788 }
00789
00790 case P_c_cpp:
00791 case P_cplus_cpp:
00792 case P_f_cpp:
00793 case P_f90_cpp:
00794 if (option_was_seen(O_usegfe)) {
00795 add_string(args, "-E");
00796 }
00797 if (index == P_f90_cpp) {
00798 if (expand_ftpp_macros) {
00799 add_string(args, "-F");
00800 }
00801 set_f90_source_form(args,TRUE);
00802 }
00803 if (input_source == NULL)
00804 input_source = string_copy(the_file);
00805 add_string(args, input_source);
00806 if (last_phase != P_any_cpp) {
00807 add_string(args, ">");
00808 current_phase = P_any_cpp;
00809 input_source = construct_name(input_source,"i");
00810 add_string(args, input_source);
00811 }
00812 break;
00813 case P_gcpp:
00814 case P_gcpp_plus:
00815 if (show_but_not_run)
00816 add_string(args, "-###");
00817 #if defined(TARG_X8664) || defined(TARG_NVISA)
00818 if( abi == ABI_N32 ){
00819 add_string(args, "-m32");
00820 }
00821 #elif defined(TARG_SL)
00822 add_string(args, "-D__JAVI__");
00823 add_string(args, "-D__SL__");
00824 add_string(args, "-D__MIPSEL__");
00825 add_string(args, "-DRAND32");
00826
00827 if (Float_Point_Support == TRUE)
00828 {
00829 add_string(args, "-D__UCLIBC_HAS_FLOATS__");
00830 add_string(args, "-D__HAS_FPU__");
00831 }
00832 #elif defined(TARG_MIPS)
00833 if( abi == ABI_N32 )
00834 add_string(args, "-mabi=n32");
00835 else
00836 add_string(args, "-mabi=64");
00837 #endif
00838
00839 if( ospace == TRUE ){
00840 add_string(args, "-Os");
00841 }
00842
00843 switch (source_lang) {
00844 case L_as:
00845 add_string(args, "-xassembler-with-cpp");
00846 break;
00847 case L_CC:
00848 add_string(args, "-xc++");
00849 break;
00850 case L_f77:
00851 case L_f90:
00852 add_string(args, "-traditional");
00853
00854 if (!option_was_seen(O_Wendif_labels))
00855 add_string(args, "-Wno-endif-labels");
00856 case L_cc:
00857 default:
00858 add_string(args, "-xc");
00859 break;
00860 }
00861
00862 #ifdef KEY
00863 if (gnu_exceptions == FALSE &&
00864 (source_lang == L_cc ||
00865 source_lang == L_CC)) {
00866 add_string(args, "-fno-exceptions");
00867 }
00868 #endif
00869
00870 if (!option_was_seen(O_nostdinc)) {
00871 char *root = directory_path(get_executable_dir());
00872 #ifdef PSC_TO_OPEN64
00873 add_inc_path(args, "%s/include/" OPEN64_FULL_VERSION,
00874 root);
00875 #endif
00876 if (source_lang == L_CC) {
00877 int v[4];
00878 get_gcc_version(v, 4);
00879 if (v[0] > 3 || (v[0] == 3 && v[1] >= 3)) {
00880 add_inc_path(args, "%s/include/"
00881 #ifdef PSC_TO_OPEN64
00882 OPEN64_FULL_VERSION
00883 #endif
00884 "/backward",
00885 root);
00886 }
00887 }
00888 add_inc_path(args, "%s/include", root);
00889 }
00890
00891
00892 add_string(args, "-E");
00893 if (sse2 == TRUE)
00894 add_string(args, "-msse2");
00895 else if(sse == TRUE)
00896 add_string(args, "-msse");
00897 else if(mmx == TRUE)
00898 add_string(args, "-mmmx");
00899
00900
00901 #if defined(TARG_SL)
00902 char *comp_target_root = getenv("COMP_TARGET_ROOT");
00903 char *root_prefix;
00904 char *inc_path;
00905 if (comp_target_root != NULL) {
00906 root_prefix = comp_target_root;
00907 asprintf(&inc_path, "%s/usr/include", root_prefix);
00908 }
00909 else {
00910 root_prefix = directory_path(get_executable_dir());
00911 asprintf(&inc_path, "%s/include", root_prefix);
00912 }
00913 add_string(args, "-isystem");
00914 add_string(args, inc_path);
00915 if (source_lang == L_CC) {
00916 asprintf(&inc_path, "%s/usr/include/c++", root_prefix);
00917 add_string(args, "-isystem");
00918 add_string(args, inc_path);
00919 }
00920 #endif
00921 #ifdef TARG_X8664
00922
00923 add_string(args, "-mfpmath=387");
00924 #endif
00925
00926 add_string(args, input_source);
00927 if (option_was_seen(O_E) && outfile != NULL) {
00928 add_string(args, "-o");
00929 add_string(args, outfile);
00930 }
00931 else if (last_phase != P_any_cpp) {
00932 current_phase = P_any_cpp;
00933 if (source_lang == L_CC)
00934 input_source = construct_name(input_source,"ii");
00935 else if (source_lang == L_as) {
00936 input_source = construct_name(input_source,"s");
00937 if (!keep_flag)
00938 input_source = concat_strings(input_source, ".s");
00939 }
00940 else
00941 input_source = construct_name(input_source,"i");
00942 add_string(args, "-o");
00943 add_string(args, input_source);
00944 }
00945 break;
00946 #ifdef KEY
00947 case P_f_coco:
00948 {
00949 char *fortran_source = input_source;
00950 current_phase = P_any_cpp;
00951 add_string(args, "-s");
00952 sprintf(buf, "-#%s", coco_setfile ? coco_setfile : "");
00953 add_string(args, buf);
00954 if (option_was_seen(O_E)) {
00955 if (outfile == NULL)
00956 add_string(args, "-E");
00957 else
00958 add_string(args, outfile);
00959 } else {
00960 input_source = construct_name(input_source, "i");
00961 add_string(args, input_source);
00962 }
00963 add_string(args, fortran_source);
00964 }
00965 break;
00966 #endif
00967 case P_pca:
00968 case P_pfa:
00969 sprintf(buf, "-I=%s", input_source);
00970 add_string(args, buf);
00971 sprintf(buf, "-original_filename=%s", the_file);
00972 add_string(args, buf);
00973 if (index == P_pfa)
00974 add_string(args, "-include=/usr/include");
00975 {
00976 char *list_suffix, *cmp_suffix;
00977 extern char *optargs;
00978
00979 if (roundoff) {
00980
00981 sprintf(buf, "-r=%c", roundoff);
00982 add_string(args, buf);
00983 } else if (O3_flag) {
00984
00985
00986 add_string(args, "-r=2");
00987 }
00988 if (index == P_pca) {
00989 cmp_suffix = "M";
00990 list_suffix = "L";
00991 } else {
00992
00993 cmp_suffix = "m";
00994 list_suffix = "l";
00995 }
00996 if (keep_list) {
00997 sprintf(buf, "-L=%s",
00998 construct_given_name(
00999 the_file, list_suffix, TRUE ));
01000 add_string(args, buf);
01001 } else {
01002 sprintf(buf, "-L=%s",
01003 construct_name(input_source,list_suffix));
01004 add_string(args, buf);
01005 }
01006 if (keep_mp) {
01007 input_source = construct_given_name(the_file,
01008 cmp_suffix, TRUE);
01009 sprintf(buf, "-analysis=%snl",
01010 construct_given_name(
01011 the_file, "a", TRUE ));
01012 add_string(args, buf);
01013 } else {
01014 input_source = construct_name(input_source,cmp_suffix);
01015 add_string(args, "-noanalysis");
01016 }
01017 }
01018 if (keep_listing) {
01019 sprintf(buf, "-lo=ocktl");
01020 add_string(args, buf);
01021 }
01022 sprintf(buf, "-CMP=%s", input_source);
01023 add_string(args, buf);
01024 add_string(args, "-cp=i");
01025 break;
01026 case P_mpc:
01027 sprintf(buf, "%s", input_source);
01028 add_string(args, buf);
01029 if (keep_mp) {
01030 input_source = construct_given_name(the_file, "P", TRUE);
01031 } else {
01032 input_source = construct_name(input_source, "P");
01033 }
01034 sprintf(buf, "-XK%s", input_source);
01035 add_string(args, buf);
01036 break;
01037 case P_f_fe:
01038 case P_cppf_fe:
01039 #ifdef KEY // Give -ansi to FTN fe and to the cpp embedded in the FTN fe.
01040
01041 if (ansi == STRICT_ANSI) {
01042 add_string(args, "-ansi");
01043 }
01044 add_targ_options ( args );
01045 #endif
01046
01047 if ( ipa == TRUE || inline_t == TRUE ) {
01048 add_string ( args, "-FE:full_split=off" );
01049 }
01050
01051 replace_string( args, "-fpic", "" );
01052 replace_string( args, "-fPIC", "" );
01053
01054 #ifndef KEY // -dsm no longer supported. Bug 4406.
01055
01056 if (option_was_seen(O_dsm)) {
01057 if (outfile != NULL && !multiple_source_files
01058 && remember_last_phase != P_any_ld)
01059 sprintf(buf, "-rii%s", make_rii_file_name(outfile)); else
01060 sprintf(buf,
01061 "-rii./rii_files/%s",
01062 construct_file_with_extension(the_file,
01063 "rii"));
01064 add_string(args, buf);
01065 }
01066 #endif
01067 sprintf(buf, "-fB,%s", construct_name(the_file,"B"));
01068 add_string(args, buf);
01069 if (keep_listing) {
01070 sprintf(buf, "-fl,%s",construct_given_name(the_file,"L",TRUE));
01071 add_string(args, buf);
01072 }
01073
01074 if (index == P_cppf_fe) {
01075 if (Disable_open_mp) {
01076 add_string(args,"-disable_open_mp");
01077 }
01078 if (Disable_old_mp) {
01079 add_string(args,"-disable_old_mp");
01080 }
01081 }
01082
01083 if (use_craylibs == TRUE) {
01084 add_string(args,"-TENV:io_library=cray");
01085 } else if (use_mipslibs == TRUE) {
01086 add_string(args,"-TENV:io_library=mips");
01087 } else {
01088
01089
01090
01091
01092 add_string(args,"-TENV:io_library=mips");
01093 }
01094 #ifdef KEY
01095 add_isystem_dirs(args);
01096 #endif
01097 #ifdef KEY
01098 {
01099 char *root = directory_path(get_executable_dir());
01100 #ifdef PSC_TO_OPEN64
01101 sprintf (buf, "-include=%s/include/" OPEN64_FULL_VERSION, root);
01102 #endif
01103 add_string(args, buf);
01104 }
01105 #endif
01106
01107 if (dashdash_flag)
01108 add_string(args,"--");
01109 add_string(args, input_source);
01110 break;
01111
01112 case P_lister:
01113 if (keep_listing) {
01114 char *listing_file;
01115 char *cif_file;
01116 char *has_path;
01117 input_source = string_copy(the_file);
01118 listing_file = construct_given_name(input_source,"L", TRUE);
01119 cif_file = construct_given_name(drop_path(the_file), "T", keep_flag || keep_cif);
01120 add_string(args, "-rs");
01121 add_string(args, "-rx");
01122 add_string(args, "-o");
01123 add_string(args, listing_file);
01124 add_string(args, input_source);
01125 has_path = strrchr (input_source, '/');
01126 if (has_path != NULL)
01127
01128 add_string(args, cif_file);
01129 }
01130 break;
01131
01132 case P_f90_fe:
01133 case P_cppf90_fe:
01134 #ifdef KEY // Give -ansi to FTN fe and to the cpp embedded in the FTN fe.
01135
01136 if (ansi == STRICT_ANSI) {
01137 add_string(args, "-ansi");
01138 }
01139 add_targ_options ( args );
01140 #endif
01141 if (index == P_cppf90_fe) {
01142 if (expand_ftpp_macros) {
01143 add_string(args, "-F");
01144 }
01145
01146 if (use_ftpp == 1) {
01147 add_string(args, "-ftpp");
01148 }
01149 }
01150
01151 replace_string ( args, "-fpic", "" );
01152 replace_string ( args, "-fPIC", "" );
01153 #ifdef KEY
01154 replace_string ( args, "-fno-pic", "" );
01155 replace_string ( args, "-fno-PIC", "" );
01156 #endif
01157
01158 if ( ipa == TRUE || inline_t == TRUE ) {
01159 add_string ( args, "-FE:full_split=off" );
01160 }
01161
01162 if (keep_listing) {
01163 add_string(args, "-Ca");
01164 }
01165
01166 #ifndef KEY // -dsm no longer supported. Bug 4406.
01167
01168 if (option_was_seen(O_dsm)) {
01169 if (outfile != NULL && !multiple_source_files
01170 && remember_last_phase != P_any_ld)
01171 sprintf(buf, "-rii%s", make_rii_file_name(outfile)); else
01172 sprintf(buf,
01173 "-rii./rii_files/%s",
01174 construct_file_with_extension(the_file,
01175 "rii"));
01176 add_string(args, buf);
01177 }
01178 #endif
01179 sprintf(buf, "-fB,%s", construct_name(the_file,"B"));
01180 add_string(args, buf);
01181 sprintf(buf, "-fC,%s", construct_given_name(the_file,"T",TRUE));
01182 add_string(args, buf);
01183 sprintf(buf, "-fD,%s", construct_given_name(the_file,"l",TRUE));
01184 add_string(args, buf);
01185
01186 if (option_was_seen(O_MDupdate) && !option_was_seen(O_MDtarget)) {
01187 add_string(args, "-MDtarget");
01188 add_string(args, construct_given_name(the_file,"o",TRUE));
01189 }
01190 if (keep_listing) {
01191 sprintf(buf, "-fl,%s",construct_given_name(the_file,"L",TRUE));
01192 add_string(args, buf);
01193 }
01194 do_f90_common_args(args) ;
01195
01196 #ifdef KEY
01197 add_isystem_dirs(args);
01198 #endif
01199 #ifdef KEY
01200 {
01201 char *root = directory_path(get_executable_dir());
01202 #ifdef PSC_TO_OPEN64
01203 sprintf (buf, "-include=%s/include/" OPEN64_FULL_VERSION, root);
01204 #endif
01205 add_string(args, buf);
01206 }
01207 #endif
01208
01209 if (Disable_open_mp) {
01210 add_string(args,"-disable_open_mp");
01211 }
01212
01213 if (Disable_old_mp) {
01214 add_string(args,"-disable_old_mp");
01215 }
01216 if (dashdash_flag)
01217 add_string(args,"--");
01218 add_string(args, input_source);
01219
01220 if (option_was_seen(O_E) && outfile != NULL) {
01221 add_string(args, "-o");
01222 add_string(args, outfile);
01223 }
01224
01225 break;
01226
01227 #ifdef KEY
01228 case P_spin_cc1:
01229 case P_spin_cc1plus:
01230 {
01231 #if !defined(_WIN32)
01232 struct utsname uts;
01233 uname(&uts);
01234 if (strstr(uts.machine, "x86_64") == NULL) {
01235 add_string(args, "-fi386-host");
01236 }
01237 #endif
01238 }
01239 if (gnu_exceptions == FALSE) {
01240 add_string(args, "-fno-gnu-exceptions");
01241 }
01242 if (fcxx_openmp == 1) {
01243 add_string(args, "-fcxx-openmp");
01244 }
01245 else if (fcxx_openmp == 0) {
01246 add_string(args, "-fno-cxx-openmp");
01247 }
01248
01249 #endif
01250 case P_c_gfe:
01251 case P_cplus_gfe:
01252 if (sse2 == TRUE)
01253 add_string(args, "-msse2");
01254 else if(sse == TRUE)
01255 add_string(args, "-msse");
01256 else if(mmx == TRUE)
01257 add_string(args, "-mmmx");
01258
01259
01260 if (show_but_not_run)
01261 add_string(args, "-###");
01262 add_string(args, "-dx");
01263 if (show_version) {
01264 add_string(args, "-version");
01265 }
01266 if (quiet_flag)
01267 add_string(args, "-quiet");
01268 #if defined(TARG_X8664) || defined(TARG_NVISA)
01269 if( abi == ABI_N32 )
01270 add_string(args, "-m32");
01271 #elif defined(TARG_MIPS)
01272 #ifndef TARG_SL
01273
01274 if (endian == ENDIAN_LITTLE)
01275 add_string(args, "-mel");
01276 else
01277 add_string(args, "-meb");
01278
01279
01280 if( abi == ABI_N32 )
01281 add_string(args, "-mabi=n32");
01282 else
01283 add_string(args, "-mabi=64");
01284 #endif
01285 #endif
01286
01287 if (!option_was_seen(O_fpreprocessed) &&
01288 !option_was_seen(O_fno_preprocessed)) {
01289 add_string(args, "-fpreprocessed");
01290 }
01291 #ifndef TARG_SL
01292 if( fbuiltin != 0 )
01293 add_string(args, "-fbuiltin" );
01294 else
01295 add_string(args, "-fno-builtin" );
01296 #endif
01297 if( fmath_errno == 0 )
01298 add_string(args, "-fno-math-errno");
01299
01300 if( ffast_math == 1 )
01301 add_string(args, "-ffast-math");
01302 #ifdef TARG_SL
01303 if (index == P_cplus_gfe) {
01304
01305 add_string(args, "-fno-exceptions");
01306 add_string(args, "-fno-rtti");
01307 }
01308 #endif
01309 add_string(args, "-dumpbase");
01310 #ifndef KEY
01311 add_string(args, drop_path(the_file));
01312 #else
01313
01314
01315
01316 add_string(args, the_file);
01317 #endif
01318 add_string(args, input_source);
01319
01320 #ifdef KEY
01321 if (index == P_spin_cc1 ||
01322 index == P_spin_cc1plus) {
01323 add_string(args, "-spinfile");
01324 add_string(args, construct_name(the_file, "spin"));
01325 break;
01326 }
01327 #endif
01328 add_string(args, "-o");
01329 add_string(args, construct_name(the_file,"B"));
01330 break;
01331 #ifdef KEY
01332 case P_wgen:
01333 sprintf(buf, "-fS,%s", construct_name(the_file, "spin"));
01334 add_string(args, buf);
01335 sprintf(buf, "-fB,%s", construct_name(the_file, "B"));
01336 add_string(args, buf);
01337 break;
01338 #endif
01339 case P_inline:
01340 if (source_kind == S_B)
01341 sprintf (buf, "-fB,%s", the_file);
01342 else
01343 sprintf(buf, "-fB,%s",
01344 construct_name(the_file,"B"));
01345 add_string (args, buf);
01346 sprintf (buf, "-fI,%s",
01347 construct_name(the_file,get_suffix_string(S_I)) );
01348 add_string (args, buf);
01349 if (dashdash_flag)
01350 add_string(args,"--");
01351 add_string(args, the_file);
01352 break;
01353 case P_ipl:
01354 add_language_option ( args );
01355 if (source_kind == S_B)
01356 sprintf (buf, "-fB,%s", the_file);
01357 else
01358 sprintf(buf, "-fB,%s",
01359 construct_name(the_file,"B"));
01360 add_string (args, buf);
01361
01362 if (instrumentation_invoked == TRUE) {
01363 if (fb_file != NULL)
01364 sprintf(buf, "-fi,%s.instr", fb_file);
01365 else if (outfile != NULL)
01366 sprintf (buf, "-fi,%s.instr", outfile);
01367 else
01368 sprintf (buf, "-fi,a.out.instr");
01369 add_string(args,buf);
01370 }
01371 else if (opt_file != NULL) {
01372
01373 sprintf(buf, "-ff,%s.instr", opt_file);
01374 add_string(args, buf);
01375 }
01376
01377 current_phase = P_any_as;
01378 if (outfile != NULL && last_phase == current_phase
01379 && !multiple_source_files
01380 && !(remember_last_phase == P_any_ld &&
01381 (
01382 #ifndef KEY
01383 option_was_seen(O_dsm) ||
01384 #endif
01385 (invoked_lang==L_CC))))
01386 {
01387 sprintf(buf, "-fo,%s", outfile);
01388 } else {
01389 #ifdef KEY
01390
01391
01392 sprintf(buf, "-fo,%s", get_object_file(the_file));
01393 #else
01394 sprintf(buf, "-fo,%s",
01395 construct_given_name(the_file,"o",
01396 (keep_flag || multiple_source_files || ((shared == RELOCATABLE) && (ipa == TRUE))) ? TRUE : FALSE));
01397 #endif
01398 }
01399 add_string(args, buf);
01400 if (dashdash_flag)
01401 add_string(args,"--");
01402 add_string(args, the_file);
01403
01404
01405 if (ipl_cmds != 0) {
01406 add_string (args, "-cmds");
01407 append_string_lists (args, ipl_cmds);
01408 }
01409 break;
01410 case P_be:
01411 #if defined(TARG_NVISA)
01412 case P_bec:
01413 #endif
01414 add_language_option ( args );
01415 add_targ_options ( args );
01416
01417 if (invoked_lang == L_f77) {
01418 if (use_craylibs == TRUE) {
01419 add_string(args,"-TENV:io_library=cray");
01420 } else if (use_mipslibs == TRUE) {
01421 add_string(args,"-TENV:io_library=mips");
01422 } else {
01423
01424
01425
01426
01427 add_string(args,"-TENV:io_library=mips");
01428 }
01429 }
01430
01431 switch (source_kind) {
01432 case S_B:
01433 if (post_fe_phase () == P_inline) {
01434 temp = construct_name(the_file,get_suffix_string(S_I));
01435 break;
01436 }
01437
01438 case S_I:
01439 case S_N:
01440 case S_O:
01441 temp = the_file;
01442 break;
01443 default:
01444 if (post_fe_phase () == P_inline)
01445 temp = construct_name(the_file,get_suffix_string(S_I));
01446 else
01447 temp = construct_name(the_file,"B");
01448 break;
01449 }
01450 sprintf (buf, "-fB,%s", temp);
01451 add_string(args, buf);
01452
01453 if (instrumentation_invoked == TRUE) {
01454 if (fb_file != NULL)
01455 sprintf(buf, "-fi,%s.instr", fb_file);
01456 else if (outfile != NULL)
01457 sprintf (buf, "-fi,%s.instr", outfile);
01458 else
01459 sprintf (buf, "-fi,a.out.instr");
01460 add_string(args,buf);
01461 }
01462 else if (opt_file != NULL) {
01463
01464 sprintf(buf, "-ff,%s.instr", opt_file);
01465 add_string(args, buf);
01466 }
01467
01468 if (internal_fb_file != NULL) {
01469
01470 sprintf(buf, "-ff,%s.instr", internal_fb_file);
01471 add_string(args, buf);
01472 }
01473
01474 #ifdef TARG_NVISA
01475 if (last_phase == P_bec && outfile != NULL) {
01476
01477 if (get_suffix(outfile) == NULL) {
01478
01479 error ("outfile (%s) should end in .c", outfile);
01480 return;
01481 }
01482 sprintf(buf, "-fc,%s", outfile);
01483 add_string(args, buf);
01484 }
01485 #endif
01486
01487 if (skip_as != TRUE || last_phase == P_be || keep_flag) {
01488
01489 add_string(args, "-s");
01490 current_phase = P_be;
01491 if (last_phase == P_be && outfile != NULL)
01492 input_source = outfile;
01493 else {
01494 #ifdef TARG_NVISA
01495 input_source = construct_name(the_file,"ptx");
01496 #else
01497 input_source = construct_name(the_file,"s");
01498 #endif
01499 }
01500 if (last_phase == P_be || keep_flag) {
01501 sprintf(buf, "-fs,%s", input_source);
01502 } else {
01503 char *s = concat_strings(input_source, ".s");
01504 mark_for_cleanup(s);
01505 sprintf(buf, "-fs,%s.s", input_source);
01506 }
01507 add_string(args, buf);
01508 }
01509 if (skip_as == TRUE && last_phase != P_be) {
01510
01511 current_phase = P_any_as;
01512
01513 if (outfile != NULL
01514 && last_phase == current_phase
01515 && !multiple_source_files
01516 #ifndef KEY
01517 && !(remember_last_phase == P_any_ld &&
01518 option_was_seen(O_dsm) )
01519 #endif
01520 )
01521 {
01522 sprintf(buf, "-fo,%s", outfile);
01523 } else {
01524 sprintf(buf, "-fo,%s",
01525 construct_given_name(the_file,"o",
01526 (keep_flag || multiple_source_files || ((shared == RELOCATABLE) && (ipa == TRUE))) ? TRUE : FALSE));
01527 }
01528 add_string(args, buf);
01529 }
01530 if (dashdash_flag)
01531 add_string(args,"--");
01532 add_string(args, the_file);
01533 break;
01534 case P_as:
01535 case P_gas:
01536 #ifdef KEY
01537 if (source_lang == L_as &&
01538 glevel >= 2) {
01539 #ifdef TARG_SL
01540 if (source_kind == S_S) {
01541 add_string(args, "-gdwarf2");
01542 } else
01543 #endif
01544 add_string(args, "-g");
01545 }
01546 #endif
01547 if (dashdash_flag)
01548 add_string(args,"--");
01549 if (show_but_not_run)
01550 add_string(args, "-###");
01551 {
01552 int len;
01553 #if defined(TARG_X8664) || defined(TARG_NVISA)
01554 if( abi == ABI_N32 )
01555 add_string(args, "-m32");
01556 #elif defined(TARG_MIPS) && !defined(TARG_SL)
01557 if( abi == ABI_N32 )
01558 add_string(args, "-mabi=n32");
01559 else
01560 add_string(args, "-mabi=64");
01561 #endif
01562
01563
01564
01565 len = strlen(input_source);
01566 if (input_source[len - 1] != 's' ||
01567 input_source[len - 2] != '.') {
01568 sprintf(buf, "%s.s", input_source);
01569 add_string(args, buf);
01570 } else {
01571 add_string(args, input_source);
01572 }
01573 }
01574 current_phase = P_any_as;
01575 #if defined TARG_X8664 || ( defined(KEY) && !defined(CROSS_COMPILATION))
01576 add_string(args, "-c");
01577 #endif
01578 #ifdef TARG_SL
01579
01580 add_string(args, "-mips64");
01581 add_string(args, "-qwa2");
01582 if (target_cpu != NULL) {
01583 if (strcmp(target_cpu, "sl1_dsp") == 0 || (strcmp(target_cpu, "sl1_pcore") == 0)) {
01584 add_string(args, "-march=sl1");
01585 } else if (strcmp(target_cpu, "sl2_pcore") == 0) {
01586 add_string(args, "-march=sl2");
01587 }
01588 }
01589 #endif
01590 add_string(args, "-o");
01591
01592
01593 if (outfile != NULL
01594 && last_phase == current_phase
01595 && !multiple_source_files
01596 #ifndef KEY
01597 && !(remember_last_phase == P_any_ld &&
01598 option_was_seen(O_dsm) )
01599 #endif
01600 )
01601 {
01602 add_string(args, outfile);
01603 } else {
01604
01605
01606
01607 if (!(keep_flag ||
01608 (ipa == TRUE) ||
01609 remember_last_phase == P_any_as)) {
01610 char *temp_obj_file = get_object_file (the_file);
01611 add_string(args, temp_obj_file);
01612 } else
01613 add_string(args, construct_given_name(the_file,"o",
01614 (keep_flag || multiple_source_files || ((shared == RELOCATABLE) && (ipa == TRUE))) ? TRUE : FALSE));
01615 }
01616 break;
01617 case P_ld:
01618 case P_ldplus:
01619
01620
01621
01622
01623
01624
01625 append_libraries_to_list (args);
01626 if (show_but_not_run)
01627 add_string(args, "-###");
01628 #if defined(TARG_X8664) || defined(TARG_NVISA)
01629 if( abi == ABI_N32 )
01630 add_string(args, "-m32");
01631 #elif defined(TARG_MIPS) && !defined(TARG_SL)
01632 if( abi == ABI_N32 )
01633 add_string(args, "-mabi=n32");
01634 else
01635 add_string(args, "-mabi=64");
01636 #endif
01637 set_library_paths(args);
01638 if (outfile != NULL) {
01639 add_string(args, "-o");
01640 add_string(args, outfile);
01641 }
01642 if (ftz_crt) {
01643 add_string(args, find_obj_path("ftz.o"));
01644 }
01645 #ifdef TARG_SL
01646 if (!option_was_seen(O_nostdlib)) {
01647 add_string(args, find_crt_path("crt1.o"));
01648 add_string(args, find_crt_path("crti.o"));
01649 if (index == P_ldplus) {
01650
01651 add_string(args, find_crt_path("crtbegin.o"));
01652 }
01653 }
01654 #endif
01655 break;
01656 case P_collect:
01657 case P_ipa_link:
01658 #if defined(TARG_X8664) || defined(TARG_NVISA)
01659 if( abi == ABI_N32 ) {
01660 add_string(args, "-m32");
01661 add_string(args, "-m");
01662 add_string(args,"elf_i386");
01663 }
01664 #elif defined(TARG_MIPS)
01665 if( abi == ABI_N32 ) {
01666 #ifndef TARG_SL
01667 add_string(args, "-mabi=n32");
01668 add_string(args, "-m");
01669 add_string(args, "elf32ltsmipn32");
01670 #endif
01671 }
01672 else {
01673 add_string(args, "-mabi=64");
01674 add_string(args, "-m");
01675 add_string(args, "elf64ltsmip");
01676 }
01677
01678
01679 #ifndef ARCH_MIPS
01680 add_library_dir (MIPS_CROSS_LIB_TOP_DIR);
01681 #endif
01682 #endif
01683
01684
01685 append_libraries_to_list (args);
01686
01687 set_library_paths(args);
01688
01689
01690 if ((shared != DSO_SHARED) && (shared != RELOCATABLE)
01691 && ! option_was_seen(O_nostartfiles))
01692 {
01693 add_string(args, find_crt_path("crt1.o"));
01694 add_string(args, find_crt_path("crti.o"));
01695 add_string(args, find_crt_path("crtbegin.o"));
01696 if (ftz_crt) {
01697 add_string(args, find_obj_path("ftz.o"));
01698 }
01699 }
01700 if (outfile != NULL) {
01701 add_string(args, "-o");
01702 add_string(args, outfile);
01703 }
01704
01705 if (instrumentation_invoked == TRUE && index != P_collect) {
01706 if (fb_file != NULL)
01707 sprintf(buf, "-IPA:propagate_feedback_file=%s", fb_file);
01708 else if (outfile != NULL)
01709 sprintf (buf, "-IPA:propagate_feedback_file=%s", outfile);
01710 else
01711 sprintf (buf, "-IPA:propagate_feedback_file=a.out");
01712 add_string(args,buf);
01713 }
01714
01715 if (opt_file != NULL && index != P_collect){
01716 sprintf(buf, "-IPA:propagate_annotation_file=%s", opt_file);
01717 add_string(args,buf);
01718 }
01719
01720
01721 break;
01722 case P_cord:
01723
01724 if (outfile != NULL)
01725 {
01726 add_string(args, "-o");
01727 add_string(args, outfile);
01728 }
01729 else
01730 {
01731 add_string(args, "-o");
01732 add_string(args, "a.out");
01733 }
01734
01735 add_string(args, create_temp_file_name("C"));
01736
01737 if (feedback_files->head) {
01738
01739 append_string_lists(args, feedback_files);
01740 }
01741 else if (outfile != NULL) {
01742
01743 add_string(args, concat_strings(outfile,".fb"));
01744 }
01745 else {
01746
01747 add_string(args, "a.out.fb");
01748 }
01749 break;
01750 case P_pixie:
01751
01752 if (outfile != NULL) {
01753 add_string(args, "-pixie_file");
01754 if (fb_xdir != NULL) {
01755 temp = concat_strings(fb_xdir, "/");
01756 temp = concat_strings(temp, drop_path(outfile));
01757 add_string(args, temp);
01758 } else {
01759 add_string(args, outfile);
01760 }
01761 count_file_name = concat_strings(drop_path(outfile), ".x.Counts");
01762 } else {
01763 add_string(args, "-pixie_file");
01764 if (fb_xdir != NULL) {
01765 temp = concat_strings(fb_xdir, "/");
01766 temp = concat_strings(temp, "a.out");
01767 add_string(args, temp);
01768 } else {
01769 add_string(args, "a.out");
01770 }
01771 count_file_name = concat_strings("a.out", ".x.Counts");
01772 }
01773 if (fb_xdir != NULL) {
01774 add_string(args, "-directory");
01775 add_string(args, fb_xdir);
01776 add_string(args, "-rpath");
01777 add_string(args, fb_xdir);
01778 }
01779 if (fb_cdir != NULL) {
01780 add_string(args, "-counts_file");
01781 temp = concat_strings(fb_cdir, "/");
01782 temp = concat_strings(temp, count_file_name);
01783 add_string(args, temp);
01784 }
01785 if (ldpath_for_pixie != NULL) {
01786 add_string(args, "-ldpath");
01787 add_string(args, ldpath_for_pixie);
01788 }
01789 add_string(args, input_source);
01790 break;
01791 case P_prof:
01792
01793 add_string(args, "-pixie");
01794 add_string(args, "-feedback");
01795 if (prof_file != NULL) {
01796 add_string(args, concat_strings(prof_file, ".x"));
01797 } else {
01798 internal_error("No count file was specified for a prof run");
01799 perror(program_name);
01800 }
01801 for (p = count_files->head; p != NULL; p = p->next)
01802 add_string(args, p->name);
01803 add_string(args, ">");
01804 add_string(args, "/dev/null");
01805 break;
01806 }
01807 }
01808
01809
01810
01811
01812
01813
01814
01815 static void
01816 get_libgcc_s_name(char **libgcc_s_std, char **libgcc_s_dir32)
01817 {
01818
01819
01820
01821
01822 if (abi == ABI_N32 && platform_is_64bit()) {
01823 int v = get_gcc_major_version();
01824 if (v < 4) {
01825 *libgcc_s_std = "gcc_s_32";
01826 *libgcc_s_dir32 = "gcc_s";
01827 return;
01828 }
01829 }
01830 *libgcc_s_std = "gcc_s";
01831 *libgcc_s_dir32 = NULL;
01832 }
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842 static void
01843 add_libgcc_s(string_list_t *args)
01844 {
01845 static char *libgcc_s = NULL;
01846 char *libgcc_s_std, *libgcc_s_dir32;
01847 static int path_set;
01848 string_item_t *p;
01849 char *name = NULL;
01850
01851 get_libgcc_s_name(&libgcc_s_std, &libgcc_s_dir32);
01852
01853
01854
01855
01856
01857 if (!path_set) {
01858 for (p = get_library_dirs()->head; p != NULL; p = p->next) {
01859 free(name);
01860 asprintf(&name, "%s/lib%s.so", p->name, libgcc_s_std);
01861 if (file_exists(name)) {
01862 add_arg(args, "-L%s", p->name);
01863 libgcc_s = libgcc_s_std;
01864 path_set = 1;
01865 break;
01866 }
01867
01868 free(name);
01869 asprintf(&name,"%s/../lib%s.so", p->name, libgcc_s_std);
01870 if (file_exists(name)) {
01871 add_arg(args, "-L%s/..", p->name);
01872 libgcc_s = libgcc_s_std;
01873 path_set = 1;
01874 break;
01875 }
01876
01877
01878
01879 if (libgcc_s_dir32 != NULL &&
01880
01881 strstr(p->name, "/32/") != NULL) {
01882 free(name);
01883 asprintf(&name,"%s/lib%s.so", p->name,
01884 libgcc_s_dir32);
01885 if (file_exists(name)) {
01886 add_arg(args, "-L%s", p->name);
01887 libgcc_s = libgcc_s_dir32;
01888 path_set = 1;
01889 break;
01890 }
01891 }
01892 }
01893
01894 free(name);
01895
01896
01897
01898
01899
01900 if (libgcc_s == NULL)
01901 libgcc_s = libgcc_s_std;
01902 }
01903
01904 add_library(args, libgcc_s);
01905 }
01906
01907 static void
01908 add_final_ld_args (string_list_t *args, phases_t ld_phase)
01909 {
01910 #ifdef TARG_X8664
01911 extern boolean link_with_mathlib;
01912 #if 0 // Bug 4813 - acml_mv is not in yet.
01913 if ((link_with_mathlib || source_lang == L_CC) &&
01914 option_was_seen(O_m64) &&
01915 strcmp(target_cpu, "em64t") && strcmp(target_cpu, "anyx86"))
01916
01917 add_library(args, "acml_mv");
01918 #endif
01919 if (option_was_seen(O_nodefaultlibs) || option_was_seen(O_nostdlib)) {
01920
01921 if (option_was_seen(O_compat_gcc) &&
01922 !option_was_seen(O_fno_fast_stdlib) &&
01923 !option_was_seen(O_nolibpscrt)) {
01924
01925 }
01926 return;
01927 }
01928 #endif
01929 #ifdef TARG_SL
01930 if (option_was_seen(O_nodefaultlibs) || option_was_seen(O_nostdlib)) {
01931
01932 char *cmd_path;
01933 char *cmp_tgt_root = NULL;
01934 if (ldscript_file) {
01935 cmp_tgt_root = getenv("LINK_SCRIPT");
01936 if (cmp_tgt_root == NULL) {
01937 error("Environment var LINK_SCRIPT not set");
01938 }
01939 else {
01940 add_string(args, "-T");
01941 asprintf(&cmd_path, "%s", cmp_tgt_root);
01942 add_string(args, cmd_path);
01943 }
01944 } else {
01945 cmp_tgt_root = getenv("COMP_TARGET_ROOT");
01946 if (use_bblibs == TRUE) {
01947 add_string(args, "-T");
01948 asprintf(&cmd_path, "%s/usr/lib/ldscripts/sl1-bb-common.ld", cmp_tgt_root);
01949 add_string(args, cmd_path);
01950 }
01951 }
01952
01953 if ((Long_Long_Support == TRUE) || (Float_Point_Support == TRUE))
01954 {
01955 add_string(args, "-lsl1m");
01956 }
01957 return;
01958 }
01959 #endif // SL
01960
01961 if (shared != RELOCATABLE) {
01962 if (invoked_lang == L_f90) {
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972 add_library(args, "fortran");
01973 add_string(args, "-lmv");
01974
01975 add_string(args, "-lm");
01976 add_library(args, "mv");
01977
01978 add_library(args, "m");
01979 add_library(args, "ffio");
01980
01981 }
01982 #ifdef KEY
01983 if (option_was_seen(O_mp) ||
01984 option_was_seen(O_apo) ||
01985 option_was_seen(O_fopenmp)) {
01986 add_string(args, "-lopenmp");
01987 }
01988
01989 if (option_was_seen (O_fprofile_arcs))
01990 add_string(args, "-lgcov");
01991 #else
01992 if (option_was_seen(O_mp)) {
01993 add_string(args, "-lmp");
01994 }
01995 #endif
01996 #ifdef KEY // bug 4230
01997 if (option_was_seen(O_pthread) ||
01998 option_was_seen(O_mp) ||
01999 option_was_seen(O_fopenmp) ||
02000 option_was_seen(O_apo)) {
02001 add_string(args, "-lpthread");
02002 }
02003 #endif
02004 }
02005
02006 #ifdef TARG_X8664
02007
02008
02009
02010 if (!option_was_seen(O_fno_fast_stdlib) &&
02011 !option_was_seen(O_nolibpscrt)) {
02012
02013 }
02014 #endif
02015
02016 #ifdef TARG_IA64
02017
02018
02019
02020 if (shared != DSO_SHARED && shared != RELOCATABLE &&
02021 ld_phase != P_ld && ld_phase != P_ldplus) {
02022 if (invoked_lang == L_CC) {
02023 add_library(args, "stdc++");
02024 }
02025 add_library (args, "gcc");
02026 add_library (args, "c");
02027 add_library(args, "gcc");
02028 }
02029 #elif !defined(TARG_SL)
02030 if (ipa == TRUE) {
02031 if (invoked_lang == L_CC) {
02032 add_library(args, "stdc++");
02033 }
02034 if (invoked_lang == L_CC && !option_was_seen(O_static)) {
02035 add_libgcc_s (args);
02036 }
02037 add_library (args, "gcc");
02038 add_library (args, "c");
02039 if (invoked_lang == L_CC && !option_was_seen(O_static))
02040 add_libgcc_s (args);
02041 add_library(args, "gcc");
02042 }
02043 #endif
02044 if (shared != RELOCATABLE) {
02045 if ( fbuiltin != 0 ) {
02046 #ifndef TARG_SL
02047
02048
02049
02050 if (invoked_lang != L_cc) {
02051 add_library(args, "mv");
02052
02053
02054 add_library(args, "m");
02055 }
02056 #else
02057 if (invoked_lang == L_CC)
02058 add_string(args, "-lstdc++");
02059 if ((Long_Long_Support == TRUE) || (Float_Point_Support == TRUE))
02060 {
02061
02062 add_string(args, "-lcx");
02063
02064
02065 add_string(args, "-lsl1m");
02066 }
02067 else
02068 {
02069
02070 add_string(args, "-lc");
02071 }
02072
02073
02074 char *cmd_path;
02075 char *cmp_tgt_root = NULL;
02076 if (ldscript_file) {
02077 cmp_tgt_root = getenv("LINK_SCRIPT");
02078 if (cmp_tgt_root == NULL) {
02079 error("Environment var LINK_SCRIPT not set");
02080 }
02081 else {
02082 add_string(args, "-T");
02083 asprintf(&cmd_path, "%s", cmp_tgt_root);
02084 add_string(args, cmd_path);
02085 }
02086 }
02087 else {
02088 add_string(args, "-T");
02089 cmp_tgt_root = getenv("COMP_TARGET_ROOT");
02090 if (use_bblibs == TRUE)
02091 asprintf(&cmd_path, "%s/usr/lib/ldscripts/sl1-bb-common.ld", cmp_tgt_root);
02092 else
02093 asprintf(&cmd_path, "%s/usr/lib/ldscripts/sl1-core-common.ld", cmp_tgt_root);
02094 add_string(args, cmd_path);
02095 }
02096
02097 if (invoked_lang == L_CC) {
02098 add_string(args, find_crt_path("crtend.o"));
02099 }
02100 add_string(args, find_crt_path("crtn.o"));
02101
02102 #endif
02103 }
02104 }
02105 #ifdef TARG_IA64
02106 if (shared != DSO_SHARED && shared != RELOCATABLE &&
02107 ld_phase != P_ld && ld_phase != P_ldplus) {
02108 add_string(args, find_crt_path("crtend.o"));
02109 add_string(args, find_crt_path("crtn.o"));
02110 }
02111 #else
02112 if (ipa == TRUE) {
02113 if (shared != DSO_SHARED && shared != RELOCATABLE) {
02114 add_string(args, find_crt_path("crtend.o"));
02115 #ifndef TARG_SL
02116 add_string(args, find_crt_path("crtn.o"));
02117 #endif
02118 }
02119 }
02120 #endif
02121 }
02122
02123 #ifdef TARG_IA64
02124 static void
02125 postprocess_ld_args (string_list_t *args)
02126 {
02127 string_item_t *p;
02128
02129 if (option_was_seen(O_pg) && !option_was_seen(O_nostdlib)) {
02130 if (prof_lib_exists("c"))
02131 add_library(args, "c");
02132 }
02133 }
02134
02135 static void
02136 add_rpath_link_option (string_list_t *args) {
02137
02138 phases_t ld_phase = determine_ld_phase (FALSE);
02139 if (ld_phase == P_ld || ld_phase == P_ldplus) {
02140 return;
02141 }
02142
02143 add_string (args,"-rpath-link");
02144 add_string (args,get_phase_dir(P_alt_library));
02145
02146
02147
02148
02149
02150
02151
02152 for (string_item_t* p = args->head; p != NULL; p = p->next) {
02153 char *dir = NULL;
02154 if (strncmp(p->name, "-L", 2))
02155 continue;
02156
02157 if (strlen(p->name) > 2) {
02158 dir = p->name + 2;
02159 } else if (p->next) {
02160 dir = p->next->name;
02161 }
02162
02163 add_after_string(args, p, dir);
02164 add_after_string(args, p, "-rpath-link");
02165 }
02166 }
02167 #else
02168 static void
02169 postprocess_ld_args (string_list_t *args)
02170 {
02171 string_item_t *p;
02172
02173 if (option_was_seen(O_pg) && !option_was_seen(O_nostdlib)) {
02174 if (prof_lib_exists("c"))
02175 add_library(args, "c");
02176 }
02177
02178
02179
02180
02181
02182
02183
02184
02185 for (p = args->head; p != NULL; p = p->next) {
02186 char *dir = NULL;
02187 if (strncmp(p->name, "-L", 2))
02188 continue;
02189
02190 if (strlen(p->name) > 2) {
02191 dir = p->name + 2;
02192 }
02193 else if (p->next) {
02194 dir = p->next->name;
02195 }
02196 if (dir) {
02197 add_after_string(args, p, concat_strings("-Wl,-rpath-link,", dir));
02198 }
02199 }
02200 }
02201 #endif
02202
02203 #define MAX_PHASE_ORDER 10
02204 static phases_t phase_order[MAX_PHASE_ORDER];
02205 static int phase_order_index = 0;
02206
02207 static phases_t be_phase = P_be;
02208
02209 static void
02210 add_phase (phases_t p)
02211 {
02212 phase_order[phase_order_index] = p;
02213 phase_order_index++;
02214 if (phase_order_index >= MAX_PHASE_ORDER)
02215 internal_error("too many phases");
02216 }
02217
02218
02219
02220 #ifdef KEY
02221
02222
02223
02224
02225
02226
02227
02228 #endif
02229 static phases_t
02230 post_fe_phase (void)
02231 {
02232 if (ipa == TRUE)
02233 return P_ipl;
02234 #ifdef KEY
02235
02236
02237
02238
02239
02240 else if (run_inline != UNDEFINED)
02241 return run_inline == TRUE ? P_inline : be_phase;
02242 #endif
02243 else if (inline_t == TRUE || inline_t == UNDEFINED)
02244 return P_inline;
02245 else
02246 return be_phase;
02247 }
02248
02249
02250
02251
02252 static void
02253 add_inline_option(void)
02254 {
02255 if (option_was_seen(O_INLINE_) || ( inline_t!= FALSE)) {
02256 switch (post_fe_phase()) {
02257 case P_ipl:
02258 add_phase_for_option(O_INLINE_, P_ipa_link);
02259 break;
02260 case P_inline:
02261 add_phase_for_option(O_INLINE_, P_inline);
02262 break;
02263 }
02264 }
02265 }
02266
02267 static void
02268 determine_phase_order (void)
02269 {
02270 phases_t next_phase = P_NONE;
02271 phases_t cpp_phase;
02272 phases_t asm_phase;
02273 phases_t link_phase;
02274 phase_order[0] = P_NONE;
02275 phase_order_index = 0;
02276
02277 #ifdef TARG_NVISA
02278 if (option_was_seen(O_multicore)) {
02279 be_phase = P_bec;
02280 }
02281 #endif
02282
02283
02284 if (source_lang == L_CC) {
02285 if (option_was_seen(O_usegfe)) {
02286 cpp_phase = P_gcpp_plus;
02287 } else {
02288 cpp_phase = P_cplus_cpp;
02289 }
02290 } else if (source_lang == L_cc) {
02291 #ifndef KEY // bug 5495
02292 if (option_was_seen(O_mp)) {
02293
02294 cpp_phase = P_cpp;
02295 }
02296 else
02297 #endif
02298 if (option_was_seen(O_usegfe)) {
02299 cpp_phase = P_gcpp;
02300 } else {
02301 cpp_phase = P_c_cpp;
02302 }
02303 } else if (source_lang == L_f77) {
02304 if (option_was_seen(O_mp)) {
02305
02306 cpp_phase = P_cpp;
02307 } else {
02308 cpp_phase = P_f_cpp;
02309 }
02310 #ifdef KEY
02311 } else if (use_coco == TRUE) {
02312 cpp_phase = P_f_coco;
02313 #endif
02314 } else if (source_lang == L_f90) {
02315 #ifdef KEY // bug 5946
02316 if (option_was_seen(O_ftpp)) {
02317 cpp_phase = P_cppf90_fe;
02318 } else if (option_was_seen(O_cpp)
02319 || option_was_seen(O_P)
02320 || option_was_seen(O_E)
02321 || (!option_was_seen(O_nocpp) &&
02322 (source_kind == S_F || source_kind == S_F90)))
02323 {
02324 if (option_was_seen(O_usegfe))
02325 cpp_phase = P_gcpp;
02326 else
02327 cpp_phase = P_cpp;
02328 } else {
02329 cpp_phase = P_NONE;
02330 }
02331 #else
02332 if (option_was_seen(O_cpp)) {
02333 if (option_was_seen(O_usegfe))
02334 cpp_phase = P_gcpp;
02335 else
02336 cpp_phase = P_cpp;
02337 } else if (use_ftpp == TRUE
02338 || option_was_seen(O_P)
02339 || option_was_seen(O_E))
02340 {
02341 cpp_phase = P_cppf90_fe;
02342 } else {
02343 cpp_phase = P_NONE;
02344 }
02345 #endif
02346 } else if (source_lang == L_as
02347 && (abi == ABI_I32 || abi == ABI_I64 || abi == ABI_IA32))
02348 {
02349 cpp_phase = P_gcpp;
02350 } else if (option_was_seen(O_usegfe)) {
02351 cpp_phase = P_gcpp;
02352 } else {
02353 cpp_phase = P_cpp;
02354 }
02355
02356 if (last_phase == P_any_cpp) {
02357 add_phase(cpp_phase);
02358 return;
02359 }
02360
02361
02362 asm_phase = P_gas;
02363
02364
02365 if (ipa == TRUE)
02366 link_phase = P_ipa_link;
02367 else if (invoked_lang == L_CC)
02368 link_phase = P_ldplus;
02369 else
02370 link_phase = P_ld;
02371
02372 #if defined(KEY) && !defined(TARG_NVISA)
02373
02374 phases_t c_fe = (gnu_major_version == 4) ? P_spin_cc1 : P_c_gfe;
02375 phases_t cplus_fe = (gnu_major_version == 4) ? P_spin_cc1plus : P_cplus_gfe;
02376 #else
02377 phases_t c_fe = P_c_gfe;
02378 phases_t cplus_fe = P_cplus_gfe;
02379 #endif
02380
02381 switch (source_kind) {
02382 case S_c:
02383 case S_C:
02384 if (first_phase != P_any_cpp) {
02385 next_phase = (source_lang == L_CC ? cplus_fe : c_fe);
02386 } else {
02387 if (source_lang == L_CC)
02388 add_phase(P_gcpp_plus);
02389 else
02390 add_phase(P_gcpp);
02391 next_phase = (source_lang == L_CC ? cplus_fe : c_fe);
02392 }
02393 break;
02394 case S_i:
02395 case S_ii:
02396 if (source_lang == L_f77)
02397 next_phase = P_f_fe;
02398 else if (source_lang == L_f90)
02399 next_phase = P_f90_fe;
02400 else if (source_lang == L_as)
02401 next_phase = asm_phase;
02402 else if (source_lang == L_CC)
02403 next_phase = cplus_fe;
02404 else if (source_lang == L_cc)
02405 next_phase = c_fe;
02406 else if (source_kind == S_ii)
02407 next_phase = cplus_fe;
02408 else
02409 next_phase = c_fe;
02410 break;
02411 case S_r:
02412 if (run_m4) add_phase(P_m4);
02413 add_phase(P_ratfor);
02414
02415 case S_f:
02416 case S_f90:
02417 if (cpp_phase == P_NONE) {
02418 next_phase = P_f90_fe;
02419 } else if (cpp_phase == P_cppf90_fe) {
02420
02421 next_phase = P_cppf90_fe;
02422 }
02423 else {
02424 add_phase(cpp_phase);
02425 next_phase = P_f90_fe;
02426 }
02427 break;
02428 case S_F:
02429 case S_F90:
02430 if ( option_was_seen(O_nocpp)) {
02431 next_phase = P_f90_fe;
02432 } else if (cpp_phase == P_NONE || cpp_phase == P_cppf90_fe) {
02433
02434 next_phase = P_cppf90_fe;
02435 } else {
02436 add_phase(cpp_phase);
02437 next_phase = P_f90_fe;
02438 }
02439 break;
02440 case S_s:
02441 if (option_was_seen(O_cpp)) {
02442 add_phase(cpp_phase);
02443 }
02444 next_phase = asm_phase;
02445 break;
02446 case S_S:
02447 if ( ! option_was_seen(O_nocpp)) {
02448 add_phase(cpp_phase);
02449 }
02450 next_phase = asm_phase;
02451 break;
02452 case S_B:
02453 next_phase = post_fe_phase ();
02454 break;
02455 case S_I:
02456 case S_N:
02457 case S_O:
02458 next_phase = be_phase;
02459 break;
02460 case S_o:
02461 next_phase = link_phase;
02462 break;
02463 }
02464
02465 while (next_phase != P_NONE) {
02466 if (last_phase < next_phase) {
02467 add_phase(P_NONE);
02468 next_phase = P_NONE;
02469 }
02470 switch (next_phase) {
02471 case P_pfa:
02472 add_phase(next_phase);
02473 next_phase = P_cppf_fe;
02474 break;
02475 case P_f_fe:
02476 case P_cppf_fe:
02477 case P_lister:
02478 case P_c_gfe:
02479 case P_cplus_gfe:
02480 add_phase(next_phase);
02481 next_phase = post_fe_phase ();
02482 break;
02483 #ifdef KEY
02484 case P_spin_cc1:
02485 case P_spin_cc1plus:
02486 add_phase(next_phase);
02487 next_phase = P_wgen;
02488 break;
02489
02490 case P_wgen:
02491 add_phase(next_phase);
02492 next_phase = post_fe_phase ();
02493 break;
02494 #endif
02495 case P_f90_fe:
02496 case P_cppf90_fe:
02497 if (keep_listing) {
02498 add_phase(next_phase);
02499 next_phase = P_lister;
02500 } else {
02501 add_phase (next_phase);
02502 next_phase = post_fe_phase ();
02503 }
02504 break;
02505 case P_inline:
02506 add_phase (next_phase);
02507 next_phase = be_phase;
02508 break;
02509 case P_ipl:
02510 add_phase(next_phase);
02511 if (option_was_seen(O_ar)) {
02512 next_phase = P_ar;
02513 }
02514 else {
02515 next_phase = link_phase;
02516 }
02517 break;
02518 case P_be:
02519 add_phase(next_phase);
02520
02521 if (skip_as == TRUE) {
02522 if (option_was_seen(O_ar)) {
02523 next_phase = P_ar;
02524 }
02525 else {
02526 next_phase = link_phase;
02527 }
02528 }
02529 else next_phase = asm_phase;
02530 break;
02531 #if defined(TARG_NVISA)
02532 case P_bec:
02533 add_phase(next_phase);
02534 next_phase = P_NONE;
02535 break;
02536 #endif
02537 case P_as:
02538 case P_gas:
02539 add_phase(next_phase);
02540 if (option_was_seen(O_ar)) {
02541 next_phase = P_ar;
02542 }
02543 else {
02544 next_phase = link_phase;
02545 }
02546 break;
02547 case P_ld:
02548 case P_ldplus:
02549 case P_collect:
02550 case P_ipa_link:
02551 add_phase(next_phase);
02552 if (cordflag==TRUE) {
02553 next_phase = P_cord;
02554 } else {
02555 add_phase(P_NONE);
02556 next_phase = P_NONE;
02557 }
02558 break;
02559 case P_cord:
02560 add_phase(next_phase);
02561 add_phase(P_NONE);
02562 next_phase = P_NONE;
02563 break;
02564 case P_NONE:
02565 break;
02566 default:
02567 internal_error("unexpected phase order");
02568 }
02569 }
02570 }
02571
02572 #ifdef _WIN32
02573 #define EXE ".exe"
02574 #define DSO ".dll"
02575 #else
02576 #ifdef __CYGWIN__
02577 #define EXE ""
02578 #define DSO ".dll"
02579 #else
02580 #define EXE ""
02581 #define DSO ".so"
02582 #endif
02583 #endif
02584
02585 static void
02586 check_existence_of_phases (void)
02587 {
02588 int i;
02589 for (i = 0; phase_order[i] != P_NONE; i++) {
02590 int give_warning = FALSE;
02591 switch (phase_order[i]) {
02592
02593 case P_pfa:
02594 if (!file_exists(get_full_phase_name(phase_order[i]))) {
02595 error("Power Fortran is not installed on this system");
02596 }
02597 break;
02598
02599 case P_mpc:
02600
02601 if (!file_exists(get_full_phase_name(phase_order[i]))) {
02602 error("Power C is not installed on this system");
02603 }
02604 break;
02605
02606
02607
02608 case P_ipl:
02609 if (!file_exists (concat_strings (get_phase_dir(phase_order[i]),
02610 "/ipl"DSO)))
02611 give_warning = TRUE;
02612
02613
02614
02615 case P_be:
02616
02617 if (!file_exists (concat_strings (get_phase_dir(phase_order[i]),
02618 #ifndef SHARED_BUILD
02619 "/be"EXE)))
02620 #else
02621 "/be"DSO)))
02622 #endif
02623 give_warning = TRUE;
02624
02625 if (!file_exists(get_full_phase_name(phase_order[i])))
02626 give_warning = TRUE;
02627
02628 if (give_warning)
02629 warning ("%s does not contain all of the Open64 compiler"
02630 " phases.", get_phase_dir(phase_order[i]));
02631 break;
02632 }
02633 }
02634 }
02635
02636 static void
02637 add_instr_archive (string_list_t* args)
02638 {
02639 extern int profile_type;
02640
02641
02642 if (instrumentation_invoked != UNDEFINED && instrumentation_invoked) {
02643
02644 unsigned long f = WHIRL_PROFILE | CG_EDGE_PROFILE | CG_VALUE_PROFILE |
02645 CG_STRIDE_PROFILE ;
02646 if (!(profile_type & ~f)) {
02647 if (profile_type & (CG_EDGE_PROFILE |
02648 CG_VALUE_PROFILE | CG_STRIDE_PROFILE)) {
02649 add_library (args,"cginstr");
02650 }
02651
02652 add_library (args, "instr");
02653 #ifndef TARG_IA64
02654 if (!option_was_seen(O_static))
02655 add_libgcc_s (args);
02656 #endif
02657 } else {
02658 fprintf (stderr, "Unknown profile types %#lx\n", profile_type & ~f);
02659 }
02660 }
02661 }
02662
02663
02664 extern char *get_binutils_lib_path(void);
02665
02666 #if 0 // need not to set d_library_path
02667 static char *
02668 find_ld_library_path(char *program_name, char *ld_library_path)
02669 {
02670 char buf[PATH_BUF_LEN];
02671 int tail;
02672
02673 if(strchr(program_name, '/') == NULL) {
02674
02675 sprintf(buf, "which %s", program_name);
02676 read_cmd_out(buf, ld_library_path);
02677
02678 sprintf(buf, "dirname \"");
02679 realpath(ld_library_path, buf + strlen(buf));
02680
02681 } else {
02682 sprintf(buf, "dirname \"");
02683 realpath(program_name, buf + strlen(buf));
02684 }
02685
02686 tail = strlen(buf);
02687 buf[tail] = '"';
02688 buf[tail+1] = '\0';
02689 read_cmd_out(buf, ld_library_path);
02690
02691 return ld_library_path;
02692 }
02693 #endif
02694
02695 static char *
02696 find_toolroot(char *program_name, char *toolroot)
02697 {
02698 char buf[PATH_BUF_LEN];
02699 FILE* fp;
02700 int tail;
02701
02702 #ifdef _WIN32
02703 if (is_absolute_file_name(program_name)) {
02704 strcpy (toolroot, directory_path (program_name));
02705 }
02706 else {
02707 return NULL;
02708 }
02709 #else
02710 if(strchr(program_name, '/') == NULL) {
02711
02712 sprintf(buf, "dirname \"`which %s`\"", program_name);
02713 } else {
02714 sprintf(buf, "dirname \"%s\"", program_name);
02715 }
02716
02717 if((fp = popen(buf, "r")) == NULL)
02718 return NULL;
02719
02720 toolroot[0] = '\0';
02721 while(fgets(buf, PATH_BUF_LEN, fp) != NULL) {
02722 strcat(toolroot, buf);
02723 }
02724 pclose(fp);
02725 #endif
02726
02727 tail = strlen(toolroot);
02728 if(toolroot[tail - 1] == '\n') {
02729 toolroot[tail - 1] = '\0';
02730 }
02731
02732 strcat(toolroot, "/..");
02733
02734
02735 strcpy(toolroot, realpath(toolroot, buf));
02736
02737 return toolroot;
02738 }
02739
02740 static char ld_library_path_found[PATH_BUF_LEN];
02741
02742 void
02743 init_phase_info (void)
02744 {
02745 char *toolroot;
02746 char *comp_target_root;
02747
02748 if (getenv("_XPG") != NULL)
02749 xpg_flag = TRUE;
02750 ld_library_path = getenv("LD_LIBRARY_PATH");
02751 #if 0
02752 if(ld_library_path == NULL) {
02753 ld_library_path = find_ld_library_path(orig_program_name,
02754 ld_library_path_found);
02755 }
02756 #endif
02757 ld_libraryn32_path = getenv("LD_LIBRARYN32_PATH");
02758 old_ld_library_path = string_copy(ld_library_path);
02759
02760 if (old_ld_library_path) {
02761 int i;
02762 for (i=0; i<strlen(old_ld_library_path); i++) {
02763 if (old_ld_library_path[i] == ':')
02764 old_ld_library_path[i] = ';';
02765 }
02766 asprintf(&old_ld_library_path, "%s;%s", old_ld_library_path,
02767 get_binutils_lib_path());
02768 } else {
02769 old_ld_library_path = get_binutils_lib_path();
02770 }
02771
02772 global_toolroot = getenv("TOOLROOT");
02773
02774 #ifndef TARG_NVISA
02775 if (global_toolroot == NULL) {
02776 global_toolroot = (char *)malloc(PATH_BUF_LEN);
02777 if(find_toolroot(orig_program_name, global_toolroot) == NULL) {
02778 free(global_toolroot);
02779 global_toolroot = NULL;
02780 }
02781 }
02782 #endif
02783
02784 if (global_toolroot != NULL) {
02785
02786 #ifdef TARG_NVISA
02787
02788 prefix_all_phase_dirs(OPEN64_PHASE_MASK, global_toolroot);
02789 #else
02790 prefix_all_phase_dirs(PHASE_MASK, global_toolroot);
02791 #endif
02792 }
02793
02794 #ifdef TARG_IA64
02795 get_phases_real_path ();
02796 #endif
02797 comp_target_root = getenv("COMP_TARGET_ROOT");
02798 if (comp_target_root != NULL) {
02799
02800 prefix_all_phase_dirs(LIB_MASK, comp_target_root);
02801 }
02802 }
02803
02804
02805
02806 void
02807 init_phase_names (void)
02808 {
02809 #if !defined(_WIN32)
02810 char *prefix, *cmd, *x;
02811 char path[MAXPATHLEN];
02812 int i, j, len, rval;
02813
02814
02815
02816 rval = readlink ("/proc/self/exe", path, sizeof(path));
02817 if (rval <= 0) {
02818 strncpy(path, orig_program_name, sizeof(path));
02819 rval = strlen(path);
02820 } else {
02821 path[rval] = '\0';
02822 }
02823
02824
02825
02826 for (i = strlen(path)-1; i >= 0; i--) {
02827 if (path[i] == '/')
02828 break;
02829 }
02830 if (i < 0) {
02831
02832 cmd = path;
02833 } else {
02834
02835 cmd = path + i + 1;
02836 }
02837
02838
02839
02840
02841
02842
02843
02844 prefix = strdup(cmd);
02845 #ifdef PSC_TO_OPEN64
02846 if ((x = strstr(prefix, "-" OPEN64_FULL_VERSION))) {
02847 #endif
02848 *x = '\0';
02849 }
02850
02851 for (i = strlen(prefix)-1; i >= 0 && prefix[i] == '-'; i--);
02852
02853 for (j = i; j >= 0; j--) {
02854 if (prefix[j] == '-') {
02855 prefix[j+1] = '\0';
02856 break;
02857 }
02858 }
02859 if (j < 0)
02860 prefix[0] = '\0';
02861
02862 for (i = P_LAST-1; i >= (int) P_NONE; i--) {
02863 char *phase_name = get_phase_name(i);
02864 if (strcmp(phase_name, "gcc") == 0 ||
02865 strcmp(phase_name, "g++") == 0) {
02866 set_phase_name (i, concat_strings(prefix, phase_name));
02867 }
02868 }
02869 #endif
02870 }
02871
02872
02873 void
02874 init_frontend_phase_names (int gnu_major_version, int gnu_minor_version)
02875 {
02876
02877 if (gnu_major_version == 4) {
02878 switch (gnu_minor_version) {
02879 case 0:
02880 break;
02881 case 2:
02882 set_phase_name(P_spin_cc1, "cc142");
02883 set_phase_name(P_spin_cc1plus, "cc1plus42");
02884 set_phase_name(P_wgen, "wgen42");
02885 break;
02886 default:
02887 error("no support for GNU 4.%d front-end", gnu_minor_version);
02888 }
02889 }
02890 }
02891
02892 void
02893 run_dsm_prelink(void)
02894 {
02895 string_list_t *args = init_string_list();
02896 copy_phase_options(args, P_dsm_prelink);
02897 append_objects_to_list(args);
02898 run_phase(P_dsm_prelink, get_full_phase_name(P_dsm_prelink), args);
02899 }
02900
02901
02902 phases_t
02903 determine_ld_phase (boolean run_ipa) {
02904 phases_t ldphase;
02905 if (run_ipa) {
02906 ldphase = P_ipa_link;
02907 }
02908 #if defined TARG_IA64 && defined CROSS_COMPILATION
02909
02910
02911
02912 else {
02913 ldphase = P_collect;
02914 }
02915 #else
02916 else if (invoked_lang == L_CC) {
02917 ldphase = P_ldplus;
02918 }
02919 #ifdef TARG_IA64
02920 else if (invoked_lang == L_cc) {
02921 ldphase = P_ld;
02922 }
02923 else {
02924
02925 ldphase = P_collect;
02926 }
02927 #else
02928 else {
02929 ldphase = P_ld;
02930 }
02931 #endif
02932 #endif
02933 return ldphase;
02934 }
02935
02936 void
02937 run_ld (void)
02938 {
02939 phases_t ldphase;
02940 char *ldpath;
02941 string_list_t *args = init_string_list();
02942
02943 if (ipa == TRUE) {
02944 ldphase = P_ipa_link;
02945 }
02946 else if (invoked_lang == L_CC) {
02947 ldphase = P_ldplus;
02948 }
02949 else {
02950 ldphase = P_ld;
02951 }
02952
02953 #ifdef KEY
02954
02955 if (option_was_seen(O_melf_i386)) {
02956 add_string(args, "-m elf_i386");
02957 }
02958 if (option_was_seen(O_melf_x86_64)) {
02959 add_string(args, "-m elf_x86_64");
02960 }
02961 #endif
02962 if (ipa == TRUE) {
02963 char *str;
02964 ldpath = get_phase_dir (ldphase);
02965 ldpath = concat_strings (ldpath, "/ipa.so");
02966 if (!file_exists (ldpath)) {
02967 error ("ipa.so is not installed on %s", get_phase_dir (ldphase));
02968 return;
02969 }
02970
02971
02972 str = "-INTERNAL:old_ld_lib_path=";
02973 if (old_ld_library_path)
02974 str = concat_strings (str, old_ld_library_path);
02975 add_string(args, str);
02976
02977 char *root_prefix = directory_path(get_executable_dir());
02978 char *our_path;
02979
02980 if (abi == ABI_N32) {
02981 asprintf(&our_path, "%s" LIBPATH "/32", root_prefix);
02982 } else {
02983 asprintf(&our_path, "%s" LIBPATH, root_prefix);
02984 }
02985
02986 add_string(args, concat_strings("-L", our_path));
02987 free(our_path);
02988
02989
02990 switch (invoked_lang) {
02991 case L_f77: str = "F77"; break;
02992 case L_f90: str = "F90"; break;
02993 case L_cc: str = "C"; break;
02994 case L_CC: str = "CC"; break;
02995 default: internal_error("run_ld: unknown language\n");
02996 }
02997 add_string(args, concat_strings("-INTERNAL:lang=", str));
02998
02999 init_crt_paths ();
03000 if (invoked_lang == L_CC ||
03001 instrumentation_invoked == TRUE ) {
03002 init_stdc_plus_plus_path();
03003 }
03004 }
03005 ldpath = get_full_phase_name(ldphase);
03006
03007
03008
03009 add_inline_option ();
03010 copy_phase_options (args, ldphase);
03011
03012 if (invoked_lang == L_CC) {
03013 if (!multiple_source_files && !((shared == RELOCATABLE) && (ipa == TRUE) && (outfile == NULL)) && !keep_flag)
03014 mark_saved_object_for_cleanup();
03015 }
03016 add_file_args (args, ldphase);
03017
03018 if (shared == RELOCATABLE && source_file != NULL)
03019 add_string(args, construct_given_name(
03020 fix_name_by_lang(source_file),
03021 "o",
03022 outfile == NULL ? TRUE : keep_flag));
03023 else
03024 append_objects_to_list (args);
03025
03026
03027
03028
03029
03030
03031 #ifdef CROSS_COMPILATION
03032 specify_dyn_linker (args);
03033 #endif
03034
03035 #if defined(KEY) && defined(TARG_MIPS)
03036 add_string(args, "-mips64");
03037 #endif
03038
03039 add_instr_archive (args);
03040
03041 add_final_ld_args (args,ldphase);
03042 #ifndef TARG_SL
03043 if ( ldphase == P_ipa_link ) {
03044 specify_ipa_dyn_linker(args);
03045 }
03046 postprocess_ld_args (args);
03047 #endif
03048
03049 run_phase (ldphase, ldpath, args);
03050 }
03051
03052 void
03053 run_ar(void)
03054 {
03055 string_list_t *args = init_string_list();
03056 char *arpath;
03057 arpath = get_full_phase_name(P_ar);
03058
03059 add_string (args, "-rc");
03060 copy_phase_options (args, P_ar);
03061 add_string (args, outfile);
03062 append_ar_objects_to_list(args);
03063 run_phase (P_ar, arpath, args);
03064 }
03065
03066
03067
03068 void
03069 run_pixie (void)
03070 {
03071 int link_status;
03072 string_list_t *args = init_string_list();
03073 char *pixie_file;
03074 char *temp;
03075
03076 copy_phase_options (args, P_pixie);
03077 add_file_args (args, P_pixie);
03078 run_phase (P_pixie, get_full_phase_name(P_pixie), args);
03079 if (outfile != NULL)
03080 temp = string_copy(outfile);
03081 else
03082 temp = string_copy("a.out");
03083 if (fb_xdir != NULL) {
03084 #if defined(_WIN32)
03085 internal_error("cannot run pixie on windows");
03086 #else
03087 pixie_file = concat_strings(fb_xdir, "/");
03088 pixie_file = concat_strings(pixie_file, drop_path(temp));
03089 link_status = symlink(pixie_file, temp);
03090 if (link_status != 0) {
03091 if (errno == EEXIST) {
03092 warning("%s already exists; link from %s to %s not created",
03093 temp, temp, pixie_file);
03094 } else {
03095 internal_error("cannot create link from %s to %s",
03096 temp, pixie_file );
03097 perror(program_name);
03098 }
03099 }
03100 #endif
03101 }
03102 }
03103
03104 void
03105 run_prof (void)
03106 {
03107 int link_status;
03108 string_list_t *args = init_string_list();
03109 char *bin_dot_pixie, *bin_plain;
03110 boolean delete_link = TRUE;
03111
03112 #ifdef _WIN32
03113 internal_error("cannot run prof on windows");
03114 #else
03115 if (prof_file != NULL) {
03116 bin_plain = string_copy (prof_file);
03117 bin_dot_pixie = concat_strings(prof_file, ".x.pixie");
03118 } else {
03119 internal_error("No count file was specified for a prof run");
03120 perror(program_name);
03121 }
03122 link_status = link(bin_plain, bin_dot_pixie);
03123 if (link_status != 0) {
03124 delete_link = FALSE;
03125 if (errno == EEXIST) {
03126 warning("Link from %s to %s already exists",
03127 bin_dot_pixie, bin_plain );
03128 } else {
03129 internal_error("cannot create link from %s to %s",
03130 bin_dot_pixie, bin_plain );
03131 perror(program_name);
03132 }
03133 }
03134
03135 copy_phase_options (args, P_prof);
03136 add_file_args (args, P_prof);
03137 run_phase (P_prof, get_full_phase_name(P_prof), args);
03138
03139 if (delete_link) {
03140 int unlink_status;
03141 unlink_status = unlink(bin_dot_pixie);
03142 if (unlink_status != 0 && errno != ENOENT) {
03143 internal_error("cannot unlink %s", bin_dot_pixie );
03144 perror(program_name);
03145 }
03146 }
03147 #endif
03148 }
03149
03150 void
03151 run_compiler (int argc, char *argv[])
03152 {
03153 int i;
03154 string_list_t *args;
03155 boolean inst_info_updated = FALSE;
03156 boolean cmd_line_updated = FALSE;
03157 buffer_t rii_file_name;
03158 buffer_t ii_file_name;
03159
03160 clear_current_errors();
03161 determine_phase_order();
03162 add_inline_option();
03163 if (execute_flag) {
03164 check_existence_of_phases();
03165 }
03166 input_source = source_file;
03167 #ifdef KEY
03168
03169 set_stack_size();
03170 #endif
03171
03172 for (i = 0; phase_order[i] != P_NONE; i++) {
03173
03174
03175
03176 if (
03177 #ifdef KEY
03178 run_inline == FALSE &&
03179 #else
03180 inline_t == FALSE &&
03181 #endif
03182 phase_order[i] == P_inline)
03183 continue;
03184
03185 if (is_matching_phase(get_phase_mask(phase_order[i]), P_any_ld)) {
03186 source_kind = S_o;
03187
03188 source_lang = get_source_lang(source_kind);
03189 run_ld ();
03190 if (Gen_feedback)
03191 run_pixie ();
03192 } else {
03193 args = init_string_list();
03194 add_file_args_first (args, phase_order[i]);
03195 copy_phase_options (args, phase_order[i]);
03196 if (!cmd_line_updated &&
03197 phase_order[i] > P_any_optfe &&
03198 phase_order[i] != P_c_gfe &&
03199 phase_order[i] != P_cplus_gfe &&
03200 #ifdef KEY
03201 phase_order[i] != P_spin_cc1 &&
03202 phase_order[i] != P_spin_cc1plus &&
03203 phase_order[i] != P_wgen &&
03204 #endif
03205 phase_order[i] < P_any_fe)
03206 {
03207 add_command_line_arg(args, source_file);
03208 cmd_line_updated = TRUE;
03209 }
03210 add_file_args (args, phase_order[i]);
03211 if (has_current_errors()) break;
03212 run_phase (phase_order[i],
03213 get_full_phase_name(phase_order[i]), args);
03214
03215
03216
03217
03218 if (phase_order[i] == P_gcpp_plus)
03219 unsetenv("DEPENDENCIES_OUTPUT");
03220
03221 if ( i == 0 && (string_md == TRUE || string_mmd == TRUE)){
03222
03223
03224
03225 string_item_t * p;
03226 for (p = args->head; p != NULL; p = p->next) {
03227 if (strcmp (p->name, "-MF") == 0) {
03228 replace_string (args, p->name, "");
03229 replace_string (args, p->next->name, "");
03230 }
03231 if (strcmp (p->name, "-MT") == 0) {
03232 replace_string (args, p->name, "");
03233 replace_string (args, p->next->name, "");
03234 }
03235 if (strcmp (p->name, "-MQ") == 0) {
03236 replace_string (args, p->name, "");
03237 replace_string (args, p->next->name, "");
03238 }
03239 }
03240 replace_string (args, "-M", "");
03241 replace_string (args, "-MM", "");
03242 replace_string (args, "-MG", "");
03243 replace_string (args, "-MP", "");
03244 run_phase (phase_order[i],
03245 get_full_phase_name(phase_order[i]), args);
03246 string_md = FALSE;
03247 string_mmd = FALSE;
03248 }
03249 if (!inst_info_updated &&
03250 phase_order[i] > P_any_optfe &&
03251 phase_order[i] < P_any_fe) {
03252
03253
03254
03255
03256 #ifndef KEY // -dsm no longer supported. Bug 4406.
03257 if (option_was_seen(O_dsm)) {
03258 if (outfile != NULL && !multiple_source_files
03259 && remember_last_phase != P_any_ld)
03260
03261 sprintf(rii_file_name, "%s",
03262 make_rii_file_name(outfile));
03263 else
03264 sprintf(rii_file_name, "./rii_files/%s",
03265 construct_file_with_extension(
03266 fix_name_by_lang(source_file),
03267 "rii"));
03268 update_instantiation_info_file(
03269 rii_file_name,source_file);
03270 }
03271 #endif
03272 if (prelink_flag && source_lang == L_CC) {
03273 if (outfile != NULL && !multiple_source_files
03274 && remember_last_phase != P_any_ld)
03275 sprintf(ii_file_name, "%s",
03276 make_ii_file_name(outfile));
03277 else
03278 sprintf(ii_file_name,
03279 "./ii_files/%s",
03280 construct_file_with_extension(
03281 source_file, "ii"));
03282 update_instantiation_info_file(
03283 ii_file_name, source_file);
03284
03285 }
03286 inst_info_updated = TRUE;
03287 }
03288 }
03289 if (has_current_errors()) break;
03290 }
03291 }
03292
03293
03294
03295
03296
03297
03298
03299
03300
03301
03302
03303
03304
03305
03306
03307
03308
03309
03310
03311
03312 #define is_shell_special(c) \
03313 ( (c) == '\'' || \
03314 (c) == '|' || \
03315 (c) == '&' || \
03316 (c) == '*' || \
03317 (c) == '?' || \
03318 (c) == '[' || \
03319 (c) == ']' || \
03320 (c) == ';' || \
03321 (c) == '!' || \
03322 (c) == '(' || \
03323 (c) == ')' || \
03324 (c) == '^' || \
03325 (c) == '<' || \
03326 (c) == '>' || \
03327 (c) <= ' ' || \
03328 (c) == '\t' || \
03329 is_shell_quote_special(c) )
03330
03331
03332
03333
03334
03335
03336
03337
03338
03339
03340
03341
03342
03343 #define is_shell_quote_special(c) \
03344 ( (c) == '"' || \
03345 (c) == '\\' || \
03346 (c) == '`' || \
03347 (c) == '$' )
03348
03349
03350
03351
03352
03353
03354 int quoted_length(char *p, int *quoted)
03355 {
03356 int len = 0;
03357 char c;
03358
03359 *quoted = 0;
03360
03361 while (c = *p++) {
03362 if (!(*quoted) &&
03363 is_shell_special(c)) {
03364 (*quoted) = 1;
03365 len += 2;
03366 }
03367 if (is_shell_quote_special(c))
03368 len ++;
03369 len ++;
03370 }
03371 return len;
03372 }
03373
03374
03375
03376
03377
03378 int quote_shell_arg(char *p, char *buf)
03379 {
03380 char c;
03381 int quoted = 0;
03382 int len;
03383
03384 len = quoted_length(p, "ed);
03385
03386 if (quoted)
03387 *buf++ = '"';
03388 while (c = *p++) {
03389 if (is_shell_quote_special(c))
03390 *buf++ = '\\';
03391 *buf++ = c;
03392 }
03393 if (quoted)
03394 *buf++ = '"';
03395
03396 return len;
03397 }
03398
03399
03400 int saved_argc;
03401 char **saved_argv;
03402 static int curr_argc;
03403 static int add_c = 0;
03404
03405
03406
03407
03408
03409
03410
03411
03412 void add_minus_c_option(void)
03413 {
03414 add_c = 1;
03415 }
03416
03417 void save_command_line(int argc, char **argv)
03418 {
03419 int i;
03420 saved_argc = argc;
03421 saved_argv = malloc((saved_argc+1) * sizeof(char *));
03422
03423 for (i = 0; i < argc; i++) {
03424 if (argv[i])
03425 saved_argv[i] = string_copy(argv[i]);
03426 else
03427 saved_argv[i] = NULL;
03428 }
03429 saved_argv[saved_argc] = NULL;
03430 }
03431
03432 int check_for_saved_option(char *opt)
03433 {
03434 int i;
03435
03436 for (i = 1; i < saved_argc; i++) {
03437 if (strcmp(opt, saved_argv[i]) == 0)
03438 return 1;
03439 }
03440
03441 return 0;
03442 }
03443
03444 void set_current_arg_pos(int n)
03445 {
03446 curr_argc = n;
03447 }
03448
03449 void cancel_saved_arg(int count)
03450 {
03451 int i;
03452 for (i = 0; i < count; i++) {
03453 if (saved_argv[curr_argc+i] != NULL)
03454 free(saved_argv[curr_argc+i]);
03455 saved_argv[curr_argc+i] = NULL;
03456 }
03457 }
03458
03459
03460
03461
03462
03463
03464
03465 static void convert_saved_command_line_into_string ( void )
03466 {
03467 int len = 0;
03468 int quoted = 0;
03469 int i;
03470 char *p;
03471
03472
03473 for (i = 1; i < saved_argc; i++) {
03474 if (saved_argv[i] != NULL) {
03475 len += quoted_length(saved_argv[i], "ed) + 1;
03476 }
03477 }
03478
03479
03480 command_line = p = malloc(len+1);
03481
03482
03483 for (i = 1; i < saved_argc; i++) {
03484 if (saved_argv[i] != NULL) {
03485 p += quote_shell_arg(saved_argv[i], p);
03486 *p++ = ' ';
03487 }
03488 }
03489
03490 if (p > command_line)
03491 p[-1] = '\0';
03492 else
03493 p[0] = '\0';
03494 }
03495
03496 static void write_command_string_into_file(FILE *cmdfile,
03497 char *sourcefile,
03498 int for_ii_file)
03499 {
03500 if (for_ii_file)
03501 fputs("CMDLINE=", cmdfile);
03502
03503 fprintf(cmdfile, "%s ", orig_program_name);
03504
03505 if (add_c) {
03506
03507
03508
03509
03510 fputs("-c ", cmdfile);
03511 }
03512 fprintf(cmdfile, "%s %s", command_line, sourcefile);
03513 if (outfile != NULL &&
03514 !multiple_source_files &&
03515 (
03516 #ifndef KEY
03517 !option_was_seen(O_dsm) &&
03518 #endif
03519 invoked_lang != L_CC ||
03520 !for_ii_file || remember_last_phase != P_any_ld)) {
03521
03522 fprintf(cmdfile, " -o %s", outfile);
03523 }
03524 fprintf(cmdfile, "\n");
03525
03526
03527 if (for_ii_file)
03528 fputs("PWD=", cmdfile);
03529 fprintf(cmdfile, "%s\n", get_cwd());
03530
03531
03532 if (for_ii_file)
03533 fputs("----\n", cmdfile);
03534 }
03535
03536 static void add_command_line_arg(string_list_t *args, char *source_file)
03537 {
03538 char *cmd_file_name;
03539 FILE *cmd_file;
03540
03541
03542
03543
03544
03545 convert_saved_command_line_into_string();
03546
03547
03548
03549
03550 cmd_file_name = create_temp_file_name("L");
03551 if (execute_flag) {
03552 cmd_file = fopen(cmd_file_name, "w");
03553 if (cmd_file == NULL) {
03554 error("write_command_string: could not create %s", cmd_file_name);
03555 } else {
03556 write_command_string_into_file(cmd_file, source_file,
03557 FALSE);
03558 fclose(cmd_file);
03559 }
03560 }
03561 if (source_lang == L_cc ||
03562 source_lang == L_CC ||
03563 source_lang == L_f77 ||
03564 source_lang == L_f90)
03565 {
03566 add_string(args, concat_strings("-FE:cmdline=", cmd_file_name));
03567 }
03568 }
03569
03570
03571
03572
03573
03574 void skip_old_ii_controls(FILE *f)
03575 {
03576 int c;
03577 int terminator_found = 0;
03578
03579 c = getc(f);
03580 while (c != EOF) {
03581 if (c == '-' &&
03582 (c = getc(f)) == '-' &&
03583 (c = getc(f)) == '-' &&
03584 (c = getc(f)) == '-') {
03585 terminator_found = 1;
03586 }
03587 while (c != '\n' && c != EOF)
03588 c = getc(f);
03589 if (terminator_found)
03590 break;
03591 if (c == '\n')
03592 c = getc(f);
03593 }
03594
03595 if (c == EOF)
03596 rewind(f);
03597 }
03598
03599
03600
03601
03602 static char *make_ii_file_name(char *objname)
03603 {
03604 char *base = driver_basename(objname);
03605 int baselen = strlen(base);
03606
03607 base = concat_strings(base, " ");
03608 if (base[baselen-2] == '.'&& base[baselen-1] == 'o')
03609 strcpy(&base[baselen-1], "ii");
03610 else
03611 strcpy(&base[baselen], ".ii");
03612
03613 return concat_strings(
03614 dirname(objname),
03615 concat_strings("/ii_files/", base));
03616 }
03617
03618
03619
03620
03621 static char *make_rii_file_name(char *objname)
03622 {
03623 char *base = driver_basename(objname);
03624 int baselen = strlen(base);
03625
03626 base = concat_strings(base, " ");
03627 if (base[baselen-2] == '.' && base[baselen-1] == 'o')
03628 strcpy(&base[baselen-1], "rii");
03629 else
03630 strcpy(&base[baselen], ".rii");
03631
03632 return concat_strings(
03633 dirname(objname),
03634 concat_strings("/rii_files/", base));
03635 }
03636
03637
03638
03639
03640
03641 int update_instantiation_info_file(char *ii_file_name, char* sourcefile)
03642 {
03643 char *new_ii_file_name = concat_strings(ii_file_name, ".NEW");
03644
03645 FILE *old_ii = fopen(ii_file_name, "r");
03646 FILE *new_ii;
03647 int c;
03648
03649 if (old_ii != NULL) {
03650
03651
03652
03653 if (show_flag) {
03654 fprintf(stderr, "%s: update_instantiation_info_file %s\n",
03655 program_name, ii_file_name);
03656 }
03657
03658 new_ii = fopen(new_ii_file_name, "w");
03659 if (new_ii == NULL) {
03660
03661
03662 error("update_instantiation_info_file: error in creating file %s",
03663 new_ii_file_name);
03664 perror("update_instantiation_info_file");
03665 return 1;
03666 }
03667
03668
03669
03670
03671
03672 skip_old_ii_controls(old_ii);
03673
03674
03675
03676
03677
03678
03679
03680 write_command_string_into_file(new_ii, sourcefile,
03681 TRUE);
03682
03683
03684 while ((c = getc(old_ii)) != EOF)
03685 putc(c, new_ii);
03686
03687
03688 fclose(old_ii);
03689 fclose(new_ii);
03690 if (rename(new_ii_file_name, ii_file_name) < 0) {
03691 error("update_instantiation_info_file: error in renaming %s to %s",
03692 new_ii_file_name, ii_file_name);
03693 perror("update_instantiation_info_file");
03694 return 1;
03695 }
03696 }
03697 free(new_ii_file_name);
03698 return 0;
03699 }
03700
03701
03702
03703
03704
03705
03706
03707
03708
03709
03710
03711
03712
03713 static void
03714 add_ipl_cmd_string (int iflag)
03715 {
03716 if (option_matches_phase (iflag, P_be)) {
03717
03718 char *name = get_current_implied_name();
03719
03720
03721
03722
03723
03724 if ( debug ) {
03725 fprintf ( stderr, "%s: %sternal, #%d of %d, %s\n",
03726 name,
03727 is_internal_option (iflag) ? "in" : "ex",
03728 iflag, LAST_PREDEFINED_OPTION,
03729 is_derived_option (iflag) ? "derived" : "primary"
03730 );
03731 }
03732
03733 if ( is_internal_option (iflag)
03734 || ( iflag >= LAST_PREDEFINED_OPTION
03735 && ! is_derived_option (iflag) ) )
03736 {
03737 char *p;
03738 name = concat_strings ("-Wb,", name );
03739 for ( p = name; *p != 0; p++ ) {
03740 if ( *p == ' ' ) *p = ',';
03741 }
03742 }
03743
03744 if (strcmp(name,"-pfa") == 0) {
03745
03746
03747
03748 name = concat_strings ("-Wb,", name);
03749 }
03750
03751
03752 if (strcmp(name,"-dsm_clone")!=0)
03753 add_multi_strings (ipl_cmds, name, FALSE);
03754 }
03755 }
03756
03757
03758 void
03759 save_ipl_commands (void)
03760 {
03761 int i;
03762 int iflag;
03763
03764
03765
03766
03767 if (ipl_cmds == 0) {
03768 ipl_cmds = init_string_list ();
03769 add_string (ipl_cmds, program_name);
03770 if ( shared == NON_SHARED ) {
03771 add_string (ipl_cmds, "-non_shared");
03772 }
03773 }
03774
03775 FOREACH_OPTION_SEEN(i) {
03776 if ( i == O_Unrecognized || i == O_show )
03777 continue;
03778 if (option_matches_language (i, invoked_lang)) {
03779 FOREACH_IMPLIED_OPTION(iflag, i) {
03780 add_ipl_cmd_string (iflag);
03781 }
03782 }
03783 }
03784
03785
03786 add_targ_options(ipl_cmds);
03787
03788 }
03789
03790
03791
03792
03793
03794
03795
03796
03797 static void
03798 set_f90_source_form(string_list_t *args,boolean set_line_length)
03799 {
03800 char buf[16];
03801
03802 sprintf(buf,"-N%d",fortran_line_length);
03803
03804 if (fortran_form == 2) {
03805
03806 add_string(args,"-ffree");
03807 } else if (fortran_form == 1) {
03808
03809 add_string(args,"-ffixed");
03810 if (set_line_length) add_string(args,buf);
03811 } else {
03812
03813 if (source_kind == S_f90 || source_kind == S_F90) {
03814 add_string(args,"-ffree");
03815 } else {
03816 add_string(args,"-ffixed");
03817 if (set_line_length) add_string(args,buf);
03818 }
03819 }
03820 }
03821
03822
03823
03824
03825
03826
03827 static void
03828 do_f90_common_args(string_list_t *args)
03829 {
03830
03831 set_f90_source_form(args,FALSE);
03832
03833 add_string(args,"-LANG:=F90");
03834 #ifdef KEY
03835 if (0 != f90_module_dir) {
03836
03837 add_string(args, f90_module_dir);
03838 }
03839 #endif
03840 }
03841
03842 #ifdef KEY
03843
03844 static void
03845 set_stack_size()
03846 {
03847 #if !defined(_WIN32) && !defined(__CYGWIN__)
03848 struct rlimit rl;
03849 rlim_t max_stack;
03850
03851
03852 if (getrlimit(RLIMIT_STACK, &rl) == -1) {
03853 warning("cannot read stack size limit");
03854 return;
03855 }
03856 if (rl.rlim_cur == RLIM_INFINITY) {
03857 return;
03858 }
03859
03860
03861 max_stack = rl.rlim_max;
03862 rl.rlim_cur = max_stack;
03863 if (setrlimit(RLIMIT_STACK, &rl) == -1) {
03864 warning("cannot change stack size limit");
03865 return;
03866 }
03867 if (getrlimit(RLIMIT_STACK, &rl) == -1 ||
03868 rl.rlim_cur != max_stack) {
03869 warning("cannot change stack size limit");
03870 return;
03871 }
03872 #endif
03873 }
03874
03875
03876
03877 int
03878 get_gcc_major_version()
03879 {
03880 #ifdef __MINGW32__
03881
03882
03883 return __GNUC__;
03884 #else
03885 int v[4];
03886 get_gcc_version(v, 4);
03887 return v[0];
03888 #endif
03889 }
03890 #endif