Back to repository
Lesson 6cd3401Entered Environment8/10

Enter a repository-shaped shell

Add make enter as an interactive entry point that exposes already-installed repository-local tools inside a child shell.

01

Apply earlier policy before enter defaults

The root Makefile includes enter.mk after global policy, aggregate targets, and toolchain wiring. The position is mainly an ownership signal and gives earlier modules an opportunity to define any ENTER_* value before a later ?= default is encountered.

A separate rule applies to recipes: Make finishes reading every included file before it expands a recipe that is needed. Recipe-time values and exported variables can therefore come from any parsed module, regardless of whether its include appears before or after the recipe text.

Makefile:18-35

14 focused lines

Loading source...
02

Keep entry parameters overridable

This first version gives the prompt label and shell command conditional defaults. An earlier module or a command-line assignment can provide either value because ?= assigns only when the variable is still undefined.

The enter name represents an action rather than a file, so .PHONY keeps a same-named filesystem entry from satisfying it.

make/enter.mk:8-26

12 focused lines

Loading source...
03

Put repository-local commands first in the child

The recipe prepends .local/bin only when it is not already the first PATH entry. That gives already-installed repository tools precedence without installing anything as part of make enter.

The doubled dollar signs preserve ${PATH-}, ${PATH:+...}, and $PATH for shell expansion. The assignment and export happen inside the recipe process, so the caller's parent shell remains unchanged.

make/enter.mk:28-61

21 focused lines

Loading source...
04

Replace the recipe shell with the entered shell

The final exec replaces Make's recipe shell with the selected interactive shell. No dormant wrapper remains to run later commands or replace the entered shell's eventual status.

Exiting that process completes the recipe and returns control to the original parent shell, whose PATH was never modified.

make/enter.mk:46-62

10 focused lines

Loading source...

Compare the child and parent PATH values

The replay starts in /work/makefile-fyi; interactive prompt decoration is omitted so the environment boundary stays visible.

step 1/5
interactive replay

Select the terminal to begin, or choose Auto-fill.

Finished this lesson?

Completion is saved on this device and used to resume the course.