Rick Eyre
Rick Eyre

Reputation: 2475

How to write a makefile

Okay so what needs to be done is that the makefile must compile a .test into a .vtt only when it's .test has changed since the most recent build. I don't have the paths to the .test files directly but I can get a list of them and the supposed path to the new .vtt file can be generated from that. What I have so far is:

SRC_DIR = .
TEST_DIR = $(SRC_DIR)/test
SPEC_DIR = $(TEST_DIR)/spec
OBJ_DIR = $(SRC_DIR)/objdir
OBJ_DIR_SPEC = $(OBJ_DIR)/test/spec
TEST_SRC := $(shell find $(SPEC_DIR) -name '*.test' -print)                                                                    
VTT_SRC := $(subst $(SRC_DIR)/test,$(OBJ_DIR)/test,$(subst .test,.vtt,$(TEST_SRC)))   
RUN_STIP_VTT = $(SPEC_DIR)/strip-vtt.py

%.vtt : %.test:
   $(PYTHON) $(RUN_STIP_VTT) $< $@

$(VTT_SRC): $(TEST_SRC)
   $(PYTHON) $(RUN_STIP_VTT) $< $@

objdir:
    mkdir $(OBJ_DIR)

check-js: objdir $(VTT_SRC)
    $(PYTHON) ./test/spec/run-tests-js.py $(OBJ_DIR_SPEC)

TEST_SOURCE is a list of the .test files that have been found. VTT_SOURCE is a list of the transformed test files into the .vtt format underneath and object directory. I need to be able to find the .vtt files dependency .test file in the TEST_SOURCE and somehow tell the makefile about that connection.

Ended up fixing it with these changes:

check-js: objdir $(VTT_SRC)
        $(PYTHON) ./test/spec/run-tests-js.py $(OBJ_DIR_SPEC)

$(OBJ_DIR)/%.vtt : $(SRC_DIR)/%.test
    @$(PYTHON) $(STIP_VTT) $< $@

Upvotes: 1

Views: 206

Answers (2)

Beta
Beta

Reputation: 99164

I'd use a static pattern rule:

$(VTT_SRC): $(OBJ_DIR)/%.vtt : $(SRC_DIR)/%.test
    $(PYTHON) $(RUN_STIP_VTT) $< $@

Upvotes: 2

Phil Miller
Phil Miller

Reputation: 38148

The VPATH construct in Make is probably what you're looking for.

Upvotes: 0

Related Questions