MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / sh_make

Function sh_make

src/pipeline/pass_shell.c:1916–1992  ·  view source on GitHub ↗

make [-C DIR] [-f FILE] [VAR=V] TARGET...: each TARGET SPAWNS the rule of * that name the makefile reads -- the first -f, else the directory's (-C is * cumulative) -- resolved when linking, through its includes. An unknown -C * or -f value is no edge, an unknown word no target; no target (the default * goal) is no edge. */

Source from the content-addressed store, hash-verified

1914 * or -f value is no edge, an unknown word no target; no target (the default
1915 * goal) is no edge. */
1916static void sh_make(sh_t *s, TSNode cmd, const sh_argv_t *a, int p) {
1917 const char *dir = ".";
1918 const char *file = NULL;
1919 const char **targets = cbm_arena_alloc(s->a, (size_t)(a->n + SKIP_ONE) * sizeof(*targets));
1920 if (!targets) {
1921 return;
1922 }
1923 int nt = 0;
1924 bool rest = false;
1925 for (int j = p + SKIP_ONE; j < a->n; j++) {
1926 const char *v = a->v[j];
1927 if (!v) {
1928 continue;
1929 }
1930 if (rest || v[0] != '-' || sh_eq(v, "-")) {
1931 if (rest || !sh_make_assignment(v)) {
1932 targets[nt++] = v;
1933 }
1934 continue;
1935 }
1936 if (sh_eq(v, "--")) {
1937 rest = true;
1938 continue;
1939 }
1940 const char *arg = NULL;
1941 mk_opt_t kind = MK_OPT_NONE;
1942 if (v[SKIP_ONE] == '-') {
1943 const char *eq = strchr(v, '=');
1944 kind = sh_make_long(v, eq ? (size_t)(eq - v) : strlen(v));
1945 arg = eq ? eq + SKIP_ONE : NULL;
1946 if (kind != MK_OPT_NONE && !eq) {
1947 j++;
1948 arg = j < a->n ? a->v[j] : NULL;
1949 }
1950 } else {
1951 for (size_t k = SKIP_ONE; v[k]; k++) {
1952 if (strchr("CfIoW", v[k])) {
1953 kind = v[k] == 'C' ? MK_OPT_DIR : v[k] == 'f' ? MK_OPT_FILE : MK_OPT_ARG;
1954 arg = v[k + SKIP_ONE] ? v + k + SKIP_ONE : NULL;
1955 if (!arg) {
1956 j++;
1957 arg = j < a->n ? a->v[j] : NULL;
1958 }
1959 break;
1960 }
1961 if (v[k] == 'j' || v[k] == 'l') {
1962 if (!v[k + SKIP_ONE] && j + SKIP_ONE < a->n &&
1963 sh_make_count(a->v[j + SKIP_ONE])) {
1964 j++;
1965 }
1966 break;
1967 }
1968 }
1969 }
1970 if (kind == MK_OPT_DIR || kind == MK_OPT_FILE) {
1971 if (!arg) {
1972 return;
1973 }

Callers 1

sh_spawnFunction · 0.85

Calls 9

sh_eqFunction · 0.85
sh_make_assignmentFunction · 0.85
sh_make_longFunction · 0.85
sh_make_countFunction · 0.85
sh_make_joinFunction · 0.85
sh_unique_fileFunction · 0.85
sh_make_defaultFunction · 0.85
sh_hit_pushFunction · 0.85
cbm_arena_allocFunction · 0.50

Tested by

no test coverage detected