6 ms·
One of the listed benefits of just is "Recipes can be listed from the command line." There is a nice trick that gives makefiles this ability: http://marmelab.c
by velcrovan 4y ago
One of the listed benefits of just is "Recipes can be listed from the command line."
There is a nice trick that gives makefiles this ability: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html http://marmelab.com/blog/2016/02/29/auto-documented-makefile...
Adding .PHONY targets and so forth is a bit inelegant, but I can share a makefile with confidence that any Linux/Mac OS/BSD user can use it without needing additional software, and I will never have to worry about make becoming unavailable or no longer maintained. Just my personal opinion.
- rcarmo 4y agoActually, I did a hack that does that too (this one is nicer, though). I can’t find mine offhand (too many makefiles), but it is also a Makefile target that runs grep -B1 on the Makefile itself and spits out each target’s name and the comment I usually add to it… And my Makefile template uses .env files too… I think I cover most of the list in my day-to-day use.
- oso2k 4y agoThat works well if you have targets with simple comments that are directly above the target and don't extend beyond a single line. It may be important to provide several lines of help. This gist has other solutions as well: https://gist.github.com/prwhite/8168133 https://gist.github.com/prwhite/8168133
- codetrotter 4y ago> I can share a makefile with confidence that any Linux/Mac OS/BSD user can use it without needing additional software Makefile portability can be tricky. Especially if you try to do something fancy with the makefiles. GNU Make has features and syntax that the other Makes don’t. Likewise there are features and syntax that some Make programs have that GNU Make doesn’t.
- deleted 4y ago[deleted]
- dijit 4y ago> but I can share a makefile with confidence that any Linux/Mac OS/BSD can use it without needing any additional software I'm sure you're kidding, but in the case that you're not: Make portability is gross. We have ./configure steps precisely because Make is difficult w.r.t. portability, but even if that wasn't the case and you were just using make as a command executor: you still have enormous warts. Oh, and yeah, you'd need whatever additional software too. Be it: headers, linters, formatters, libraries or test suites that you've bundled. Valgrind is a popular make target, but "Make" does not bring in valgrind (for example). Honestly one of the most backwards things the Go community did was adopt "Make", it's so kludgey even as a pure command executor that I can't really take anyone seriously who argues for it's use. I'm not saying "Just" is a replacement, I don't know what is. Most of the arguments for using Make boil down to "I enjoy typing `make <something>`" and "you probably have it installed already?".
- alisonatwork 4y agoThis. People here are acting like make is installed by default on all Linuxes, but it absolutely is not. And the various BSD makes are very different to GNU make. Make portability is bad enough on UNIX-like OSes, to say nothing of what a crapshoot it is on Windows. Even if you do have make installed on Windows, there's no guarantee that what it shells to is going to be able to run all the commands people tend to put in there. Plain old shell scripting is much more portable than make, because a shell is definitely installed on every UNIX-like OS, and there is a very clear baseline of functionality that works in every Bourne/POSIX descendant. And it's quite likely to exist on a modern Windows developer machine too because bash is bundled together with Git. My theory of writing developer scripts is to prefer the tool that already exists in the language you're developing. Gradle for JVM, npm for Node etc. Otherwise just use shell. Make feels like wrong tool for the job.
- velcrovan 4y agoThis just in, Windows isn't UNIXy, film at 11 Let me know what shell scripting selectively builds only the artifacts whose dependencies have changed (honest question).
- 4y ago
- apatheticonion 4y agoEDIT: Not really a serious suggestion Make is not _that_ portable. If you're using high level languages and only need a task runner to kick off your compiler, watch rules or similar and need portability, you could write an executable bash script with functions that serve as your commands; #!/bin/bash set -e function build() { echo "Your build steps" } function clean() { echo "Your clean steps" } eval $1 $@ Which you can run with $ ./task clean $ ./task build You can also write these kinds of task scripts in JavaScript or Python - which might be easier to manage compatibility with Windows
- velcrovan 4y agoAll of my makefiles have SHELL = /bin/bash as the first line. Let me know what a bash script would look like that does dependency checking for each build artifact
- apatheticonion 4y agoYeah that's fair. I only use make as a task runner for high level languages where the compilers that take care of those aspects of compilation. My makefile commands are never much more complicated than "cargo build" or adding compiler flags to my "go build" command
- remram 4y agoWhy not write two files ./clean.sh and ./build.sh instead?
- apatheticonion 4y agoNo reason why you couldn't do that too - it's to taste. I generally like to have fewer files in the top level of my repos to keep them approachable. You could also have a folder that contains scripts like: `./scripts/build`
- tomjakubowski 4y agoIt's a little more convenient to share code / variables between tasks in a single script
- rgoulter 4y ago> ... any Linux/Mac OS/BSD user can use it without needing additional software ... In my experience, `make` also needs to be installed. (On ubuntu it's part of `build-essential`). I guess more precisely, `just` might not be available in all package managers?
- oso2k 4y agoThere's also a whole GH gist on the topic that a few of us have golf'd on. https://gist.github.com/prwhite/8168133 https://gist.github.com/prwhite/8168133 The linked blog's solution is also mentioned in the gist comments. https://gist.github.com/prwhite/8168133?permalink_comment_id=4160255#gistcomment-4160255 https://gist.github.com/prwhite/8168133?permalink_comment_id...
- oso2k 4y agoI like similar tricks. Another trick I like to use is being able to do a `make showconfig` and have it print the list of variables & their values that I care about. You can see that here. You can also see my Make+BASH solution for documenting targets. https://github.com/lpsantil/oop0/blob/master/Makefile#L87-L111 https://github.com/lpsantil/oop0/blob/master/Makefile#L87-L1...
- dgunay 4y agoOne nice thing fish does is that it can enumerate your make commands via tab completion
- pletnes 4y agoAs can bash and zsh!