Generating dependencies for a makefile
I'm trying to use a makefile to generate assets for web application. I have a script which generates dependencies for a开发者_开发问答 given CSS or JS file as a list of filenames. How can I modify it and use in makefile?
UPD: Here's what I came up with for CSS. It's tailored for our workflow, we use lots of CSS imports in development environment.
#CSS_SRCs should contain only import directives
CSS_SRC = base.css base-inner.css
CSS_MIN = $(CSS_SRC:.css=.min.css)
#CSS compression tool of your choice
CSS_COMPRESSOR=cat
%.min.css:
$(CSS_COMPRESSOR) $^ > $@
all: $(CSS_MIN)
%.d: %.css
rm -f $@; \
printf '$*.min.css $@: ' >> $@; \
sed -e 's|@import url(\"\([^\"]*\)\");|\1|' $< | tr '\n' ' '>> $@
include $(CSS_SRC:.css=.d)
With JavaScripts it's a little bit trickier cause I need to pull dependencies out of Google Closure library.
Write the dependencies out as 'make' rules, and then include the file in the Makefile.
精彩评论