# # Generalized C/C++ interface for Microsoft C/C++ # # rcsid = $Header: /cvs/xtest/xtest/src/tet3/compiler.ccg,v 1.1 2005-10-31 23:09:07 jamey Exp $ # # SCCS: @(#)compiler.ccg 1.3 (98/09/01) TETware release 3.3 # # this version used when compiling TETware on Windows NT # Andrew Dingwall, UniSoft Ltd., October 1996 # # MODIFICATIONS: # # Andrew Dingwall, UniSoft Ltd., July 1998 # Added support for building DLLs. # Commented out the -link option - it wasn't implemented! # # CL option prefixes: these are passed through to compiler Copts = { "-C", "-d", "-D", "-F", "-G", "-H", "-I", "-J", "-O", "-U", "-u", "-V", "-W", "-Z" }; Copts_compile_only = { "-E", "-P" }; coptions = { "-nologo" }; map = 0; val = 0; dll = 0; Libc = "libc.lib"; Libs = {}; Srcs = {}; Objs = {}; Output = ""; for (i in ARGV) do flag = substr(i,1,2); if (i == "-c") compile_only = 1; elif (i == "-S") # assembler listing coptions |= "/Fa"; compile_only = 1; elif (substr(i,-2) == ".c") Srcs |= i; opath = filepath(substr(i,1,length(i)-1)); Objs |= opath[length(opath)-1] | "obj "; elif (substr(i,-4) == ".asm") Srcs |= i; opath = filepath(substr(i,1,length(i)-3)); Objs |= opath[length(opath)-1] | "obj "; elif (substr(i,-4) == ".cpp") Srcs |= i; opath = filepath(substr(i,1,length(i)-3)); Objs |= opath[length(opath)-1] | "obj "; elif (substr(i,-4) == ".obj") Objs |= i | " "; elif (i == "-o") advance i; Output = i; elif (substr(i,1,3) == "-Fe") # support -Fe Output = substr(i,4); elif (index(Copts, flag) != 0) coptions |= i; elif (index(Copts_compile_only, flag) != 0) coptions |= i; compile_only = 1; elif (i == "-M") map = 1; # elif (substr(i,1,5) == "-link") # LinkOptions |= " " | i; elif (substr(i,-4) == ".lib") Libs |= i | " "; elif (i == "-v") verbose = 1; elif (i == "-ML") coptions |= i; elif (i == "-MT") coptions |= i; Libc = "libcmt.lib"; elif (i == "-MD") coptions |= i; Libc = "msvcrt.lib"; elif (i == "-MLd") coptions |= i; Libc = "libcd.lib"; elif (i == "-MTd") coptions |= i; Libc = "libcmtd.lib"; elif (i == "-MDd") coptions |= i; Libc = "msvcrtd.lib"; elif (i == "-LD") dll = 1; coptions |= "-MD"; Libc = "msvcrt.lib"; elif (i == "-LDd") dll = 1; coptions |= "-MDd"; Libc = "msvcrtd.lib"; elif (substr(i,1,1) == "-") println "Unknown option:", i, "(ignored)"; else println "Unknown", i, "(ignored)"; fi done if (! Objs) print "No source or object files!\n"; exit 1; fi if (Output == "") Output = Objs[0]; if (dll) Output = substr(Output, 1, rindex(Output,".")) | "lib"; else Output = substr(Output, 1, rindex(Output,".")) | "exe"; fi fi # compile all .c files for (i in Srcs) do if (verbose) print "cl ", "-c "; for (j in coptions) do print j, " "; done print i, "\n\n"; fi val = execv("cl", "-c", coptions, i); if (val) exit val; fi done if (compile_only) exit val; fi ldoptions = "-nologo"; if (dll) ldoptions |= " -dll -implib:" | replace(Output, "/", "\\"); Output = substr(Output, 1, rindex(Output,".")) | "dll"; else ldoptions |= " -align:0x1000 -subsystem:console -entry:mainCRTStartup"; fi ldoptions |= " -out:" | replace(Output, "/", "\\"); if (map) ldoptions |= " -map"; fi Libs |= Libc | " kernel32.lib"; ldfiles = ""; for (i in Objs) do ldfiles |= " " | replace(i, "/", "\\"); done for (i in Libs) do ldfiles |= " " | replace(i, "/", "\\"); done if (verbose) println "link " | ldoptions | ldfiles, "\n"; fi exit exec("link " | ldoptions | ldfiles);