Hey, I’m trying to create a pipeline that takes files from a flat directory source/ that contains files with names formatted as yyyy-mm-dd-some-file-name.md and processes them with the output being created in destination/yyyy/mm/dd/some-file-name.md. I managed to string together an ugly script that converts the source path to destination path, but the problem is that make says that there is no rule to make the target. Here is my code so far:
SOURCE := $(wildcard source/*.md)
DESTINATION := $(foreach f,SOURCE,destination/$(shell echo $(notdir $(f)) | sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md$$/\1\/\2\/\3\/\4.md/'))
$(DESTINATION): $(SOURCE)
@mkdir -p $(dir $(shell echo $(notdir $@) | sed -E 's/^([0-9]{4})-([0-9]{2})-([0-9]{2})-(.*)\.md$$/\1\/\2\/\3/'))
/bin/bash ./myscript.sh $< > $@
I believe that make sees that there are no target directories yet and just aborts the rule, but I’m not knowledgeable enough and just starting out with that tool. I would appreciate some guidance if any of you folks know a bit of Make.


This breaks down when there are more than one
SOURCEfile, since eachDESTINATIONfile depends on all source files. This means that$<will always be the first file inSOURCE. For example, ifsourcecontains the files0001-01-01-some-file-name.mdand0002-02-02-some-file-name.md:OP is probably better off using a scripting language to automate this kind of thing
EDIT: Fixed example filenames
Well spotted, thanks. I replied further down the thread to OP with another option for doing this in Make, if you’d like to spot any bugs in that one too ;)