xparq / bbmake

Tinkering with rmyorston's pdpmake
https://frippery.org/make
Other
0 stars 0 forks source link

Path-aware inference rules #1

Closed xparq closed 1 year ago

xparq commented 1 year ago

Making inference rules work even if the target and prerequisite are not in the same dir (i.e. they differ also in their path, not just their suffixes) would enable (or vastly simplify) some important practical use cases (i.e. building outside the source tree, without tedious workarounds).

It adds support for path prefixes to implicit prerequisite names (e.g. src/), via an extended inference rule syntax:

test: x.o
src/%.c.o:
    @echo "YAY, path-aware inf. rules!!! $< -> $@"

While this is a vague & incomplete approximation of NMAKE's path-extended inference rules, it could be a "high-gain" first stage toward proper pattern rules a'la GNU make (#2)...

Accordingly, it already uses the % pattern-matching placeholder in the rule definitions, for a (kinda-sorta) forward-compatible approach. However, limitations currently:


TODO:


NOTES:

xparq commented 1 year ago

BTW, this alone already makes it possible to build an entire source tree, auto-scanned, into a separate output tree (with some minor little extra hand-holding):

PROGRAM = test
SRC = src
OUT = out

# --- No edits needed below

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

all: linktree_kludge # See below...

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

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

# Work around the current rigid out/%.o -> src/out/%.c name inference:
linktree_kludge: 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