changeset 762:206c449eaa81

Get "portable" builds working on Linux and add a build time check for whether /proc exists
author Michael Pavone <pavone@retrodev.com>
date Sun, 28 Jun 2015 18:44:11 -0700
parents ffb8cc5845fa
children 2a25ea5d94f7 bb60259e8edf
files Makefile util.c
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Sun Jun 28 17:16:24 2015 -0700
+++ b/Makefile	Sun Jun 28 18:44:11 2015 -0700
@@ -22,7 +22,8 @@
 LIBS=sdl2 glew gl
 endif #Darwin
 
-CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value -Wno-logical-op-parentheses
+HAS_PROC:=$(shell if [ -d /proc ]; then echo -e -DHAS_PROC; fi)
+CFLAGS:=-std=gnu99 -Wreturn-type -Werror=return-type -Werror=implicit-function-declaration -Wno-unused-value -Wno-logical-op-parentheses $(HAS_PROC)
 FIXUP:=
 ifdef PORTABLE
 CFLAGS+= -DGLEW_STATIC -Iglew/include
@@ -32,6 +33,9 @@
 CFLAGS+= -IFrameworks/SDL2.framework/Headers
 LDFLAGS+= -FFrameworks -framework SDL2 -framework OpenGL
 FIXUP:=install_name_tool -change @rpath/SDL2.framework/Versions/A/SDL2 @executable_path/Frameworks/SDL2.framework/Versions/A/SDL2 ./blastem
+else
+CFLAGS+= -Isdl/include
+LDFLAGS+= -Wl,-rpath='$$ORIGIN/lib' -Llib -lSDL2 $(shell pkg-config --libs gl)
 endif #Darwin
 
 else
--- a/util.c	Sun Jun 28 17:16:24 2015 -0700
+++ b/util.c	Sun Jun 28 18:44:11 2015 -0700
@@ -138,11 +138,12 @@
 {
 	static char * exe_dir;
 	if (!exe_dir) {
+		char * cur;
+#ifndef HAS_PROC
 		char * linktext = readlink_alloc("/proc/self/exe");
 		if (!linktext) {
 			goto fallback;
 		}
-		char * cur;
 		int linksize = strlen(linktext);
 		for(cur = linktext + linksize - 1; cur != linktext; cur--)
 		{
@@ -154,6 +155,7 @@
 		if (cur == linktext) {
 			free(linktext);
 fallback:
+#endif
 			if (!exe_str) {
 				fputs("/proc/self/exe is not available and set_exe_str was not called!", stderr);
 			}
@@ -167,9 +169,11 @@
 					break;
 				}
 			}
+#ifndef HAS_PROC
 		} else {
 			exe_dir = linktext;
 		}
+#endif
 	}
 	return exe_dir;
 }