commit 56b8970e016ef878addb3a2bb6b965bab0618dd4 from: Benjamin Stürz date: Fri Nov 15 23:06:39 2024 UTC make: implement -C option commit - 03656db54f9d24e0e5c6344b159da1eb3d78932f commit + 56b8970e016ef878addb3a2bb6b965bab0618dd4 blob - c61a0ebec9766c51e3d0c5f54733206a010e1c36 blob + fae3ab7b588ebd6ec2fca7724642b14d063bbc34 --- make/make.c +++ make/make.c @@ -1382,7 +1382,7 @@ struct scope *sc; usage () { - fprintf (stderr, "usage: %s [-pv] [target...]\n", m_make.value); + fprintf (stderr, "usage: %s [-pv] [-C dir] [target...]\n", m_make.value); return 1; } @@ -1392,23 +1392,25 @@ char **argv; struct scope *sc; struct path *path; struct macro *m; - char *s; + char *s, *cd = NULL; int i, option, pr = 0, n = 0; m_dmake.value = m_make.value = argv[0]; str_reset (); - while ((option = getopt (argc, argv, "pv")) != -1) { - str_push (' '); - str_push ('-'); - str_push (option); + while ((option = getopt (argc, argv, "pvC:")) != -1) { switch (option) { case 'p': + str_push_str (" -p"); pr = 1; break; case 'v': + str_push_str (" -v"); verbose = 1; break; + case 'C': + cd = optarg; + break; case '?': return usage (); default: @@ -1416,6 +1418,9 @@ char **argv; } } + if (cd != NULL && chdir (cd) != 0) + err (1, "chdir()"); + argv += optind; argc -= optind;