cococry / leif

Minimal, configurable & GPU accelerated Immediate Mode UI Library written with modern OpenGL
794 stars 32 forks source link

Issue with the Makefile #5

Closed the-fuckin-nobody closed 4 months ago

the-fuckin-nobody commented 4 months ago

Found out this while trying to run your music player lyssa, the error is :

[LEIF ERROR]: Failed to open font file '/home/dex/.leif/assets/fonts/inter.ttf'

Then I looked at the Makefile for leif. The install section of the Makefile tries to copy the .leif directory to ~/, See here:

install:
    cp lib/libleif.a /usr/local/lib/ 
    cp -r include/leif /usr/local/include/ 
    cp -r .leif ~/

The intended behavior is that to copy the .leif directory to user's home dir, but when used with sudo command, due to privilege escalation, the .leif directory gets copied to root's home, .i.e /root/, So when I try to run lyssa, it gives the aforementioned error, since there is no .leif directory in the user's home, it is in root's home instead. Same error is with lyssa's Makefile too , the .lyssa directory get's copied to root's home , rather than user's home. Don't know if this is intentional but since the binary is looking for the dotfile in the user's home instead of root's home, I raised this issue.

Steps to reproduce:

run sudo make install run lyssa

cococry commented 4 months ago

thank you for pointing that, out i fixed the mistake in the last commit.

the-fuckin-nobody commented 4 months ago

Yeah this seems good and fixes issues with sudo make install, but what if someone runs sudo make instead of just make it would still result in copying to the wrong path. Maybe add a note in the README.md , to not run sudo make or maybe just change the whole idea of using the ~/.leif directory and instead use some dir in /usr/local/... dir so, an absolute path is used instead. I'm happy to help with a PR for that if you're busy or smth. It just requires changing some strings in leif.c lol .

LfFont lf_load_font_asset(const char* asset_name, const char* file_extension, uint32_t font_size) {
  char leif_dir[strlen(getenv(HOMEDIR)) + strlen("/.leif")];    // <--- here 
  memset(leif_dir, 0, sizeof(leif_dir)); //<---maybe here
  strcat(leif_dir, getenv(HOMEDIR)); //<---- here
  strcat(leif_dir, "/.leif");// <----  and here too

I do not want to sound too much complaining , but its good to avoid tilde expansion paths in the Makefile. Great work on this project.

cococry commented 4 months ago

If you could open a PR i would greatly appreciate that. New contributors are always welcome :)

the-fuckin-nobody commented 4 months ago

Sorry couldn't add a PR due to some issues IRL. As the install.sh script provided fixes this issue, I'm closing this one :-)