Skip to content

Start updating BLD notes#32

Open
tekknolagi wants to merge 57 commits into
mainfrom
mb-bld-3
Open

Start updating BLD notes#32
tekknolagi wants to merge 57 commits into
mainfrom
mb-bld-3

Conversation

@tekknolagi
Copy link
Copy Markdown
Owner

No description provided.

Comment thread lecture-notes/3-bld.md
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).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)".

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely; was planning on saying something like "more about this later" since it's coming right up

Comment thread lecture-notes/3-bld.md
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we hyphenate "simply-expanded"?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea. if this is correct, please say so

Comment thread lecture-notes/3-bld.md
### Simple vs recursive expansion
### Functions

### Make variables and functions are textual
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should definitely talk about how quoting differs/interacts between Make and shell in this section.

Comment thread lecture-notes/3-bld.md
*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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lecture-notes/3-bld.md
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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/name/filename/? It's very common for beginners to not realize that every target is a file by default. (.PHONY excepted, of course.)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "--the filename"

@tchebb
Copy link
Copy Markdown
Collaborator

tchebb commented Jan 23, 2024

The mb-bld-outline branch definitely has unmerged work on the BLD notes, some of which (mainly adding an outline) overlaps with this PR. We should reconcile them tomorrow.

You were right that mb-bld-lec2 was old, though—it was squashed into commit ee7619f, so I've deleted it.

@tekknolagi
Copy link
Copy Markdown
Owner Author

I looked over the outline but I think it predates the slides. I started following the slides for these notes.

Comment thread lecture-notes/3-bld.md
@@ -289,7 +292,7 @@ A DAG, just like Git uses!
└───────┘└───────┘└───────┘
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Mermaid diagram

Comment thread lecture-notes/3-bld.md
```
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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a footnote explaining why the .h files don't need to be listed in the command explicitly?

Comment thread lecture-notes/3-bld.md
for more automatic variables.

### Simple vs recursive expansion
### Functions
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we push this to a later lecture?

Comment thread lecture-notes/3-bld.md
Comment thread lecture-notes/3-bld.md
Comment thread lecture-notes/3-bld.md
`.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
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

demo reading docs and reading source to verify; that's the point of the class

Comment thread lecture-notes/3-bld.md
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
`@`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a good place to also mention the - prefix, which makes a failure of that command non-fatal.

Comment thread lecture-notes/3-bld.md
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:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO for @tchebb: remind myself of the nuances here so I can review this section more thoroughly

Comment thread lecture-notes/3-bld.md
Comment thread lecture-notes/3-bld.md
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md
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>
Copy link
Copy Markdown
Owner Author

@tekknolagi tekknolagi Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do something with nm -u?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or readelf -s | grep UND

Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Co-authored-by: Tom Hebb <tommyhebb@gmail.com>
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Comment thread lecture-notes/3-bld.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants