Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add appimage build target #398

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FreeDesktop/sameboy.png
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ ifdef DATA_DIR
CFLAGS += -DDATA_DIR="\"$(DATA_DIR)\""
endif

APPIMAGE_BUILD ?=

ifdef APPIMAGE_BUILD
CFLAGS += -DAPPIMAGE_BUILD
endif

# Set tools

# Use clang if it's available.
Expand Down Expand Up @@ -197,6 +203,8 @@ SDL_TARGET := $(BIN)/SDL/sameboy
TESTER_TARGET := $(BIN)/tester/sameboy_tester
endif

APPIMAGE_DIR := $(BIN)/AppImage/

cocoa: $(BIN)/SameBoy.app
quicklook: $(BIN)/SameBoy.qlgenerator
sdl: $(SDL_TARGET) $(BIN)/SDL/dmg_boot.bin $(BIN)/SDL/cgb_boot.bin $(BIN)/SDL/agb_boot.bin $(BIN)/SDL/sgb_boot.bin $(BIN)/SDL/sgb2_boot.bin $(BIN)/SDL/LICENSE $(BIN)/SDL/registers.sym $(BIN)/SDL/background.bmp $(BIN)/SDL/Shaders
Expand Down Expand Up @@ -458,6 +466,13 @@ else
cp FreeDesktop/sameboy.desktop $(DESTDIR)$(PREFIX)/share/applications/sameboy.desktop
endif

appimage: $(APPIMAGE_DIR)/AppDir
OUTPUT=$(APPIMAGE_DIR)/SameBoy.AppImage \
linuxdeploy --appdir $< -v2 --output appimage --desktop-file FreeDesktop/sameboy.desktop --icon-file FreeDesktop/sameboy.png

$(APPIMAGE_DIR)/AppDir:
+make APPIMAGE_BUILD=1 DESTDIR=$@ PREFIX=/usr install

$(DESTDIR)$(PREFIX)/share/icons/hicolor/%/apps/sameboy.png: FreeDesktop/AppIcon/%.png
-@$(MKDIR) -p $(dir $@)
cp -f $^ $@
Expand Down
19 changes: 18 additions & 1 deletion SDL/utils.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "utils.h"
Expand All @@ -25,7 +26,23 @@ char *resource_path(const char *filename)
if (access(path, F_OK) == 0) {
return path;
}
snprintf(path, sizeof(path), "%s%s", DATA_DIR, filename);

char* directory = DATA_DIR;
#ifdef APPIMAGE_BUILD
char* appdir = getenv("APPDIR");
if (appdir)
{
directory = malloc(strlen(DATA_DIR) + strlen(appdir) + 1);
strcpy(directory, appdir);
strcat(directory, DATA_DIR);
}
#endif

snprintf(path, sizeof(path), "%s%s", directory, filename);

#ifdef APPIMAGE_BUILD
if (appdir) free(directory);
#endif
#endif
return path;
}
Expand Down