rmyorston / pdpmake

Public domain POSIX make
https://frippery.org/make
Other
103 stars 10 forks source link

Implementing VPATH #29

Open absolutelynothinghere opened 9 months ago

absolutelynothinghere commented 9 months ago

Hello 👋

Are there plans to implement VPATH in pdpmake? It would facilitate making out-of-tree builds.

Thank you.

rmyorston commented 9 months ago

Hi, there aren't any immediate plans for VPATH, but I'll put it on the (imaginary) roadmap.

xparq commented 8 months ago

I've just experimented with a very simple, but effective ("high-yield") change that enables out-of-tree builds for a lot of common cases, covering some fairly decent ground by a straightforward extension to inference rules. In addition to

.c.o:

you can also write

src/%.c.o:

And it does what you'd expect. (Well, if your expectations are curbed...: it's not a real pattern (yet), just a placeholder for the target's name + path.)

(It was made possible by the very clean and simple pdpmake implementation, where everything just clicked nicely. It's like a chess board with lots of "resources", potential nice moves that you can make later, when the need comes.)

This alone already makes it possible to build entire source trees (with auto-scanned sources) into a separate output tree with trivial little makefiles (with some minor little extra hand-holding, until further refinements), like this:

PROGRAM = test
SRC = src
OUT = out

# --- No edits needed below

sources != find $(SRC) -name '*.c'
objs = $(sources:$(SRC)/%.c=$(OUT)/%.o)

all: linktree # See below...

$(PROGRAM): $(objs)
    $(CC) $^ -o $@

$(SRC)/%.c.o:
    @mkdir -p `dirname $@`
    $(CC) -c $< -o $@

# Workaround for the current rigid out/%.o -> src/out/%.c name inference:
linktree: mk_treelink .WAIT $(PROGRAM) .WAIT rm_treelink
mk_treelink:; @if [ ! -e $(SRC)/$(OUT) ]; then ln -s '.' $(SRC)/$(OUT); fi
rm_treelink:; @if [   -L $(SRC)/$(OUT) ]; then rm        $(SRC)/$(OUT); fi

Details, diff


Ron, I'm not suggesting that this should be merged as-is (partly because my understanding of pdpmake is still ridiculously limited, partly because GNU-like pattern rules would be preferable, albeit not as simple), but an identical/similar feature that could do this would indeed be a huge usability boost.