Do More and `make` Less with GNU Make and Less.js
thumbtack.com
thumbtack.com
The examples break these rules more then a couple of times. Their very last examples won't work, because they generate the %.d file in the same rule that is only supposed to generate the %.css file. Because of this, 'make' has no way of figuring out what rule to run to create the %.d file, so the -include will fail from the .d files not existing in the first run (-include and include-file generation happen before the default rule is started, because it happens at parsing time). Providing a separate %.d rule would fix this issue (And also fix the issue that every time you compile your dependency info will be generated again, even if it hasn't changed.). For example, if you wrote a 'make clean' which only cleaned the %.css files, all of the %.d files would be generated again when you generate the %.css files, even though it's not nessisary. There's also a small error that 'all' isn't the default rule to run, the default is simply the first rule in the file. It's common to see 'all' defined high-up in a Makefile as something like 'all: real-all', where 'real-all' is defined below after other various things take place, and it does the actual heavy lifting of kicking off the compilation.
Yes. The following is an example of how to handle C header dependencies. It could be adapted to build css from less and would be an improvement on the blog post technique.
sources := $(wildcard *.c)
-include $(subst .c,.d,$(sources))
%.d: %.c
$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\ 1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
It uses the fact that if you include a file which doesn't exist but for which there is a rule to build it, GNU make will build it for you. $(objtree)/%.d: $(srctree)/%.c
@$(CC) -MM -MP -MF $@ $(CPPFLAGS) $< -MT $(objtree)/$*.o -MT $@
That generates a dependency file in the form: $(objtree)/%.o $(objtree)/%.d: (dependency list)
(dependency-list-entry-1):
(dependency-list-entry-2):
etc...
It's pretty handy. Avoiding all the sed stuff is nice.Except the elephant in the room, Windows.
Annoying. But I still don't miss grunt :)
To accomplish the same/similar thing with gulp in one of my projects:
var gulp = require('gulp');
var less = require('gulp-less');
var concat = require('gulp-concat');
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
gulp.task('styles', function() {
return gulp.src(['assets/styles/**/*.less'])
.pipe(less())
.pipe(concat('app.css'))
.pipe(rename({suffix: '.min'}))
.pipe(minifyCSS())
.pipe(gulp.dest('www/css/'))
});
The make example is really cool but I'd be lost if I needed to modify it even ever so slightly. Maybe this speaks more to my lack of experience using the sed/tr/etc but make just seems more complicated to manage. That's just my two cents.However the resulting Makefile became a complete mess. Which unfortunately is a very common problem one when it comes to Makefiles.
Which I think is what plays to make's advantage. The one thing it does is track dependencies between files and the shell commands it takes to make them. The rest is punted to the shell commands.