简体   繁体   中英

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

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 $< > $@

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM