Start updating BLD notes#32
Conversation
| at all, as they have different semantics than in other programming languages: | ||
|
|
||
| **Simply expanded** means that variable references and function calls on the | ||
| right hand side happen when the variable is *defined* (in the *read-in* phase). |
There was a problem hiding this comment.
Is this the first time we use the term "read-in phase"? If so, might want to replace it with something more self-explanatory like "when the Makefile is initially parsed (before any recipes run)".
There was a problem hiding this comment.
likely; was planning on saying something like "more about this later" since it's coming right up
| syntax. You will likely not want to use recursively expanded variables much, if | ||
| at all, as they have different semantics than in other programming languages: | ||
|
|
||
| **Simply expanded** means that variable references and function calls on the |
There was a problem hiding this comment.
nit: should we hyphenate "simply-expanded"?
There was a problem hiding this comment.
no idea. if this is correct, please say so
| ### Simple vs recursive expansion | ||
| ### Functions | ||
|
|
||
| ### Make variables and functions are textual |
There was a problem hiding this comment.
Should definitely talk about how quoting differs/interacts between Make and shell in this section.
| *automatic variables* and help refer to different parts of the rule so you, the | ||
| programmer, don't repeat yourself too much. | ||
|
|
||
| There are many automatic variables, particuarly in the GNU implementation of |
There was a problem hiding this comment.
Should we link to the GNU docs that have the full list here? Can't remember if that's our practice in lecture notes or not.
| Make, but you will probably see these three the most: `$@`, `$^`, and `$<`. In | ||
| order: | ||
|
|
||
| * `$@` refers to the name of the target. In our example above, this is used in |
There was a problem hiding this comment.
s/name/filename/? It's very common for beginners to not realize that every target is a file by default. (.PHONY excepted, of course.)
There was a problem hiding this comment.
maybe "--the filename"
|
The You were right that |
|
I looked over the outline but I think it predates the slides. I started following the slides for these notes. |
| @@ -289,7 +292,7 @@ A DAG, just like Git uses! | |||
| └───────┘└───────┘└───────┘ | |||
| ``` | ||
| Both `main.c` and `main.h` are prerequisites for `main.o`, but because | ||
| `main.c` is listed as the first prerequisite, it can be referred to by `$<` | ||
| in the build recipe. |
There was a problem hiding this comment.
Maybe a footnote explaining why the .h files don't need to be listed in the command explicitly?
| for more automatic variables. | ||
|
|
||
| ### Simple vs recursive expansion | ||
| ### Functions |
There was a problem hiding this comment.
Can we push this to a later lecture?
| `.cpp`, `.o`). | ||
|
|
||
| Because they are built-in, they support limited customization. If the implicit | ||
| rule makes use of variables (such as `CC`, `CFLAGS`, and `LDFLAGS`), then you |
There was a problem hiding this comment.
Talk about how to figure out if an implicit rule uses variables? I generally just hope the Make docs are correct/complete, which they usually are but sometimes aren't. But perhaps there's an easy-to-understand source of truth that would be a better reference?
There was a problem hiding this comment.
demo reading docs and reading source to verify; that's the point of the class
| This can be useful for debugging, but sometimes the command's only purpose is | ||
| to print something else (e.g. `echo`). In this case, it's not helpful. To | ||
| prevent the command from being printed, preface its line in your recipe with | ||
| `@`. |
There was a problem hiding this comment.
Might be a good place to also mention the - prefix, which makes a failure of that command non-fatal.
| You learned about environment variables in the command-line module. They are a | ||
| great way to pass around snippets of data between programs. As such, they are | ||
| commonly used in Make. Make even *imports all environment variables* as Make | ||
| variables. For example, if you have the following Makefile: |
There was a problem hiding this comment.
TODO for @tchebb: remind myself of the nuances here so I can review this section more thoroughly
| 0: f3 0f 1e fa endbr64 | ||
| 4: 50 push rax | ||
| 5: 31 c0 xor eax,eax | ||
| 7: e8 00 00 00 00 call c <main+0xc> |
There was a problem hiding this comment.
can we do something with nm -u?
There was a problem hiding this comment.
or readelf -s | grep UND
Co-authored-by: Tom Hebb <tommyhebb@gmail.com>
No description provided.