📄 make.c
字号:
return CompileFile(l, list);
else if (!xstricmpz(ext, ".asm"))
return AssembleFile(l, list);
else if (!xstricmpz(ext, ".rc"))
return RCFile(l, list);
else
return !exists(list->output);
}
//-------------------------------------------------------------------------
void ReplaceWildcards(PROJLIST *l, char *buf, char *steps)
{
while (*steps)
{
if (*steps == '$' && *(steps + 1) == '(')
{
int skip = 0;
char data[MAX_PATH];
data[0] = 0;
if (!strncmp(steps + 2, "OUTPUTDIR", 9))
{
skip = 12;
if (l->outputPath[0])
strcpy(data, l->outputPath);
else
{
char *p;
strcpy(data, szProjectName);
p = strrchr(data, '\\');
if (p)
{
if (p[ - 1] == ':')
p[1] = 0;
else
p[0] = 0;
}
}
}
else if (!strncmp(steps + 2, "INSTALLDIR", 10))
{
skip = 13;
strcpy(data, szInstallPath);
}
else if (!strncmp(steps + 2, "SYSTEMDIR", 9))
{
skip = 12;
GetSystemDirectory(data, MAX_PATH);
}
else if (!strncmp(steps + 2, "WINDIR", 6))
{
skip = 9;
GetWindowsDirectory(data, MAX_PATH);
}
else if (!strncmp(steps + 2, "PROJECTDIR", 10))
{
char *p;
skip = 13;
strcpy(data, szProjectName);
p = strrchr(data, '\\');
if (p)
if (p[ - 1] == ':')
p[1] = 0;
else
p[0] = 0;
}
else
{
char *n = strchr(steps, ')');
if (n)
{
int len = n - steps - 2;
strncpy(data, steps + 2, len);
data[len] = 0;
n = getenv(data);
if (n)
{
strcpy(data, n);
skip = len + 3;
}
}
}
if (!skip || steps[skip - 1] != ')')
*buf++ = *steps++;
else
{
*buf++ = '"';
strcpy(buf, data);
buf += strlen(buf);
steps += skip;
while (*steps && (isalnum(*steps) || *steps == '\\' || *steps
== '.'))
*buf++ = *steps++;
*buf++ = '"';
}
}
else
{
*buf++ = *steps++;
}
}
*buf = 0;
}
//-------------------------------------------------------------------------
int PrePost(PROJLIST *l, char *tag, char *label, char *steps)
{
char buf[1024];
char buf1[1024];
if (steps[0])
{
CompileMessage(tag, label);
while (1)
{
char *p = buf;
while (*steps && *steps != '\n')
if (*steps == '\r')
steps++;
else
*p++ = *steps++;
*p = 0;
ReplaceWildcards(l, buf1, buf);
if (Execute(0, buf1, ERR_BUILD_WINDOW))
{
CompileMessage(tag, "Error processing");
errcount++;
return TRUE;
}
if (! *steps)
break;
else
steps++;
}
}
return FALSE;
}
//-------------------------------------------------------------------------
void ErrWarnCounts()
{
char buf[256];
sprintf(buf, "\r\nCompile done. Errors: %d, Warnings: %d\r\n", errcount,
warncount);
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)buf);
}
//-------------------------------------------------------------------------
int MakerThread(int type)
{
PROJLIST *l = projectList;
int rv;
int globalerr = FALSE;
IsMaking(TRUE);
CreateTempFileName();
errcount = warncount = 0;
SendMessage(hwndError, WM_SELERRWINDOW, 0, ERR_BUILD_WINDOW);
dmgrHideWindow(DID_ERRORWND, FALSE);
SendMessage(hwndClient, WM_MDIACTIVATE, (WPARAM)hwndError, 0);
if (!l || !l->files)
{
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)
"Create a project and add targets before building");
if (!l)
ExtendedMessageBox("Build Error", MB_SETFOREGROUND | MB_SYSTEMMODAL,
"Before you can compile your files you need to create a project and add targets and source files");
else
ExtendedMessageBox("Build Error", MB_SETFOREGROUND | MB_SYSTEMMODAL,
"Before you can compile your files you need to add source files to the project");
IsMaking(FALSE);
return 0 ;
}
SaveDrawAll();
markProjects(0);
rv = CalcRebuilds();
if (type == IDM_BUILDALL)
markProjects(1);
else if (!rv)
{
CompileMessage("Project is up to date", "");
IsMaking(FALSE);
return 0;
}
if (uState != notDebugging)
{
if (ExtendedMessageBox("Build Alert", MB_YESNO,
"Project Build requires the debugger be stopped. Stop the debugger now?") != IDYES)
{
browsing = FALSE;
IsMaking(FALSE);
return 0;
}
abortDebugThread();
}
TagLinesAdjust(0, TAGM_UPDATEDEBUG);
stopBuild = FALSE;
while (l && !stopBuild)
{
if (l->rebuild)
{
FILELIST *m = l->files;
int dont = PrePost(l, "Pre Build: ", l->prebuildlabel, l
->prebuildsteps);
CalcRebuilds();
if (!dont && !stopBuild)
{
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)
"Compiling...\r\n");
while (m && !stopBuild)
{
if (m->rebuild)
{
dont |= buildFile(l, m);
m->rebuild = FALSE;
}
m = m->next;
}
if (!dont && !stopBuild)
{
if (l->buildType == BT_LIBRARY)
dont |= libFile(l);
else
{
dont |= linkFile(l);
}
if (!dont)
dont = PrePost(l, "Post Build: ", l->postbuildlabel, l
->postbuildsteps);
}
}
if (!dont && !stopBuild)
l->buildFlags &= ~BF_CHANGEDTARGET;
globalerr |= dont;
}
l = l->next;
}
if (stopBuild)
{
SendMessage(hwndError, WM_SETTEXT, ERR_BUILD_WINDOW, (LPARAM)
"Build Process Aborted\r\n");
}
else
{
ErrWarnCounts();
if (!errcount && browseInfo)
{
FreeBrowseInfo();
browseFile(projectList);
}
}
CheckEditWindowChanged();
MessageBeep(MB_OK);
if (browsing)
{
if (errcount)
browsing = FALSE;
else
PostMessage(hwndFrame, WM_COMMAND, IDM_BROWSE, 0);
}
IsMaking(FALSE);
return errcount;
}
//-------------------------------------------------------------------------
static PROJLIST *compilerProjlist;
static int compilerSel;
void CompilerThread(void)
{
HWND win;
FILELIST *m = compilerProjlist->files;
IsMaking(TRUE);
CreateTempFileName();
errcount = warncount = 0;
if (uState != notDebugging)
{
if (ExtendedMessageBox("Compile Alert", MB_YESNO,
"Compile requires the debugger be stopped. Stop the debugger now?")
!= IDYES)
{
IsMaking(FALSE);
return ;
}
abortDebugThread();
}
if (IsWindow(win = (HWND)SendMessage(hwndClient, WM_MDIGETACTIVE, 0, 0)) &&
!IsSpecialWindow(win))
{
DWINFO *ptr = (DWINFO*)GetWindowLong(win, 0);
if (SendMessage(ptr->dwHandle, EM_GETMODIFY, 0, 0))
SendMessage(win, WM_COMMAND, IDM_SAVE, 0);
}
SendMessage(hwndError, WM_SELERRWINDOW, 0, ERR_BUILD_WINDOW);
dmgrHideWindow(DID_ERRORWND, FALSE);
SendMessage(hwndClient, WM_MDIACTIVATE, (WPARAM)hwndError, 0);
while (--compilerSel)
if (m)
m = m->next;
OutputFile(compilerProjlist, m, 0);
buildFile(compilerProjlist, m);
ErrWarnCounts();
MessageBeep(MB_OK);
IsMaking(FALSE);
}
//-------------------------------------------------------------------------
void Maker(int wParam)
{
DWORD threadhand;
if (wParam == IDM_STOPBUILD)
stopBuild = TRUE;
else
CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)MakerThread,
(LPVOID)wParam, 0, &threadhand));
}
//-------------------------------------------------------------------------
void Compiler(PROJLIST *l, int sel)
{
DWORD threadhand;
compilerProjlist = l;
compilerSel = sel;
CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)CompilerThread, 0, 0,
&threadhand));
}
//-------------------------------------------------------------------------
int RebuildMessage(void)
{
return ExtendedMessageBox("Rebuild?", MB_YESNO,
"Project needs to be rebuilt,\n rebuild project before debugging?") ==
IDYES;
#ifdef XXXXX
static char *header = "The following files need to be rebuilt:\n\n";
static char *trailer = "\n\n rebuild project before debugging?";
int rv;
char *buf, *p;
int size = 0, count = 0;
PROJLIST *l = projectList;
while (l)
{
FILELIST *m = l->files;
while (m)
{
DEPENDSLIST *n = m->depends;
while (n)
{
if (n->rebuild)
{
size += strlen(n->title);
count++;
}
n = n->next;
}
if (m->rebuild)
{
size += strlen(m->title);
count++;
}
m = m->next;
}
l = l->next;
}
if (!count)
size += count + 1+strlen(header) + strlen(trailer);
buf = malloc(size);
if (!buf)
return ExtendedMessageBox("Rebuild?", MB_YESNO,
"Project needs to be rebuilt,\n rebuild project before debugging?") == IDYES;
l = projectList;
strcpy(buf, header);
p = buf + strlen(buf);
while (l)
{
FILELIST *m = l->files;
while (m)
{
DEPENDSLIST *n = m->depends;
while (n)
{
if (n->rebuild)
{
sprintf(p, "%s\n", n->title);
p += strlen(p);
}
n = n->next;
}
m = m->next;
}
l = l->next;
}
l = projectList;
while (l)
{
FILELIST *m = l->files;
while (m)
{
if (m->rebuild)
{
sprintf(p, "%s\n", m->title);
p += strlen(p);
}
m = m->next;
}
l = l->next;
}
strcat(p, trailer);
rv = MessageBox(0, buf, "Rebuild?", MB_YESNO) == IDYES;
free(buf);
return rv;
#endif
}
//-------------------------------------------------------------------------
void dbgRebuildMainThread(int wParam)
{
PROJLIST *plist;
int i;
plist = ProjectFindSelectedEXE();
if (!plist)
{
ExtendedMessageBox("Debug error", MB_SETFOREGROUND | MB_SYSTEMMODAL,
"Please select a target in the project window");
}
else
{
if (xstricmp(plist->name + strlen(plist->name) - 4, ".exe"))
ExtendedMessageBox("Debug error", MB_SETFOREGROUND | MB_SYSTEMMODAL,
"Selected target is not an EXE file");
else
{
int rebuild = FALSE;
markProjects(0);
if (CalcRebuilds() || AnyModified())
{
if (RebuildMessage())
{
if (MakerThread(IDM_MAKE))
return ;
}
}
else if (plist->buildFlags &BF_CHANGEDTARGET)
{
if (ExtendedMessageBox("Rebuild?", MB_YESNO,
"Target settings have changed,\n rebuild project before debugging?") == IDYES)
{
if (MakerThread(IDM_BUILDALL))
return ;
}
}
initiateDebug(plist);
if ((wParam &0xffff) != IDM_STARTSTOP)
{
i = SendMessage(hwndToolDebug, TB_GETSTATE, IDM_STARTSTOP, 0);
SendMessage(hwndToolDebug, TB_SETSTATE, IDM_STARTSTOP, MAKELONG
(TBSTATE_CHECKED | i, 0));
}
return ;
}
}
i = SendMessage(hwndToolDebug, TB_GETSTATE, IDM_STARTSTOP, 0);
SendMessage(hwndToolDebug, TB_SETSTATE, IDM_STARTSTOP, MAKELONG
(~TBSTATE_CHECKED &i, 0));
}
//-------------------------------------------------------------------------
void dbgRebuildMain(int wParam)
{
DWORD threadhand;
if (wParam == IDM_STOPBUILD)
stopBuild = TRUE;
else
CloseHandle(CreateThread(0, 0, (LPTHREAD_START_ROUTINE)
dbgRebuildMainThread, (LPVOID)wParam, 0, &threadhand));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -