diff options
| -rw-r--r-- | Makefile | 40 |
1 files changed, 32 insertions, 8 deletions
| @@ -67,6 +67,21 @@ APPIMAGETOOL_SHA256 := ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3c | |||
| 67 | # RANDOMX_DIR=... explicitly; the recipe below will still never delete a | 67 | # RANDOMX_DIR=... explicitly; the recipe below will still never delete a |
| 68 | # directory that lacks the marker file this build writes after a successful | 68 | # directory that lacks the marker file this build writes after a successful |
| 69 | # build. Exported so src/Makefile's own RANDOMX_DIR ?= picks the same tree. | 69 | # build. Exported so src/Makefile's own RANDOMX_DIR ?= picks the same tree. |
| 70 | # | ||
| 71 | # Every use of it below is quoted, and the recipe rejects a value that cannot | ||
| 72 | # name exactly one directory before it reaches anything destructive. Unquoted, | ||
| 73 | # the marker guard could be stepped around: a value holding a glob that matches | ||
| 74 | # two directories made `[ -d $(RANDOMX_DIR) ]` a two-argument test, which dies | ||
| 75 | # with "unexpected operator" instead of answering, so the && short-circuited, | ||
| 76 | # the guard was skipped, and the rm -rf below ran against every match. A value | ||
| 77 | # holding a space or a `&&` broke the outer test the same way and reported | ||
| 78 | # "already built". Whitespace and glob characters are refused outright rather | ||
| 79 | # than merely quoted, because src/Makefile interpolates this same value into | ||
| 80 | # -I$(RANDOMX_DIR)/src and -L$(RANDOMX_DIR)/build unquoted, where neither can | ||
| 81 | # survive. A relative value is refused rather than silently made absolute: it | ||
| 82 | # would mean two different directories to this Makefile and to src/Makefile, | ||
| 83 | # whose cwd is src/, and a command-line assignment reaches the sub-make through | ||
| 84 | # MAKEFLAGS, where it outranks anything exported from here. | ||
| 70 | RANDOMX_DIR ?= $(ROOT)/randomx-build | 85 | RANDOMX_DIR ?= $(ROOT)/randomx-build |
| 71 | export RANDOMX_DIR | 86 | export RANDOMX_DIR |
| 72 | 87 | ||
| @@ -126,25 +141,34 @@ deps-secp256k1: | |||
| 126 | fi | 141 | fi |
| 127 | 142 | ||
| 128 | deps-randomx: | 143 | deps-randomx: |
| 129 | @if [ ! -f $(RANDOMX_DIR)/build/librandomx.a ]; then \ | 144 | @ws="$$(printf ' \t')"; \ |
| 130 | if [ -d $(RANDOMX_DIR) ] && [ ! -f $(RANDOMX_DIR)/.bitflash-built ]; then \ | 145 | case "$(RANDOMX_DIR)" in \ |
| 146 | "") echo "ERROR: RANDOMX_DIR is empty"; exit 1 ;; \ | ||
| 147 | /) echo "ERROR: RANDOMX_DIR is /, refusing"; exit 1 ;; \ | ||
| 148 | *[$$ws]*) echo "ERROR: RANDOMX_DIR contains whitespace: $(RANDOMX_DIR)"; exit 1 ;; \ | ||
| 149 | *[*?[]*) echo "ERROR: RANDOMX_DIR contains a glob character: $(RANDOMX_DIR)"; exit 1 ;; \ | ||
| 150 | /*) ;; \ | ||
| 151 | *) echo "ERROR: RANDOMX_DIR must be an absolute path: $(RANDOMX_DIR)"; exit 1 ;; \ | ||
| 152 | esac | ||
| 153 | @if [ ! -f "$(RANDOMX_DIR)/build/librandomx.a" ]; then \ | ||
| 154 | if [ -d "$(RANDOMX_DIR)" ] && [ ! -f "$(RANDOMX_DIR)/.bitflash-built" ]; then \ | ||
| 131 | echo "ERROR: $(RANDOMX_DIR) exists but was not created by this build"; \ | 155 | echo "ERROR: $(RANDOMX_DIR) exists but was not created by this build"; \ |
| 132 | echo " refusing to rm -rf it -- remove it yourself or set RANDOMX_DIR"; \ | 156 | echo " refusing to rm -rf it -- remove it yourself or set RANDOMX_DIR"; \ |
| 133 | exit 1; \ | 157 | exit 1; \ |
| 134 | fi; \ | 158 | fi; \ |
| 135 | echo "==> building RandomX"; \ | 159 | echo "==> building RandomX"; \ |
| 136 | rm -rf $(RANDOMX_DIR); \ | 160 | rm -rf "$(RANDOMX_DIR)" && \ |
| 137 | git init -q $(RANDOMX_DIR); \ | 161 | git init -q "$(RANDOMX_DIR)" && \ |
| 138 | cd $(RANDOMX_DIR) && \ | 162 | cd "$(RANDOMX_DIR)" && \ |
| 139 | git remote add origin $(RANDOMX_REPO) && \ | 163 | git remote add origin $(RANDOMX_REPO) && \ |
| 140 | git fetch -q --depth 1 origin $(RANDOMX_COMMIT) && \ | 164 | git fetch -q --depth 1 origin $(RANDOMX_COMMIT) && \ |
| 141 | git checkout -q --detach FETCH_HEAD && \ | 165 | git checkout -q --detach FETCH_HEAD && \ |
| 142 | test "$$(git rev-parse HEAD)" = "$(RANDOMX_COMMIT)" && \ | 166 | test "$$(git rev-parse HEAD)" = "$(RANDOMX_COMMIT)" && \ |
| 143 | echo "==> RandomX pinned at $(RANDOMX_COMMIT)" && \ | 167 | echo "==> RandomX pinned at $(RANDOMX_COMMIT)" && \ |
| 144 | mkdir -p $(RANDOMX_DIR)/build && \ | 168 | mkdir -p "$(RANDOMX_DIR)/build" && \ |
| 145 | cd $(RANDOMX_DIR)/build && cmake .. -DCMAKE_BUILD_TYPE=Release && \ | 169 | cd "$(RANDOMX_DIR)/build" && cmake .. -DCMAKE_BUILD_TYPE=Release && \ |
| 146 | make -j$(NPROC) randomx && \ | 170 | make -j$(NPROC) randomx && \ |
| 147 | touch $(RANDOMX_DIR)/.bitflash-built && \ | 171 | touch "$(RANDOMX_DIR)/.bitflash-built" && \ |
| 148 | echo "==> RandomX done"; \ | 172 | echo "==> RandomX done"; \ |
| 149 | else \ | 173 | else \ |
| 150 | echo "==> RandomX already built"; \ | 174 | echo "==> RandomX already built"; \ |