summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-22 21:15:38 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-22 21:15:38 -0800
commitf69db0983a2f435e7a0147bf8ad82b16196d4397 (patch)
tree206952a99c231a5a2214c41a8576fe7e82db6871
parent3916a1dcdac01b4a7da14c9561707046af6a1ef5 (diff)
Added some Makefile options to build a packaging friendly executable
-rw-r--r--Makefile18
-rw-r--r--config.c12
-rw-r--r--nuklear_ui/blastem_nuklear.c4
-rwxr-xr-xrender_sdl.c31
-rw-r--r--util.c10
5 files changed, 56 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 7b2fc5e..8a5b397 100644
--- a/Makefile
+++ b/Makefile
@@ -47,6 +47,14 @@ endif #USE_GLES
FONT:=nuklear_ui/font.o
endif #Darwin
+ifdef HOST_ZLIB
+LIBS+= zlib
+LIBZOBJS=
+else
+LIBZOBJS=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o\
+ zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
+endif
+
ifeq ($(OS),Darwin)
#This should really be based on whether or not the C compiler is clang rather than based on the OS
CFLAGS+= -Wno-logical-op-parentheses
@@ -156,8 +164,6 @@ AUDIOOBJS=ym2612.o psg.o wave.o
CONFIGOBJS=config.o tern.o util.o paths.o
NUKLEAROBJS=$(FONT) nuklear_ui/blastem_nuklear.o nuklear_ui/sfnt.o controller_info.o
RENDEROBJS=render_sdl.o ppm.o
-LIBZOBJS=zlib/adler32.o zlib/compress.o zlib/crc32.o zlib/deflate.o zlib/gzclose.o zlib/gzlib.o zlib/gzread.o\
- zlib/gzwrite.o zlib/infback.o zlib/inffast.o zlib/inflate.o zlib/inftrees.o zlib/trees.o zlib/uncompr.o zlib/zutil.o
ifdef NOZLIB
CFLAGS+= -DDISABLE_ZLIB
@@ -202,6 +208,14 @@ ifeq ($(OS),Windows)
MAINOBJS+= res.o
endif
+ifdef CONFIG_PATH
+CFLAGS+= -DCONFIG_PATH='"'$(CONFIG_PATH)'"'
+endif
+
+ifdef DATA_PATH
+CFLAGS+= -DDATA_PATH='"'$(DATA_PATH)'"'
+endif
+
ALL=dis$(EXE) zdis$(EXE) stateview$(EXE) vgmplay$(EXE) blastem$(EXE)
ifneq ($(OS),Windows)
ALL+= termhelper
diff --git a/config.c b/config.c
index 10238b8..351bff7 100644
--- a/config.c
+++ b/config.c
@@ -205,14 +205,24 @@ uint8_t serialize_config_file(tern_node *config, char *path)
tern_node *parse_bundled_config(char *config_name)
{
+ tern_node *ret = NULL;
+#ifdef CONFIG_PATH
+ if (!strcmp("default.cfg", config_name) || !strcmp("blastem.cfg", config_name)) {
+ char *confpath = path_append(CONFIG_PATH, config_name);
+ ret = parse_config_file(confpath);
+ free(confpath);
+ } else {
+#endif
uint32_t confsize;
char *confdata = read_bundled_file(config_name, &confsize);
- tern_node *ret = NULL;
if (confdata) {
confdata[confsize] = 0;
ret = parse_config(confdata);
free(confdata);
}
+#ifdef CONFIG_PATH
+ }
+#endif
return ret;
}
diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c
index d35c184..b2b9fe9 100644
--- a/nuklear_ui/blastem_nuklear.c
+++ b/nuklear_ui/blastem_nuklear.c
@@ -1512,7 +1512,11 @@ shader_prog *get_shader_list(uint32_t *num_out)
progs = NULL;
prog_storage = 0;
}
+#ifdef DATA_PATH
+ shader_dir = path_append(DATA_PATH, "shaders");
+#else
shader_dir = path_append(get_exe_dir(), "shaders");
+#endif
entries = get_dir_list(shader_dir, &num_entries);
progs = get_shader_progs(entries, num_entries, progs, &num_progs, &prog_storage);
*num_out = num_progs;
diff --git a/render_sdl.c b/render_sdl.c
index 62bac8f..2f5bfcd 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -13,6 +13,7 @@
#include "genesis.h"
#include "bindings.h"
#include "util.h"
+#include "paths.h"
#include "ppm.h"
#include "png.h"
#include "config.h"
@@ -489,24 +490,28 @@ static GLuint load_shader(char * fname, GLenum shader_type)
char * shader_path = alloc_concat_m(3, parts);
FILE * f = fopen(shader_path, "rb");
free(shader_path);
- if (!f) {
- parts[0] = get_exe_dir();
- parts[1] = "/shaders/";
- shader_path = alloc_concat_m(3, parts);
- f = fopen(shader_path, "rb");
+ GLchar * text;
+ long fsize;
+ if (f) {
+ fsize = file_size(f);
+ text = malloc(fsize);
+ if (fread(text, 1, fsize, f) != fsize) {
+ warning("Error reading from shader file %s\n", fname);
+ free(text);
+ return 0;
+ }
+ } else {
+ shader_path = path_append("shaders", fname);
+ uint32_t fsize32;
+ text = read_bundled_file(shader_path, &fsize32);
free(shader_path);
- if (!f) {
+ if (!text) {
warning("Failed to open shader file %s for reading\n", fname);
return 0;
}
+ fsize = fsize32;
}
- long fsize = file_size(f);
- GLchar * text = malloc(fsize);
- if (fread(text, 1, fsize, f) != fsize) {
- warning("Error reading from shader file %s\n", fname);
- free(text);
- return 0;
- }
+
if (strncmp(text, "#version", strlen("#version"))) {
GLchar *tmp = text;
text = alloc_concat(shader_prefix, tmp);
diff --git a/util.c b/util.c
index e54e8ea..50f79ee 100644
--- a/util.c
+++ b/util.c
@@ -875,14 +875,18 @@ char const *get_userdata_dir()
char *read_bundled_file(char *name, uint32_t *sizeret)
{
- char *exe_dir = get_exe_dir();
- if (!exe_dir) {
+#ifdef DATA_PATH
+ char *data_dir = DATA_PATH;
+#else
+ char *data_dir = get_exe_dir();
+ if (!data_dir) {
if (sizeret) {
*sizeret = -1;
}
return NULL;
}
- char const *pieces[] = {exe_dir, PATH_SEP, name};
+#endif
+ char const *pieces[] = {data_dir, PATH_SEP, name};
char *path = alloc_concat_m(3, pieces);
FILE *f = fopen(path, "rb");
free(path);