fix: pcmake output 后缀处理

- output = demo  -> demo.exe (自动追加 .exe)
- output = demo.exe -> demo.exe (不重复追加)
- output = demo.EXE -> demo.EXE (大小写不敏感)
- clean 命令同步修复
这个提交包含在:
Paze AI
2026-08-16 14:49:25 +08:00
父节点 cafa815116
当前提交 5162ce7419
+30 -17
查看文件
@@ -190,6 +190,29 @@ static int file_exists(const char *f) {
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
quoted paths with spaces correctly (system() misbehaves) */
static int run_command(const char *cmd) {
@@ -275,11 +298,7 @@ int main(int argc, char **argv) {
}
{
char outbuf[512];
strncpy(outbuf, g_output, sizeof outbuf - 1);
outbuf[sizeof outbuf - 1] = 0;
#ifdef _WIN32
strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1);
#endif
make_output_name(g_output, outbuf, sizeof outbuf);
printf(" rm %s\n", 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]);
{
char outbuf[512];
strncpy(outbuf, g_output, sizeof outbuf - 1);
outbuf[sizeof outbuf - 1] = 0;
#ifdef _WIN32
strncat(outbuf, ".exe", sizeof outbuf - strlen(outbuf) - 1);
#endif
make_output_name(g_output, outbuf, sizeof outbuf);
len += snprintf(cmd + len, sizeof cmd - len, " -o \"%s\"", outbuf);
}
printf(" link %s\n", g_output);
@@ -337,12 +352,10 @@ int main(int argc, char **argv) {
return 1;
}
printf("pcmake: build OK -> %s%s\n", g_output,
#ifdef _WIN32
".exe"
#else
""
#endif
);
{
char outbuf[512];
make_output_name(g_output, outbuf, sizeof outbuf);
printf("pcmake: build OK -> %s\n", outbuf);
}
return 0;
}