snestracker icon indicating copy to clipboard operation
snestracker copied to clipboard

SDL_GetBasePath() on Linux installation not sufficient

Open OPNA2608 opened this issue 4 years ago • 3 comments

I'm currently cobbling together a test-expression for including snestracker in Nixpkgs, and I'm running into some problems. One of them being the use of SDL_GetBasePath() to find assets, which doesn't play nice with the way these are usually spread out on a Linux system.

(The way package contents are usually distributed in the Linux FHS)
  • Binaries get moved to a /bin directory under a prefix, e.g. /bin with an empty prefix, /usr/local/bin with prefix /usr/local. In the case of Nix, this would be something like /nix/store/<hash>-snestracker-unstable-20200610/bin/

  • Global assets get moved to a /share directory under said prefix. Where exactly they end up depends on their specific use-case, but application-specific assets often go to $prefix/share/<applicationName>. For instance, I'm moving the cursors directory and tracker.spc to /nix/store/<hash>-snestracker-unstable-20200610/share/snestracker/

When std starts up, it calls SDL_GetBasePath() to find the cursor assets. SDL_GetBasePath() however leads to the directory the executable resides in, which in a properly system-installed package is not where the assets would reside in.

My really ugly workaround right now is keeping the binaries in /share/snestracker and symlinking them into the appropriate /bin directory, which gets the application further ~~but seemingly nowhere near a proper launch~~. Are there plans to improve this? A simple ../share/snestracker/ appended to the path returned by SDL_GetBasePath() via an ifdef + instructions for packagers to put the assets in such a relative directory would be a quite simple fix for this particular problem, but maybe there are smarter ways of solving this.

OPNA2608 avatar Jun 12 '20 22:06 OPNA2608

Hi, once again thanks for your time and energy. I can tell you put great care into this.

Another path that snestracker uses is the pref_path. Start up std and read the start of its debug printout what the pref_path is.

I imagine providing a FHS_PACKAGE=1 make which assigns path appropriately for a FHS (Filesystem Hierarchy Standard) environment.

Quick Thoughts on Build System

This seems to also relate to snestracker's build system, which I am holding off on migration to cmake or automake for the foreseeable future, so I can invest my time into the most important part first - making a great tracker.

bazz1tv avatar Jun 13 '20 06:06 bazz1tv

(updated my comment)

bazz1tv avatar Jun 13 '20 06:06 bazz1tv

pref_path won't fly as a replacement, if that's what you're suggesting. This points to a user-specific preference directory. It should be searched for user-specific overrides of the application settings, but not for the base assets. For example,

pref_path = /home/myuser/.local/share/Black_Hole_Studios/SNES_Tracker/

A proper build system with dependency detection would be greatly appreciated in the future, as I currently have to patch several bits of the codebase to get it through the compilation process.

(A glimpse into the expression, maybe you can spot any obvious bad changes)
  patchPhase = ''
    # Fix references to /bin/bash.
    patchShebangs $PWD
    # Remove "hotlinking" attempt.
    substituteInPlace Makefile \
      --replace 'make -C submodules/libgme_m install-lib-direct' 'echo "skipping hotlink attempt"'
    # Add additional error degradation switch, otherwise compilation failure.
    substituteInPlace pc/Makefile \
      --replace '-Wall' '-Wall -Wno-error=format-security'
  '';

  preBuild = ''
    # We skip executing the submodules script
    # because wrapping them as separate nix derivations
    # means greater freedom in adjusting them
    # and building in parallel.
    # Remove unpopulated submodule stubs and
    # link to the compiled derivations + relevant directory of these instead.
    rm -r submodules/{libgme_m,pcx2snes}
    ln -s ${libgme_m}/lib submodules/libgme_m
    ln -s ${pcx2snes}/bin submodules/pcx2snes

    # Fix build being unable to compile & link against GTK
    # due to missing dependency tracking by
    # the build system.
    NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $(pkg-config gtk+-2.0 --cflags)"
    NIX_LDFLAGS="$NIX_LDFLAGS $(pkg-config gtk+-2.0 --libs)"
  '';

  # Settings to override Makefile defaults.
  buildFlags = [ 
    "prefix=${placeholder "out"}"
    "gme_PREFIX=${libgme_m}/include"
    "WLAPREFIX=${wla-dx}/bin/"
    "PCX2SNES_PREFIX=${pcx2snes}/bin/"
  ];

  # Missing install target in Makefile
  # Binaries need to be linked from shared/snestracker
  # into bin due to https://github.com/bazzinotti/snestracker/issues/60
  installPhase = ''
    mkdir -p $out/{bin,share}
    mv ./pc/bin $out/share/snestracker
    for exe in {7zDec,st,std,unrar}; do
      ln -s $out/share/snestracker/$exe $out/bin/$exe
    done
  '';

But as long as it's on your "should be done, eventually" list, it's fine.

OPNA2608 avatar Jun 13 '20 09:06 OPNA2608