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 static char *rcs_id = "$Source: driver/SCCS/s.main.c $ $Revision: 1.109 $";
00049
00050 #include <ctype.h>
00051 #include <stdio.h>
00052 #include <stdlib.h>
00053 #include <strings.h>
00054 #include <stamp.h>
00055 #include <cmplrs/rcodes.h>
00056 #include <sys/types.h>
00057 #include <sys/stat.h>
00058 #include <errno.h>
00059 #include <time.h>
00060 #include <unistd.h>
00061 #include "pathscale_defs.h"
00062 #include "string_utils.h"
00063 #include "options.h"
00064 #include "option_seen.h"
00065 #include "option_names.h"
00066 #include "opt_actions.h"
00067 #include "get_options.h"
00068 #include "lang_defs.h"
00069 #include "errors.h"
00070 #include "phases.h"
00071 #include "file_utils.h"
00072 #include "file_names.h"
00073 #include "run.h"
00074 #include "objects.h"
00075 #include "version.h"
00076
00077 char *help_pattern;
00078 boolean debug;
00079 boolean nostdinc = TRUE;
00080 int show_version;
00081 boolean show_copyright;
00082 boolean dump_version;
00083 boolean show_search_path;
00084 boolean show_defaults;
00085 boolean print_help = FALSE;
00086
00087 #if 0
00088
00089
00090 extern boolean is_replacement_combo(int);
00091 #endif
00092
00093 extern void toggle_implicits(void);
00094 extern void set_defaults(void);
00095 extern void add_special_options (void);
00096
00097 static void check_old_CC_options (char *name);
00098 static void check_makedepend_flags (void);
00099 static void mark_used (void);
00100 static void dump_args (char *msg);
00101 static void print_help_msg (void);
00102 static void print_defaults (int argc, char *argv[]);
00103 static void append_default_options (int *argc, char *(*argv[]));
00104 #ifdef PSC_TO_OPEN64
00105 static void append_open64_env_flags (int *argc, char *(*argv[]), char *env_var);
00106 #endif
00107 static void print_search_path (void);
00108 static void display_version (boolean dump_version_only);
00109
00110 static string_list_t *files;
00111 static string_list_t *file_suffixes;
00112 string_list_t *feedback_files;
00113
00114 boolean parsing_default_options = FALSE;
00115 boolean drop_option;
00116
00117 #ifdef TARG_X8664
00118 boolean link_with_mathlib;
00119 #endif
00120
00121 const char compiler_version[] = INCLUDE_STAMP;
00122 static void set_executable_dir (void);
00123
00124 static void prescan_options (int argc, char *argv[]);
00125
00126 static void no_args(void)
00127 {
00128 fprintf(stderr, "%s: no input files\n", program_name);
00129 fprintf(stderr, "For general help: %s --help\n", program_name);
00130 fprintf(stderr, "To search help: %s -help:<string>\n", program_name);
00131 do_exit(RC_USER_ERROR);
00132 }
00133
00134 int
00135 main (int argc, char *argv[])
00136 {
00137 int i;
00138 int flag;
00139 int base_flag;
00140 string_item_t *p, *q;
00141 int num_files = 0;
00142 #ifdef KEY
00143 char *unrecognized_dashdash_option_name = NULL;
00144 #endif
00145
00146 init_error_list();
00147 program_name = drop_path(argv[0]);
00148 orig_program_name = string_copy(argv[0]);
00149 file_utils_set_program_name(orig_program_name);
00150
00151
00152 #ifdef PSC_TO_OPEN64
00153 append_open64_env_flags(&argc, &argv, "OPEN64_GENFLAGS");
00154 #endif
00155
00156
00157
00158 append_default_options(&argc, &argv);
00159
00160 save_command_line(argc, argv);
00161 files = init_string_list();
00162 file_suffixes = init_string_list();
00163 feedback_files = init_string_list ();
00164 init_options();
00165 init_temp_files();
00166 init_crash_reporting();
00167 init_count_files();
00168 init_option_seen();
00169 init_objects();
00170
00171 invoked_lang = get_named_language(program_name);
00172
00173
00174
00175 #ifdef PSC_TO_OPEN64
00176 if (invoked_lang == L_cc)
00177 append_open64_env_flags(&argc, &argv, "OPEN64_CFLAGS");
00178 else if (invoked_lang == L_CC)
00179 append_open64_env_flags(&argc, &argv, "OPEN64_CXXFLAGS");
00180 else if (invoked_lang == L_f77 || invoked_lang == L_f90)
00181 append_open64_env_flags(&argc, &argv, "OPEN64_FFLAGS");
00182 #endif
00183
00184 check_for_driver_controls (argc, argv);
00185
00186
00187
00188 #if !defined(TARG_SL)
00189 set_executable_dir();
00190 #endif
00191
00192 dump_outfile_to_stdout = FALSE;
00193
00194
00195 init_phase_names();
00196
00197 init_phase_info();
00198
00199
00200
00201
00202
00203
00204
00205 remove_phase_for_option(O_A,P_f90_cpp);
00206 remove_phase_for_option(O_E,P_f90_cpp);
00207
00208
00209
00210
00211 prescan_options(argc, argv);
00212
00213 i = 1;
00214 while (i < argc) {
00215 option_name = argv[i];
00216
00217
00218
00219
00220 if (!strcmp(option_name, "-default_options")) {
00221 parsing_default_options = TRUE;
00222 i++;
00223 continue;
00224 }
00225
00226 set_current_arg_pos(i);
00227 if (argv[i][0] == '-' && !dashdash_flag) {
00228 flag = get_option(&i, argv);
00229 if (flag == O_Unrecognized) {
00230 if (print_warnings) {
00231
00232
00233
00234
00235
00236
00237
00238 if (!strncmp(option_name, "--", 2)) {
00239 unrecognized_dashdash_option_name =
00240 option_name;
00241 }
00242 else if (option_was_seen(O_compat_gcc) ||
00243 #ifdef PSC_TO_OPEN64
00244 getenv("OPEN64_STRICT_GCC")) {
00245 #endif
00246
00247 warning("unknown flag: %s", option_name);
00248 } else {
00249
00250 parse_error(option_name, "unknown flag");
00251 }
00252 }
00253 }
00254 else {
00255
00256
00257 option_name = get_option_name(flag);
00258 }
00259
00260 flag = get_real_option_if_aliased (flag);
00261
00262
00263 if (is_derived_option (flag)) {
00264 base_flag = get_derived_parent(flag);
00265
00266 base_flag = get_real_option_if_aliased (base_flag);
00267 }
00268 else {
00269 base_flag = flag;
00270 }
00271
00272 drop_option = FALSE;
00273
00274 #ifdef KEY
00275
00276
00277 if (ipa == FALSE &&
00278 base_flag == O_IPA_) {
00279 drop_option = TRUE;
00280 } else
00281 #endif
00282
00283 opt_action(base_flag);
00284
00285
00286
00287 if (!drop_option) {
00288 if (is_maybe_linker_option(base_flag)) {
00289 add_maybe_linker_option(base_flag);
00290 } else if (is_object_option(base_flag)) {
00291
00292 add_object (base_flag, optargs);
00293 source_kind = S_o;
00294 } else {
00295
00296 add_option_seen (flag);
00297 }
00298 }
00299 } else if (argv[i][0] == '+') {
00300 check_old_CC_options(argv[i]);
00301 i++;
00302 } else {
00303 source_kind = get_source_kind(argv[i]);
00304
00305 if (last_phase == P_any_cpp && source_kind == S_o)
00306 {
00307 source_kind = S_c;
00308 }
00309 if (source_kind == S_o) {
00310
00311 add_object (O_object, argv[i]);
00312
00313
00314 add_ar_objects(argv[i]);
00315 } else {
00316
00317
00318
00319
00320
00321
00322
00323 char *obj_name = get_object_file(argv[i]);
00324 add_object (O_object, obj_name);
00325 add_ar_objects(obj_name);
00326 add_string(files, argv[i]);
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 add_string(file_suffixes,
00339 get_suffix_string(source_kind));
00340 num_files++;
00341 }
00342 cancel_saved_arg(1);
00343 i++;
00344 }
00345 }
00346
00347
00348
00349
00350 finalize_maybe_linker_options (num_files == 0);
00351
00352
00353
00354 if (num_files > 0 &&
00355 unrecognized_dashdash_option_name != NULL) {
00356 parse_error(unrecognized_dashdash_option_name, "unknown flag");
00357 }
00358
00359
00360 Check_Target ();
00361
00362 #if defined(TARG_NVISA)
00363 if (show_version) {
00364
00365 fprintf(stderr, "NVIDIA (R) CUDA Open64 Compiler\n");
00366 fprintf(stderr, "%s\n", cset_id);
00367 fprintf(stderr, "Built on %s\n", build_date);
00368 }
00369 if (show_copyright) {
00370 fprintf(stderr, "Portions Copyright (c) 2005-2008 NVIDIA Corporation\n");
00371 fprintf(stderr, "Portions Copyright (c) 2002-2005 PathScale, Inc.\n");
00372 fprintf(stderr, "Portions Copyright (c) 2000-2001 Silicon Graphics, Inc.\n");
00373 fprintf(stderr, "All Rights Reserved.\n");
00374 }
00375 #endif //TARG_NVISA
00376 if (show_search_path) {
00377 print_search_path();
00378 }
00379 if (show_defaults) {
00380 print_defaults(argc, argv);
00381 }
00382
00383 if (argc == 1)
00384 {
00385 no_args();
00386 }
00387
00388 if (print_help || help_pattern != NULL)
00389 {
00390 print_help_msg();
00391 }
00392 if ( ! show_version && ! execute_flag && ! show_flag && ! dump_version) {
00393 do_exit(RC_OKAY);
00394 }
00395 if (source_kind == S_NONE || read_stdin) {
00396 if (read_stdin) {
00397 source_file = "-";
00398 if (option_was_seen(O_E)) {
00399 #ifdef KEY
00400
00401
00402 if (source_lang == L_NONE)
00403 #endif
00404 source_lang = L_cpp;
00405 } else {
00406 char *obj_name;
00407 source_kind = get_source_kind(source_file);
00408 source_lang = invoked_lang;
00409 obj_name = get_object_file(
00410 fix_name_by_lang(source_file));
00411 add_object (O_object, obj_name);
00412 }
00413 }
00414 else if (show_version || dump_version) {
00415
00416 }
00417 else {
00418 no_args();
00419 }
00420 }
00421
00422
00423
00424
00425 FOREACH_OPTION_SEEN(i) {
00426 if (current_option_seen_later(i)) {
00427 set_current_option_unseen();
00428 } else if (flag_is_superceded(i)) {
00429 set_option_unseen(i);
00430 }
00431 }
00432
00433 #if 0
00434
00435 check_for_combos();
00436 #endif
00437
00438 if ((option_was_seen(O_fpic) ||
00439 option_was_seen(O_fPIC))
00440 && mem_model == M_MEDIUM) {
00441 error("unimplemented: code model medium not supported in PIC mode");
00442 }
00443 #ifdef KEY
00444
00445 if (mem_model != M_SMALL &&
00446 abi == ABI_N32) {
00447 error("code model \"%s\" not support in 32-bit mode", mem_model_name);
00448 }
00449
00450 if (option_was_seen(O_static) &&
00451 mem_model != M_SMALL) {
00452 error("-static can only be used with -mcmodel=small");
00453 }
00454
00455 if (option_was_seen(O_static_data) &&
00456 mpkind == NORMAL_MP) {
00457 warning("-static-data specified with -mp can cause incorrect "
00458 "execution if a routine with static data is called from a "
00459 "parallel region.");
00460 }
00461 #endif
00462
00463 if (debug) {
00464 dump_args("user flags");
00465 }
00466 if (ipa == TRUE)
00467 save_ipl_commands ();
00468
00469 if (outfile != NULL && (strcmp(outfile, "-") == 0)) {
00470
00471 outfile = create_temp_file_name("x");
00472 dump_outfile_to_stdout = TRUE;
00473 }
00474
00475
00476 if (feedback_files->head) cordflag=TRUE;
00477
00478
00479 if (cordflag!=TRUE) {
00480 last_phase=earliest_phase(P_any_ld, last_phase);
00481 }
00482
00483
00484 mark_used();
00485
00486
00487 toggle_implicits();
00488
00489
00490 set_defaults();
00491
00492 #ifdef KEY
00493
00494
00495 if (gnu_major_version == 4) {
00496 if (option_was_seen(O_fwritable_strings) ||
00497 option_was_seen(O_fno_writable_strings)) {
00498 warning("ignored -fwritable-strings/-fno-writable-strings because"
00499 " option not supported under GNU GCC 4");
00500 set_option_unseen(O_fwritable_strings);
00501 set_option_unseen(O_fno_writable_strings);
00502 }
00503 if ((source_lang == L_cc ||
00504 source_lang == L_CC) &&
00505 option_was_seen(O_mp) &&
00506 gnu_minor_version < 2) {
00507 warning("ignored -mp because option not supported under"
00508 " GNU GCC 4.0");
00509 set_option_unseen(O_mp);
00510 }
00511 else if (gnu_minor_version >= 2 &&
00512 !option_was_seen(O_fno_cxx_openmp)) {
00513 add_option_seen(O_fcxx_openmp);
00514 toggle(&fcxx_openmp,1);
00515 }
00516 } else {
00517 if (option_was_seen(O_fgnu_exceptions) ||
00518 option_was_seen(O_fno_gnu_exceptions)) {
00519 warning("ignored -fgnu-exceptions/-fno-gnu-exceptions because"
00520 " option is for GNU GCC 4 only");
00521 set_option_unseen(O_fgnu_exceptions);
00522 set_option_unseen(O_fno_gnu_exceptions);
00523 gnu_exceptions = UNDEFINED;
00524 }
00525 }
00526
00527
00528 init_frontend_phase_names(gnu_major_version, gnu_minor_version);
00529 #endif
00530
00531
00532
00533 if (show_version || dump_version) {
00534 display_version(dump_version);
00535 if (!execute_flag ||
00536 source_kind == S_NONE)
00537 do_exit(RC_OKAY);
00538 }
00539
00540 if (num_files > 1) {
00541 multiple_source_files = TRUE;
00542 }
00543
00544 check_makedepend_flags ();
00545 add_library_options();
00546 add_special_options();
00547
00548 if (debug) {
00549 dump_args("with defaults");
00550 dump_objects();
00551 }
00552 if (has_errors()) return error_status;
00553
00554 catch_signals();
00555 remember_last_phase = last_phase;
00556
00557
00558
00559
00560
00561 if ((multiple_source_files ||
00562 option_was_seen(O_ar)
00563 #ifndef KEY
00564 || option_was_seen(O_dsm)
00565 #endif
00566 ) &&
00567 ((last_phase == P_any_ld) && (shared != RELOCATABLE)) ||
00568 (last_phase == P_pixie)) {
00569
00570 last_phase = P_any_as;
00571 add_minus_c_option();
00572 }
00573
00574 if (Use_feedback) {
00575 struct stat stat_buf;
00576 time_t fb_file_mod_time;
00577 time_t count_file_mod_time;
00578 boolean fb_file_exists = TRUE;
00579
00580 if (fb_cdir != NULL)
00581 warning ("-fb_cdir cannot be used with -fbuse; -fb_cdir ignored");
00582 save_name(&fb_file, concat_strings(drop_path(prof_file), ".x.cfb"));
00583 if (!(stat(fb_file, &stat_buf) != 0 && errno == ENOENT))
00584 fb_file_mod_time = stat_buf.st_mtime;
00585 else
00586 fb_file_exists = FALSE;
00587 if (!(stat(count_files->head->name, &stat_buf) != 0 && errno == ENOENT))
00588 count_file_mod_time = stat_buf.st_mtime;
00589 else {
00590 internal_error("%s doesn't exist", count_files->head->name);
00591 perror(program_name);
00592 }
00593
00594 if (!fb_file_exists || (fb_file_mod_time <= count_file_mod_time))
00595 run_prof();
00596 }
00597
00598 if (read_stdin) {
00599 if ( option_was_seen(O_E)
00600 || (source_lang != L_NONE && source_kind != S_o))
00601 {
00602 run_compiler(argc, argv);
00603 }
00604 else {
00605 error("-E or specified language required when input is from standard input");
00606 }
00607 cleanup();
00608 return error_status;
00609 }
00610
00611 for (p = files->head, q=file_suffixes->head; p != NULL; p = p->next, q=q->next)
00612 {
00613 source_file = p->name;
00614 #ifdef KEY
00615 run_inline = UNDEFINED;
00616
00617 if (show_flag == TRUE)
00618 #endif
00619 if (multiple_source_files) {
00620 fprintf(stderr, "%s:\n", source_file);
00621 }
00622 if (execute_flag && !file_exists(source_file)) {
00623 error("file does not exist: %s", source_file);
00624 continue;
00625 }
00626 source_kind = get_source_kind_from_suffix(q->name);
00627 source_lang = get_source_lang(source_kind);
00628 if (source_lang != invoked_lang
00629 && source_lang != L_as
00630 && (fullwarn || (source_lang == L_f90)) )
00631 {
00632 warning("compiler not invoked with language of source file; will compile with %s but link with %s", get_lang_name(source_lang), get_lang_name(invoked_lang));
00633 }
00634 run_compiler(argc, argv);
00635 if (multiple_source_files) cleanup();
00636 }
00637 if (has_errors()) {
00638 cleanup();
00639 cleanup_temp_objects();
00640 return error_status;
00641 }
00642
00643 if (num_files == 0 || remember_last_phase != last_phase) {
00644
00645 last_phase = remember_last_phase;
00646 source_file = NULL;
00647 source_kind = S_o;
00648 source_lang = get_source_lang(source_kind);
00649
00650 #ifndef KEY // -dsm_clone no longer supported. Bug 4406.
00651 if (option_was_seen(O_dsm_clone)) {
00652 run_dsm_prelink();
00653 if (has_errors()) {
00654 cleanup();
00655 cleanup_temp_objects();
00656 return error_status;
00657 }
00658 }
00659 #endif
00660 if (option_was_seen(O_ar)) {
00661 run_ar();
00662 }
00663 else {
00664 run_ld ();
00665 }
00666 if (Gen_feedback)
00667 run_pixie();
00668 }
00669 if (dump_outfile_to_stdout == TRUE)
00670 dump_file_to_stdout(outfile);
00671 cleanup();
00672 cleanup_temp_objects();
00673 return error_status;
00674 }
00675
00676 static void set_executable_dir (void) {
00677 char *dir;
00678 size_t dirlen;
00679 char *ldir;
00680
00681
00682
00683
00684
00685
00686 dir = get_executable_dir ();
00687 if (dir == NULL) return;
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700 ldir = drop_path (dir);
00701 if (strcmp (ldir, "bin") == 0) {
00702 char *basedir = directory_path (dir);
00703 #if defined(TARG_NVISA)
00704 substitute_phase_dirs ("/lib", basedir, "/lib/");
00705 #endif
00706 #ifdef PSC_TO_OPEN64
00707 substitute_phase_dirs ("/lib", basedir, "/lib/" OPEN64_FULL_VERSION);
00708 substitute_phase_dirs ("/lib/" OPEN64_NAME_PREFIX "cc-lib",
00709 basedir, "/lib/" OPEN64_FULL_VERSION);
00710 #endif
00711 substitute_phase_dirs ("/include", basedir, "/include");
00712 return;
00713 }
00714
00715
00716 ldir = strstr (dir, "/lib/gcc-lib");
00717 if (ldir != 0) {
00718 if (ldir[12] == '/') {
00719
00720 ldir = substring_copy (dir, 0, ldir+4-dir);
00721 substitute_phase_dirs ("/bin", dir, "");
00722 substitute_phase_dirs ("/lib", ldir, "");
00723 #ifdef PSC_TO_OPEN64
00724 substitute_phase_dirs ("/lib/" OPEN64_NAME_PREFIX "cc-lib", dir, "");
00725 #endif
00726 substitute_phase_dirs ("/include", dir, "/include");
00727 } else if (ldir[12] == '\0') {
00728
00729 ldir = substring_copy (dir, 0, ldir+4-dir);
00730 substitute_phase_dirs ("/bin", dir, "");
00731 substitute_phase_dirs ("/lib", ldir, "");
00732 #ifdef PSC_TO_OPEN64
00733 substitute_phase_dirs ("/lib/" OPEN64_NAME_PREFIX "cc-lib", dir, "");
00734 #endif
00735 substitute_phase_dirs ("/include", dir, "/include");
00736 }
00737 return;
00738 }
00739 }
00740
00741 static void
00742 check_old_CC_options (char *name)
00743 {
00744 if (strcmp(name, "+I") == 0) {
00745 warn_no_longer_supported2(name, "-keep");
00746 } else if (strcmp(name, "+L") == 0) {
00747 warn_no_longer_supported(name);
00748 } else if (strcmp(name, "+d") == 0) {
00749 warn_no_longer_supported2(name, "-INLINE:none");
00750 } else if (strcmp(name, "+p") == 0 ||
00751 strcmp(name, "+pc") == 0 ||
00752 strcmp(name, "+pa") == 0) {
00753 warn_ignored(name);
00754 warning("the effect of +p is now the default (see -anach and -cfront)");
00755 } else if (strcmp(name, "+v") == 0) {
00756 warn_no_longer_supported2(name, "-show");
00757 } else if (strcmp(name, "+w") == 0) {
00758 warn_no_longer_supported2(name, "-fullwarn");
00759 } else if (strcmp(name, "+a0") == 0) {
00760 warn_no_longer_supported(name);
00761 } else if (strcmp(name, "+a1") == 0) {
00762 warn_no_longer_supported(name);
00763 } else {
00764 parse_error(name, "bad syntax");
00765 }
00766 }
00767
00768
00769
00770
00771
00772
00773 static void
00774 check_makedepend_flags (void)
00775 {
00776 int flag;
00777 if (option_was_seen(O_MDupdate)) {
00778 if (outfile != NULL) {
00779
00780
00781
00782
00783 flag = add_string_option(O_MDtarget, outfile);
00784 add_option_seen (flag);
00785 }
00786 if (!multiple_source_files && files->head != NULL
00787 && last_phase == P_any_ld)
00788 {
00789
00790
00791 if (outfile == NULL) {
00792 char *s = change_suffix(files->head->name, NULL);
00793 s[strlen(s)-1] = NIL;
00794 flag = add_string_option(O_MDtarget, s);
00795 add_option_seen (flag);
00796 }
00797 flag = add_string_option(O_MDignore,
00798 get_object_file(files->head->name) );
00799 add_option_seen (flag);
00800 }
00801 }
00802 }
00803
00804
00805 static void
00806 mark_used (void)
00807 {
00808 int i;
00809 int iflag;
00810
00811 FOREACH_OPTION(i) {
00812 if (option_was_seen(i) && !option_was_implicitly_seen(i)) {
00813 FOREACH_IMPLIED_OPTION(iflag, i) {
00814 if (option_was_seen(iflag)) {
00815 continue;
00816 }
00817 add_option_implicitly_seen (iflag);
00818 if (is_object_option(iflag)
00819 && option_matches_language(i, invoked_lang) )
00820 {
00821
00822
00823
00824
00825
00826 add_object (O_object, get_current_implied_name());
00827 }
00828 }
00829 }
00830 }
00831 }
00832
00833 static void
00834 print_help_msg (void)
00835 {
00836 int i;
00837 char *msg;
00838 char *name;
00839 fprintf(stderr, "usage: %s <options> <files>\n", program_name);
00840 if (help_pattern != NULL)
00841 fprintf(stderr, "available options that contain %s:\n", help_pattern);
00842 else
00843 fprintf(stderr, "available options:\n");
00844
00845 FOREACH_OPTION(i) {
00846 msg = get_option_help(i);
00847 if (msg != NULL) {
00848 if (option_matches_language (i, invoked_lang)) {
00849 name = get_option_name(i);
00850
00851 if (help_pattern != NULL
00852 && strstr(name, help_pattern) == NULL
00853 && strstr(msg, help_pattern) == NULL)
00854 {
00855 continue;
00856 }
00857 fprintf(stderr, "\t%s: %s\n", name, msg);
00858 }
00859 }
00860 }
00861 if (help_pattern == NULL && invoked_lang == L_cc) {
00862 fprintf(stderr, "The environment variable OPEN64_CC is also checked\n");
00863 }
00864 do_exit(RC_OKAY);
00865 }
00866
00867 static void
00868 dump_args (char *msg)
00869 {
00870 int i;
00871 printf("dump args %s: ", msg);
00872 FOREACH_OPTION_SEEN(i) {
00873 if (i == O_Unrecognized) continue;
00874 #if 0
00875
00876
00877
00878
00879
00880 if (is_replacement_combo(i)) {
00881 int iflag;
00882 FOREACH_IMPLIED_OPTION(iflag, i) {
00883 printf(" %s", get_current_implied_name());
00884 }
00885 } else {
00886 #endif
00887 printf(" %s", get_option_name(i));
00888 }
00889 printf("\n");
00890 }
00891
00892
00893
00894
00895
00896
00897
00898 void do_exit(int code)
00899 {
00900 #ifdef KEY // Bug 6678.
00901 unlink(get_report_file_name());
00902 #endif
00903 if (code != 0) {
00904 code = 1;
00905 }
00906
00907 exit(code);
00908 }
00909
00910
00911 static struct explicit_lang {
00912 const char *name;
00913 source_kind_t kind;
00914 languages_t lang;
00915 } explicit_langs[] = {
00916 { "assembler", S_s, L_as, },
00917 { "assembler-with-cpp", S_S, L_as, },
00918 { "c", S_c, L_cc, },
00919 { "c++", S_C, L_CC, },
00920 { "c++-cpp-output", S_ii, L_CC, },
00921 { "c++-header", S_C, L_CC, },
00922 { "c-header", S_c, L_cc, },
00923 { "cpp-output", S_i, L_cc, },
00924 { "f77", S_f90, L_f77, },
00925 { "f77-cpp-input", S_i, L_f77, },
00926 { "f90", S_f90, L_f90, },
00927 { "f90-cpp-input", S_i, L_f90, },
00928 { "f95", S_f90, L_f90, },
00929 { "f95-cpp-input", S_i, L_f90, },
00930 { "none", S_NONE, L_NONE, },
00931 { "ratfor", S_r, L_f77, },
00932 { NULL, S_NONE, L_NONE, },
00933 };
00934
00935 void set_explicit_lang(const char *flag, const char *lang)
00936 {
00937 struct explicit_lang *x;
00938
00939 for (x = explicit_langs; x->name != NULL; x++) {
00940 if (strcmp(lang, x->name) == 0) {
00941 ignore_suffix = x->lang != S_NONE;
00942 if (x->kind == S_NONE) {
00943 ignore_suffix = FALSE;
00944 default_source_kind = S_NONE;
00945 } else {
00946 ignore_suffix = TRUE;
00947 source_kind = default_source_kind = x->kind;
00948 source_lang = x->lang;
00949 }
00950 break;
00951 }
00952 }
00953
00954 if (x->name == NULL) {
00955 parse_error(flag, "Unknown language");
00956 do_exit(RC_USER_ERROR);
00957 }
00958 }
00959
00960
00961 static void
00962 prescan_options (int argc, char *argv[])
00963 {
00964 char *ipa_conflict_option = NULL;
00965 int i;
00966
00967 for (i = 1; i < argc; i++) {
00968 if (!strcasecmp(argv[i], "-ipa") ||
00969 !strcmp(argv[i], "-Ofast")) {
00970 ipa = TRUE;
00971 } else if (!strcmp(argv[i], "-keep")) {
00972 keep_flag = TRUE;
00973 } else if (!strcmp(argv[i], "-save_temps")) {
00974 keep_flag = TRUE;
00975 } else if (!strcmp(argv[i], "-compat-gcc")) {
00976 compat_gcc = TRUE;
00977 } else if (!strcmp(argv[i], "-S")) {
00978 ipa_conflict_option = argv[i];
00979 } else if (!strcmp(argv[i], "-fbgen")) {
00980 ipa_conflict_option = argv[i];
00981 } else if (argv[i][0] == '-' && argv[i][1] == 'g') {
00982 if (!strcmp(argv[i], "-g") ||
00983 !strcmp(argv[i], "-g1") ||
00984 !strcmp(argv[i], "-g2") ||
00985 !strcmp(argv[i], "-g3") ||
00986 !strcmp(argv[i], "-gdwarf-2") ||
00987 !strcmp(argv[i], "-gdwarf-21") ||
00988 !strcmp(argv[i], "-gdwarf-22") ||
00989 !strcmp(argv[i], "-gdwarf-23") ||
00990 !strcmp(argv[i], "-ggdb") ||
00991 !strcmp(argv[i], "-ggdb3")) {
00992 ipa_conflict_option = argv[i];
00993 }
00994 }
00995 }
00996
00997
00998
00999
01000 if (ipa &&
01001 ipa_conflict_option != NULL) {
01002 char msg[200];
01003 for (i = 1; i < argc; i++) {
01004 if (!strcasecmp(argv[i], "-ipa") ||
01005 !strcmp(argv[i], "-Ofast")) {
01006 sprintf(msg, "%s %s combination not allowed, replaced with %s",
01007 argv[i], ipa_conflict_option, ipa_conflict_option);
01008 warning(msg);
01009 ipa = FALSE;
01010 argv[i] = "-dummy";
01011 }
01012 }
01013 }
01014 }
01015
01016 static void
01017 print_defaults(int argc, char *argv[])
01018 {
01019 int i;
01020 boolean parsing_defaults;
01021
01022 fprintf(stderr, "Optimization level and compilation target:\n ");
01023
01024
01025 if (olevel == UNDEFINED)
01026 fprintf(stderr, " -O2");
01027 else
01028 fprintf(stderr, " -O%d", olevel);
01029
01030
01031 if (target_cpu != NULL)
01032 fprintf(stderr, " -mcpu=%s", target_cpu);
01033 else
01034 internal_error("no default target cpu");
01035
01036 #ifdef TARG_MIPS
01037
01038 switch (abi) {
01039 case ABI_N32: fprintf(stderr, " -n32"); break;
01040 case ABI_64: fprintf(stderr, " -64"); break;
01041 default: internal_error("unknown default ABI");
01042 }
01043 #endif
01044
01045 #ifdef TARG_X8664
01046
01047 switch (abi) {
01048 case ABI_N32: fprintf(stderr, " -m32"); break;
01049 case ABI_64: fprintf(stderr, " -m64"); break;
01050 default: internal_error("unknown default ABI");
01051 }
01052
01053
01054 fprintf(stderr, " -msse");
01055 fprintf(stderr, " %s", sse2 == TRUE ? "-msse2" : "-mno-sse2");
01056 fprintf(stderr, " %s", sse3 == TRUE ? "-msse3" : "-mno-sse3");
01057 fprintf(stderr, " %s", m3dnow == TRUE ? "-m3dnow" : "-mno-3dnow");
01058 fprintf(stderr, " %s", sse4a == TRUE ? "-msse4a" : "-mno-sse4a");
01059 #endif
01060
01061
01062 if ((invoked_lang == L_cc ||
01063 invoked_lang == L_CC) &&
01064 !is_toggled(gnu_major_version)) {
01065 int gcc_version = get_gcc_major_version();
01066 if (gcc_version == 3 ||
01067 gcc_version == 4) {
01068 fprintf(stderr, " -gnu%d", gcc_version);
01069 } else {
01070 internal_error("print_defaults: unknown GCC version %d\n", gcc_version);
01071 }
01072 }
01073
01074 fprintf(stderr, "\n");
01075
01076
01077 fprintf(stderr, "Options from compiler.defaults file:\n ");
01078 parsing_defaults = FALSE;
01079 for (i = 0; i < argc; i++) {
01080 if (!strcmp(argv[i], "-default_options")) {
01081 parsing_defaults = TRUE;
01082 } else if (parsing_defaults == TRUE) {
01083 fprintf(stderr, " %s", argv[i]);
01084 }
01085 }
01086 fprintf(stderr, "\n");
01087 }
01088
01089 static int
01090 read_compiler_defaults(FILE *f, string_list_t *default_options_list)
01091 {
01092 const int max_len = 1000;
01093 char *p, buf[max_len];
01094 char *q, option[max_len];
01095 int count = 0;
01096 int line = 0;
01097 boolean in_single_quotes = FALSE;
01098 boolean in_double_quotes = FALSE;
01099 boolean follows_escape_char = FALSE;
01100 boolean in_comment = FALSE;
01101
01102
01103 option[0] = '\0';
01104 q = option;
01105 while (fgets(buf, max_len, f) != NULL) {
01106 boolean end_of_line = FALSE;
01107 boolean continuation = FALSE;
01108 line++;
01109
01110
01111 for (p = buf; *p != '\0' && !end_of_line; p++) {
01112 boolean add_new_option = FALSE;
01113
01114 if (follows_escape_char) {
01115 follows_escape_char = FALSE;
01116 if (*p == '\n') {
01117
01118 continuation = TRUE;
01119 end_of_line = TRUE;
01120 } else {
01121
01122 *q++ = *p;
01123 }
01124 } else if (in_comment) {
01125 if (*p == '\n') {
01126 end_of_line = TRUE;
01127 in_comment = FALSE;
01128 }
01129 } else {
01130 switch (*p) {
01131 case '\n':
01132 add_new_option = TRUE;
01133 end_of_line = TRUE;
01134 break;
01135 case '#':
01136 if (in_single_quotes || in_double_quotes) {
01137 *q++ = '#';
01138 } else {
01139 in_comment = TRUE;
01140 }
01141 break;
01142 case ' ':
01143 if (in_single_quotes || in_double_quotes)
01144 *q++ = ' ';
01145 else
01146 add_new_option = TRUE;
01147 break;
01148 case '\'':
01149 if (in_single_quotes) {
01150 in_single_quotes = FALSE;
01151 } else if (in_double_quotes) {
01152 *q++ = '\'';
01153 } else {
01154 in_single_quotes = TRUE;
01155 }
01156 break;
01157 case '"':
01158 if (in_single_quotes) {
01159 *q++ = '"';
01160 } else if (in_double_quotes) {
01161 in_double_quotes = FALSE;
01162 } else {
01163 in_double_quotes = TRUE;
01164 }
01165 break;
01166 case '\\':
01167 if (in_single_quotes)
01168 *q++ = '\\';
01169 else
01170 follows_escape_char = TRUE;
01171 break;
01172 default:
01173 *q++ = *p;
01174 }
01175 }
01176
01177
01178 if (add_new_option &&
01179 option[0] != '\0') {
01180 *q++ = '\0';
01181 if (strlen(option) >= max_len) {
01182 internal_error("read_compiler_defaults: buffer overrun");
01183 return -1;
01184 }
01185 add_string(default_options_list, option);
01186 option[0] = '\0';
01187 q = option;
01188 count++;
01189 }
01190 }
01191 }
01192
01193 return count;
01194 }
01195
01196
01197 static void
01198 append_default_options (int *argc, char *(*argv[]))
01199 {
01200 char *compiler_defaults_path =
01201 #ifdef PSC_TO_OPEN64
01202 string_copy(getenv("OPEN64_COMPILER_DEFAULTS_PATH"));
01203 #endif
01204 int default_options_count = 0;
01205 string_list_t *default_options_list = init_string_list();
01206
01207 if (compiler_defaults_path == NULL) {
01208 char *exe_dir = get_executable_dir();
01209 asprintf(&compiler_defaults_path, "%.*s/etc",
01210 (int)(strlen(exe_dir) - 4), exe_dir);
01211 }
01212
01213
01214
01215 while (compiler_defaults_path) {
01216 char *p, *path;
01217 path = compiler_defaults_path;
01218 for (p = path; ; p++) {
01219 if (*p == '\0') {
01220 compiler_defaults_path = NULL;
01221 break;
01222 } else if (*p == ':') {
01223 *p = '\0';
01224 compiler_defaults_path = p + 1;
01225 break;
01226 }
01227 }
01228
01229
01230 FILE *f;
01231 char buf[1000];
01232 strcpy(buf, path);
01233 strcat(buf, "/compiler.defaults");
01234 if ((f = fopen(buf, "r")) != NULL) {
01235 default_options_count = read_compiler_defaults(f, default_options_list);
01236 fclose(f);
01237 if (default_options_count == -1)
01238 return;
01239 break;
01240 }
01241 }
01242
01243
01244 {
01245 int new_argc = *argc + default_options_count + 1;
01246 char **new_argv = malloc(new_argc * sizeof(char*));
01247 int i, index;
01248 string_item_t *p;
01249
01250
01251 for (index = 0; index < *argc; index++) {
01252 new_argv[index] = (*argv)[index];
01253 }
01254
01255
01256 new_argv[index++] = "-default_options";
01257
01258
01259 for (p = default_options_list->head; p != NULL; p = p->next) {
01260 new_argv[index++] = p->name;
01261 }
01262
01263
01264 *argc = new_argc;
01265 *argv = new_argv;
01266 }
01267 }
01268
01269
01270
01271 static void
01272 append_open64_env_flags (int *argc, char *(*argv[]), char *env_var)
01273 {
01274 char * default_opt = string_copy(getenv(env_var));
01275 char * p, * q;
01276 char ** new_argv;
01277 int new_argc, fin = 0;
01278
01279 if (default_opt) {
01280 new_argc = *argc;
01281 new_argv = (char **) calloc (*argc, sizeof (char *));
01282 memcpy (new_argv, *argv, *argc * sizeof (char *));
01283 for (p = default_opt, q = default_opt; fin == 0; p++) {
01284 switch (*p) {
01285 case '\0':
01286 fin = 1;
01287 case ' ':
01288 *p = '\0';
01289 new_argc++;
01290 new_argv = (char **) realloc (new_argv, new_argc * (sizeof (char *)));
01291 new_argv [new_argc-1] = strdup (q);
01292 q = p+1;
01293 break;
01294 default:
01295 break;
01296 }
01297 }
01298 *argc = new_argc;
01299 *argv = new_argv;
01300 }
01301
01302
01303 #if defined(__MINGW32__)
01304
01305 {
01306 string tmp = concat_strings(env_var, "=");
01307 putenv (tmp);
01308 }
01309 #else
01310 unsetenv (env_var);
01311 #endif
01312 }
01313
01314 static FILE *
01315 read_gcc_output(char *cmdline)
01316 {
01317
01318 char *gcc_path = get_full_phase_name(P_gcpp);
01319 char *gcc_cmd = NULL;
01320 FILE *fp = NULL;
01321
01322 if (asprintf(&gcc_cmd, "%s %s", gcc_path, cmdline) == -1) {
01323 internal_error("cannot allocate memory");
01324 goto bail;
01325 }
01326
01327 if ((fp = popen(gcc_cmd, "r")) == NULL) {
01328 internal_error("cannot execute linker");
01329 fp = NULL;
01330 }
01331
01332 bail:
01333 free(gcc_path);
01334 free(gcc_cmd);
01335 return fp;
01336 }
01337
01338
01339
01340
01341 static void
01342 print_search_path ()
01343 {
01344 char *exe_dir = get_executable_dir();
01345 string_list_t *libdirs = init_string_list();
01346
01347 char *root_prefix = directory_path(get_executable_dir());
01348 char *our_path;
01349 FILE *fp;
01350 string_item_t *p;
01351 char *gcc_lib_ptr;
01352 int buflen;
01353
01354 printf ("install: %.*s\n", (int)(strlen(exe_dir) - 4), exe_dir);
01355 printf ("programs: %s:%s\n", exe_dir, get_phase_dir (P_be));
01356
01357 if (abi == ABI_N32) {
01358 #ifdef PSC_TO_OPEN64
01359 asprintf(&our_path, "%s/lib/" OPEN64_FULL_VERSION "/32",
01360 root_prefix);
01361 } else {
01362 asprintf(&our_path, "%s/lib/" OPEN64_FULL_VERSION, root_prefix);
01363 #endif
01364 }
01365
01366
01367 add_string(libdirs, our_path);
01368
01369 if (abi == ABI_N32) {
01370 add_string(libdirs, ":/lib");
01371 add_string(libdirs, ":/usr/lib");
01372 } else {
01373 add_string(libdirs, ":/lib64");
01374 add_string(libdirs, ":/usr/lib64");
01375 }
01376
01377 if ((fp = read_gcc_output ("-print-search-dirs"))) {
01378 char buf[BUFSIZ];
01379 while (fgets (buf, BUFSIZ, fp) != NULL) {
01380 if (strncmp (buf, "libraries", 9) == 0) {
01381 gcc_lib_ptr = strchr (buf, '/');
01382
01383 buflen = strlen (buf);
01384 buf[buflen-2] = '\0';
01385 if (gcc_lib_ptr) {
01386 add_string (libdirs, concat_strings (":", gcc_lib_ptr));
01387 }
01388 }
01389 }
01390 pclose (fp);
01391 }
01392
01393 fputs ("libraries: ", stdout);
01394 for (p = libdirs->head; p != NULL; p = p->next) {
01395 fputs (p->name, stdout);
01396 }
01397 putc('\n', stdout);
01398
01399 free (our_path);
01400 }
01401
01402
01403 const char *
01404 get_gcc_version(int *v, int nv)
01405 {
01406 static char version[128];
01407 static int major;
01408 static int minor;
01409 static int patch;
01410
01411 if (version[0] == '\0') {
01412 #if defined(__MINGW32__)
01413
01414
01415 sprintf(version, "%d.%d", __GNUC__, __GNUC_MINOR__);
01416 #else
01417 FILE *fp = read_gcc_output("-dumpversion");
01418 char *c;
01419 fread(version, 1, sizeof(version) - 1, fp);
01420 pclose(fp);
01421
01422 version[sizeof(version) - 1] = '\0';
01423
01424 if ((c = strchr(version, '\n'))) {
01425 *c = '\0';
01426 }
01427 #endif
01428 }
01429
01430 if (v) {
01431 char *l = version + strlen(version);
01432 char *a;
01433 int i;
01434
01435 for (i = 0, a = version; i < nv; i++) {
01436 char *d;
01437 if (a < l && isdigit(*a)) {
01438 v[i] = strtol(a, &d, 10);
01439 a = d + 1;
01440 } else {
01441 v[i] = 0;
01442 }
01443 }
01444 }
01445
01446 return version;
01447 }
01448
01449 static void
01450 display_version(boolean dump_version_only)
01451 {
01452 int gcc_version;
01453 char *open64_gcc_version;
01454
01455
01456
01457 if (is_toggled(gnu_major_version))
01458 gcc_version = get_gcc_major_version();
01459
01460 if (gnu_major_version == 3)
01461 open64_gcc_version = OPEN64_GCC_VERSION;
01462 else if (gnu_major_version == 4) {
01463 if (gnu_minor_version == 0)
01464 open64_gcc_version = OPEN64_GCC40_VERSION;
01465 else if (gnu_minor_version == 2)
01466 open64_gcc_version = OPEN64_GCC42_VERSION;
01467 else
01468 internal_error("display_version: unexpected GCC version 4.%d\n",
01469 gnu_minor_version);
01470 } else
01471 internal_error("display_version: unexpected GCC version %d\n",
01472 gnu_major_version);
01473
01474 if (dump_version_only == TRUE) {
01475 #ifdef PSC_TO_OPEN64
01476 if (option_was_seen(O_compat_gcc))
01477 puts(open64_gcc_version);
01478 else
01479 puts(OPEN64_FULL_VERSION);
01480 #endif
01481 return;
01482 }
01483
01484 fprintf(stderr, "Open64 Compiler Suite: Version %s\n",
01485 compiler_version);
01486 if (show_version > 1) {
01487 fprintf(stderr, "Changeset: %s\n", cset_id);
01488 fprintf(stderr, "Built by: %s@%s in %s\n", build_user, build_host,
01489 build_root);
01490 }
01491 fprintf(stderr, "Built on: %s\n", build_date);
01492 fprintf(stderr, "Thread model: posix\n");
01493
01494 #ifdef PSC_TO_OPEN64
01495 fprintf(stderr, "GNU gcc version %s", open64_gcc_version);
01496 fprintf(stderr, " (Open64 " OPEN64_FULL_VERSION " driver)\n");
01497 #endif
01498 }