Changeset 3653 in kBuild
- Timestamp:
- Nov 4, 2024 12:22:49 AM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/main.c
r3481 r3653 1418 1418 1419 1419 /* bird: */ 1420 # ifdef CONFIG_NEW_WIN32_CTRL_EVENT1421 # include <process.h>1420 # ifdef CONFIG_NEW_WIN32_CTRL_EVENT 1421 # include <process.h> 1422 1422 static UINT g_tidMainThread = 0; 1423 1423 static int volatile g_sigPending = 0; /* lazy bird */ 1424 # ifndef _M_IX861424 # ifndef _M_IX86 1425 1425 static LONG volatile g_lTriggered = 0; 1426 1426 static CONTEXT g_Ctx; 1427 # endif1428 1429 # ifdef _M_IX861427 # endif 1428 1429 # ifdef _M_IX86 1430 1430 static __declspec(naked) void dispatch_stub(void) 1431 1431 { … … 1444 1444 } 1445 1445 } 1446 # else /* !_M_IX86 */1446 # else /* !_M_IX86 */ 1447 1447 static void dispatch_stub(void) 1448 1448 { … … 1456 1456 exit(131); 1457 1457 } 1458 # endif /* !_M_IX86 */1458 # endif /* !_M_IX86 */ 1459 1459 1460 1460 static BOOL WINAPI ctrl_event(DWORD CtrlType) … … 1465 1465 1466 1466 /*fprintf(stderr, "dbg: ctrl_event sig=%d\n", sig);*/ 1467 # ifndef _M_IX861467 # ifndef _M_IX86 1468 1468 /* only once. */ 1469 1469 if (InterlockedExchange(&g_lTriggered, 1)) … … 1472 1472 return TRUE; 1473 1473 } 1474 # endif1474 # endif 1475 1475 1476 1476 /* open the main thread and suspend it. */ … … 1484 1484 Ctx.ContextFlags = CONTEXT_FULL; 1485 1485 if (GetThreadContext(hThread, &Ctx) 1486 # ifdef _M_IX861486 # ifdef _M_IX86 1487 1487 && Ctx.Esp >= 0x1000 1488 # else1488 # else 1489 1489 && Ctx.Rsp >= 0x1000 1490 # endif1490 # endif 1491 1491 ) 1492 1492 { 1493 # ifdef _M_IX861493 # ifdef _M_IX86 1494 1494 ((uintptr_t *)Ctx.Esp)[-1] = Ctx.Eip; 1495 1495 Ctx.Esp -= sizeof(uintptr_t); 1496 1496 Ctx.Eip = (uintptr_t)&dispatch_stub; 1497 # else1497 # else 1498 1498 g_Ctx = Ctx; 1499 1499 Ctx.Rsp -= 0x80; … … 1501 1501 Ctx.Rsp += 8; /* (Stack aligned before call instruction, not after.) */ 1502 1502 Ctx.Rip = (uintptr_t)&dispatch_stub; 1503 # endif1503 # endif 1504 1504 1505 1505 SetThreadContext(hThread, &Ctx); … … 1520 1520 return TRUE; 1521 1521 } 1522 # endif /* CONFIG_NEW_WIN32_CTRL_EVENT */1522 # endif /* CONFIG_NEW_WIN32_CTRL_EVENT */ 1523 1523 1524 1524 #endif /* WINDOWS32 */ … … 2408 2408 2409 2409 #ifdef KMK 2410 /* Check for [Mm]akefile.kup and change directory when found. 2411 Makefile.kmk overrides Makefile.kup but not plain Makefile. 2410 /* If no [Mm]akefile.kmk in the current directory, we may want to ascend to a 2411 parent directory that contains one. This is explicitly ordered by placing 2412 [Mm]akefile.kup files in the directory. And since 2024-11-04 we 2413 automatically do this when here is a goal (e.g. main.o) on the command 2414 line and no other default makefiles around. This new behvior simplifies 2415 compiling individial source files from the editor without requiring us to 2416 sprinkle Makefile.kup-files around the tree, esp. in 3rd party code. 2417 2412 2418 If no -C arguments were given, fake one to indicate chdir. */ 2413 2419 if (makefiles == 0) 2414 2420 { 2415 2421 struct stat st; 2416 if (( ( stat ("Makefile.kup", &st) == 0 2417 && S_ISREG (st.st_mode) ) 2418 || ( stat ("makefile.kup", &st) == 0 2419 && S_ISREG (st.st_mode) ) ) 2420 && stat ("Makefile.kmk", &st) < 0 2422 if (stat ("Makefile.kmk", &st) < 0 2421 2423 && stat ("makefile.kmk", &st) < 0) 2422 2424 { … … 2424 2426 char *cur = &fake_path[2]; 2425 2427 int up_levels = 1; 2426 while (up_levels < 16) 2428 2429 /* If there are any .kup-files. */ 2430 if (( stat ("Makefile.kup", &st) == 0 2431 && S_ISREG (st.st_mode) ) 2432 || ( stat ("makefile.kup", &st) == 0 2433 && S_ISREG (st.st_mode) ) ) 2427 2434 { 2428 /* File with higher precedence.s */ 2429 strcpy (cur, "/Makefile.kmk"); 2430 if (stat (fake_path, &st) == 0) 2431 break; 2432 strcpy (cur, "/makefile.kmk"); 2433 if (stat (fake_path, &st) == 0) 2434 break; 2435 2436 /* the .kup files */ 2437 strcpy (cur, "/Makefile.kup"); 2438 if ( stat (fake_path, &st) != 0 2439 || !S_ISREG (st.st_mode)) 2435 while (up_levels < 16) 2440 2436 { 2441 strcpy (cur, "/makefile.kup"); 2437 /* File with higher precedence. */ 2438 strcpy (cur, "/Makefile.kmk"); 2439 if (stat (fake_path, &st) == 0) 2440 break; 2441 cur[1] = 'm'; 2442 if (stat (fake_path, &st) == 0) 2443 break; 2444 2445 /* the .kup files */ 2446 strcpy (cur, "/Makefile.kup"); 2442 2447 if ( stat (fake_path, &st) != 0 2443 2448 || !S_ISREG (st.st_mode)) 2444 break; 2449 { 2450 cur[1] = 'm'; 2451 if ( stat (fake_path, &st) != 0 2452 || !S_ISREG (st.st_mode)) 2453 break; 2454 } 2455 2456 /* ok */ 2457 strcpy (cur, "/.."); 2458 cur += 3; 2459 up_levels++; 2445 2460 } 2446 2447 /* ok */ 2448 strcpy (cur, "/.."); 2449 cur += 3; 2450 up_levels++; 2461 if (up_levels >= 16) 2462 O (fatal, NILF, _("Makefile.kup recursion is too deep.")); 2451 2463 } 2452 2453 if (up_levels >= 16) 2454 O (fatal, NILF, _("Makefile.kup recursion is too deep.")); 2455 2456 /* attempt to change to the directory. */ 2457 *cur = '\0'; 2458 if (chdir (fake_path) < 0) 2459 pfatal_with_name (fake_path); 2460 2461 /* add the string to the directories. */ 2462 if (!directories) 2464 /* If there are no default makefiles either and one or more goals on 2465 the command line, go looking for kmk-files up the parent tree. */ 2466 else if (goals != NULL 2467 && stat ("GNUmakefile", &st) < 0 2468 && stat ("makefile", &st) < 0 2469 && stat ("Makefile", &st) < 0 2470 #ifdef WINDOWS32 2471 && stat ("makefile.mak", &st) < 0 2472 #endif 2473 ) 2474 while (up_levels < 16) 2475 { 2476 /* File with higher precedence.s */ 2477 strcpy (cur, "/Makefile.kmk"); 2478 if (stat (fake_path, &st) == 0) 2479 break; 2480 cur[1] = 'm'; 2481 if (stat (fake_path, &st) == 0) 2482 break; 2483 2484 /* ok */ 2485 strcpy (cur, "/.."); 2486 cur += 3; 2487 up_levels++; 2488 } 2489 else 2490 up_levels = 0; 2491 if (up_levels > 0 && up_levels < 16) 2463 2492 { 2464 directories = xmalloc (sizeof(*directories)); 2465 directories->list = xmalloc (5 * sizeof (char *)); 2466 directories->max = 5; 2467 directories->idx = 0; 2493 /* attempt to change to the directory. */ 2494 *cur = '\0'; 2495 if (chdir (fake_path) < 0) 2496 pfatal_with_name (fake_path); 2497 2498 /* add the string to the directories. */ 2499 if (!directories) 2500 { 2501 directories = xmalloc (sizeof(*directories)); 2502 directories->list = xmalloc (5 * sizeof (char *)); 2503 directories->max = 5; 2504 directories->idx = 0; 2505 } 2506 else if (directories->idx == directories->max - 1) 2507 { 2508 directories->max += 5; 2509 directories->list = xrealloc ((void *)directories->list, 2510 directories->max * sizeof (char *)); 2511 } 2512 directories->list[directories->idx++] = fake_path; 2468 2513 } 2469 else if (directories->idx == directories->max - 1)2470 {2471 directories->max += 5;2472 directories->list = xrealloc ((void *)directories->list,2473 directories->max * sizeof (char *));2474 }2475 directories->list[directories->idx++] = fake_path;2476 2514 } 2477 2515 }
Note:
See TracChangeset
for help on using the changeset viewer.