hendry
hendry

Reputation: 10823

Build script to Makefile

I struggle to write Makefiles and I'm building up some examples to learn from. I want to use Makefiles since it makes builds concurrent, projects more uniform and easier to manage.

Do you have any resources to share?

For example I am struggling to think how to turn this simple build script into a Makefile, so that index.html is only built when its index.src.html is modified.

for i in */index.src.html
do
    anolis --max-depth=3 $i $(dirname $i)/index.html
done

Upvotes: 2

Views: 1128

Answers (1)

jmtd
jmtd

Reputation: 1244

Try using a pattern rule. From the GNU Makefile manual:

Thus, a pattern rule ‘%.o : %.c’ says how to make any file stem.o from another file stem.c.

So, something like

INFILES = $(shell find . -name index.src.html)
OUTFILES = $(addsuffix .html, $(basename $(basename $(INFILES))))

default: $(OUTFILES)

%.html : %.src.html
    anolis --max-depth=3 $< $@

clean:
    rm -f $(OUTFILES)

The trick then becomes building up INFILES in a reliable and safe way.

Upvotes: 2

Related Questions