As I used `make` more and more for our node projects, I missed the clean outputs `grunt` or `gulp` provide.<p>To fix that, I created `make2tap`: <a href="https://www.npmjs.com/package/make2tap" rel="nofollow">https://www.npmjs.com/package/make2tap</a><p>This small utility takes a `make` output and generate a `TAP` one that you can pipe to any `TAP reporter`.<p>Our current `make build | make2tap | tap-format-spec` looks like: <a href="http://i.imgur.com/chs0Jf3.png" rel="nofollow">http://i.imgur.com/chs0Jf3.png</a>
They should really be using bash for this, not make. There is nothing wrong with bash scripts calling Make -- for building with DEPENDENCIES. But when you aren't doing that, just use bash (because Make is actually Make + bash to begin with).<p>This is dumb:<p><pre><code> restart-frontend: ## Restart the frontend and admin apps in dev
@make stop-frontend-dev && make run-frontend-dev
@echo "Frontend app restarted"
</code></pre>
Write it with a shell script like this:<p><pre><code> stop-frontend-dev() {
...
}
run-frontend-dev() {
...
}
restart-front-end() {
stop-frontend-dev
run-frontend-dev
echo "Frontend app restarted"
}
build() {
make # this actually does stuff you can't do in bash.
}
"$@" # call function $1 with args $2... Can also print help here.
</code></pre>
This is a lot cleaner. The PID stuff can be done with bash too.
I like the ideas here, but for long-running processes like file watching, dev servers, hot reloading, etc. a better format is Procfile (<a href="https://devcenter.heroku.com/articles/procfile" rel="nofollow">https://devcenter.heroku.com/articles/procfile</a>). The ideas from this article could be nicely applied to it.<p>Procfil is a format that declares a named list of processes to be run that can be controlled by tools like Foreman (<a href="http://ddollar.github.io/foreman/" rel="nofollow">http://ddollar.github.io/foreman/</a>) and Honcho (<a href="https://pypi.python.org/pypi/honcho" rel="nofollow">https://pypi.python.org/pypi/honcho</a>). The advantage is being able to start and stop them concurrently as a group, useful for things that otherwise take a tmux session or multiple windows/tabs, like dev server + file watching + live reload: they become a simple `foreman start`. Processes can also be started individually. Procfiles can also be exported to other formats, like systemd, upstart, inittab, etc.<p>Here's an example Procfile from a web project I've been working on. Since it uses node I went with node tools like http-server and watch, but it could just as easily use any other web server or file watcher. The way it works is it starts a web server serving public/; starts a live reload server for public/; and watches the src/ directory for changes and re-runs make. The makefile has a few rules for compiling JS and CSS from src/ to public/.<p><pre><code> web: ./node_modules/.bin/http-server
livereload: ./node_modules/.bin/livereload public
watch: ./node_modules/.bin/watch make src</code></pre>
>Wouldn’t it better if we could just type make, and get a list of available commands, together with their desciption?<p>No, Jesus Christ, please don't. Preserve default action as being to build.<p>Good user interface and good user experience relies on meeting expectations. This behavior breaks those expectations. What if your expectations are different, you ask? In environments where there is an established tradition I think it is rude to break with the norm unless there is a compelling reason to do so. The commandline is popular among developers, other IT professionals and power users because of how efficient it is. It is efficient because there is not all the noise, handholding and other bullsh*t. Please let us keep it that way.<p>Use a specific target to list other targets. I've seen some people use "make targets".
An alternative way that just uses GNU make functions: <a href="http://www.cmcrossroads.com/article/self-documenting-makefiles" rel="nofollow">http://www.cmcrossroads.com/article/self-documenting-makefil...</a>
Thanks for sharing! This is a great way to document and see documentation for main targets in Makefile.<p>We use Makefile in same way to execute project related tasks like deployments and run development environments. This will even further help to show main targets from a Makefile easily and pretty standard way. Will be taken into use.<p>You can achieve similar by writing bash scripts, but it will be mostly custom and others need to learn how to use it and extend it. Makefile gives you a standard way of writing small utilities related to all your project, and almost everybody knows how Makefile works and if not, they can learn from existing documentation.
Good idea but target names might contain numbers as well, so you should adjust the regular expression used:<p>@grep -P '^[a-zA-Z0-9_-]+:.<i>?## .</i>$$' $(MAKEFILE_LIST) | ...
Shorter, more fail-proof help target:<p><pre><code> help:
@awk -F ':|##' \
'/^[^\t].+?:.*?##/ {\
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
}' $(MAKEFILE_LIST)
</code></pre>
... but I agree, breaking expectations is somewhat bad.
Also, many shells have completion for Makefiles nowadays, though, that won't get you an additional help text.
You probably want to be using phony targets if your Makefile consists of stuff like this. See: <a href="https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html" rel="nofollow">https://www.gnu.org/software/make/manual/html_node/Phony-Tar...</a>
I've been using a similar self-documenting technique myself for a while now, too. Although, my version preserved the traditional part where just calling `make` starts building the program and also supported short one line descriptions and longer ones.<p>Slightly OT: I like how Rake handles this, which is what gave me the idea in the first place
Here is a version with no dependencies to grep or awk but just sed. I did not tested it on OS X yet.<p><pre><code> help:
@eval $$(sed -r -n 's/^([a-zA-Z0-9_-]+):.*?## (.*)$$/printf "\\033[36m%-30s\\033[0m %s\\n" "\1" "\2" ;/; ta; b; :a p' $(MAKEFILE_LIST) | sort)</code></pre>
I do this in my bash scripts, if anyone wants to see how.<p><a href="https://github.com/ehartsuyker/node-deb/blob/ede596b2c8a07f1f1925e4f8e51df5ba9ef15be3/node-deb#L44" rel="nofollow">https://github.com/ehartsuyker/node-deb/blob/ede596b2c8a07f1...</a>
But then you have lost the default target of make and instead of make && make install you end up with make build && make install. That's going to break a brain or two when people try to figure out why their default MO doesn't work.