mickelson / attract

A graphical front-end for command line emulators that hides the underlying operating system and is intended to be controlled with a joystick or gamepad.
http://attractmode.org
GNU General Public License v3.0
393 stars 113 forks source link

Please make it easier to make the DATA_PATH directory relative #754

Open duganchen opened 4 months ago

duganchen commented 4 months ago

Okay, use case first.

I want to build Attract Mode for my Steam Deck, but I don't want to build it on my Steam Deck because that would involve enabling Developer Mode, setting the filesystem to be read-write, and, well, making those intrusive changes. Instead, I want to build it on another machine (using Docker, of course), smoke-test it on that machine (where my username isn't "deck"), copy the output directory to my Steam Deck's home directory, and then add it to Steam as a non-Steam game. So, in the end, my Steam Deck would have:

The lib directory can be dealt with using patchelf (I know I should be able to do this with an environment variable, but I couldn't get that to work):

patchelf --set-rpath \$ORIGIN/../lib /path/to/attract-2.7.0/bin/attract

(Reference: https://stackoverflow.com/questions/13769141/can-i-change-rpath-in-an-already-compiled-binary)

The share directory location, well, that's why I entered the ticket. I want Attract Mode to look for it in a place relative to the executable location. The only way I could get that to work was by patching the Makefile:

diff '--color=auto' -rupN attract-2.7.0.orig/Makefile attract-2.7.0/Makefile
--- attract-2.7.0.orig/Makefile 2023-06-10 12:32:15.000000000 -0700
+++ attract-2.7.0/Makefile      2024-02-19 21:12:09.231851985 -0800
@@ -784,13 +784,13 @@ $(GSBASE_OBJ_DIR)/%.o: $(EXTLIBS_DIR)/ga
 $(GSBASE_OBJ_DIR):
        $(MD) $@

-$(DATA_PATH):
+$(datarootdir):
        $(MD) -p $(DESTDIR)$@

-install: $(EXE) $(DATA_PATH)
+install: $(EXE) $(datarootdir)
        install -D $(EXE) $(DESTDIR)$(bindir)/$(EXE)
-       mkdir -p $(DESTDIR)$(DATA_PATH)
-       cp -r config/* $(DESTDIR)$(DATA_PATH)
+       mkdir -p $(datarootdir)/attract
+       cp -r config/* $(datarootdir)/attract

 smallclean:
        -$(RM) $(OBJ_DIR)/*.o *~ core

I don't know if I did it exactly right, but that does work. My build command line is then:

make install prefix=/output/attract-2.7.0 datadir=../share

Reference: https://stackoverflow.com/questions/9654062/tell-a-configure-script-to-use-a-relative-path-for-datarootdir

The point is is that it would be nice to have an easier way of making the executable look for DATA_PATH in a relative location, and not an absolute one.

This would also make it easier to build, say, an AppImage, which needs the executable to look for data in paths that are relative to the executable location.