📄 cl-wrapper.c
字号:
/* cl-wrapper -- gcc-lookalike wrapper for the Microsoft C compiler * Copyright (C) 2001--2004 Tor Lillqvist * * This program accepts Unix-style C compiler command line arguments, * and runs the Microsoft C compiler (cl) with corresponding arguments. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <errno.h>#include <io.h>static char *cmdline;static const char *cmdline_compiler;static const char *cmdline_args;static const char **libraries;static const char **libdirs;static const char **objects;static const char *output_executable = NULL;static const char *output_object = NULL;static const char *executable_type = NULL;static const char *source = NULL;static const char *def_file = NULL;static int lib_ix = 0;static int libdir_ix = 0;static int object_ix = 0;static int compileonly = 0, debug = 0, output = 0, verbose = 0, version = 0;static int nsources = 0;static float cl_version;static FILE *force_header = NULL;#define DUMMY_C_FILE "__dummy__.c"#define INDIRECT_CMDLINE_FILE "__cl_wrapper.at"#define FORCE_HEADER "__force_header.h"static int MD_flag = 0;static int MP_flag = 0;static const char *MT_file = NULL;static const char *MF_file = NULL;/* cl warnings that should be errors */static const int error_warnings[] = { 4002, /* too many actual parameters for macro */ 4003, /* not enough actual parameters for macro */ 4020, /* too many actual parameters */ 4021, /* too few actual parameters */ 4045, /* array bounds overflow */ 0};/* cl warnings that should be disabled */static const int disable_warnings[] = { 4057, /* indirection to slightly different base types */ 4132, /* const object should be initialized */ 0};/* cl warnings that should be ignored even if the gcc -Wall option is * used, to make cl more gcc like */static const int ignore_warnings_with_Wall[] = { 4018, /* signed/unisgned mismatch */ 4100, /* unreferenced formal parameter */ 4127, /* conditional expression is constant */ 4152, /* nonstandard extension, function/data pointer conversion in expression */ 4505, /* unreferenced local function */ 4514, /* unreferenced inline function */ 0};/* gcc links with these by default */static const char *default_libs[] = { "gdi32", "comdlg32", "user32", "advapi32", "shell32", "oldnames", /* mingw has dirent functions in its mingwex library, silly */ "dirent", NULL};static const struct{ const char *gcc; const char *cl;} gcc_warnings[] = { { "traditional", "4001" }, { "unused-variable", "4101" }, { "unused-parameter", "4100" }, { "unused-label", "4102" }, { "unused-function", "4505" }, { "unused", "4101,4100,4102,4505" }, { NULL, NULL }}; static const char *backslashify (const char *string){ char *result = malloc (strlen (string) + 1); const char *p = string; char *q = result; while (*p) { if (*p == '/') *q = '\\'; else *q = *p; p++; q++; } *q = '\0'; return result;}static const char *quote (const char *string){ char *result = malloc (strlen (string) * 2 + 1); const char *p = string; char *q = result; while (*p) { if (*p == '"') *q++ = '\\'; *q++ = *p; p++; } *q = '\0'; return result;}static voidopen_force_header (void){ if (force_header != NULL) return; force_header = fopen (FORCE_HEADER, "wt"); if (force_header == NULL) { fprintf (stderr, "Could not open temporary file " FORCE_HEADER " for writing: %s\n", strerror (errno)); exit (1); }}static voidprocess_argv (int argc, const char **argv){ int i, k; const char *lastdot; for (i = 1; i < argc; i++) if (strcmp (argv[i], "-c") == 0) { compileonly++; strcat (cmdline, " -c"); } else if (strncmp (argv[i], "-D", 2) == 0) { strcat (cmdline, " "); strcat (cmdline, quote (argv[i])); if (strlen (argv[i]) == 2) { i++; strcat (cmdline, quote (argv[i])); } } else if (strncmp (argv[i], "-U", 2) == 0) { strcat (cmdline, " "); strcat (cmdline, argv[i]); } else if (strcmp (argv[i], "-E") == 0) strcat (cmdline, " -E"); else if (strcmp (argv[i], "-g") == 0) debug++; else if (strncmp (argv[i], "-I", 2) == 0) { strcat (cmdline, " -I "); if (strlen (argv[i]) > 2) { strcat (cmdline, quote (backslashify (argv[i] + 2))); } else { i++; strcat (cmdline, quote (backslashify (argv[i]))); } } else if (strcmp (argv[i], "-idirafter") == 0) { const char *include = getenv ("INCLUDE"); const char *afterdir = backslashify (argv[i+1]); char *newinclude; if (!include) include = ""; newinclude = malloc (strlen (include) + strlen (afterdir) + 20); strcat (newinclude, "INCLUDE="); if (*include) { strcat (newinclude, include); strcat (newinclude, ";"); } strcat (newinclude, afterdir); _putenv (newinclude); i++; } else if (strcmp (argv[i], "-MT") == 0) { i++; MT_file = argv[i]; } else if (strcmp (argv[i], "-MD") == 0) MD_flag++; else if (strcmp (argv[i], "-MP") == 0) MP_flag++; else if (strcmp (argv[i], "-MF") == 0) { i++; MF_file = argv[i]; } else if (strncmp (argv[i], "-l", 2) == 0) { /* Ignore -lm */ if (strcmp (argv[i], "-lm") != 0) libraries[lib_ix++] = argv[i] + 2; } else if (strncmp (argv[i], "-L", 2) == 0) { if (strlen (argv[i]) > 2) { libdirs[libdir_ix++] = backslashify (argv[i] + 2); } else { i++; libdirs[libdir_ix++] = backslashify (argv[i]); } } else if (strcmp (argv[i], "-shared") == 0) ; /* See -LD below */ else if (strcmp (argv[i], "-o") == 0) { if (output) { fprintf (stderr, "Multiple -o options\n"); exit (1); } output = 1; i++; lastdot = strrchr (argv[i], '.'); if (lastdot != NULL && (stricmp (lastdot, ".exe") == 0 || stricmp (lastdot, ".dll") == 0)) { strcat (cmdline, " -Fe"); strcat (cmdline, backslashify (argv[i])); output_executable = argv[i]; executable_type = strrchr (output_executable, '.'); } else if (lastdot != NULL && (strcmp (lastdot, ".obj") == 0 || strcmp (lastdot, ".o") == 0 )) { strcat (cmdline, " -Fo"); output_object = argv[i]; strcat (cmdline, backslashify (argv[i])); } else { strcat (cmdline, " -Fe"); strcat (cmdline, argv[i]); if (lastdot == NULL || strcmp (lastdot, ".exe") != 0) strcat (cmdline, ".exe"); } } else if (strncmp (argv[i], "-O", 2) == 0) strcat (cmdline, " -O2"); else if (strncmp (argv[i], "-mcpu=", 6) == 0) { const char *cpu = argv[i]+6; if (strcmp (cpu, "i386") == 0) strcat (cmdline, " -G3"); else if (strcmp (cpu, "i486") == 0) strcat (cmdline, " -G4"); else if (strcmp (cpu, "i586") == 0 || strcmp (cpu, "pentium") == 0) strcat (cmdline, " -G5");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -