Skip to content

Commit 07827ff

Browse files
committed
Make style.json runtime path configurable via PREFIX
style.cpp's getConfigPath() searches three hardcoded paths for the plugin's style.json. The second of these was a literal /usr/local/etc/magnetophon/style/style.json, which downstream packagers (Nix, distros installing to non-/usr/local prefixes) had to rewrite via sed/substituteInPlace to point at their actual install location. Replace the hardcoded literal with a MAGNETOPHON_SYSCONFDIR compile-time macro, fallback /usr/local/etc/magnetophon. The top-level Makefile derives this from $(PREFIX)/etc/$(pkgname) and passes it to the common sub-make as SYSCONFDIR, which adds -DMAGNETOPHON_SYSCONFDIR="$(SYSCONFDIR)" to style.cpp's compile line specifically. C++ adjacent string literal concatenation then joins the path with '/style/style.json' at the call site. Use runtime_sysconfdir = $(PREFIX)/etc rather than $(sysconfdir) = $(DESTDIR)$(PREFIX)/etc, because the compile-time path should reflect where the file ends up after installation, not where a staged install temporarily writes it. Also switch the shebangs of generate-ttl.sh and patch/apply.sh from #!/bin/bash to #!/usr/bin/env bash. Both scripts are POSIX-compatible anyway; env-based shebangs work uniformly across build environments (Nix sandbox, BSD, macOS-with-Homebrew-bash) without requiring patchShebangs. Allows the nixpkgs derivation to drop both substituteInPlace and patchShebangs from its postPatch hook, and switch installFlags to makeFlags so PREFIX reaches both the build (for the macro) and the install (for destination paths).
1 parent b3da7aa commit 07827ff

5 files changed

Lines changed: 35 additions & 5 deletions

File tree

plugin/dpf/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ vst3dir ?= $(DESTDIR)$(PREFIX)/lib/vst3
6262
clapdir ?= $(DESTDIR)$(PREFIX)/lib/clap
6363
bindir ?= $(DESTDIR)$(PREFIX)/bin
6464
sysconfdir ?= $(DESTDIR)$(PREFIX)/etc
65+
# Where installed config files will be found at runtime, excluding any
66+
# DESTDIR staging prefix (which only affects where the install step
67+
# writes them, not where the running binary looks for them). Compile
68+
# time uses this; install time uses $(sysconfdir) above.
69+
runtime_sysconfdir ?= $(PREFIX)/etc
6570
datarootdir ?= $(DESTDIR)$(PREFIX)/share
6671
datadir ?= $(datarootdir)
6772
docdir ?= $(datarootdir)/doc
@@ -72,7 +77,7 @@ dpf: patch
7277

7378
.PHONY: common
7479
common: dpf
75-
$(MAKE) -C common
80+
$(MAKE) -C common SYSCONFDIR=$(runtime_sysconfdir)/$(pkgname)
7681

7782
.PHONY: DigiDrie
7883
DigiDrie: common

plugin/dpf/common/Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
BUILD_DIR = ../build/common
22

3+
# Where style.json will live at runtime (excluding any DESTDIR staging
4+
# prefix). Set by the top-level Makefile from $(PREFIX)/etc/$(pkgname);
5+
# overridable if invoking this sub-make directly.
6+
SYSCONFDIR ?= /usr/local/etc/magnetophon
7+
8+
CXXFLAGS_COMMON = -Wall -std=c++17 -O3 -fPIC
9+
310
OBJ := \
411
$(BUILD_DIR)/gui/style.o \
512
$(BUILD_DIR)/gui/TinosBoldItalic.o \
613

714
build: $(OBJ)
815

16+
# style.cpp's runtime path lookup is configured at compile time via
17+
# MAGNETOPHON_SYSCONFDIR. The shell sees the \" sequences and turns
18+
# them into literal " characters, so g++ sees -DMACRO="value", which
19+
# in turn defines the macro as a C string literal.
20+
$(BUILD_DIR)/gui/style.o : gui/style.cpp
21+
@mkdir -p $(dir $@)
22+
g++ $(CXXFLAGS_COMMON) -DMAGNETOPHON_SYSCONFDIR=\"$(SYSCONFDIR)\" -c -o $@ $<
23+
924
$(BUILD_DIR)/%.o : %.cpp
1025
@mkdir -p $(dir $@)
11-
g++ -Wall -std=c++17 -O3 -fPIC -c -o $@ $<
26+
g++ $(CXXFLAGS_COMMON) -c -o $@ $<

plugin/dpf/common/gui/style.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ inline fs::path getXdgConfigHome()
4545
return fs::path("");
4646
}
4747

48+
// The local-prefix system config path is set at compile time so that
49+
// downstream packagers (Nix, distros installing to a non-/usr/local
50+
// PREFIX, etc.) can point this lookup at their actual install location
51+
// via -DMAGNETOPHON_SYSCONFDIR=... The third lookup below (/etc) and
52+
// the first ($XDG_CONFIG_HOME) are intentionally hardcoded — those are
53+
// standard system / user paths that don't follow a build-time prefix.
54+
#ifndef MAGNETOPHON_SYSCONFDIR
55+
# define MAGNETOPHON_SYSCONFDIR "/usr/local/etc/magnetophon"
56+
#endif
57+
4858
inline void logNotExist(fs::path path)
4959
{
5060
std::cerr << path << " is not regular file or doesn't exist.\n";
@@ -56,7 +66,7 @@ inline fs::path getConfigPath()
5666
if (fs::is_regular_file(styleJsonPath)) return styleJsonPath;
5767
logNotExist(styleJsonPath);
5868

59-
styleJsonPath = fs::path("/usr/local/etc/magnetophon/style/style.json");
69+
styleJsonPath = fs::path(MAGNETOPHON_SYSCONFDIR "/style/style.json");
6070
if (fs::is_regular_file(styleJsonPath)) return styleJsonPath;
6171
logNotExist(styleJsonPath);
6272

plugin/dpf/generate-ttl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
set -e
44

plugin/dpf/patch/apply.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# Note that this script assumes patch will be applied correctly.
44
#

0 commit comments

Comments
 (0)