Unix found with GNU Make for automatic file updates

I have files .hamland you want to automatically convert them to files .htmland update the latest when they change .haml.

The general makefile rule is not a problem:

%.html: %.haml
    hamlpy $< $@

But now I need a rule or command to do the following:

  • find all X.hamlfiles intemplates/
  • execute the command make X.html, where X is the same file name ( hamlreplaced by html).

I cannot find how to do this using GNU Make or Unix.

+5
source share
2 answers

If all your files *.hamlhave a good name (i.e. spaces or other funny characters), you can do this with a call find(1):

HAML_FILES = $(shell find templates/ -type f -name '*.haml')
HTML_FILES = $(HAML_FILES:.haml=.html)

all: $(HTML_FILES)

%.html : %.haml
        hamlpy $< $@
+8

GNU make wildcard :

INDIR := templates
OUTDIR := ${CURDIR}

haml_files := $(wildcard ${INDIR}/*.haml)
html_files := $(subst ${INDIR}/,${OUTDIR}/,${haml_files:.haml=.html})

all : ${html_files}

clean :
    rm -f ${html_files}

${OUTDIR}/%.html : ${INDIR}/%.haml
    hamlpy $< $@

.PHONY : all clean

INDIR OUTDIR , , iutputs:

$ make INDIR=. OUTDIR=.
+7

All Articles