hi,
i'm trying to fix the fluxus osx app that it can be run from any
directories not just from /Applications.
the problem is that boot.scm is loaded from an absolute path, and i
haven't managed to find out the current path from scheme if the program
is run as an osx application. tried (current-directory),
(find-system-path 'exec-file), (find-system-path 'orig-dir),
(find-executable-path), but none of them worked.
at last i managed to get the current directory using the
CFBundleCopyResourcesDirectoryURL function call from c. i replace the
collects path and data directories based on this. patch attached. so the
startup script looks like this when run:
(define plt-collects-location
"/Users/gabor/projects/fluxus/git/fluxus/Fluxus.app/Contents/Resources/collects/")
(define fluxus-collects-location
"/Users/gabor/projects/fluxus/git/fluxus/Fluxus.app/Contents/Resources/collects/")
(define fluxus-version "016") (define fluxus-data-location
"/Users/gabor/projects/fluxus/git/fluxus/Fluxus.app/Contents/Resources")
(load (string-append fluxus-collects-location "/fluxus-" fluxus-version
"/boot.scm"))
which seems to be right, but i receive this error message from a default
plt module, when the app is run:
Fluxus.app/Contents/Resources/collects/mzlib/unit.ss:1460:38: syntax: no
pattern variables before ellipses in template at: ... in: ((import i.s
...) (export e.s ...) dep . body)
do you have any idea what this could be? any help would be appreciated.
best,
gabor
diff --git a/SConstruct b/SConstruct
index 00c050e..bde75ce 100644
--- a/SConstruct
+++ b/SConstruct
@@ -49,11 +49,6 @@ if sys.platform == 'darwin':
else:
PLTCollectsLocation = PLTLib + "/collects/"
-if sys.platform == 'darwin' and GetOption('app'):
- PLTCollectsLocation =
'/Applications/Fluxus.app/Contents/Resources/collects/'
- FluxusCollectsLocation =
'/Applications/Fluxus.app/Contents/Resources/collects/'
- DataLocation = '/Applications/Fluxus.app/Contents/Resources'
-
LibPaths = [
PLTLib,
PLTLib+"/..",
@@ -76,9 +71,12 @@ env = Environment(CCFLAGS = '-ggdb -pipe -Wall -O3
-ffast-math -Wno-unused -fPIC
if env['PLATFORM'] == 'darwin':
IncludePaths += ['/opt/local/include',
- '/opt/local/include/freetype2']
+ '/opt/local/include/freetype2']
LibPaths += ['/opt/local/lib']
+if sys.platform == 'darwin' and GetOption('app'):
+ env.Append(CCFLAGS=' -D__APPLE_APP__')
+
env.Append(CPPPATH = IncludePaths)
env.Append(LIBPATH = LibPaths)
env.Append(CCFLAGS=' -DFLUXUS_MAJOR_VERSION='+MajorVersion)
@@ -116,19 +114,19 @@ if ARGUMENTS.get("3M","1")=="1":
# to be passed to the CheckLibWithHeader(...) at configure time.
# We may add extra libraries later on per platform basis
LibList = [["m", "math.h"],
- ["pthread", "pthread.h"],
- ["dl", "stdio.h"],
- ["mzscheme3m", PLTInclude + "/scheme.h"],
- ["jpeg", ["stdio.h", "stdlib.h", "jpeglib.h"]],
- ["tiff", "tiff.h"],
- ["freetype", "ft2build.h"],
- ["z", "zlib.h"],
- ["png", "png.h"],
- ["ode", "ode/ode.h"],
- ["sndfile", "sndfile.h"],
- ["fftw3", "fftw3.h"],
- ["lo", "lo/lo.h"],
- ["GLEW", "GL/glew.h"]]
+ ["pthread", "pthread.h"],
+ ["dl", "stdio.h"],
+ ["mzscheme3m", PLTInclude + "/scheme.h"],
+ ["jpeg", ["stdio.h", "stdlib.h", "jpeglib.h"]],
+ ["tiff", "tiff.h"],
+ ["freetype", "ft2build.h"],
+ ["z", "zlib.h"],
+ ["png", "png.h"],
+ ["ode", "ode/ode.h"],
+ ["sndfile", "sndfile.h"],
+ ["fftw3", "fftw3.h"],
+ ["lo", "lo/lo.h"],
+ ["GLEW", "GL/glew.h"]]
if env['PLATFORM'] == 'posix':
env.Prepend(LINKFLAGS = ["-rdynamic"])
@@ -143,11 +141,11 @@ if env['PLATFORM'] == 'posix':
# add the X11 libs on - needed if we are not building on xorg
if ARGUMENTS.get("X11",0):
LibList=[["Xi", "X11/Xlib.h"],
- ["Xmu", "X11/Xlib.h"],
- ["Xext", "X11/Xlib.h"],
- ["Xt", "X11/Xlib.h"],
- ["SM", "X11/Xlib.h"],
- ["ICE", "X11/Xlib.h"]] + LibList;
+ ["Xmu", "X11/Xlib.h"],
+ ["Xext", "X11/Xlib.h"],
+ ["Xt", "X11/Xlib.h"],
+ ["SM", "X11/Xlib.h"],
+ ["ICE", "X11/Xlib.h"]] +
LibList;
elif env['PLATFORM'] == 'darwin':
# add jack as a library if not making an app
if not GetOption('app'):
@@ -207,13 +205,13 @@ if not GetOption('clean'):
os.system("mzc --c-mods src/base.c ++lib scheme/base")
Source = ["src/GLEditor.cpp",
- "src/GLFileDialog.cpp",
- "src/Interpreter.cpp",
- "src/Repl.cpp",
- "src/Recorder.cpp",
- "src/FluxusMain.cpp",
- "src/PolyGlyph.cpp",
- "src/main.cpp"]
+ "src/GLFileDialog.cpp",
+ "src/Interpreter.cpp",
+ "src/Repl.cpp",
+ "src/Recorder.cpp",
+ "src/FluxusMain.cpp",
+ "src/PolyGlyph.cpp",
+ "src/main.cpp"]
env.Program(source = Source, target = Target)
@@ -230,8 +228,9 @@ if env['PLATFORM'] == 'darwin' and GetOption('app'):
from macos.osxbundle import *
TOOL_BUNDLE(env)
# We add frameworks after configuration bit so that testing is faster.
+ # ApplicationServices is required for CFBundle functions
# FIXME: check if Jackmp is available if making an app
- env.Replace(FRAMEWORKS = Split("GLUT OpenGL CoreAudio PLT_MrEd
Jackmp"))
+ env.Replace(FRAMEWORKS = Split("GLUT OpenGL CoreAudio
ApplicationServices PLT_MrEd Jackmp"))
# add dynamic libs
frameworks = [PLTLib + '/PLT_MrEd.framework',
'/Library/Frameworks/Jackmp.framework']
diff --git a/src/Interpreter.cpp b/src/Interpreter.cpp
index 85a0895..1d4bb16 100644
--- a/src/Interpreter.cpp
+++ b/src/Interpreter.cpp
@@ -20,6 +20,11 @@
#include "base.c"
+#ifdef __APPLE_APP__
+#include <ApplicationServices/ApplicationServices.h> // for texture loading
+#include <sys/param.h> // for MAXPATHLEN
+#endif
+
using namespace std;
using namespace fluxus;
@@ -39,10 +44,10 @@ Scheme_Object *Interpreter::m_ErrReadPort=NULL;
Scheme_Object *Interpreter::m_OutWritePort=NULL;
Scheme_Object *Interpreter::m_ErrWritePort=NULL;
std::string Interpreter::m_Language;
-
+
void Interpreter::Register()
{
- MZ_GC_DECL_REG(0);
+ MZ_GC_DECL_REG(0);
MZ_GC_REG();
MZ_REGISTER_STATIC(Interpreter::m_Scheme);
@@ -50,7 +55,7 @@ void Interpreter::Register()
MZ_REGISTER_STATIC(Interpreter::m_ErrReadPort);
MZ_REGISTER_STATIC(Interpreter::m_OutWritePort);
MZ_REGISTER_STATIC(Interpreter::m_ErrWritePort);
-
+
MZ_GC_UNREG();
}
@@ -78,6 +83,29 @@ void Interpreter::Initialise()
// load the startup script
char startup[1024];
+
+#ifdef __APPLE_APP__
+ char data_location[MAXPATHLEN];
+ char collects_location[MAXPATHLEN];
+ // get osx app bundle resources directory
+ CFURLRef url =
CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
+ CFURLGetFileSystemRepresentation(url, true, (unsigned char
*)data_location, MAXPATHLEN);
+
+ // generate collects directory path
+ strncpy(collects_location, data_location, MAXPATHLEN);
+ strncat(collects_location, "/collects/", MAXPATHLEN);
+
+ CFRelease(url);
+
+ snprintf(startup,1024,STARTUP_SCRIPT.c_str(),
+ collects_location,
+ collects_location,
+ FLUXUS_MAJOR_VERSION,
+ FLUXUS_MINOR_VERSION,
+ data_location);
+
+ fprintf(stderr, "%s\n", startup);
+#else
// insert the version number
snprintf(startup,1024,STARTUP_SCRIPT.c_str(),
PLT_COLLECTS_LOCATION,
@@ -85,15 +113,16 @@ void Interpreter::Initialise()
FLUXUS_MAJOR_VERSION,
FLUXUS_MINOR_VERSION,
DATA_LOCATION);
+#endif
Interpret(startup,NULL,true);
MZ_GC_UNREG();
}
-void Interpreter::SetRepl(Repl *s)
-{
- m_Repl=s;
+void Interpreter::SetRepl(Repl *s)
+{
+ m_Repl=s;
}
void fill_from_port(Scheme_Object* port, char *dest, long size)
@@ -102,14 +131,14 @@ void fill_from_port(Scheme_Object* port, char *dest, long
size)
MZ_GC_VAR_IN_REG(0, port);
MZ_GC_VAR_IN_REG(1, dest);
MZ_GC_REG();
-
- long pos=0;
+
+ long pos=0;
while (scheme_char_ready(port) && pos<size)
{
dest[pos++]=scheme_getc(port);
}
dest[pos]=0;
-
+
MZ_GC_UNREG();
}
@@ -120,26 +149,26 @@ string Interpreter::SetupLanguage(const string &str)
}
bool Interpreter::Interpret(const string &str, Scheme_Object **ret, bool abort)
-{
+{
char msg[LOG_SIZE];
mz_jmp_buf * volatile save = NULL, fresh;
-
+
MZ_GC_DECL_REG(1);
MZ_GC_VAR_IN_REG(0, msg);
MZ_GC_REG();
-
+
string code = SetupLanguage(str);
-
+
save = scheme_current_thread->error_buf;
scheme_current_thread->error_buf = &fresh;
-
- if (scheme_setjmp(scheme_error_buf))
+
+ if (scheme_setjmp(scheme_error_buf))
{
scheme_current_thread->error_buf = save;
- if (m_ErrReadPort!=NULL)
+ if (m_ErrReadPort!=NULL)
{
fill_from_port(m_ErrReadPort, msg, LOG_SIZE);
- if (strlen(msg)>0)
+ if (strlen(msg)>0)
{
if (m_Repl==NULL) cerr<<msg<<endl;
else m_Repl->Print(string(msg));
@@ -148,8 +177,8 @@ bool Interpreter::Interpret(const string &str,
Scheme_Object **ret, bool abort)
if (abort) exit(-1);
MZ_GC_UNREG();
return false;
- }
- else
+ }
+ else
{
if (ret==NULL)
{
@@ -161,7 +190,7 @@ bool Interpreter::Interpret(const string &str,
Scheme_Object **ret, bool abort)
}
scheme_current_thread->error_buf = save;
}
-
+
if (m_OutReadPort!=NULL)
{
fill_from_port(m_OutReadPort, msg, LOG_SIZE);
@@ -170,8 +199,8 @@ bool Interpreter::Interpret(const string &str,
Scheme_Object **ret, bool abort)
if (m_Repl==NULL) cerr<<msg<<endl;
else m_Repl->Print(string(msg));
}
- }
-
+ }
+
MZ_GC_UNREG();
return true;
}