Mercurial > projects > ldc
diff 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 |
line wrap: on
line diff
--- a/dmd/mars.c Wed Oct 15 20:22:18 2008 +0200 +++ b/dmd/mars.c Thu Oct 16 22:07:02 2008 +0200 @@ -55,12 +55,9 @@ ll_ext = "ll"; bc_ext = "bc"; s_ext = "s"; + obj_ext = "o"; #if _WIN32 - obj_ext = "obj"; -#elif POSIX - obj_ext = "o"; -#else -#error "fix this" + obj_ext_alt = "obj"; #endif copyright = "Copyright (c) 1999-2008 by Digital Mars and Tomas Lindquist Olsen"; @@ -167,14 +164,12 @@ -op do not strip paths from source file\n\ -oq write object files with fully qualified names\n\ -of<filename> name output file to <filename>\n\ - extension of <filename> determines output type\n\ - no extension means native object or executable\n\ - if the extension is ll, bc, s, or o/obj, linking is disabled\n\ + if -c and extension of <filename> is known, it determines the output type\n\ \n\ -output-ll write LLVM IR\n\ -output-bc write LLVM bitcode\n\ -output-s write native assembly\n\ - -output-o write native object\n\ + -output-o write native object (default if no -output switch passed)\n\ \n\ -c do not link\n\ -L<linkerflag> pass <linkerflag> to linker\n\ @@ -298,7 +293,7 @@ global.params.Dversion = 2; global.params.quiet = 1; - global.params.output_o = 1; + global.params.output_o = OUTPUTFLAGdefault; global.params.linkswitches = new Array(); global.params.libfiles = new Array(); @@ -453,38 +448,6 @@ if (!p[3]) goto Lnoarg; global.params.objname = p + 3; - - // remove default output - if (global.params.output_ll == 1) - global.params.output_ll = 0; - if (global.params.output_bc == 1) - global.params.output_bc = 0; - if (global.params.output_s == 1) - global.params.output_s = 0; - if (global.params.output_o == 1) - global.params.output_o = 0; - - // determine output based on ext - ext = FileName::ext(global.params.objname); - if (!ext) { - global.params.link = 1; - global.params.output_o = 1; - } else if (strcmp(ext, global.ll_ext) == 0) { - global.params.output_ll = 1; - global.params.link = 0; - } else if (strcmp(ext, global.bc_ext) == 0) { - global.params.output_bc = 1; - global.params.link = 0; - } else if (strcmp(ext, global.s_ext) == 0) { - global.params.output_s = 1; - global.params.link = 0; - } else if (strcmp(ext, global.obj_ext) == 0) { - global.params.output_o = 1; - global.params.link = 0; - } else { - global.params.output_o = 1; - } - break; case 'p': @@ -502,16 +465,22 @@ case 'u': if (strncmp(p+1, "output-", 7) != 0) goto Lerror; + + // remove default output + if (global.params.output_o == OUTPUTFLAGdefault) + global.params.output_o = OUTPUTFLAGno; + if (strcmp(p+8, global.ll_ext) == 0) - global.params.output_ll = 2; + global.params.output_ll = OUTPUTFLAGset; else if (strcmp(p+8, global.bc_ext) == 0) - global.params.output_bc = 2; + global.params.output_bc = OUTPUTFLAGset; else if (strcmp(p+8, global.s_ext) == 0) - global.params.output_s = 2; + global.params.output_s = OUTPUTFLAGset; else if (strcmp(p+8, global.obj_ext) == 0) - global.params.output_o = 2; + global.params.output_o = OUTPUTFLAGset; else goto Lerror; + break; case 0: @@ -788,13 +757,48 @@ if (global.params.useUnitTests) global.params.useAssert = 1; - if (!global.params.obj) + // LDC output determination + + // if we don't link, autodetect target from extension + if(!global.params.link && global.params.objname) { + ext = FileName::ext(global.params.objname); + bool autofound = false; + if (!ext) { + // keep things as they are + } else if (strcmp(ext, global.ll_ext) == 0) { + global.params.output_ll = OUTPUTFLAGset; + autofound = true; + } else if (strcmp(ext, global.bc_ext) == 0) { + global.params.output_bc = OUTPUTFLAGset; + autofound = true; + } else if (strcmp(ext, global.s_ext) == 0) { + global.params.output_s = OUTPUTFLAGset; + autofound = true; + } else if (strcmp(ext, global.obj_ext) == 0) { + global.params.output_o = OUTPUTFLAGset; + autofound = true; + } else { + // append dot, so forceExt won't change existing name even if it contains dots + size_t len = strlen(global.params.objname); + size_t extlen = strlen("."); + char* s = (char *)alloca(len + 1 + extlen + 1); + memcpy(s, global.params.objname, len); + s[len] = '.'; + s[len+1+extlen] = 0; + global.params.objname = s; + + } + if(autofound && global.params.output_o == OUTPUTFLAGdefault) + global.params.output_o = OUTPUTFLAGno; + } + + // only link if possible + if (!global.params.obj || !global.params.output_o) global.params.link = 0; if (global.params.link) { global.params.exefile = global.params.objname; - global.params.objname = NULL; } else if (global.params.run) {