Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Support converting -out <path> into -out:<path> for link.exe

This requires modifying the arguments used even if just calling
one single command (instead of just calling the original argv+1).
  • Loading branch information...
commit 85df146e6ddf9f1a85f1b46122ac704db75423cf 1 parent e8aeeba
Martin Storsjö authored August 28, 2012

Showing 1 changed file with 30 additions and 11 deletions. Show diff stats Hide diff stats

  1. 41  compilewrap.c
41  compilewrap.c
@@ -55,8 +55,8 @@ static char* create_cmdline(char **argv)
55 55
 
56 56
 int main(int argc, char* argv[])
57 57
 {
58  
-    int i, cpp_argc, cc_argc;
59  
-    char **cpp_argv, **cc_argv;
  58
+    int i, cpp_argc, cc_argc, pass_argc;
  59
+    char **cpp_argv, **cc_argv, **pass_argv;
60 60
     int exit_code;
61 61
     int input_source = 0, input_obj = 0, flag_compile = 0;
62 62
     int msvc = 0;
@@ -74,7 +74,8 @@ int main(int argc, char* argv[])
74 74
 
75 75
     cpp_argv = malloc((argc + 2) * sizeof(*cpp_argv));
76 76
     cc_argv = malloc((argc + 3) * sizeof(*cc_argv));
77  
-    cpp_argc = cc_argc = 0;
  77
+    pass_argv = malloc((argc + 3) * sizeof(*pass_argv));
  78
+    cpp_argc = cc_argc = pass_argc = 0;
78 79
     for (i = 1; i < argc; ) {
79 80
         int len = strlen(argv[i]);
80 81
         int ext_inputfile = 0;
@@ -89,24 +90,31 @@ int main(int argc, char* argv[])
89 90
                 input_obj = 1;
90 91
             }
91 92
         }
92  
-        if (!strncmp(argv[i], "-Fo", 3) || !strcmp(argv[i], "-o")) {
  93
+        if (!strncmp(argv[i], "-Fo", 3) || !strcmp(argv[i], "-out") || !strcmp(argv[i], "-o")) {
93 94
             // Copy the output filename only to cc
94  
-            if (!strcmp(argv[i], "-Fo") && i + 1 < argc) {
95  
-                /* Support the nonstandard syntax -Fo filename, to get around
  95
+            if ((!strcmp(argv[i], "-Fo") || !strcmp(argv[i], "-out")) && i + 1 < argc) {
  96
+                /* Support the nonstandard syntax -Fo filename or -out filename, to get around
96 97
                  * msys file name mangling issues. */
97  
-                sprintf(fo_buffer, "-Fo%s", argv[i + 1]);
  98
+                if (!strcmp(argv[i], "-out"))
  99
+                    sprintf(fo_buffer, "-out:%s", argv[i + 1]);
  100
+                else
  101
+                    sprintf(fo_buffer, "%s%s", argv[i], argv[i + 1]);
98 102
                 outname = argv[i + 1];
99 103
                 cc_argv[cc_argc++] = fo_buffer;
  104
+                pass_argv[pass_argc++] = fo_buffer;
100 105
                 i += 2;
101 106
             } else if (!strncmp(argv[i], "-Fo", 3)) {
102 107
                 cc_argv[cc_argc++] = argv[i];
  108
+                pass_argv[pass_argc++] = argv[i];
103 109
                 outname = argv[i] + 3;
104 110
                 i++;
105 111
             } else {
106 112
                 /* -o */
107 113
                 cc_argv[cc_argc++] = argv[i++];
  114
+                pass_argv[pass_argc++] = argv[i];
108 115
                 if (i < argc) {
109 116
                     outname = argv[i];
  117
+                    pass_argv[pass_argc++] = argv[i];
110 118
                     cc_argv[cc_argc++] = argv[i++];
111 119
                 }
112 120
             }
@@ -124,6 +132,7 @@ int main(int argc, char* argv[])
124 132
             }
125 133
         } else if (!strcmp(argv[i], "-c")) {
126 134
             // Copy the compile flag only to cc, set the preprocess flag for cpp
  135
+            pass_argv[pass_argc++] = argv[i];
127 136
             cc_argv[cc_argc++] = argv[i++];
128 137
             if (msvc)
129 138
                 cpp_argv[cpp_argc++] = "/P";
@@ -132,36 +141,45 @@ int main(int argc, char* argv[])
132 141
             flag_compile = 1;
133 142
         } else if (ext_inputfile) {
134 143
             // Input filename, pass to cpp only, set the temp file input to cc
  144
+            pass_argv[pass_argc++] = argv[i];
135 145
             cpp_argv[cpp_argc++] = argv[i++];
136 146
             cc_argv[cc_argc++] = temp_file_2;
137 147
         } else if (!strcmp(argv[i], "-MMD")) {
138 148
             // Preprocessor-only parameter
  149
+            pass_argv[pass_argc++] = argv[i];
139 150
             cpp_argv[cpp_argc++] = argv[i++];
140 151
         } else if (!strcmp(argv[i], "-MF") || !strcmp(argv[i], "-MT")) {
141 152
             // Deps generation, pass to cpp only
  153
+            pass_argv[pass_argc++] = argv[i];
142 154
             cpp_argv[cpp_argc++] = argv[i++];
143  
-            if (i < argc)
  155
+            if (i < argc) {
  156
+                pass_argv[pass_argc++] = argv[i];
144 157
                 cpp_argv[cpp_argc++] = argv[i++];
  158
+            }
145 159
         } else if (!strncmp(argv[i], "-FI", 3)) {
146 160
             // Forced include, pass to cpp only
  161
+            pass_argv[pass_argc++] = argv[i];
147 162
             cpp_argv[cpp_argc++] = argv[i++];
148 163
         } else {
149 164
             // Normal parameter, copy to both cc and cpp
  165
+            pass_argv[pass_argc++] = argv[i];
150 166
             cc_argv[cc_argc++]   = argv[i];
151 167
             cpp_argv[cpp_argc++] = argv[i];
152 168
             i++;
153 169
         }
154 170
     }
155 171
 
  172
+    cpp_argv[cpp_argc++] = NULL;
  173
+    cc_argv[cc_argc++] = NULL;
  174
+    pass_argv[pass_argc++] = NULL;
  175
+
156 176
     if (!flag_compile || !source_file || !outname) {
157 177
         /* Doesn't seem like we should be invoked, just call the parameters as such */
158  
-        cmdline = create_cmdline(&argv[1]);
  178
+        cmdline = create_cmdline(pass_argv);
159 179
         exit_code = system(cmdline);
160 180
         goto exit;
161 181
     }
162 182
 
163  
-    cpp_argv[cpp_argc++] = NULL;
164  
-    cc_argv[cc_argc++] = NULL;
165 183
     cmdline = create_cmdline(cpp_argv);
166 184
     exit_code = system(cmdline);
167 185
     if (exit_code) {
@@ -193,5 +211,6 @@ int main(int argc, char* argv[])
193 211
     free(cmdline);
194 212
     free(cc_argv);
195 213
     free(cpp_argv);
  214
+    free(pass_argv);
196 215
     return exit_code ? 1 : 0;
197 216
 }

0 notes on commit 85df146

Please sign in to comment.
Something went wrong with that request. Please try again.