If I want to use the command
make
and add a flag to its code, that did not exist before, in which files in the make-4.3.tar.gz should I add a definition of the flag and its implementation?
Asked
Active
Viewed 516 times
1

CS2000
- 51
- 4
-
@lrelia I meant for example I want to add a flag called "abcd" so my command should be "make --abcd=FILE" how can I support that? – CS2000 Dec 29 '21 at 17:08
-
You should not edit anything in the tarball. The tarball is derived from the source, and you should edit the source in the VCS. – William Pursell Dec 29 '21 at 17:10
-
1but.. don't you want to use a variable instead? `make abcd=fine` would work just fine. – KamilCuk Dec 29 '21 at 17:11
-
1You would have to extract the tarball, modify the code and rebuild. But why? Maybe you want to define a symbol and use the standard make: `make abcd=FILE`. Then, in the Makefile do: `ifdef abcd`, etc – Craig Estey Dec 29 '21 at 17:18
1 Answers
0
in which files in the make-4.3.tar.gz should I add a definition of the flag and its implementation?
Seems pretty easy, parsing is done in https://github.com/mirror/make/blob/d365bdfdbc925d663f3f38caf2635761f8ce068f/src/main.c#L2958 with getopt_long
. args
are initiliazed at https://github.com/mirror/make/blob/d365bdfdbc925d663f3f38caf2635761f8ce068f/src/main.c#L2693 where switches
are defined https://github.com/mirror/make/blob/d365bdfdbc925d663f3f38caf2635761f8ce068f/src/main.c#L423 . There are many "combinations" of switches depending on environment variables, see decode_env_switches
usages. So just add a new global variable to hold the values, new flag in switches
array with filename
type and you are good to go.

KamilCuk
- 120,984
- 8
- 59
- 111
-
thank you so much, can you please explain to me this format: { 'C', filename, &directories, 0, 0, 0, 0, 0, "directory" } (copied from line 451)? and where can I implement the functionality of the flag? – CS2000 Dec 29 '21 at 17:25
-
There is nothing to explain... I mean, it's not tricky or obfuscated in any way. Which part is unclear to you? It's a [structure initiallization](https://en.cppreference.com/w/c/language/struct_initialization). You can learn C programming from [some C books](https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list). The structure definitions is right above - structure members seem descriptive enough to guess what they mean. – KamilCuk Dec 29 '21 at 17:28