-
Notifications
You must be signed in to change notification settings - Fork 10
Makefile refactor #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makefile refactor #119
Conversation
f2b04c9 to
44d449a
Compare
jfhamlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the cleanup! looks awesome and works well :). just had a few questions/nits and then i think we're good to merge!
|
|
||
| SHELL := bash | ||
|
|
||
| GO-VERSION ?= 1.19.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the switch from SNAKE_CASE to KEBAB-CASE? i've seen kebab for targets but snake seems like the norm for variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if you read through my explanations in the commit messages, but 7f2d72d
Makefiles inherit from the env which only allows SNAKE_CASE. KEBAB-BASE is only allowed in Makefile vars, not env ones, so it makes the vars ownership very clear.
You can override vars from the command line like this:
ENV_VAR=foo make all MAKE-VAR=bar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also in commit 1b0f4cd I made almost all of the SINGLEWORD Makefile vars into MULTI-WORD vars, to drive home that they don't ever come from (can't come from) the environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point! don't feel strongly, but i wanted to understand the motivation and i failed to read the (useful!) commit messages :)
| STDLIB-ORIGINALS-DIR := scripts/rewrite-core/originals | ||
| STDLIB-ORIGINALS := $(wildcard $(STDLIB-ORIGINALS-DIR)/*.clj) | ||
| STDLIB-NAMES := $(STDLIB-ORIGINALS:scripts/rewrite-core/originals/%=%) | ||
| STDLIB-ORIGINALS := $(STDLIB-NAMES:%=scripts/rewrite-core/originals/,%) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this line needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's this line in main: https://github.com/glojurelang/glojure/blob/main/Makefile#L6
| #------------------------------------------------------------------------------- | ||
| default: all | ||
|
|
||
| .PHONY: all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we keep the .PHONY declarations for the targets that don't produce files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. .PHONY is not only noisy and useless. I found out from this refactor that it can be dangerous.
Here https://github.com/glojurelang/glojure/blob/main/Makefile#L44 all deps on go-generate but that target doesn't exist. The Makefile should error but it doesn't because https://github.com/glojurelang/glojure/blob/main/Makefile#L52 marks go-generate as PHONY.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwiw i've been bitten by missing .PHONY before, but i don't feel strongly. happy to run with this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too, but those bites are rare and almost instantly recognized.
The bite I described (where PHONY masked a typo) remained hidden for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an interesting fact about PHONY you might now know...
You can put all your PHONY targets on one line at the end of the file if you want:
.PHONY: all test clean etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put all your PHONY targets on one line at the end of the file if you want:
ah, i'm familiar with that, but i prefer to keep them adjacent to their targets so it's harder for them to get out of sync — which i managed to do with one of the targets anyway :)
Thanks! FWIW, I learned a few new Makefile tricks from your work along the way. 👍 |
jfhamlin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarifications! I'll merge after CI finishes :)
|
I can resolve if you want... |
|
Let me know. |
ah, please do if you don't mind! |
I was getting failures for `make test` until I realized I hadn't pulled the test suite submodule. Now we always update submodules first so should work for everyone. Added report.html to clean target and ignored it.
Setting SHELL to bash allows us to make use of a more dependable environment. It also allows us to use bash syntax which in many cases is cleaner because you don't need to be concerned with supporting any shell. `bash` is preferable to `/bin/bash` since it will pick up possibly more preferable bash version from the PATH. Like on macOS, /bin/bash is stuck at 3.2, but its easy to `brew install bash` to get the latest version in /usr/local/bin/bash.
Make allows `-` in var names. (Actually it allows nearly all chars :). Environment variables allow allow \w chars (alphanum and _). Make inherits vars from the environment. By using `-` over `_` we make clear which vars come from the environment and which are local to the Makefile.
For consistency, added `-` where 2 words were made into one. Added 2nd word to a few one word vars.
Only `.PHONY: test` is needed because we have a `test` dir. The other .PHONY targets add little value and are noisy.
The generate target was not being run. It did not cause an error becase it was hidden by a bad .PHONY target.
This makes things easier to understand and maintain.
and make them overridable by user. Added a usage comment to top. Note: Where env var overrides go before a command, Makefile var overrides go after the `make` command.
Simplify to aot command
Using @ is for noisy or inconsequential commands. It's important to see what make is actually running though. Helps see obvious mistakes as well.
Let's us make these individually if needed.
'make test' runs both like before. Before TEST-FILES was picking up the test suite glj file by mistake, I believe.
a || b && c && d in bash always runs c and d, which was not the intent, I believe.
The command `make` runs the first Makefile target.
Having the first target be called 'default' makes it obvious what is
going on.
I often specify no deps for the default target so running `make' prints:
Nothing to be done for 'default'.
Add force=1 to the end of a make command to force rebuilds. Adds update-clojure-sources to the front of `make all`.
For use in Makefiles that sit in front of this one. For forks that are working on new AOT and platforms.
44d449a to
751490c
Compare
|
Rebased |
Refactored the Makefile in 15 commits, with details in each commit message.
Found and fixed some bugs along the way.
All previous targets should work as before.