user1977661
user1977661

Reputation: 263

Makefile: rebuild target if its source changes

I've got this Makefile in a PHP project (this is trimmed down from the full Makefile). How can I change this so automake detects that public/assets/styles/main.scss has changed & re-run sass?

all: public/assets/styles/styles.css

public/assets/styles/styles.css:
    sass public/assets/styles/main.scss > public/assets/styles/styles.css

Upvotes: 0

Views: 80

Answers (1)

Andrea Biondo
Andrea Biondo

Reputation: 1686

Simply make the .scss file a prerequisite of your .css target. As a bonus, avoid repetition of your base path and use automatic variables to make the recipe less redundant:

STYLEDIR := public/assets/styles

all: $(STYLEDIR)/styles.css

$(STYLEDIR)/styles.css: $(STYLEDIR)/main.scss
    sass $< > $@

Upvotes: 1

Related Questions