Milad
Milad

Reputation: 5490

Run two make phony targets in parallel

I (mis)use make's phony targets for conveniently doing all sorts of random things in my project. For example:

.PHONY: css
css:
    @(sass foo.scss foo.css)

But sometimes these commands will run forever until I explicitly kill them. For instance when sass is watching a file for changes:

.PHONY: watch_css
watch_css:
    @(sass --watch foo.scss:foo.css)

This is fine, but sometimes I want to combine multiple recipes in a single target:

.PHONY: watch_css1
watch_css1:
    @(sass --watch foo1.scss:foo1.css)

.PHONY: watch_css2
watch_css2:
    @(sass --watch foo2.scss:foo2.css)

.PHONY: watch
watch: watch_css1 watch_css2

How can I get make watch to run both watch_css1 and watch_css2 in parallel? If I explicitly do make -j2 watch things work fine but is there a way to embed that into the makefile itself?

Upvotes: 0

Views: 593

Answers (1)

MadScientist
MadScientist

Reputation: 100781

You can run make recursively:

watch:
        $(MAKE) -j2 watch_css1 watch_css2

Upvotes: 1

Related Questions