From c6807ca55bc772f4d2bb3de40e6d155034ed17c5 Mon Sep 17 00:00:00 2001 From: Matheus Moreira Date: Mon, 1 Mar 2021 03:32:50 -0300 Subject: [PATCH] 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. --- Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 76ec679cc..153e1d4a8 100644 --- a/Makefile +++ b/Makefile @@ -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 \