Created
May 9, 2014 18:23
-
-
Save mundry/db868a094858d0b2ca88 to your computer and use it in GitHub Desktop.
A Makefile to build SASS files with automatically generated dependencies from a target's imports.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OUTPUT_DIR := build | |
SOURCES_DIR := styles | |
DEPS_DIR := .deps | |
RM := rm -rf | |
RUBY := ruby | |
SASS := scss | |
SASS_OPTIONS := --unix-newlines | |
SASS_OPTIONS += --style compressed | |
SASS_OPTIONS += --precision 8 | |
SASS_OPTIONS += -E utf-8 | |
SASS_OPTIONS += --no-cache | |
SASS_DEPENDENCY_GENERATOR := $(RUBY) | |
SASS_DEPENDENCY_GENERATOR += -r sass | |
SASS_DEPENDENCY_GENERATOR += -e | |
SASS_DEPENDENCY_GENERATOR += 'deps = Sass::Engine.for_file(ARGV[0], {cache: false}).dependencies.collect { |d| d.options[:filename] };\ | |
File.open("$(DEPS_DIR)/" + File.basename(ARGV[0]) + ".d", "w") { |f| f.puts ARGV[1] + ": " + deps.join(" "); f.puts "\n" + deps.join(":\n\n") + ":" unless deps.empty? }' | |
QUIET_RUBY = @echo RUBY '' $(notdir $<).d; | |
QUIET_SASS = @echo SASS '' $(notdir $@); | |
SOURCES := $(shell ls $(SOURCES_DIR)/[^_]*.scss) | |
TARGETS := $(addprefix $(OUTPUT_DIR)/,$(SOURCES:.scss=.css)) | |
D_FILES := $(addprefix $(DEPS_DIR)/,$(addsuffix .d,$(subst $(SOURCES_DIR)/,,$(SOURCES)))) | |
all: $(TARGETS) | |
$(OUTPUT_DIR)/$(SOURCES_DIR)/%.css: $(SOURCES_DIR)/%.scss | |
$(QUIET_RUBY)$(SASS_DEPENDENCY_GENERATOR) $< $@ | |
$(QUIET_SASS)$(SASS) $(SASS_OPTIONS) $< $@ | |
-include $(D_FILES) | |
clean: | |
$(RM) $(TARGETS) $(DEPS_DIR) | |
.PHONY: all clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment