From ba49dd6cb4632f76be4cfeffeaf45b6e4bf9c2da Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 26 Sep 2017 09:42:24 -0400 Subject: [PATCH] Change build system to create standalone app bundle with resources inside, use ~/Documents/Rack as local directory --- Makefile | 46 +++++++++++++++++++++++++--------------------- src/asset.cpp | 44 ++++++++++++++++++++++++++++---------------- src/main.cpp | 5 +++++ 3 files changed, 58 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 75b34bd1..2ee90fc3 100644 --- a/Makefile +++ b/Makefile @@ -74,29 +74,15 @@ include compile.mk dist: all -ifndef VERSION - $(error VERSION is not set.) -endif - mkdir -p dist/Rack - mkdir -p dist/Rack/plugins - cp -R LICENSE* res dist/Rack/ -ifeq ($(ARCH), lin) - cp Rack Rack.sh dist/Rack/ - cp dep/lib/libsamplerate.so.0 dist/Rack/ - cp dep/lib/libjansson.so.4 dist/Rack/ - cp dep/lib/libGLEW.so.2.1 dist/Rack/ - cp dep/lib/libglfw.so.3 dist/Rack/ - cp dep/lib/libcurl.so.4 dist/Rack/ - cp dep/lib/libzip.so.5 dist/Rack/ - cp dep/lib/libportaudio.so.2 dist/Rack/ - cp dep/lib/libportmidi.so dist/Rack/ -endif + $(MAKE) -C plugins/Fundamental dist + ifeq ($(ARCH), mac) - $(eval BUNDLE := dist/Rack/$(TARGET).app) + $(eval BUNDLE := dist/$(TARGET).app) mkdir -p $(BUNDLE) mkdir -p $(BUNDLE)/Contents mkdir -p $(BUNDLE)/Contents/Resources cp Info.plist $(BUNDLE)/Contents/ + cp -R LICENSE* res $(BUNDLE)/Contents/Resources mkdir -p $(BUNDLE)/Contents/MacOS cp Rack $(BUNDLE)/Contents/MacOS/ @@ -123,8 +109,13 @@ ifeq ($(ARCH), mac) install_name_tool -change @rpath/libportmidi.dylib @executable_path/libportmidi.dylib $(BUNDLE)/Contents/MacOS/Rack otool -L $(BUNDLE)/Contents/MacOS/Rack + + mkdir -p $(BUNDLE)/Contents/Resources/plugins + cp -R plugins/Fundamental/dist/Fundamental $(BUNDLE)/Contents/Resources/plugins endif ifeq ($(ARCH), win) + mkdir -p dist/Rack + cp -R LICENSE* res dist/Rack/ cp Rack.exe dist/Rack/ cp /mingw64/bin/libwinpthread-1.dll dist/Rack/ cp /mingw64/bin/zlib1.dll dist/Rack/ @@ -138,11 +129,24 @@ ifeq ($(ARCH), win) cp dep/bin/libsamplerate-0.dll dist/Rack/ cp dep/bin/libzip-5.dll dist/Rack/ cp dep/bin/portaudio_x64.dll dist/Rack/ + mkdir -p dist/Rack/plugins + cp -R plugins/Fundamental/dist/Fundamental dist/Rack/plugins/ endif - - # Fundamental - $(MAKE) -C plugins/Fundamental dist +ifeq ($(ARCH), lin) + mkdir -p dist/Rack + cp -R LICENSE* res dist/Rack/ + cp Rack Rack.sh dist/Rack/ + cp dep/lib/libsamplerate.so.0 dist/Rack/ + cp dep/lib/libjansson.so.4 dist/Rack/ + cp dep/lib/libGLEW.so.2.1 dist/Rack/ + cp dep/lib/libglfw.so.3 dist/Rack/ + cp dep/lib/libcurl.so.4 dist/Rack/ + cp dep/lib/libzip.so.5 dist/Rack/ + cp dep/lib/libportaudio.so.2 dist/Rack/ + cp dep/lib/libportmidi.so dist/Rack/ + mkdir -p dist/Rack/plugins cp -R plugins/Fundamental/dist/Fundamental dist/Rack/plugins/ +endif ifeq ($(ARCH), mac) cd dist && ln -s /Applications Applications diff --git a/src/asset.cpp b/src/asset.cpp index 97005a6b..21f8fc70 100644 --- a/src/asset.cpp +++ b/src/asset.cpp @@ -1,25 +1,28 @@ #include "asset.hpp" -#include // for realpath #include +#include // for mkdir +#if ARCH_MAC + #include + #include +#endif -namespace rack { +namespace rack { -static std::string fileRealPath(std::string path) { - char *rpath = realpath(path.c_str(), NULL); - if (!rpath) - return ""; - - std::string rrpath = path; - free(rpath); - return rrpath; -} std::string assetGlobal(std::string filename) { std::string path; #if ARCH_MAC - // TODO + CFBundleRef bundle = CFBundleGetMainBundle(); + CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(bundle); + char buf[PATH_MAX]; + Boolean success = CFURLGetFileSystemRepresentation(resourcesUrl, TRUE, (UInt8 *)buf, sizeof(buf)); + assert(success); + CFRelease(resourcesUrl); + path = buf; + path += "/"; + path += filename; #endif #if ARCH_WIN path = "./" + filename; @@ -27,13 +30,20 @@ std::string assetGlobal(std::string filename) { #if ARCH_LIN path = "./" + filename; #endif - return fileRealPath(path); + return path; } std::string assetLocal(std::string filename) { std::string path; #if ARCH_MAC - // TODO + // Get home directory + struct passwd *pw = getpwuid(getuid()); + assert(pw); + path = pw->pw_dir; + path += "/Documents/Rack"; + mkdir(path.c_str(), 0755); + path += "/"; + path += filename; #endif #if ARCH_WIN // TODO @@ -43,12 +53,14 @@ std::string assetLocal(std::string filename) { // If Rack is "installed" (however that may be defined), look in ~/.Rack or something instead path = "./" + filename; #endif - return fileRealPath(path); + return path; } std::string assetPlugin(Plugin *plugin, std::string filename) { assert(plugin); - return fileRealPath(plugin->path + "/" + filename); + std::string path; + path = plugin->path + "/" + filename; + return path; } diff --git a/src/main.cpp b/src/main.cpp index 6b00ac80..ac071445 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,11 +4,16 @@ #include "plugin.hpp" #include "settings.hpp" #include "asset.hpp" +#include using namespace rack; int main(int argc, char* argv[]) { + char *cwd = getcwd(NULL, 0); + printf("Current working directory is %s\n", cwd); + free(cwd); + pluginInit(); engineInit(); guiInit();