4 ms·
The World's Most Boring Build System
- foldr 11y agoI've never seen a good way of dealing with nested directories in make. E.g., say you have the following directory layout: /foo/a.js /foo/b/c.js /foo/d/e.js And you want minified files to be written to: /bar/a.js /bar/b/c.js /bar/d/e.js I'm not a huge fan of Grunt/Gulp, but doing this is very easy using those tools.
- dozzie 11y agoI don't see what's difficult here.
- foldr 11y agoHow would you write a Makefile to do this? (So that you could add additional directories without having to modify the Makefile.)
- dozzie 11y agoI don't know, I would use wildcards, I guess? And maybe some path substitution. SOURCES := $(shell find foo -type f -name '*.js') TARGETS := $(patsubst foo/%,bar/%,$(SOURCES)) .PHONY: all all: $(TARGETS) bar/%.js: foo/%.js mkdir -p $(dir $@) minify $< > $@
- foldr 11y agoOk, fair enough, that’s how far I got when I tried replacing my Gulpfile with a Makefile. However, things become more difficult if the output files have a different extension. E.g. converting jsx files to js files. I didn’t find a way of handling that case that wasn’t way more complex than the corresponding code in Gulp.
- dozzie 11y agoOoh, a tricky one. It may be much more difficult. SOURCES := $(shell find foo -type f -name '*.jsx') TARGETS := $(patsubst foo/%.jsx,bar/%.js,$(SOURCES)) .PHONY: all all: $(TARGETS) bar/%.js: foo/%.jsx mkdir -p $(dir $@) minify $< > $@
- foldr 11y agoI admit, this is easy enough with 'patsubst' and 'dir'. I had not discovered those, and doing the same job with sed got too messy to be worth the trouble. I haven’t seen example code for this particular pattern before, so thanks, it’s useful. I'll switch over to make now.
- dozzie 11y agoI'm glad you like this solution. Indeed, the $(patsubt) function is one of the most useful, along with $(wildcard) and $(foreach).
- roolebo 11y agoI can see what are you talking about. You need to use order only dependencies for this: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html https://www.gnu.org/software/make/manual/html_node/Prerequis...
- foldr 11y agoHow do those help exactly? I believe you, but it's far from obvious, and it arguably makes more sense to use Gulp than to fiddle around with obscure features of GNU Make.
- roolebo 11y agoOrder-only prerequisites are needed whenever your rules depend on existence of some directories. So directories become make goals too in a sense. Obviously it's way too tedious to write all that by hand. You can have some sort of high-level js.mk scattered in each directory of your project, then there's a top level Makefile which will include all those js.mk files and expand them from high level definitions to make rules. Make is good only if you create a sort of framework around for your domain. However the learning curve is way too steep. I would only attempt to use make if Gulp does its job horribly bad.
- dozzie 11y agoBut wait, your build system is not stupidly tied to a library manager and installer! How are we supposed to live with that? Like, you want us to actually consider what's a necessary dependency for our projects to work? Outrageous!