VirtualBox

Changeset 3653 in kBuild


Ignore:
Timestamp:
Nov 4, 2024 12:22:49 AM (4 months ago)
Author:
bird
Message:

kmk: Automatically ascend if no makefile found and a goal was given on the command line. This is to eliminating the need for Makefile.kup-files as far as compiling individual source files from an editor is concerned.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/main.c

    r3481 r3653  
    14181418
    14191419/* bird: */
    1420 #ifdef CONFIG_NEW_WIN32_CTRL_EVENT
    1421 #include <process.h>
     1420# ifdef CONFIG_NEW_WIN32_CTRL_EVENT
     1421#  include <process.h>
    14221422static UINT g_tidMainThread = 0;
    14231423static int volatile g_sigPending = 0; /* lazy bird */
    1424 # ifndef _M_IX86
     1424#  ifndef _M_IX86
    14251425static LONG volatile g_lTriggered = 0;
    14261426static CONTEXT g_Ctx;
    1427 # endif
    1428 
    1429 # ifdef _M_IX86
     1427#  endif
     1428
     1429#  ifdef _M_IX86
    14301430static __declspec(naked) void dispatch_stub(void)
    14311431{
     
    14441444    }
    14451445}
    1446 # else /* !_M_IX86 */
     1446#  else /* !_M_IX86 */
    14471447static void dispatch_stub(void)
    14481448{
     
    14561456        exit(131);
    14571457}
    1458 # endif /* !_M_IX86 */
     1458#  endif /* !_M_IX86 */
    14591459
    14601460static BOOL WINAPI ctrl_event(DWORD CtrlType)
     
    14651465
    14661466    /*fprintf(stderr, "dbg: ctrl_event sig=%d\n", sig);*/
    1467 #ifndef _M_IX86
     1467#  ifndef _M_IX86
    14681468    /* only once. */
    14691469    if (InterlockedExchange(&g_lTriggered, 1))
     
    14721472        return TRUE;
    14731473    }
    1474 #endif
     1474#  endif
    14751475
    14761476    /* open the main thread and suspend it. */
     
    14841484    Ctx.ContextFlags = CONTEXT_FULL;
    14851485    if (GetThreadContext(hThread, &Ctx)
    1486 #ifdef _M_IX86
     1486#  ifdef _M_IX86
    14871487        && Ctx.Esp >= 0x1000
    1488 #else
     1488#  else
    14891489        && Ctx.Rsp >= 0x1000
    1490 #endif
     1490#  endif
    14911491       )
    14921492    {
    1493 #ifdef _M_IX86
     1493#  ifdef _M_IX86
    14941494        ((uintptr_t *)Ctx.Esp)[-1] = Ctx.Eip;
    14951495        Ctx.Esp -= sizeof(uintptr_t);
    14961496        Ctx.Eip = (uintptr_t)&dispatch_stub;
    1497 #else
     1497#  else
    14981498        g_Ctx = Ctx;
    14991499        Ctx.Rsp -= 0x80;
     
    15011501        Ctx.Rsp += 8;   /* (Stack aligned before call instruction, not after.) */
    15021502        Ctx.Rip  = (uintptr_t)&dispatch_stub;
    1503 #endif
     1503#  endif
    15041504
    15051505        SetThreadContext(hThread, &Ctx);
     
    15201520    return TRUE;
    15211521}
    1522 #endif /* CONFIG_NEW_WIN32_CTRL_EVENT */
     1522# endif /* CONFIG_NEW_WIN32_CTRL_EVENT */
    15231523
    15241524#endif  /* WINDOWS32 */
     
    24082408
    24092409#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
    24122418     If no -C arguments were given, fake one to indicate chdir. */
    24132419  if (makefiles == 0)
    24142420    {
    24152421      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
    24212423       && stat ("makefile.kmk", &st) < 0)
    24222424        {
     
    24242426          char *cur = &fake_path[2];
    24252427          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) ) )
    24272434            {
    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)
    24402436                {
    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");
    24422447                  if (   stat (fake_path, &st) != 0
    24432448                      || !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++;
    24452460                }
    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."));
    24512463            }
    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)
    24632492            {
    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;
    24682513            }
    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;
    24762514        }
    24772515    }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette