Allow make install under FreeDesktop

This commit is contained in:
Lior Halphon 2021-02-27 04:13:50 +02:00
parent 0a983b788e
commit 2b263937da
22 changed files with 56 additions and 6 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -0,0 +1,12 @@
[Desktop Entry]
Version=1.0
Type=Application
Icon=sameboy
Exec=sameboy
Name=SameBoy
Comment=Game Boy and Game Boy Color emulator
Keywords=game;boy;gameboy;color;emulator
Terminal=false
StartupNotify=false
Categories=Application;Game;
MimeType=application/x-gameboy-rom;application/x-gameboy-color-rom

View File

@ -30,6 +30,14 @@ else
DEFAULT := sdl DEFAULT := sdl
endif endif
ifneq ($(shell which xdg-open),)
# Running on an FreeDesktop environment, configure for (optional) installation
DESTDIR ?=
PREFIX ?= /usr/local
DATA_DIR ?= $(PREFIX)/share/sameboy/
CAN_INSTALL := true
endif
default: $(DEFAULT) default: $(DEFAULT)
ifeq ($(MAKECMDGOALS),) ifeq ($(MAKECMDGOALS),)
@ -421,6 +429,33 @@ $(BIN)/BootROMs/%.bin: BootROMs/%.asm $(OBJ)/BootROMs/SameBoyLogo.pb12
libretro: libretro:
CFLAGS="$(WARNINGS)" $(MAKE) -C libretro CFLAGS="$(WARNINGS)" $(MAKE) -C libretro
# install for Linux/FreeDesktop/etc.
# Does not install mimetype icons because FreeDesktop is cursed abomination with no right to exist.
# If you somehow find a reasonable way to make associate an icon with an extension in this dumpster
# fire of a desktop environment, open an issue or a pull request
ifneq ($(CAN_INSTALL),)
ICON_NAMES := apps/sameboy
ICON_SIZES := 16x16 32x32 64x64 128x128 256x256 512x512
ICONS := $(foreach name,$(ICON_NAMES), $(foreach size,$(ICON_SIZES),$(DESTDIR)$(PREFIX)/share/icons/hicolor/$(size)/$(name).png))
install: sdl $(DESTDIR)$(PREFIX)/share/applications/sameboy.desktop $(ICONS)(PREFIX)/share/mime/application/x-gameboy-color-rom.xml
mkdir -p $(DESTDIR)$(PREFIX)/share/sameboy/
cp -rf $(BIN)/SDL/* $(DESTDIR)$(PREFIX)/share/sameboy/
mv $(DESTDIR)$(PREFIX)/share/sameboy/sameboy $(DESTDIR)$(PREFIX)/bin/sameboy
ifeq ($(DESTDIR),)
-xdg-icon-resource forceupdate --mode system
-xdg-desktop-menu forceupdate --mode system
endif
$(DESTDIR)$(PREFIX)/share/icons/hicolor/%/apps/sameboy.png: FreeDesktop/AppIcon/%.png
-@$(MKDIR) -p $(dir $@)
cp -f $^ $@
$(DESTDIR)$(PREFIX)/share/applications/sameboy.desktop: FreeDesktop/sameboy.desktop
-@$(MKDIR) -p $(dir $@)
cp -f $^ $@
endif
# Clean # Clean
clean: clean:
rm -rf build rm -rf build

View File

@ -1,13 +1,11 @@
#include <SDL.h> #include <SDL.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "utils.h" #include "utils.h"
const char *resource_folder(void) static const char *resource_folder(void)
{ {
#ifdef DATA_DIR
return DATA_DIR;
#else
static const char *ret = NULL; static const char *ret = NULL;
if (!ret) { if (!ret) {
ret = SDL_GetBasePath(); ret = SDL_GetBasePath();
@ -16,13 +14,19 @@ const char *resource_folder(void)
} }
} }
return ret; return ret;
#endif
} }
char *resource_path(const char *filename) char *resource_path(const char *filename)
{ {
static char path[1024]; static char path[1024];
snprintf(path, sizeof(path), "%s%s", resource_folder(), filename); snprintf(path, sizeof(path), "%s%s", resource_folder(), filename);
#ifdef DATA_DIR
if (access(path, F_OK) == 0) {
return path;
}
snprintf(path, sizeof(path), "%s%s", DATA_DIR, filename);
#endif
return path; return path;
} }

View File

@ -2,7 +2,6 @@
#define utils_h #define utils_h
#include <stddef.h> #include <stddef.h>
const char *resource_folder(void);
char *resource_path(const char *filename); char *resource_path(const char *filename);
void replace_extension(const char *src, size_t length, char *dest, const char *ext); void replace_extension(const char *src, size_t length, char *dest, const char *ext);