Mercurial > octave-nkf
comparison mkoctfile.cc.in @ 12174:db1f49eaba6b
whitespace fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 26 Jan 2011 23:49:42 -0500 |
parents | 1140bd9f9b21 |
children |
comparison
equal
deleted
inserted
replaced
12173:dd2af7b8dafe | 12174:db1f49eaba6b |
---|---|
48 | 48 |
49 static string OCTAVE_VERSION = %OCTAVE_CONF_VERSION%; | 49 static string OCTAVE_VERSION = %OCTAVE_CONF_VERSION%; |
50 | 50 |
51 static std::string | 51 static std::string |
52 substitute_prefix (const std::string& s, const std::string& prefix, | 52 substitute_prefix (const std::string& s, const std::string& prefix, |
53 const std::string& new_prefix) | 53 const std::string& new_prefix) |
54 { | 54 { |
55 std::string retval = s; | 55 std::string retval = s; |
56 | 56 |
57 if (!prefix.empty () && new_prefix != prefix) | 57 if (!prefix.empty () && new_prefix != prefix) |
58 { | 58 { |
59 int len = prefix.length (); | 59 int len = prefix.length (); |
60 if (retval.find (prefix) == 0) | 60 if (retval.find (prefix) == 0) |
61 retval.replace (0, len, new_prefix); | 61 retval.replace (0, len, new_prefix); |
62 } | 62 } |
63 | 63 |
64 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) | 64 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
65 std::replace (retval.begin (), retval.end (), '/', '\\'); | 65 std::replace (retval.begin (), retval.end (), '/', '\\'); |
66 #endif | 66 #endif |
77 | 77 |
78 while (true) | 78 while (true) |
79 { | 79 { |
80 c = static_cast<char> (fgetc (fp)); | 80 c = static_cast<char> (fgetc (fp)); |
81 if (c == '\n' || c == EOF) | 81 if (c == '\n' || c == EOF) |
82 break; | 82 break; |
83 if (buf.size () <= idx) | 83 if (buf.size () <= idx) |
84 buf.resize (buf.size () + 100); | 84 buf.resize (buf.size () + 100); |
85 buf[idx++] = c; | 85 buf[idx++] = c; |
86 } | 86 } |
87 if (idx == 0) | 87 if (idx == 0) |
88 return string (""); | 88 return string (""); |
89 else | 89 else |
128 while (true) | 128 while (true) |
129 { | 129 { |
130 int status = GetModuleFileName (0, &bin_dir[0], n); | 130 int status = GetModuleFileName (0, &bin_dir[0], n); |
131 | 131 |
132 if (status < n) | 132 if (status < n) |
133 { | 133 { |
134 bin_dir.resize (status); | 134 bin_dir.resize (status); |
135 break; | 135 break; |
136 } | 136 } |
137 else | 137 else |
138 { | 138 { |
139 n *= 2; | 139 n *= 2; |
140 bin_dir.resize (n); | 140 bin_dir.resize (n); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 if (! bin_dir.empty ()) | 144 if (! bin_dir.empty ()) |
145 { | 145 { |
146 size_t pos = bin_dir.rfind ("\\bin\\"); | 146 size_t pos = bin_dir.rfind ("\\bin\\"); |
147 | 147 |
148 if (pos != string::npos) | 148 if (pos != string::npos) |
149 vars["OCTAVE_HOME"] = bin_dir.substr (0, pos); | 149 vars["OCTAVE_HOME"] = bin_dir.substr (0, pos); |
150 } | 150 } |
151 #endif | 151 #endif |
152 | 152 |
153 vars["SED"] = get_variable ("SED", %OCTAVE_CONF_SED%); | 153 vars["SED"] = get_variable ("SED", %OCTAVE_CONF_SED%); |
154 | 154 |
160 std::string DEFAULT_OCTLIBDIR = %OCTAVE_CONF_OCTLIBDIR%; | 160 std::string DEFAULT_OCTLIBDIR = %OCTAVE_CONF_OCTLIBDIR%; |
161 | 161 |
162 if (! vars["OCTAVE_HOME"].empty ()) | 162 if (! vars["OCTAVE_HOME"].empty ()) |
163 { | 163 { |
164 DEFAULT_OCTINCLUDEDIR | 164 DEFAULT_OCTINCLUDEDIR |
165 = substitute_prefix (DEFAULT_OCTINCLUDEDIR, vars["OCTAVE_PREFIX"], | 165 = substitute_prefix (DEFAULT_OCTINCLUDEDIR, vars["OCTAVE_PREFIX"], |
166 vars["OCTAVE_HOME"]); | 166 vars["OCTAVE_HOME"]); |
167 | 167 |
168 DEFAULT_INCLUDEDIR | 168 DEFAULT_INCLUDEDIR |
169 = substitute_prefix (DEFAULT_INCLUDEDIR, vars["OCTAVE_PREFIX"], | 169 = substitute_prefix (DEFAULT_INCLUDEDIR, vars["OCTAVE_PREFIX"], |
170 vars["OCTAVE_HOME"]); | 170 vars["OCTAVE_HOME"]); |
171 | 171 |
172 DEFAULT_LIBDIR | 172 DEFAULT_LIBDIR |
173 = substitute_prefix (DEFAULT_LIBDIR, vars["OCTAVE_PREFIX"], | 173 = substitute_prefix (DEFAULT_LIBDIR, vars["OCTAVE_PREFIX"], |
174 vars["OCTAVE_HOME"]); | 174 vars["OCTAVE_HOME"]); |
175 | 175 |
176 DEFAULT_OCTLIBDIR | 176 DEFAULT_OCTLIBDIR |
177 = substitute_prefix (DEFAULT_OCTLIBDIR, vars["OCTAVE_PREFIX"], | 177 = substitute_prefix (DEFAULT_OCTLIBDIR, vars["OCTAVE_PREFIX"], |
178 vars["OCTAVE_HOME"]); | 178 vars["OCTAVE_HOME"]); |
179 } | 179 } |
180 | 180 |
181 vars["OCTINCLUDEDIR"] = get_variable ("OCTINCLUDEDIR", DEFAULT_OCTINCLUDEDIR); | 181 vars["OCTINCLUDEDIR"] = get_variable ("OCTINCLUDEDIR", DEFAULT_OCTINCLUDEDIR); |
182 vars["INCLUDEDIR"] = get_variable ("INCLUDEDIR", DEFAULT_INCLUDEDIR); | 182 vars["INCLUDEDIR"] = get_variable ("INCLUDEDIR", DEFAULT_INCLUDEDIR); |
183 vars["LIBDIR"] = get_variable ("LIBDIR", DEFAULT_LIBDIR); | 183 vars["LIBDIR"] = get_variable ("LIBDIR", DEFAULT_LIBDIR); |
294 " -g Enable debugging options for compilers.\n" | 294 " -g Enable debugging options for compilers.\n" |
295 "\n" | 295 "\n" |
296 " -p VAR, --print VAR Print configuration variable VAR. Recognized\n" | 296 " -p VAR, --print VAR Print configuration variable VAR. Recognized\n" |
297 " variables are:\n" | 297 " variables are:\n" |
298 "\n" | 298 "\n" |
299 " ALL_CFLAGS FLIBS\n" | 299 " ALL_CFLAGS FLIBS\n" |
300 " ALL_CXXFLAGS FPICFLAG\n" | 300 " ALL_CXXFLAGS FPICFLAG\n" |
301 " ALL_FFLAGS INCFLAGS\n" | 301 " ALL_FFLAGS INCFLAGS\n" |
302 " ALL_LDFLAGS LAPACK_LIBS\n" | 302 " ALL_LDFLAGS LAPACK_LIBS\n" |
303 " BLAS_LIBS LDFLAGS\n" | 303 " BLAS_LIBS LDFLAGS\n" |
304 " CC LD_CXX\n" | 304 " CC LD_CXX\n" |
305 " CFLAGS LD_STATIC_FLAG\n" | 305 " CFLAGS LD_STATIC_FLAG\n" |
306 " CPICFLAG LFLAGS\n" | 306 " CPICFLAG LFLAGS\n" |
307 " CPPFLAGS LIBCRUFT\n" | 307 " CPPFLAGS LIBCRUFT\n" |
308 " CXX LIBOCTAVE\n" | 308 " CXX LIBOCTAVE\n" |
309 " CXXFLAGS LIBOCTINTERP\n" | 309 " CXXFLAGS LIBOCTINTERP\n" |
310 " CXXPICFLAG LIBS\n" | 310 " CXXPICFLAG LIBS\n" |
311 " DEPEND_EXTRA_SED_PATTERN OCTAVE_LIBS\n" | 311 " DEPEND_EXTRA_SED_PATTERN OCTAVE_LIBS\n" |
312 " DEPEND_FLAGS RDYNAMIC_FLAG\n" | 312 " DEPEND_FLAGS RDYNAMIC_FLAG\n" |
313 " DL_LD READLINE_LIBS\n" | 313 " DL_LD READLINE_LIBS\n" |
314 " DL_LDFLAGS RLD_FLAG\n" | 314 " DL_LDFLAGS RLD_FLAG\n" |
315 " F77 SED\n" | 315 " F77 SED\n" |
316 " FFLAGS XTRA_CFLAGS\n" | 316 " FFLAGS XTRA_CFLAGS\n" |
317 " FFTW_LIBS XTRA_CXXFLAGS\n" | 317 " FFTW_LIBS XTRA_CXXFLAGS\n" |
318 "\n" | 318 "\n" |
319 " --link-stand-alone Link a stand-alone executable file.\n" | 319 " --link-stand-alone Link a stand-alone executable file.\n" |
320 "\n" | 320 "\n" |
321 " --mex Assume we are creating a MEX file. Set the\n" | 321 " --mex Assume we are creating a MEX file. Set the\n" |
322 " default output extension to \".mex\".\n" | 322 " default output extension to \".mex\".\n" |
354 retval = s.substr (0, pos); | 354 retval = s.substr (0, pos); |
355 if (strip_path) | 355 if (strip_path) |
356 { | 356 { |
357 size_t p1 = retval.rfind ('/'), p2 = retval.rfind ('\\'); | 357 size_t p1 = retval.rfind ('/'), p2 = retval.rfind ('\\'); |
358 pos = (p1 != string::npos && p2 != string::npos | 358 pos = (p1 != string::npos && p2 != string::npos |
359 ? max (p1, p2) : (p2 != string::npos ? p2 : p1)); | 359 ? max (p1, p2) : (p2 != string::npos ? p2 : p1)); |
360 if (pos != string::npos) | 360 if (pos != string::npos) |
361 retval = retval.substr (0, pos); | 361 retval = retval.substr (0, pos); |
362 } | 362 } |
363 return retval; | 363 return retval; |
364 } | 364 } |
365 | 365 |
366 inline bool | 366 inline bool |
371 | 371 |
372 inline bool | 372 inline bool |
373 ends_with (const string& s, const string& suffix) | 373 ends_with (const string& s, const string& suffix) |
374 { | 374 { |
375 return (s.length () >= suffix.length () | 375 return (s.length () >= suffix.length () |
376 && s.rfind (suffix) == s.length () - suffix.length ()); | 376 && s.rfind (suffix) == s.length () - suffix.length ()); |
377 } | 377 } |
378 | 378 |
379 static int | 379 static int |
380 run_command (const string& cmd) | 380 run_command (const string& cmd) |
381 { | 381 { |
427 { | 427 { |
428 string arg = argv[i]; | 428 string arg = argv[i]; |
429 size_t len = arg.length (); | 429 size_t len = arg.length (); |
430 | 430 |
431 if (ends_with (arg, ".c")) | 431 if (ends_with (arg, ".c")) |
432 { | 432 { |
433 file = arg; | 433 file = arg; |
434 cfiles.push_back (file); | 434 cfiles.push_back (file); |
435 } | 435 } |
436 else if (ends_with (arg, ".cc") || ends_with (arg, ".C") | 436 else if (ends_with (arg, ".cc") || ends_with (arg, ".C") |
437 || ends_with (arg, ".cpp")) | 437 || ends_with (arg, ".cpp")) |
438 { | 438 { |
439 file = arg; | 439 file = arg; |
440 ccfiles.push_back (file); | 440 ccfiles.push_back (file); |
441 } | 441 } |
442 else if (ends_with (arg, ".f") || ends_with (arg, ".F") | 442 else if (ends_with (arg, ".f") || ends_with (arg, ".F") |
443 || ends_with (arg, "f90") || ends_with (arg, ".F90")) | 443 || ends_with (arg, "f90") || ends_with (arg, ".F90")) |
444 { | 444 { |
445 file = arg; | 445 file = arg; |
446 f77files.push_back (file); | 446 f77files.push_back (file); |
447 } | 447 } |
448 else if (ends_with (arg, ".o") || ends_with (arg, ".obj")) | 448 else if (ends_with (arg, ".o") || ends_with (arg, ".obj")) |
449 { | 449 { |
450 file = arg; | 450 file = arg; |
451 objfiles += (" " + quote_path (arg)); | 451 objfiles += (" " + quote_path (arg)); |
452 } | 452 } |
453 else if (ends_with (arg, ".lib") || ends_with (arg, ".a")) | 453 else if (ends_with (arg, ".lib") || ends_with (arg, ".a")) |
454 { | 454 { |
455 file = arg; | 455 file = arg; |
456 libfiles += (" " + quote_path (arg)); | 456 libfiles += (" " + quote_path (arg)); |
457 } | 457 } |
458 else if (arg == "-d" || arg == "-debug" || arg == "--debug" | 458 else if (arg == "-d" || arg == "-debug" || arg == "--debug" |
459 || arg == "-v" || arg == "-verbose" || arg == "--verbose") | 459 || arg == "-v" || arg == "-verbose" || arg == "--verbose") |
460 { | 460 { |
461 debug = true; | 461 debug = true; |
462 if (vars["CC"] == "cc-msvc") | 462 if (vars["CC"] == "cc-msvc") |
463 vars["CC"] += " -d"; | 463 vars["CC"] += " -d"; |
464 if (vars["CXX"] == "cc-msvc") | 464 if (vars["CXX"] == "cc-msvc") |
465 vars["CXX"] += " -d"; | 465 vars["CXX"] += " -d"; |
466 if (vars["DL_LD"] == "cc-msvc") | 466 if (vars["DL_LD"] == "cc-msvc") |
467 vars["DL_LD"] += " -d"; | 467 vars["DL_LD"] += " -d"; |
468 } | 468 } |
469 else if (arg == "-h" || arg == "-?" || arg == "-help" || arg == "--help") | 469 else if (arg == "-h" || arg == "-?" || arg == "-help" || arg == "--help") |
470 { | 470 { |
471 cout << usage_msg << endl; | 471 cout << usage_msg << endl; |
472 cout << help_msg << endl; | 472 cout << help_msg << endl; |
473 return 0; | 473 return 0; |
474 } | 474 } |
475 else if (starts_with (arg, "-I")) | 475 else if (starts_with (arg, "-I")) |
476 { | 476 { |
477 incflags += (" " + quote_path (arg)); | 477 incflags += (" " + quote_path (arg)); |
478 } | 478 } |
479 else if (arg == "-idirafter") | 479 else if (arg == "-idirafter") |
480 { | 480 { |
481 if (i < argc-1) | 481 if (i < argc-1) |
482 { | 482 { |
483 arg = argv[++i]; | 483 arg = argv[++i]; |
484 incflags += (" -idirafter " + arg); | 484 incflags += (" -idirafter " + arg); |
485 } | 485 } |
486 else | 486 else |
487 cerr << "mkoctfile: include directory name missing" << endl; | 487 cerr << "mkoctfile: include directory name missing" << endl; |
488 } | 488 } |
489 else if (starts_with (arg, "-D")) | 489 else if (starts_with (arg, "-D")) |
490 { | 490 { |
491 defs += (" " + arg); | 491 defs += (" " + arg); |
492 } | 492 } |
493 else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l") | 493 else if (starts_with (arg, "-Wl,") || starts_with (arg, "-l") |
494 || starts_with (arg, "-L") || starts_with (arg, "-R")) | 494 || starts_with (arg, "-L") || starts_with (arg, "-R")) |
495 { | 495 { |
496 ldflags += (" " + arg); | 496 ldflags += (" " + arg); |
497 } | 497 } |
498 else if (arg == "-M" || arg == "-depend" || arg == "--depend") | 498 else if (arg == "-M" || arg == "-depend" || arg == "--depend") |
499 { | 499 { |
500 depend = true; | 500 depend = true; |
501 compile = false; | 501 compile = false; |
502 } | 502 } |
503 else if (arg == "-o" || arg == "-output" || arg == "--output") | 503 else if (arg == "-o" || arg == "-output" || arg == "--output") |
504 { | 504 { |
505 if (i < argc-1) | 505 if (i < argc-1) |
506 { | 506 { |
507 arg = argv[++i]; | 507 arg = argv[++i]; |
508 outputfile = arg; | 508 outputfile = arg; |
509 } | 509 } |
510 else | 510 else |
511 cerr << "mkoctfile: output file name missing" << endl; | 511 cerr << "mkoctfile: output file name missing" << endl; |
512 } | 512 } |
513 else if (arg == "-p" || arg == "-print" || arg == "--print") | 513 else if (arg == "-p" || arg == "-print" || arg == "--print") |
514 { | 514 { |
515 if (i < argc-1) | 515 if (i < argc-1) |
516 { | 516 { |
517 arg = argv[++i]; | 517 arg = argv[++i]; |
518 cout << vars[arg] << endl; | 518 cout << vars[arg] << endl; |
519 return 0; | 519 return 0; |
520 } | 520 } |
521 else | 521 else |
522 cerr << "mkoctfile: --print requires argument" << endl; | 522 cerr << "mkoctfile: --print requires argument" << endl; |
523 } | 523 } |
524 else if (arg == "-s" || arg == "-strip" || arg == "--strip") | 524 else if (arg == "-s" || arg == "-strip" || arg == "--strip") |
525 { | 525 { |
526 if (no_oct_file_strip_on_this_platform) | 526 if (no_oct_file_strip_on_this_platform) |
527 cerr << "mkoctfile: stripping disabled on this platform" << endl; | 527 cerr << "mkoctfile: stripping disabled on this platform" << endl; |
528 else | 528 else |
529 strip = true; | 529 strip = true; |
530 } | 530 } |
531 else if (arg == "-c" || arg == "-compile" || arg == "--compile") | 531 else if (arg == "-c" || arg == "-compile" || arg == "--compile") |
532 { | 532 { |
533 link = false; | 533 link = false; |
534 } | 534 } |
535 else if (arg == "-g") | 535 else if (arg == "-g") |
536 { | 536 { |
537 vars["ALL_CFLAGS"] += " -g"; | 537 vars["ALL_CFLAGS"] += " -g"; |
538 vars["ALL_CXXFLAGS"] += " -g"; | 538 vars["ALL_CXXFLAGS"] += " -g"; |
539 vars["ALL_FFLAGS"] += " -g"; | 539 vars["ALL_FFLAGS"] += " -g"; |
540 } | 540 } |
541 else if (arg == "-link-stand-alone" || arg == "--link-stand-alone") | 541 else if (arg == "-link-stand-alone" || arg == "--link-stand-alone") |
542 { | 542 { |
543 link_stand_alone = true; | 543 link_stand_alone = true; |
544 } | 544 } |
545 else if (arg == "-mex" || arg == "--mex") | 545 else if (arg == "-mex" || arg == "--mex") |
546 { | 546 { |
547 incflags += " -I."; | 547 incflags += " -I."; |
548 #ifdef _MSC_VER | 548 #ifdef _MSC_VER |
549 ldflags += " -Wl,-export:mexFunction"; | 549 ldflags += " -Wl,-export:mexFunction"; |
550 #endif | 550 #endif |
551 output_ext = ".mex"; | 551 output_ext = ".mex"; |
552 } | 552 } |
553 else if (starts_with (arg, "-W")) | 553 else if (starts_with (arg, "-W")) |
554 { | 554 { |
555 pass_on_options += (" " + arg); | 555 pass_on_options += (" " + arg); |
556 } | 556 } |
557 else | 557 else |
558 { | 558 { |
559 cerr << "mkoctfile: unrecognized argument " << arg; | 559 cerr << "mkoctfile: unrecognized argument " << arg; |
560 return 1; | 560 return 1; |
561 } | 561 } |
562 | 562 |
563 if (!file.empty () && octfile.empty ()) | 563 if (!file.empty () && octfile.empty ()) |
564 octfile = file; | 564 octfile = file; |
565 } | 565 } |
566 | 566 |
567 if (link_stand_alone) | 567 if (link_stand_alone) |
568 { | 568 { |
569 if (!outputfile.empty ()) | 569 if (!outputfile.empty ()) |
570 output_option = "-o " + outputfile; | 570 output_option = "-o " + outputfile; |
571 } | 571 } |
572 else | 572 else |
573 { | 573 { |
574 if (!outputfile.empty ()) | 574 if (!outputfile.empty ()) |
575 { | 575 { |
578 size_t len_ext = output_ext.length (); | 578 size_t len_ext = output_ext.length (); |
579 if (octfile.substr (len-len_ext) != output_ext) | 579 if (octfile.substr (len-len_ext) != output_ext) |
580 octfile += output_ext; | 580 octfile += output_ext; |
581 } | 581 } |
582 else | 582 else |
583 octfile = basename (octfile, true) + output_ext; | 583 octfile = basename (octfile, true) + output_ext; |
584 } | 584 } |
585 | 585 |
586 list<string>::const_iterator it; | 586 list<string>::const_iterator it; |
587 | 587 |
588 if (depend) | 588 if (depend) |
589 { | 589 { |
590 for (it = cfiles.begin (); it != cfiles.end (); ++it) | 590 for (it = cfiles.begin (); it != cfiles.end (); ++it) |
591 { | 591 { |
592 string f = *it, dfile = basename (f, true) + ".d", line; | 592 string f = *it, dfile = basename (f, true) + ".d", line; |
593 | 593 |
594 unlink (dfile.c_str ()); | 594 unlink (dfile.c_str ()); |
595 string cmd = vars["CC"] + " " + vars["DEPEND_FLAGS"] + " " | 595 string cmd = vars["CC"] + " " + vars["DEPEND_FLAGS"] + " " |
596 + vars["CPPFLAGS"] + " " + vars["ALL_CFLAGS"] + " " | 596 + vars["CPPFLAGS"] + " " + vars["ALL_CFLAGS"] + " " |
597 + incflags + " " + defs + " " + quote_path (f); | 597 + incflags + " " + defs + " " + quote_path (f); |
598 | 598 |
599 FILE *fd = popen (cmd.c_str (), "r"); | 599 FILE *fd = popen (cmd.c_str (), "r"); |
600 ofstream fo (dfile.c_str ()); | 600 ofstream fo (dfile.c_str ()); |
601 int pos; | 601 int pos; |
602 while (!feof (fd)) | 602 while (!feof (fd)) |
603 { | 603 { |
604 line = get_line (fd); | 604 line = get_line (fd); |
605 if ((pos = line.rfind (".o:")) != string::npos) | 605 if ((pos = line.rfind (".o:")) != string::npos) |
606 { | 606 { |
607 int spos = line.rfind ('/', pos); | 607 int spos = line.rfind ('/', pos); |
608 string ofile = (spos == string::npos ? line.substr (0, pos+2) : line.substr (spos+1, pos-spos+1)); | 608 string ofile = (spos == string::npos ? line.substr (0, pos+2) : line.substr (spos+1, pos-spos+1)); |
609 fo << "pic/" << ofile << " " << ofile << " " << dfile << line.substr (pos) << endl; | 609 fo << "pic/" << ofile << " " << ofile << " " << dfile << line.substr (pos) << endl; |
610 } | 610 } |
611 else | 611 else |
612 fo << line << endl; | 612 fo << line << endl; |
613 } | 613 } |
614 pclose (fd); | 614 pclose (fd); |
615 fo.close (); | 615 fo.close (); |
616 } | 616 } |
617 | 617 |
618 for (it = ccfiles.begin (); it != ccfiles.end (); ++it) | 618 for (it = ccfiles.begin (); it != ccfiles.end (); ++it) |
619 { | 619 { |
620 string f = *it, dfile = basename (f, true) + ".d", line; | 620 string f = *it, dfile = basename (f, true) + ".d", line; |
621 | 621 |
622 unlink (dfile.c_str ()); | 622 unlink (dfile.c_str ()); |
623 string cmd = vars["CC"] + " " + vars["DEPEND_FLAGS"] + " " | 623 string cmd = vars["CC"] + " " + vars["DEPEND_FLAGS"] + " " |
624 + vars["CPPFLAGS"] + " " + vars["ALL_CXXFLAGS"] + " " | 624 + vars["CPPFLAGS"] + " " + vars["ALL_CXXFLAGS"] + " " |
625 + incflags + " " + defs + " " + quote_path (f); | 625 + incflags + " " + defs + " " + quote_path (f); |
626 | 626 |
627 FILE *fd = popen (cmd.c_str (), "r"); | 627 FILE *fd = popen (cmd.c_str (), "r"); |
628 ofstream fo (dfile.c_str ()); | 628 ofstream fo (dfile.c_str ()); |
629 int pos; | 629 int pos; |
630 while (!feof (fd)) | 630 while (!feof (fd)) |
631 { | 631 { |
632 line = get_line (fd); | 632 line = get_line (fd); |
633 if ((pos = line.rfind (".o:")) != string::npos) | 633 if ((pos = line.rfind (".o:")) != string::npos) |
634 { | 634 { |
635 int spos = line.rfind ('/', pos); | 635 int spos = line.rfind ('/', pos); |
636 string ofile = (spos == string::npos ? line.substr (0, pos+2) : line.substr (spos+1, pos-spos+1)); | 636 string ofile = (spos == string::npos ? line.substr (0, pos+2) : line.substr (spos+1, pos-spos+1)); |
637 fo << "pic/" << ofile << " " << ofile << " " << dfile << line.substr (pos+2) << endl; | 637 fo << "pic/" << ofile << " " << ofile << " " << dfile << line.substr (pos+2) << endl; |
638 } | 638 } |
639 else | 639 else |
640 fo << line << endl; | 640 fo << line << endl; |
641 } | 641 } |
642 pclose (fd); | 642 pclose (fd); |
643 fo.close (); | 643 fo.close (); |
644 } | 644 } |
645 | 645 |
646 return 0; | 646 return 0; |
647 } | 647 } |
648 | 648 |
649 for (it = f77files.begin (); it != f77files.end (); ++it) | 649 for (it = f77files.begin (); it != f77files.end (); ++it) |
650 { | 650 { |
651 string f = *it, b = basename (f, true); | 651 string f = *it, b = basename (f, true); |
652 if (!vars["F77"].empty ()) | 652 if (!vars["F77"].empty ()) |
653 { | 653 { |
654 string o; | 654 string o; |
655 if (!outputfile.empty ()) | 655 if (!outputfile.empty ()) |
656 { | 656 { |
657 if (link) | 657 if (link) |
658 o = b + ".o"; | 658 o = b + ".o"; |
659 else | 659 else |
660 o = outputfile; | 660 o = outputfile; |
661 } | 661 } |
662 else | 662 else |
663 o = b + ".o"; | 663 o = b + ".o"; |
664 objfiles += (" " + o); | 664 objfiles += (" " + o); |
665 string cmd = vars["F77"] + " -c " + vars["FPICFLAG"] + " " | 665 string cmd = vars["F77"] + " -c " + vars["FPICFLAG"] + " " |
666 + vars["ALL_FFLAGS"] + " " + incflags + " " + defs + " " | 666 + vars["ALL_FFLAGS"] + " " + incflags + " " + defs + " " |
667 + pass_on_options + " " + f + " -o " + o; | 667 + pass_on_options + " " + f + " -o " + o; |
668 result = run_command (cmd); | 668 result = run_command (cmd); |
669 } | 669 } |
670 else | 670 else |
671 { | 671 { |
672 cerr << "mkoctfile: no way to compile Fortran file " << f << endl; | 672 cerr << "mkoctfile: no way to compile Fortran file " << f << endl; |
673 return 1; | 673 return 1; |
674 } | 674 } |
675 } | 675 } |
676 | 676 |
677 for (it = cfiles.begin (); it != cfiles.end (); ++it) | 677 for (it = cfiles.begin (); it != cfiles.end (); ++it) |
678 { | 678 { |
679 string f = *it; | 679 string f = *it; |
680 if (!vars["CC"].empty ()) | 680 if (!vars["CC"].empty ()) |
681 { | 681 { |
682 string b = basename (f, true), o; | 682 string b = basename (f, true), o; |
683 if (!outputfile.empty ()) | 683 if (!outputfile.empty ()) |
684 { | 684 { |
685 if (link) | 685 if (link) |
686 o = b + ".o"; | 686 o = b + ".o"; |
687 else | 687 else |
688 o = outputfile; | 688 o = outputfile; |
689 } | 689 } |
690 else | 690 else |
691 o = b + ".o"; | 691 o = b + ".o"; |
692 objfiles += (" " + o); | 692 objfiles += (" " + o); |
693 string cmd = vars["CC"] + " -c " + vars["CPPFLAGS"] + " " | 693 string cmd = vars["CC"] + " -c " + vars["CPPFLAGS"] + " " |
694 + vars["CPICFLAG"] + " " + vars["ALL_CFLAGS"] + " " | 694 + vars["CPICFLAG"] + " " + vars["ALL_CFLAGS"] + " " |
695 + pass_on_options + " " + incflags + " " + defs + " " | 695 + pass_on_options + " " + incflags + " " + defs + " " |
696 + quote_path (f) + " -o " + quote_path (o); | 696 + quote_path (f) + " -o " + quote_path (o); |
697 result = run_command (cmd); | 697 result = run_command (cmd); |
698 } | 698 } |
699 else | 699 else |
700 { | 700 { |
701 cerr << "mkoctfile: no way to compile C file " << f << endl; | 701 cerr << "mkoctfile: no way to compile C file " << f << endl; |
702 return 1; | 702 return 1; |
703 } | 703 } |
704 } | 704 } |
705 | 705 |
706 for (it = ccfiles.begin (); it != ccfiles.end (); ++it) | 706 for (it = ccfiles.begin (); it != ccfiles.end (); ++it) |
707 { | 707 { |
708 string f = *it; | 708 string f = *it; |
709 if (!vars["CXX"].empty ()) | 709 if (!vars["CXX"].empty ()) |
710 { | 710 { |
711 string b = basename (f, true), o; | 711 string b = basename (f, true), o; |
712 if (!outputfile.empty ()) | 712 if (!outputfile.empty ()) |
713 { | 713 { |
714 if (link) | 714 if (link) |
715 o = b + ".o"; | 715 o = b + ".o"; |
716 else | 716 else |
717 o = outputfile; | 717 o = outputfile; |
718 } | 718 } |
719 else | 719 else |
720 o = b + ".o"; | 720 o = b + ".o"; |
721 objfiles += (" " + o); | 721 objfiles += (" " + o); |
722 string cmd = vars["CXX"] + " -c " + vars["CPPFLAGS"] + " " | 722 string cmd = vars["CXX"] + " -c " + vars["CPPFLAGS"] + " " |
723 + vars["CXXPICFLAG"] + " " + vars["ALL_CXXFLAGS"] + " " | 723 + vars["CXXPICFLAG"] + " " + vars["ALL_CXXFLAGS"] + " " |
724 + pass_on_options + " " + incflags + " " + defs + " " | 724 + pass_on_options + " " + incflags + " " + defs + " " |
725 + quote_path (f) + " -o " + quote_path (o); | 725 + quote_path (f) + " -o " + quote_path (o); |
726 result = run_command (cmd); | 726 result = run_command (cmd); |
727 } | 727 } |
728 else | 728 else |
729 { | 729 { |
730 cerr << "mkoctfile: no way to compile C++ file " << f << endl; | 730 cerr << "mkoctfile: no way to compile C++ file " << f << endl; |
731 return 1; | 731 return 1; |
732 } | 732 } |
733 } | 733 } |
734 | 734 |
735 if (link && !objfiles.empty ()) | 735 if (link && !objfiles.empty ()) |
736 { | 736 { |
737 if (link_stand_alone) | 737 if (link_stand_alone) |
738 { | 738 { |
739 if (!vars["LD_CXX"].empty ()) | 739 if (!vars["LD_CXX"].empty ()) |
740 { | 740 { |
741 string cmd = vars["LD_CXX"] + " " + vars["CPPFLAGS"] + " " | 741 string cmd = vars["LD_CXX"] + " " + vars["CPPFLAGS"] + " " |
742 + vars["ALL_CXXFLAGS"] + " " + vars["RDYNAMIC_FLAG"] | 742 + vars["ALL_CXXFLAGS"] + " " + vars["RDYNAMIC_FLAG"] |
743 + " " + vars["ALL_LDFLAGS"] + " " + pass_on_options | 743 + " " + vars["ALL_LDFLAGS"] + " " + pass_on_options |
744 + " " + output_option + " " + objfiles + " " + libfiles | 744 + " " + output_option + " " + objfiles + " " + libfiles |
745 + " " + ldflags + " " + vars["LFLAGS"] + " " | 745 + " " + ldflags + " " + vars["LFLAGS"] + " " |
746 + vars["RLD_FLAG"] + " " + vars["OCTAVE_LIBS"] + " " | 746 + vars["RLD_FLAG"] + " " + vars["OCTAVE_LIBS"] + " " |
747 + vars["LAPACK_LIBS"] + " " + vars["BLAS_LIBS"] + " " | 747 + vars["LAPACK_LIBS"] + " " + vars["BLAS_LIBS"] + " " |
748 + vars["FFTW_LIBS"] + " " + vars["READLINE_LIBS"] + " " | 748 + vars["FFTW_LIBS"] + " " + vars["READLINE_LIBS"] + " " |
749 + vars["LIBS"] + " " + vars["FLIBS"]; | 749 + vars["LIBS"] + " " + vars["FLIBS"]; |
750 result = run_command (cmd); | 750 result = run_command (cmd); |
751 } | 751 } |
752 else | 752 else |
753 { | 753 { |
754 cerr << "mkoctfile: no way to link stand-alone executable file" | 754 cerr << "mkoctfile: no way to link stand-alone executable file" |
755 << endl; | 755 << endl; |
756 return 1; | 756 return 1; |
757 } | 757 } |
758 } | 758 } |
759 else | 759 else |
760 { | 760 { |
761 string LINK_DEPS = vars["LFLAGS"] + " " + vars["OCTAVE_LIBS"] | 761 string LINK_DEPS = vars["LFLAGS"] + " " + vars["OCTAVE_LIBS"] |
762 + " " + vars["LDFLAGS"] + " " + vars["BLAS_LIBS"] + " " | 762 + " " + vars["LDFLAGS"] + " " + vars["BLAS_LIBS"] + " " |
763 + vars["FFTW_LIBS"] + " " + vars["LIBS"] + " " + vars["FLIBS"]; | 763 + vars["FFTW_LIBS"] + " " + vars["LIBS"] + " " + vars["FLIBS"]; |
764 string cmd = vars["DL_LD"] + " " + vars["DL_LDFLAGS"] + " " | 764 string cmd = vars["DL_LD"] + " " + vars["DL_LDFLAGS"] + " " |
765 + pass_on_options + " -o " + octfile + " " + objfiles + " " | 765 + pass_on_options + " -o " + octfile + " " + objfiles + " " |
766 + libfiles + " " + ldflags + " " + LINK_DEPS; | 766 + libfiles + " " + ldflags + " " + LINK_DEPS; |
767 result = run_command (cmd); | 767 result = run_command (cmd); |
768 } | 768 } |
769 | 769 |
770 if (strip) | 770 if (strip) |
771 { | 771 { |
772 string cmd = "strip " + octfile; | 772 string cmd = "strip " + octfile; |
773 result = run_command (cmd); | 773 result = run_command (cmd); |
774 } | 774 } |
775 } | 775 } |
776 | 776 |
777 return result; | 777 return result; |
778 } | 778 } |