Makefile: ensure linked output directory exists

Building in RAM is faster and reduces wear on storage devices.
This can be achieved by symlinking the output directory to a tmpfs location:

    ln -s /tmp/cosmopolitan/o o
    ln -s $XDG_RUNTIME_DIR/cosmopolitan/o o

In most Linux distributions, there is a tmpfs mounted at /tmp.
Distributions using systemd also provide a tmpfs mounted at /run
with private directories for every user at /run/user/$UID.
The XDG_RUNTIME_DIR environment variable usually points to this directory.

These file systems are ephemeral: the whole tree is lost when it is unmounted.
This may cause build errors if the link points to a directory that no longer exists.
It is therefore necessary to ensure its existence.
This commit is contained in:
Matheus Moreira 2021-03-01 03:32:50 -03:00 committed by GitHub
parent 5e069a64d4
commit c6807ca55b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -70,6 +70,15 @@ GNUMAKEFLAGS += --output-sync
.FEATURES: output-sync
.PHONY: all o bins check test depend tags
# If the output directory is a symbolic link, make sure the target directory exists.
# This makes it easy to build on tmpfs:
#
# ln -s /tmp/cosmopolitan/o o
# ln -s $XDG_RUNTIME_DIR/cosmopolitan/o o
#
output_directory_link := $(shell readlink o)
$(if $(output_directory_link),$(shell mkdir -p $(output_directory_link)))
all: o
o: o/$(MODE)/ape \
o/$(MODE)/dsp \