Skip to content
Advertisement

Makefile generate numerical list of files

I have a Makefile that I use for building a book I am writing into EPUB and Kindle formats.

However, my list of source files is getting really long:

CHAPTERS = 
    1.md 
    2.md 
    ...
    30.md 

I am trying to generate this list programmatically, and I got it working with:

CHAPTERS = $(addsuffix .md, $(shell seq 1 30))

But can’t help but feel I feel like there is a simpler way.

Is there a simpler method to achieve numerical file generation (i.e. can this be reduced to a single command instead of 2 nested commands)?

Advertisement

Answer

Coincidentally, the GNUmake Table Toolkit features such a function:

$(call interval,start,range[,step])

$(call interval,5,5) --> 5 6 7 8 9
$(call interval,2,3,100) --> 2 102 202

Of course, simple is just a relative measure…

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement