Skip to content

Commit

Permalink
make: create target directory if symlinked
Browse files Browse the repository at this point in the history
Handles the case where the build directory is a symbolic link
to another directory and the target directory does not exist.

This allows seamlessly building lone in RAM using tmpfs by simply
creating a symbolic link to a non-existent directory of a mounted
RAM file system.

  ln -s /tmp/lone/build
  ln -s /run/user/1000/lone/build
  • Loading branch information
matheusmoreira committed Sep 15, 2024
1 parent 0194c20 commit ba1bb7a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ source_to_test = $(patsubst $(directories.source.tests)/%.c,$(directories.build.

ARCH := $(TARGET)

directories.build := build/$(ARCH)
directories.build.root := build
directories.build := $(directories.build.root)/$(ARCH)
directories.build.tools := $(directories.build)/tools
directories.build.tests := $(directories.build)/tests
directories.build.objects := $(directories.build)/objects
Expand Down Expand Up @@ -156,6 +157,7 @@ test: tests lone tools

targets.phony += directories
directories:
scripts/create-symlinked-directory.bash $(directories.build.root)
mkdir -p $(sort $(directories.create))

.PHONY: $(targets.phony)
Expand Down
9 changes: 9 additions & 0 deletions scripts/create-symlinked-directory.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/bash

directory="${1}"
linked="$(readlink "${directory}")"
result="${?}"

if [[ "${result}" -eq 0 && ! -d "${linked}" ]]; then
mkdir -p "${linked}"
fi

0 comments on commit ba1bb7a

Please sign in to comment.