makefile - gnu make recreating directory structure in target -
i'd use gnumake image compression , preparations websites.
i have structure like
src www.site1.org images foo.jpg bar.png css style.scss www.site2.org images baz.svg css design.scss i want able recreate structure in target directory while using other tools optimize/compile sources e.g. convert --strip src/www.site1.org/images/foo.jpg target/www.site1.org/images/foo.jpg
i can find jpegs using src:=$(shell find . -name '*.jpg') , create variable holding targets targets=$(src:src=target).
but don't find way of writing rule (naively) like:
$(target): $(src) convert --strip $< $@ i've searched internet quiet time didn't find appropriate.
you use:
src := $(shell find src -name '*.jpg') targets = $(patsubst src/%,target/%,$(src)) all: $(targets) $(targets): target/%: src/% convert --strip $< $@ which says: each word in targets, match against target/% pattern (and record % sub-expression), consider single dependency src/% , apply recipe. gnu make feature, documented in section 4.12 static pattern rules of manual.
by way, $(src:src=target) not think because pattern matches @ end of each word of $(src). so, foo_src substituted foo_target src/foo left unmodified. patsubst more powerful substitution function.
Comments
Post a Comment