fix: pcmake output 后缀处理
- output = demo -> demo.exe (自动追加 .exe) - output = demo.exe -> demo.exe (不重复追加) - output = demo.EXE -> demo.EXE (大小写不敏感) - clean 命令同步修复
这个提交包含在:
+30
-17
@@ -190,6 +190,29 @@ static int file_exists(const char *f) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* build the output file name: append .exe on Windows only if
|
||||||
|
the configured name does not already end with .exe (case-insensitive) */
|
||||||
|
static int ends_with_exe(const char *s)
|
||||||
|
{
|
||||||
|
int n = (int)strlen(s);
|
||||||
|
if (n < 4) return 0;
|
||||||
|
s += n - 4;
|
||||||
|
return (tolower((unsigned char)s[1])=='e')
|
||||||
|
&& (tolower((unsigned char)s[2])=='x') && (tolower((unsigned char)s[3])=='e');
|
||||||
|
}
|
||||||
|
|
||||||
|
static void make_output_name(const char *in, char *out, int outsize)
|
||||||
|
{
|
||||||
|
int n = (int)strlen(in);
|
||||||
|
if (n >= outsize) n = outsize - 1;
|
||||||
|
memcpy(out, in, n);
|
||||||
|
out[n] = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (!ends_with_exe(out))
|
||||||
|
strncat(out, ".exe", outsize - n - 1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* run a command line; Windows uses CreateProcess to handle
|
/* run a command line; Windows uses CreateProcess to handle
|
||||||
quoted paths with spaces correctly (system() misbehaves) */
|
quoted paths with spaces correctly (system() misbehaves) */
|
||||||
static int run_command(const char *cmd) {
|
static int run_command(const char *cmd) {
|
||||||
@@ -275,11 +298,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
char outbuf[512];
|
char outbuf[512];
|
||||||
strncpy(outbuf, g_output, sizeof outbuf - 1);
|
make_output_name(g_output, outbuf, sizeof outbuf);
|
||||||
outbuf[sizeof outbuf - 1] = 0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1);
|
|
||||||
#endif
|
|
||||||
printf(" rm %s\n", outbuf);
|
printf(" rm %s\n", outbuf);
|
||||||
remove(outbuf);
|
remove(outbuf);
|
||||||
}
|
}
|
||||||
@@ -323,11 +342,7 @@ int main(int argc, char **argv) {
|
|||||||
len += snprintf(cmd + len, sizeof cmd - len, " -l%s", g_libs[i]);
|
len += snprintf(cmd + len, sizeof cmd - len, " -l%s", g_libs[i]);
|
||||||
{
|
{
|
||||||
char outbuf[512];
|
char outbuf[512];
|
||||||
strncpy(outbuf, g_output, sizeof outbuf - 1);
|
make_output_name(g_output, outbuf, sizeof outbuf);
|
||||||
outbuf[sizeof outbuf - 1] = 0;
|
|
||||||
#ifdef _WIN32
|
|
||||||
strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1);
|
|
||||||
#endif
|
|
||||||
len += snprintf(cmd + len, sizeof cmd - len, " -o \"%s\"", outbuf);
|
len += snprintf(cmd + len, sizeof cmd - len, " -o \"%s\"", outbuf);
|
||||||
}
|
}
|
||||||
printf(" link %s\n", g_output);
|
printf(" link %s\n", g_output);
|
||||||
@@ -337,12 +352,10 @@ int main(int argc, char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("pcmake: build OK -> %s%s\n", g_output,
|
{
|
||||||
#ifdef _WIN32
|
char outbuf[512];
|
||||||
".exe"
|
make_output_name(g_output, outbuf, sizeof outbuf);
|
||||||
#else
|
printf("pcmake: build OK -> %s\n", outbuf);
|
||||||
""
|
}
|
||||||
#endif
|
|
||||||
);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户