CIF
CIF

Reputation: 1774

Recursive in Makefile... any other solutions?

What I want to do is to compress all css in all subfolders under a certain folder.

for example, I have

/resources/css/
/resources/css/parent.css
/resources/css/child.css
/resources/css/import/import.css

something like this... (above is just an example, file names are not being used in real-world).

So, I tried searching for doing recursion in Makefile. But seems like it's not a recommended way, but then was told to use "include" and have Makefile under each sub-folders and the most parent Makefile should call sub-folder's Makefile.

But! I don't like this way of doing. I don't want to create Makefile for every sub-folder.

Is there a other way to handle this case? Any other tool suggestions, I'm willing to learn and try out.

I just want to do simple one command to compress all the css under my folder. (even js). Thanks!

Upvotes: 2

Views: 197

Answers (1)

Phil Miller
Phil Miller

Reputation: 38118

In your Makefile,

# Define a variable that encompasses all of the CSS files:
CSSFILES := $(shell find . -name '*.css')

# Target compressed versions of each
default: $(CSSFILES:%.css=%.compressed.css)

# Tell Make how to compress (tab leading command line)
%.compressed.css: %.css
        compresscommand --input $< --output $@

Upvotes: 4

Related Questions