makefilechicken-scheme

How can I use wildcards to remove repetition in my makefile?


I've got a makefile for Advent of Code that I've decided to do in chicken scheme.

However, it's starting to grow, and I'd like to remove the repetition.

Here's a section of what I've got so far, but how do I make it so it can automatically find all days instead of 2 entries per day and an ever increasing main target?

all: advent2015

# advent years - this is ever increasing with the *.so targets
advent2015: $(ADVENTS_SRC)2015/advent2015.scm \
 aoc2015day01.so aoc2015day02.so
    $(CSC) $(INCLUDE_FLAGS) $< -d3 -O2 -compile-syntax -o $@

# individual days - how do i write a single rule that works for all days?
aoc2015day01.so: $(ADVENTS_SRC)2015/aoc2015day01.scm aoc-files.so
    $(CSC) $(INCLUDE_FLAGS) $(LIBFLAGS) $< -j aoc2015day01 -emit-types-file aoc2015day01.types -o $@
    $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) aoc2015day01.import.scm

aoc2015day01.import.so: aoc2015day01.so
    $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) aoc2015day01.import.scm

# day02...
aoc2015day02.so: $(ADVENTS_SRC)2015/aoc2015day02.scm aoc-files.so
    $(CSC) $(INCLUDE_FLAGS) $(LIBFLAGS) $< -j aoc2015day02 -emit-types-file aoc2015day02.types -o $@
    $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) aoc2015day02.import.scm

aoc2015day02.import.so: aoc2015day02.so
    $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) aoc2015day02.import.scm

I tried a small change to the advent2015 target by specifying a wildcard in the so files it is using, but make completely skipped generating the targets.


Solution

  • No problem:

    DAYS := 01 02 03 04 <...> 24 25
    
    all: advent2015
    
    advent2015: $(ADVENTS_SRC)2015/advent2015.scm \
         $(foreach D,$(DAYS),aoc2015day$(D).so)
            $(CSC) $(INCLUDE_FLAGS) $< -d3 -O2 -compile-syntax -o $@
    
    %.so: $(ADVENTS_SRC)2015/%.scm aoc-files.so
            $(CSC) $(INCLUDE_FLAGS) $(LIBFLAGS) $< -j $* -emit-types-file $*.types -o $@
            $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) $*.import.scm
    
    %.import.so: %.so
            $(CSC) $(INCLUDE_FLAGS) $(IMPORTFLAGS) $*.import.scm
    

    I'm not sure these commands are actually correct but they're what you provided above, so you can fix them if not.