Mercurial > projects > ldc
comparison dmd/mars.c @ 708:fd5665da3a27
Hopefully sensible command switch handling. Changed default ext to .o on Windows.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Thu, 16 Oct 2008 22:07:02 +0200 |
parents | 716684a0d63f |
children | 8c0d3ec8dbbb |
comparison
equal
deleted
inserted
replaced
707:1556a9328ba1 | 708:fd5665da3a27 |
---|---|
53 | 53 |
54 // LDC | 54 // LDC |
55 ll_ext = "ll"; | 55 ll_ext = "ll"; |
56 bc_ext = "bc"; | 56 bc_ext = "bc"; |
57 s_ext = "s"; | 57 s_ext = "s"; |
58 obj_ext = "o"; | |
58 #if _WIN32 | 59 #if _WIN32 |
59 obj_ext = "obj"; | 60 obj_ext_alt = "obj"; |
60 #elif POSIX | |
61 obj_ext = "o"; | |
62 #else | |
63 #error "fix this" | |
64 #endif | 61 #endif |
65 | 62 |
66 copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen"; | 63 copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen"; |
67 written = "written by Walter Bright and Tomas Lindquist Olsen"; | 64 written = "written by Walter Bright and Tomas Lindquist Olsen"; |
68 version = "v1.035"; | 65 version = "v1.035"; |
165 -o- do not write object file\n\ | 162 -o- do not write object file\n\ |
166 -od<objdir> write object files to directory <objdir>\n\ | 163 -od<objdir> write object files to directory <objdir>\n\ |
167 -op do not strip paths from source file\n\ | 164 -op do not strip paths from source file\n\ |
168 -oq write object files with fully qualified names\n\ | 165 -oq write object files with fully qualified names\n\ |
169 -of<filename> name output file to <filename>\n\ | 166 -of<filename> name output file to <filename>\n\ |
170 extension of <filename> determines output type\n\ | 167 if -c and extension of <filename> is known, it determines the output type\n\ |
171 no extension means native object or executable\n\ | |
172 if the extension is ll, bc, s, or o/obj, linking is disabled\n\ | |
173 \n\ | 168 \n\ |
174 -output-ll write LLVM IR\n\ | 169 -output-ll write LLVM IR\n\ |
175 -output-bc write LLVM bitcode\n\ | 170 -output-bc write LLVM bitcode\n\ |
176 -output-s write native assembly\n\ | 171 -output-s write native assembly\n\ |
177 -output-o write native object\n\ | 172 -output-o write native object (default if no -output switch passed)\n\ |
178 \n\ | 173 \n\ |
179 -c do not link\n\ | 174 -c do not link\n\ |
180 -L<linkerflag> pass <linkerflag> to linker\n\ | 175 -L<linkerflag> pass <linkerflag> to linker\n\ |
181 \n\ | 176 \n\ |
182 -w enable warnings\n\ | 177 -w enable warnings\n\ |
296 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run | 291 global.params.llvmInline = 0; // use this one instead to know if inline passes should be run |
297 global.params.obj = 1; | 292 global.params.obj = 1; |
298 global.params.Dversion = 2; | 293 global.params.Dversion = 2; |
299 global.params.quiet = 1; | 294 global.params.quiet = 1; |
300 | 295 |
301 global.params.output_o = 1; | 296 global.params.output_o = OUTPUTFLAGdefault; |
302 | 297 |
303 global.params.linkswitches = new Array(); | 298 global.params.linkswitches = new Array(); |
304 global.params.libfiles = new Array(); | 299 global.params.libfiles = new Array(); |
305 global.params.objfiles = new Array(); | 300 global.params.objfiles = new Array(); |
306 global.params.ddocfiles = new Array(); | 301 global.params.ddocfiles = new Array(); |
451 | 446 |
452 case 'f': | 447 case 'f': |
453 if (!p[3]) | 448 if (!p[3]) |
454 goto Lnoarg; | 449 goto Lnoarg; |
455 global.params.objname = p + 3; | 450 global.params.objname = p + 3; |
456 | |
457 // remove default output | |
458 if (global.params.output_ll == 1) | |
459 global.params.output_ll = 0; | |
460 if (global.params.output_bc == 1) | |
461 global.params.output_bc = 0; | |
462 if (global.params.output_s == 1) | |
463 global.params.output_s = 0; | |
464 if (global.params.output_o == 1) | |
465 global.params.output_o = 0; | |
466 | |
467 // determine output based on ext | |
468 ext = FileName::ext(global.params.objname); | |
469 if (!ext) { | |
470 global.params.link = 1; | |
471 global.params.output_o = 1; | |
472 } else if (strcmp(ext, global.ll_ext) == 0) { | |
473 global.params.output_ll = 1; | |
474 global.params.link = 0; | |
475 } else if (strcmp(ext, global.bc_ext) == 0) { | |
476 global.params.output_bc = 1; | |
477 global.params.link = 0; | |
478 } else if (strcmp(ext, global.s_ext) == 0) { | |
479 global.params.output_s = 1; | |
480 global.params.link = 0; | |
481 } else if (strcmp(ext, global.obj_ext) == 0) { | |
482 global.params.output_o = 1; | |
483 global.params.link = 0; | |
484 } else { | |
485 global.params.output_o = 1; | |
486 } | |
487 | |
488 break; | 451 break; |
489 | 452 |
490 case 'p': | 453 case 'p': |
491 if (p[3]) | 454 if (p[3]) |
492 goto Lerror; | 455 goto Lerror; |
500 break; | 463 break; |
501 | 464 |
502 case 'u': | 465 case 'u': |
503 if (strncmp(p+1, "output-", 7) != 0) | 466 if (strncmp(p+1, "output-", 7) != 0) |
504 goto Lerror; | 467 goto Lerror; |
468 | |
469 // remove default output | |
470 if (global.params.output_o == OUTPUTFLAGdefault) | |
471 global.params.output_o = OUTPUTFLAGno; | |
472 | |
505 if (strcmp(p+8, global.ll_ext) == 0) | 473 if (strcmp(p+8, global.ll_ext) == 0) |
506 global.params.output_ll = 2; | 474 global.params.output_ll = OUTPUTFLAGset; |
507 else if (strcmp(p+8, global.bc_ext) == 0) | 475 else if (strcmp(p+8, global.bc_ext) == 0) |
508 global.params.output_bc = 2; | 476 global.params.output_bc = OUTPUTFLAGset; |
509 else if (strcmp(p+8, global.s_ext) == 0) | 477 else if (strcmp(p+8, global.s_ext) == 0) |
510 global.params.output_s = 2; | 478 global.params.output_s = OUTPUTFLAGset; |
511 else if (strcmp(p+8, global.obj_ext) == 0) | 479 else if (strcmp(p+8, global.obj_ext) == 0) |
512 global.params.output_o = 2; | 480 global.params.output_o = OUTPUTFLAGset; |
513 else | 481 else |
514 goto Lerror; | 482 goto Lerror; |
483 | |
515 break; | 484 break; |
516 | 485 |
517 case 0: | 486 case 0: |
518 error("-o no longer supported, use -of or -od"); | 487 error("-o no longer supported, use -of or -od"); |
519 break; | 488 break; |
786 global.params.quiet = 1; | 755 global.params.quiet = 1; |
787 | 756 |
788 if (global.params.useUnitTests) | 757 if (global.params.useUnitTests) |
789 global.params.useAssert = 1; | 758 global.params.useAssert = 1; |
790 | 759 |
791 if (!global.params.obj) | 760 // LDC output determination |
761 | |
762 // if we don't link, autodetect target from extension | |
763 if(!global.params.link && global.params.objname) { | |
764 ext = FileName::ext(global.params.objname); | |
765 bool autofound = false; | |
766 if (!ext) { | |
767 // keep things as they are | |
768 } else if (strcmp(ext, global.ll_ext) == 0) { | |
769 global.params.output_ll = OUTPUTFLAGset; | |
770 autofound = true; | |
771 } else if (strcmp(ext, global.bc_ext) == 0) { | |
772 global.params.output_bc = OUTPUTFLAGset; | |
773 autofound = true; | |
774 } else if (strcmp(ext, global.s_ext) == 0) { | |
775 global.params.output_s = OUTPUTFLAGset; | |
776 autofound = true; | |
777 } else if (strcmp(ext, global.obj_ext) == 0) { | |
778 global.params.output_o = OUTPUTFLAGset; | |
779 autofound = true; | |
780 } else { | |
781 // append dot, so forceExt won't change existing name even if it contains dots | |
782 size_t len = strlen(global.params.objname); | |
783 size_t extlen = strlen("."); | |
784 char* s = (char *)alloca(len + 1 + extlen + 1); | |
785 memcpy(s, global.params.objname, len); | |
786 s[len] = '.'; | |
787 s[len+1+extlen] = 0; | |
788 global.params.objname = s; | |
789 | |
790 } | |
791 if(autofound && global.params.output_o == OUTPUTFLAGdefault) | |
792 global.params.output_o = OUTPUTFLAGno; | |
793 } | |
794 | |
795 // only link if possible | |
796 if (!global.params.obj || !global.params.output_o) | |
792 global.params.link = 0; | 797 global.params.link = 0; |
793 | 798 |
794 if (global.params.link) | 799 if (global.params.link) |
795 { | 800 { |
796 global.params.exefile = global.params.objname; | 801 global.params.exefile = global.params.objname; |
797 global.params.objname = NULL; | |
798 } | 802 } |
799 else if (global.params.run) | 803 else if (global.params.run) |
800 { | 804 { |
801 error("flags conflict with -run"); | 805 error("flags conflict with -run"); |
802 fatal(); | 806 fatal(); |